Example #1
0
 private void btn_EditItem_Click(object sender, EventArgs e)//Edit values of selected item of selected row
 {
     //Only continues if Row has been selected
     if (this.dgv_Basket.SelectedRows.Count > 0)
     {
         //Makes rows selected select full row.
         this.dgv_Basket.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
         //Rows selected is equal to an item in OrderItems.
         this.dgv_Basket.DataSource = shop.OrderItems;
         //Create new item (oi) using data in selected rows.
         OrderItem oi = new OrderItem((dgv_Basket.CurrentRow.Cells[0].Value.ToString()),
                                      Convert.ToDecimal(dgv_Basket.CurrentRow.Cells[2].Value),
                                      Convert.ToInt32(dgv_Basket.CurrentRow.Cells[1].Value));
         //Uses oi so the data can be used in other form (EditUI)
         EditUI edit = new EditUI(oi);
         //Continues only after user clicks OK on EditUI Form.
         if (edit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             //Convert string to decimal.
             decimal editedLatestPrice;
             if (Decimal.TryParse((edit.SEditedLatestPrice.Remove(0, 1)), out editedLatestPrice))
             {
                 // Use the new inputted data from EditUI to create and add the item to the list.
                 OrderItem ni = new OrderItem(edit.EditedProductName, editedLatestPrice, edit.EditedQuantity);
                 shop.EditProduct(oi.ProductName, edit.EditedProductName, editedLatestPrice, edit.EditedQuantity, ni);
                 dgv_Basket.Update();
                 UpdateReadOnlys();
             }
         }
     }
     else //Will keep showing unless a row is selected.
     {
         MessageBox.Show("Please select one row");
     }
 }
Example #2
0
 //Edit values of selected item of selected row
 private void btn_EditItem_Click(object sender, EventArgs e)
 {
     //Only continues if Row has been selected
     if (this.dgv_Basket.SelectedRows.Count > 0)
     {
         //Makes rows selected select full row.
         this.dgv_Basket.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
         //Rows selected is equal to an item in OrderItems.
         this.dgv_Basket.DataSource = shop.OrderItems;
         //Create new item (oi) using data in selected rows.
         OrderItem oi = new OrderItem((dgv_Basket.CurrentRow.Cells[0].Value.ToString()),
             Convert.ToDecimal(dgv_Basket.CurrentRow.Cells[2].Value),
             Convert.ToInt32(dgv_Basket.CurrentRow.Cells[1].Value));
         //Uses oi so the data can be used in other form (EditUI)
         EditUI edit = new EditUI(oi);
         //Continues only after user clicks OK on EditUI Form.
         if (edit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             //Convert string to decimal.
             decimal editedLatestPrice;
             if (Decimal.TryParse((edit.SEditedLatestPrice.Remove(0, 1)), out editedLatestPrice))
             {
                 // Use the new inputted data from EditUI to create and add the item to the list.
                 OrderItem ni = new OrderItem(edit.EditedProductName, editedLatestPrice, edit.EditedQuantity);
                 shop.EditProduct(oi.ProductName, edit.EditedProductName, editedLatestPrice, edit.EditedQuantity, ni);
                 dgv_Basket.Update();
                 UpdateReadOnlys();
             }
         }
     }
     else //Will keep showing unless a row is selected.
     {
         MessageBox.Show("Please select one row");
     }
 }