Ejemplo n.º 1
0
        private void Download()
        {
            DateTime dteProcessingDate = DateTime.Now;

            Products clsProduct = new Products();
            ProductDetails[] arrProductDetails = clsProduct.List();

            Contacts clsContact = new Contacts(clsProduct.Connection, clsProduct.Transaction);
            ContactDetails clsContactDetails ;

            ContactGroups clsContactGroup = new ContactGroups(clsProduct.Connection, clsProduct.Transaction);
            ContactGroupDetails clsContactGroupDetails;

            ProductVariations clsProductVariation = new ProductVariations(clsProduct.Connection, clsProduct.Transaction);
			DataTable dtaProductVariation;

            try{
                lblError.Text += "Creating xml file...<br /><br />";
                string xmlFileName = Server.MapPath(@"\RetailPlus\temp\ExportedProductList_" + CompanyDetails.BECompanyCode + "_" + dteProcessingDate.ToString("yyyyMMddHHmm") + ".xml");
                XmlTextWriter writer = new XmlTextWriter(xmlFileName, System.Text.Encoding.UTF8);
                
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteComment("This file represents the latest list of " + CompanyDetails.CompanyName + " products as of '" + dteProcessingDate.ToString("yyyyMMddHHmm")  + "'.");
                writer.WriteComment("Save this in your local file. Goto 'File', click 'Save As', select the location in your local directory, click 'Save'.");
                writer.WriteStartElement("Products");
                lblError.Text += "Creating Products...<br /><br />";
                foreach(ProductDetails clsProductDetails in arrProductDetails)
                {
                    writer.WriteStartElement("Item");
                    lblError.Text += "Writing " + clsProductDetails.ProductCode + "...";
                    writer.WriteAttributeString("ProductID", XmlConvert.ToString(clsProductDetails.ProductID));
                    writer.WriteAttributeString("ProductCode", clsProductDetails.ProductCode);
                    writer.WriteAttributeString("BarCode", clsProductDetails.BarCode);
                    writer.WriteAttributeString("ProductDesc", clsProductDetails.ProductDesc);
                    writer.WriteAttributeString("ProductGroupID", XmlConvert.ToString(clsProductDetails.ProductGroupID));
                    writer.WriteAttributeString("ProductGroupCode", clsProductDetails.ProductGroupCode);
                    writer.WriteAttributeString("ProductGroupName", clsProductDetails.ProductGroupName);
                    writer.WriteAttributeString("ProductSubGroupID", XmlConvert.ToString(clsProductDetails.ProductSubGroupID));
                    writer.WriteAttributeString("ProductSubGroupCode", clsProductDetails.ProductSubGroupCode);
                    writer.WriteAttributeString("ProductSubGroupName", clsProductDetails.ProductSubGroupName);
                    writer.WriteAttributeString("BaseUnitID", XmlConvert.ToString(clsProductDetails.BaseUnitID));
                    writer.WriteAttributeString("BaseUnitCode", clsProductDetails.BaseUnitCode);
                    writer.WriteAttributeString("BaseUnitName", clsProductDetails.BaseUnitName);
                    writer.WriteAttributeString("DateCreated", clsProductDetails.DateCreated.ToString("MM/dd/yyyy HH:mm:ss"));
                    writer.WriteAttributeString("Deleted",  XmlConvert.ToString(clsProductDetails.Deleted));
                    writer.WriteAttributeString("Price", XmlConvert.ToString(clsProductDetails.Price));
                    writer.WriteAttributeString("PurchasePrice", XmlConvert.ToString(clsProductDetails.PurchasePrice));
                    writer.WriteAttributeString("IncludeInSubtotalDiscount", XmlConvert.ToString(clsProductDetails.IncludeInSubtotalDiscount));
                    writer.WriteAttributeString("VAT", XmlConvert.ToString(clsProductDetails.VAT));
                    writer.WriteAttributeString("EVAT", XmlConvert.ToString(clsProductDetails.EVAT));
                    writer.WriteAttributeString("LocalTax", XmlConvert.ToString(clsProductDetails.LocalTax));
                    writer.WriteAttributeString("Quantity", XmlConvert.ToString(clsProductDetails.Quantity));
                    writer.WriteAttributeString("MinThreshold", XmlConvert.ToString(clsProductDetails.MinThreshold));
                    writer.WriteAttributeString("MaxThreshold", XmlConvert.ToString(clsProductDetails.MaxThreshold));

                    //Get the SUpplier Details
                    clsContactDetails = clsContact.Details(clsProductDetails.SupplierID);

                    writer.WriteAttributeString("ContactID", XmlConvert.ToString(clsContactDetails.ContactID));
                    writer.WriteAttributeString("ContactCode", clsContactDetails.ContactCode);
                    writer.WriteAttributeString("ContactName", clsContactDetails.ContactName);
                    
                    clsContactGroupDetails = clsContactGroup.Details(clsContactDetails.ContactGroupID);
                    writer.WriteAttributeString("ContactGroupCode", clsContactGroupDetails.ContactGroupCode);
                    writer.WriteAttributeString("ContactGroupCategory", clsContactGroupDetails.ContactGroupCategory.ToString("G"));
                    writer.WriteAttributeString("ContactGroupName", clsContactDetails.ContactGroupName);

                    writer.WriteAttributeString("ModeOfTerms", clsContactDetails.ModeOfTerms.ToString("G"));
                    writer.WriteAttributeString("Terms", clsContactDetails.Terms.ToString());
                    writer.WriteAttributeString("Address", clsContactDetails.Address);
                    writer.WriteAttributeString("BusinessName", clsContactDetails.BusinessName);
                    writer.WriteAttributeString("TelephoneNo", clsContactDetails.TelephoneNo);
                    writer.WriteAttributeString("Remarks", clsContactDetails.Remarks);
                    writer.WriteAttributeString("Debit", "0");
                    writer.WriteAttributeString("Credit", "0");
                    writer.WriteAttributeString("CreditLimit", clsContactDetails.CreditLimit.ToString());
                    writer.WriteAttributeString("IsCreditAllowed", clsContactDetails.IsCreditAllowed.ToString());
                    writer.WriteAttributeString("ContactDateCreated", clsContactDetails.DateCreated.ToString("MM/dd/yyyy HH:mm:ss"));

                    writer.WriteAttributeString("ChartOfAccountIDPurchase", XmlConvert.ToString(clsProductDetails.ChartOfAccountIDPurchase));
                    writer.WriteAttributeString("ChartOfAccountIDSold", XmlConvert.ToString(clsProductDetails.ChartOfAccountIDSold));
                    writer.WriteAttributeString("ChartOfAccountIDInventory", XmlConvert.ToString(clsProductDetails.ChartOfAccountIDInventory));
                    writer.WriteAttributeString("ChartOfAccountIDTaxPurchase", XmlConvert.ToString(clsProductDetails.ChartOfAccountIDTaxPurchase));
                    writer.WriteAttributeString("ChartOfAccountIDTaxSold", XmlConvert.ToString(clsProductDetails.ChartOfAccountIDTaxSold));
                    writer.WriteAttributeString("IsItemSold", XmlConvert.ToString(clsProductDetails.IsItemSold));
                    writer.WriteAttributeString("WillPrintProductComposition", XmlConvert.ToString(clsProductDetails.WillPrintProductComposition));
                    writer.WriteAttributeString("UpdatedBy", XmlConvert.ToString(clsProductDetails.UpdatedBy));
                    writer.WriteAttributeString("UpdatedOn", clsProductDetails.UpdatedOn.ToString("MM/dd/yyyy HH:mm:ss"));
                    writer.WriteAttributeString("PercentageCommision", XmlConvert.ToString(clsProductDetails.PercentageCommision));
                    writer.WriteAttributeString("QuantityIN", XmlConvert.ToString(clsProductDetails.QuantityIN));
                    writer.WriteAttributeString("QuantityOUT", XmlConvert.ToString(clsProductDetails.QuantityOUT));

                    //Get Variations
                    dtaProductVariation = clsProductVariation.ListAsDataTable(clsProductDetails.ProductID, null, System.Data.SqlClient.SortOrder.Ascending);
                    foreach (DataRow rowVariation in dtaProductVariation.Rows)
                    {
                        writer.WriteStartElement("Variation", null);
                        writer.WriteAttributeString("VariationCode", rowVariation["VariationCode"].ToString());
                        writer.WriteAttributeString("VariationType", rowVariation["VariationType"].ToString());
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                    lblError.Text += " Done.<br /><br />";
                }
                writer.WriteEndElement();

                //Write the XML to file and close the writer
                writer.Flush();
                writer.Close();
                lblError.Text += "Done creating XML file. <br /><br />";
                //lblError.Text = "/RetailPlus/temp/ExportedProductList_" + CompanyDetails.BECompanyCode + "_" + dteProcessingDate.ToString("yyyyMMddHHmm") + ".xml<br /><br />" + lblError.Text;
                clsProduct.CommitAndDispose();

                string stScript = "<Script>";
                stScript += "window.open('../../temp/ExportedProductList_" + CompanyDetails.BECompanyCode + "_" + dteProcessingDate.ToString("yyyyMMddHHmm") + ".xml');";
                stScript += "</Script>";
                Response.Write(stScript);
            }
            catch (Exception ex)
            {
                lblError.Text += "ERROR WHILE CREATING xml FILE: " + ex.Message;
            }
        }
Ejemplo n.º 2
0
        private void SynchronizeFromBranch()
        {
            try
            {
                lblError.Text = string.Empty;

                Branch clsBranch = new Branch();
                BranchDetails clsBranchDetails = clsBranch.Details(Convert.ToInt16(cboSynchronizeFromBranch.SelectedItem.Value.ToString()));
                clsBranch.CommitAndDispose();

                if (IPAddress.IsOpen(clsBranchDetails.DBIP, int.Parse(clsBranchDetails.DBPort)) == false)
                {
                    lblError.Text = "Sorry cannot connect to Branch '" + cboSynchronizeFromBranch.SelectedItem.Text + "'. Please check you connection to IP Address :" + clsBranchDetails.DBIP + ". <br /><br />";
                    lblError.Text += "HOW TO CHECK : <br /><br />";
                    lblError.Text += "  1. Open command prompt<br />";
                    lblError.Text += "  2. Type ping[space][IP Address]<br /><br />";
                    lblError.Text += "If the answer is 'Request timed out.' then contact system administrator.<br />";
                    lblError.Text += "Else if the answer is 'Reply...' Follow the next steps.<br /><br />";
                    lblError.Text += "  3. Type telnet[space][IP Address][sapce][IP Port]<br /><br />";

                    return;
                }

                Session.Timeout = 60 * 60 * 30;

                Products clsProduct = new Products();
                clsProduct.GetConnection();
                ProductDetails clsProductDetails;
                ContactGroups clsContactGroup = new ContactGroups(clsProduct.Connection, clsProduct.Transaction);
                Contacts clsContact = new Contacts(clsProduct.Connection, clsProduct.Transaction);
                Data.Unit clsUnit = new Data.Unit(clsProduct.Connection, clsProduct.Transaction);
                Data.ProductGroup clsProductGroup = new Data.ProductGroup(clsProduct.Connection, clsProduct.Transaction);
                Data.ProductSubGroup clsProductSubGroup = new Data.ProductSubGroup(clsProduct.Connection, clsProduct.Transaction);
                Data.Variation clsVariation = new Variation(clsProduct.Connection, clsProduct.Transaction);

                RemoteBranchInventory clsBranchInventory = new RemoteBranchInventory();
                clsBranchInventory.GetConnectionToBranch(clsBranchDetails.DBIP, clsBranchDetails.DBPort);

                Products clsBranchProduct = new Products(clsBranchInventory.Connection, clsBranchInventory.Transaction);
                ProductDetails[] arrBranchProductDetails = clsBranchProduct.List();

                ContactGroups clsBranchContactGroup = new ContactGroups(clsBranchInventory.Connection, clsBranchInventory.Transaction);
                Contacts clsBranchContact = new Contacts(clsBranchInventory.Connection, clsBranchInventory.Transaction);
                Data.Unit clsBranchUnit = new Data.Unit(clsBranchInventory.Connection, clsBranchInventory.Transaction);
                Data.ProductGroup clsBranchProductGroup = new Data.ProductGroup(clsBranchInventory.Connection, clsBranchInventory.Transaction);
                Data.ProductSubGroup clsBranchProductSubGroup = new Data.ProductSubGroup(clsBranchInventory.Connection, clsBranchInventory.Transaction);
                Data.Variation clsBranchVariation = new Variation(clsBranchInventory.Connection, clsBranchInventory.Transaction);
                
                foreach (ProductDetails clsBranchProductDetails in arrBranchProductDetails)
                {
                    clsProductDetails = clsBranchProductDetails;
                    try
                    {
                        clsProductDetails.ProductID = clsProduct.Details(clsProductDetails.BarCode).ProductID;
                        if (clsProductDetails.ProductID != 0)
                        {
                            lblError.Text += clsProductDetails.BarCode + " already exist.<br /><br />";
                            clsProduct.UpdatePurchasing(clsProductDetails.ProductID, clsBranchProductDetails.MatrixID, clsProductDetails.SupplierID, clsProductDetails.BaseUnitID, clsProductDetails.PurchasePrice);
                            clsProduct.UpdateSellingPrice(clsProductDetails.ProductID, clsBranchProductDetails.MatrixID, clsProductDetails.SupplierID, clsProductDetails.BaseUnitID, clsProductDetails.Price, clsProductDetails.Price1, clsProductDetails.Price2, clsProductDetails.Price3, clsProductDetails.Price4, clsProductDetails.Price5);
                        }
                        else
                        {
                            clsProductDetails.ProductID = clsProduct.DetailsByCode(Constants.BRANCH_ID_MAIN, clsProductDetails.BarCode).ProductID;
                            if (clsProductDetails.ProductID != 0)
                            {
                                lblError.Text += clsProductDetails.ProductCode + " already exist.<br /><br />";
                                clsProduct.UpdateBarcode(clsProductDetails.ProductID, clsProductDetails.BarCode);
                                clsProduct.UpdatePurchasing(clsProductDetails.ProductID, clsBranchProductDetails.MatrixID, clsProductDetails.SupplierID, clsProductDetails.BaseUnitID, clsProductDetails.PurchasePrice);
                                clsProduct.UpdateSellingPrice(clsProductDetails.ProductID, clsBranchProductDetails.MatrixID, clsProductDetails.SupplierID, clsProductDetails.BaseUnitID, clsProductDetails.Price, clsProductDetails.Price1, clsProductDetails.Price2, clsProductDetails.Price3, clsProductDetails.Price4, clsProductDetails.Price5);
                            }
                            else
                            {
                                clsProductDetails.SupplierID = clsContact.Details(clsProductDetails.SupplierCode).ContactID;
                                if (clsProductDetails.SupplierID == 0)
                                {
                                    ContactDetails clsBranchContactDetails = clsBranchContact.Details(clsProductDetails.SupplierCode);
                                    if (clsContactGroup.Details(clsBranchContactDetails.ContactGroupID).ContactGroupID == 0)
                                    {
                                        ContactGroupDetails clsBranchContactGroupDetails = clsBranchContactGroup.Details(clsBranchContactDetails.ContactGroupID);
                                        clsBranchContactDetails.ContactGroupID = clsContactGroup.Insert(clsBranchContactGroupDetails);
                                    }
                                    clsProductDetails.SupplierID = clsContact.Insert(clsBranchContactDetails);
                                }

                                clsProductDetails.BaseUnitID = clsUnit.Details(clsProductDetails.BaseUnitCode).UnitID;
                                if (clsProductDetails.BaseUnitID == 0)
                                {
                                    UnitDetails clsBranchUnitDetails = clsBranchUnit.Details(clsBranchProductDetails.BaseUnitID);
                                    clsProductDetails.BaseUnitID = clsUnit.Insert(clsBranchUnitDetails);
                                }

                                clsProductDetails.ProductGroupID = clsProductGroup.Details(clsProductDetails.ProductGroupCode).ProductGroupID;
                                if (clsProductDetails.ProductGroupID == 0)
                                {
                                    ProductGroupDetails clsBranchProductGroupDetails = clsBranchProductGroup.Details(clsBranchProductDetails.ProductGroupID);
                                    clsProductDetails.ProductGroupID = clsProductGroup.Insert(clsBranchProductGroupDetails);
                                }

                                clsProductDetails.ProductSubGroupID = clsProductSubGroup.Details(clsProductDetails.ProductSubGroupCode).ProductSubGroupID;
                                if (clsProductDetails.ProductSubGroupID == 0)
                                {
                                    ProductSubGroupDetails clsBranchProductSubGroupDetails = clsBranchProductSubGroup.Details(clsBranchProductDetails.ProductSubGroupID);
                                    clsProductDetails.ProductSubGroupID = clsProductSubGroup.Insert(clsBranchProductSubGroupDetails);
                                }

                                clsProductDetails.Quantity = 0;
                                clsProductDetails.QuantityIN = 0;
                                clsProductDetails.QuantityOUT = 0;

                                try
                                {
                                    clsProductDetails.ProductID = clsProduct.Insert(clsProductDetails);
                                    lblError.Text += clsProductDetails.ProductCode + " inserted.<br /><br />";
                                }
                                catch (Exception exProduct){
                                    lblError.Text += "<div class=ms-alternating> ERROR INSERTING ITEM: " + clsProductDetails.ProductCode + " err: " + exProduct.Message + ".</div><br /><br />";
                                    if (clsProduct.Connection.State == ConnectionState.Closed)
                                    {
                                        clsProduct = new Products();
                                        clsProduct.GetConnection();
                                        clsContactGroup = new ContactGroups(clsProduct.Connection, clsProduct.Transaction);
                                        clsContact = new Contacts(clsProduct.Connection, clsProduct.Transaction);
                                        clsUnit = new Data.Unit(clsProduct.Connection, clsProduct.Transaction);
                                        clsProductGroup = new Data.ProductGroup(clsProduct.Connection, clsProduct.Transaction);
                                        clsProductSubGroup = new Data.ProductSubGroup(clsProduct.Connection, clsProduct.Transaction);
                                        clsVariation = new Variation(clsProduct.Connection, clsProduct.Transaction);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception exProducts)
                    {
                        lblError.Text += "<div class=ms-alternating> ERROR INSERTING ITEM: " + clsProductDetails.ProductCode + " err: " + exProducts.Message + ".</div><br /><br />";
                        if (clsProduct.Connection.State == ConnectionState.Closed)
                        {
                            clsProduct = new Products();
                            clsProduct.GetConnection();
                            clsContactGroup = new ContactGroups(clsProduct.Connection, clsProduct.Transaction);
                            clsContact = new Contacts(clsProduct.Connection, clsProduct.Transaction);
                            clsUnit = new Data.Unit(clsProduct.Connection, clsProduct.Transaction);
                            clsProductGroup = new Data.ProductGroup(clsProduct.Connection, clsProduct.Transaction);
                            clsProductSubGroup = new Data.ProductSubGroup(clsProduct.Connection, clsProduct.Transaction);
                            clsVariation = new Variation(clsProduct.Connection, clsProduct.Transaction);
                        }
                    }
                }

                clsProduct.CommitAndDispose();
                clsBranchInventory.CommitAndDispose();

                lblError.Text = "Done synchronizing products from Branch: " + clsBranchDetails.BranchCode + "<br /><br />" + lblError.Text;
            }
            catch (Exception ex)
            {
                lblError.Text += "ERROR WHILE CREATING INSERT STATEMENT: " + ex.Message;
            }
        }