public void addNewReceipt(int gdid) { int good_dimension_id = gdid; Good_Dimension good_Dimension = dbContext.Good_Dimensions.Find(good_dimension_id); if (good_Dimension == null) { MessageBox.Show("Any vendor code matches!"); return; } if (good_Dimension.Available < 1) { MessageBox.Show("Available only " + good_Dimension.Available + " units\n with this vendor code"); return; } if (order.Receipts.Where(r => r.Good_Dimension_Id == good_dimension_id).Count() == 0) { good_Dimension.Available -= Convert.ToInt32(addVendorCodeCountNumericUpDown.Value); // DBCONTEXT CHANGING changes.Add(new ReceiptChange(good_Dimension.Good_Dimension_Id, Convert.ToInt32(addVendorCodeCountNumericUpDown.Value), true)); order.Receipts.Add(new Receipt { Good_Dimension_Id = good_dimension_id, Good_Dimension = good_Dimension, Amount = Convert.ToInt32(addVendorCodeCountNumericUpDown.Value), Order = order, Position_Price = good_Dimension.Price * addVendorCodeCountNumericUpDown.Value }); } else { good_Dimension.Available -= Convert.ToInt32(addVendorCodeCountNumericUpDown.Value); // DBCONTEXT CHANGING changes.Add(new ReceiptChange(good_Dimension.Good_Dimension_Id, Convert.ToInt32(addVendorCodeCountNumericUpDown.Value), true)); Receipt receipt = order.Receipts.Where(r => r.Good_Dimension_Id == good_dimension_id).ToList()[0]; receipt.Amount += Convert.ToInt32(addVendorCodeCountNumericUpDown.Value); receipt.Position_Price = good_Dimension.Price * receipt.Amount; // TODO: Deleting overflowed vendor codes with canceling } fullPriceLabel.Text = "Full price: " + order.Receipts.Sum(o => o.Position_Price); receiptsDataGridView.DataSource = new BindingList<Receipt>(order.Receipts); }
public GoodDimensionEditSubForm(ref InstaMarketDbContext dbContext, ref Good_Dimension good_dimension) { InitializeComponent(); this.dbContext = dbContext; this.good_dimension = good_dimension; goodDimensionIdLabel.Text += good_dimension.Good_Dimension_Id; goodIdLabel.Text += good_dimension.Good_Id; goodLabel.Text += good_dimension.Good.ToString(); dimensionIdLabel.Text += good_dimension.Dimension_Id; dimensionLabel.Text += good_dimension.Dimension.ToString(); priceNumericUpDown.Value = good_dimension.Price; amountNumericUpDown.Value = good_dimension.Available; }
private void addVendorCodeButton_Click(object sender, EventArgs e) { int vendorCode = 0; try { vendorCode = Convert.ToInt32(vendorCodeTextBox.Text); } catch { MessageBox.Show("Wrong vendor code format"); return; } Good_Dimension good_Dimension = dbContext.Good_Dimensions.Find(vendorCode); if (good_Dimension != null) { if (publication.Good_Dimension_Publications.FirstOrDefault(gpd => gpd.Good_Dimension_Id == vendorCode) == null) { publication.Good_Dimension_Publications.Add(new Good_Dimension_Publication { Good_Dimension_Id = vendorCode, Publication_Id = publication.Publication_Id, Publication = publication, Good_Dimension = good_Dimension }); publicationGoodDimensionsDataGridView.DataSource = new BindingList <Good_Dimension_Publication>(publication.Good_Dimension_Publications); } else { MessageBox.Show("This vendor code is already attached"); } } else { MessageBox.Show("Any matches to this vendor code"); } }