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

            if (oBtn != null && FormLoaded)
            {
                var Selected = (TLADM_WhseStore)cmboWarehouses.SelectedItem;
                if (Selected == null)
                {
                    MessageBox.Show("Please select a warehouse from the combobox provided");
                    return;
                }

                using (var context = new TTI2Entities())
                {
                    foreach (DataGridViewRow Row in dataGridView1.Rows)
                    {
                        if (Row.Cells[0].Value == null)
                        {
                            continue;
                        }

                        var RWComplete = core.RowComplete(Row, MandatoryFields);
                        var cnt        = RWComplete.Where(x => x == false).Count();

                        if (cnt == MandatoryFields.Length)
                        {
                            continue;
                        }

                        if (cnt != 0)
                        {
                            var errorM = core.returnMessage(RWComplete, true, MandatoryFields);
                            if (!string.IsNullOrEmpty(errorM))
                            {
                                MessageBox.Show(errorM, "Error Message for Line No" + (Row.Index + 1).ToString());
                                return;
                            }
                        }

                        TLCSV_StockOnHand SOH = new TLCSV_StockOnHand();
                        var Style_FK          = (int)Row.Cells[1].Value;
                        var Colour_FK         = (int)Row.Cells[2].Value;
                        var Size_FK           = (int)Row.Cells[3].Value;



                        TLADM_Styles  Styles  = context.TLADM_Styles.Find(Style_FK);
                        TLADM_Colours Colours = context.TLADM_Colours.Find(Colour_FK);
                        TLADM_Sizes   Sizes   = context.TLADM_Sizes.Find(Size_FK);

                        SOH.TLSOH_PastelNumber  = Styles.Sty_PastelNo + Colours.Col_FinishedCode + "NG" + Sizes.SI_PastelNo;
                        SOH.TLSOH_BoxNumber     = Row.Cells[0].Value.ToString();
                        SOH.TLSOH_Style_FK      = (int)Row.Cells[1].Value;
                        SOH.TLSOH_Colour_FK     = (int)Row.Cells[2].Value;
                        SOH.TLSOH_Size_FK       = (int)Row.Cells[3].Value;
                        SOH.TLSOH_CMT_FK        = (int)Row.Cells[4].Value;
                        SOH.TLSOH_Weight        = (decimal)Row.Cells[5].Value;
                        SOH.TLSOH_BoxedQty      = Convert.ToInt32(Row.Cells[6].Value.ToString());
                        SOH.TLSOH_Grade         = Row.Cells[7].Value.ToString().ToUpper().Trim();
                        SOH.TLSOH_BoxType       = 1;
                        SOH.TLSOH_DateIntoStock = dtpTransdate.Value;
                        SOH.TLSOH_WareHouse_FK  = Selected.WhStore_Id;
                        if (SOH.TLSOH_Grade.Contains("A"))
                        {
                            SOH.TLSOH_Is_A = true;
                        }

                        var Cwork = context.TLCMT_CompletedWork.Where(x => x.TLCMTWC_BoxNumber == SOH.TLSOH_BoxNumber).FirstOrDefault();
                        if (Cwork != null)
                        {
                            SOH.TLSOH_CutSheet_FK = Cwork.TLCMTWC_CutSheet_FK;
                        }

                        var Already = context.TLCSV_StockOnHand.Where(x => x.TLSOH_BoxNumber == SOH.TLSOH_BoxNumber).FirstOrDefault();
                        if (Already != null)
                        {
                            if (!Already.TLSOH_Write_Off)
                            {
                                continue;
                            }
                        }

                        context.TLCSV_StockOnHand.Add(SOH);
                    }

                    try
                    {
                        context.SaveChanges();
                        MessageBox.Show("Data successfully save to the database");
                        cmboWarehouses.SelectedItem = -1;
                        dataGridView1.Rows.Clear();

                        frmStockTakeOn_Load(this, null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }
                }
            }
        }
Beispiel #2
0
        private void cmboCMTLine_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox oCmbo = sender as ComboBox;

            if (oCmbo != null && formloaded)
            {
                var selected = (int)oCmbo.SelectedValue;
                if (selected != 0)
                {
                    formloaded = false;
                    dataGridView1.Rows.Clear();
                    dataGridView2.Rows.Clear();
                    formloaded = true;

                    txtDifference.Text = "0";
                    txtTotAGrade.Text  = "0";
                    txtTotBGrade.Text  = "0";
                    txtTPIssued.Text   = "0";
                    txtTPPanels.Text   = "0";
                    txtNoBoxes.Text    = "0";

                    using (var context = new TTI2Entities())
                    {
                        var LI = context.TLCMT_LineIssue.Find(selected);
                        if (LI != null)
                        {
                            CS = context.TLCUT_CutSheet.Find(LI.TLCMTLI_CutSheet_FK);
                            if (CS != null)
                            {
                                CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == CS.TLCutSH_Pk).FirstOrDefault();
                                if (CSR == null)
                                {
                                    MessageBox.Show("Technical error encounted. Qoute number 1400");
                                    frmCompleted_Load(this, null);
                                    return;
                                }

                                //-------------------------------------------------------
                                //We have to check that all the BFA Data has been recorded
                                //--------------------------------------------------------------------
                                int BFACount = context.TLCMT_AuditMeasureRecorded.Where(x => x.TLBFAR_CutSheet_FK == CS.TLCutSH_Pk).Count();
                                if (BFACount == 0)
                                {
                                    MessageBox.Show("Please enter the BFA Audit information" + Environment.NewLine + "using the facility provided");
                                    frmCompleted_Load(this, null);
                                    return;
                                }

                                //------------------------------------------------------
                                // We have to now
                                //=========================================
                                var ExpectUnits = context.TLCUT_ExpectedUnits.Where(x => x.TLCUTE_CutSheet_FK == CS.TLCutSH_Pk).ToList();
                                foreach (var Unit in ExpectUnits)
                                {
                                    TLADM_Sizes Size = new TLADM_Sizes();
                                    Size.SI_Description = context.TLADM_Sizes.Find(Unit.TLCUTE_Size_FK).SI_Description;
                                    Size.SI_id          = Unit.TLCUTE_Size_FK;

                                    oCmboA.Items.Add(Size);
                                }
                                //---------------------------------------------------------------
                                //If expected units data not available, for what ever reason, go back to the original order
                                //==========================================================================
                                if (oCmboA.Items.Count == 0)
                                {
                                    var CutSheetDetail = context.TLCUT_CutSheetReceiptDetail.Where(x => x.TLCUTSHRD_CutSheet_FK == CSR.TLCUTSHR_Pk).GroupBy(x => x.TLCUTSHRD_Size_FK);
                                    foreach (var Grouped in CutSheetDetail)
                                    {
                                        var         Size_Pk = Grouped.FirstOrDefault().TLCUTSHRD_Size_FK;
                                        TLADM_Sizes Size    = new TLADM_Sizes();
                                        Size.SI_Description = context.TLADM_Sizes.Find(Size_Pk).SI_Description;
                                        Size.SI_id          = Size_Pk;

                                        oCmboA.Items.Add(Size);
                                    }
                                }

                                oCmboA.DisplayMember = "SI_Description";
                                oCmboA.ValueMember   = "SI_Id";

                                txtCutSheet.Text = CS.TLCutSH_No;

                                var DB = context.TLDYE_DyeBatch.Find(CS.TLCutSH_DyeBatch_FK);
                                if (DB != null)
                                {
                                    var DO = context.TLDYE_DyeOrder.Find(DB.DYEB_DyeOrder_FK);
                                    if (DO != null)
                                    {
                                        var dt = core.FirstDateOfWeek(DO.TLDYO_OrderDate.Year, DO.TLDYO_CMTReqWeek);
                                        txtDateRequired.Text = dt.AddDays(5).ToString("dd/MM/yyyy");
                                    }
                                }

                                Styles      = context.TLADM_Styles.Find(CS.TLCutSH_Styles_FK);
                                Colours     = context.TLADM_Colours.Find(CS.TLCutSH_Colour_FK);
                                StyleGrades = context.TLADM_StylesGrades.Where(x => x.TLSG_Style_Fk == CS.TLCutSH_Styles_FK).FirstOrDefault();

                                var Existing = context.TLCUT_CutSheetReceiptDetail.Where(x => x.TLCUTSHRD_CutSheet_FK == CSR.TLCUTSHR_Pk).ToList();

                                /* if (Existing != null)
                                 * {
                                 *   Sizes = context.TLADM_Sizes.Find(Existing.FirstOrDefault().TLCUTSHRD_Size_FK);
                                 * }*/

                                foreach (var row in Existing)
                                {
                                    var index = dataGridView1.Rows.Add();
                                    this.dataGridView1.Rows[index].Cells[0].Value = row.TLCUTSHRD_BoxNumber;
                                    this.dataGridView1.Rows[index].Cells[1].Value = Styles.Sty_Description;
                                    this.dataGridView1.Rows[index].Cells[2].Value = Colours.Col_Display;
                                    this.dataGridView1.Rows[index].Cells[3].Value = row.TLCUTSHRD_BoxUnits;
                                }

                                txtTPIssued.Text = Existing.Sum(x => x.TLCUTSHRD_BoxUnits).ToString();

                                // 0 Box No                          datagridView2
                                // 1 Code                            datagridView2
                                // 2 Size                            datagridView2
                                // 3 Grade                           datagridView2
                                // 4 Qty                             datagridView2
                                // 5 Weight                          dataGridView2
                                // 6 FK CutSheetSheet Receipt Detail datagridView2
                                formloaded = false;
                                foreach (var row in Existing)
                                {
                                    var index = dataGridView2.Rows.Add();
                                    this.dataGridView2.Rows[index].Cells[0].Value = row.TLCUTSHRD_BoxNumber;
                                    this.dataGridView2.Rows[index].Cells[1].Value = string.Empty;
                                    this.dataGridView2.Rows[index].Cells[2].Value = null; // string.Empty;
                                    this.dataGridView2.Rows[index].Cells[3].Value = string.Empty;
                                    this.dataGridView2.Rows[index].Cells[4].Value = 0;
                                    this.dataGridView2.Rows[index].Cells[5].Value = 0.00M;
                                    this.dataGridView2.Rows[index].Cells[6].Value = row.TLCUTSHRD_Pk;
                                }
                                formloaded = true;

                                if (this.dataGridView2.Rows.Count != 0)
                                {
                                    this.dataGridView2.CurrentCell = this.dataGridView2.Rows[0].Cells[1];
                                    this.dataGridView2.BeginEdit(true);
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        private void cmboFabric_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox oCmbo = sender as ComboBox;

            if (oCmbo != null && formloaded)
            {
                var selected = (TLADM_Griege)cmboFabric.SelectedItem;
                if (selected != null)
                {
                    var result = (from u in MandatoryFields
                                  where u[0] == oCmbo.Name
                                  select u).FirstOrDefault();

                    if (result != null)
                    {
                        int nbr = Convert.ToInt32(result[2].ToString());
                        MandSelected[nbr] = true;
                    }

                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        row.Cells[1].Value = 0.00M;
                        row.Cells[2].Value = 0.00M;
                        row.Cells[3].Value = 0.00M;
                    }

                    using (var context = new TTI2Entities())
                    {
                        var FabWeight = context.TLADM_FabricWeight.Find(selected.TLGreige_FabricWeight_FK);
                        var FabWidth  = context.TLADM_FabWidth.Find(selected.TLGreige_FabricWidth_FK);

                        FabricYield = core.FabricYield(FabWeight.FWW_Calculation_Value, FabWidth.FW_Calculation_Value);

                        if (FabricYield != 0)
                        {
                            txtYieldFactor.Text = Math.Round(FabricYield, 4).ToString();
                        }

                        var FabQual = context.TLADM_GreigeQuality.Where(x => x.GQ_Pk == selected.TLGreige_Quality_FK).FirstOrDefault();
                        if (FabQual != null)
                        {
                            var ExistingData = context.TLDYE_RecipeDefinition.ToList();
                            if (ExistingData != null)
                            {
                                IList <TLADM_Colours> Cols = new List <TLADM_Colours>();

                                foreach (var row in ExistingData)
                                {
                                    TLADM_Colours cl = context.TLADM_Colours.Find(row.TLDYE_ColorChart_FK);

                                    Cols.Add(cl);
                                }

                                cmboColors.DataSource    = context.TLADM_Colours.OrderBy(x => x.Col_Display).ToList();
                                cmboColors.ValueMember   = "Col_Id";
                                cmboColors.DisplayMember = "Col_Display";
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button        oBtn           = sender as Button;
            TLADM_Colours SelectedColour = null;

            bool lAdd = false;

            if (lNew)
            {
                lAdd = true;
            }

            if (rbStandard.Checked)
            {
                SelectedColour = (TLADM_Colours)cmboColours.SelectedItem;
                if (SelectedColour == null)
                {
                    MessageBox.Show("Please select a colour from the drop down box provided");
                    return;
                }

                if (QueryParms.FabricQualities.Count == 0)
                {
                    MessageBox.Show("Please add a Quality");
                    return;
                }
            }

            if (oBtn != null && formloaded)
            {
                var ErrorM = core.returnMessage(MandSelected, false, MandatoryFields);

                if (!String.IsNullOrEmpty(ErrorM))
                {
                    MessageBox.Show(ErrorM);
                    return;
                }

                foreach (DataGridViewRow dr in dataGridView1.Rows)
                {
                    if (rbStandard.Checked)
                    {
                        var tst = fieldEntered.Find(x => x.rownumber == dr.Index);
                        if (tst.fieldComplete == null)
                        {
                            continue;
                        }

                        tst.fieldComplete[1] = true;

                        var cnt = tst.fieldComplete.Where(x => x == false).Count();
                        if (cnt == MandatoryRows.Length)
                        {
                            continue;
                        }

                        cnt = tst.fieldComplete.Where(x => x == true).Count();
                    }
                }

                // 0  index of the main record
                // 1  ConsumablesDC
                // 2  Grams Per Litre
                // 3  Ratios
                // 4  Liquid Ratios
                using (var context = new TTI2Entities())
                {
                    TLDYE_RecipeDefinition rd = new TLDYE_RecipeDefinition();
                    if (!lAdd)
                    {
                        var selected = (TLDYE_RecipeDefinition)cmboProductCodes.SelectedItem;
                        if (selected != null)
                        {
                            rd = context.TLDYE_RecipeDefinition.Find(selected.TLDYE_DefinePk);
                        }
                    }

                    rd.TLDYE_DefineCode = txtProductCode.Text;

                    if (rbStandard.Checked)
                    {
                        rd.TLDYE_DefineDescription = txtProductCode.Text + " " + SelectedColour.Col_Display;
                    }
                    else
                    {
                        rd.TLDYE_DefineDescription = txtProductCode.Text;
                    }

                    if (rbStandard.Checked)
                    {
                        rd.TLDYE_ProgramLoad     = Convert.ToInt32(txtProgramLoad.Text);
                        rd.TLDYE_LiquidLoad      = Convert.ToInt32(txtProgramVolume.Text);
                        rd.TLDYE_ColorChart_FK   = SelectedColour.Col_Id;
                        rd.TLDYE_StandardReceipe = true;
                    }
                    else
                    {
                        rd.TLDYE_LiquidLoad      = 0;
                        rd.TLDYE_ProgramLoad     = 0;
                        rd.TLDYE_ColorChart_FK   = null;
                        rd.TLDYE_StandardReceipe = false;
                    }
                    if (lAdd)
                    {
                        context.TLDYE_RecipeDefinition.Add(rd);
                    }
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                MessageBox.Show("Property: " + validationError.PropertyName + " Error " + validationError.ErrorMessage);
                            }
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);

                        return;
                    }

                    // 0  index of the main record
                    // 1  ConsumablesDC
                    // 2  Grams Per Litre
                    // 3  Ratios
                    // 4  Liquid Ratios
                    foreach (DataGridViewRow dr in dataGridView1.Rows)
                    {
                        if (dr.Cells[1].Value == null)
                        {
                            continue;
                        }

                        var tst = fieldEntered.Find(x => x.rownumber == dr.Index);
                        if (tst.fieldComplete == null)
                        {
                            continue;
                        }

                        tst.fieldComplete[1] = true;

                        var cnt = tst.fieldComplete.Where(x => x == false).Count();
                        if (cnt == MandatoryRows.Length)
                        {
                            continue;
                        }

                        lAdd = false;

                        if (dr.Cells[0].Value == null)
                        {
                            lAdd = true;
                        }

                        cnt = tst.fieldComplete.Where(x => x == true).Count();
                        if (cnt == MandatoryRows.Length)
                        {
                            TLDYE_DefinitionDetails defdet = new TLDYE_DefinitionDetails();
                            if (!lAdd)
                            {
                                var index = Convert.ToInt32(dr.Cells[0].Value.ToString());
                                defdet = context.TLDYE_DefinitionDetails.Find(index);
                            }

                            defdet.TLDYED_Cosumables_FK = (int)dr.Cells[1].Value;
                            if (dr.Cells[2].Value != null)
                            {
                                if ((bool)dr.Cells[2].Value == true)
                                {
                                    defdet.TLDYED_LiqCalc = true;
                                }
                                else
                                {
                                    defdet.TLDYED_LiqCalc = false;
                                }
                            }
                            else
                            {
                                defdet.TLDYED_LiqCalc = false;
                            }

                            defdet.TLDYED_MELFC      = (decimal)dr.Cells[3].Value;
                            defdet.TLDYED_LiqRatio   = (int)dr.Cells[4].Value;
                            defdet.TLDYED_Receipe_FK = rd.TLDYE_DefinePk;

                            if (lAdd)
                            {
                                context.TLDYE_DefinitionDetails.Add(defdet);
                            }
                        }
                    }
                    //---------------------------------------------------------
                    //
                    //----------------------------------------------------------------
                    if (rbStandard.Checked)
                    {
                        //------------------------------------------------------------------------------------
                        // First we must ensure that any previous records that may exist are deleted and that we start with a clean slate
                        //---------------------------------------------------------------------------
                        context.TLDYE_ReceipeGreigeQual.RemoveRange(context.TLDYE_ReceipeGreigeQual.Where(x => x.TLGQ_ReceipeDef_FK == rd.TLDYE_DefinePk));
                        //------------------------------------------------------
                        // new development
                        //----------------------------------------------------------
                        foreach (var Qual in QueryParms.FabricQualities)
                        {
                            TLDYE_ReceipeGreigeQual repQual = new TLDYE_ReceipeGreigeQual();
                            repQual.TLGQ_GreigeQuality_FK = Qual.GQ_Pk;
                            repQual.TLGQ_ReceipeDef_FK    = rd.TLDYE_DefinePk;

                            context.TLDYE_ReceipeGreigeQual.Add(repQual);
                        }
                    }

                    try
                    {
                        context.SaveChanges();
                        MessageBox.Show("Data saved to database successfully");
                    }
                    catch (Exception ex)
                    {
                        // MessageBox.Show(ex.Message);
                        MessageBox.Show(ex.InnerException.ToString());
                    }
                    finally
                    {
                        this.cmboGreigeQuality.Items.Clear();
                        dataGridView1.Rows.Clear();
                        SetUp();
                    }
                }
            }
        }