Beispiel #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;

            if (oBtn != null && formloaded)
            {
                var ErrM = core.returnMessage(MandSelected, false, MandatoryFields);
                if (!String.IsNullOrEmpty(ErrM))
                {
                    MessageBox.Show(ErrM);
                    return;
                }
                using (var context = new TTI2Entities())
                {
                    if (Add)
                    {
                        var LNU = context.TLADM_LastNumberUsed.Find(3);
                        if (LNU != null)
                        {
                            LNU.col4 += 1;
                        }
                    }

                    TLDYE_ComDyeBatch cb = new TLDYE_ComDyeBatch();
                    if (!Add)
                    {
                        var Prev = (TLDYE_ComDyeBatch)cmboPrevBatches.SelectedItem;
                        if (Prev != null)
                        {
                            cb = context.TLDYE_ComDyeBatch.Find(Prev.DYEBC_Pk);
                        }
                    }

                    cb.DYEBC_BatchDate    = dtpBatchDate.Value;
                    cb.DYEBC_BatchNo      = txtBatchNo.Text;
                    cb.DYEBC_DateOrder    = dtpDateOrdered.Value;
                    cb.DYEBC_DateRequired = dtpDateOrdered.Value;
                    cb.DYEBC_Greige_FK    = (int)cmboGreige.SelectedValue;
                    cb.DYEBC_Trim_Fk      = (int)cmboTrims.SelectedValue;
                    cb.DYEBC_Customer_FK  = (int)cmboCustomer.SelectedValue;
                    cb.DYEBC_Colour_FK    = (int)cmboColours.SelectedValue;

                    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)
                        {
                            cb.DYEBC_TransactionType = TranType.TrxT_Pk;
                        }
                    }

                    if (Add)
                    {
                        context.TLDYE_ComDyeBatch.Add(cb);
                        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)
                        {
                            var exceptionMessages = new StringBuilder();
                            do
                            {
                                exceptionMessages.Append(ex.Message);
                                ex = ex.InnerException;
                            }while (ex != null);

                            MessageBox.Show(exceptionMessages.ToString());
                        }
                    }

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

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

                        TLKNI_GreigeCommissionTransctions rec = context.TLKNI_GreigeCommissionTransctions.Find(index);
                        if (rec != null)
                        {
                            rec.GreigeCom_Batched     = true;
                            rec.GreigeCom_DyeBatch_FK = cb.DYEBC_Pk;
                        }

                        TLDYE_ComDyeBatchDetails cdb = new TLDYE_ComDyeBatchDetails();
                        cdb.TLCDD_PieceNo_FK     = rec.GreigeCom_PK;
                        cdb.TLCDD_ComDyeBatch_FK = cb.DYEBC_Pk;

                        context.TLDYE_ComDyeBatchDetails.Add(cdb);
                    }

                    try
                    {
                        context.SaveChanges();

                        MessageBox.Show("Data saved to database successfully");
                        frmDyeViewReport vrep = new frmDyeViewReport(9, cb.DYEBC_Pk);
                        vrep.ShowDialog(this);
                        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)
                    {
                        var exceptionMessages = new StringBuilder();
                        do
                        {
                            exceptionMessages.Append(ex.Message);
                            ex = ex.InnerException;
                        }while (ex != null);

                        MessageBox.Show(exceptionMessages.ToString());
                    }
                }
            }
        }
Beispiel #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;
            int    CLNU = 0;

            if (oBtn != null && formloaded)
            {
                var ErrorM = core.returnMessage(MandatorySelected, false, MandatoryFields);
                if (!String.IsNullOrEmpty(ErrorM))
                {
                    MessageBox.Show(ErrorM);
                    return;
                }
                using (var context = new TTI2Entities())
                {
                    var LNU = context.TLADM_LastNumberUsed.Find(2);
                    if (LNU != null)
                    {
                        LNU.col8 += 1;
                    }

                    var custSelected = (TLADM_CustomerFile)cmbCommissionC.SelectedItem;
                    var store        = (TLADM_WhseStore)cmbStore.SelectedItem;

                    if (custSelected != null)
                    {
                        CLNU = custSelected.Cust_LastNumberUsed;

                        custSelected = context.TLADM_CustomerFile.Find(custSelected.Cust_Pk);
                        custSelected.Cust_LastNumberUsed = CLNU + 1;
                    }

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

                        TLKNI_GreigeCommissionTransctions comTrans = new TLKNI_GreigeCommissionTransctions();
                        comTrans.GreigeCom_Custdoc        = txtCustDeliveryDoc.Text;
                        comTrans.GreigeCom_Customer_FK    = custSelected.Cust_Pk;
                        comTrans.GreigeCom_Comments       = txtComments.Text;
                        comTrans.GreigeCom_CustOrderNo    = (string)row.Cells[4].Value;
                        comTrans.GreigeCom_Grade          = (string)row.Cells[3].Value;
                        comTrans.GreigeCom_GrnNo          = CLNU;
                        comTrans.GreigeCom_NettWeight     = (decimal)row.Cells[5].Value;
                        comTrans.GreigeCom_PieceNo        = row.Cells[0].Value.ToString();
                        comTrans.GreigeCom_ProductType_FK = (int)row.Cells[2].Value;
                        comTrans.GreigeCom_Transdate      = dateTimePicker1.Value;
                        comTrans.GreigeCom_TTSNo          = (string)row.Cells[1].Value;
                        comTrans.GreigeCom_Store_FK       = store.WhStore_Id;
                        comTrans.GreigeCom_Display        = CLNU.ToString() + " " + txtCustDeliveryDoc.Text;
                        context.TLKNI_GreigeCommissionTransctions.Add(comTrans);

                        try
                        {
                            context.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                        }
                        //we need to store further information in a separate file for the processing in the Dye Module

                        TLKNI_GreigeProduction gp = new TLKNI_GreigeProduction();
                        gp.GreigeP_Captured = true;
                        //-----------------------------------------------------------
                        // gp.GreigeP_KnitO_Fk = CLNU;
                        //------------------------------------------------------
                        gp.GreigeP_KnitO_Fk          = comTrans.GreigeCom_PK;
                        gp.GreigeP_CommisionCust     = true;
                        gp.GreigeP_CommissionCust_FK = custSelected.Cust_Pk;
                        gp.GreigeP_Grade             = (string)row.Cells[3].Value;
                        gp.GreigeP_InspDate          = DateTime.Now;
                        gp.GreigeP_Inspected         = true;
                        gp.GreigeP_Meas1             = 0;
                        gp.GreigeP_Meas2             = 0;
                        gp.GreigeP_Meas3             = 0;
                        gp.GreigeP_Meas4             = 0;
                        gp.GreigeP_Meas5             = 0;
                        gp.GreigeP_Meas6             = 0;
                        gp.GreigeP_Meas7             = 0;
                        gp.GreigeP_Meas8             = 0;
                        gp.GreigeP_PDate             = DateTime.Now;
                        gp.GreigeP_PieceNo           = (string)row.Cells[0].Value;
                        gp.GreigeP_weight            = (decimal)row.Cells[5].Value;
                        gp.GreigeP_weightAvail       = (decimal)row.Cells[5].Value;
                        gp.GreigeP_Store_FK          = store.WhStore_Id;
                        gp.GreigeP_Greige_Fk         = (int)row.Cells[2].Value;
                        gp.GreigeP_CommissionGrn     = CLNU;


                        context.TLKNI_GreigeProduction.Add(gp);
                    }
                    try
                    {
                        context.SaveChanges();
                        MessageBox.Show("Data successfully saved to the database");
                        frmKnitViewRep vRep = new frmKnitViewRep(13, CLNU);
                        int            h    = Screen.PrimaryScreen.WorkingArea.Height;
                        int            w    = Screen.PrimaryScreen.WorkingArea.Width;
                        vRep.ClientSize = new Size(w, h);
                        vRep.ShowDialog(this);
                        dataGridView1.Rows.Clear();
                        SetUp(false);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }