示例#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();
                    }
                }
            }
        }
示例#2
0
        private void btnAcceptSuggestion_Click(object sender, EventArgs e)
        {
            try
            {
                if (gvSuggestedReffils.SelectedCells.Count == 0)
                {
                    throw new Exception("No suggestions!");
                }
                if (gvSuggestedReffils.SelectedCells.Count < 2)
                {
                    throw new Exception("Select the entire row!");
                }
                string SearchValue      = "";
                string SuggestedOrderID = "";
                foreach (DataGridViewRow row in gvSuggestedReffils.SelectedRows)
                {
                    SuggestedOrderID = row.Cells[0].Value.ToString();
                    SearchValue      = SuggestedOrderID;
                }

                int rowIndex = -1;
                foreach (DataGridViewRow row in gvSuggestedReffils.Rows)
                {
                    if (row.Cells[0].Value.ToString().Equals(SearchValue))
                    {
                        rowIndex = row.Index;
                        gvSuggestedReffils.Rows[rowIndex].Selected = true;
                        string OrderID     = row.Cells[0].Value.ToString();
                        string WarehouseID = row.Cells[2].Value.ToString();
                        string Product     = row.Cells[1].Value.ToString();

                        if (string.IsNullOrWhiteSpace(txtQuantity.Text) || txtQuantity.Text == "0")
                        {
                            throw new Exception("Please insert a quantity!\n");
                        }
                        string Quantity = txtQuantity.Text.ToString();


                        using (var context = new WMSEntities())
                        {
                            using (var dbContextTransaction = context.Database.BeginTransaction())
                            {
                                try
                                {
                                    context.AcceptSuggestion(Int32.Parse(OrderID), Int32.Parse(Quantity));
                                    context.SaveChanges();
                                    int warehouseID = Int32.Parse(WarehouseID);
                                    using (var context1 = new WMSEntities())
                                    {
                                        var result = (from p in context1.Products
                                                      where p.ProductName == Product
                                                      select p.ProductID).First();
                                        int  prodID  = Int32.Parse(result.ToString());
                                        Form Barcode = new FormBarcode(prodID);
                                        Barcode.ShowDialog();
                                    }
                                    Form RefillForm = new RefillForm(0, warehouseID, Product, Quantity, true);
                                    RefillForm.ShowDialog();
                                    dbContextTransaction.Commit();
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message.ToString());
                                    dbContextTransaction.Rollback();
                                }
                            }
                        }
                    }
                }

                this.Close();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }