Exemple #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;
            Decimal weight = 0.00M;
            bool AddRec = false;
            TLADM_TranactionType TranType = null;


            if (oBtn != null && formloaded)
            {
                var Select = (TLDYE_DyeBatch)cmboBatchNumber.SelectedItem;
                if (Select == null)
                {
                    MessageBox.Show("Please select a batch number from the drop down box ");
                    return;
                }

                using (var context = new TTI2Entities())
                {
                    var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "DYE").FirstOrDefault();
                    if (Dept != null)
                    {
                        TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1400).FirstOrDefault();
                    }
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        TLDYE_DyeBatchDetails bd = new TLDYE_DyeBatchDetails();

                        int index = (int)row.Cells[0].Value;

                        bd = context.TLDYE_DyeBatchDetails.Find(index);
                        if (bd != null)
                        {
                            if ((bool)row.Cells[6].Value == true)
                            {
                                bd.DYEBO_Rejected = false;
                                bd.DYEBO_RejectedDate = null;
                                bd.DYEBO_QAApproved = true;
                                bd.DYEBO_ApprovalDate = dtpTransDate.Value;
                                if (bd.DYEBO_CutSheet)
                                    bd.DYEBO_CutSheet = false;


                                weight += (decimal)row.Cells[5].Value;
                                bd.DYEBO_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK;
                                AddRec = true;
                            }

                        }
                    }

                    if (AddRec)
                    {
                        var LNU = context.TLADM_LastNumberUsed.Find(3);

                        TLDYE_DyeTransactions tt = new TLDYE_DyeTransactions();
                        tt.TLDYET_BatchNo = Select.DYEB_BatchNo;
                        tt.TLDYET_BatchWeight = Select.DYEB_BatchKG;
                        tt.TLDYET_SequenceNo = Select.DYEB_SequenceNo;
                        tt.TLDYET_Batch_FK = Select.DYEB_Pk;
                        tt.TLDYET_TransactionNumber = "RFREV" + LNU.col7.ToString().PadLeft(6, '0');
                        tt.TLDYET_Date = dtpTransDate.Value;
                        tt.TLDYET_TransactionWeight = weight;
                        tt.TLDYET_TransactionType = (int)TranType.TrxT_Pk;
                        tt.TLDYET_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK;

                        context.TLDYE_DyeTransactions.Add(tt);

                        try
                        {
                            LNU.col7 += 1;
                            context.SaveChanges();
                            MessageBox.Show("Data successfully saved to the database");
                            frmDyeViewReport vRep = new frmDyeViewReport(11, tt.TLDYET_Pk, true);
                            vRep.ShowDialog(this);

                            frmRejectFabricReversal_Load(this, null);

                        }
                        catch (System.Data.Entity.Validation.DbEntityValidationException en)
                        {
                            foreach (var eve in en.EntityValidationErrors)
                            {
                                MessageBox.Show("following validation errors: Type" + eve.Entry.Entity.GetType().Name.ToString() + "State " + eve.Entry.State.ToString());
                                foreach (var ve in eve.ValidationErrors)
                                {
                                    MessageBox.Show("- Property" + ve.PropertyName + " Message " + ve.ErrorMessage);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView oDgv = sender as DataGridView;

            if (oDgv.Focused && oDgv.CurrentCell is DataGridViewCheckBoxCell)
            {
                TLDYE_DyeBatch db = new TLDYE_DyeBatch();

                using (var context = new TTI2Entities())
                {
                    int DyeBatchKey = (int)oDgv.CurrentRow.Cells[0].Value;
                    db = context.TLDYE_DyeBatch.Find(DyeBatchKey);
                    if (db != null)
                    {
                        db.DYEB_Transfered   = true;
                        db.DYEB_TransferDate = dtpTransferDate.Value;

                        var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("DYE")).FirstOrDefault();
                        if (Dept != null)
                        {
                            var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 300).FirstOrDefault();
                            if (TranType != null)
                            {
                                db.DYEB_TransactionType_FK = TranType.TrxT_Pk;
                            }
                        }

                        TLDYE_DyeTransactions dt = new TLDYE_DyeTransactions();
                        dt.TLDYET_BatchNo         = db.DYEB_BatchNo;
                        dt.TLDYET_BatchWeight     = db.DYEB_BatchKG;
                        dt.TLDYET_Date            = dtpTransferDate.Value;
                        dt.TLDYET_SequenceNo      = db.DYEB_SequenceNo;
                        dt.TLDYET_TransactionType = db.DYEB_TransactionType_FK;
                        dt.TLDYET_Batch_FK        = db.DYEB_Pk;
                        dt.TLDYET_Stage           = 2;
                        dt.TLDYET_CurrentStore_FK = (int)context.TLADM_TranactionType.Find(db.DYEB_TransactionType_FK).TrxT_ToWhse_FK;

                        context.TLDYE_DyeTransactions.Add(dt);

                        var DBD = context.TLDYE_DyeBatchDetails.Where(x => x.DYEBD_DyeBatch_FK == db.DYEB_Pk).ToList();
                        foreach (var rowx in DBD)
                        {
                            rowx.DYEBO_CurrentStore_FK = dt.TLDYET_CurrentStore_FK;
                        }

                        try
                        {
                            context.SaveChanges();
                            frmDyeViewReport vRep = new frmDyeViewReport(8, DyeBatchKey);
                            int h = Screen.PrimaryScreen.WorkingArea.Height;
                            int w = Screen.PrimaryScreen.WorkingArea.Width;
                            vRep.ClientSize = new Size(w, h);
                            vRep.ShowDialog(this);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                oDgv.Rows.RemoveAt(oDgv.CurrentRow.Index);
            }
        }
Exemple #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button             oBtn   = sender as Button;
            bool               Add    = false;
            TLADM_QADyeProcess Stages = null;

            if (oBtn != null && formloaded)
            {
                var selected = (TLDYE_NonCompliance)cmboBatches.SelectedItem;
                if (selected != null)
                {
                    if (dataGridView4.Rows.Count == 0)
                    {
                        MessageBox.Show("Please supply a non consumable description and quantity");
                        return;
                    }
                    using (var context = new TTI2Entities())
                    {
                        if (rbPass.Checked || rbReprocess.Checked)
                        {
                            var DB = context.TLDYE_DyeBatch.Find(selected.TLDYE_NcrBatchNo_FK);
                            if (DB != null)
                            {
                                Stages = (TLADM_QADyeProcess)cmboProcess.SelectedItem;
                                if (rbPass.Checked)
                                {
                                    if (Stages.QADYEP_Pk == 1)
                                    {
                                        DB.DYEB_Stage1 = true;
                                    }
                                    else if (Stages.QADYEP_Pk == 2)
                                    {
                                        DB.DYEB_Stage2 = true;
                                    }
                                    else
                                    {
                                        DB.DYEB_Stage3 = true;
                                    }
                                }

                                if (rbReprocess.Checked)
                                {
                                    DB.DYEB_Reprocess = true;

                                    if (rbReprocess.Checked)
                                    {
                                        var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("DYE")).FirstOrDefault();
                                        if (Dept != null)
                                        {
                                            TLDYE_DyeTransactions trns = new TLDYE_DyeTransactions();
                                            trns.TLDYET_BatchNo     = DB.DYEB_BatchNo;
                                            trns.TLDYET_BatchWeight = DB.DYEB_BatchKG;
                                            trns.TLDYET_Date        = DateTime.Now;
                                            trns.TLDYET_SequenceNo  = DB.DYEB_SequenceNo;
                                            trns.TLDYET_Batch_FK    = DB.DYEB_Pk;
                                            trns.TLDYET_RejectDate  = DateTime.Now;

                                            var TT = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 500).FirstOrDefault();
                                            if (TT != null)
                                            {
                                                trns.TLDYET_TransactionType = TT.TrxT_Pk;
                                                trns.TLDYET_CurrentStore_FK = (int)TT.TrxT_ToWhse_FK;
                                            }

                                            context.TLDYE_DyeTransactions.Add(trns);
                                        }
                                    }
                                }
                            }
                        }

                        foreach (DataGridViewRow row in dataGridView1.Rows)
                        {
                            if (row.Cells[1].Value.ToString() == bool.FalseString)
                            {
                                continue;
                            }

                            //--------------------------------------------------------------
                            // We dont want to update the same record twice
                            //----------------------------------------------------------
                            var Value  = (int)row.Cells[0].Value;
                            var record = context.TLDYE_NonComplianceDetail.Where(x => x.DYENCRD_ComNumber == selected.TLDYE_NcrNumber &&
                                                                                 x.DYENCRD_Code_FK == Value && x.DYENCRD_FR).FirstOrDefault();
                            if (record != null)
                            {
                                continue;
                            }

                            TLDYE_NonComplianceDetail nonD = new TLDYE_NonComplianceDetail();
                            nonD.DYENCRD_BatchNo_Fk = selected.TLDYE_NcrBatchNo_FK;
                            nonD.DYENCRD_FR         = true;
                            nonD.DYENCRD_Code_FK    = (int)row.Cells[0].Value;
                            nonD.DYENCRD_ComNumber  = selected.TLDYE_NcrNumber;

                            context.TLDYE_NonComplianceDetail.Add(nonD);
                        }

                        foreach (DataGridViewRow row in dataGridView2.Rows)
                        {
                            if (row.Cells[1].Value.ToString() == bool.FalseString)
                            {
                                continue;
                            }

                            //--------------------------------------------------------------
                            // We dont want to update the same record twice
                            //----------------------------------------------------------
                            var Value  = (int)row.Cells[0].Value;
                            var record = context.TLDYE_NonComplianceDetail.Where(x => x.DYENCRD_ComNumber == selected.TLDYE_NcrNumber &&
                                                                                 x.DYENCRD_Code_FK == Value && !x.DYENCRD_FR).FirstOrDefault();
                            if (record != null)
                            {
                                continue;
                            }

                            TLDYE_NonComplianceDetail nonD = new TLDYE_NonComplianceDetail();
                            nonD.DYENCRD_BatchNo_Fk = selected.TLDYE_NcrBatchNo_FK;
                            nonD.DYENCRD_FR         = false;
                            nonD.DYENCRD_Code_FK    = (int)row.Cells[0].Value;
                            nonD.DYENCRD_ComNumber  = selected.TLDYE_NcrNumber;

                            context.TLDYE_NonComplianceDetail.Add(nonD);
                        }

                        foreach (DataGridViewRow row in dataGridView3.Rows)
                        {
                            if (row.Cells[1].Value == null)
                            {
                                continue;
                            }

                            var Value = 0.00M;
                            if (row.Cells[4].Value != null)
                            {
                                decimal.TryParse(row.Cells[4].Value.ToString(), out Value);
                            }

                            if (Value == 0.00M)
                            {
                                continue;
                            }

                            Add = false;

                            TLDYE_NonComplianceConsDetail nonD = new TLDYE_NonComplianceConsDetail();
                            // Cant add the same record twice
                            if (row.Cells[0].Value != null)
                            {
                                var index = (int)row.Cells[0].Value;
                                nonD = context.TLDYE_NonComplianceConsDetail.Find(index);
                            }
                            else
                            {
                                Add = true;
                            }

                            nonD.DYENCCON_BatchNo_FK = selected.TLDYE_NcrBatchNo_FK;
                            nonD.DYENCCON_ConOrNon   = true;
                            nonD.DYENCCON_Code_FK    = (int)row.Cells[1].Value;
                            nonD.DYENCCON_ConNumber  = selected.TLDYE_NcrNumber;
                            nonD.DYENCCON_Qunatities = (decimal)row.Cells[4].Value;

                            if (Add)
                            {
                                context.TLDYE_NonComplianceConsDetail.Add(nonD);
                            }
                        }

                        foreach (DataGridViewRow row in dataGridView4.Rows)
                        {
                            if (row.Cells[1].Value == null)
                            {
                                continue;
                            }

                            Add = false;

                            TLDYE_NonComplianceConsDetail nonD = new TLDYE_NonComplianceConsDetail();
                            // Cant add the same record twice
                            if (row.Cells[0].Value != null)
                            {
                                var index = (int)row.Cells[0].Value;
                                nonD = context.TLDYE_NonComplianceConsDetail.Find(index);
                            }
                            else
                            {
                                Add = true;
                            }

                            nonD.DYENCCON_BatchNo_FK = selected.TLDYE_NcrBatchNo_FK;
                            nonD.DYENCCON_ConOrNon   = false;
                            nonD.DYENCCON_Code_FK    = (int)row.Cells[1].Value;
                            nonD.DYENCCON_ConNumber  = selected.TLDYE_NcrNumber;
                            if (row.Cells[2].Value != null)
                            {
                                nonD.DYENCCON_Qunatities = (decimal)row.Cells[2].Value;
                            }
                            else
                            {
                                nonD.DYENCCON_Qunatities = 0.00M;
                            }

                            if (Add)
                            {
                                context.TLDYE_NonComplianceConsDetail.Add(nonD);
                            }
                        }



                        try
                        {
                            context.SaveChanges();
                            MessageBox.Show("Data saved successfully to database");
                            frmDyeViewReport vRep = new frmDyeViewReport(7, selected.TLDYE_NcrNumber);
                            int h = Screen.PrimaryScreen.WorkingArea.Height;
                            int w = Screen.PrimaryScreen.WorkingArea.Width;
                            vRep.ClientSize = new Size(w, h);
                            vRep.ShowDialog(this);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
Exemple #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button  oBtn   = sender as Button;
            decimal weight = 0.00M;
            bool    AddRec = true;
            TLADM_TranactionType TranType = null;

            if (oBtn != null && formloaded)
            {
                var Select = (TLDYE_DyeBatch)cmboBatchNumber.SelectedItem;
                if (Select == null)
                {
                    MessageBox.Show("Please select a batch number from the drop down box");
                    return;
                }


                using (var context = new TTI2Entities())
                {
                    var DB = context.TLDYE_DyeBatch.Find(Select.DYEB_Pk);
                    if (DB != null)
                    {
                        DB.DYEB_QAInspected = true;
                    }

                    var LNU = context.TLADM_LastNumberUsed.Find(3);
                    if (LNU != null)
                    {
                        LNU.col8 += 1;
                    }

                    if (Select.DYEB_CommissinCust)
                    {
                        var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "DYE").FirstOrDefault();
                        if (Dept != null)
                        {
                            TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 900).FirstOrDefault();
                        }
                    }
                    else
                    {
                        var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "DYE").FirstOrDefault();
                        if (Dept != null)
                        {
                            TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 700).FirstOrDefault();
                        }
                    }

                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        TLDYE_DyeBatchDetails bd = new TLDYE_DyeBatchDetails();

                        if (row.Cells[0].Value == null)
                        {
                            continue;
                        }

                        int index = (int)row.Cells[0].Value;

                        bd = context.TLDYE_DyeBatchDetails.Find(index);
                        if (bd != null)
                        {
                            if ((bool)row.Cells[6].Value == true)
                            {
                                bd.DYEBO_QAApproved = true;
                                //use this date tocalculate the days production days
                                bd.DYEBO_ApprovalDate    = dtpTransDate.Value;
                                bd.DYEBO_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK;
                                weight += (decimal)row.Cells[5].Value;
                                AddRec  = true;
                            }
                        }
                    }

                    if (AddRec)
                    {
                        TLDYE_DyeTransactions tt = new TLDYE_DyeTransactions();
                        tt.TLDYET_BatchNo     = Select.DYEB_BatchNo;
                        tt.TLDYET_BatchWeight = Select.DYEB_BatchKG;
                        tt.TLDYET_SequenceNo  = Select.DYEB_SequenceNo;
                        tt.TLDYET_Batch_FK    = Select.DYEB_Pk;

                        tt.TLDYET_Date = dtpTransDate.Value;
                        tt.TLDYET_TransactionWeight = weight;
                        tt.TLDYET_TransactionNumber = txtTransNumber.Text;
                        tt.TLDYET_Batch_FK          = Select.DYEB_Pk;
                        tt.TLDYET_TransactionType   = (int)TranType.TrxT_Pk;
                        tt.TLDYET_CurrentStore_FK   = (int)TranType.TrxT_ToWhse_FK;

                        context.TLDYE_DyeTransactions.Add(tt);
                        try
                        {
                            context.SaveChanges();
                            MessageBox.Show("Data successfully saved to the database");
                            Setup();
                        }
                        catch (System.Data.Entity.Validation.DbEntityValidationException en)
                        {
                            foreach (var eve in en.EntityValidationErrors)
                            {
                                MessageBox.Show("following validation errors: Type" + eve.Entry.Entity.GetType().Name.ToString() + "State " + eve.Entry.State.ToString());
                                foreach (var ve in eve.ValidationErrors)
                                {
                                    MessageBox.Show("- Property" + ve.PropertyName + " Message " + ve.ErrorMessage);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
Exemple #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;
            IList <TLDYE_DyeBatchDetails> DBDetails = new List <TLDYE_DyeBatchDetails>();
            IList <TLADM_Departments>     Depts     = new List <TLADM_Departments>();

            bool Add = true;

            if (oBtn != null && formloaded)
            {
                var Selected = (TLDYE_DyeBatch)cmboBatchNo.SelectedItem;
                if (Selected == null)
                {
                    MessageBox.Show("Please select a dyebatch from the drop down box");
                    return;
                }

                var SelectedOp = (TLADM_MachineOperators)cmboOperator.SelectedItem;
                if (SelectedOp == null)
                {
                    MessageBox.Show("Please select an operator from the drop down list");
                    return;
                }

                using (var context = new TTI2Entities())
                {
                    Depts = context.TLADM_Departments.ToList();

                    var DB = context.TLDYE_DyeBatch.Find(Selected.DYEB_Pk);
                    if (DB != null)
                    {
                        //-------------------------------------------------
                        // This does the dye batch
                        //------------------------------------------------------------
                        if (rbBtnNo.Checked)
                        {
                            DB.DYEB_Stage1 = true;
                        }

                        var Dept = Depts.Where(x => x.Dep_ShortCode.Contains("DYE")).FirstOrDefault();
                        if (Dept != null)
                        {
                            TLDYE_DyeTransactions trns = new TLDYE_DyeTransactions();
                            trns = context.TLDYE_DyeTransactions.Where(x => x.TLDYET_Batch_FK == DB.DYEB_Pk && x.TLDYET_Stage == 3).FirstOrDefault();
                            if (trns == null)
                            {
                                trns = new TLDYE_DyeTransactions();
                            }
                            else
                            {
                                Add = false;
                            }

                            trns.TLDYET_BatchNo     = DB.DYEB_BatchNo;
                            trns.TLDYET_BatchWeight = DB.DYEB_BatchKG;
                            trns.TLDYET_Date        = DateTime.Now;
                            trns.TLDYET_SequenceNo  = DB.DYEB_SequenceNo;
                            trns.TLDYET_Batch_FK    = DB.DYEB_Pk;
                            trns.TLDYET_Stage       = 3;
                            if (rbBtnNo.Checked)
                            {
                                trns.TLDYET_Rejected = false;
                            }
                            else
                            {
                                trns.TLDYET_Rejected   = true;
                                trns.TLDYET_RejectDate = DateTime.Now;
                            }

                            var TT = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 400).FirstOrDefault();
                            if (TT != null)
                            {
                                trns.TLDYET_TransactionType = TT.TrxT_Pk;
                                trns.TLDYET_CurrentStore_FK = (int)TT.TrxT_ToWhse_FK;
                            }

                            if (Add)
                            {
                                context.TLDYE_DyeTransactions.Add(trns);
                            }

                            DBDetails = context.TLDYE_DyeBatchDetails.Where(x => x.DYEBD_DyeBatch_FK == DB.DYEB_Pk).ToList();
                            foreach (var Record in DBDetails)
                            {
                                Record.DYEBO_CurrentStore_FK = trns.TLDYET_CurrentStore_FK;
                            }
                        }
                        //-------------------------------------------------------------------------
                        // This code assign operators
                        //----------------------------------------------------------------
                        var selected = (TLADM_MachineOperators)cmboOperator.SelectedItem;
                        if (selected != null)
                        {
                            var allop = context.TLDYE_AllocatedOperator.Where(x => x.DYEOP_BatchNo_FK == DB.DYEB_Pk).FirstOrDefault();
                            if (allop == null)
                            {
                                allop = new TLDYE_AllocatedOperator();
                                allop.DYEOP_BatchDate   = DateTime.Now;
                                allop.DYEOP_Operator_FK = selected.MachOp_Pk;
                                allop.DYEOP_BatchNo_FK  = DB.DYEB_Pk;

                                context.TLDYE_AllocatedOperator.Add(allop);
                            }
                            else
                            {
                                allop.DYEOP_BatchDate   = DateTime.Now;
                                allop.DYEOP_Operator_FK = selected.MachOp_Pk;
                            }
                        }

                        //if (DB.DYEB_SequenceNo == 0)
                        //{
                        //---------------------------------------------------------------------
                        // 1st thing get the colour of the batch
                        //---------------------------------------------------------------------
                        var Colour = context.TLADM_Colours.Find(DB.DYEB_Colour_FK);
                        //----------------------------------------------------------------
                        // Now get the Receipe for this colour
                        //----------------------------------------------------------------
                        var Receipe = context.TLDYE_RecipeDefinition.Where(x => x.TLDYE_ColorChart_FK == DB.DYEB_Colour_FK).FirstOrDefault();
                        if (Receipe != null)
                        {
                            var ReceipeDefinition = context.TLDYE_DefinitionDetails.Where(x => x.TLDYED_Receipe_FK == Receipe.TLDYE_DefinePk).ToList();
                            foreach (var Definition in ReceipeDefinition)
                            {
                                var ConsDC = context.TLADM_ConsumablesDC.Find(Definition.TLDYED_Cosumables_FK);
                                if (ConsDC.ConsDC_Discontinued)
                                {
                                    continue;
                                }

                                if (!Definition.TLDYED_LiqCalc)
                                {
                                    var Kgs = (Definition.TLDYED_MELFC * DB.DYEB_BatchKG) / 100;
                                    //-----------------------------------
                                    //Find this Record in the SOH
                                    //----------------------------------------------
                                    if (Dept != null)
                                    {
                                        var SOH = context.TLDYE_ConsumableSOH.Where(x => x.DYCSH_Consumable_FK == Definition.TLDYED_Cosumables_FK &&
                                                                                    x.DYCSH_DyeKitchen).FirstOrDefault();
                                        //------------------------
                                        // Now there might be NO stock on hand for this item
                                        //--------------------------------------------------------
                                        if (SOH == null)
                                        {
                                            var Whse = context.TLADM_WhseStore.Where(x => x.WhStore_DepartmentFK == Dept.Dep_Id && x.WhStore_DyeKitchen).FirstOrDefault();

                                            TLDYE_ConsumableSOH cons = new TLDYE_ConsumableSOH();
                                            cons.DYCSH_Consumable_FK = Definition.TLDYED_Cosumables_FK;
                                            cons.DYCSH_StockOnHand  -= Kgs;
                                            cons.DYCSH_WhseStore_FK  = Whse.WhStore_Id;

                                            context.TLDYE_ConsumableSOH.Add(cons);
                                            try
                                            {
                                                context.SaveChanges();
                                            }
                                            catch (Exception ex)
                                            {
                                                MessageBox.Show("Unable to adjust consummable Stock on hand table" + ex.Message);
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            SOH.DYCSH_StockOnHand -= Kgs;
                                        }
                                    }
                                }
                                else
                                {
                                    //-------------------------------------------
                                    // We Now use the the liquidity factor
                                    //------------------------------------------------------------
                                    var Kgs = (Definition.TLDYED_MELFC * DB.DYEB_BatchKG * Definition.TLDYED_LiqRatio) / 1000;
                                    //-----------------------------------
                                    //Find this Record in the SOH
                                    //----------------------------------------------
                                    var SOH = context.TLDYE_ConsumableSOH.Where(x => x.DYCSH_Consumable_FK == Definition.TLDYED_Cosumables_FK && x.DYCSH_DyeKitchen).FirstOrDefault();
                                    //------------------------
                                    // Now there might be NO stock on hand for this item in the consumables stock on hand
                                    //--------------------------------------------------------
                                    if (SOH == null)
                                    {
                                        var Whse = context.TLADM_WhseStore.Where(x => x.WhStore_DepartmentFK == Dept.Dep_Id && x.WhStore_DyeKitchen).FirstOrDefault();

                                        TLDYE_ConsumableSOH cons = new TLDYE_ConsumableSOH();
                                        cons.DYCSH_Consumable_FK = Definition.TLDYED_Cosumables_FK;
                                        cons.DYCSH_StockOnHand  -= Kgs;
                                        cons.DYCSH_WhseStore_FK  = Whse.WhStore_Id;

                                        context.TLDYE_ConsumableSOH.Add(cons);
                                        try
                                        {
                                            context.SaveChanges();
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show("Unable to adjust consummable Stock on hand table" + ex.Message);
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        SOH.DYCSH_StockOnHand -= Kgs;
                                    }
                                }
                            }

                            try
                            {
                                context.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Unable to adjust consummable Stock on hand table" + ex.Message);
                            }
                            //  }
                        }
                    }

                    try
                    {
                        context.SaveChanges();
                        SetUp();
                        MessageBox.Show("Data saved to database successfully");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
Exemple #6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;
            IList <TLDYE_DyeBatch> DB = new List <TLDYE_DyeBatch>();
            Decimal Nett = 0.00M;
            TLADM_TranactionType TranType = null;
            Decimal BatchWeight           = 0.00M;


            if (oBtn != null && formloaded)
            {
                var errorM = core.returnMessage(MandSelected, true, MandatoryFields);
                if (!string.IsNullOrEmpty(errorM))
                {
                    MessageBox.Show(errorM);
                    return;
                }

                using (var context = new TTI2Entities())
                {
                    var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "DYE").FirstOrDefault();
                    if (Dept != null)
                    {
                        if (rbFabricStore.Checked)
                        {
                            TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1100).FirstOrDefault();
                        }
                        else
                        {
                            TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1200).FirstOrDefault();
                        }
                    }

                    var LNU = context.TLADM_LastNumberUsed.Find(3);
                    if (LNU != null)
                    {
                        LNU.col10 += 1;;
                    }

                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if ((bool)row.Cells[10].Value == true)
                        {
                            var index = Int32.Parse(row.Cells[0].Value.ToString());
                            var DBD   = context.TLDYE_DyeBatchDetails.Find(index);
                            if (DBD != null)
                            {
                                DBD.DYEBO_CurrentStore_FK = TranType.TrxT_Pk;
                                DBD.DYEBO_TransactionNo   = txtTransNumber.Text;
                                DBD.DYEBO_DateSold        = dtTransDate.Value;
                                DBD.DYEBO_Sold            = true;

                                BatchWeight += DBD.DYEBD_GreigeProduction_Weight;
                                Nett        += DBD.DYEBO_Nett;
                            }
                        }
                    }


                    TLDYE_DyeTransactions tt = new TLDYE_DyeTransactions();
                    tt.TLDYET_BatchNo           = "0";
                    tt.TLDYET_BatchWeight       = BatchWeight;
                    tt.TLDYET_SequenceNo        = 0;
                    tt.TLDYET_Batch_FK          = 0;
                    tt.TLDYET_Date              = dtTransDate.Value;
                    tt.TLDYET_TransactionWeight = Nett;
                    tt.TLDYET_TransactionNumber = txtTransNumber.Text;
                    tt.TLDYET_TransactionType   = TranType.TrxT_Pk;
                    tt.TLDYET_CurrentStore_FK   = (int)TranType.TrxT_ToWhse_FK;
                    tt.TLDYET_Customer_FK       = ((TLADM_CustomerFile)cmboCustomers.SelectedItem).Cust_Pk;
                    tt.TLDYET_FabricSales       = true;
                    tt.TLDYET_CustomerOrderNo   = txtOrderNumber.Text;

                    context.TLDYE_DyeTransactions.Add(tt);
                    try
                    {
                        context.SaveChanges();
                        MessageBox.Show("Data succesfully saved to database");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            Button  oBtn                = sender as Button;
            decimal Weight              = 0.00M;
            int     CurrentStore_FK     = 0;
            TLADM_TranactionType  TT    = null;
            TLADM_Departments     Depts = null;
            TLDYE_DyeTransactions dt    = null;

            if (oBtn != null && formloaded)
            {
                var errorM = core.returnMessage(MandSelected, true, MandatoryFields);
                if (!string.IsNullOrEmpty(errorM))
                {
                    MessageBox.Show(errorM);
                    return;
                }

                var selected = (TLDYE_DyeBatch)cmboDyeBatches.SelectedItem;

                using (var context = new TTI2Entities())
                {
                    var LNU = context.TLADM_LastNumberUsed.Find(3);
                    if (LNU != null)
                    {
                        LNU.col6 += 1;
                    }


                    var TotalWeight = 0.00M;

                    //--------- first attend to current records
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if ((bool)row.Cells[1].Value == false)
                        {
                            continue;
                        }

                        Weight = (decimal)row.Cells[3].Value;

                        TotalWeight += Weight;

                        var Pk = (int)row.Cells[0].Value;
                        if (Pk != 0)
                        {
                            var Record = context.TLDYE_DyeBatchDetails.Find(Pk);
                            if (Record != null)
                            {
                                Record.DYEBO_AdjustedWeight = Weight;
                                Record.DYEBO_TransactionNo  = txtNumber.Text;
                                Record.DYEBO_WriteOff       = true;
                                Depts = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("DYE")).FirstOrDefault();
                                if (Depts != null)
                                {
                                    TT = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Depts.Dep_Id && x.TrxT_Number == 1000).FirstOrDefault();
                                    if (TT != null)
                                    {
                                        Record.DYEBO_CurrentStore_FK = (int)TT.TrxT_ToWhse_FK;
                                        CurrentStore_FK = (int)TT.TrxT_ToWhse_FK;
                                    }
                                }
                            }
                        }
                    }


                    dt = new TLDYE_DyeTransactions();
                    dt.TLDYET_BatchNo            = selected.DYEB_BatchNo;
                    dt.TLDYET_Date               = DateTime.Now;
                    dt.TLDYET_SequenceNo         = selected.DYEB_SequenceNo;
                    dt.TLDYET_CurrentStore_FK    = CurrentStore_FK;
                    dt.TLDYET_TransactionWeight  = TotalWeight;
                    dt.TLDYET_AuthorisedBy       = txtApprovedBy.Text;
                    dt.TLDYET_Adjustment_Reasons = txtReasons.Text;
                    dt.TLDYET_TransactionType    = TT.TrxT_Pk;
                    dt.TLDYET_BatchWeight        = selected.DYEB_BatchKG;
                    dt.TLDYET_Batch_FK           = selected.DYEB_Pk;
                    dt.TLDYET_TransactionNumber  = txtNumber.Text;

                    context.TLDYE_DyeTransactions.Add(dt);

                    //---------------------------------------------------------------------
                    // This is the daily log file that needs to be updated
                    //-------------------------------------------------------

                    string Mach_IP = Dns.GetHostEntry(Dns.GetHostName())
                                     .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork)
                                     .ToString();

                    TLADM_DailyLog DailyLog = new TLADM_DailyLog();
                    DailyLog.TLDL_IPAddress    = Mach_IP;
                    DailyLog.TLDL_Dept_Fk      = Depts.Dep_Id;
                    DailyLog.TLDL_Date         = DateTime.Now;
                    DailyLog.TLDL_TransDetail  = "Dye House Adjustment";
                    DailyLog.TLDL_AuthorisedBy = txtApprovedBy.Text;
                    DailyLog.TLDL_Comments     = txtNumber.Text;

                    context.TLADM_DailyLog.Add(DailyLog);

                    try
                    {
                        context.SaveChanges();
                        MessageBox.Show("Data successfully stored to database");
                        frmDyeViewReport vRep = new frmDyeViewReport(15, dt.TLDYET_Pk);
                        vRep.ShowDialog(this);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;
            TLDYE_DyeTransactions         trns         = new TLDYE_DyeTransactions();
            IList <TLDYE_DyeBatchDetails> BatchDetails = new List <TLDYE_DyeBatchDetails>();

            if (oBtn != null && formloaded)
            {
                var DB = (TLDYE_DyeBatch)cmboBatchNumber.SelectedItem;
                if (DB == null)
                {
                    MessageBox.Show("Please select a dye batch from the drop down list");
                    return;
                }

                var OP = (TLADM_MachineOperators)cmboOperator.SelectedItem;
                if (OP == null)
                {
                    MessageBox.Show("Please select an operator from the drop down list");
                    return;
                }


                var GP = (TLKNI_GreigeProduction)oCmboPieceNumber.SelectedItem;
                if (GP == null)
                {
                    MessageBox.Show("Please cselect a piece number from the drop down box");
                    return;
                }

                using (var context = new TTI2Entities())
                {
                    if (_StabAfterDrying)
                    {
                        trns = context.TLDYE_DyeTransactions.Where(x => x.TLDYET_Batch_FK == DB.DYEB_Pk && x.TLDYET_Stage == 4).FirstOrDefault();
                    }
                    else
                    {
                        trns = context.TLDYE_DyeTransactions.Where(x => x.TLDYET_Batch_FK == DB.DYEB_Pk && x.TLDYET_Stage == 5).FirstOrDefault();
                    }

                    if (trns == null)
                    {
                        trns = new TLDYE_DyeTransactions();
                        trns.TLDYET_BatchNo     = DB.DYEB_BatchNo;
                        trns.TLDYET_BatchWeight = DB.DYEB_BatchKG;
                        trns.TLDYET_Date        = DateTime.Now;
                        trns.TLDYET_SequenceNo  = DB.DYEB_SequenceNo;
                        trns.TLDYET_Batch_FK    = DB.DYEB_Pk;
                        if (_StabAfterDrying)
                        {
                            trns.TLDYET_Stage = 4;
                        }
                        else
                        {
                            trns.TLDYET_Stage = 5;
                        }

                        if (rbPassYes.Checked)
                        {
                            trns.TLDYET_Rejected = false;
                        }
                        else
                        {
                            trns.TLDYET_Rejected   = true;
                            trns.TLDYET_RejectDate = DateTime.Now;
                        }

                        var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("DYE")).FirstOrDefault();
                        if (Dept != null)
                        {
                            var TT = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 400).FirstOrDefault();
                            if (TT != null)
                            {
                                trns.TLDYET_TransactionType = TT.TrxT_Pk;
                                trns.TLDYET_CurrentStore_FK = (int)TT.TrxT_ToWhse_FK;
                            }
                        }

                        context.TLDYE_DyeTransactions.Add(trns);
                    }


                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        TLDYE_NonComplianceAnalysis nca = new TLDYE_NonComplianceAnalysis();

                        Add = true;

                        nca.TLDYEDC_Code_FK     = (int)row.Cells[0].Value;
                        nca.TLDYEDC_BatchNo     = DB.DYEB_Pk;
                        nca.TLDYEDC_Operator_FK = (int)cmboOperator.SelectedValue;
                        nca.TLDYEDC_PieceNo_FK  = GP.GreigeP_Pk;

                        if (rbPassYes.Checked)
                        {
                            nca.TLDYEDC_Pass = true;
                        }
                        else
                        {
                            nca.TLDYEDC_Pass = false;
                        }

                        nca.TLDYEDC_Date = DateTime.Now;

                        if (_StabAfterDrying)
                        {
                            nca.TLDYEDC_NCStage = 4;
                        }
                        else
                        {
                            nca.TLDYEDC_NCStage = 5;
                        }

                        nca.TLDYEDC_Value = (decimal)row.Cells[2].Value;

                        if (Add)
                        {
                            context.TLDYE_NonComplianceAnalysis.Add(nca);
                        }
                    }


                    if (rbPassYes.Checked)
                    {
                        var DBatch = context.TLDYE_DyeBatch.Find(DB.DYEB_Pk);
                        if (DBatch != null)
                        {
                            if (_StabAfterDrying)
                            {
                                DBatch.DYEB_Stage2 = true;
                            }
                            else
                            {
                                DBatch.DYEB_Stage3 = true;
                            }
                        }
                    }

                    try
                    {
                        context.SaveChanges();
                        MessageBox.Show("Data saved to database successfully");
                        SetUp(false);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button  oBtn   = sender as Button;
            Decimal Weight = 0.00M;

            TLADM_TranactionType trantype = null;

            if (oBtn != null && formloaded)
            {
                var Select = (TLDYE_DyeBatch)cmboBatchNumber.SelectedItem;
                if (Select == null)
                {
                    MessageBox.Show("Please select a Batch number from the drop down box");
                    return;
                }


                int SingleRow = (from Rows in dataGridView1.Rows.Cast <DataGridViewRow>()
                                 where ((Decimal)Rows.Cells[5].Value == 0.00M ||
                                        (Decimal)Rows.Cells[6].Value == 0.00M ||
                                        (Decimal)Rows.Cells[7].Value == 0.00M)
                                 select Rows).Count();
                if (SingleRow > 0)
                {
                    MessageBox.Show("There are incorrect values in the form. Please correct before saving");
                    return;
                }


                using (var context = new TTI2Entities())
                {
                    var DB = context.TLDYE_DyeBatch.Find(Select.DYEB_Pk);
                    if (DB != null)
                    {
                        DB.DYEB_OutProcess     = true;
                        DB.DYEB_OutProcessDate = DateTime.Now;
                    }

                    var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "DYE").FirstOrDefault();
                    if (Dept != null)
                    {
                        trantype = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 600).FirstOrDefault();
                    }

                    int Cnt = 0;

                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        TLDYE_DyeBatchDetails bd = new TLDYE_DyeBatchDetails();

                        if (row.Cells[0].Value == null)
                        {
                            continue;
                        }

                        int index = (int)row.Cells[0].Value;

                        bd = context.TLDYE_DyeBatchDetails.Find(index);
                        if (bd != null)
                        {
                            Weight += (decimal)row.Cells[5].Value;

                            bd.DYEBO_Nett       = (decimal)row.Cells[5].Value;
                            bd.DYEBO_DiskWeight = (decimal)row.Cells[6].Value;
                            bd.DYEBO_Width      = (decimal)row.Cells[7].Value;
                            bd.DYEBO_Meters     = (decimal)row.Cells[8].Value;
                            bd.DYEBO_TransDate  = dtpTransDate.Value;
                            bd.DYEBO_DyeDate    = dtpDyeDate.Value;
                            if (trantype != null)
                            {
                                bd.DYEBO_CurrentStore_FK = (int)trantype.TrxT_ToWhse_FK;
                            }

                            if (Convert.ToDecimal(row.Cells[5].Value.ToString()) != 0)
                            {
                                Cnt += 1;
                            }
                        }
                    }

                    int NoOfRecs = context.TLDYE_DyeBatchDetails.Where(x => x.DYEBD_DyeBatch_FK == DB.DYEB_Pk).ToList().Count;
                    if (Cnt == NoOfRecs)
                    {
                        DB.DYEB_Closed = true;
                    }

                    TLDYE_DyeTransactions tt = new TLDYE_DyeTransactions();
                    tt.TLDYET_BatchNo           = Select.DYEB_BatchNo;
                    tt.TLDYET_BatchWeight       = Select.DYEB_BatchKG;
                    tt.TLDYET_TransactionType   = (int)trantype.TrxT_Pk;
                    tt.TLDYET_SequenceNo        = Select.DYEB_SequenceNo;
                    tt.TLDYET_Batch_FK          = Select.DYEB_Pk;
                    tt.TLDYET_Date              = dtpTransDate.Value;
                    tt.TLDYET_TransactionWeight = Weight;
                    tt.TLDYET_CurrentStore_FK   = (int)trantype.TrxT_ToWhse_FK;

                    context.TLDYE_DyeTransactions.Add(tt);

                    try
                    {
                        context.SaveChanges();
                        MessageBox.Show("Data successfully saved to the database");
                        Setup();
                    }
                    catch (System.Data.Entity.Validation.DbEntityValidationException en)
                    {
                        foreach (var eve in en.EntityValidationErrors)
                        {
                            MessageBox.Show("following validation errors: Type" + eve.Entry.Entity.GetType().Name.ToString() + "State " + eve.Entry.State.ToString());
                            foreach (var ve in eve.ValidationErrors)
                            {
                                MessageBox.Show("- Property" + ve.PropertyName + " Message " + ve.ErrorMessage);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }