Пример #1
0
        private void cmboPanelIssue_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox oCmbo = (ComboBox)sender;

            if (oCmbo != null && FormLoaded)
            {
                if (dataGridView1.Rows.Count != 0)
                {
                    dataGridView1.Rows.Clear();
                }

                using (var context = new TTI2Entities())
                {
                    var SelectedItem = (TLCMT_PanelIssue)oCmbo.SelectedItem;
                    if (SelectedItem != null)
                    {
                        TLCMT_PanelIssue pi = context.TLCMT_PanelIssue.Find(SelectedItem.CMTPI_Pk);
                        if (pi != null)
                        {
                            var pidetail = context.TLCMT_PanelIssueDetail.Where(x => x.CMTPID_PI_FK == pi.CMTPI_Pk).ToList();
                            foreach (var item in pidetail)
                            {
                                var index = dataGridView1.Rows.Add();
                                dataGridView1.Rows[index].Cells[1].Value = false;
                                var CutSheetReceipt = context.TLCUT_CutSheetReceipt.Find(item.CMTPID_CutSheet_FK);
                                dataGridView1.Rows[index].Cells[2].Value = context.TLCUT_CutSheet.Find(CutSheetReceipt.TLCUTSHR_CutSheet_FK).TLCutSH_No;
                                dataGridView1.Rows[index].Cells[0].Value = context.TLCUT_CutSheet.Find(CutSheetReceipt.TLCUTSHR_CutSheet_FK).TLCutSH_Pk;
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;
            TLADM_LastNumberUsed   LNU = null;
            TLCMT_PanelIssue       pi  = new TLCMT_PanelIssue();
            TLCMT_PanelIssueDetail pid = new TLCMT_PanelIssueDetail();
            TLCUT_CutSheetReceipt  CSR = new TLCUT_CutSheetReceipt();
            bool Add = false;

            if (oBtn != null && formloaded)
            {
                var selected = (TLADM_Departments)cmboCMTDepartment.SelectedItem;
                if (selected == null)
                {
                    MessageBox.Show("Please select a CMT from the drop downlist");
                    return;
                }

                if (((TLADM_WhseStore)cmboDepartments.SelectedItem) == null)
                {
                    MessageBox.Show("Please select Store from which to make an selection");
                    return;
                }

                using (var context = new TTI2Entities())
                {
                    int Number = Convert.ToInt32(label1.Text);
                    pi = context.TLCMT_PanelIssue.Where(x => x.CMTPI_Number == Number).FirstOrDefault();
                    if (pi == null)
                    {
                        pi  = new TLCMT_PanelIssue();
                        Add = true;
                    }

                    pi.CMTPI_Number          = Number;
                    pi.CMTPI_Date            = dtpTransDate.Value;
                    pi.CMTPI_Department_FK   = selected.Dep_Id;
                    pi.CMTPI_Closed          = false;
                    pi.CMTPI_DeliveryNumber  = 0;
                    pi.CMTPI_CutSheetSummary = false;
                    pi.CMTPI_FromWhse_FK     = ((TLADM_WhseStore)cmboDepartments.SelectedItem).WhStore_Id;

                    var TransType = context.TLADM_TranactionType.Where(x => x.TrxT_Number == 100 && x.TrxT_Department_FK == selected.Dep_Id).FirstOrDefault();
                    if (TransType != null)
                    {
                        pi.CMTPI_TranType_FK = TransType.TrxT_Pk;
                    }
                    pi.CMTPI_Display = "DN -" + "0".PadLeft(4, ' ') + " - TL " + Number.ToString().PadLeft(5, '0');

                    if (Add)
                    {
                        context.TLCMT_PanelIssue.Add(pi);
                    }

                    if (Add && selected != null)
                    {
                        LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == selected.Dep_Id).FirstOrDefault();
                        if (LNU != null)
                        {
                            LNU.col1 += 1;
                        }
                    }

                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }

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

                        Add = true;
                        pid = new TLCMT_PanelIssueDetail();
                        if ((int)row.Cells[0].Value != 0)
                        {
                            var index = (int)row.Cells[0].Value;
                            pid = context.TLCMT_PanelIssueDetail.Find(index);
                            if (pid == null)
                            {
                                pid = new TLCMT_PanelIssueDetail();
                            }
                            else
                            {
                                Add = false;
                            }
                        }
                        //--------------------------------------------------------
                        pid.CMTPID_CutSheet_FK = (int)row.Cells[1].Value;
                        pid.CMTPID_PI_FK       = pi.CMTPI_Pk;
                        pid.CMTPID_Receipted   = false;
                        pid.CMTPID_BIFabric    = false;

                        CSR = context.TLCUT_CutSheetReceipt.Find(pid.CMTPID_CutSheet_FK);
                        if (CSR != null)
                        {
                            CSR.TLCUTSHR_Issued = true;
                        }

                        if (Add)
                        {
                            context.TLCMT_PanelIssueDetail.Add(pid);
                        }
                    }

                    try
                    {
                        var SelectedRows = (
                            from Rows in dataGridView1.Rows.Cast <DataGridViewRow>()
                            where (bool)Rows.Cells[2].Value == true
                            select Rows).ToList();

                        foreach (var SelectedRow in SelectedRows)
                        {
                            var index = SelectedRow.Index;
                            dataGridView1.Rows.RemoveAt(index);
                        }

                        context.SaveChanges();
                        MessageBox.Show("Data saved successfully to to database");

                        //This report has been housed in the the Cutting Form View Program....
                        Cutting.frmCutViewRep vRep = new Cutting.frmCutViewRep(12, pi.CMTPI_Pk);
                        int h = Screen.PrimaryScreen.WorkingArea.Height;
                        int 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)
                    {
                        var exceptionMessages = new StringBuilder();
                        do
                        {
                            exceptionMessages.Append(ex.Message);
                            ex = ex.InnerException;
                        }while (ex != null);
                        MessageBox.Show(exceptionMessages.ToString());
                    }
                }
            }
        }
Пример #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn         = sender as Button;
            bool   UpDateHeader = true;

            if (oBtn != null && formloaded)
            {
                var LNSelected = (TLADM_WhseStore)cmboStoreFacilities.SelectedItem;
                if (LNSelected == null)
                {
                    MessageBox.Show("Please select a store");
                    return;
                }

                TLCMT_PanelIssue PIselected = (TLCMT_PanelIssue)cmboDelivery.SelectedItem;

                using (var context = new TTI2Entities())
                {
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        var CutSheetPk = (int)row.Cells[0].Value;

                        if ((bool)row.Cells[2].Value == false)
                        {
                            DialogResult Res = MessageBox.Show("Warning . This cutsheet not selected. Will be sent back to originating Panel Store", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (Res == DialogResult.Yes)
                            {
                                var CutSheetReceipt = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == CutSheetPk).FirstOrDefault();
                                if (CutSheetReceipt != null)
                                {
                                    CutSheetReceipt.TLCUTSHR_InPanelStore  = true;
                                    CutSheetReceipt.TLCUTSHR_Issued        = false;
                                    CutSheetReceipt.TLCUTSHR_InReceiptCage = false;
                                }
                                UpDateHeader = false;
                                continue;
                            }
                        }

                        TLCMT_LineIssue li = new TLCMT_LineIssue();
                        li.TLCMTLI_Date           = dtpTransDate.Value;
                        li.TLCMTLI_CutSheet_FK    = CutSheetPk;
                        li.TLCMTLI_CmtFacility_FK = PIselected.CMTPI_Department_FK;
                        li.TLCMTLI_PanelIssue_FK  = PIselected.CMTPI_Pk;
                        li.TLCMTLI_WhStore_FK     = LNSelected.WhStore_Id;
                        li.TLCMTLI_Required_Date  = dtpTransDate.Value.AddDays(7);
                        li.TLCMTLI_PanelIssue_FK  = PIselected.CMTPI_Pk;
                        try
                        {
                            li.TLCMTLI_IssueQty = int.Parse(row.Cells[5].Value.ToString());
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }

                        //---------------------------------------
                        // this is to ensure that the record is only added once to the table
                        //-------------------------------------------------------------------------------
                        var AlreadyIssued = context.TLCMT_LineIssue.Where(x => x.TLCMTLI_CutSheet_FK == CutSheetPk).FirstOrDefault();
                        if (AlreadyIssued == null)
                        {
                            context.TLCMT_LineIssue.Add(li);
                        }

                        var CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == CutSheetPk).FirstOrDefault();
                        if (CSR != null)
                        {
                            CSR.TLCUTSHR_InReceiptCage = true;

                            var PanIssueDetail = context.TLCMT_PanelIssueDetail.Where(X => X.CMTPID_CutSheet_FK == CSR.TLCUTSHR_Pk).FirstOrDefault();
                            if (PanIssueDetail != null)
                            {
                                PanIssueDetail.CMTPID_Receipted = true;
                            }
                        }
                    }

                    if (UpDateHeader)
                    {
                        PIselected = context.TLCMT_PanelIssue.Find(PIselected.CMTPI_Pk);
                        if (PIselected != null)
                        {
                            PIselected.CMTPI_Receipted = true;
                        }
                    }

                    try
                    {
                        context.SaveChanges();
                        dataGridView1.Rows.Clear();

                        cmboStoreFacilities.SelectedIndex = -1;
                        cmboCMT.SelectedIndex             = -1;
                        TxtStoreFacilities.Text           = string.Empty;

                        MessageBox.Show("Data saved successfully to database");

                        DialogResult res = MessageBox.Show("Do you wish to print a full report", "All transactions", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        if (res == DialogResult.OK)
                        {
                            frmCMTViewRep vRep = new frmCMTViewRep(3, PIselected.CMTPI_Pk);
                            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);
                    }
                }
            }
        }