private void ConfirmORDC(InventoryContentItem ordc, DataRow[] r, string message) { DataRow[] r2 = orders.Select("PTL = " + r[0][1]); if (r2.Length > 0) { r2[0][3] = 1; string[] values = message.Split(';'); r2[0][4] = Convert.ToInt32(values[0]); if (values.Length >= 2 && values[1] != "") { String new_ser = values[1]; var command = "INSERT INTO ptl_database." + orders.TableName + "(mdCode, address, zone, series, seriesFull, status, actQuantity, userId) VALUES('" + values[4].ToString() + "', '" + values[2].ToString() + "', " + values[3].ToString() + ", '" + new_ser + "', '" + (values[5].ToString()) + "', 1, " + values[0].ToString() + ", " + (this.Owner as MainWindow).currentUser + ")"; (this.Owner as MainWindow).sqlQueriesToSend.Add(command); // This is mine } else if (values.Length < 2) { (this.Owner as MainWindow).sqlQueriesToSend.Add("UPDATE ptl_database." + orders.TableName + " SET status=1, userId=" + (this.Owner as MainWindow).currentUser + ", actQuantity=" + Convert.ToInt32(values[0]) + ", datetimeChecked=CURRENT_TIMESTAMP WHERE invId=" + ordc.RefID + ";"); // HERE SENDING TO DATABASE } } ordc.status = Status.confirmed; bool all_confirmed = true; foreach (InventoryContentItem o in OrdersPanel.Children.OfType <InventoryContentItem>()) { if (o.status != Status.confirmed) { all_confirmed = false; } } if (all_confirmed) { this.Confirmed = true; } }
public InventoryWindow(Inventory orderTable, DataTable PTLS, MySqlConnection conn) { InitializeComponent(); connect = conn; medical_series = new List <string>(); medical_series_full = new List <string>(); expandedItem = null; orders = orderTable; PTLs = PTLS; this.order_name = orderTable.TableName; //this.order_id = order_id; string[] st = { "Gateway", "ID" }; dt = PTLs.DefaultView.ToTable(true, st); /*string disp = ""; * foreach (DataRow row in dt.Rows) * { * disp += row[0].ToString() + ", " + row[1].ToString() + "\n"; * } * * MessageBox.Show(disp);*/ //string disp = ""; dt.Columns[0].ColumnName = "Gateway"; dt.Columns[1].ColumnName = "ID"; action_list = new List <Tuple <bool, int, string> > [dt.Rows.Count]; for (int ind = 0; ind < dt.Rows.Count; ind++) { action_list[ind] = new List <Tuple <bool, int, string> >(); } this.Owner = (MainWindow)Application.Current.MainWindow; this.ResizeMode = ResizeMode.NoResize; this.Closing += (se, e) => { if (!Confirmed && !(Owner as MainWindow).close) { MessageBox.Show("Инвентаризация аяқталмады!"); e.Cancel = true; } }; this.Loaded += (se, ev) => { Start(); }; foreach (DataRow row in orders.Rows) { if (Convert.ToInt32(row[3]) == 0) { DataRow[] r = PTLs.Select("Global = " + row[1]); if (r.Length > 0) { DataRow[] rw = dt.Select("Gateway = " + r[0][2] + " AND ID = " + r[0][3]); if (rw.Length > 0) { int index = dt.Rows.IndexOf(rw[0]); Tuple <bool, int, string> t = new Tuple <bool, int, string>(false, Convert.ToInt32(row[0]), row[2].ToString()); action_list[index].Add(t); Tuple <bool, int, string> t2 = new Tuple <bool, int, string>(true, Convert.ToInt32(row[0]), "000000"); action_list[index].Add(t2); } } } } int i = 1; //OrdersPanel.Visibility = Visibility.Collapsed; string[] s = { "" }; foreach (DataRow row in orders.Rows) { InventoryContentItem ordc = new InventoryContentItem(i, Convert.ToInt32(row[0]), s, row[6].ToString(), row[5].ToString(), row[2].ToString(), Convert.ToInt32(row[1]), medical_series, 1); if (Convert.ToInt32(row[3]) == 0) { ordc.QuantityCollected = 0; } else { ordc.status = Status.confirmed; ordc.QuantityCollected = Convert.ToInt32(row[4]); } ordc.ShowButtonPressed1 += (se, ev) => // if plus (new series) button pressed { medical_series.Clear(); medical_series_full.Clear(); { med_series = new DataTable(); string stu = "SELECT seriesNumber, seriesFull FROM medicamentsseries WHERE mdCode='" + row[7].ToString() + "';"; // I am working here MySqlDataAdapter da1 = new MySqlDataAdapter(stu, connect); da1.Fill(med_series); //MessageBox.Show(row[7].ToString()); } if (med_series.Rows.Count > 0) { med_series.Columns[0].ColumnName = "medical_series"; //MEDICAL SERIES med_series.Columns[1].ColumnName = "medical_series_full"; } foreach (DataRow row2 in med_series.Rows) { medical_series.Add(row2[0].ToString()); medical_series_full.Add(row2[1].ToString()); } //MessageBox.Show(medical_series[0]); InventoryContentItem ordc1 = new InventoryContentItem(i, Convert.ToInt32(row[0]), s, row[6].ToString(), row[5].ToString(), row[2].ToString(), Convert.ToInt32(row[1]), medical_series, 0); // Last parameter is mode (for series). 0 means series will be chosen by combobox if (Convert.ToInt32(row[3]) == 0) { ordc1.QuantityCollected = 0; } else { ordc1.status = Status.confirmed; ordc1.QuantityCollected = Convert.ToInt32(row[4]); } OrdersPanel.Children.Add(ordc1); // adding new element to the panel, but this time there is a combobox for series i++; ordc1.ShowButtonPressed += (se1, ev1) => { DataRow[] r = PTLs.Select("Global = " + (se1 as InventoryContentItem).PTL_global); if (r.Length > 0) { string ser_full = ""; foreach (DataRow row2 in med_series.Rows) { if (string.Equals((se1 as InventoryContentItem).Additional_series, row2[0].ToString())) { ser_full = row2[1].ToString(); break; } } ConfirmORDC(se1 as InventoryContentItem, r, ((se1 as InventoryContentItem).QuantityCollected.ToString() + ";" + (se1 as InventoryContentItem).Additional_series) + ";" + row[5].ToString() + ";" + row[8].ToString() + ";" + row[7].ToString() + ";" + ser_full); // add new parameters here for splitting ((MainWindow)Application.Current.MainWindow).ptlconn.ClearNode(Convert.ToInt32(r[0][2]), Convert.ToInt32(r[0][3])); DataRow[] rw = dt.Select("Gateway = " + r[0][2] + " AND ID = " + r[0][3]); if (rw.Length > 0) { int index = dt.Rows.IndexOf(rw[0]); int c = action_list[index].Count; for (int ind = c - 1; ind >= 0; ind--) { if (action_list[index][ind].Item2 == (se1 as InventoryContentItem).RefID) { action_list[index].RemoveAt(ind); } } if (action_list[index].Count > 0) { SendToPTL(action_list[index][0]); } } } }; }; ordc.ShowButtonPressed += (se, ev) => { DataRow[] r = PTLs.Select("Global = " + (se as InventoryContentItem).PTL_global); if (r.Length > 0) { ConfirmORDC(se as InventoryContentItem, r, ((se as InventoryContentItem).QuantityCollected.ToString())); //MessageBox.Show((se as InventoryContentItem).Additional_series); ((MainWindow)Application.Current.MainWindow).ptlconn.ClearNode(Convert.ToInt32(r[0][2]), Convert.ToInt32(r[0][3])); DataRow[] rw = dt.Select("Gateway = " + r[0][2] + " AND ID = " + r[0][3]); if (rw.Length > 0) { int index = dt.Rows.IndexOf(rw[0]); int c = action_list[index].Count; for (int ind = c - 1; ind >= 0; ind--) { if (action_list[index][ind].Item2 == (se as InventoryContentItem).RefID) { action_list[index].RemoveAt(ind); } } /*for (int ind = 0; ind < c; ind++) * { * Tuple<bool, int, string> t = action_list[index].Dequeue(); * if (t.Item2 != (se as InventoryContentItem).RefID) * { * action_list[index].Enqueue(t); * } * }*/ if (action_list[index].Count > 0) { SendToPTL(action_list[index][0]); } } } }; /*ordc.ExpandMe += (se, ev) => * { * if (expandedItem != null) * { * expandedItem.Expanded = false; * } * expandedItem = (se as InventoryContentItem); * expandedItem.Expanded = true; * };*/ OrdersPanel.Children.Add(ordc); i++; } }