Пример #1
0
        private void ProductsForm_Load(object sender, EventArgs e)
        {
            context = new WMSEntities();
            context.Configuration.LazyLoadingEnabled = false;
            //var query = context.Clients.OrderBy(p => p.ID);

            var query =
                from product in context.Products
                join client in context.Clients on product.ClientID equals client.ID
                join region in context.Regions on product.RegionID equals region.ID
                select new
            {
                product.ID,
                product.Name,
                product.Width,
                product.Height,
                product.Depth,
                product.Amount,

                ClientID   = client.ID,
                ClientName = client.Name,
                RegionID   = region.ID,
                RegionName = region.Name
            };

            productsDataGridView.DataSource = query.ToList();
        }
Пример #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            HashSet <int> rows = new HashSet <int>();

            foreach (var row in productsDataGridView.SelectedCells)
            {
                int RowIndex = ((System.Windows.Forms.DataGridViewTextBoxCell)row).RowIndex;
                rows.Add((int)productsDataGridView[0, RowIndex].Value);
            }


            foreach (int row in rows)
            {
                using (WMSEntities cont = new WMSEntities())
                {
                    var query = from t in cont.Products
                                where t.ID == row
                                select t;
                    if (query.Count() > 0)
                    {
                        var t = query.ToList().First();
                        cont.Products.Remove(t);
                        cont.SaveChanges();
                    }
                }
            }

            ProductsForm_Load(null, null);
        }
Пример #3
0
        public SuggestedReffils()
        {
            InitializeComponent();
            using (var context = new WMSEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                    try
                    {
                        gvSuggestedReffils.DataSource = (from c in context.SuggestedRefillOrders
                                                         from p in context.Products
                                                         from w in context.Warehouses
                                                         where w.WarehouseID == c.WarehouseID
                                                         where p.ProductID == c.ProductID

                                                         select new
                        {
                            c.SuggestedOrderID,
                            //p.ProductID,
                            p.ProductName,
                            w.WarehouseID,
                            WarehouseAddress = w.Address
                        }
                                                         ).Distinct().ToList();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        MessageBox.Show(ex.Message.ToString());
                    }
            }
        }
Пример #4
0
        public UnprocessedOrders()
        {
            InitializeComponent();
            using (var context = new WMSEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                    try
                    {
                        gvUnproccOrders.DataSource = (from c in context.Clients
                                                      join cd in context.ClientOrderDetails on c.ClientID equals cd.ClientID
                                                      where cd.OrderState.Equals("unprocessed")
                                                      join p in context.Products on cd.ProductID equals p.ProductID

                                                      select new
                        {
                            cd.OrderID,
                            c.Name,
                            c.Address,
                            p.ProductName,
                            cd.Quantity,
                            cd.WarehouseID
                        }
                                                      ).Distinct().ToList();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        MessageBox.Show(ex.Message.ToString());
                    }
            }
        }
Пример #5
0
        private void CellForms_Load(object sender, EventArgs e)
        {
            context = new WMSEntities();
            context.Configuration.LazyLoadingEnabled = false;
            //var query = context.Clients.OrderBy(p => p.ID);

            var query =
                from cell in context.Cells
                join types in context.CellTypes on cell.TypeID equals types.ID
                join region in context.Regions on cell.RegionID equals region.ID
                join ware in context.Warehouses on cell.WarehouseID equals ware.ID
                select new
            {
                cell.ID,
                cell.Name,
                cell.Width,
                cell.Height,
                cell.Depth,
                cell.SizeControl,
                cell.Amount,
                cell.AmountControl,
                cell.Stillage,
                cell.Tier,
                cell.Position,

                TypeID        = types.ID,
                TypeName      = types.Name,
                RegionID      = region.ID,
                RegionName    = region.Name,
                WarehouseID   = ware.ID,
                WarehouseName = ware.Name,
            };

            productsDataGridView.DataSource = query.ToList();
        }
Пример #6
0
        private void RegionsForm_Load(object sender, EventArgs e)
        {
            context = new WMSEntities();
            var query = context.Regions.OrderBy(p => p.ID);

            regionsBindingSource.DataSource = query.ToList();

            dataGridViewTextBoxColumn1.ReadOnly = true;
        }
Пример #7
0
 public AfterWarehouseStock()
 {
     InitializeComponent();
     using (var context = new WMSEntities())
     {
         cmbWarehouse.DataSource = (from c in context.Warehouses
                                    select c.WarehouseID
                                    ).ToList();
     }
 }
Пример #8
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (WMSEntities cont = new WMSEntities())
     {
         Users t = new Users {
             ID = 1 + LastID(), Name = textBox2.Text
         };
         cont.Users.Add(t);
         cont.SaveChanges();
     }
     UsersForm_Load(null, null);
 }
Пример #9
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();
                    }
                }
            }
        }
Пример #10
0
 //додавання нового рядка
 private void button1_Click(object sender, EventArgs e)
 {
     using (WMSEntities cont = new WMSEntities())
     {
         Clients t = new Clients()
         {
             ID = 1 + LastID(), Name = textBox2.Text, Code = textBox1.Text
         };
         cont.Clients.Add(t);
         cont.SaveChanges();
     }
     Form1_Load(null, null);
 }
Пример #11
0
        public CurrentSales()
        {
            InitializeComponent();
            var context = new WMSEntities();

            txtCurrentSales.Text = "Please select a Warehouse";
            var result = (from c in context.Warehouses
                          select c.Address
                          ).ToList();

            warehousesComboBox.DataSource = (from c in context.Warehouses
                                             select c.WarehouseID
                                             ).ToList();
        }
Пример #12
0
        private int LastID()
        {
            int res = 0;

            using (WMSEntities cont = new WMSEntities())
            {
                var query = cont.Products.OrderBy(p => p.ID);
                if (query.Count() > 0)
                {
                    res = query.ToList().Last().ID;
                }
            }
            return(res);
        }
Пример #13
0
        private void btnStockW_Click(object sender, EventArgs e)
        {
            int warehouseID = Int32.Parse(cmbWarehouse.SelectedItem.ToString());

            using (var context = new WMSEntities())
            {
                gvStockW.DataSource = (from p in context.Products
                                       where p.WarehouseID == warehouseID
                                       select new
                {
                    ProductName = p.ProductName,
                    UnitsInStock = p.UnitsInStock
                }
                                       ).Distinct().ToList();
            }
        }
Пример #14
0
 public RefillOrders()
 {
     InitializeComponent();
     using (var context = new WMSEntities())
     { gvRefillOrders.DataSource = (from rd in context.RefillOrders
                                    join rod in context.RefillOrderDetails on rd.OrderID equals rod.OrderID
                                    join p in context.Products on rod.ProductID equals p.ProductID
                                    select new
         {
             p.ProductName,
             rd.OrderSource,
             rd.OrderDestination,
             rod.Quantity
         }
                                    ).Distinct().ToList(); }
 }
Пример #15
0
        private void btnStockP_Click(object sender, EventArgs e)
        {
            string ProductName = Search_txt.Text;

            using (var context = new WMSEntities())
            {
                gvStockP.DataSource = (from p in context.Products
                                       where p.ProductName == ProductName
                                       select new
                {
                    WarehouseId = p.WarehouseID,
                    UnitsInStock = p.UnitsInStock
                }
                                       ).ToList();
            }
        }
Пример #16
0
 void AutoCompleteText()
 {
     using (var context = new WMSEntities())
     {
         Search_txt.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
         Search_txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
         AutoCompleteStringCollection coll = new AutoCompleteStringCollection();
         var test = (from p in context.Products
                     select p.ProductName
                     ).Distinct().ToList();
         foreach (var a in test)
         {
             coll.Add(a);
         }
         Search_txt.AutoCompleteCustomSource = coll;
     }
 }
Пример #17
0
        public DetailsForm(string ProductName, string Source, string Destination, string Quantity)
        {
            InitializeComponent();
            int source      = Int32.Parse(Source);
            int destination = Int32.Parse(Destination);
            int quantity    = Int32.Parse(Quantity);

            using (var context = new WMSEntities())
            {
                string SourceFinal = "";
                if (Source == "0")
                {
                    SourceFinal = "Factory";
                }
                else
                {
                    var SourceAdress = (from w in context.Warehouses
                                        where w.WarehouseID == source
                                        select w.Address).First();
                    SourceFinal = SourceAdress.ToString();
                }


                var DestinationAdress = (from w in context.Warehouses
                                         where w.WarehouseID == destination
                                         select w.Address).First();

                if (SourceFinal == "Factory")
                {
                    txtDetails.Text = "Refill order from factory to warehouse " + Destination + " at adress " + DestinationAdress.ToString();
                    txtDetails.AppendText(Environment.NewLine);
                    txtDetails.AppendText("Product name--->" + ProductName);
                    txtDetails.AppendText(Environment.NewLine);
                    txtDetails.AppendText("Quantity of products--->" + Quantity);
                }
                else
                {
                    txtDetails.Text = "Refill order from warehouse " + Source + " at adress " + SourceFinal + " to warehouse " + Destination + " at adress " + DestinationAdress.ToString();
                    txtDetails.AppendText(Environment.NewLine);
                    txtDetails.AppendText("Product name--->" + ProductName);
                    txtDetails.AppendText(Environment.NewLine);
                    txtDetails.AppendText("Quantity of products--->" + Quantity);
                }
            }
        }
Пример #18
0
 private void btnCurrentSales_Click(object sender, EventArgs e)
 {
     using (var contex = new WMSEntities())
     {
         int WarehouseID = Int32.Parse(warehousesComboBox.SelectedItem.ToString());
         gvCurrentSales.DataSource = (from c in contex.CurrentSales
                                      join cd in contex.ClientOrderDetails on c.OrderID equals cd.OrderID
                                      where c.WarehouseID == WarehouseID & c.OrderID == cd.OrderID
                                      join p in contex.Products on cd.ProductID equals p.ProductID
                                      select new
         {
             Order = c.OrderID,
             ProductName = p.ProductName,
             Quantity = cd.Quantity,
             Price = c.TotalPrice
         }).Distinct().ToList();
     }
 }
Пример #19
0
        public MakeRefillForm()
        {
            InitializeComponent();
            AutoCompleteText();
            using (var context = new WMSEntities())
            {
                cmbWarehouse.DataSource = (from c in context.Warehouses
                                           select c.WarehouseID
                                           ).ToList();
            }
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = @"Data Source=.;Initial Catalog=WMS;Integrated Security=True";

            SqlCommand command = new SqlCommand();

            command.Connection  = conn;
            command.CommandText = "Select * FROM Products ";


            SqlDataAdapter adapter = new SqlDataAdapter(command);

            adapter.Fill(dbdataset);
        }
Пример #20
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (NameText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Name is empty !");
                return;
            }

            if (AmountText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Amount is empty !");
                return;
            }

            if (WidthText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Width is empty !");
                return;
            }

            if (HeightText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Height is empty !");
                return;
            }

            if (DepthText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Depth is empty !");
                return;
            }

            if (StillageText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Stillage is empty !");
                return;
            }

            if (TierText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Tier is empty !");
                return;
            }
            if (PositionText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Position is empty !");
                return;
            }

            if (SizeControlText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Size control is empty !");
                return;
            }
            if (AmountControlText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Amount control is empty !");
                return;
            }


            decimal nAmount;

            if (!decimal.TryParse(AmountText.Text.Trim(), out nAmount))
            {
                MessageBox.Show("Amount: bad format of number !");
                return;
            }

            decimal nWidth;

            if (!decimal.TryParse(WidthText.Text.Trim(), out nWidth))
            {
                MessageBox.Show("Width: bad format of number !");
                return;
            }

            decimal nHeight;

            if (!decimal.TryParse(HeightText.Text.Trim(), out nHeight))
            {
                MessageBox.Show("Height: bad format of number !");
                return;
            }

            decimal nDepth;

            if (!decimal.TryParse(DepthText.Text.Trim(), out nDepth))
            {
                MessageBox.Show("Depth: bad format of number !");
                return;
            }

            int nStillage;

            if (!int.TryParse(StillageText.Text.Trim(), out nStillage))
            {
                MessageBox.Show("Stillage: bad format of number !");
                return;
            }

            int nTier;

            if (!int.TryParse(TierText.Text.Trim(), out nTier))
            {
                MessageBox.Show("Tier: bad format of number !");
                return;
            }

            int nPosition;

            if (!int.TryParse(PositionText.Text.Trim(), out nPosition))
            {
                MessageBox.Show("Position: bad format of number !");
                return;
            }
            int nSizeControl;

            if (!int.TryParse(SizeControlText.Text.Trim(), out nSizeControl))
            {
                MessageBox.Show("Size control: bad format of number !");
                return;
            }
            int nAmountControl;

            if (!int.TryParse(AmountControlText.Text.Trim(), out nAmountControl))
            {
                MessageBox.Show("Amount control: bad format of number !");
                return;
            }

            if (clientsDataGridView.SelectedCells.Count == 0)
            {
                MessageBox.Show("Choose the Client !");
                return;
            }

            if (regionDataGridView.SelectedCells.Count == 0)
            {
                MessageBox.Show("Choose the Region !");
                return;
            }
            if (warehoesesGridView.SelectedCells.Count == 0)
            {
                MessageBox.Show("Choose the Warehouse !");
                return;
            }

            var row      = clientsDataGridView.SelectedCells[0];
            int RowIndex = ((System.Windows.Forms.DataGridViewTextBoxCell)row).RowIndex;
            int nTypeID  = (int)clientsDataGridView[0, RowIndex].Value;

            row      = regionDataGridView.SelectedCells[0];
            RowIndex = ((System.Windows.Forms.DataGridViewTextBoxCell)row).RowIndex;
            int nRegionID = (int)regionDataGridView[0, RowIndex].Value;

            row      = warehoesesGridView.SelectedCells[0];
            RowIndex = ((System.Windows.Forms.DataGridViewTextBoxCell)row).RowIndex;
            int nWareID = (int)warehoesesGridView[0, RowIndex].Value;


            using (WMSEntities cont = new WMSEntities())
            {
                Cells t = new Cells
                {
                    ID     = int.Parse(IDText.Text),
                    Name   = NameText.Text.Trim(),
                    Amount = nAmount,
                    Width  = nWidth,
                    Height = nHeight,
                    Depth  = nDepth,

                    Stillage      = nStillage,
                    Tier          = nTier,
                    Position      = nPosition,
                    SizeControl   = nSizeControl,
                    AmountControl = nAmountControl,

                    TypeID      = nTypeID,
                    RegionID    = nRegionID,
                    WarehouseID = nWareID
                };

                cont.Cells.AddOrUpdate(t);


                cont.SaveChanges();
            }


            DialogResult = DialogResult.OK;
            Close();
        }
Пример #21
0
        //кнопка "ОК"
        private void button1_Click(object sender, EventArgs e)
        {
            //перевірка кокектності заповнення
            if (NameText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Name is empty !");
                return;
            }

            if (AmountText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Amount is empty !");
                return;
            }

            if (WidthText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Width is empty !");
                return;
            }

            if (HeightText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Height is empty !");
                return;
            }

            if (DepthText.Text.Trim().Length == 0)
            {
                MessageBox.Show("Depth is empty !");
                return;
            }

            decimal nAmount;

            if (!decimal.TryParse(AmountText.Text.Trim(), out nAmount))
            {
                MessageBox.Show("Amount: bad format of number !");
                return;
            }

            decimal nWidth;

            if (!decimal.TryParse(WidthText.Text.Trim(), out nWidth))
            {
                MessageBox.Show("Width: bad format of number !");
                return;
            }

            decimal nHeight;

            if (!decimal.TryParse(HeightText.Text.Trim(), out nHeight))
            {
                MessageBox.Show("Height: bad format of number !");
                return;
            }

            decimal nDepth;

            if (!decimal.TryParse(DepthText.Text.Trim(), out nDepth))
            {
                MessageBox.Show("Depth: bad format of number !");
                return;
            }

            if (clientsDataGridView.SelectedCells.Count == 0)
            {
                MessageBox.Show("Choose the Client !");
                return;
            }

            if (regionDataGridView.SelectedCells.Count == 0)
            {
                MessageBox.Show("Choose the Region !");
                return;
            }

            var row       = clientsDataGridView.SelectedCells[0];
            int RowIndex  = ((System.Windows.Forms.DataGridViewTextBoxCell)row).RowIndex;
            int nClientID = (int)clientsDataGridView[0, RowIndex].Value;

            row      = regionDataGridView.SelectedCells[0];
            RowIndex = ((System.Windows.Forms.DataGridViewTextBoxCell)row).RowIndex;
            int nRegionID = (int)regionDataGridView[0, RowIndex].Value;

            using (WMSEntities cont = new WMSEntities())
            {
                Products t = new Products
                {
                    ID       = int.Parse(IDText.Text),
                    Name     = NameText.Text.Trim(),
                    Amount   = nAmount,
                    Width    = nWidth,
                    Height   = nHeight,
                    Depth    = nDepth,
                    ClientID = nClientID,
                    RegionID = nRegionID,
                };

                cont.Products.AddOrUpdate(t);


                cont.SaveChanges();
            }


            DialogResult = DialogResult.OK;
            Close();
        }
Пример #22
0
        private void btnProcessOrder_Click(object sender, EventArgs e)
        {
            try {
                if (gvUnproccOrders.SelectedCells.Count == 0)
                {
                    throw new Exception("No orders to process!");
                }
                if (gvUnproccOrders.SelectedCells.Count < 2)
                {
                    throw new Exception("Select the entire row!");
                }
                string SearchValue = "";
                string OrderID     = "";
                foreach (DataGridViewRow row in gvUnproccOrders.SelectedRows)
                {
                    OrderID     = row.Cells[0].Value.ToString();
                    SearchValue = OrderID;
                }

                int rowIndex = -1;
                foreach (DataGridViewRow row in gvUnproccOrders.Rows)
                {
                    if (row.Cells[0].Value.ToString().Equals(SearchValue))
                    {
                        rowIndex = row.Index;
                        gvUnproccOrders.Rows[rowIndex].Selected = true;
                        string ClientName  = row.Cells[1].Value.ToString();
                        string Adress      = row.Cells[2].Value.ToString();
                        string Product     = row.Cells[3].Value.ToString();
                        string Quantity    = row.Cells[4].Value.ToString();
                        string WarehouseID = row.Cells[5].Value.ToString();

                        using (var context = new WMSEntities())
                        {
                            using (var dbContextTransaction = context.Database.BeginTransaction())
                            {
                                try
                                {
                                    var prodID = (from p in context.Products
                                                  where p.ProductName.Equals(Product)
                                                  select p).First().ProductID;


                                    int warehouseID   = Int32.Parse(WarehouseID);
                                    var WarehouseName = (from c in context.Warehouses
                                                         where c.WarehouseID.Equals(warehouseID)
                                                         select c).First().Address;
                                    var check = (from p in context.Products
                                                 where p.ProductName.Equals(Product) && p.WarehouseID.Equals(warehouseID)
                                                 select p).FirstOrDefault();

                                    if (check != null)
                                    {
                                        if (!string.IsNullOrWhiteSpace(check.ToString()))
                                        {
                                            var unitsInStock = (from p in context.Products
                                                                where p.ProductName.Equals(Product) && p.WarehouseID.Equals(warehouseID)
                                                                select p).FirstOrDefault().UnitsInStock;
                                            if (unitsInStock < Int32.Parse(Quantity))
                                            {
                                                MessageBox.Show(String.Format("Unfortunately, warehouse {0} do not have {1} units of {2}. Trying to refill from other warehouses...", WarehouseID, Quantity, Product));
                                                int orderID = Int32.Parse(OrderID);
                                                TryRefillfromWarehouse(Product, Quantity, warehouseID, orderID, ClientName, Adress);
                                            }
                                            else
                                            {
                                                var rez = (from p in context.Products
                                                           where p.ProductName.Equals(Product)
                                                           select new
                                                {
                                                    rowID = p.RowID,
                                                    Price = p.UnitPrice,
                                                    prodID = p.ProductID
                                                }).ToList();

                                                int   quantity       = Int32.Parse(Quantity);
                                                float price          = float.Parse(rez[0].Price.ToString());
                                                Form  processingForm = new ProcessingOrder(OrderID, ClientName, Adress, Product, quantity, rez[0].rowID, price);
                                                processingForm.Show();
                                                int units   = Int32.Parse(Quantity);
                                                int orderID = Int32.Parse(OrderID);
                                                context.UpdateDB(Product, units, warehouseID);
                                                context.SaveChanges();
                                                context.MarkProcessed(orderID, prodID);
                                                context.SaveChanges();
                                                dbContextTransaction.Commit();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        int orderID = Int32.Parse(OrderID);
                                        MessageBox.Show(String.Format("Unfortunately, {0} warehouse do not have {1} units of {2}. Trying to refill from other warehouses...", WarehouseName, Quantity, Product));
                                        TryRefillfromWarehouse(Product, Quantity, warehouseID, orderID, ClientName, Adress);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message.ToString());
                                    dbContextTransaction.Rollback();
                                }
                            }
                        }
                    }
                }

                this.Close();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #23
0
        //при запуску форми - наповнення вмістом з БД
        private void AddEditProduct_Load(object sender, EventArgs e)
        {
            context = new WMSEntities();
            context.Configuration.LazyLoadingEnabled = false;
            //var query = context.Clients.OrderBy(p => p.ID);


            var query =
                from client in context.Clients
                select new
            {
                client.ID,
                client.Name,
            };

            clientsDataGridView.DataSource = query.ToList();

            query =
                from region in context.Regions
                select new
            {
                region.ID,
                region.Name,
            };

            regionDataGridView.DataSource = query.ToList();

            if (editMode)
            {
                int nID = int.Parse(IDText.Text);

                using (WMSEntities cont = new WMSEntities())
                {
                    var q =
                        from products in cont.Products
                        where products.ID == nID
                        select products;
                    Products first = q.ToList().First();
                    NameText.Text   = first.Name;
                    AmountText.Text = first.Amount.ToString();
                    WidthText.Text  = first.Width.ToString();
                    HeightText.Text = first.Height.ToString();
                    DepthText.Text  = first.Depth.ToString();

                    for (int i = 0; i < clientsDataGridView.RowCount; i++)
                    {
                        int nClientID = (int)clientsDataGridView[0, i].Value;
                        if (nClientID == first.ClientID)
                        {
                            clientsDataGridView[0, i].Selected = true;

                            break;
                        }
                    }

                    for (int i = 0; i < regionDataGridView.RowCount; i++)
                    {
                        int nRegionID = (int)regionDataGridView[0, i].Value;
                        if (nRegionID == first.RegionID)
                        {
                            regionDataGridView[0, i].Selected = true;

                            break;
                        }
                    }
                }
            }
        }
Пример #24
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);
            }
        }
Пример #25
0
        private void AddEditCell_Load(object sender, EventArgs e)
        {
            context = new WMSEntities();
            context.Configuration.LazyLoadingEnabled = false;
            //var query = context.Clients.OrderBy(p => p.ID);


            var query =
                from types in context.CellTypes
                select new
            {
                types.ID,
                types.Name,
            };

            clientsDataGridView.DataSource = query.ToList();

            query =
                from region in context.Regions
                select new
            {
                region.ID,
                region.Name,
            };

            regionDataGridView.DataSource = query.ToList();

            query =
                from ware in context.Warehouses
                select new
            {
                ware.ID,
                ware.Name,
            };

            warehoesesGridView.DataSource = query.ToList();

            if (editMode)
            {
                int nID = int.Parse(IDText.Text);

                using (WMSEntities cont = new WMSEntities())
                {
                    var q =
                        from cells in cont.Cells
                        where cells.ID == nID
                        select cells;

                    Cells first = q.ToList().First();
                    NameText.Text          = first.Name;
                    AmountText.Text        = first.Amount.ToString();
                    WidthText.Text         = first.Width.ToString();
                    HeightText.Text        = first.Height.ToString();
                    DepthText.Text         = first.Depth.ToString();
                    StillageText.Text      = first.Stillage.ToString();
                    TierText.Text          = first.Tier.ToString();
                    PositionText.Text      = first.Position.ToString();
                    SizeControlText.Text   = first.SizeControl.ToString();
                    AmountControlText.Text = first.AmountControl.ToString();



                    for (int i = 0; i < clientsDataGridView.RowCount; i++)
                    {
                        int nClientID = (int)clientsDataGridView[0, i].Value;
                        if (nClientID == first.TypeID)
                        {
                            clientsDataGridView[0, i].Selected = true;

                            break;
                        }
                    }

                    for (int i = 0; i < regionDataGridView.RowCount; i++)
                    {
                        int nRegionID = (int)regionDataGridView[0, i].Value;
                        if (nRegionID == first.RegionID)
                        {
                            regionDataGridView[0, i].Selected = true;

                            break;
                        }
                    }

                    for (int i = 0; i < warehoesesGridView.RowCount; i++)
                    {
                        int nWareID = (int)warehoesesGridView[0, i].Value;
                        if (nWareID == first.WarehouseID)
                        {
                            warehoesesGridView[0, i].Selected = true;

                            break;
                        }
                    }
                }
            }
        }
Пример #26
0
        private void btnReport_Click(object sender, EventArgs e)
        {
            try
            {
                if (gvCurrentSales.Rows.Count == 0)
                {
                    throw new Exception("Please select a warehouse and press 'See Current Sales' button!");
                }

                int WarehouseID = Int32.Parse(warehousesComboBox.SelectedItem.ToString());
                using (var contex = new WMSEntities())
                {
                    var queryResult = (from c in contex.CurrentSales
                                       join cd in contex.ClientOrderDetails on c.OrderID equals cd.OrderID
                                       where c.WarehouseID == WarehouseID & c.OrderID == cd.OrderID
                                       join p in contex.Products on cd.ProductID equals p.ProductID
                                       select new
                    {
                        Order = c.OrderID,
                        ProductName = p.ProductName,
                        Quantity = cd.Quantity,
                        Price = c.TotalPrice
                    }).Distinct().ToList();
                    var totalSum = (from c in contex.CurrentSales
                                    select c.TotalPrice).Sum();


                    Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

                    if (xlApp == null)
                    {
                        MessageBox.Show("Excel is not properly installed!!");
                        return;
                    }

                    Excel.Workbook  xlWorkBook;
                    Excel.Worksheet xlWorkSheet;
                    object          misValue = System.Reflection.Missing.Value;


                    xlWorkBook              = xlApp.Workbooks.Add(misValue);
                    xlWorkSheet             = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                    xlWorkSheet.Cells[1, 1] = "Sales report for warehouse " + WarehouseID.ToString();
                    xlWorkSheet.Cells[2, 1] = "Order ID";
                    xlWorkSheet.Cells[2, 2] = "Product name";
                    xlWorkSheet.Cells[2, 3] = "Quantity";
                    xlWorkSheet.Cells[2, 4] = "Price";

                    int i = 0;
                    for (i = 0; i < queryResult.Count; i++)
                    {
                        xlWorkSheet.Cells[i + 3, 1] = queryResult[i].Order;
                        xlWorkSheet.Cells[i + 3, 2] = queryResult[i].ProductName;
                        xlWorkSheet.Cells[i + 3, 3] = queryResult[i].Quantity;
                        xlWorkSheet.Cells[i + 3, 4] = queryResult[i].Price;
                    }

                    xlWorkSheet.Cells[i + 4, 1] = "Total sales for warehouse " + WarehouseID.ToString() + " are " + totalSum.ToString();
                    string FileNameAndPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\Sales Warehouse " + WarehouseID.ToString() + ".xls";
                    xlWorkBook.SaveAs(FileNameAndPath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                    xlWorkBook.Close(true, misValue, misValue);
                    xlApp.Quit();


                    Marshal.ReleaseComObject(xlWorkSheet);
                    Marshal.ReleaseComObject(xlWorkBook);
                    Marshal.ReleaseComObject(xlApp);



                    MessageBox.Show("Report in Excel format is created , you can find the file " + FileNameAndPath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #27
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();
                    }
                }
            }
        }