Example #1
0
        private void btnRefill_Click(object sender, EventArgs e)
        {
            int    warehouseID = Int32.Parse(cmbWarehouse.SelectedItem.ToString());
            string ProductName = Search_txt.Text;

            if (String.IsNullOrEmpty(txtQuantity.Text))
            {
                MessageBox.Show("Please insert a quantity!!");
                return;
            }
            int quantity = Int32.Parse(txtQuantity.Text.ToString());

            if (quantity <= 0)
            {
                MessageBox.Show("Please insert a valid quantity (greater than zero)!!");
                txtQuantity.Clear();
                txtQuantity.Focus();
                return;
            }
            using (var context = new WMSEntities())
            {
                var result = (from p in context.Products
                              where p.ProductName == ProductName
                              select p.ProductID).First();
                int  prodID  = Int32.Parse(result.ToString());
                Form Barcode = new FormBarcode(prodID);
                Barcode.ShowDialog();
            }


            Form Refill = new RefillForm(0, warehouseID, ProductName, txtQuantity.Text.ToString(), true);

            Refill.ShowDialog();

            using (var context = new WMSEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        context.RefillFromWarehouse(0, warehouseID, quantity, ProductName);
                        context.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());
                        dbContextTransaction.Rollback();
                    }
                }
            }
        }
Example #2
0
        private void TryRefillfromWarehouse(string Product, string Quantity, int DestinationWarehouseID, int OrderID, string ClientName, string Adress)
        {
            using (var context = new WMSEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        int quantity = Int32.Parse(Quantity);
                        var result   = (from p in context.Products
                                        where p.ProductName.Equals(Product) && p.UnitsInStock >= quantity
                                        select new
                        {
                            SourceWarehouseID = p.WarehouseID,
                            units = p.UnitsInStock,
                            prodID = p.ProductID,
                            rowID = p.RowID,
                            price = p.UnitPrice
                        });

                        if (!string.IsNullOrWhiteSpace(result.ToString()))
                        {
                            if (result.Count() != 0)
                            {
                                var rez = result.ToList();

                                DialogResult dr = MessageBox.Show(String.Format("Do you want to refill warehouse {0} from warehouse {1} with product ->{2}, units->{3}?", DestinationWarehouseID, rez[0].SourceWarehouseID, Product, Quantity), "The Question",
                                                                  MessageBoxButtons.YesNo,
                                                                  MessageBoxIcon.Question,
                                                                  MessageBoxDefaultButton.Button1);


                                switch (dr)
                                {
                                case DialogResult.Yes:
                                {
                                    int sourceID;
                                    Int32.TryParse(rez[0].SourceWarehouseID.ToString(), out sourceID);
                                    float price  = float.Parse(rez[0].price.ToString());
                                    Form  refill = new RefillForm(sourceID, DestinationWarehouseID, Product, Quantity, false);
                                    refill.ShowDialog();
                                    context.RefillFromWarehouse(rez[0].SourceWarehouseID, DestinationWarehouseID, quantity, Product);
                                    refill.Close();
                                    //          Form BarCodeCheck = new BarCodeCheck(rez[0].prodID);
                                    //        BarCodeCheck.Show();
                                    MessageBox.Show("The refill is done! Order is ready to be processed! ");
                                    Form fr = new ProcessingOrder(OrderID.ToString(), ClientName, Adress, Product, quantity, rez[0].rowID, price);
                                    fr.Show();
                                    context.UpdateDB(Product, quantity, DestinationWarehouseID);
                                    context.SaveChanges();
                                    context.MarkProcessed(OrderID, rez[0].prodID);

                                    context.SaveChanges();
                                    dbContextTransaction.Commit();

                                    break;
                                };

                                case DialogResult.No:
                                {
                                    break;
                                };
                                }
                            }
                            else
                            {
                                var rez = (from p in context.Products
                                           where p.ProductName.Equals(Product)
                                           select new
                                {
                                    prodID = p.ProductID,
                                    rowID = p.RowID,
                                    Price = p.UnitPrice
                                }).ToList();

                                Form refill = new RefillForm(0, DestinationWarehouseID, Product, Quantity, false);
                                refill.ShowDialog();
                                // Form BarCodeCheck = new BarCodeCheck(rez[0].prodID);
                                //BarCodeCheck.Show();
                                context.RefillFromWarehouse(0, DestinationWarehouseID, quantity, Product);
                                context.SaveChanges();
                                refill.Close();
                                MessageBox.Show("The refill is done! Order is ready to be processed! ");
                                float price = float.Parse(rez[0].Price.ToString());
                                Form  fr    = new ProcessingOrder(OrderID.ToString(), ClientName, Adress, Product, quantity, rez[0].rowID, price);
                                fr.Show();
                                context.MarkProcessed(OrderID, rez[0].prodID);
                                context.SaveChanges();
                                context.UpdateDB(Product, quantity, DestinationWarehouseID);
                                context.SaveChanges();
                                dbContextTransaction.Commit();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());
                        dbContextTransaction.Rollback();
                    }
                }
            }
        }