private void Save()
        {
            if (tbQty.Value <= 0)
            {
                MessageBox.Show("Enter Quantity");

                tbQty.Value = 0;

                tbQty.Focus();
            }
            else if (!recDate.SelectedDate.HasValue)
            {
                MessageBox.Show("Purchased date is required");
                recDate.Focus();
            }
            else
            {
                int?maxCount = dbContext.tbl_BoxSeries.Where(p => p.BoxCode == _boxCode).Select(p => p.SeriesNo).DefaultIfEmpty(0).Max();

                int count = maxCount.GetValueOrDefault() + 1;

                if (maxCount.GetValueOrDefault() == 0)
                {
                    for (int i = count; i <= tbQty.Value; i++)
                    {
                        //MessageBox.Show(i.ToString());

                        tbl_BoxSeries _tb2 = new tbl_BoxSeries()
                        {
                            BoxCode = _boxCode,

                            SeriesNo = i,

                            IsDisposed = false,

                            IsUsed = false,

                            IsDelivered = false,

                            IsReturned = false,

                            IsIssuedToProduction = false,

                            IsIssuedToWareHouse = false,

                            EncodedBy = _name,

                            DateEncoded = DateTime.Now
                        };

                        dbContext.tbl_BoxSeries.Add(_tb2);


                        tbl_PurchasedHistory tbldata = new tbl_PurchasedHistory()
                        {
                            ItemCode      = _boxCode + "-" + i.ToString(),
                            DatePurchased = recDate.SelectedDate.Value
                        };

                        dbContext.tbl_PurchasedHistory.Add(tbldata);
                    }

                    dbContext.SaveChanges();
                }
                else
                {
                    for (int i = maxCount.GetValueOrDefault() + 1; i <= maxCount.GetValueOrDefault() + tbQty.Value; i++)
                    {
                        tbl_BoxSeries _tb2 = new tbl_BoxSeries()
                        {
                            BoxCode = _boxCode,

                            SeriesNo = i,

                            IsDisposed = false,

                            IsUsed = false,

                            IsDelivered = false,

                            IsReturned = false,

                            IsIssuedToProduction = false,

                            IsIssuedToWareHouse = false,

                            EncodedBy = _name,

                            DateEncoded = DateTime.Now
                        };

                        dbContext.tbl_BoxSeries.Add(_tb2);


                        tbl_PurchasedHistory tbldata = new tbl_PurchasedHistory()
                        {
                            ItemCode      = _boxCode + "-" + i.ToString(),
                            DatePurchased = recDate.SelectedDate.Value
                        };

                        dbContext.tbl_PurchasedHistory.Add(tbldata);
                    }

                    dbContext.SaveChanges();
                }

                var a = from data in dbContext.tbl_BoxMaster
                        join boxSeries in dbContext.tbl_BoxSeries on data.BoxCode equals boxSeries.BoxCode
                        into UP
                        from boxSeries in UP.DefaultIfEmpty()
                        where data.BoxCode == _boxCode
                        orderby boxSeries.SeriesNo

                        select new
                {
                    BoxCode              = data.BoxCode,
                    SeriesNo             = boxSeries.SeriesNo,
                    IsDisposed           = boxSeries.IsDisposed,
                    IsUsed               = boxSeries.IsUsed,
                    IsIssuedToProduction = boxSeries.IsIssuedToProduction,
                    IsIssuedToWareHouse  = boxSeries.IsIssuedToWareHouse,
                    IsDelivered          = boxSeries.IsDelivered,
                    IsReturned           = boxSeries.IsReturned,
                    BoxSeriesCode        = boxSeries.BoxCode + "-" + boxSeries.SeriesNo
                };

                string empname = string.Empty;

                var empdata = dbHRIS.SKPI_GetAllEmployeesByEmpID(_empID).ToList();

                foreach (DataRow dr in ConvertToDataTable(empdata).Rows)
                {
                    empname = dr["FullName_LnameFirst"].ToString();
                }

                tbl_TransactionMaster transact = new tbl_TransactionMaster()
                {
                    TransactBy         = empname,
                    TransactionDetails = "Encoded New Box Series Quantity",
                    CreationDateTime   = DateTime.Now
                };

                dbContext.tbl_TransactionMaster.Add(transact);

                dbContext.SaveChanges();

                MessageBox.Show("Quantity successfully added");

                tbQty.Value = 0;

                tbQty.Focus();

                LoadData();
            }
        }
Exemple #2
0
        private void TbCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                try
                {
                    bool isexists = dbContext.tbl_BoxSeries.Any(x => x.BoxCode + "-" + x.SeriesNo.ToString() == tbCode.Text.Trim() && x.IsUsed == true && x.IsIssuedToProduction == false &&
                                                                x.IsIssuedToWareHouse == false && x.IsDelivered == false && x.IsReturned == false && x.IsDisposed == false);

                    if (isexists)
                    {
                        var a = dbContext.tbl_BoxSeries.Where(x => x.BoxCode + "-" + x.SeriesNo.ToString() == tbCode.Text.Trim()).FirstOrDefault();

                        tbl_BoxSeries tbl = a as tbl_BoxSeries;

                        tbl.IsIssuedToProduction = true;

                        tbl.IsIssuedToWareHouse = false;

                        tbl.IsDelivered = false;

                        tbl.IsReturned = false;

                        dbContext.Entry(tbl).State = System.Data.Entity.EntityState.Modified;

                        dbContext.SaveChanges();



                        string empname = string.Empty;

                        var empdata = dbHRIS.SKPI_GetAllEmployeesByEmpID(_empID).ToList();

                        foreach (DataRow dr in ConvertToDataTable(empdata).Rows)
                        {
                            empname = dr["FullName_LnameFirst"].ToString();
                        }

                        tbl_TransactionMaster transact = new tbl_TransactionMaster()
                        {
                            TransactBy         = empname,
                            TransactionDetails = "Issued Item: " + tbCode.Text.Trim(),
                            CreationDateTime   = DateTime.Now
                        };

                        dbContext.tbl_TransactionMaster.Add(transact);

                        dbContext.SaveChanges();


                        tbCode.Clear();
                        //tbCode.Focus();

                        LoadData();
                    }
                    else
                    {
                        var b = dbContext.tbl_PartitionSeries.Where(x => x.PartitionCode + "-" + x.Part_SeriesNo.ToString() == tbCode.Text.Trim()).FirstOrDefault();

                        tbl_PartitionSeries tbl = b as tbl_PartitionSeries;

                        tbl.IsIssuedToProduction = true;

                        tbl.IsIssuedToWareHouse = false;

                        tbl.IsDelivered = false;

                        tbl.IsReturned = false;

                        dbContext.Entry(tbl).State = System.Data.Entity.EntityState.Modified;

                        dbContext.SaveChanges();


                        string empname = string.Empty;

                        var empdata = dbHRIS.SKPI_GetAllEmployeesByEmpID(_empID).ToList();

                        foreach (DataRow dr in ConvertToDataTable(empdata).Rows)
                        {
                            empname = dr["FullName_LnameFirst"].ToString();
                        }

                        tbl_TransactionMaster transact = new tbl_TransactionMaster()
                        {
                            TransactBy         = empname,
                            TransactionDetails = "Issued Item: " + tbCode.Text.Trim(),
                            CreationDateTime   = DateTime.Now
                        };

                        dbContext.tbl_TransactionMaster.Add(transact);

                        dbContext.SaveChanges();


                        tbCode.Clear();
                        //tbCode.Focus();

                        LoadData();
                    }
                }
                catch
                {
                    if (gridBox.Items.Count == 0 && gridPartition.Items.Count == 0)
                    {
                        divIssuance.IsEnabled = true;
                        tbCode.Clear();
                        tbQty.Value = 0;
                        tbQty.Focus();
                    }
                    else
                    {
                        divIssuance.IsEnabled = false;
                        tbQty.Value           = 0;
                        tbCode.Clear();
                        tbCode.Focus();
                    }
                }
            }
        }
Exemple #3
0
        private void Issue()
        {
            var a = dbContext.tbl_BoxMaster.Where(t => t.BoxCode == _boxcode).FirstOrDefault();

            tbl_BoxMaster _tb = a as tbl_BoxMaster;

            _usage = _tb.UsagePerBox.GetValueOrDefault();

            var countInventory = dbContext.tbl_BoxSeries.Count(p => p.BoxCode == _boxcode && p.IsUsed == false);

            var countInventory_Partition = dbContext.tbl_PartitionSeries.Count(p => p.BoxCode == _boxcode && p.IsUsed == false);


            int QtyInStock_Box       = countInventory;
            int QtyInStock_Partition = countInventory_Partition;
            int neededBox            = Convert.ToInt32(tbQty.Value);
            int neededPartition      = neededBox * _usage;


            if (QtyInStock_Box >= neededBox)
            {
                if (QtyInStock_Partition >= neededPartition)
                {
                    IssueBox(neededBox);

                    IssuePartition(neededPartition);

                    LoadData();
                    tbQty.Value = 0;

                    string empname = string.Empty;

                    var empdata = dbHRIS.SKPI_GetAllEmployeesByEmpID(_empID).ToList();

                    foreach (DataRow dr in ConvertToDataTable(empdata).Rows)
                    {
                        empname = dr["FullName_LnameFirst"].ToString();
                    }

                    tbl_TransactionMaster transact = new tbl_TransactionMaster()
                    {
                        TransactBy         = empname,
                        TransactionDetails = "Preparing for Box Issuance",
                        CreationDateTime   = DateTime.Now
                    };

                    dbContext.tbl_TransactionMaster.Add(transact);

                    dbContext.SaveChanges();

                    MessageBox.Show("Records Ready For Scanning");
                }
                else
                {
                    int boxtogive = QtyInStock_Partition / _usage;

                    int partitionToGive = boxtogive * _usage;

                    IssueBox(boxtogive);

                    IssuePartition(partitionToGive);

                    LoadData();
                    tbQty.Value = 0;

                    string empname = string.Empty;

                    var empdata = dbHRIS.SKPI_GetAllEmployeesByEmpID(_empID).ToList();

                    foreach (DataRow dr in ConvertToDataTable(empdata).Rows)
                    {
                        empname = dr["FullName_LnameFirst"].ToString();
                    }

                    tbl_TransactionMaster transact = new tbl_TransactionMaster()
                    {
                        TransactBy         = empname,
                        TransactionDetails = "Preparing for Box Issuance",
                        CreationDateTime   = DateTime.Now
                    };

                    dbContext.tbl_TransactionMaster.Add(transact);

                    dbContext.SaveChanges();

                    MessageBox.Show("Records Ready For Scanning");
                }
            }
            else if (QtyInStock_Box < neededBox && QtyInStock_Box > 0)
            {
                int boxtogive = QtyInStock_Box;

                int partitionToGive = boxtogive * _usage;

                IssueBox(boxtogive);

                IssuePartition(partitionToGive);

                LoadData();
                tbQty.Value = 0;

                string empname = string.Empty;

                var empdata = dbHRIS.SKPI_GetAllEmployeesByEmpID(_empID).ToList();

                foreach (DataRow dr in ConvertToDataTable(empdata).Rows)
                {
                    empname = dr["FullName_LnameFirst"].ToString();
                }

                tbl_TransactionMaster transact = new tbl_TransactionMaster()
                {
                    TransactBy         = empname,
                    TransactionDetails = "Preparing for Box Issuance",
                    CreationDateTime   = DateTime.Now
                };

                dbContext.tbl_TransactionMaster.Add(transact);

                dbContext.SaveChanges();

                MessageBox.Show("Records Ready For Scanning");
            }

            else
            {
                MessageBox.Show("Cannot issue box. No available stocks");
                LoadData();
                tbQty.Value = 0;
            }



            //if (countInventory >= Convert.ToInt32(tbQty.Value))
            //{
            //    //Count Box
            //    int QtyInStock = countInventory;
            //    int neededQty = Convert.ToInt32(tbQty.Value);

            //    int div = QtyInStock / neededQty; //quotient
            //    int mod = QtyInStock % neededQty; //remainder

            //    //Check Partition
            //    //Needed Partition
            //    int totalPartition = QtyInStock * _usage;

            //    //Count Partition
            //    var countInventory_Partition = dbContext.tbl_PartitionSeries.Count(p => p.BoxCode == _boxcode && p.IsUsed == false);

            //    int divPartition = countInventory_Partition / totalPartition; //quotient
            //    int modPartition = countInventory_Partition % totalPartition; //remainder


            //    //If stock partition is greater than the quantity needed
            //    if (countInventory_Partition > totalPartition)
            //    {
            //        //if (modPartition > 0)
            //        //{
            //        //MessageBoxResult results = MessageBox.Show("Cannot issue some partitions." + Environment.NewLine
            //        //    + "Total Box To Be Issued: " + QtyInStock + Environment.NewLine
            //        //    + "Total Partitions To Be Issued: " + divPartition + Environment.NewLine
            //        //    //+ "Remaining Quantity From Needed Quantity: " + modPartition.ToString().Trim() + Environment.NewLine
            //        //    + "Do you want to continue?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            //        //if (results == MessageBoxResult.Yes)
            //        //{
            //        //    // Do this
            //        //    //Set As Issued
            //        //    var dataBox = dbContext.tbl_BoxSeries.Where(p => p.BoxCode == _boxcode && p.IsUsed == false).Take(QtyInStock).ToList();

            //        //    dataBox.ForEach(p => p.IsUsed = true);

            //        //    dbContext.SaveChanges();


            //        //    //Set as Issued
            //        //    var dataPartition = dbContext.tbl_PartitionSeries.Where(p => p.BoxCode == _boxcode && p.IsUsed == false).Take(divPartition).ToList();

            //        //    dataBox.ForEach(p => p.IsUsed = true);

            //        //    dbContext.SaveChanges();

            //        //    MessageBox.Show("Record Successfully Saved");
            //        //}

            //        //}
            //        //else
            //        //{

            //        // Do this
            //        //Set As Issued
            //        IssueBox(QtyInStock);

            //        //Set as Issued
            //        IssuePartition(totalPartition);

            //        MessageBox.Show("Record Successfully Saved");
            //        //}
            //    }
            //    else
            //    {
            //        int boxToBeFilled = countInventory_Partition / _usage;

            //        int partTogive = boxToBeFilled * _usage;

            //        MessageBoxResult result = MessageBox.Show("The remaining partitions will no longer be sufficient to fill the required quantity? " +
            //            "Needed Partition: " + totalPartition.ToString().Trim() + Environment.NewLine +
            //            "Remaining Partition: " + countInventory_Partition.ToString().Trim() + Environment.NewLine +
            //            "Boxes To Be Filled By Remaining Quantity: " + boxToBeFilled.ToString().Trim() + Environment.NewLine +
            //            "Do you want to continue?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            //        if (result == MessageBoxResult.Yes)
            //        {
            //            // Do this
            //            //Set As Issued
            //            IssueBox(boxToBeFilled);

            //            //Set as Issued
            //            IssuePartition(partTogive);
            //        }
            //    }

            //}
            //else if (countInventory == 0)
            //{
            //    MessageBox.Show("Cannot issue box. No available stocks");
            //    tbQty.Value = 0;
            //}
            //else
            //{
            //    //Count Box
            //    var countInventoryRemaining = dbContext.tbl_BoxSeries.Count(p => p.BoxCode == _boxcode && p.IsUsed == false);

            //    MessageBoxResult result = MessageBox.Show("Needed quantity is more than the stock boxes? " + Environment.NewLine +
            //        "Needed Quantity: " + tbQty.Value.ToString().Trim() + Environment.NewLine +
            //        "Remaining Quantity: " + countInventoryRemaining.ToString().Trim() + Environment.NewLine +
            //        "Do you want to continue?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            //    if (result == MessageBoxResult.Yes)
            //    {
            //        //Check Partition
            //        //Needed Partition
            //        int totalPartition = countInventoryRemaining * _usage;

            //        //Count Partition
            //        var countInventory_Partition = dbContext.tbl_PartitionSeries.Count(p => p.BoxCode == _boxcode && p.IsUsed == false);

            //        int divPartition = countInventory_Partition / totalPartition; //quotient
            //        int modPartition = countInventory_Partition % totalPartition; //remainder

            //        //If stock partition is greater than the quantity needed
            //        if (countInventory_Partition > totalPartition)
            //        {
            //            if (modPartition > 0)
            //            {
            //                MessageBoxResult results = MessageBox.Show("Cannot issue some partitions." + Environment.NewLine
            //                    + "Total Box To Be Issued: " + countInventoryRemaining + Environment.NewLine
            //                    + "Total Partitions To Be Issued: " + divPartition + Environment.NewLine
            //                    + "Remaining Quantity From Needed Quantity: " + modPartition.ToString().Trim() + Environment.NewLine
            //                    + "Do you want to continue?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            //                if (results == MessageBoxResult.Yes)
            //                {
            //                    // Do this
            //                    //Set As Issued
            //                    IssueBox(countInventoryRemaining);

            //                    //Set as Issued
            //                    IssuePartition(divPartition);

            //                    MessageBox.Show("Record Successfully Saved");
            //                }
            //            }
            //            else
            //            {
            //                // Do this
            //                //Set As Issued
            //                IssueBox(countInventoryRemaining);

            //                //Set as Issued
            //                IssuePartition(divPartition);


            //                MessageBox.Show("Record Successfully Saved");
            //            }
            //        }
            //        else
            //        {
            //            if (_usage < divPartition)
            //            {
            //                MessageBox.Show("Cannot Issue Box");
            //            }
            //            else
            //            {
            //                int boxToBeFilled = countInventory_Partition / _usage;

            //                int partTogive = boxToBeFilled * _usage;

            //                if (boxToBeFilled >= countInventoryRemaining && boxToBeFilled != 0)
            //                {
            //                    MessageBoxResult result3 = MessageBox.Show("The remaining partitions will no longer be sufficient to fill the required quantity? " +
            //                        "Needed Partition: " + totalPartition.ToString().Trim() + Environment.NewLine +
            //                        "Remaining Partition: " + countInventory_Partition.ToString().Trim() + Environment.NewLine +
            //                        "Boxes To Be Filled By Remaining Quantity: " + boxToBeFilled.ToString().Trim() + Environment.NewLine +
            //                        "Do you want to continue?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            //                    if (result3 == MessageBoxResult.Yes)
            //                    {
            //                        // Do this
            //                        //Set As Issued
            //                        IssueBox(boxToBeFilled);

            //                        //Set as Issued
            //                        IssuePartition(partTogive);
            //                    }
            //                }
            //                else
            //                {
            //                    MessageBox.Show("Cannot Issue Box");
            //                }
            //            }
            //        }
            //    }
            //}
        }
        private void RadButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Do you want to continue?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                if (!recDate.SelectedDate.HasValue || string.IsNullOrEmpty(tbItemCode.Text))
                {
                    MessageBox.Show("Please complete all fields");
                }
                else
                {
                    bool isexists = dbContext.tbl_BoxSeries.Any(x => x.BoxCode + "-" + x.SeriesNo.ToString() == tbItemCode.Text.Trim());

                    if (isexists)
                    {
                        var a = dbContext.tbl_BoxSeries.Where(x => x.BoxCode + "-" + x.SeriesNo.ToString() == tbItemCode.Text.Trim()).FirstOrDefault();

                        tbl_BoxSeries tbl = a as tbl_BoxSeries;

                        tbl.IsDisposed = true;

                        tbl.ModifiedBy = _name;

                        tbl.DateModified = DateTime.Now;

                        dbContext.Entry(tbl).State = System.Data.Entity.EntityState.Modified;

                        dbContext.SaveChanges();

                        tbl_DisposalHistory dataDisposal = new tbl_DisposalHistory()
                        {
                            ItemCode     = tbItemCode.Text,
                            QtyDisposed  = 1,
                            DisposalDate = recDate.SelectedDate.Value,
                            DisposedBy   = _name
                        };

                        dbContext.tbl_DisposalHistory.Add(dataDisposal);

                        dbContext.SaveChanges();

                        tbl_TransactionMaster transact = new tbl_TransactionMaster()
                        {
                            TransactBy         = _name,
                            TransactionDetails = "Disposed Item: " + tbItemCode.Text.Trim(),
                            CreationDateTime   = DateTime.Now
                        };

                        dbContext.tbl_TransactionMaster.Add(transact);

                        dbContext.SaveChanges();

                        tbItemCode.Clear();

                        tbItemCode.Focus();

                        recDate.SelectedDate = DateTime.Now;
                    }
                    else
                    {
                        var b = dbContext.tbl_PartitionSeries.Where(x => x.PartitionCode + "-" + x.Part_SeriesNo.ToString() == tbItemCode.Text.Trim()).FirstOrDefault();

                        tbl_PartitionSeries tbl = b as tbl_PartitionSeries;

                        tbl.IsDisposed = true;

                        tbl.ModifiedBy = _name;

                        tbl.DateModified = DateTime.Now;

                        dbContext.Entry(tbl).State = System.Data.Entity.EntityState.Modified;

                        dbContext.SaveChanges();

                        tbl_DisposalHistory dataDisposal = new tbl_DisposalHistory()
                        {
                            ItemCode     = tbItemCode.Text,
                            QtyDisposed  = 1,
                            DisposalDate = recDate.SelectedDate.Value,
                            DisposedBy   = _name
                        };

                        dbContext.tbl_DisposalHistory.Add(dataDisposal);

                        dbContext.SaveChanges();

                        tbl_TransactionMaster transact = new tbl_TransactionMaster()
                        {
                            TransactBy         = _name,
                            TransactionDetails = "Disposed Item: " + tbItemCode.Text.Trim(),
                            CreationDateTime   = DateTime.Now
                        };

                        dbContext.tbl_TransactionMaster.Add(transact);

                        dbContext.SaveChanges();

                        tbItemCode.Clear();

                        tbItemCode.Focus();

                        recDate.SelectedDate = DateTime.Now;
                    }
                }
            }
            else
            {
                recDate.Focus();
            }
        }
        private Boolean Save()
        {
            Boolean _isValid = false;

            _isValid = _isValidFields();

            if (!_isValid)
            {
                return(false);
            }

            int?maxCount = dbContext.tbl_PartitionSeries.Where(p => p.BoxCode == _boxCode && p.PartitionCode == _partCode.Trim()).Select(p => p.Part_SeriesNo).DefaultIfEmpty(0).Max();

            int count = maxCount.GetValueOrDefault() + 1;

            if (maxCount.GetValueOrDefault() == 0)
            {
                for (int i = count; i <= tbQty.Value; i++)
                {
                    tbl_PartitionSeries _tb2 = new tbl_PartitionSeries()
                    {
                        BoxCode = _boxCode,

                        PartitionCode = _partCode,

                        Part_SeriesNo = i,

                        IsDisposed = false,

                        IsUsed = false,

                        IsDelivered = false,

                        IsReturned = false,

                        IsIssuedToProduction = false,

                        IsIssuedToWareHouse = false,

                        EncodedBy = _name,

                        DateEncoded = DateTime.Now
                    };

                    dbContext.tbl_PartitionSeries.Add(_tb2);

                    tbl_PurchasedHistory tbldata = new tbl_PurchasedHistory()
                    {
                        ItemCode      = _partCode + "-" + i.ToString(),
                        DatePurchased = recDate.SelectedDate.Value
                    };

                    dbContext.tbl_PurchasedHistory.Add(tbldata);
                }

                dbContext.SaveChanges();
            }
            else
            {
                for (int i = maxCount.GetValueOrDefault() + 1; i <= maxCount.GetValueOrDefault() + tbQty.Value; i++)
                {
                    tbl_PartitionSeries _tb2 = new tbl_PartitionSeries()
                    {
                        BoxCode = _boxCode,

                        PartitionCode = _partCode,

                        Part_SeriesNo = i,

                        IsDisposed = false,

                        IsUsed = false,

                        IsDelivered = false,

                        IsReturned = false,

                        IsIssuedToProduction = false,

                        IsIssuedToWareHouse = false,

                        EncodedBy = _name,

                        DateEncoded = DateTime.Now
                    };

                    dbContext.tbl_PartitionSeries.Add(_tb2);


                    tbl_PurchasedHistory tbldata = new tbl_PurchasedHistory()
                    {
                        ItemCode      = _partCode + "-" + i.ToString(),
                        DatePurchased = recDate.SelectedDate.Value
                    };

                    dbContext.tbl_PurchasedHistory.Add(tbldata);
                }

                dbContext.SaveChanges();
            }

            string empname = string.Empty;

            var empdata = dbHRIS.SKPI_GetAllEmployeesByEmpID(_empID).ToList();

            foreach (DataRow dr in ConvertToDataTable(empdata).Rows)
            {
                empname = dr["FullName_LnameFirst"].ToString();
            }

            tbl_TransactionMaster transact = new tbl_TransactionMaster()
            {
                TransactBy         = empname,
                TransactionDetails = "Encoded New Partition Series Quantity",
                CreationDateTime   = DateTime.Now
            };

            dbContext.tbl_TransactionMaster.Add(transact);

            dbContext.SaveChanges();

            MessageBox.Show("Quantity successfully added");

            tbQty.Value = 0;

            tbQty.Focus();

            LoadPartitionSeries();

            return(true);
        }
        private void TbCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                try
                {
                    if (stat == false)
                    {
                        GetBoxCode();

                        var a = dbContext.tbl_BoxSeries.Where(x => x.BoxCode + "-" + x.SeriesNo.ToString() == tbCode.Text.Trim()

                                                              ).FirstOrDefault();

                        tbl_BoxSeries tbl = a as tbl_BoxSeries;

                        tbl.IsIssuedToProduction = false;

                        tbl.IsIssuedToWareHouse = false;

                        tbl.IsDelivered = true;

                        tbl.IsReturned = false;

                        dbContext.Entry(tbl).State = System.Data.Entity.EntityState.Modified;

                        dbContext.SaveChanges();


                        var dataBox = dbContext.tbl_PartitionSeries.Where(p => p.BoxCode == _boxcodes

                                                                          && p.IsUsed == true && p.IsIssuedToProduction == false && p.IsIssuedToWareHouse == true

                                                                          && p.IsDelivered == false && p.IsReturned == false && p.IsDisposed == false).Take(_usage).ToList();

                        //Update data
                        dataBox.ForEach(p =>
                        {
                            p.IsUsed = true; p.IsIssuedToProduction = false; p.IsIssuedToWareHouse = false;

                            p.IsDelivered = true; p.IsReturned = false; p.IsDisposed = false;
                        }
                                        );

                        dbContext.SaveChanges();


                        tbl_TransactionMaster transact = new tbl_TransactionMaster()
                        {
                            TransactBy         = _name,
                            TransactionDetails = "Delivered Item: " + tbCode.Text.Trim(),
                            CreationDateTime   = DateTime.Now
                        };

                        dbContext.tbl_TransactionMaster.Add(transact);

                        dbContext.SaveChanges();


                        LoadData();

                        tbCode.Clear();

                        tbCode.Focus();
                    }
                    else
                    {
                        bool isexists = dbContext.tbl_BoxSeries.Any(x => x.BoxCode + "-" + x.SeriesNo.ToString() == tbCode.Text.Trim());

                        if (isexists)
                        {
                            var a = dbContext.tbl_BoxSeries.Where(x => x.BoxCode + "-" + x.SeriesNo.ToString() == tbCode.Text.Trim()).FirstOrDefault();

                            tbl_BoxSeries tbl = a as tbl_BoxSeries;

                            tbl.IsIssuedToProduction = false;

                            tbl.IsIssuedToWareHouse = false;

                            tbl.IsDelivered = false;

                            tbl.IsReturned = false;

                            tbl.IsUsed = false;

                            dbContext.Entry(tbl).State = System.Data.Entity.EntityState.Modified;

                            dbContext.SaveChanges();

                            tbl_TransactionMaster transact = new tbl_TransactionMaster()
                            {
                                TransactBy         = _name,
                                TransactionDetails = "Received Item: " + tbCode.Text.Trim(),
                                CreationDateTime   = DateTime.Now
                            };

                            dbContext.tbl_TransactionMaster.Add(transact);

                            dbContext.SaveChanges();


                            tbCode.Clear();

                            tbCode.Focus();

                            LoadData();
                        }
                        else
                        {
                            var b = dbContext.tbl_PartitionSeries.Where(x => x.PartitionCode + "-" + x.Part_SeriesNo.ToString() == tbCode.Text.Trim()).FirstOrDefault();

                            tbl_PartitionSeries tbl = b as tbl_PartitionSeries;

                            tbl.IsIssuedToProduction = false;

                            tbl.IsIssuedToWareHouse = false;

                            tbl.IsDelivered = false;

                            tbl.IsReturned = false;

                            tbl.IsUsed = false;

                            dbContext.Entry(tbl).State = System.Data.Entity.EntityState.Modified;

                            dbContext.SaveChanges();

                            tbl_TransactionMaster transact = new tbl_TransactionMaster()
                            {
                                TransactBy         = _name,
                                TransactionDetails = "Received Item: " + tbCode.Text.Trim(),
                                CreationDateTime   = DateTime.Now
                            };

                            dbContext.tbl_TransactionMaster.Add(transact);

                            dbContext.SaveChanges();

                            tbCode.Clear();

                            tbCode.Focus();

                            LoadData();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("No Records Found");
                }
            }
        }
        private void BtnPrint_Click(object sender, RoutedEventArgs e)
        {
            var lstCodes1 = dbContext.tblBarcodeToPrints.ToList();

            if (lstCodes1 != null)
            {
                dbContext.tblBarcodeToPrints.RemoveRange(lstCodes1);

                dbContext.SaveChanges();
            }


            var lstCodes = dbContext.tblBarcodeToPrints.ToList();

            if (lstCodes != null)
            {
                dbContext.tblBarcodeToPrints.RemoveRange(lstCodes);

                dbContext.SaveChanges();
            }

            for (int i = 0; i < gridBoxCode.Items.Count; i++)
            {
                var mycheckbox = gridBoxCode.Columns[0].GetCellContent(gridBoxCode.Items[i]) as CheckBox;

                TextBlock itemCode = gridBoxCode.Columns[1].GetCellContent(gridBoxCode.Items[i]) as TextBlock;

                TextBlock itemTag = gridBoxCode.Columns[2].GetCellContent(gridBoxCode.Items[i]) as TextBlock;

                if (mycheckbox.IsChecked == true)
                {
                    tblBarcodeToPrint data = new tblBarcodeToPrint()
                    {
                        ItemCode = itemCode.Text,
                        ItemDesc = itemTag.Text
                    };

                    dbContext.tblBarcodeToPrints.Add(data);

                    tbl_TransactionMaster transact = new tbl_TransactionMaster()
                    {
                        TransactBy         = _name,
                        TransactionDetails = "Print Item: " + itemCode.Text.Trim(),
                        CreationDateTime   = DateTime.Now
                    };

                    dbContext.tbl_TransactionMaster.Add(transact);
                }
            }

            dbContext.SaveChanges();

            for (int i = 0; i < gridPartition.Items.Count; i++)
            {
                var       mycheckbox2 = gridPartition.Columns[0].GetCellContent(gridPartition.Items[i]) as CheckBox;
                TextBlock itemCode2   = gridPartition.Columns[1].GetCellContent(gridPartition.Items[i]) as TextBlock;
                TextBlock itemTag2    = gridPartition.Columns[2].GetCellContent(gridPartition.Items[i]) as TextBlock;
                if (mycheckbox2.IsChecked == true)
                {
                    tblBarcodeToPrint data = new tblBarcodeToPrint()
                    {
                        ItemCode = itemCode2.Text,
                        ItemDesc = itemTag2.Text
                    };

                    dbContext.tblBarcodeToPrints.Add(data);

                    tbl_TransactionMaster transact = new tbl_TransactionMaster()
                    {
                        TransactBy         = _name,
                        TransactionDetails = "Print Item: " + itemCode2.Text.Trim(),
                        CreationDateTime   = DateTime.Now
                    };

                    dbContext.tbl_TransactionMaster.Add(transact);
                }
            }

            dbContext.SaveChanges();

            PrintPreview frm = new PrintPreview();

            frm.ShowDialog();
        }
        private void Save()
        {
            string empname = string.Empty;

            var empdata = dbHRIS.SKPI_GetAllEmployeesByEmpID(_empID).ToList();

            foreach (DataRow dr in ConvertToDataTable(empdata).Rows)
            {
                empname = dr["FullName_LnameFirst"].ToString();
            }

            int?maxCount = dbContext.tbl_PartitionSeries.Where(p => p.BoxCode == _boxCode && p.PartitionCode == tbPartitionCode.Text.Trim()).Select(p => p.Part_SeriesNo).DefaultIfEmpty(0).Max();

            int count = maxCount.GetValueOrDefault() + 1;

            if (maxCount.GetValueOrDefault() == 0)
            {
                for (int i = count; i <= tbQty.Value; i++)
                {
                    tbl_PartitionSeries _tb2 = new tbl_PartitionSeries()
                    {
                        BoxCode = _boxCode,

                        PartitionCode = tbPartitionCode.Text.Trim(),

                        Part_SeriesNo = i,

                        IsDisposed = false,

                        IsUsed = false,

                        IsDelivered = false,

                        IsReturned = false,

                        IsIssuedToProduction = false,

                        IsIssuedToWareHouse = false,
                        EncodedBy           = _name,
                        DateEncoded         = DateTime.Now
                    };

                    dbContext.tbl_PartitionSeries.Add(_tb2);


                    tbl_TransactionMaster transact = new tbl_TransactionMaster()
                    {
                        TransactBy         = empname,
                        TransactionDetails = "New Item Inserted: " + tbPartitionCode.Text.Trim(),
                        CreationDateTime   = DateTime.Now
                    };

                    dbContext.tbl_TransactionMaster.Add(transact);
                }

                dbContext.SaveChanges();

                //dbContext.SaveChanges();
            }
            else
            {
                for (int i = maxCount.GetValueOrDefault() + 1; i <= maxCount.GetValueOrDefault() + tbQty.Value; i++)
                {
                    tbl_PartitionSeries _tb2 = new tbl_PartitionSeries()
                    {
                        BoxCode = _boxCode,

                        PartitionCode = tbPartitionCode.Text.Trim(),

                        Part_SeriesNo = i,

                        IsDisposed = false,

                        IsUsed = false,

                        IsDelivered = false,

                        IsReturned = false,

                        IsIssuedToProduction = false,

                        IsIssuedToWareHouse = false,
                        EncodedBy           = _name,
                        DateEncoded         = DateTime.Now
                    };

                    dbContext.tbl_PartitionSeries.Add(_tb2);

                    tbl_TransactionMaster transact = new tbl_TransactionMaster()
                    {
                        TransactBy         = empname,
                        TransactionDetails = "New Item Inserted: " + tbPartitionCode.Text.Trim(),
                        CreationDateTime   = DateTime.Now
                    };

                    dbContext.tbl_TransactionMaster.Add(transact);
                }

                dbContext.SaveChanges();
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var user = dbContext.tblUsers.Where(x => x.EmpID == tbUsername.Text).FirstOrDefault();

            tblUser data = user as tblUser;

            if (user != null)
            {
                var data2 = dbHRIS.SKPI_GetAllEmployeesByEmpID(data.EmpID).Take(1).ToList();

                foreach (DataRow dr in ConvertToDataTable(data2).Rows)
                {
                    _name = dr["FullName_FnameFirst"].ToString();
                }

                tbl_TransactionMaster transact = new tbl_TransactionMaster()
                {
                    TransactBy         = _name,
                    TransactionDetails = "Login",
                    CreationDateTime   = DateTime.Now
                };

                dbContext.tbl_TransactionMaster.Add(transact);

                dbContext.SaveChanges();

                if (data.RoleID == "01" || data.RoleID == "02")
                {
                    BoxAndPartitionMaster frm = new BoxAndPartitionMaster();

                    frm._empID = data.EmpID;

                    frm._role = data.RoleID;

                    frm.Show();

                    this.Hide();
                }
                else if (data.RoleID == "03")
                {
                    Production frm = new Production();

                    frm._empID = data.EmpID;

                    frm._role = data.RoleID;

                    frm.Show();

                    this.Hide();
                }
                else if (data.RoleID == "04")
                {
                    Warehouse frm = new Warehouse();

                    frm._empID = data.EmpID;

                    frm._role = data.RoleID;

                    frm.Show();

                    this.Hide();
                }
            }
        }
Exemple #10
0
        private Boolean Insert()
        {
            Boolean _result = false;

            _result = _isValidFields();

            if (!_result)
            {
                return(false);
            }

            bool isexists = dbContext.tbl_BoxMaster.Any(x => x.BoxCode == tbBoxCode.Text.Trim());

            if (!isexists)
            {
                tbl_BoxMaster _tb = new tbl_BoxMaster()
                {
                    BoxCode = tbBoxCode.Text,

                    BoxDescription = tbBoxDesc.Text,

                    UsagePerBox = Convert.ToInt32(tbUsage.Value),

                    ItemTag = tbItemTag.Text,

                    CusCode = cboCustomer.SelectedValue.ToString()
                };

                dbContext.tbl_BoxMaster.Add(_tb);

                dbContext.SaveChanges();


                string empname = string.Empty;

                var empdata = dbHRIS.SKPI_GetAllEmployeesByEmpID(_empID).ToList();

                foreach (DataRow dr in ConvertToDataTable(empdata).Rows)
                {
                    empname = dr["FullName_LnameFirst"].ToString();
                }

                tbl_TransactionMaster transact = new tbl_TransactionMaster()
                {
                    TransactBy         = empname,
                    TransactionDetails = "New Item Inserted: " + tbBoxCode.Text.Trim(),
                    CreationDateTime   = DateTime.Now
                };

                dbContext.tbl_TransactionMaster.Add(transact);

                dbContext.SaveChanges();


                BoxAndPartitionMaster.gridBox.ItemsSource = dbContext.tbl_BoxMaster.ToList();

                MessageBox.Show("Record successfully saved");

                tbBoxCode.Text = tbBoxDesc.Text = tbItemTag.Text = string.Empty;

                cboCustomer.SelectedIndex = -1;

                tbBoxCode.Focus();
            }
            else
            {
            }

            return(true);
        }