private void comboBox1_SelectedValueChanged(object sender, EventArgs e) { listBox1.Items.Clear(); dataGridView1.Rows.Clear(); panel2.Visible = false; string name = comboBox1.Text; string[] obj = DBObject.GetObjectByName(name); if (obj != null) { int id = Convert.ToInt32(obj[0]); shops = DBShop.GetShopById(id); if (shops.Count != 0) { shops.ForEach(el => listBox1.Items.Add(el[2])); } else { string msg = "Перечень магазинов для данного товара не найден!"; cc.LogError(msg); MessageBox.Show(msg, "Ошибка!"); } } }
private void SaveBD_Click(object sender, EventArgs e) { try { foreach (int r in rowIds) { string[] Cells = ToArray(dataGridView2.Rows[r]); DBObject.SetObject(Cells); DBShop.SetShop(Cells); } string msg = "База обновлена!"; MessageBox.Show(msg, "Выполнено"); cc.LogSuccess(msg); rowIds.Clear(); } catch (Exception ex) { cc.LogError($"{ex.Message.ToString()}"); return; } string[] ToArray(DataGridViewRow row) { string[] rowCells = new string[row.Cells.Count]; for (int i = 0; i < row.Cells.Count; i++) { rowCells[i] = row.Cells[i].Value.ToString(); } return(rowCells); } }
private void AddDB_Click(object sender, EventArgs e) { string tBO = tBObject.Text.Trim(); string tBS = comboBox2.Text.Trim(); string tBL = tBLink.Text.Trim(); if (tBO != "" && tBS != "" && tBL != "") { AvailibiltyCheck(); comboBox2.Text = ""; tBLink.Text = ""; SetPivotTable(); } else { string msg = "Заполните все поля дибилы!"; cc.LogError(msg); MessageBox.Show(msg, "Ошибка"); } void AvailibiltyCheck() { string[] str = DBObject.GetObjectByName(tBO); if (str == null) { if (DBObject.AddObject(new string[] { tBO })) { str = DBObject.GetObjectByName(tBO); } } if (DBShop.AddShop(new string[] { str[0], tBS, tBL })) { string msg = $"Товар '{tBO}' добавлен в базу данных"; MessageBox.Show(msg, "Выполнено"); cc.LogSuccess(msg); } } }
private void ButtonDelete_Click(object sender, EventArgs e) { var rows = dataGridView2.SelectedRows; if (rows.Count > 0) { for (int i = 0; i < rows.Count; i++) { string shopName = rows[i].Cells[4].Value.ToString(); DBShop.DeleteShopByName(shopName); } SetPivotTable(); string msg = "Магазин(ы) удален(ы)!"; cc.LogSuccess(msg); MessageBox.Show(msg, "Выполнено"); } else { string msg = "Не ожидал ошибки? Выбери строку для удаления, придурок."; cc.LogError(msg); MessageBox.Show(msg, "Ошибка!"); } }