Ejemplo n.º 1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            Button    oBtn = sender as Button;
            DataTable dt   = new DataTable();
            IList <TLCSV_PuchaseOrderDetail> PODetail  = new List <TLCSV_PuchaseOrderDetail>();
            IList <TLCSV_StockOnHand>        SOHDetail = new List <TLCSV_StockOnHand>();
            List <DATA> SOHGrouped = new List <DATA>();

            BindingSource bindingSource1 = new BindingSource();

            if (oBtn != null && formloaded)
            {
                if (UserD._External)
                {
                    if (QueryParms.Customers.Count == 0)
                    {
                        MessageBox.Show("Please select a customer from the drop down list");
                        return;
                    }

                    if (QueryParms.Whses.Count == 0)
                    {
                        MessageBox.Show("Please select a warehouse fro the drop down list");
                        return;
                    }
                }

                using (var context = new TTI2Entities())
                {
                    DGVOutput.DataSource = null;
                    DGVOutput.Rows.Clear();

                    if (rbAvailable.Checked || rbGrossStock.Checked)
                    {
                        //============================================================
                        // Can be either Gross Stock or Available stock data needed
                        // Start with Gross Stock always
                        //-------------------------------------------------------
                        SOHDetail = repo.GrossSOHQuery(QueryParms).ToList();
                        if (rbAvailable.Checked)
                        {
                            // Available Stock only
                            //----------------------------------------------------------
                            SOHDetail = SOHDetail.Where(x => !x.TLSOH_Picked).ToList();
                        }


                        if (SOHDetail.Count == 0)
                        {
                            DGVOutput.Visible = false;
                            MessageBox.Show("No records found for selection made");
                            return;
                        }

                        var GroupedData = SOHDetail.GroupBy(x => new { x.TLSOH_Style_FK, x.TLSOH_Colour_FK, x.TLSOH_Size_FK }).ToList();
                        foreach (var Grouped in GroupedData)
                        {
                            var Sty    = Grouped.FirstOrDefault().TLSOH_Style_FK;
                            var Clr    = Grouped.FirstOrDefault().TLSOH_Colour_FK;
                            var xSize  = Grouped.FirstOrDefault().TLSOH_Size_FK;
                            var BoxQty = Grouped.Sum(x => (int?)x.TLSOH_BoxedQty ?? 0);
                            var Record = SOHGrouped.Find(x => x._StyleFK == Sty && x._ColourFK == Clr && x._SizeFK == xSize);

                            var index = SOHGrouped.IndexOf(Record);

                            if (index < 0)
                            {
                                DATA dd = new DATA();
                                dd._BoxedQty = BoxQty;
                                dd._ColourFK = Clr;
                                dd._SizeFK   = xSize;
                                dd._StyleFK  = Sty;

                                SOHGrouped.Add(dd);
                            }
                            else
                            {
                                Record._BoxedQty += BoxQty;
                            }
                        }

                        //now ready to display
                        //-------------------------------------------------
                        dt = new DataTable();
                        DataColumn column;

                        // Create column 1
                        //----------------------------------------------
                        column            = new DataColumn();
                        column.DataType   = System.Type.GetType("System.String");
                        column.ColumnName = "Style";
                        dt.Columns.Add(column);

                        // Create column 2
                        //----------------------------------------------
                        column            = new DataColumn();
                        column.DataType   = System.Type.GetType("System.String");
                        column.ColumnName = "Colour";
                        dt.Columns.Add(column);
                        // Add the size names to the top of the grid box
                        //-------------------------------------------------------
                        foreach (var soh in SOHGrouped)
                        {
                            var xSize = context.TLADM_Sizes.Find(soh._SizeFK).SI_Description;
                            if (!dt.Columns.Contains(xSize))
                            {
                                dt.Columns.Add(xSize, typeof(Int32));
                            }
                            else
                            {
                                continue;
                            }
                        }

                        foreach (var soh in SOHGrouped)
                        {
                            var xStyle  = context.TLADM_Styles.Find(soh._StyleFK).Sty_Description;
                            var xColour = context.TLADM_Colours.Find(soh._ColourFK).Col_Display;
                            var xSize   = context.TLADM_Sizes.Find(soh._SizeFK).SI_Description;
                            var index   = dt.Columns.IndexOf(xSize);

                            var SingleRow = (from Rows in dt.Rows.Cast <DataRow>()
                                             where Rows.Field <String>(0) == xStyle && Rows.Field <String>(1) == xColour
                                             select Rows).FirstOrDefault();

                            if (SingleRow != null)
                            {
                                SingleRow[index] = soh._BoxedQty;
                            }
                            else
                            {
                                var TheNewRow = dt.NewRow();
                                TheNewRow[0]     = xStyle;
                                TheNewRow[1]     = xColour;
                                TheNewRow[index] = soh._BoxedQty;

                                dt.Rows.Add(TheNewRow);
                            }
                        }

                        DataView DataV = dt.DefaultView;
                        DataV.Sort = dt.Columns[0].ColumnName + "," + dt.Columns[1].ColumnName;

                        DGVOutput.DataSource = DataV.ToTable();
                        DGVOutput.Visible    = true;
                    }
                    else
                    {
                        //=======================================================================
                        //  this section of the code does the outstanding purchase orders
                        //=====================================================================
                        var Data = repo.POQuery(QueryParms);
                        if (Data.Count() == 0)
                        {
                            DGVOutput.Visible = false;
                            MessageBox.Show("No records found for selection made");
                            return;
                        }

                        var GroupedData = Data.GroupBy(x => new { x.TLCUSTO_Style_FK, x.TLCUSTO_Colour_FK, x.TLCUSTO_Size_FK }).ToList();
                        foreach (var Grouped in GroupedData)
                        {
                            var Sty    = Grouped.FirstOrDefault().TLCUSTO_Style_FK;
                            var Clr    = Grouped.FirstOrDefault().TLCUSTO_Colour_FK;
                            var xSize  = Grouped.FirstOrDefault().TLCUSTO_Size_FK;
                            var BoxQty = Grouped.Sum(x => (int?)x.TLCUSTO_Qty ?? 0);
                            var Record = SOHGrouped.Find(x => x._StyleFK == Sty && x._ColourFK == Clr && x._SizeFK == xSize);
                            var index  = SOHGrouped.IndexOf(Record);

                            if (index < 0)
                            {
                                DATA dd = new DATA();
                                dd._BoxedQty = BoxQty;
                                dd._ColourFK = Clr;
                                dd._SizeFK   = xSize;
                                dd._StyleFK  = Sty;

                                SOHGrouped.Add(dd);
                            }
                            else
                            {
                                Record._BoxedQty += BoxQty;
                            }
                        }
                        //now ready to display
                        //-------------------------------------------------
                        dt = new DataTable();
                        DataColumn column;

                        // Create column 1
                        //----------------------------------------------
                        column            = new DataColumn();
                        column.DataType   = System.Type.GetType("System.String");
                        column.ColumnName = "Style";
                        dt.Columns.Add(column);

                        // Create column 2
                        //----------------------------------------------
                        column            = new DataColumn();
                        column.DataType   = System.Type.GetType("System.String");
                        column.ColumnName = "Colour";
                        dt.Columns.Add(column);
                        // Add the size names to the top of the grid box
                        //-------------------------------------------------------
                        foreach (var soh in SOHGrouped)
                        {
                            var xSize = context.TLADM_Sizes.Find(soh._SizeFK).SI_Description;
                            if (!dt.Columns.Contains(xSize))
                            {
                                dt.Columns.Add(xSize, typeof(Int32));
                            }
                            else
                            {
                                continue;
                            }
                        }

                        foreach (var soh in SOHGrouped)
                        {
                            var xStyle  = context.TLADM_Styles.Find(soh._StyleFK).Sty_Description;
                            var xColour = context.TLADM_Colours.Find(soh._ColourFK).Col_Display;
                            var xSize   = context.TLADM_Sizes.Find(soh._SizeFK).SI_Description;
                            var index   = dt.Columns.IndexOf(xSize);

                            var SingleRow = (from Rows in dt.Rows.Cast <DataRow>()
                                             where Rows.Field <String>(0) == xStyle && Rows.Field <String>(1) == xColour
                                             select Rows).FirstOrDefault();

                            if (SingleRow != null)
                            {
                                SingleRow[index] = soh._BoxedQty;
                            }
                            else
                            {
                                var TheNewRow = dt.NewRow();
                                TheNewRow[0]     = xStyle;
                                TheNewRow[1]     = xColour;
                                TheNewRow[index] = soh._BoxedQty;

                                dt.Rows.Add(TheNewRow);
                            }
                        }

                        DataView DataV = dt.DefaultView;
                        DataV.Sort           = dt.Columns[0].ColumnName + "," + dt.Columns[1].ColumnName;
                        DGVOutput.DataSource = DataV.ToTable();
                        DGVOutput.Visible    = true;
                    }
                }
            }
        }
Ejemplo n.º 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);
                                }
                            }
                        }
                    }
                }
            }
        }