Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;
            bool   Add  = false;
            TLCUT_CutSheetReceipt CSR = null;

            if (oBtn != null)
            {
                if (dataGridView1.Rows.Count < Convert.ToInt32(txtBundles.Text))
                {
                    MessageBox.Show("Please complete the form correctly");
                    return;
                }

                var selected = (TLCUT_CutSheet)cmboCutSheet.SelectedItem;
                if (selected != null)
                {
                    var Machine = (TLADM_MachineDefinitions)cmboMachines.SelectedItem;
                    if (Machine == null)
                    {
                        MessageBox.Show("Please select a machine on which this cutsheet was cut");
                        return;
                    }
                    using (var context = new TTI2Entities())
                    {
                        var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("CUT")).FirstOrDefault();

                        var CS = context.TLCUT_CutSheet.Find(selected.TLCutSH_Pk);
                        if (CS != null)
                        {
                            CS.TLCutSH_WIPComplete = true;
                            CS.TLCUTSH_AddNotes    = string.Empty;
                        }
                        CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == selected.TLCutSH_Pk).FirstOrDefault();
                        if (CSR == null)
                        {
                            Add = true;
                            CSR = new TLCUT_CutSheetReceipt();
                        }

                        CSR.TLCUTSHR_Style_FK      = selected.TLCutSH_Styles_FK;
                        CSR.TLCUTSHR_CutSheet_FK   = selected.TLCutSH_Pk;
                        CSR.TLCUTSHR_Date          = dtpTransDate.Value;
                        CSR.TLCUTSHR_NoOfBundles   = Convert.ToInt32(txtBundles.Text);
                        CSR.TLCUTSHR_Machine_FK    = Machine.MD_Pk;
                        CSR.TLCUTSHR_InBundleStore = true;
                        if (CSR.TLCUTSHR_InBundleStore)
                        {
                            var CutStore = context.TLADM_WhseStore.Where(x => x.WhStore_DepartmentFK == CS.TLCutSH_Department_FK && x.WhStore_BundleStore).FirstOrDefault();
                            if (CutStore != null)
                            {
                                CSR.TLCUTSHR_WhseBunStore_FK  = CutStore.WhStore_Id;
                                CSR.TLCUTSHR_DateIntoBunStore = dtpTransDate.Value;
                            }
                        }
                        if (Add)
                        {
                            context.TLCUT_CutSheetReceipt.Add(CSR);
                        }

                        try
                        {
                            context.SaveChanges();
                        }
                        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);
                        }


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

                            TLCUT_CutSheetReceiptDetail CSRD = new TLCUT_CutSheetReceiptDetail();

                            Add = true;
                            if ((int)row.Cells[0].Value != 0)
                            {
                                var index = (int)row.Cells[0].Value;
                                CSRD = context.TLCUT_CutSheetReceiptDetail.Find(index);

                                if (CSRD != null)
                                {
                                    Add = false;
                                }
                                else
                                {
                                    CSRD = new TLCUT_CutSheetReceiptDetail();
                                }
                            }

                            CSRD.TLCUTSHRD_CutSheet_FK   = CSR.TLCUTSHR_Pk;
                            CSRD.TLCUTSHRD_Description   = (String)row.Cells[1].Value;
                            CSRD.TLCUTSHRD_Size_FK       = (int)row.Cells[2].Value;
                            CSRD.TLCUTSHRD_BundleQty     = (int)row.Cells[3].Value;
                            CSRD.TLCUTSHRD_InBundleStore = true;

                            if (Dept != null)
                            {
                                var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 200).FirstOrDefault();
                                if (TranType != null)
                                {
                                    CSRD.TLCUTSHRD_TransactionType = TranType.TrxT_Pk;
                                    CSRD.TLCUTSHRD_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK;
                                }
                            }

                            if (Add)
                            {
                                context.TLCUT_CutSheetReceiptDetail.Add(CSRD);
                            }
                        }

                        TLCUT_CutSheetReceiptBoxes CSRB = new TLCUT_CutSheetReceiptBoxes();
                        CSRB = context.TLCUT_CutSheetReceiptBoxes.Where(x => x.TLCUTSHB_CutSheet_FK == CSR.TLCUTSHR_Pk).FirstOrDefault();

                        Add = false;
                        if (CSRB == null)
                        {
                            CSRB = new TLCUT_CutSheetReceiptBoxes();
                            Add  = true;
                        }

                        CSRB.TLCUTSHB_CutSheet_FK = CSR.TLCUTSHR_Pk;

                        if (!String.IsNullOrEmpty(txtAdultBoxes.Text))
                        {
                            CSRB.TLCUTSHB_AdultBoxes = Convert.ToInt32(txtAdultBoxes.Text);
                        }
                        else
                        {
                            CSRB.TLCUTSHB_AdultBoxes = 0;
                        }

                        if (!String.IsNullOrEmpty(txtKidsBoxes.Text))
                        {
                            CSRB.TLCUTSHB_KidBoxes = Convert.ToInt32(txtKidsBoxes.Text);
                        }
                        else
                        {
                            CSRB.TLCUTSHB_KidBoxes = 0;
                        }

                        if (!String.IsNullOrEmpty(txtBinding.Text))
                        {
                            CSRB.TLCUTSHB_Binding = Convert.ToInt32(txtBinding.Text);
                        }
                        else
                        {
                            CSRB.TLCUTSHB_Binding = 0;
                        }

                        if (!String.IsNullOrEmpty(txtRibbing.Text))
                        {
                            CSRB.TLCUTSHB_Ribbing = Convert.ToInt32(txtRibbing.Text);
                        }
                        else
                        {
                            CSRB.TLCUTSHB_Ribbing = 0;
                        }


                        if (Add)
                        {
                            context.TLCUT_CutSheetReceiptBoxes.Add(CSRB);
                        }

                        try
                        {
                            context.SaveChanges();
                            MessageBox.Show("Data saved successfully to database");
                            dataGridView1.Rows.Clear();
                            dataGridView2.Rows.Clear();
                            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);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool Update = false;

            Button oBtn = sender as Button;

            if (oBtn != null && formloaded)
            {
                var selected = (TLCUT_CutSheet)cmboCutSheet.SelectedItem;
                if (selected == null)
                {
                    MessageBox.Show("Please select a cut sheet from the drop down list ");
                    return;
                }

                var WhseSelected = (TLADM_WhseStore)cmboRejectStore.SelectedItem;
                if (WhseSelected == null)
                {
                    MessageBox.Show("Please select a reject store from the drop down list");
                    return;
                }

                if (String.IsNullOrEmpty(txtAuthorisedBy.Text))
                {
                    MessageBox.Show("Please complete the approved by details");
                    return;
                }

                using (var context = new TTI2Entities())
                {
                    var CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == selected.TLCutSH_Pk).FirstOrDefault();

                    CutReportOptions cropts = new CutReportOptions();
                    cropts.remarks    = rtbNotes.Text;
                    cropts.TransDate  = dtpTransDate.Value;
                    cropts.ApprovedBy = txtAuthorisedBy.Text;
                    cropts.Pk         = CSR.TLCUTSHR_Pk;
                    cropts.CutSheetPk = selected.TLCutSH_Pk;
                    cropts.ReturnedTo = context.TLADM_WhseStore.Find(WhseSelected.WhStore_Id).WhStore_Description;

                    var cs = context.TLCUT_CutSheet.Find(selected.TLCutSH_Pk);
                    if (cs != null)
                    {
                        cs.TLCutSH_Notes = rtbNotes.Text;
                    }

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

                        //------------------------------------------------------
                        // 1st Step reduce the SOH with what was written off
                        //-----------------------------------------------------------
                        var index = (int)row.Cells[0].Value;
                        var CSRD  = context.TLCUT_CutSheetReceiptDetail.Find(index);
                        if (CSRD != null)
                        {
                            CSRD.TLCUTSHRD_RejectQty   += (int)row.Cells[6].Value;
                            CSRD.TLCUTSHRD_RejectDate   = dtpTransDate.Value;
                            CSRD.TLCUTSHRD_RejectReason = (int)row.Cells[5].Value;
                        }

                        //-------------------------------------------------
                        // Now create a new Record of the written off value
                        //---------------------------------------------------
                        TLCUT_CutSheetReceiptDetail NewCSR = new TLCUT_CutSheetReceiptDetail();
                        NewCSR.TLCUTSHRD_CutSheet_FK     = CSR.TLCUTSHR_Pk;
                        NewCSR.TLCUTSHRD_Description     = row.Cells[2].Value.ToString() + "R";
                        NewCSR.TLCUTSHRD_Size_FK         = (int)row.Cells[3].Value;
                        NewCSR.TLCUTSHRD_BundleQty       = (int)row.Cells[4].Value;
                        NewCSR.TLCUTSHRD_BoxUnits        = 0;
                        NewCSR.TLCUTSHRD_TransactionType = 55;
                        NewCSR.TLCUTSHRD_CurrentStore_FK = WhseSelected.WhStore_Id;
                        NewCSR.TLCUTSHRD_PanelRejected   = true;
                        NewCSR.TLCUTSHRD_RejectDate      = dtpTransDate.Value;
                        NewCSR.TLCUTSHRD_RejectQty       = (int)row.Cells[6].Value;
                        NewCSR.TLCUTSHRD_RejectReason    = (int)row.Cells[5].Value;

                        context.TLCUT_CutSheetReceiptDetail.Add(NewCSR);

                        Update = true;
                    }

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

                    var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("CUT")).FirstOrDefault();

                    TLADM_DailyLog DailyLog = new TLADM_DailyLog();
                    DailyLog.TLDL_IPAddress    = Mach_IP;
                    DailyLog.TLDL_Dept_Fk      = Dept.Dep_Id;
                    DailyLog.TLDL_Date         = DateTime.Now;
                    DailyLog.TLDL_TransDetail  = "Cutting Dept Panel Rejected";
                    DailyLog.TLDL_AuthorisedBy = txtAuthorisedBy.Text;;
                    DailyLog.TLDL_Comments     = rtbNotes.Text;
                    context.TLADM_DailyLog.Add(DailyLog);

                    //----------------------------------------------------------
                    if (Update)
                    {
                        try
                        {
                            context.SaveChanges();
                            MessageBox.Show("Data saved successfully to database");
                            frmCutViewRep vRep = new frmCutViewRep(3, cropts);
                            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);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;
            TLCUT_CutSheetReceipt CSR = null;

            if (oBtn != null && formloaded)
            {
                using (var context = new TTI2Entities())
                {
                    var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("CUT")).FirstOrDefault();

                    if (CutSheetSelected != 0)
                    {
                        CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == CutSheetSelected).FirstOrDefault();
                        if (CSR != null)
                        {
                            CSR.TLCUTSHR_InBundleStore      = false;
                            CSR.TLCUTSHR_InPanelStore       = true;
                            CSR.TLCUTSHR_DateIntoPanelStore = dtpTransActionDate.Value;

                            var CS = context.TLCUT_CutSheet.Find(CSR.TLCUTSHR_CutSheet_FK);
                            if (CS != null)
                            {
                                if (rtbAdditional.Text.Length != 0)
                                {
                                    CS.TLCUTSH_AddNotes = rtbAdditional.Text;
                                }

                                CS.TLCUTSH_Completed_Date = DateTime.Now;
                                CSR.TLCUTSHR_Colour_FK    = CS.TLCutSH_Colour_FK;
                                var CutStore = context.TLADM_WhseStore.Where(x => x.WhStore_DepartmentFK == CS.TLCutSH_Department_FK && x.WhStore_PanelStore).FirstOrDefault();
                                if (CutStore != null)
                                {
                                    CSR.TLCUTSHR_WhsePanStore_FK    = CutStore.WhStore_Id;
                                    CSR.TLCUTSHR_DateIntoPanelStore = dtpTransActionDate.Value;
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please select a cutsheet from the drop down box");
                        return;
                    }

                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        TLCUT_CutSheetReceiptDetail CSRD = new TLCUT_CutSheetReceiptDetail();

                        var index = (int)row.Cells[0].Value;
                        CSRD = context.TLCUT_CutSheetReceiptDetail.Find(index);

                        if (CSRD != null)
                        {
                            CSRD.TLCUTSHRD_BoxNumber = dataGridView1.Rows[row.Index].Cells[3].Value.ToString();
                            if ((int)dataGridView1.Rows[row.Index].Cells[4].Value == 0)
                            {
                                continue;
                            }

                            CSRD.TLCUTSHRD_BoxUnits      = (int)dataGridView1.Rows[row.Index].Cells[4].Value;
                            CSRD.TLCUTSHRD_BoxType_FK    = 1; // removed to speed up data capture (int)dataGridView1.Rows[row.Index].Cells[5].Value;
                            CSRD.TLCUTSHRD_InBundleStore = false;
                            CSRD.TLCUTSHRD_PanelDate     = dtpTransActionDate.Value;

                            if (Dept != null)
                            {
                                var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 600).FirstOrDefault();
                                if (TranType != null)
                                {
                                    CSRD.TLCUTSHRD_TransactionType = TranType.TrxT_Pk;
                                    CSRD.TLCUTSHRD_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK;
                                }
                            }
                        }
                    }

                    var CSB = context.TLCUT_CutSheetReceiptBoxes.Where(x => x.TLCUTSHB_Pk == CSR.TLCUTSHR_Pk).FirstOrDefault();
                    if (CSB != null)
                    {
                        int value = 0;
                        if (int.TryParse(txtAdultBoxes.Text, out value))
                        {
                            CSB.TLCUTSHB_AdultBoxes = value;
                        }


                        value = 0;
                        if (int.TryParse(txtBinding.Text, out value))
                        {
                            CSB.TLCUTSHB_Binding = value;
                        }

                        value = 0;
                        if (int.TryParse(txtKidsBoxes.Text, out value))
                        {
                            CSB.TLCUTSHB_KidBoxes = value;
                        }
                        value = 0;
                        if (int.TryParse(txtRibbing.Text, out value))
                        {
                            CSB.TLCUTSHB_Ribbing = value;
                        }
                    }

                    try
                    {
                        context.SaveChanges();
                        MessageBox.Show("Data saved successfully to database");
                        dataGridView1.Rows.Clear();

                        //This form is the summary form for Mary in the accessories store
                        //===================================================
                        frmCutViewRep vRep = new frmCutViewRep(11, CutSheetSelected);
                        int           h    = Screen.PrimaryScreen.WorkingArea.Height;
                        int           w    = Screen.PrimaryScreen.WorkingArea.Width;
                        vRep.ClientSize = new Size(w, h);
                        vRep.ShowDialog();

                        //This form is the CMT Issued to line document
                        //==============================================================
                        vRep            = new frmCutViewRep(14, CutSheetSelected);
                        h               = Screen.PrimaryScreen.WorkingArea.Height;
                        w               = Screen.PrimaryScreen.WorkingArea.Width;
                        vRep.ClientSize = new Size(w, h);
                        vRep.ShowDialog();
                    }
                    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);
                    }
                }
            }
        }