Exemplo n.º 1
0
        private void GridFill()
        {
            dataGridView1.ColumnCount        = 4;
            dataGridView1.Columns[0].Name    = "Parts Name";
            dataGridView1.Columns[1].Name    = "Batch Number";
            dataGridView1.Columns[2].Name    = "Amount";
            dataGridView1.Columns[3].Name    = "Order Item ID";
            dataGridView1.Columns[3].Visible = false;

            DataGridViewLinkColumn lnk = new DataGridViewLinkColumn()
            {
                HeaderText = "Action",
                Name       = "Remove",
                Text       = "Remove",
                UseColumnTextForLinkValue = true
            };

            dataGridView1.Columns.Add(lnk);


            using (var context = new Session4Entities())
            {
                #region populating Parts box
                var getParts = (from x in context.Parts
                                select x.Name);
                HashSet <string> parts = new HashSet <string>();
                foreach (var item in getParts)
                {
                    parts.Add(item);
                }
                partsBox.Items.AddRange(parts.ToArray());



                #endregion

                #region populating the Parts list with current values of parts of the order
                var getCurentparts = (from x in context.Orders
                                      where x.ID == _oID
                                      join y in context.OrderItems on x.ID equals y.OrderID
                                      join z in context.Parts on y.PartID equals z.ID
                                      select new { z.Name, y.BatchNumber, y.Amount, y.ID });
                foreach (var item in getCurentparts)
                {
                    List <string> vs = new List <string>()
                    {
                        item.Name, item.BatchNumber, item.Amount.ToString(), item.ID.ToString()
                    };
                    dataGridView1.Rows.Add(vs.ToArray());
                }
            }

            #endregion
        }
Exemplo n.º 2
0
 private void warehouseManagementToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var context = new Session4Entities())
     {
         var getNewID = (from x in context.Orders
                         orderby x.ID descending
                         select x.ID).First() + 1;
         (new WarehouseEdit(getNewID)).ShowDialog();
         GridFill();
     }
 }
Exemplo n.º 3
0
        private void InventoryReport_Load(object sender, EventArgs e)
        {
            List <string> warehouse = new List <string>();

            using (var context = new Session4Entities())
            {
                var warehouses = (from x in context.Warehouses
                                  select x.Name);
                foreach (var item in warehouses)
                {
                    warehouse.Add(item);
                }
            }
            warehouseBox.Items.AddRange(warehouse.ToArray());
        }
Exemplo n.º 4
0
        private void POEdit_Load(object sender, EventArgs e)
        {
            using (var context = new Session4Entities())
            {
                GridFill();
                #region populating Suppliers box
                var getSuppliers = (from x in context.Suppliers
                                    select x.Name);
                HashSet <string> suppliers = new HashSet <string>();
                foreach (var item in getSuppliers)
                {
                    suppliers.Add(item);
                }
                supplierBox.Items.AddRange(suppliers.ToArray());
                #endregion

                #region populating Warehouse box
                var getWarehouse = (from x in context.Warehouses
                                    select x.Name);
                HashSet <string> warehouse = new HashSet <string>();
                foreach (var item in getWarehouse)
                {
                    warehouse.Add(item);
                }
                warehouseBox.Items.AddRange(warehouse.ToArray());
                #endregion

                var check = (from x in context.Orders
                             where x.ID == _oID
                             select x).FirstOrDefault();

                #region Pre-popluating each drop-down with actual values of the specific order if Editing
                if (check != null)
                {
                    var getOrderMain = (from x in context.Orders
                                        where x.ID == _oID
                                        join y in context.Warehouses on x.DestinationWarehouseID equals y.ID
                                        join z in context.Suppliers on x.SupplierID equals z.ID
                                        select new { x.Date, Destination = y.Name, Suppliers = z.Name }).First();
                    date.Value = getOrderMain.Date;
                    warehouseBox.SelectedItem = getOrderMain.Destination;
                    supplierBox.SelectedItem  = getOrderMain.Suppliers;
                }
                #endregion
            }
        }
Exemplo n.º 5
0
        private void WarehouseEdit_Load(object sender, EventArgs e)
        {
            GridFill();
            using (var context = new Session4Entities())
            {
                #region populating Warehouse box
                var getWarehouse = (from x in context.Warehouses
                                    select x.Name);
                HashSet <string> source      = new HashSet <string>();
                HashSet <string> destination = new HashSet <string>();
                foreach (var item in getWarehouse)
                {
                    source.Add(item);
                    destination.Add(item);
                }
                sourceBox.Items.AddRange(source.ToArray());
                desBox.Items.AddRange(destination.ToArray());
                #endregion

                var check = (from x in context.Orders
                             where x.ID == _oID
                             select x).FirstOrDefault();
                if (check != null)
                {
                    #region Pre-popluating each drop-down with actual values of the specific order
                    var getOrderSource = (from x in context.Orders
                                          where x.ID == _oID
                                          join y in context.Warehouses on x.DestinationWarehouseID equals y.ID
                                          select new { x.Date, Destination = y.Name }).First();

                    var getOrderDes = (from x in context.Orders
                                       where x.ID == _oID
                                       join y in context.Warehouses on x.SourceWarehouseID equals y.ID
                                       select y.Name).First();

                    date.Value             = getOrderSource.Date;
                    sourceBox.SelectedItem = getOrderSource.Destination;
                    desBox.SelectedItem    = getOrderDes;
                    #endregion
                }
            }
        }
Exemplo n.º 6
0
        private void batchBox_Click(object sender, EventArgs e)
        {
            if (partsBox.SelectedItem != null)
            {
                batchBox.Items.Clear();
                using (var context = new Session4Entities())
                {
                    var getPartID = (from x in context.Parts
                                     where x.Name.Equals(partsBox.SelectedItem.ToString())
                                     select x.ID).First();

                    var getBatchNumber = (from x in context.OrderItems
                                          where x.PartID.Equals(getPartID)
                                          select x.BatchNumber);

                    HashSet <string> batchNumber = new HashSet <string>();
                    foreach (var item in getBatchNumber)
                    {
                        batchNumber.Add(item);
                    }
                    batchBox.Items.AddRange(batchNumber.ToArray());
                }
            }
        }
Exemplo n.º 7
0
        private void currentStock_CheckedChanged(object sender, EventArgs e)
        {
            using (var context = new Session4Entities())
            {
                if (warehouseBox.SelectedItem != null)
                {
                    var getWarehouseID = (from x in context.Warehouses
                                          where x.Name.Equals(warehouseBox.SelectedItem.ToString())
                                          select x.ID).First();


                    var getPartsCurrent = (from x in context.OrderItems
                                           where x.Order.DestinationWarehouseID == getWarehouseID
                                           where x.Order.TransactionTypeID == 1
                                           select x);


                    gridFill();

                    foreach (var item in getPartsCurrent.Select(x => x.Part.Name).Distinct())
                    {
                        var getPartAmt = (from x in context.OrderItems
                                          where x.Order.DestinationWarehouseID == getWarehouseID
                                          where x.Order.TransactionTypeID == 1
                                          where x.Part.Name == item
                                          select x.Amount).Sum();

                        var checkBatch = (from x in context.OrderItems
                                          where x.Part.Name == item
                                          select x.Part.BatchNumberHasRequired).FirstOrDefault();

                        var getID = (from x in context.OrderItems
                                     where x.Part.Name == item
                                     select x.PartID).First();

                        if (checkBatch == true)
                        {
                            List <string> vs = new List <string>()
                            {
                                item, getPartAmt.ToString(), "View Batch Numbers", getID.ToString()
                            };

                            result.Rows.Add(vs.ToArray());
                        }

                        else
                        {
                            List <string> vs = new List <string>()
                            {
                                item, getPartAmt.ToString(), "", getID.ToString()
                            };

                            result.Rows.Add(vs.ToArray());
                        }
                    }

                    foreach (DataGridViewRow item in result.Rows)
                    {
                        if (item.Cells[2].Value.ToString() == "View Batch Numbers")
                        {
                            item.Cells[2].Style.ForeColor = Color.Blue;
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void result_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                var getRowIndex = e.RowIndex;
                if (e.ColumnIndex == 2)
                {
                    var getPartID = Convert.ToInt64(result.Rows[e.RowIndex].Cells[3].Value);
                    using (var context = new Session4Entities())
                    {
                        if (result.Rows[e.RowIndex].Cells[2].Value.ToString() == "View Batch Numbers" && currentStock.Checked)
                        {
                            var getWarehouseID = (from x in context.Warehouses
                                                  where x.Name.Equals(warehouseBox.SelectedItem.ToString())
                                                  select x.ID).First();

                            var getBatch = (from x in context.OrderItems
                                            where x.PartID == getPartID
                                            where x.Order.TransactionTypeID == 1 && x.Order.DestinationWarehouseID == getWarehouseID
                                            select x);

                            List <string> message = new List <string>();
                            foreach (var item in getBatch)
                            {
                                message.Add($"The amount for this batch item of {item.BatchNumber} is: {item.Amount}");
                            }
                            var m = string.Join("\n", message);
                            MessageBox.Show(m, "Batch Numbers", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }

                        else if (result.Rows[e.RowIndex].Cells[2].Value.ToString() == "View Batch Numbers" && receivedStock.Checked)
                        {
                            var getWarehouseID = (from x in context.Warehouses
                                                  where x.Name.Equals(warehouseBox.SelectedItem.ToString())
                                                  select x.ID).First();

                            var getBatch = (from x in context.OrderItems
                                            where x.PartID == getPartID
                                            where x.Order.TransactionTypeID == 2 && x.Order.DestinationWarehouseID == getWarehouseID
                                            select x);

                            List <string> message = new List <string>();
                            foreach (var item in getBatch)
                            {
                                message.Add($"The amount for this batch item of {item.BatchNumber} is: {item.Amount}");
                            }
                            var m = string.Join("\n", message);
                            MessageBox.Show(m, "Batch Numbers", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }

                        else if (result.Rows[e.RowIndex].Cells[2].Value.ToString() == "View Batch Numbers" && outOfStock.Checked)
                        {
                            var getWarehouseID = (from x in context.Warehouses
                                                  where x.Name.Equals(warehouseBox.SelectedItem.ToString())
                                                  select x.ID).First();

                            var getBatch = (from x in context.OrderItems
                                            where x.PartID == getPartID
                                            where x.Order.TransactionTypeID == 2 && x.Order.SourceWarehouseID == getWarehouseID
                                            select x);



                            List <string> message = new List <string>();
                            foreach (var item in getBatch)
                            {
                                message.Add($"The amount for this batch item of {item.BatchNumber} is: {item.Amount}");
                            }
                            var m = string.Join("\n", message);
                            MessageBox.Show(m, "Batch Numbers", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        private void GridFill()
        {
            list.ColumnCount        = 8;
            list.Columns[0].Name    = "Part Name";
            list.Columns[1].Name    = "Transaction Type";
            list.Columns[2].Name    = "Date";
            list.Columns[3].Name    = "Amount";
            list.Columns[4].Name    = "Source";
            list.Columns[5].Name    = "Destination";
            list.Columns[6].Name    = "Order ID";
            list.Columns[7].Name    = "Order Item ID";
            list.Columns[6].Visible = false;
            list.Columns[7].Visible = false;
            list.Rows.Clear();
            list.Update();
            list.Refresh();

            DataGridViewLinkColumn lnkEdit = new DataGridViewLinkColumn()
            {
                HeaderText = "Action",
                Name       = "Edit",
                Text       = "Edit",
                UseColumnTextForLinkValue = true
            };

            DataGridViewLinkColumn lnkRemove = new DataGridViewLinkColumn()
            {
                HeaderText = "Action",
                Name       = "Remove",
                Text       = "Remove",
                UseColumnTextForLinkValue = true
            };

            list.Columns.AddRange(lnkEdit, lnkRemove);

            using (var context = new Session4Entities())
            {
                var getOrder = (from x in context.Orders
                                join y in context.OrderItems on x.ID equals y.OrderID
                                join z in context.Parts on y.PartID equals z.ID
                                join a in context.TransactionTypes on x.TransactionTypeID equals a.ID
                                orderby x.Date descending
                                select new { z.Name, Transaction = a.Name, x.Date, y.Amount, x.ID, OrderItemID = y.ID, x.SourceWarehouseID, x.DestinationWarehouseID });

                foreach (var item in getOrder)
                {
                    var getSourceWarehouse = (from x in context.Warehouses
                                              where x.ID == item.SourceWarehouseID
                                              select x.Name).FirstOrDefault();

                    var getDestinationWarehouse = (from x in context.Warehouses
                                                   where x.ID == item.DestinationWarehouseID
                                                   select x.Name).FirstOrDefault();

                    List <string> vs = new List <string>()
                    {
                        item.Name, item.Transaction, item.Date.ToString("yyyy/MM/dd"), item.Amount.ToString(),
                        getSourceWarehouse, getDestinationWarehouse, item.ID.ToString(), item.OrderItemID.ToString()
                    };

                    list.Rows.Add(vs.ToArray());
                }

                foreach (DataGridViewRow item in list.Rows)
                {
                    var transactionType = (item.Cells[1].Value).ToString();
                    if (transactionType == "Purchase Order")
                    {
                        item.Cells[3].Style.BackColor = Color.LightGreen;
                    }
                }
            }
        }
Exemplo n.º 10
0
        private void list_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                var getRowIndex = list.Rows[e.RowIndex].Cells[e.ColumnIndex].RowIndex;

                if (list.Rows[e.RowIndex].Cells[e.ColumnIndex].ColumnIndex == 9)
                {
                    var result = MessageBox.Show("Are you sure you want to delete this record?", "Delete",
                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (result == DialogResult.Yes)
                    {
                        var getOrderItemID = Convert.ToInt64(list.Rows[e.RowIndex].Cells[7].Value);
                        var partName       = list.Rows[e.RowIndex].Cells[0].Value.ToString();
                        using (var context = new Session4Entities())
                        {
                            var findPart = (from x in context.Parts
                                            where x.Name.Equals(partName)
                                            select new { x.ID, x.MinimumAmount }).First();

                            var findAmountTotal = (from x in context.OrderItems
                                                   where x.PartID.Equals(findPart.ID)
                                                   select x.Amount).Sum();

                            if ((findAmountTotal - Convert.ToDecimal(list.Rows[e.RowIndex].Cells[3].Value)) > findPart.MinimumAmount)
                            {
                                var toDelete = (from x in context.OrderItems
                                                where x.ID == getOrderItemID
                                                select x).First();
                                context.OrderItems.Remove(toDelete);
                                context.SaveChanges();
                                list.Rows.RemoveAt(getRowIndex);
                                GridFill();
                            }

                            else
                            {
                                MessageBox.Show("Unable to delete item. Item does not even hit minimum required amount in all warehouses combined!",
                                                "Item amount is below required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }

                else if (list.Rows[e.RowIndex].Cells[e.ColumnIndex].ColumnIndex == 8)
                {
                    if (list.Rows[e.RowIndex].Cells[1].Value.ToString() == "Purchase Order")
                    {
                        var getOrderID = Convert.ToInt64(list.Rows[e.RowIndex].Cells[6].Value);
                        (new POEdit(getOrderID)).ShowDialog();
                        GridFill();
                    }
                    else if (list.Rows[e.RowIndex].Cells[1].Value.ToString() == "Warehouse Management")
                    {
                        var getOrderID = Convert.ToInt64(list.Rows[e.RowIndex].Cells[6].Value);
                        (new WarehouseEdit(getOrderID)).ShowDialog();
                        GridFill();
                    }
                }
            }
        }
Exemplo n.º 11
0
        private void submit_Click(object sender, EventArgs e)
        {
            using (var context = new Session4Entities())
            {
                var checkCurrect = (from x in context.Orders
                                    where x.ID == _oID
                                    select x).FirstOrDefault();

                var getDestination = (from x in context.Warehouses
                                      where x.Name.Equals(warehouseBox.SelectedItem.ToString())
                                      select x.ID).First();

                var getSupplierID = (from x in context.Suppliers
                                     where x.Name.Equals(supplierBox.SelectedItem.ToString())
                                     select x.ID).First();

                if (checkCurrect != null)
                {
                    var getCurentparts = (from x in context.OrderItems
                                          where x.OrderID == _oID
                                          select x);

                    foreach (var item in getCurentparts)
                    {
                        context.OrderItems.Remove(item);
                    }


                    var currentOrder = (from x in context.Orders
                                        where x.ID.Equals(_oID)
                                        select new { x }).First();



                    currentOrder.x.SupplierID             = getSupplierID;
                    currentOrder.x.Date                   = date.Value;
                    currentOrder.x.DestinationWarehouseID = getDestination;
                }

                else
                {
                    context.Orders.Add(new Order()
                    {
                        Date = date.Value,
                        SourceWarehouseID      = null,
                        DestinationWarehouseID = getDestination,
                        SupplierID             = getSupplierID,
                        TransactionTypeID      = 1,
                        ID = _oID
                    });
                }

                var getRows = dataGridView1.RowCount;

                if (getRows > 0)
                {
                    foreach (DataGridViewRow item in dataGridView1.Rows)
                    {
                        var getPartName = item.Cells[0].Value.ToString();
                        var findPartID  = (from x in context.Parts
                                           where x.Name.Equals(getPartName)
                                           select x.ID).First();
                        context.OrderItems.Add(new OrderItem()
                        {
                            OrderID     = _oID,
                            Amount      = Convert.ToDecimal(item.Cells[2].Value),
                            BatchNumber = item.Cells[1].Value.ToString(),
                            PartID      = findPartID
                        });
                    }
                    context.SaveChanges();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Please insert at least 1 part into the purchase order!", "Purchase Order empty",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
Exemplo n.º 12
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            using (var context = new Session4Entities())
            {
                var selectedPart = partsBox.SelectedItem.ToString();
                var findPartID   = (from x in context.Parts
                                    where x.Name.Equals(selectedPart)
                                    select new { x.ID, x.MinimumAmount, x.BatchNumberHasRequired }).First();

                var getCurrentAmount = (from x in context.OrderItems
                                        where x.PartID == findPartID.ID
                                        select x.Amount).Sum();

                var boolcheck = true;
                foreach (DataGridViewRow item in dataGridView1.Rows)
                {
                    if (selectedPart.Equals(item.Cells[0].Value.ToString()))
                    {
                        MessageBox.Show("Cannot add duplicate parts. Please delete and add the part with correct intended total amount!",
                                        "Duplicate record", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        boolcheck = false;
                    }
                }

                if (boolcheck)
                {
                    if ((batchBox.Text == "".Trim()) && (findPartID.BatchNumberHasRequired == true))
                    {
                        MessageBox.Show("A batch number is required for the intended part to add!", "Missing batch number",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        try
                        {
                            var currentTotal = (getCurrentAmount + decimal.Parse(amountBox.Text));
                            if (decimal.Parse(amountBox.Text) <= 0)
                            {
                                MessageBox.Show("Please enter a positive value!", "Invalid amount",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else if (currentTotal < findPartID.MinimumAmount)
                            {
                                MessageBox.Show($"Minimum amout of intended part needed is {findPartID.MinimumAmount}. Total after addition of intended part is {currentTotal}.",
                                                "Insufficient parts for warehouse!", MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                            }
                            else
                            {
                                List <string> vs = new List <string>()
                                {
                                    partsBox.SelectedItem.ToString(),
                                              batchBox.Text,
                                              amountBox.Text
                                };
                                dataGridView1.Rows.Add(vs.ToArray());
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Please enter a valid number for amount!", "Invalid amount",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            using (var context = new Session4Entities())
            {
                var selectedPart    = partsBox.SelectedItem.ToString();
                var sourceWarehouse = sourceBox.SelectedItem.ToString();

                var findSourceID = (from x in context.Warehouses
                                    where x.Name.Equals(sourceWarehouse)
                                    select x.ID).First();

                var findPartID = (from x in context.Parts
                                  where x.Name.Equals(selectedPart)
                                  select new { x.ID, x.MinimumAmount, x.BatchNumberHasRequired }).First();

                var findSourcePart = (from x in context.Orders
                                      where x.SourceWarehouseID == findSourceID
                                      join y in context.OrderItems on x.ID equals y.OrderID
                                      where y.PartID == findPartID.ID
                                      select y);

                var boolcheck = true;
                foreach (DataGridViewRow item in dataGridView1.Rows)
                {
                    if (selectedPart.Equals(item.Cells[0].Value.ToString()))
                    {
                        MessageBox.Show("Cannot add duplicate parts. Please delete and add the part with correct intended total amount!",
                                        "Duplicate record", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        boolcheck = false;
                    }
                }


                if (boolcheck)
                {
                    if ((batchBox.Text == "".Trim()) && (findPartID.BatchNumberHasRequired == true))
                    {
                        MessageBox.Show("A batch number is required for the intended part to add!", "Missing batch number",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        try
                        {
                            var getSourceAmount = (from x in context.Orders
                                                   where x.SourceWarehouseID == findSourceID
                                                   join y in context.OrderItems on x.ID equals y.OrderID
                                                   where y.PartID == findPartID.ID
                                                   select y.Amount).Sum();

                            var getDestination = (from x in context.Warehouses
                                                  where x.Name.Equals(desBox.SelectedItem.ToString())
                                                  select x.ID).First();

                            var getSource = (from x in context.Warehouses
                                             where x.Name.Equals(sourceBox.SelectedItem.ToString())
                                             select x.ID).First();

                            var currentTotal = (getSourceAmount - decimal.Parse(amountBox.Text));
                            if (decimal.Parse(amountBox.Text) <= 0)
                            {
                                MessageBox.Show("Please enter a positive value!", "Invalid amount",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else if (currentTotal < 0)
                            {
                                MessageBox.Show($"Attempted transaction on intended part will set the Source Warehouse value of intended part to be negative! Current amount in Source Warehouse is {getSourceAmount}.",
                                                "Insufficient parts for warehouse!", MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                            }

                            else if (getSource == getDestination)
                            {
                                MessageBox.Show("Source warehouse cannot be the same as Destination warehouse!", "Warehouse is the same!",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }

                            else
                            {
                                List <string> vs = new List <string>()
                                {
                                    partsBox.SelectedItem.ToString(),
                                              batchBox.Text,
                                              amountBox.Text
                                };
                                dataGridView1.Rows.Add(vs.ToArray());
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Please enter a valid number. If this problem still persist, the source warehouse may not have a record of intended part!", "Invalid amount",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }