Beispiel #1
0
        private void bgwZeroOutInvNeg_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                mstStatus = "Connecting to database...";
                bgwZeroOutInvNeg.ReportProgress(10);

                AceSoft.RetailPlus.Client.MasterDB clsMasterConnection = new AceSoft.RetailPlus.Client.MasterDB();
                clsMasterConnection.GetConnection();

                mstStatus = "Updating product negative quantity to zero...";
                bgwZeroOutInvNeg.ReportProgress(20);
                Data.ProductInventories clsProductInventories = new Data.ProductInventories(clsMasterConnection.Connection, clsMasterConnection.Transaction);
                clsProductInventories.ZeroOutNegativeInventorygByBranch(mclsBranchDetails.BranchID);

                mstStatus = "Commiting to database...";
                bgwZeroOutInvNeg.ReportProgress(90);
                clsMasterConnection.CommitAndDispose();

                bgwZeroOutInvNeg.ReportProgress(100);
            }
            catch { throw; }
        }
Beispiel #2
0
        private void SaveToDB()
        {
            AceSoft.RetailPlus.Client.MasterDB clsMasterConnection;
			Data.Products clsProducts;
            Data.Inventory clsInventory;
            Data.Database clsDatabase;

            Data.ERPConfig clsERPConfig = new Data.ERPConfig();
            Data.ERPConfigDetails clsERPConfigDetails = clsERPConfig.Details();
            string strReferenceNo = Constants.CLOSE_INVENTORY_CODE + CompanyDetails.BECompanyCode + DateTime.Now.Year.ToString() + clsERPConfig.get_LastClosingNo();
            clsERPConfig.CommitAndDispose();

            Data.ProductDetails clsProductDetails;
            Data.InventoryDetails clsInventoryDetails;

            DateTime dtePostingDate = DateTime.Now;

            if (!Directory.Exists("invfiles/backups/")) Directory.CreateDirectory("invfiles/backups/");
            if (File.Exists("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + ".inv"))
            {
                if (MessageBox.Show("You have already loaded the inventory for this branch today. Please verify the file you are loading. Would you like to continue?", "RetailPlus", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
                {
                    bgwSavetoDB.ReportProgress(100);
                    return;
                }
            }
            else
            {
                System.IO.File.Copy("invfiles/" + mclsBranchDetails.BranchCode + ".inv", "invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + ".inv");
            }

            InvExLog clsInvExLog = new InvExLog();
            clsInvExLog.BranchDetails = mclsBranchDetails;
            if (File.Exists("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_exc.inv"))
            {
                System.IO.File.Copy("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_exc.inv", "invfiles/backups/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_exc.inv" + "_" + DateTime.Now.ToString("yyyyddMMhhmmss"));
                System.IO.File.Delete("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_exc.inv");
            }

            InvLoadedLog clsInvLoadedLog = new InvLoadedLog();
            clsInvLoadedLog.BranchDetails = mclsBranchDetails;
            if (File.Exists("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_saved.inv"))
            {
                System.IO.File.Copy("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_saved.inv", "invfiles/backups/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_saved.inv" + "_" + DateTime.Now.ToString("yyyyddMMhhmmss"));
                System.IO.File.Delete("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_saved.inv");
            }

            decimal iCtr = 1, iRows = Decimal.Parse(mdtItems.Rows.Count.ToString());
            foreach (System.Data.DataRow dr in mdtItems.Rows)
			{
                string strBarCode = dr["BarCode"].ToString();
                decimal decQuantity = decimal.Parse(dr["Quantity"].ToString());

                string strUnit = dr["Unit"].ToString();
                string strDescription = dr["Description"].ToString();

                mstStatus = "[" + iCtr.ToString() + "/" + iRows + "]Saving " + strBarCode + strDescription;
                bgwSavetoDB.ReportProgress(int.Parse(Math.Ceiling(iCtr / iRows * 100).ToString()));
                iCtr++;

        back:
                clsMasterConnection = new AceSoft.RetailPlus.Client.MasterDB();
                try
                {
                    clsMasterConnection.GetConnection();

                    clsProducts = new Data.Products(clsMasterConnection.Connection, clsMasterConnection.Transaction);
                    clsInventory = new Data.Inventory(clsMasterConnection.Connection, clsMasterConnection.Transaction);

                    clsProductDetails = clsProducts.Details(mclsBranchDetails.BranchID, strBarCode);
                    if (clsProductDetails.ProductID == 0)
                    {
                        clsInvExLog.AddItem(strBarCode, decQuantity, strUnit, strDescription);
                    }
                    else
                    {
                        clsInvLoadedLog.AddItem(strBarCode, decQuantity, strUnit, strDescription);

                        /*******************************************
                        * Add to Inventory
                        * ****************************************/
                        //clsProduct.AddQuantity(lngProductID, decQuantity);
                        //if (lngVariationMatrixID != 0) { clsProductVariationsMatrix.AddQuantity(lngVariationMatrixID, decQuantity); }
                        // July 26, 2011: change the above codes to the following
                        clsProducts.AddQuantity(mclsBranchDetails.BranchID, clsProductDetails.ProductID, 0, decQuantity, Data.Products.getPRODUCT_INVENTORY_MOVEMENT_VALUE(Data.PRODUCT_INVENTORY_MOVEMENT.ADD_INVENTORY_BY_BRANCH) + " /" + clsProductDetails.BaseUnitCode, DateTime.Now, strReferenceNo, "System");


                        //-- STEP 1: Insert to tblInventory for reporting purposes
                        /*******************************************
                            * Add to Inventory Analysis
                            * ****************************************/
                        clsInventoryDetails = new Data.InventoryDetails();
                        clsInventoryDetails.BranchID = mclsBranchDetails.BranchID;
                        clsInventoryDetails.PostingDateFrom = clsERPConfigDetails.PostingDateFrom;
                        clsInventoryDetails.PostingDateTo = clsERPConfigDetails.PostingDateTo;
                        clsInventoryDetails.PostingDate = dtePostingDate;
                        clsInventoryDetails.ReferenceNo = strReferenceNo;
                        clsInventoryDetails.ContactID = clsProductDetails.SupplierID;
                        clsInventoryDetails.ContactCode = clsProductDetails.SupplierCode;
                        clsInventoryDetails.ProductID = clsProductDetails.ProductID;
                        clsInventoryDetails.ProductCode = clsProductDetails.ProductCode;
                        clsInventoryDetails.VariationMatrixID = 0;
                        clsInventoryDetails.MatrixDescription = "";
                        clsInventoryDetails.ClosingQuantity = clsProductDetails.Quantity;
                        clsInventoryDetails.ClosingActualQuantity = decQuantity + clsProductDetails.Quantity;
                        clsInventoryDetails.ClosingCost = (decQuantity + clsProductDetails.Quantity) * clsProductDetails.PurchasePrice;
                        clsInventoryDetails.ClosingVAT = (decQuantity + clsProductDetails.Quantity) * clsProductDetails.PurchasePrice * decimal.Parse("0.12");	// Purchase Cost with VAT
                        clsInventoryDetails.PurchasePrice = clsProductDetails.PurchasePrice;

                        clsInventory.Insert(clsInventoryDetails);
                    }
                    
                    clsMasterConnection.CommitAndDispose();
                }
                catch (Exception ex) 
                {
                    if (ex.Message.Contains("Deadlock found when trying to get lock; try restarting transaction"))
                    { try { clsMasterConnection.ThrowException(ex); } catch { } clsDatabase = new Data.Database(); clsDatabase.FlushHosts(); clsDatabase.CommitAndDispose(); goto back; }
                    else if (ex.InnerException.Message.Contains("Deadlock found when trying to get lock; try restarting transaction"))
                    { try { clsMasterConnection.ThrowException(ex); } catch { } clsDatabase = new Data.Database(); clsDatabase.FlushHosts(); clsDatabase.CommitAndDispose(); goto back; }
                }
			}
            
            bgwSavetoDB.ReportProgress(100);
        }
Beispiel #3
0
        private void bgwZeroOutInvNeg_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                mstStatus = "Connecting to database...";
                bgwZeroOutInvNeg.ReportProgress(10);

                AceSoft.RetailPlus.Client.MasterDB clsMasterConnection = new AceSoft.RetailPlus.Client.MasterDB();
                clsMasterConnection.GetConnection();

                mstStatus = "Updating product negative quantity to zero...";
                bgwZeroOutInvNeg.ReportProgress(20);
                Data.ProductInventories clsProductInventories = new Data.ProductInventories(clsMasterConnection.Connection, clsMasterConnection.Transaction);
                clsProductInventories.ZeroOutNegativeInventorygByBranch(mclsBranchDetails.BranchID);

                mstStatus = "Commiting to database...";
                bgwZeroOutInvNeg.ReportProgress(90);
                clsMasterConnection.CommitAndDispose();

                bgwZeroOutInvNeg.ReportProgress(100);
            }
            catch { throw; }
        }
Beispiel #4
0
        private void SaveToDB()
        {
            AceSoft.RetailPlus.Client.MasterDB clsMasterConnection;
            Data.Products  clsProducts;
            Data.Inventory clsInventory;
            Data.Database  clsDatabase;

            Data.ERPConfig        clsERPConfig        = new Data.ERPConfig();
            Data.ERPConfigDetails clsERPConfigDetails = clsERPConfig.Details();
            string strReferenceNo = Constants.CLOSE_INVENTORY_CODE + CompanyDetails.BECompanyCode + DateTime.Now.Year.ToString() + clsERPConfig.get_LastClosingNo();

            clsERPConfig.CommitAndDispose();

            Data.ProductDetails   clsProductDetails;
            Data.InventoryDetails clsInventoryDetails;

            DateTime dtePostingDate = DateTime.Now;

            if (!Directory.Exists("invfiles/backups/"))
            {
                Directory.CreateDirectory("invfiles/backups/");
            }
            if (File.Exists("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + ".inv"))
            {
                if (MessageBox.Show("You have already loaded the inventory for this branch today. Please verify the file you are loading. Would you like to continue?", "RetailPlus", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
                {
                    bgwSavetoDB.ReportProgress(100);
                    return;
                }
            }
            else
            {
                System.IO.File.Copy("invfiles/" + mclsBranchDetails.BranchCode + ".inv", "invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + ".inv");
            }

            InvExLog clsInvExLog = new InvExLog();

            clsInvExLog.BranchDetails = mclsBranchDetails;
            if (File.Exists("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_exc.inv"))
            {
                System.IO.File.Copy("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_exc.inv", "invfiles/backups/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_exc.inv" + "_" + DateTime.Now.ToString("yyyyddMMhhmmss"));
                System.IO.File.Delete("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_exc.inv");
            }

            InvLoadedLog clsInvLoadedLog = new InvLoadedLog();

            clsInvLoadedLog.BranchDetails = mclsBranchDetails;
            if (File.Exists("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_saved.inv"))
            {
                System.IO.File.Copy("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_saved.inv", "invfiles/backups/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_saved.inv" + "_" + DateTime.Now.ToString("yyyyddMMhhmmss"));
                System.IO.File.Delete("invfiles/" + mclsBranchDetails.BranchCode + DateTime.Now.ToString("yyyyMMdd") + "_saved.inv");
            }

            decimal iCtr = 1, iRows = Decimal.Parse(mdtItems.Rows.Count.ToString());

            foreach (System.Data.DataRow dr in mdtItems.Rows)
            {
                string  strBarCode  = dr["BarCode"].ToString();
                decimal decQuantity = decimal.Parse(dr["Quantity"].ToString());

                string strUnit        = dr["Unit"].ToString();
                string strDescription = dr["Description"].ToString();

                mstStatus = "[" + iCtr.ToString() + "/" + iRows + "]Saving " + strBarCode + strDescription;
                bgwSavetoDB.ReportProgress(int.Parse(Math.Ceiling(iCtr / iRows * 100).ToString()));
                iCtr++;

back:
                clsMasterConnection = new AceSoft.RetailPlus.Client.MasterDB();
                try
                {
                    clsMasterConnection.GetConnection();

                    clsProducts  = new Data.Products(clsMasterConnection.Connection, clsMasterConnection.Transaction);
                    clsInventory = new Data.Inventory(clsMasterConnection.Connection, clsMasterConnection.Transaction);

                    clsProductDetails = clsProducts.Details(mclsBranchDetails.BranchID, strBarCode);
                    if (clsProductDetails.ProductID == 0)
                    {
                        clsInvExLog.AddItem(strBarCode, decQuantity, strUnit, strDescription);
                    }
                    else
                    {
                        clsInvLoadedLog.AddItem(strBarCode, decQuantity, strUnit, strDescription);

                        /*******************************************
                         * Add to Inventory
                         * ****************************************/
                        //clsProduct.AddQuantity(lngProductID, decQuantity);
                        //if (lngVariationMatrixID != 0) { clsProductVariationsMatrix.AddQuantity(lngVariationMatrixID, decQuantity); }
                        // July 26, 2011: change the above codes to the following
                        clsProducts.AddQuantity(mclsBranchDetails.BranchID, clsProductDetails.ProductID, 0, decQuantity, Data.Products.getPRODUCT_INVENTORY_MOVEMENT_VALUE(Data.PRODUCT_INVENTORY_MOVEMENT.ADD_INVENTORY_BY_BRANCH) + " /" + clsProductDetails.BaseUnitCode, DateTime.Now, strReferenceNo, "System");


                        //-- STEP 1: Insert to tblInventory for reporting purposes

                        /*******************************************
                         * Add to Inventory Analysis
                         * ****************************************/
                        clsInventoryDetails                       = new Data.InventoryDetails();
                        clsInventoryDetails.BranchID              = mclsBranchDetails.BranchID;
                        clsInventoryDetails.PostingDateFrom       = clsERPConfigDetails.PostingDateFrom;
                        clsInventoryDetails.PostingDateTo         = clsERPConfigDetails.PostingDateTo;
                        clsInventoryDetails.PostingDate           = dtePostingDate;
                        clsInventoryDetails.ReferenceNo           = strReferenceNo;
                        clsInventoryDetails.ContactID             = clsProductDetails.SupplierID;
                        clsInventoryDetails.ContactCode           = clsProductDetails.SupplierCode;
                        clsInventoryDetails.ProductID             = clsProductDetails.ProductID;
                        clsInventoryDetails.ProductCode           = clsProductDetails.ProductCode;
                        clsInventoryDetails.VariationMatrixID     = 0;
                        clsInventoryDetails.MatrixDescription     = "";
                        clsInventoryDetails.ClosingQuantity       = clsProductDetails.Quantity;
                        clsInventoryDetails.ClosingActualQuantity = decQuantity + clsProductDetails.Quantity;
                        clsInventoryDetails.ClosingCost           = (decQuantity + clsProductDetails.Quantity) * clsProductDetails.PurchasePrice;
                        clsInventoryDetails.ClosingVAT            = (decQuantity + clsProductDetails.Quantity) * clsProductDetails.PurchasePrice * decimal.Parse("0.12"); // Purchase Cost with VAT
                        clsInventoryDetails.PurchasePrice         = clsProductDetails.PurchasePrice;

                        clsInventory.Insert(clsInventoryDetails);
                    }

                    clsMasterConnection.CommitAndDispose();
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Deadlock found when trying to get lock; try restarting transaction"))
                    {
                        try { clsMasterConnection.ThrowException(ex); } catch { } clsDatabase = new Data.Database(); clsDatabase.FlushHosts(); clsDatabase.CommitAndDispose(); goto back;
                    }
                    else if (ex.InnerException.Message.Contains("Deadlock found when trying to get lock; try restarting transaction"))
                    {
                        try { clsMasterConnection.ThrowException(ex); } catch { } clsDatabase = new Data.Database(); clsDatabase.FlushHosts(); clsDatabase.CommitAndDispose(); goto back;
                    }
                }
            }

            bgwSavetoDB.ReportProgress(100);
        }