Пример #1
0
        private void UpdateToDb()
        {
            clsWarehouseTransferLine transferLine = new clsWarehouseTransferLine();
            clsWarehouseTransferHead transferHead = new clsWarehouseTransferHead();
            clsLogs logs = new clsLogs();

            transferHead.WarehouseTransferID = Convert.ToInt32(TxtTransferID.Text);
            transferHead.WarehouseRef        = TxtFromWarehouseRef.Text.TrimEnd();
            transferHead.ToWarehouseRef      = TxtToWarehouseRef.Text.TrimEnd();
            transferHead.MovementDate        = Convert.ToDateTime(DtpDate.Value);
            transferHead.Qty                 = Convert.ToInt32(txtTotalTransferTo.Text.TrimEnd());
            transferHead.UserID              = LogggedInUser;
            transferHead.Reference           = TxtTFNote.Text.TrimEnd();
            transferHead.WarehouseTransferID = Convert.ToInt32(TxtTransferID.Text.TrimEnd());
            transferHead.UpdateWarehouseTransferHead();
            for (int index = 0; index < DgvRecords.Rows.Count; index++)
            {
                transferLine.StockCode  = DgvRecords.Rows[index].Cells[0].Value.ToString();
                transferLine.CurrentQty = Convert.ToInt32(DgvRecords.Rows[index].Cells[1].Value);
                transferLine.TOQty      = Convert.ToInt32(DgvRecords.Rows[index].Cells[2].Value) * -1;
                transferLine.TIQty      = Convert.ToInt32(DgvRecords.Rows[index].Cells[2].Value);
                transferLine.UpdateWarehouseTransferLine();
                logs.StockCode            = transferLine.StockCode;
                logs.LocationRef          = transferHead.WarehouseRef;
                logs.LocationType         = 1;
                logs.SupplierRef          = "N/A";
                logs.DeliveredQtyBoxes    = 0;
                logs.DeliveredQtyGarments = transferLine.TOQty;
                logs.DeliveredQtyHangers  = transferLine.TOQty;
                logs.MovementType         = 2;
                logs.MovementDate         = transferHead.MovementDate;
                logs.Qty = transferLine.TOQty;
                logs.StringMovementType = "WarehouseTransfer";
                logs.RecordType         = "WarehouseTransfer-Item";
                logs.Reference          = transferHead.Reference;
                logs.UserID             = LogggedInUser;
                logs.SaveToSysLogTable();
                logs.SaveToStockMovementsTable();
                logs.StockCode            = transferLine.StockCode;
                logs.LocationRef          = transferHead.ToWarehouseRef;
                logs.LocationType         = 1;
                logs.SupplierRef          = "N/A";
                logs.DeliveredQtyBoxes    = 0;
                logs.DeliveredQtyGarments = transferLine.TIQty;
                logs.DeliveredQtyHangers  = transferLine.TIQty;
                logs.MovementType         = 2;
                logs.Qty = transferLine.TIQty;
                logs.StringMovementType = "WarehouseTransfer";
                logs.RecordType         = "WarehouseTransfer-Item";
                logs.Reference          = transferHead.Reference;
                logs.UserID             = LogggedInUser;
                logs.SaveToSysLogTable();
                logs.SaveToStockMovementsTable();
            }
        }
Пример #2
0
 // Saving = new updating = old to the database
 private void CmdOK_Click(object sender, EventArgs e)
 {
     if (TxteMail.Text != "Please Try Again")
     {
         clsLogs logs = new clsLogs();
         logs.StockCode    = "NULL";
         logs.SupplierRef  = "NULL";
         logs.LocationRef  = TxtShopRef.Text.TrimEnd();
         logs.Qty          = 0;
         logs.MovementDate = DateTime.Today;
         logs.UserID       = UserIDs;
         if (FormMode == "New")
         {
             logs.StringMovementType = "New Shop";
             logs.RecordType         = "New Shop Record";
             logs.Reference          = "New Shop Record";
         }
         else
         {
             logs.StringMovementType = "Update Shop";
             logs.RecordType         = "Update-Item-Shop";
             logs.Reference          = "Update Shop Record";
         }
         objShop.ShopRef      = TxtShopRef.Text.TrimEnd();
         objShop.ShopName     = TxtShopName.Text.TrimEnd();
         objShop.AddressLine1 = TxtAddress1.Text.TrimEnd();
         objShop.AddressLine2 = TxtAddress2.Text.TrimEnd();
         objShop.AddressLine3 = TxtAddress3.Text.TrimEnd();
         objShop.AddressLine4 = TxtAddress4.Text.TrimEnd();
         objShop.PostCode     = TxtPostCode.Text.TrimEnd();
         objShop.ShopType     = cboWType.Text.TrimEnd();
         objShop.Telephone    = TxtTelephone1.Text.TrimEnd();
         objShop.Fax          = TxtFax.Text.TrimEnd();
         objShop.eMail        = TxteMail.Text.TrimEnd();
         objShop.ContactName  = TxtContactName.Text.TrimEnd();
         objShop.Memo         = TxtMemo.Text.TrimEnd();
         objShop.UserID       = UserIDs;
         if (FormMode == "New")
         {
             objShop.SaveShopToDB();
         }
         else
         {
             objShop.UpdateShopToDB();
         }
     }
     else
     {
         MessageBox.Show("Please enter a valid email address!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
         TxteMail.SelectAll();
     }
     this.Close();
 }
Пример #3
0
        private void CmdOK_Click(object sender, EventArgs e)
        {
            // Saving / updating the master table into the database
            if (FormMode == "New")
            {
                SaveToDb();
            }
            else
            {
                clsLogs Dlogs = new clsLogs
                {
                    TransferReference = Convert.ToInt32(TxtTransferID.Text),
                    MovementDate      = oldDate,
                    MovementType      = 2
                };  // Delete old StockMovements details for current transfer
                Dlogs.DeleteFromStockMovemmentsTable();
                UpdateToDb();
            }

            this.Close();
        }
        private void CmdOK_Click(object sender, EventArgs e)
        {
            clsShopTransferHead transferHead = new clsShopTransferHead();
            clsShopTransferLine transferLine = new clsShopTransferLine();

            int SavedID = 0;

            transferHead.ShopRef      = TxtFromShopRef.Text.TrimEnd();
            transferHead.ShopName     = txtFromShopName.Text.TrimEnd();
            transferHead.ToShopName   = txtToShopName.Text.TrimEnd();
            transferHead.ToShopRef    = TxtToShopRef.Text.TrimEnd();
            transferHead.MovementDate = Convert.ToDateTime(DtpDate.Value);
            transferHead.Qty          = Convert.ToInt32(txtTotalTransferTo.Text.TrimEnd());
            transferHead.UserID       = LogggedInUser;
            transferHead.Reference    = TxtTFNote.Text.TrimEnd();
            // Saving / updating the master table into the database
            if (FormMode == "New")
            {
                transferHead.SaveShopTransferHead();
                SavedID = transferHead.GetLastShopTransferHead();
            }
            else
            {
                clsLogs Dlogs = new clsLogs();  // Delete old StockMovements details for current transfer
                Dlogs.TransferReference = SavedID;
                Dlogs.MovementDate      = olddate;
                Dlogs.MovementType      = 2;
                Dlogs.DeleteFromStockMovemmentsTable();
                transferHead.ShopTransferID = Convert.ToInt32(TxtTransferID.Text.TrimEnd());
                transferHead.UpdateShopTransferHead();
            }

            clsLogs logs = new clsLogs();

            logs.TransferReference      = SavedID;
            transferLine.ShopTransferID = SavedID;
            logs.MovementDate           = transferHead.MovementDate;
            logs.LocationType           = 2;
            logs.MovementType           = 4;
            logs.DeliveredQtyGarments   = 0;
            logs.DeliveredQtyBoxes      = 0;
            logs.SupplierRef            = "N/A";
            logs.Reference          = transferHead.Reference;
            logs.UserID             = transferHead.UserID;
            logs.StringMovementType = "WarehouseTransfer";
            logs.RecordType         = "WarehouseTransfer-Item";
            for (int index = 0; index < DgvRecords.Rows.Count; index++)
            {
                transferLine.StockCode = DgvRecords.Rows[index].Cells[0].Value.ToString();
                logs.StockCode         = transferLine.StockCode;
                transferLine.CurrQty   = Convert.ToInt32(DgvRecords.Rows[index].Cells[1].Value);
                transferLine.TOQty     = Convert.ToInt32(DgvRecords.Rows[index].Cells[2].Value) * -1;
                transferLine.TIQty     = Convert.ToInt32(DgvRecords.Rows[index].Cells[2].Value);
                if (FormMode == "New")
                {
                    logs.LocationRef         = transferHead.ShopRef;
                    logs.Qty                 = transferLine.TOQty;
                    logs.DeliveredQtyHangers = logs.Qty;
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                    transferLine.SaveShopTransferLine();
                    logs.LocationRef         = transferHead.ToShopRef;
                    logs.Qty                 = transferLine.TIQty;
                    logs.DeliveredQtyHangers = logs.Qty;
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                }
                else
                {
                    logs.Qty = transferLine.TOQty;
                    logs.DeliveredQtyHangers = logs.Qty;
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                    transferLine.UpdateShopTransferLine();
                    logs.Qty = transferLine.TIQty;
                    logs.DeliveredQtyHangers = logs.Qty;
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                }
            }
            this.Close();
        }
Пример #5
0
        private void CmdOK_Click(object sender, EventArgs e)
        {
            // Saving the record to the database tblWarehouses and tblSysLog tables
            // New form = Save
            // old form = update
            clsWarehouse objWarehouse = new clsWarehouse(UserIDs);
            clsLogs      logs         = new clsLogs();

            logs.StockCode    = "NULL";
            logs.SupplierRef  = "NULL";
            logs.LocationRef  = TxtWarehouseRef.Text.TrimEnd();
            logs.Qty          = 0;
            logs.MovementDate = DateTime.Today;
            logs.UserID       = UserIDs;
            if (Modeform == "New")
            {
                logs.StringMovementType = "New Warehouse";
                logs.RecordType         = "New Warehouse Record";
                logs.Reference          = "New Waerhouse Record";
            }
            else
            {
                logs.StringMovementType = "Update Warehouse";
                logs.RecordType         = "Update-Item-Warehouse";
                logs.Reference          = "Update Warehouse Record";
            }
            if (Modeform == "New")
            {
                objWarehouse.WarehouseRef   = TxtWarehouseRef.Text.TrimEnd();
                objWarehouse.WarehouseName  = TxtWarehouseName.Text.TrimEnd();
                objWarehouse.AddressLine1   = TxtAddress1.Text.TrimEnd();
                objWarehouse.AddressLine2   = TxtAddress2.Text.TrimEnd();
                objWarehouse.AddressLine3   = TxtAddress3.Text.TrimEnd();
                objWarehouse.AddressLine4   = TxtAddress4.Text.TrimEnd();
                objWarehouse.PostCode       = TxtPostCode.Text.TrimEnd();
                objWarehouse.Telephone      = TxtTelephone1.Text.TrimEnd();
                objWarehouse.ContactName    = TxtContactName.Text.TrimEnd();
                objWarehouse.eMail          = TxteMail.Text.TrimEnd();
                objWarehouse.Fax            = TxtFax.Text.TrimEnd();
                objWarehouse.Memo           = TxtMemo.Text.TrimEnd();
                objWarehouse.WarehouseType  = cboWType.Text.TrimEnd();
                objWarehouse.WebsiteAddress = TxtWebsite.Text.TrimEnd();
                objWarehouse.SaveWarehouseToDB();
            }
            else
            {
                objWarehouse.WarehouseRef   = TxtWarehouseRef.Text.TrimEnd();
                objWarehouse.WarehouseName  = TxtWarehouseName.Text.TrimEnd();
                objWarehouse.AddressLine1   = TxtAddress1.Text.TrimEnd();
                objWarehouse.AddressLine2   = TxtAddress2.Text.TrimEnd();
                objWarehouse.AddressLine3   = TxtAddress3.Text.TrimEnd();
                objWarehouse.AddressLine4   = TxtAddress4.Text.TrimEnd();
                objWarehouse.PostCode       = TxtPostCode.Text.TrimEnd();
                objWarehouse.Telephone      = TxtTelephone1.Text.TrimEnd();
                objWarehouse.ContactName    = TxtContactName.Text.TrimEnd();
                objWarehouse.eMail          = TxteMail.Text.TrimEnd();
                objWarehouse.Fax            = TxtFax.Text.TrimEnd();
                objWarehouse.Memo           = TxtMemo.Text.TrimEnd();
                objWarehouse.WarehouseType  = cboWType.Text.TrimEnd();
                objWarehouse.WebsiteAddress = TxtWebsite.Text.TrimEnd();
                objWarehouse.UpdateWarehouseToDB();
            }
            logs.SaveToSysLogTable();
            this.Close();
        }
Пример #6
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            clsShopReturnHead returnHead = new clsShopReturnHead();
            clsShopReturnLine returnLine = new clsShopReturnLine();
            clsLogs           logs       = new clsLogs();
            int SavedID = 0;

            // Header of both adjustments and log file
            returnHead.WarehouseRef = txtWarehouseRef.Text.TrimEnd();
            returnHead.Reference    = txtReference.Text.TrimEnd();
            returnHead.ShopRef      = txtShopRef.Text.TrimEnd();
            returnHead.TotalItems   = Convert.ToInt32(txtTotalItems.Text.TrimEnd());
            returnHead.MovementDate = Convert.ToDateTime(DtpDate.Value);
            returnHead.UserID       = LoggedInUser;
            if (FormMode == "New")
            {
                returnHead.SaveShopReturnHead();
                SavedID = returnHead.GetLastShopReturnHead();
            }
            else
            {
                clsLogs Dlogs = new clsLogs();  // Delete old StockMovements Data from Table
                Dlogs.TransferReference = Convert.ToInt32(txtReturnID.Text.TrimEnd());
                Dlogs.MovementDate      = oldDate;
                Dlogs.MovementType      = 9;
                Dlogs.DeleteFromStockMovemmentsTable();
                returnHead.ShopReturnID = Convert.ToInt32(txtReturnID.Text.TrimEnd());
                returnHead.UpdateShopReturnHead();
            }
            logs.TransferReference  = SavedID;
            returnLine.ShopReturnID = SavedID;
            logs.MovementDate       = returnHead.MovementDate;
            logs.UserID             = returnHead.UserID;
            logs.MovementType       = 8;
            logs.StringMovementType = "Shop Return Item";
            for (int index = 0; index < DgvRecords.Rows.Count; index++)
            {
                logs.LocationRef     = returnHead.WarehouseRef;
                returnLine.StockCode = DgvRecords.Rows[index].Cells[0].Value.ToString();
                returnLine.Qty       = Convert.ToInt32(DgvRecords.Rows[index].Cells[1].Value);
                logs.StockCode       = returnLine.StockCode;
                logs.RecordType      = "Shop Return";
                logs.Reference       = logs.StringMovementType;
                logs.SupplierRef     = "N/A";
                if (FormMode == "New")
                {
                    logs.LocationType        = 2;
                    logs.LocationRef         = returnHead.ShopRef;
                    logs.Qty                 = returnLine.Qty * -1;
                    logs.DeliveredQtyHangers = returnLine.Qty * -1;
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                    returnLine.SaveShopReturnLine();
                    logs.LocationRef         = returnHead.WarehouseRef;
                    logs.LocationType        = 1;
                    logs.Qty                 = returnLine.Qty;
                    logs.DeliveredQtyHangers = returnLine.Qty;
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                }
                else
                {
                    logs.LocationRef         = returnHead.ShopRef;
                    logs.Qty                 = returnLine.Qty * -1;
                    logs.DeliveredQtyHangers = logs.Qty;
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                    returnLine.UpdateShopReturnLine();
                    logs.LocationRef         = returnHead.WarehouseRef;
                    logs.Qty                 = returnLine.Qty;
                    logs.DeliveredQtyHangers = logs.Qty;
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                }
            }
            Close();
        }
Пример #7
0
        private void SaveToDb()
        {
            clsWarehouseAdjustmentHead adjustmentHead = new clsWarehouseAdjustmentHead();
            int SavedID = 0;

            // Header of both adjustments and log file
            adjustmentHead.WarehouseRef   = TxtWarehouseRef.Text.TrimEnd();
            adjustmentHead.Reference      = TxtReference.Text.TrimEnd();
            adjustmentHead.TotalGainItems = Convert.ToInt32(TxtTotalGain.Text.TrimEnd());
            adjustmentHead.TotalLossItems = Convert.ToInt32(TxtTotalLoss.Text.TrimEnd());
            adjustmentHead.MovementDate   = Convert.ToDateTime(DateTimePicker1.Value);
            adjustmentHead.UserID         = LoggedInUser;

            adjustmentHead.SaveWarehouseAdjustmentHead();
            SavedID = adjustmentHead.GetLastWarehouseAdjustmentHead();

            clsWarehouseAdjustmentLine adjustmentLine = new clsWarehouseAdjustmentLine();
            clsLogs logs = new clsLogs();  // Save To system Log and StockMovements Table

            logs.TransferReference = SavedID;
            adjustmentLine.WarehouseAdjustmentID = SavedID;
            logs.LocationRef = adjustmentHead.WarehouseRef;
            for (int index = 0; index < dgvItems.Rows.Count; index++)
            {
                // Saving details to tblWarehouseAdjustmentLines Table
                adjustmentLine.StockCode    = dgvItems.Rows[index].Cells[0].Value.ToString();
                adjustmentLine.MovementType = dgvItems.Rows[index].Cells[1].Value.ToString();
                adjustmentLine.Qty          = Convert.ToInt32(dgvItems.Rows[index].Cells[2].Value);
                adjustmentLine.Value        = Convert.ToDecimal(dgvItems.Rows[index].Cells[3].Value);
                // Saving details to tblStockMovements Table
                logs.StockCode    = adjustmentLine.StockCode;
                logs.LocationRef  = adjustmentHead.WarehouseRef;
                logs.LocationType = 1;
                logs.SupplierRef  = "N/A";
                if (adjustmentLine.MovementType == "Loss")
                {
                    logs.DeliveredQtyHangers = Convert.ToInt32(dgvItems.Rows[index].Cells[2].Value) * -1;
                }
                else
                {
                    logs.DeliveredQtyHangers = Convert.ToInt32(dgvItems.Rows[index].Cells[2].Value);
                }
                logs.DeliveredQtyGarments = 0;
                logs.DeliveredQtyBoxes    = 0;
                if (adjustmentLine.MovementType == "Loss")
                {
                    logs.MovementType = 7;
                }
                else
                {
                    logs.MovementType = 6;
                }
                logs.MovementDate       = adjustmentHead.MovementDate;
                logs.Reference          = adjustmentHead.Reference;
                logs.StringMovementType = "WarehouseAdjustment-" + adjustmentLine.MovementType;
                logs.RecordType         = "WarehouseAdjustment-Item";
                logs.UserID             = LoggedInUser;
                // Save to the relevent data tables on each itteration of the Datagridview control
                logs.SaveToSysLogTable();
                logs.SaveToStockMovementsTable();
                if (FormMode == "New")
                {
                    adjustmentLine.SaveWarehouseAdjustmentLine();
                }
                else
                {
                    adjustmentLine.UpdateWarehouseAdjustmentLine();
                }
            }
        }
Пример #8
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            clsShopSaleHead saleHead = new clsShopSaleHead();
            clsShopSaleLine saleLine = new clsShopSaleLine();
            clsLogs         logs     = new clsLogs();
            decimal         toConvert;

            saleHead.ShopRef      = txtShopRef.Text.TrimEnd();
            saleHead.ShopName     = lblShopName.Text.TrimEnd();
            saleHead.MovementDate = Convert.ToDateTime(DateTimePicker1.Value);
            decimal.TryParse(txtTotal.Text, System.Globalization.NumberStyles.AllowCurrencySymbol | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands, CultureInfo.CurrentCulture, out toConvert);
            saleHead.Value = toConvert;
            saleHead.Qty   = Convert.ToInt32(txtTotalGarments.Text.TrimEnd());
            decimal.TryParse(txtVAT.Text, System.Globalization.NumberStyles.AllowCurrencySymbol | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands, CultureInfo.CurrentCulture, out toConvert);
            saleHead.VATRate = toConvert;
            saleHead.UserID  = LoggedInUser;
            saleHead.SaveShopSaleHead();
            saleLine.SalesID        = saleHead.GetLastShopSaleHead();
            logs.StockCode          = "ALL";
            logs.SupplierRef        = "ALL";
            logs.LocationRef        = saleHead.ShopRef;
            logs.Qty                = saleHead.Qty;
            logs.RecordType         = "Sales Add-Start";
            logs.Reference          = logs.RecordType;
            logs.MovementDate       = saleHead.MovementDate;
            logs.StringMovementType = "Sales Add";
            logs.UserID             = saleHead.UserID;
            //logs.Reference = "Sales ID: [" + saleHead.SalesID.ToString() + "]";
            logs.SaveToSysLogTable();
            if (FormMode == "New")
            {
                for (int a = 0; a < DgvRecords.Rows.Count; a++)
                {
                    saleLine.StockCode            = DgvRecords.Rows[a].Cells[0].Value.ToString();
                    saleLine.DeliveredQtyGarments = Convert.ToInt32(DgvRecords.Rows[a].Cells[1].Value.ToString());
                    saleLine.CurrentQty           = Convert.ToInt32(DgvRecords.Rows[a].Cells[2].Value.ToString());
                    saleLine.TotalItems           = Convert.ToInt32(DgvRecords.Rows[a].Cells[3].Value.ToString());
                    saleLine.Qty         = Convert.ToInt32(DgvRecords.Rows[a].Cells[4].Value.ToString());
                    saleLine.SalesAmount = Convert.ToDecimal(DgvRecords.Rows[a].Cells[5].Value.ToString());
                    saleLine.SaveShopSaleLine();    // Save to database
                    logs.LocationRef        = saleHead.ShopRef;
                    logs.MovementDate       = saleHead.MovementDate;
                    logs.StockCode          = saleLine.StockCode;
                    logs.MovementValue      = saleLine.SalesAmount;
                    logs.Qty                = saleLine.Qty;
                    logs.StringMovementType = "Shop Sale Add-Item";
                    //    logs.RecordType = "Sale Record [" + logs.StockCode + "]";
                    logs.MovementDate         = saleHead.MovementDate;
                    logs.UserID               = saleHead.UserID;
                    logs.MovementType         = 5;
                    logs.LocationType         = 2;
                    logs.TransferReference    = saleLine.SalesID;
                    logs.DeliveredQtyHangers  = logs.Qty;
                    logs.DeliveredQtyBoxes    = 0;
                    logs.DeliveredQtyGarments = logs.DeliveredQtyBoxes;
                    logs.SupplierRef          = ""; // Add function to clsStock to get the supplier Ref from the table.
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                }
                logs.DeleteZeroQtyFromStockMovementsTable();
                logs.StockCode          = "ALL";
                logs.SupplierRef        = "ALL";
                logs.LocationRef        = saleHead.ShopRef;
                logs.Qty                = saleHead.Qty;
                logs.RecordType         = "Sales Add-End";
                logs.MovementDate       = saleHead.MovementDate;
                logs.StringMovementType = "Sales Add";
                logs.UserID             = saleHead.UserID;
                logs.Reference          = "Sales ID: [" + saleHead.SalesID.ToString() + "]";
                logs.SaveToSysLogTable();
            }
            else
            {
                logs.MovementType      = 5;
                logs.TransferReference = Convert.ToInt32(txtSalesID.Text.TrimEnd());
                logs.MovementDate      = OldDate;
                logs.DeleteFromStockMovemmentsTable();
                logs.StockCode          = "ALL";
                logs.SupplierRef        = "ALL";
                logs.LocationRef        = saleHead.ShopRef;
                logs.Qty                = saleHead.Qty;
                logs.RecordType         = "Sales Update-Start";
                logs.MovementDate       = saleHead.MovementDate;
                logs.StringMovementType = "Sales Update";
                logs.UserID             = saleHead.UserID;
                logs.Reference          = "Sales ID: [" + saleHead.SalesID.ToString() + "]";
                logs.SaveToSysLogTable();
                for (int a = 0; a < DgvRecords.Rows.Count - 1; a++)
                {
                    saleLine.StockCode            = DgvRecords.Rows[a].Cells[0].Value.ToString();
                    saleLine.DeliveredQtyGarments = Convert.ToInt32(DgvRecords.Rows[a].Cells[1].Value.ToString());
                    saleLine.CurrentQty           = Convert.ToInt32(DgvRecords.Rows[a].Cells[2].Value.ToString());
                    saleLine.TotalItems           = Convert.ToInt32(DgvRecords.Rows[a].Cells[3].Value.ToString());
                    saleLine.Qty         = Convert.ToInt32(DgvRecords.Rows[a].Cells[4].Value.ToString());
                    saleLine.SalesAmount = Convert.ToDecimal(DgvRecords.Rows[a].Cells[5].Value.ToString());
                    saleLine.UpdateShopSaleLine();    // Save to database
                    logs.LocationRef          = saleHead.ShopRef;
                    logs.MovementDate         = saleHead.MovementDate;
                    logs.StockCode            = saleLine.StockCode;
                    logs.Qty                  = saleLine.Qty;
                    logs.StringMovementType   = "Shop Sale Update";
                    logs.RecordType           = "Sale Record [" + logs.StockCode + "]";
                    logs.MovementDate         = saleHead.MovementDate;
                    logs.UserID               = saleHead.UserID;
                    logs.MovementType         = 5;
                    logs.LocationType         = 2;
                    logs.Reference            = "Sale-Update-Item";
                    logs.TransferReference    = saleLine.SalesID;
                    logs.DeliveredQtyGarments = logs.Qty;
                    logs.DeliveredQtyBoxes    = 0;
                    logs.DeliveredQtyHangers  = logs.DeliveredQtyBoxes;
                    logs.SupplierRef          = ""; // Add function to clsStock to get the supplier Ref from the table.
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                }
            }
            Close();
        }
        private void cmdOK_Click(object sender, EventArgs e)
        {
            clsPurchaseOrderHead orderHead = new clsPurchaseOrderHead(LoggedUser);
            clsPurchaseOrderLine orderLine = new clsPurchaseOrderLine();
            clsStock             stock     = new clsStock();
            clsLogs logs = new clsLogs();

            logs.StockCode    = TxtOurRef.Text.TrimEnd();
            logs.SupplierRef  = TxtSupplierRef.Text.TrimEnd();
            logs.LocationRef  = TxtWarehouseRef.Text.TrimEnd();
            logs.Qty          = Convert.ToInt32(TxtTotalGarments.Text.TrimEnd());
            logs.MovementDate = dateTimePicker1.Value;
            logs.UserID       = LoggedUser;
            if (FormMode == "New")
            {
                logs.StringMovementType = "New Purchase Order";
                logs.RecordType         = "Add-New-Item-Start";
                logs.Reference          = "Add New Purchase Order";
            }
            else
            {
                logs.StringMovementType = "Update Purchase Order";
                logs.RecordType         = "Update-Item-Start";
                logs.Reference          = "Update Purchase Order";
            }
            logs.SaveToSysLogTable();
            if (CheckBox1.Checked == true)
            {
                logs.LocationType      = 2;
                logs.MovementType      = 3;
                orderHead.DeliveryType = "Direct To Shop";
            }
            else
            {
                logs.LocationType      = 1;
                logs.MovementType      = 1;
                orderHead.DeliveryType = "Direct To Warehouse";
            }
            orderHead.OurRef          = TxtOurRef.Text.TrimEnd();
            orderHead.SupplierRef     = TxtSupplierRef.Text.TrimEnd();
            orderHead.WarehouseRef    = TxtWarehouseRef.Text.TrimEnd();
            orderHead.TotalHangers    = Convert.ToInt32(TxtTotalLooseItems.Text.TrimEnd());
            orderHead.TotalBoxes      = Convert.ToInt32(TxtTotalBoxes.Text.TrimEnd());
            orderHead.TotalGarments   = Convert.ToInt32(TxtTotalGarments.Text.TrimEnd());
            orderHead.NetAmount       = Convert.ToDecimal(TxtTotalNet.Text.TrimEnd());
            orderHead.Commission      = Convert.ToDecimal(TxtCommission.Text.TrimEnd());
            orderHead.DeliveryCharge  = Convert.ToDecimal(TxtDeliveryCharges.Text.TrimEnd());
            orderHead.VATAmount       = Convert.ToDecimal(TxtVATAmount.Text.TrimEnd());
            orderHead.TotalAmount     = Convert.ToDecimal(TxtTotalOrderPrice.Text.TrimEnd());
            orderHead.DeliveryDate    = dateTimePicker1.Value;
            orderHead.SupplierInvoice = TxtSuppliersInvoiceNumber.Text.TrimEnd();
            orderHead.SeasonName      = CboSeasonName.Text.TrimEnd();
            orderHead.Notes           = TxtNotes.Text.TrimEnd();
            orderHead.Shipper         = TxtShipperName.Text.TrimEnd();
            orderHead.ShipperInvoice  = TxtShipperInvoiceNumber.Text.TrimEnd();
            orderHead.UserID          = LoggedUser;
            if (FormMode == "New")
            {
                orderHead.SaveToPurchaseOrderHeadtbl();
                orderHead.PurchaseOrderID = orderHead.GetLastPurchaseOrderHead();
                logs.TransferReference    = orderHead.PurchaseOrderID;
                orderLine.PurchaseOrderID = orderHead.PurchaseOrderID;
                for (int i = 0; i < DgvItems.Rows.Count; i++)
                {
                    orderLine.StockCode            = DgvItems.Rows[i].Cells[0].Value.ToString();
                    orderLine.DeliveredQtyGarments = Convert.ToInt32(DgvItems.Rows[i].Cells[1].Value);
                    orderLine.DeliveredQtyBoxes    = Convert.ToInt32(DgvItems.Rows[i].Cells[2].Value);
                    orderLine.DeliveredQtyHangers  = Convert.ToInt32(DgvItems.Rows[i].Cells[3].Value);
                    orderLine.LineAmount           = Convert.ToDecimal(DgvItems.Rows[i].Cells[4].Value);
                    logs.StockCode            = DgvItems.Rows[i].Cells[0].Value.ToString();
                    logs.DeliveredQtyBoxes    = Convert.ToInt32(DgvItems.Rows[i].Cells[2].Value.ToString());
                    logs.DeliveredQtyGarments = Convert.ToInt32(DgvItems.Rows[i].Cells[1].Value.ToString());
                    logs.DeliveredQtyHangers  = Convert.ToInt32(DgvItems.Rows[i].Cells[3].Value.ToString());
                    logs.MovementValue        = Convert.ToDecimal(DgvItems.Rows[i].Cells[4].Value);
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                    if (orderLine.SaveToPurchaseOrderLinetbl() == true)
                    {
                        stock.StockCode = orderLine.StockCode;
                        if (stock.CheckStockCodeSave() == 0)
                        {
                            stock.StockCode            = orderLine.StockCode;
                            stock.SupplierRef          = orderHead.SupplierRef;
                            stock.SeasonName           = orderHead.SeasonName;
                            stock.DeadCode             = false;
                            stock.CostValue            = orderLine.LineAmount;
                            stock.DeliveredQtyBoxes    = orderLine.DeliveredQtyBoxes;
                            stock.DeliveredQtyGarments = orderLine.DeliveredQtyGarments;
                            stock.DeliveredQtyHangers  = orderLine.DeliveredQtyHangers;
                            stock.AmountTaken          = 0.00m;
                            stock.PCMarkUp             = -1.00m;
                            stock.ZeroQty = false;
                            stock.UserID  = LoggedUser;
                            stock.SaveStockCode();
                        }
                    }
                    else
                    {
                    }
                }
            }
            else
            {
                orderHead.PurchaseOrderID = Convert.ToInt32(TxtOrderID.Text.TrimEnd());
                logs.TransferReference    = orderHead.PurchaseOrderID;
                orderHead.UpdateToPurchaseOrderHeadtbl();
                for (int i = 0; i < DgvItems.Rows.Count; i++)
                {
                    orderLine.StockCode            = DgvItems.Rows[i].Cells[0].Value.ToString();
                    orderLine.DeliveredQtyGarments = Convert.ToInt32(DgvItems.Rows[i].Cells[1].Value);
                    orderLine.DeliveredQtyBoxes    = Convert.ToInt32(DgvItems.Rows[i].Cells[2].Value);
                    orderLine.DeliveredQtyHangers  = Convert.ToInt32(DgvItems.Rows[i].Cells[3].Value);
                    orderLine.LineAmount           = Convert.ToDecimal(DgvItems.Rows[i].Cells[4].Value);
                    orderLine.UpdateToPurchaseOrderLinetbl();
                    logs.StockCode            = orderLine.StockCode;
                    logs.DeliveredQtyBoxes    = orderLine.DeliveredQtyBoxes;
                    logs.DeliveredQtyGarments = orderLine.DeliveredQtyGarments;
                    logs.DeliveredQtyHangers  = orderLine.DeliveredQtyHangers;
                    logs.MovementValue        = orderLine.LineAmount;
                    logs.SaveToSysLogTable();
                    logs.SaveToStockMovementsTable();
                }
            }
            logs.StockCode   = TxtOurRef.Text.TrimEnd();
            logs.SupplierRef = TxtSupplierRef.Text.TrimEnd();
            logs.LocationRef = TxtWarehouseRef.Text.TrimEnd();
            logs.Qty         = Convert.ToInt32(TxtTotalGarments.Text.TrimEnd());
            if (FormMode == "New")
            {
                logs.StringMovementType = "New Purchase Order";
                logs.RecordType         = "Add-New-Item-Start";
                logs.Reference          = "Add New Purchase Order";
            }
            else
            {
                logs.StringMovementType = "Update Purchase Order";
                logs.RecordType         = "Update-Item-Start";
                logs.Reference          = "Update Purchase Order";
            }
            logs.SaveToSysLogTable();
            Close();
        }
        private void CmdOK_Click(object sender, EventArgs e)
        {
            clsShopAdjustmentHead adjustmentHead = new clsShopAdjustmentHead();
            clsShopAdjustmentLine adjustmentLine = new clsShopAdjustmentLine();
            clsLogs logs = new clsLogs();
            int     Total;

            Total = Convert.ToInt32(txtTotalGain.Text.TrimEnd()) + Convert.ToInt32(txtTotalLoss.Text.TrimEnd());

            int SavedID = 0;

            // Header of both adjustments and log file
            adjustmentHead.ShopRef        = txtWarehouseRef.Text.TrimEnd();
            adjustmentHead.Reference      = txtReference.Text.TrimEnd();
            adjustmentHead.TotalGainItems = Convert.ToInt32(txtTotalGain.Text.TrimEnd());
            adjustmentHead.TotalLossItems = Convert.ToInt32(txtTotalLoss.Text.TrimEnd());
            adjustmentHead.MovementDate   = Convert.ToDateTime(DateTimePicker1.Value);
            adjustmentHead.UserID         = LoggedInUser;
            if (FormMode == "New")
            {
                adjustmentHead.SaveShopAdjustmentHead();
                SavedID = adjustmentHead.GetLastShopAdjustmentHead();
            }
            else
            {
                clsLogs Dlogs = new clsLogs();  // Delete old StockMovements Data from Table
                Dlogs.TransferReference = Convert.ToInt32(TxtSID.Text.TrimEnd());
                Dlogs.MovementDate      = oldDate;
                Dlogs.MovementType      = 6;
                Dlogs.DeleteFromStockMovemmentsTable();
                Dlogs.MovementType = 7;
                Dlogs.DeleteFromStockMovemmentsTable();
                adjustmentHead.ID = Convert.ToInt32(TxtSID.Text.TrimEnd());

                adjustmentHead.UpdateShopAdjustmentHead();
            }
            logs.TransferReference = SavedID;
            adjustmentLine.ID      = SavedID;
            logs.LocationRef       = adjustmentHead.ShopRef;
            for (int index = 0; index < dgvItems.Rows.Count; index++)
            {
                // Saving details to tblWarehouseAdjustmentLines Table
                adjustmentLine.StockCode    = dgvItems.Rows[index].Cells[0].Value.ToString();
                adjustmentLine.MovementType = dgvItems.Rows[index].Cells[1].Value.ToString();
                adjustmentLine.Qty          = Convert.ToInt32(dgvItems.Rows[index].Cells[2].Value);

                // adjustmentLine.Value = Convert.ToDecimal(dgvItems.Rows[index].Cells[3].Value);
                // Saving details to tblStockMovements Table
                logs.StockCode    = adjustmentLine.StockCode;
                logs.LocationRef  = adjustmentHead.ShopRef;
                logs.LocationType = 2;
                logs.SupplierRef  = "N/A";
                if (adjustmentLine.MovementType == "Loss")
                {
                    logs.DeliveredQtyHangers = Convert.ToInt32(dgvItems.Rows[index].Cells[2].Value) * -1;
                }
                else
                {
                    logs.DeliveredQtyHangers = Convert.ToInt32(dgvItems.Rows[index].Cells[2].Value);
                }
                logs.DeliveredQtyGarments = 0;
                logs.DeliveredQtyBoxes    = 0;
                if (adjustmentLine.MovementType == "Loss")
                {
                    logs.MovementType = 7;
                }
                else
                {
                    logs.MovementType = 6;
                }
                logs.MovementDate       = adjustmentHead.MovementDate;
                logs.Reference          = adjustmentHead.Reference;
                logs.StringMovementType = "WarehouseAdjustment-" + adjustmentLine.MovementType;
                logs.RecordType         = "WarehouseAdjustment-Item";
                logs.UserID             = LoggedInUser;
                // Save to the relevent data tables on each itteration of the Datagridview control
                logs.SaveToSysLogTable();
                logs.SaveToStockMovementsTable();
                if (FormMode == "New")
                {
                    adjustmentLine.SaveShopAdjustmentLine();
                }
                else
                {
                    adjustmentLine.UpdateShopAdjustmentLine();
                }
            }
            Close();
        }