Ejemplo n.º 1
0
        /// <summary>
        /// Удаление(нажатие на кнопку).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteButton_Click(object sender, EventArgs e)
        {
            var selectedNode = (StorageNode)storageTree.SelectedNode;

            if (selectedNode != null)
            {
                try
                {
                    DialogResult result = MessageBox.Show("Are you sure want to delete this row?", "Warning", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        var selectedCells = dataGrid.SelectedCells;
                        if (selectedCells != null && selectedCells.Count > 0)
                        {
                            var productRow = (ProductRow)selectedCells[0].OwningRow;
                            Storage.Products.Remove(productRow.Product);
                            selectedNode.Cathegory.Products.Remove(productRow.Product);
                            dataGrid.Rows.RemoveAt(selectedCells[0].RowIndex);
                            SuperSmartCsvManager.WriteToCsv((StorageNode)selectedNode);
                        }
                    }
                }
                catch (InvalidOperationException)
                {
                    MessageBox.Show("Choose correct row.");
                }
            }
            else
            {
                MessageBox.Show("Choose cathegory.");
            }
        }
Ejemplo n.º 2
0
 /// <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.");
     }
 }
Ejemplo n.º 3
0
 /// <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
     {
     }
 }