Exemplo n.º 1
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();
                    }
                }
            }
        }
        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 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 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();
            }
        }