예제 #1
0
        private void cmboCurrentPI_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox oCmbo = sender as ComboBox;
            TLCMT_PanelIssueDetail result = null;

            if (oCmbo != null && formloaded)
            {
                using (var context = new TTI2Entities())
                {
                    dataGridView1.Rows.Clear();

                    var selected = (TLCMT_PanelIssue)cmboCurrentPI.SelectedItem;
                    if (selected != null)
                    {
                        cmboCMTDepartment.SelectedValue = selected.CMTPI_Department_FK;
                        label1.Text = selected.CMTPI_Number.ToString();

                        var Current = context.TLCMT_PanelIssueDetail.Where(x => x.CMTPID_PI_FK == selected.CMTPI_Pk).ToList();

                        var Existing = context.TLCUT_CutSheetReceipt.ToList();
                        foreach (var CutSheetR in Existing)
                        {
                            result = (from u in Current
                                      where u.CMTPID_CutSheet_FK == CutSheetR.TLCUTSHR_Pk
                                      select u).FirstOrDefault();

                            if (CutSheetR.TLCUTSHR_Issued && result == null)
                            {
                                continue;
                            }

                            var index = dataGridView1.Rows.Add();

                            if (result == null)
                            {
                                dataGridView1.Rows[index].Cells[0].Value = 0;
                            }
                            else
                            {
                                dataGridView1.Rows[index].Cells[0].Value = result.CMTPID_Pk;
                            }

                            dataGridView1.Rows[index].Cells[1].Value = CutSheetR.TLCUTSHR_Pk;
                            if (CutSheetR.TLCUTSHR_Issued)
                            {
                                dataGridView1.Rows[index].Cells[2].Value = true;
                            }
                            else
                            {
                                dataGridView1.Rows[index].Cells[2].Value = false;
                            }

                            //-------------------------------------------------------
                            //find the Original CutSheet
                            //--------------------------------------------------
                            var CS = context.TLCUT_CutSheet.Find(CutSheetR.TLCUTSHR_CutSheet_FK);
                            if (CS != null)
                            {
                                dataGridView1.Rows[index].Cells[3].Value = "CS" + CS.TLCutSH_No.Remove(0, 2).ToString();
                            }

                            dataGridView1.Rows[index].Cells[4].Value = CutSheetR.TLCUTSHR_Date.ToShortDateString();
                            var xColour = context.TLADM_Colours.Find(CutSheetR.TLCUTSHR_Colour_FK);
                            if (xColour != null)
                            {
                                dataGridView1.Rows[index].Cells[5].Value = xColour.Col_Display;
                            }

                            if (CutSheetR.TLCUTSHR_Issued)
                            {
                                var Grp = context.TLCUT_CutSheetReceiptDetail.Where(x => x.TLCUTSHRD_CutSheet_FK == CutSheetR.TLCUTSHR_Pk);
                                if (Grp.Count() != 0)
                                {
                                    // dataGridView1.Rows[index].Cells[10].Value = Grp.Sum(x => x.TLCUTSHRD_BoxUnits);
                                    txtPanels.Text = (Convert.ToInt32(txtPanels.Text) + Grp.Sum(x => x.TLCUTSHRD_BoxUnits)).ToString();
                                }
                                var Boxes = context.TLCUT_CutSheetReceiptBoxes.Where(x => x.TLCUTSHB_CutSheet_FK == CutSheetR.TLCUTSHR_Pk).FirstOrDefault();
                                if (Boxes != null)
                                {
                                    int TotalBoxes = Convert.ToInt32(txtTotalBoxes.Text);
                                    txtAdultsBoxes.Text = (Convert.ToInt32(txtAdultsBoxes.Text) + Boxes.TLCUTSHB_AdultBoxes).ToString();
                                    TotalBoxes         += Boxes.TLCUTSHB_AdultBoxes;
                                    txtKidsBoxes.Text   = (Convert.ToInt32(txtKidsBoxes.Text) + Boxes.TLCUTSHB_KidBoxes).ToString();
                                    TotalBoxes         += Boxes.TLCUTSHB_KidBoxes;
                                    txtTotalBoxes.Text  = TotalBoxes.ToString();
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #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());
                    }
                }
            }
        }