private void editToolStripMenuItem_Click(object sender, EventArgs e) { if (tableNameLable.Text.Equals("Goods")) { Model.Good good = mainFormGridView.SelectedRows.Count == 0 ? null : (Model.Good)mainFormGridView.SelectedRows[0].DataBoundItem; if (good == null) { MessageBox.Show("You should to select at least one row"); } else { GoodSubForm goodSubForm = new GoodSubForm(ref dbContext, ref good, false); goodSubForm.Show(); } } else if (tableNameLable.Text.Equals("Dimensions")) { Model.Dimension dimension = mainFormGridView.SelectedRows.Count == 0 ? null : (Model.Dimension)mainFormGridView.SelectedRows[0].DataBoundItem; if (dimension == null) { MessageBox.Show("You should to select at least one row"); } else { DimensionSubForm dimensionSubForm = new DimensionSubForm(ref dbContext, ref dimension, false); dimensionSubForm.Show(); } } else if (tableNameLable.Text.Equals("Vendor codes")) { Model.Good_Dimension good_dimension = mainFormGridView.SelectedRows.Count == 0 ? null : (Model.Good_Dimension)mainFormGridView.SelectedRows[0].DataBoundItem; if (good_dimension == null) { MessageBox.Show("You should to select at least one row"); } else { GoodDimensionEditSubForm good_dimensionSubForm = new GoodDimensionEditSubForm(ref dbContext, ref good_dimension); good_dimensionSubForm.Show(); } } else if (tableNameLable.Text.Equals("Publications")) { Model.Publication publication = mainFormGridView.SelectedRows.Count == 0 ? null : (Model.Publication)mainFormGridView.SelectedRows[0].DataBoundItem; if (publication == null) { MessageBox.Show("You should to select at least one row"); } else { PublicationSubForm publicationSubForm = new PublicationSubForm(ref dbContext, ref publication); publicationSubForm.Show(); } } else if (tableNameLable.Text.Equals("Deliveries")) { Model.Delivery delivery = mainFormGridView.SelectedRows.Count == 0 ? null : (Model.Delivery)mainFormGridView.SelectedRows[0].DataBoundItem; if (delivery == null) { MessageBox.Show("You should to select at least one row"); } else { DeliverySubForm deliverySubForm = new DeliverySubForm(ref dbContext, ref delivery, false); deliverySubForm.Show(); } } else if (tableNameLable.Text.Equals("Orders")) { Model.Order order = mainFormGridView.SelectedRows.Count == 0 ? null : (Model.Order)mainFormGridView.SelectedRows[0].DataBoundItem; if (order == null) { MessageBox.Show("You should to select at least one row"); } else { OrderSubForm orderSubForm = new OrderSubForm(ref dbContext, ref order, false); orderSubForm.Show(); } } }
public bool TryToParse() { if (Text != null) { try { string beforeStars = Text.Substring(0, Text.IndexOf('*')); List <string> lfpdm = beforeStars.Split(',').ToList(); if (lfpdm.Count < 4 || lfpdm[0].Length < 2 || lfpdm[1].Length < 2 || Regex.Match(lfpdm[2], @"^(\+[0-9]{9})$").Success || dbContext.Deliveries.FirstOrDefault(d => d.Delivery_Id == Convert.ToInt32(lfpdm[3])) == null) { return(false); } string afterStars = Text.Substring(Text.LastIndexOf('*') + 1); List <string> vas = afterStars.Split(',').ToList(); List <int> vendorCodes = vas.Select(va => Convert.ToInt32(va.Substring(0, va.IndexOf('-')))).ToList(); List <int> amounts = vas.Select(va => Convert.ToInt32(va.Substring(va.IndexOf('-') + 1))).ToList(); if (vendorCodes.Count != amounts.Count || vendorCodes.Count == 0) { return(false); } Model.Order order = new Model.Order { Receipts = new List <Model.Receipt>(), Date = DateTime.Now }; order.Last_Name = lfpdm[0]; order.First_Name = lfpdm[1]; order.Phone_Number = lfpdm[2]; order.Delivery_Id = Convert.ToInt32(lfpdm[3]); if (lfpdm.Count == 5) { order.Email = lfpdm[4]; } for (int i = 0; i < vendorCodes.Count; i++) { if (amounts[i] < 1) { return(false); } Model.Good_Dimension goodDimension = dbContext.Good_Dimensions.FirstOrDefault(gd => gd.Good_Dimension_Id == vendorCodes[i]); if (goodDimension == null) { return(false); } order.Receipts.Add(new Model.Receipt { Amount = amounts[i], Good_Dimension_Id = vendorCodes[i], Order = order, Position_Price = goodDimension.Price * amounts[i] }); } order.Full_Price = order.Receipts.Sum(r => r.Position_Price); Order = order; return(true); } catch { return(false); } } else { return(false); } }