示例#1
0
        private void createNewOrderFromSelectedVendorCodesButton_Click(object sender, EventArgs e)
        {
            if (mainFormGridView.SelectedRows.Count == 0)
            {
                MessageBox.Show("You should to choose at least one row");
                return;
            }
            List <Model.Good_Dimension> vendorCodes = new List <Model.Good_Dimension>();

            for (int i = 0; i < mainFormGridView.SelectedRows.Count; i++)
            {
                vendorCodes.Add((Model.Good_Dimension)mainFormGridView.SelectedRows[i].DataBoundItem);
            }


            Model.Order order = new Model.Order {
                Receipts = new List <Model.Receipt>(), Date = DateTime.Now
            };
            OrderSubForm orderSubForm = new OrderSubForm(ref dbContext, ref order, true);

            foreach (var x in vendorCodes)
            {
                orderSubForm.addNewReceipt(x.Good_Dimension_Id);
            }
            orderSubForm.Show();
        }
示例#2
0
        private void bindingNavigatorOrderDeleteButton_Click(object sender, EventArgs e)
        {
            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");
                    return;
                }
                else
                {
                    foreach (Model.Receipt r in order.Receipts)
                    {
                        try
                        {
                            dbContext.Good_Dimensions.Find(r.Good_Dimension_Id).Available += r.Amount;
                        }
                        catch { MessageBox.Show("Trouble with recover available items for unit\nVendor code: " + r.Good_Dimension_Id); }    // No DB problems cathching
                    }
                }

                dbContext.Orders.Remove(order);
                dbContext.SaveChanges();
            }
        }
示例#3
0
        // Order receipt
        private void orderPanelSaveReceipt_Click(object sender, EventArgs e)
        {
            if (saveReportFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            else
            {
                // Получаем выбранный файл
                string writePath = saveReportFileDialog.FileName;
                string text      = "            RECEIPT\n___________________________________________\n";

                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");
                    return;
                }
                text += "    Order№" + order.Order_Id + "\n    Date of order " + order.Date + "\n    Client: " + order.First_Name + " " + order.Last_Name + "\n\n";

                int posIndex = 1;
                foreach (var part in order.Receipts)
                {
                    string goodDimension = part.Good_Dimension.ToString();
                    text += posIndex + ". " + goodDimension + "    Count: " + part.Amount + "    Price=" + part.Position_Price + "\n";
                }
                text += "\n                         Full price: " + order.Full_Price + "\n____________________________________________\n";
                text += "    Date of receipt: " + DateTime.Now;

                try
                {
                    using (StreamWriter sw = new StreamWriter(writePath, false, System.Text.Encoding.Default))
                    {
                        sw.WriteLine(text);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
示例#4
0
 private void addToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (tableNameLable.Text.Equals("Goods"))
     {
         Model.Good  good        = new Model.Good();
         GoodSubForm goodSubForm = new GoodSubForm(ref dbContext, ref good, true);
         goodSubForm.Show();
     }
     else if (tableNameLable.Text.Equals("Dimensions"))
     {
         Model.Dimension  dimension        = new Model.Dimension();
         DimensionSubForm dimensionSubForm = new DimensionSubForm(ref dbContext, ref dimension, true);
         dimensionSubForm.Show();
     }
     else if (tableNameLable.Text.Equals("Vendor codes"))
     {
         Good_DimensionAddSubForm good_DimensionAddSubForm = new Good_DimensionAddSubForm(ref dbContext);
         good_DimensionAddSubForm.Show();
     }
     else if (tableNameLable.Text.Equals("Shops"))
     {
         Model.Shop     shop        = new Model.Shop();
         ShopAddSubForm shopSubForm = new ShopAddSubForm(ref dbContext, ref shop, ref instaApi);
         shopSubForm.Show();
     }
     else if (tableNameLable.Text.Equals("Deliveries"))
     {
         Model.Delivery  delivery        = new Model.Delivery();
         DeliverySubForm deliverySubForm = new DeliverySubForm(ref dbContext, ref delivery, true);
         deliverySubForm.Show();
     }
     else if (tableNameLable.Text.Equals("Orders"))
     {
         Model.Order order = new Model.Order {
             Receipts = new List <Model.Receipt>(), Date = DateTime.Now
         };
         OrderSubForm orderSubForm = new OrderSubForm(ref dbContext, ref order, true);
         orderSubForm.Show();
     }
 }
示例#5
0
 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();
         }
     }
 }
示例#6
0
        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);
            }
        }