/// <summary> /// Редактировать товар(нажатие на кнопку). /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void editButton_Click(object sender, EventArgs e) { try { var selectedNode = storageTree.SelectedNode; if (selectedNode != null) { if (dataGrid.SelectedCells.Count == 0) { return; } var productRow = ((ProductRow)dataGrid.SelectedCells[0].OwningRow); ProductCardView pcv = new ProductCardView(productRow); pcv.ShowDialog(); if (pcv.Result != null) { object[] toSave = productRow.Product.GetArray(); for (int i = 0; i < toSave.Length; ++i) { productRow.Cells[i].Value = toSave[i]; } SuperSmartCsvManager.WriteToCsv((StorageNode)selectedNode); } } } catch { MessageBox.Show("Choose correct row."); } }
/// <summary> /// Нажатие на кнопку добавить. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void addButton_Click(object sender, EventArgs e) { try { var selectedNode = storageTree.SelectedNode; if (selectedNode != null) { var pcv = new ProductCardView(); pcv.ShowDialog(); Product pr = pcv.Result; if (pr == null) { return; } var array = pr.GetArray(); var row = new ProductRow(); row.Product = pr; row.CreateCells(dataGrid); for (int j = 0; j < array.Length; ++j) { row.Cells[j].Value = array[j]; } dataGrid.Rows.Add(row); Storage.Products.Add(pr); ((StorageNode)selectedNode).Cathegory.Products.Add(pr); SuperSmartCsvManager.WriteToCsv((StorageNode)selectedNode); } } catch { } }