Example #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;
                    }
                }
            }
        }
Example #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);
                                }
                            }
                        }
                    }
                }
            }
        }