private void searchElementSuuplyByEAN() // поиск по EAN коду товара { currentElementSupply = new elementSupply(cn); result r = currentElementSupply.searchByEan(tbElementEAN.Text); setStatusText(r); if (currentElementSupply.getId() == "") { /*string ms = "Ошибка определения товара. ID=''"; * MesShow(ms); * setStatusText(ms);*/ return; } tbElementEAN.Enabled = false; tbElementName.Text = currentElementSupply.getName(); tbElementQuantity.Enabled = true; tbElementQuantity.Focus(); }
private void addElementToSupply() { int q = 0; try { q = int.Parse(tbElementQuantity.Text); } catch (Exception ee) { setStatusText(ee.Message); return; } currentElementSupply.setQuantity(q); if (dtDgvElementSupply == null) { dtDgvElementSupply = new DataTable(); dtDgvElementSupply.Columns.Add("id", typeof(string)); dtDgvElementSupply.Columns.Add("EAN", typeof(string)); dtDgvElementSupply.Columns.Add("PAN", typeof(string)); dtDgvElementSupply.Columns.Add("Наименование", typeof(string)); dtDgvElementSupply.Columns.Add("Количество", typeof(int)); dgvSupply.DataSource = dtDgvElementSupply; hideDGVColumns(dgvSupply, new string[] { "id" }); setLeaveStyleDgv(dgvSupply, null); setColumnsWidthDGV(); // Устанавливаем ширину столбцов в таблице gbSupplyElements.Enabled = true; } for (int a = 0; a < dtDgvElementSupply.Rows.Count; a++) { // Если товар уже есть в таблице if (dtDgvElementSupply.Rows[a].Field <string>("EAN") == currentElementSupply.getEan()) { // Если товар с таким кодом EAN уже есть в таблице dtDgvElementSupply.Rows[a].SetField <int>("Количество", dtDgvElementSupply.Rows[a].Field <int>("Количество") + currentElementSupply.getQuantity()); setStatusText("Количество обновлено"); currentElementSupply = null; tbElementEAN.Enabled = true; clearControls(gbElementSupply); tbElementEAN.Focus(); return; } } // Если такого товара еще нет в таблице DataRow dr = dtDgvElementSupply.NewRow(); dr.SetField <string>("id", currentElementSupply.getId()); dr.SetField <string>("EAN", currentElementSupply.getEan()); dr.SetField <string>("PAN", currentElementSupply.getManfacturerCode()); dr.SetField <string>("Наименование", currentElementSupply.getName()); dr.SetField <int>("Количество", currentElementSupply.getQuantity()); dtDgvElementSupply.Rows.Add(dr); tbElementEAN.Enabled = true; clearControls(gbElementSupply); tbElementEAN.Focus(); }