using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Linq.Expressions; using System.Runtime.Remoting.Messaging; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Database; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OnDoc.Klassen; using OnDocScript; //using OnDocScript; using Syncfusion.Windows.Forms.Edit; using Syncfusion.WinForms.Controls; using Syncfusion.WinForms.DataGrid.Enums; using Windows.Devices.AllJoyn; using Windows.UI.Xaml.Controls; namespace OnDoc.Diverses { public partial class valueselector : SfForm { public string partnernr { get; set; } = ""; public string datenherkunft { get; set; } = ""; public string selected_value { get; set; } public DateTime selected_datetime { get; set; } = DateTime.Now; public valueselector() { InitializeComponent(); this.panel1.Visible = false; this.GridData.Visible = true; } public valueselector(Boolean Showcalendar) { InitializeComponent(); this.panel1.Visible = true; this.GridData.Visible = false; label2.Text = DateTime.Now.ToString("dd.MM.yyyy"); } private void valueselector_Load(object sender, EventArgs e) { this.SetDesktopLocation(Cursor.Position.X, Cursor.Position.Y); this.sfCalendar1.SelectedDate = DateTime.Now; } public async void rungraphql() { OnDocScriptGraphQL.OnDocScriptGraphQL ql = new OnDocScriptGraphQL.OnDocScriptGraphQL(); try { await ql.rungraphql(datenherkunft, this.partnernr); if (ql.resultstring != "") { string r = ql.resultstring; selected_value = r; this.DialogResult = DialogResult.OK; this.Close(); } else { this.GridData.DataSource = ql.resultdatatable; } ql = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } } public async void runscript() { NewScript newScript = new NewScript(AppParams.connectionstring, AppParams.apikey, datenherkunft.Replace("&OnDocScript", "")); newScript.AddVariable("Partnernr", this.partnernr.ToString()); newScript.AddVariable("temppath", AppParams.tempdir + @"\"); await newScript.Execute(); string result = newScript.get_scriptresult(); //DataSet ds = new DataSet(); DataTable dt = new DataTable(); //ds = (DataSet)JsonConvert.DeserializeObject(result, (typeof(DataSet))); dt = (DataTable)JsonConvert.DeserializeObject(result, (typeof(DataTable))); this.GridData.DataSource = dt; GridData.AutoSizeColumnsMode = Syncfusion.WinForms.DataGrid.Enums.AutoSizeColumnsMode.AllCells; newScript = null; } public void OnDocList(string inputstring) { try { int colcount = 0; string[] element = inputstring.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); DataTable dt = new DataTable(); int i = 0; foreach (string elementitem in element) { if (elementitem != "") { if (i == 1) { string[] cols = elementitem.Split(';'); foreach (string colitem in cols) { dt.Columns.Add(colitem); colcount++; } } if (i > 1) { DataRow dr = dt.NewRow(); if (colcount == 1) { dr[0] = elementitem; } else { string[] values = elementitem.Split(';'); int col = 0; foreach (string valueitem in values) { dr[col] = valueitem; col = col + 1; } } dt.Rows.Add(dr); } i++; } } dt.AcceptChanges(); this.GridData.DataSource = dt; } catch { }; } public void load_data() { if (datenherkunft == "" || datenherkunft == "&Freitext&") { return; } if (datenherkunft.Contains("OnDocScript")) { runscript(); this.Visible = true; return; } if (datenherkunft.Contains("OnDocGraphQL")) { rungraphql(); return; } if (datenherkunft.Contains("OnDocList")) { OnDocList(datenherkunft); return; } this.Visible = true; Database.DB dB = new Database.DB(AppParams.connectionstring); dB.clear_parameter(); dB.add_parameter("@nrpar00",partnernr); dB.add_parameter("@regel", datenherkunft); dB.Get_Tabledata("dbo.SP_Dokumentbearbeitung_DokWertList", true, false); this.GridData.DataSource = dB.dsdaten.Tables[0]; GridData.AutoSizeColumnsMode = Syncfusion.WinForms.DataGrid.Enums.AutoSizeColumnsMode.AllCells; } private void GridData_CellClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs e) { string value = ""; try { var selectedItem = e.DataRow; var dataRow = (e.DataRow.RowData as DataRowView).Row; value = dataRow[0].ToString(); selected_value = value; } catch { selected_value = ""; } } private void GridData_CellDoubleClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs e) { string value = ""; try { var selectedItem = e.DataRow; var dataRow = (e.DataRow.RowData as DataRowView).Row; value = dataRow[0].ToString(); selected_value = value; } catch { selected_value = ""; } DialogResult = DialogResult.OK; this.Close(); } private void sfCalendar1_Click(object sender, EventArgs e) { this.selected_datetime = (DateTime)sfCalendar1.SelectedDate; } private void sfCalendar1_DoubleClick(object sender, EventArgs e) { sfCalendar1_Click(sender, e); DialogResult = DialogResult.OK; this.Close(); } private void panel2_Click(object sender, EventArgs e) { sfCalendar1.SelectedDate = DateTime.Now; sfCalendar1_DoubleClick(sender, e); } private void button1_Click(object sender, EventArgs e) { sfCalendar1_DoubleClick(sender, e); } private void GridData_DrawCell(object sender, Syncfusion.WinForms.DataGrid.Events.DrawCellEventArgs e) { //try //{ // if (e.Column.MappingName == "SAREC00") // { // e.Handled = true; // var selectedItem = e.DataRow; // var dataRow = (e.DataRow.RowData as DataRowView).Row; // e.Style.Font.Strikeout = true; // Pen borderPen = new Pen(Color.LightGray); // e.Graphics.DrawLine(borderPen, e.Bounds.Right, e.Bounds.Top, e.Bounds.Right, e.Bounds.Bottom); // e.Graphics.DrawLine(borderPen, e.Bounds.Left, e.Bounds.Bottom, e.Bounds.Right, e.Bounds.Bottom); // return; // } //} //catch { } } private void GridData_QueryCellStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryCellStyleEventArgs e) { //try //{ // if (e.Column.MappingName == "SAREC00") // { // var selectedItem = e.DataRow; // var dataRow = (e.DataRow.RowData as DataRowView).Row; // e.Style.Font.Strikeout = true; // return; // } //} //catch { } } private void GridData_QueryRowStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryRowStyleEventArgs e) { try { if (e.RowType == RowType.DefaultRow) { var dataRowView = e.RowData as DataRowView; if (dataRowView != null) { var dataRow = dataRowView.Row; var cellValue = dataRow["SAREC00"].ToString(); if (cellValue == "7") e.Style.Font.Strikeout = true; } } } catch { } } } }