示例#1
0
        private void frmCustomerSales_Load(object sender, EventArgs e)
        {
            formloaded = false;

            CustParameters = new CustomerServicesParameters();

            using (var context = new TTI2Entities())
            {
                var Customers = context.TLADM_CustomerFile.OrderBy(x => x.Cust_Description).ToList();
                foreach (var Customer in Customers)
                {
                    cmboCustomers.Items.Add(new CustomerServices.CheckComboBoxItem(Customer.Cust_Pk, Customer.Cust_Description, false));
                }

                var Styles = context.TLADM_Styles.OrderBy(x => x.Sty_Description).ToList();
                foreach (var Style in Styles)
                {
                    cmboStyles.Items.Add(new CustomerServices.CheckComboBoxItem(Style.Sty_Id, Style.Sty_Description, false));
                }

                var Colours = context.TLADM_Colours.Where(x => !(bool)x.Col_Discontinued).OrderBy(x => x.Col_Display).ToList();
                foreach (var Colour in Colours)
                {
                    cmboColours.Items.Add(new CustomerServices.CheckComboBoxItem(Colour.Col_Id, Colour.Col_Display, false));
                }

                var Sizes = context.TLADM_Sizes.Where(x => !(bool)x.SI_Discontinued).OrderBy(x => x.SI_DisplayOrder).ToList();
                foreach (var Size in Sizes)
                {
                    cmboSizes.Items.Add(new CustomerServices.CheckComboBoxItem(Size.SI_id, Size.SI_Description, false));
                }
            }
            rbSummarisedByCustomer.Checked = false;
            formloaded = true;
        }
示例#2
0
        private void frmOutStandingPL_Load(object sender, EventArgs e)
        {
            formloaded = false;

            QueryParms = new CustomerServicesParameters();

            using (var context = new TTI2Entities())
            {
                var WareHouses = context.TLADM_WhseStore.Where(x => x.WhStore_GradeA).OrderBy(x => x.WhStore_Description).ToList();
                foreach (var WareHouse in WareHouses)
                {
                    cmboWareHouses.Items.Add(new CustomerServices.CheckComboBoxItem(WareHouse.WhStore_Id, WareHouse.WhStore_Description, false));
                }

                var Styles = context.TLADM_Styles.OrderBy(x => x.Sty_Description).ToList();
                foreach (var Style in Styles)
                {
                    cmboStyles.Items.Add(new CustomerServices.CheckComboBoxItem(Style.Sty_Id, Style.Sty_Description, false));
                }

                var Colours = context.TLADM_Colours.Where(x => (bool)!x.Col_Discontinued).OrderBy(x => x.Col_Display).ToList();
                foreach (var Colour in Colours)
                {
                    cmboColours.Items.Add(new CustomerServices.CheckComboBoxItem(Colour.Col_Id, Colour.Col_Display, false));
                }

                var Sizes = context.TLADM_Sizes.Where(x => (bool)!x.SI_Discontinued).OrderBy(x => x.SI_DisplayOrder).ToList();
                foreach (var Size in Sizes)
                {
                    cmboSizes.Items.Add(new CustomerServices.CheckComboBoxItem(Size.SI_id, Size.SI_Description, false));
                }
            }
            formloaded = true;
        }
示例#3
0
        private void frmResetPickingList_Load(object sender, EventArgs e)
        {
            var ComboSource = new BindingList <KeyValuePair <int, string> >();

            FormLoaded = false;

            cmboOrderAssigned.DataSource = null;
            cmboOrderAssigned.Items.Clear();

            QueryParms = new CustomerServicesParameters();

            using (var context = new TTI2Entities())
            {
                var WareHouses = context.TLADM_WhseStore.Where(x => x.WhStore_GradeA).OrderBy(x => x.WhStore_Description).ToList();
                foreach (var WareHouse in WareHouses)
                {
                    cmboWarehouses.Items.Add(new CustomerServices.CheckComboBoxItem(WareHouse.WhStore_Id, WareHouse.WhStore_Description, false));
                }

                var Customers = context.TLADM_CustomerFile.OrderBy(x => x.Cust_Description).ToList();
                foreach (var Customer in Customers)
                {
                    cmboCustomer.Items.Add(new CustomerServices.CheckComboBoxItem(Customer.Cust_Pk, Customer.Cust_Description, false));
                }
            }

            FormLoaded = true;
        }
示例#4
0
        private void frmSeleEMailAddress_Load(object sender, EventArgs e)
        {
            QueryParms = new CustomerServicesParameters();

            using (var context = new TTI2Entities())
            {
                var Ua = context.TLSEC_UserAccess.Where(x => !(bool)x.TLSECUA_Discontinued && x.TLSUCUA_EmailAddress.Length != 0).OrderBy(x => x.TLSECUA_UserName).ToList();
                foreach (var U in Ua)
                {
                    cmboEMailAddress.Items.Add(new CheckComboBoxItem(U.TLSECUA_Pk, U.TLSECUA_UserName, false));
                }
            }
        }
        private void frmTransferWarehouseToWarehouse_Load(object sender, EventArgs e)
        {
            FormLoaded = false;

            using (var context = new TTI2Entities())
            {
                cmboFromwarehouse.DataSource    = context.TLADM_WhseStore.Where(x => x.WhStore_WhseOrStore).ToList();
                cmboFromwarehouse.DisplayMember = "WhStore_Description";
                cmboFromwarehouse.ValueMember   = "WhStore_Id";
                cmboFromwarehouse.SelectedItem  = -1;

                cmboTowareHouse.DataSource    = context.TLADM_WhseStore.Where(x => x.WhStore_WhseOrStore).ToList();
                cmboTowareHouse.DisplayMember = "WhStore_Description";
                cmboTowareHouse.ValueMember   = "WhStore_Id";
                cmboTowareHouse.SelectedItem  = -1;

                var Styles = context.TLADM_Styles.OrderBy(x => x.Sty_Description).ToList();
                foreach (var Style in Styles)
                {
                    cmboStyle.Items.Add(new CustomerServices.CheckComboBoxItem(Style.Sty_Id, Style.Sty_Description, false));
                }

                var Colours = context.TLADM_Colours.OrderBy(x => x.Col_Display).ToList();
                foreach (var Colour in Colours)
                {
                    cmboColour.Items.Add(new CustomerServices.CheckComboBoxItem(Colour.Col_Id, Colour.Col_Display, false));
                }

                var Sizes = context.TLADM_Sizes.Where(x => !(bool)x.SI_Discontinued).OrderBy(x => x.SI_DisplayOrder).ToList();
                foreach (var Size in Sizes)
                {
                    cmboSizes.Items.Add(new CustomerServices.CheckComboBoxItem(Size.SI_id, Size.SI_Description, false));
                }
            }

            QueryParms     = new CustomerServicesParameters();
            TransferMode   = false;
            btnSubmit.Text = "Submit";
            FormLoaded     = true;
        }
示例#6
0
        private void frmStockLists_Load(object sender, EventArgs e)
        {
            FormLoaded = false;

            repo       = new Repository();
            QueryParms = new CustomerServicesParameters();

            using (var context = new TTI2Entities())
            {
                var WareHouses = context.TLADM_WhseStore.Where(x => x.WhStore_WhseOrStore).OrderBy(x => x.WhStore_Description).ToList();
                foreach (var WareHouse in WareHouses)
                {
                    this.comboWareHouse.Items.Add(new CheckComboBoxItem(WareHouse.WhStore_Id, WareHouse.WhStore_Description, false));
                }

                var Styles = context.TLADM_Styles.OrderBy(x => x.Sty_Description).ToList();
                foreach (var Style in Styles)
                {
                    this.comboStyles.Items.Add(new CheckComboBoxItem(Style.Sty_Id, Style.Sty_Description, false));
                }

                var Colours = context.TLADM_Colours.Where(x => !(bool)x.Col_Discontinued).OrderBy(x => x.Col_Display).ToList();
                foreach (var Colour in Colours)
                {
                    this.comboColour.Items.Add(new CheckComboBoxItem(Colour.Col_Id, Colour.Col_Display, false));
                }

                var Sizes = context.TLADM_Sizes.Where(x => !(bool)x.SI_Discontinued).OrderBy(x => x.SI_DisplayOrder).ToList();
                foreach (var Size in Sizes)
                {
                    this.comboSizes.Items.Add(new CheckComboBoxItem(Size.SI_id, Size.SI_Description, false));
                }
            }

            //--------------------------------------------------------
            // wire up the check state changed event
            //--------------------------------------------------------------------------------------------------------

            FormLoaded = true;
        }
示例#7
0
        private void frmNegativeStock_Load(object sender, EventArgs e)
        {
            formloaded = false;
            using (var context = new TTI2Entities())
            {
                var Customers = (from Cust in context.TLADM_CustomerFile
                                 join CustTypes in context.TLADM_CustomerTypes on Cust.Cust_CustomerCat_FK equals CustTypes.CT_Id
                                 where CustTypes.CT_ShortCode == "WS"
                                 select Cust).ToList();
                foreach (var Customer in Customers)
                {
                    cmboCustomers.Items.Add(new CustomerServices.CheckComboBoxItem(Customer.Cust_Pk, Customer.Cust_Description, false));
                }

                var Styles = context.TLADM_Styles.Where(x => (bool)!x.Sty_Discontinued).OrderBy(x => x.Sty_Description).ToList();
                foreach (var Style in Styles)
                {
                    cmboStyles.Items.Add(new CustomerServices.CheckComboBoxItem(Style.Sty_Id, Style.Sty_Description, false));
                }

                var Colours = context.TLADM_Colours.Where(x => (bool)!x.Col_Discontinued).OrderBy(x => x.Col_Display).ToList();
                foreach (var Colour in Colours)
                {
                    cmboColours.Items.Add(new CustomerServices.CheckComboBoxItem(Colour.Col_Id, Colour.Col_Display, false));
                }

                var Sizes = context.TLADM_Sizes.Where(x => (bool)!x.SI_Discontinued).OrderBy(x => x.SI_DisplayOrder).ToList();
                foreach (var Size in Sizes)
                {
                    cmboSizes.Items.Add(new CustomerServices.CheckComboBoxItem(Size.SI_id, Size.SI_Description, false));
                }

                repo = new Repository();
            }

            QueryParms = new CustomerServicesParameters();
            formloaded = true;
        }
        private void frmDetailCustomerOrders_Load(object sender, EventArgs e)
        {
            IList <TLADM_CustomerFile> CustFile = null;

            formloaded = false;

            repo  = new Repository();
            parms = new  CustomerServicesParameters();


            var reportOptions = new BindingList <KeyValuePair <int, string> >();

            using (var context = new TTI2Entities())
            {
                if (UserDet._External == false)
                {
                    CustFile = context.TLADM_CustomerFile.OrderBy(x => x.Cust_Description).ToList();

                    foreach (var Customer in CustFile)
                    {
                        comboCustomers.Items.Add(new CustomerServices.CheckComboBoxItem(Customer.Cust_Pk, Customer.Cust_Description, false));
                    }
                }
                else
                {
                    var AccessPermitted = context.TLADM_CustomerAccess.Where(x => x.CustAcc_User_Fk == UserDet._UserPk).ToList();
                    foreach (var Access in AccessPermitted)
                    {
                        var CustDesc = context.TLADM_CustomerFile.Find(Access.CustAcc_Customer_Fk).Cust_Description;
                        comboCustomers.Items.Add(new CustomerServices.CheckComboBoxItem(Access.CustAcc_Customer_Fk, CustDesc, false));
                    }
                }

                var Styles = context.TLADM_Styles.OrderBy(x => x.Sty_Description).ToList();
                foreach (var Style in Styles)
                {
                    comboStyles.Items.Add(new CustomerServices.CheckComboBoxItem(Style.Sty_Id, Style.Sty_Description, false));
                }

                var Colours = context.TLADM_Colours.OrderBy(x => x.Col_Display).ToList();
                foreach (var Colour in Colours)
                {
                    comboColours.Items.Add(new CustomerServices.CheckComboBoxItem(Colour.Col_Id, Colour.Col_Display, false));
                }

                var Sizes = context.TLADM_Sizes.Where(x => (bool)!x.SI_Discontinued).OrderBy(x => x.SI_DisplayOrder).ToList();
                foreach (var Size in Sizes)
                {
                    comboSizes.Items.Add(new CustomerServices.CheckComboBoxItem(Size.SI_id, Size.SI_Description, false));
                }


                rbProvisionalOrdersOnly.Checked = false;
                rbStdOrdersOnly.Checked         = true;
            }

            //--------------------------------------------------------
            // wire up the check state changed event
            //--------------------------------------------------------------------------------------------------------

            this.comboCustomers.CheckStateChanged += new System.EventHandler(this.comboCust_CheckStateChanged);
            this.comboStyles.CheckStateChanged    += new System.EventHandler(this.cmboStyles_CheckStateChanged);
            this.comboColours.CheckStateChanged   += new System.EventHandler(this.cmboColours_CheckStateChanged);
            this.comboSizes.CheckStateChanged     += new System.EventHandler(this.cmboSizes_CheckStateChanged);

            formloaded = true;
        }
示例#9
0
        private void frmPivotTables_Load(object sender, EventArgs e)
        {
            IList <TLADM_WhseStore>    WareHouses = null;
            IList <TLADM_CustomerFile> Customers  = null;


            DGVOutput.Visible = false;
            using (var context = new TTI2Entities())
            {
                if (!UserD._External)
                {
                    WareHouses = context.TLADM_WhseStore.Where(x => x.WhStore_WhseOrStore).OrderBy(x => x.WhStore_Description).ToList();
                    foreach (var WareHouse in WareHouses)
                    {
                        cmboWareHouses.Items.Add(new CustomerServices.CheckComboBoxItem(WareHouse.WhStore_Id, WareHouse.WhStore_Description, false));
                    }

                    Customers = context.TLADM_CustomerFile.OrderBy(x => x.Cust_Description).ToList();
                    foreach (var Customer in Customers)
                    {
                        cmboCustomers.Items.Add(new CustomerServices.CheckComboBoxItem(Customer.Cust_Pk, Customer.Cust_Description, false));
                    }
                }
                else
                {
                    WareHouses = context.TLADM_WhseStore.Where(x => x.WhStore_WhseOrStore && !x.WhStore_RePack && x.WhStore_GradeA).OrderBy(x => x.WhStore_Description).ToList();
                    foreach (var WareHouse in WareHouses)
                    {
                        cmboWareHouses.Items.Add(new CustomerServices.CheckComboBoxItem(WareHouse.WhStore_Id, WareHouse.WhStore_Description, false));
                    }

                    var AccessPermitted = context.TLADM_CustomerAccess.Where(x => x.CustAcc_User_Fk == UserD._UserPk).ToList();
                    foreach (var Access in AccessPermitted)
                    {
                        var CustDesc = context.TLADM_CustomerFile.Find(Access.CustAcc_Customer_Fk).Cust_Description;
                        cmboCustomers.Items.Add(new CustomerServices.CheckComboBoxItem(Access.CustAcc_Customer_Fk, CustDesc, false));
                    }
                }

                var Styles = context.TLADM_Styles.OrderBy(x => x.Sty_Description).ToList();
                foreach (var Style in Styles)
                {
                    cmboStyles.Items.Add(new CustomerServices.CheckComboBoxItem(Style.Sty_Id, Style.Sty_Description, false));
                }

                var Sizes = context.TLADM_Sizes.Where(x => (bool)!x.SI_Discontinued).OrderBy(x => x.SI_DisplayOrder).ToList();
                foreach (var Size in Sizes)
                {
                    cmboSizes.Items.Add(new CustomerServices.CheckComboBoxItem(Size.SI_id, Size.SI_Description, false));
                }

                var Colours = context.TLADM_Colours.OrderBy(x => x.Col_Display).ToList();
                foreach (var Colour in Colours)
                {
                    cmboColours.Items.Add(new CustomerServices.CheckComboBoxItem(Colour.Col_Id, Colour.Col_Display, false));
                }
            }

            QueryParms = new CustomerServicesParameters();

            formloaded = true;
        }
示例#10
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button     oBtn = sender as Button;
            Repository repo = new Repository();
            CustomerServicesParameters parms = new CustomerServicesParameters();
            CSVServices svces       = new CSVServices();
            int         TransNumber = 0;

            if (oBtn != null && formloaded)
            {
                var SelectedTransporter = (TLADM_Transporters)cmboTransporters.SelectedItem;
                if (SelectedTransporter == null)
                {
                    MessageBox.Show("Please select a transporter");
                    return;
                }

                using (var context = new TTI2Entities())
                {
                    var selected = (TLADM_CustomerFile)cmboCustomers.SelectedItem;
                    if (selected == null)
                    {
                        MessageBox.Show("Please select a customer from the drop down box");
                        return;
                    }

                    parms.Customers.Add(repo.LoadCustomers(selected.Cust_Pk));

                    var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("CSV")).FirstOrDefault();
                    if (Dept != null)
                    {
                        var LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == Dept.Dep_Id).FirstOrDefault();
                        if (LNU != null)
                        {
                            TransNumber        = LNU.col4;
                            LNU.col4          += 1;
                            txtDeliveryNo.Text = "F" + LNU.col4.ToString().PadLeft(5, '0');
                        }
                    }

                    int Fk = 0;

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

                        //  Find the record the allocated file
                        //----------------------------------------------------
                        var pk = (int)row.Cells[0].Value;
                        parms.OrdersAllocated.Add(repo.LoadOrderAllocated(pk));

                        var Allocated = context.TLCSV_OrderAllocated.Find(pk);
                        if (Allocated != null)
                        {
                            Allocated.TLORDA_Delivered      = true;
                            Allocated.TLORDA_DeliveredDate  = DateTime.Now;
                            Allocated.TLORDA_DelTransNumber = TransNumber;
                            Allocated.TLORDA_Transporter    = string.Empty;
                            Allocated.TLORDA_Transporter_FK = SelectedTransporter.TLTRNS_Pk;
                            Allocated.TLORDA_PLStockOrder   = false;

                            Fk = (int)row.Cells[6].Value;
                            var soh = context.TLCSV_StockOnHand.Where(x => x.TLSOH_PickListNo == Fk && !x.TLSOH_Sold).ToList();
                            foreach (var rec in soh)
                            {
                                rec.TLSOH_Sold        = true;
                                rec.TLSOH_SoldDate    = DateTime.Now;
                                rec.TLSOH_Customer_Fk = selected.Cust_Pk;
                                rec.TLSOH_DNListNo    = TransNumber;
                                rec.TLSOH_DNListDate  = DateTime.Now;

                                var POD = context.TLCSV_PuchaseOrderDetail.Find(rec.TLSOH_POOrderDetail_FK);
                                if (POD != null)
                                {
                                    POD.TLCUSTO_Delivered            = true;
                                    POD.TLCUSTO_DeliveredDate        = DateTime.Now;
                                    POD.TLCUSTO_DeliveryNumber       = TransNumber;
                                    POD.TLCUSTO_QtyDelivered_ToDate += rec.TLSOH_BoxedQty;

                                    if (POD.TLCUSTO_Qty - POD.TLCUSTO_QtyDelivered_ToDate <= 0)
                                    {
                                        POD.TLCUSTO_Closed = true;
                                    }
                                }
                            }

                            //Make this a global transaction
                            //===========================================================
                            var RePackTransactions = context.TLCSV_RePackTransactions.Where(x => x.REPACT_PurchaseOrder_FK == Allocated.TLORDA_POOrder_FK).ToList();
                            foreach (var RePackTransaction in RePackTransactions)
                            {
                                var RePackConfig = context.TLCSV_RePackConfig.Find(RePackTransaction.REPACT_RePackConfig_FK);
                                if (RePackConfig != null)
                                {
                                    RePackConfig.PORConfig_SizeBoxQty_Delivered += RePackTransaction.REPACT_BoxedQty;
                                }
                            }
                        }
                    }

                    try
                    {
                        context.SaveChanges();

                        MessageBox.Show("data successfully saved to database");
                        dataGridView1.Rows.Clear();
                        cmboCustomers.SelectedValue = -1;


                        svces.TransNumber   = TransNumber;
                        svces.DateIntoStock = DateTime.Now;
                        svces.DNReprint     = false;

                        frmCSViewRep vRep = new frmCSViewRep(10, parms, svces);
                        int          h    = Screen.PrimaryScreen.WorkingArea.Height;
                        int          w    = Screen.PrimaryScreen.WorkingArea.Width;
                        vRep.ClientSize = new Size(w, h);
                        vRep.ShowDialog(this);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
示例#11
0
        private void frmStockOnHand_Load(object sender, EventArgs e)
        {
            IList <TLADM_WhseStore> Whses = null;

            formloaded = false;

            repo       = new Repository();
            QueryParms = new CustomerServicesParameters();

            if (_OptionNo == 1)
            {
                this.Text = "Stock quantities on hand";
            }
            else
            {
                this.Text = "Boxes in stock";
            }

            rbGradeA.Checked = true;

            using (var context = new TTI2Entities())
            {
                if (_Ud == null || !_Ud._External)
                {
                    Whses = context.TLADM_WhseStore.Where(x => x.WhStore_WhseOrStore && x.WhStore_GradeA).ToList();
                }
                else
                {
                    Whses = context.TLADM_WhseStore.Where(x => x.WhStore_WhseOrStore && x.WhStore_GradeA && !x.WhStore_RePack).ToList();
                }

                foreach (var Whse in Whses)
                {
                    comboWhses.Items.Add(new CustomerServices.CheckComboBoxItem(Whse.WhStore_Id, Whse.WhStore_Description, false));
                }

                var Styles = context.TLADM_Styles.OrderBy(x => x.Sty_Description).ToList();
                foreach (var Style in Styles)
                {
                    comboStyles.Items.Add(new CustomerServices.CheckComboBoxItem(Style.Sty_Id, Style.Sty_Description, false));
                }

                var Colours = context.TLADM_Colours.OrderBy(x => x.Col_Display).ToList();
                foreach (var Colour in Colours)
                {
                    comboColours.Items.Add(new CustomerServices.CheckComboBoxItem(Colour.Col_Id, Colour.Col_Display, false));
                }

                var Sizes = context.TLADM_Sizes.Where(x => (bool)!x.SI_Discontinued).OrderBy(x => x.SI_DisplayOrder).ToList();
                foreach (var Size in Sizes)
                {
                    comboSizes.Items.Add(new CustomerServices.CheckComboBoxItem(Size.SI_id, Size.SI_Description, false));
                }
                //--------------------------------------------------------
                // wire up the check state changed event
                //--------------------------------------------------------------------------------------------------------
                this.comboWhses.CheckStateChanged   += new System.EventHandler(this.cmboWhses_CheckStateChanged);
                this.comboStyles.CheckStateChanged  += new System.EventHandler(this.cmboStyles_CheckStateChanged);
                this.comboColours.CheckStateChanged += new System.EventHandler(this.cmboColours_CheckStateChanged);
                this.comboSizes.CheckStateChanged   += new System.EventHandler(this.cmboSizes_CheckStateChanged);
            }
            formloaded = true;
        }
示例#12
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;
            TLCSV_OrderAllocated OrderAllocated = null;
            Repository           repo           = new Repository();
            CSVServices          services       = new CSVServices();

            shirtParameters = new  CustomerServicesParameters();

            if (oBtn != null && formloaded)
            {
                var WareHouse = (TLADM_WhseStore)cmboWareHouse.SelectedItem;
                if (WareHouse == null)
                {
                    MessageBox.Show("Please select a warehouse from the drop down box");
                    return;
                }

                if (txtCustomerRef.Text.Length == 0)
                {
                    MessageBox.Show("Please enter a customer reference");
                    return;
                }

                if (txtReasons.Text.Length == 0)
                {
                    MessageBox.Show("Please enter the reason these goods are being returned");
                    return;
                }

                if (txtApprovedBy.Text.Length == 0)
                {
                    MessageBox.Show("Please enter the name of the approver");
                    return;
                }
                //----------------------------------------------------------------------------------
                using (var context = new TTI2Entities())
                {
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if ((bool)row.Cells[1].Value == false)
                        {
                            continue;
                        }

                        OrderAllocated = new TLCSV_OrderAllocated();
                        var Pk = (int)row.Cells[0].Value;
                        OrderAllocated = context.TLCSV_OrderAllocated.Find(Pk);
                        if (OrderAllocated != null)
                        {
                            OrderAllocated.TLORDA_Returned      = true;
                            OrderAllocated.TLORDA_ReturnCustRef = txtCustomerRef.Text;
                            OrderAllocated.TLORDA_ApprovedBy    = txtApprovedBy.Text;
                            OrderAllocated.TLORDA_ReturnNumber  = TransNumber;
                            OrderAllocated.TLORDA_ReturnedDate  = dtpTransactionDate.Value;

                            shirtParameters.OrdersAllocated.Add(repo.LoadOrderAllocated(Pk));
                        }
                    }

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

                        var ReSold = (bool)row.Cells[2].Value;

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

                        var soh = context.TLCSV_StockOnHand.Find(Pk);
                        if (soh != null)
                        {
                            int BoxedQty = (int)row.Cells[7].Value;
                            soh.TLSOH_ReturnedBoxQty = BoxedQty;
                            soh.TLSOH_BoxedQty       = BoxedQty;
                            soh.TLSOH_WareHouse_FK   = WareHouse.WhStore_Id;
                            soh.TLSOH_ReturnNumber   = TransNumber;
                            soh.TLSOH_ReturnedDate   = dtpTransactionDate.Value;

                            if (!ReSold)
                            {
                                soh.TLSOH_Returned = true;
                                soh.TLSOH_Grade    = "B";
                            }
                            else
                            {
                                soh.TLSOH_Picked              = false;
                                soh.TLSOH_PickListDate        = null;
                                soh.TLSOH_PickListNo          = 0;
                                soh.TLSOH_Sold                = false;
                                soh.TLSOH_DNListDate          = null;
                                soh.TLSOH_DNListNo            = 0;
                                soh.TLSOH_Grade               = "A";
                                soh.TLSOH_SoldDate            = null;
                                soh.TLSOH_WareHousePickList   = 0;
                                soh.TLSOH_WareHouseDeliveryNo = 0;
                            }
                        }
                    }

                    try
                    {
                        var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("CSV")).FirstOrDefault();
                        if (Dept != null)
                        {
                            var LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == Dept.Dep_Id).FirstOrDefault();
                            if (LNU != null)
                            {
                                TransNumber = LNU.col5;
                                LNU.col5   += 1;
                            }
                        }

                        //-------------------------------------------------------
                        //
                        //-----------------------------------------------------------
                        string Mach_IP = Dns.GetHostEntry(Dns.GetHostName())
                                         .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork)
                                         .ToString();

                        TLADM_DailyLog DailyLog = new TLADM_DailyLog();
                        DailyLog.TLDL_IPAddress    = Mach_IP;
                        DailyLog.TLDL_Dept_Fk      = Dept.Dep_Id;
                        DailyLog.TLDL_Date         = DateTime.Now;
                        DailyLog.TLDL_TransDetail  = "Customer Services - Stock Returned";
                        DailyLog.TLDL_AuthorisedBy = txtApprovedBy.Text;;
                        DailyLog.TLDL_Comments     = txtCustomerRef.Text;

                        context.TLADM_DailyLog.Add(DailyLog);

                        context.SaveChanges();
                        MessageBox.Show("Data successfully saved to the database");

                        dataGridView1.Rows.Clear();
                        dataGridView2.Rows.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }

                    services.ApprovedBy  = txtApprovedBy.Text;
                    services.Reasons     = txtReasons.Text;
                    services.ReturnDate  = dtpTransactionDate.Value;
                    services.CustomerRef = txtCustomerRef.Text;
                    services.WareHouse   = WareHouse.WhStore_Id;

                    frmCSViewRep vRep = new frmCSViewRep(11, shirtParameters, services);
                    int          h    = Screen.PrimaryScreen.WorkingArea.Height;
                    int          w    = Screen.PrimaryScreen.WorkingArea.Width;
                    vRep.ClientSize = new Size(w, h);
                    vRep.ShowDialog(this);

                    frmCustomerReturns_Load(this, null);
                }
            }
        }