Beispiel #1
0
		private void LoadRecord()
		{
			Int32 iID = Convert.ToInt32(Common.Decrypt(Request.QueryString["id"],Session.SessionID));
			Variation clsVariation = new Variation();
			VariationDetails clsDetails = clsVariation.Details(iID);
			clsVariation.CommitAndDispose();

			lblVariationID.Text = clsDetails.VariationID.ToString();
			txtVariationCode.Text = clsDetails.VariationCode;
			txtVariationType.Text = clsDetails.VariationType;
		}
Beispiel #2
0
		private void LoadOptions()
		{
			DataClass clsDataClass = new DataClass();
			lblProductGroupID.Text = Common.Decrypt((string)Request.QueryString["groupid"],Session.SessionID);
			lblProductGroupVariationID.Text = Common.Decrypt(Request.QueryString["id"],Session.SessionID);

			Variation clsVariation = new Variation();
			string VariationType = clsVariation.Details( Convert.ToInt32(lblProductGroupVariationID.Text)).VariationType;
			clsVariation.CommitAndDispose();

			ProductGroupVariations clsProductGroupVariation = new ProductGroupVariations();
			
			cboVariationType.DataTextField = "VariationType";
			cboVariationType.DataValueField = "VariationID";
			cboVariationType.DataSource =  clsDataClass.DataReaderToDataTable(clsProductGroupVariation.AvailableVariations(Convert.ToInt32(lblProductGroupID.Text),"VariationType",SortOption.Ascending)).DefaultView;
			cboVariationType.DataBind();
			cboVariationType.Items.Add(new ListItem(VariationType, lblProductGroupVariationID.Text));
			cboVariationType.SelectedIndex = cboVariationType.Items.Count - 1;

			clsProductGroupVariation.CommitAndDispose();		
		}
Beispiel #3
0
		private Int32 SaveRecord()
		{
			VariationDetails clsDetails = new VariationDetails();

			clsDetails.VariationCode = txtVariationCode.Text;
			clsDetails.VariationType = txtVariationType.Text;

			Variation clsVariation = new Variation();
			int id = clsVariation.Insert(clsDetails);
			clsVariation.CommitAndDispose();

			return id;
		}
Beispiel #4
0
		private void SaveRecord()
		{
			Variation clsVariation = new Variation();
			VariationDetails clsDetails = new VariationDetails();

			clsDetails.VariationID = Convert.ToInt16(lblVariationID.Text);
			clsDetails.VariationCode = txtVariationCode.Text;
			clsDetails.VariationType = txtVariationType.Text;

			clsVariation.Update(clsDetails);
			clsVariation.CommitAndDispose();
		}
Beispiel #5
0
		private void Upload()
		{
			if( ( txtPath.PostedFile != null ) && ( txtPath.PostedFile.ContentLength > 0 ) )
			{
				string fn = System.IO.Path.GetFileName(txtPath.PostedFile.FileName);
				string SaveLocation = "/RetailPlus/temp/uploaded_" + fn;

				txtPath.PostedFile.SaveAs(SaveLocation);
				XmlTextReader reader = new XmlTextReader(SaveLocation);
				reader.WhitespaceHandling = WhitespaceHandling.None;

				Stock clsStock = new Stock();
				clsStock.GetConnection();

				string strStockTransactionNo = null;
				long StockID = 0;
				long ContactID = 0;
				int UnitID = 0;
				long ProductGroupID = 0;
				long ProductSubGroupID = 0;
				long ProductID = 0;
				long ProductBaseMatrixID = 0;

				VariationDetails clsVariationDetails;
				int VariationID = 0;

				StockItemDetails clsStockItemDetails = new StockItemDetails();

				while (reader.Read()) 
				{
					switch (reader.NodeType) 
					{
						case XmlNodeType.Element:
							if (reader.Name == "Stock") 
							{
								strStockTransactionNo = reader.GetAttribute("TransactionNo");

								StockID = clsStock.Details(reader.GetAttribute("TransactionNo")).StockID;
								if (StockID > 0)
								{
									clsStock.CommitAndDispose();
									Label1.Text = "<b>This file has already been added to inventory.<br />";
									Label1.Text += "Please refer to transaction No: " + strStockTransactionNo + ".</b>";
									reader.Close();
									return;
								}
								Contacts clsContact = new Contacts(clsStock.Connection, clsStock.Transaction);
								ContactID = clsContact.Details(reader.GetAttribute("ContactCode")).ContactID;
								if (ContactID == 0)
								{
									ContactDetails clsContactDetails = new ContactDetails();
									clsContactDetails.ContactCode = reader.GetAttribute("ContactCode");
									clsContactDetails.ContactName = reader.GetAttribute("ContactName");
									clsContactDetails.ContactGroupID = Convert.ToInt32(reader.GetAttribute("ContactGroupID"));
                                    clsContactDetails.ModeOfTerms = (ModeOfTerms)Enum.Parse(typeof(ModeOfTerms), reader.GetAttribute("ModeOfTerms"));
									clsContactDetails.Terms = Convert.ToInt32(reader.GetAttribute("Terms"));
									clsContactDetails.Address = reader.GetAttribute("Address");
									clsContactDetails.BusinessName = reader.GetAttribute("BusinessName");
									clsContactDetails.TelephoneNo = reader.GetAttribute("TelephoneNo");
									clsContactDetails.Remarks = reader.GetAttribute("Remarks");
									clsContactDetails.Debit = Convert.ToDecimal(reader.GetAttribute("Debit"));
									clsContactDetails.Credit = Convert.ToDecimal(reader.GetAttribute("Credit"));
									clsContactDetails.IsCreditAllowed = Convert.ToBoolean(reader.GetAttribute("IsCreditAllowed"));
									clsContactDetails.CreditLimit = Convert.ToDecimal(reader.GetAttribute("CreditLimit"));
									ContactID = clsContact.Insert(clsContactDetails);
								}

                                StockDetails clsStockDetails = new StockDetails();
								clsStockDetails.TransactionNo = reader.GetAttribute("TransactionNo");
								clsStockDetails.StockTypeID = Convert.ToInt16(Constants.STOCK_TYPE_TRANSFER_FROM_BRANCH_ID);
								clsStockDetails.StockDate = DateTime.Now;
								clsStockDetails.SupplierID = ContactID;
								clsStockDetails.Remarks = reader.GetAttribute("StockRemarks") + Environment.NewLine + "Original Stock Date: " + reader.GetAttribute("StockDate");
								
								StockItemDetails[] itemDetails = new StockItemDetails[0];
								clsStockDetails.StockItems = itemDetails;

								StockID = clsStock.Insert(clsStockDetails);
							}
							else if (reader.Name == "Item") 
							{
								Data.Unit clsUnit = new Data.Unit(clsStock.Connection, clsStock.Transaction);
								UnitID = clsUnit.Details(reader.GetAttribute("ProductUnitCode")).UnitID;
								if (UnitID == 0) 
								{
									UnitDetails clsUnitDetails = new UnitDetails();
									clsUnitDetails.UnitCode = reader.GetAttribute("ProductUnitCode");
									clsUnitDetails.UnitName = reader.GetAttribute("ProductUnitName");
									UnitID = clsUnit.Insert(clsUnitDetails);
								}

								ProductGroup clsProductGroup = new ProductGroup(clsStock.Connection, clsStock.Transaction);
								ProductGroupID = clsProductGroup.Details(reader.GetAttribute("ProductGroupCode")).ProductGroupID;
								if (ProductGroupID == 0) 
								{
									Label1.Text += "inserting product group....";
									ProductGroupDetails clsProductGroupDetails = new ProductGroupDetails();
									clsProductGroupDetails.ProductGroupCode = reader.GetAttribute("ProductGroupCode");
									clsProductGroupDetails.ProductGroupName = reader.GetAttribute("ProductGroupName");
                                    clsProductGroupDetails.UnitDetails = new UnitDetails
                                    {
                                        UnitID = UnitID
                                    };
									clsProductGroupDetails.Price = Convert.ToDecimal(reader.GetAttribute("Price"));
									clsProductGroupDetails.PurchasePrice = Convert.ToDecimal(reader.GetAttribute("PurchasePrice"));
									clsProductGroupDetails.IncludeInSubtotalDiscount = Convert.ToBoolean(reader.GetAttribute("IncludeInSubtotalDiscount"));
									clsProductGroupDetails.VAT = Convert.ToDecimal(reader.GetAttribute("VAT"));
									clsProductGroupDetails.EVAT = Convert.ToDecimal(reader.GetAttribute("EVAT"));
									clsProductGroupDetails.LocalTax = Convert.ToDecimal(reader.GetAttribute("LocalTax"));
									ProductGroupID = clsProductGroup.Insert(clsProductGroupDetails);
								}
								
								ProductSubGroup clsProductSubGroup = new ProductSubGroup(clsStock.Connection, clsStock.Transaction);
								ProductSubGroupID = clsProductSubGroup.Details(reader.GetAttribute("ProductSubGroupCode")).ProductSubGroupID;
								if (ProductSubGroupID == 0) 
								{
									Label1.Text += "inserting product sub-group....";
									ProductSubGroupDetails clsProductSubGroupDetails = new ProductSubGroupDetails();
									clsProductSubGroupDetails.ProductGroupID = ProductGroupID;
									clsProductSubGroupDetails.ProductSubGroupCode = reader.GetAttribute("ProductSubGroupCode");
									clsProductSubGroupDetails.ProductSubGroupName = reader.GetAttribute("ProductSubGroupName");
									clsProductSubGroupDetails.BaseUnitID = UnitID;
									clsProductSubGroupDetails.Price = Convert.ToDecimal(reader.GetAttribute("Price"));
									clsProductSubGroupDetails.PurchasePrice = Convert.ToDecimal(reader.GetAttribute("PurchasePrice"));
									clsProductSubGroupDetails.IncludeInSubtotalDiscount = Convert.ToBoolean(reader.GetAttribute("IncludeInSubtotalDiscount"));
									clsProductSubGroupDetails.VAT = Convert.ToDecimal(reader.GetAttribute("VAT"));
									clsProductSubGroupDetails.EVAT = Convert.ToDecimal(reader.GetAttribute("EVAT"));
									clsProductSubGroupDetails.LocalTax = Convert.ToDecimal(reader.GetAttribute("LocalTax"));
									ProductSubGroupID = clsProductSubGroup.Insert(clsProductSubGroupDetails);
								}

								Products clsProduct = new Products(clsStock.Connection, clsStock.Transaction);
                                ProductID = clsProduct.Details(reader.GetAttribute("BarCode")).ProductID;
								if (ProductID == 0) 
								{
									Label1.Text += "inserting product....";
									ProductDetails clsProductDetails = new ProductDetails();
									clsProductDetails.ProductCode  = reader.GetAttribute("ProductCode");
									clsProductDetails.BarCode  = reader.GetAttribute("BarCode");
									clsProductDetails.ProductDesc = reader.GetAttribute("ProductDesc");
									clsProductDetails.ProductGroupID = ProductGroupID; 
									clsProductDetails.ProductSubGroupID  = ProductSubGroupID;
									clsProductDetails.ProductDesc  = reader.GetAttribute("ProductDesc");
									clsProductDetails.BaseUnitID = UnitID;
									clsProductDetails.Price = Convert.ToDecimal(reader.GetAttribute("Price")); 
									clsProductDetails.PurchasePrice = Convert.ToDecimal(reader.GetAttribute("PurchasePrice")); 
									clsProductDetails.IncludeInSubtotalDiscount = Convert.ToBoolean(reader.GetAttribute("IncludeInSubtotalDiscount")); 
									clsProductDetails.VAT = Convert.ToDecimal(reader.GetAttribute("VAT")); 
									clsProductDetails.EVAT = Convert.ToDecimal(reader.GetAttribute("EVAT")); 
									clsProductDetails.LocalTax = Convert.ToDecimal(reader.GetAttribute("LocalTax")); 
									clsProductDetails.Quantity = 0;
									clsProductDetails.MinThreshold = Convert.ToDecimal(reader.GetAttribute("MinThreshold"));
									clsProductDetails.MaxThreshold = Convert.ToDecimal(reader.GetAttribute("MaxThreshold"));
									clsProductDetails.SupplierID = Contacts.DEFAULT_SUPPLIER_ID;
									ProductID = clsProduct.Insert(clsProductDetails);
								}

                                //ProductVariationsMatrix clsProductVariationsMatrix = new ProductVariationsMatrix(clsStock.Connection, clsStock.Transaction);
                                //ProductBaseMatrixID = clsProductVariationsMatrix.BaseDetails(0, 0, ProductID, reader["ItemBaseVariationDescription"].ToString()).MatrixID;
                                //if (ProductBaseMatrixID == 0)
                                //{
                                //    ProductBaseMatrixDetails clsBaseDetails = new ProductBaseMatrixDetails();
                                //    clsBaseDetails.ProductID = ProductID;
                                //    clsBaseDetails.Description = reader.GetAttribute("ItemBaseVariationDescription");
                                //    clsBaseDetails.UnitID = UnitID;
                                //    clsBaseDetails.Price = Convert.ToDecimal(reader.GetAttribute("Price"));
                                //    clsBaseDetails.PurchasePrice = Convert.ToDecimal(reader.GetAttribute("PurchasePrice"));
                                //    clsBaseDetails.IncludeInSubtotalDiscount = Convert.ToBoolean(reader.GetAttribute("IncludeInSubtotalDiscount"));
                                //    clsBaseDetails.Quantity = 0;
                                //    clsBaseDetails.VAT = Convert.ToDecimal(reader.GetAttribute("VAT"));
                                //    clsBaseDetails.EVAT = Convert.ToDecimal(reader.GetAttribute("EVAT"));
                                //    clsBaseDetails.LocalTax = Convert.ToDecimal(reader.GetAttribute("LocalTax"));
                                //    clsBaseDetails.MinThreshold = Convert.ToDecimal(reader.GetAttribute("MinThreshold"));
                                //    clsBaseDetails.MaxThreshold = Convert.ToDecimal(reader.GetAttribute("MaxThreshold"));
                                //    ProductBaseMatrixID = clsProductVariationsMatrix.InsertBaseVariation(clsBaseDetails);
                                //    clsBaseDetails.MatrixID = ProductBaseMatrixID;
                                //}

								clsStockItemDetails = new StockItemDetails();
								clsStockItemDetails.StockID = StockID;
								clsStockItemDetails.ProductID = ProductID;
								clsStockItemDetails.VariationMatrixID = ProductBaseMatrixID;
								clsStockItemDetails.ProductUnitID = UnitID;
								clsStockItemDetails.StockTypeID = Convert.ToInt16(Constants.STOCK_TYPE_TRANSFER_FROM_BRANCH_ID);
								clsStockItemDetails.StockDate = DateTime.Now;
								clsStockItemDetails.Quantity = Convert.ToDecimal(reader.GetAttribute("ItemQuantity"));
								clsStockItemDetails.Remarks = reader.GetAttribute("ItemRemarks");

                                Security.AccessUserDetails clsAccessUserDetails = (Security.AccessUserDetails)Session["AccessUserDetails"];
                                clsStock.AddItem(Constants.BRANCH_ID_MAIN, strStockTransactionNo, clsAccessUserDetails.Name, clsStockItemDetails, StockDirections.Increment);
							}
							else if (reader.Name == "Variation" && reader.GetAttribute("VariationCode") != null)
							{
								Variation clsVariation = new Variation(clsStock.Connection, clsStock.Transaction);
								VariationID = clsVariation.Details(reader.GetAttribute("VariationCode")).VariationID;
								if (VariationID == 0 ) 
								{	
									clsVariationDetails = new VariationDetails();
									clsVariationDetails.VariationCode = reader.GetAttribute("VariationCode");
									clsVariationDetails.VariationType = reader.GetAttribute("VariationType");
									VariationID = clsVariation.Insert(clsVariationDetails);
								}

								ProductVariationDetails clsProductVariationDetails = new ProductVariationDetails();
								clsProductVariationDetails.ProductID = ProductID;
								clsProductVariationDetails.VariationID = VariationID;

								ProductVariations clsProductVariation = new ProductVariations(clsStock.Connection, clsStock.Transaction);
								if (clsProductVariation.isExist(clsProductVariationDetails) == false)
								{
									long ProductVariationID = clsProductVariation.Insert(clsProductVariationDetails);
								}

							}
							else if (reader.Name == "VariationMatrix" && reader.GetAttribute("VariationCode") != null)
							{
								Variation clsVariation = new Variation(clsStock.Connection, clsStock.Transaction);
								VariationID = clsVariation.Details(reader.GetAttribute("VariationCode")).VariationID;
								if (VariationID == 0) 
								{
									clsVariationDetails = new VariationDetails();
									clsVariationDetails.VariationCode = reader.GetAttribute("VariationCode");
									clsVariationDetails.VariationType = reader.GetAttribute("VariationType");
									VariationID = clsVariation.Insert(clsVariationDetails);
								}

								ProductVariationsMatrix clsProductVariationsMatrix = new ProductVariationsMatrix(clsStock.Connection, clsStock.Transaction);
								if (clsProductVariationsMatrix.isExist(ProductBaseMatrixID, VariationID) == false)
								{
									ProductVariationsMatrixDetails clsProductVariationsMatrixDetails = new ProductVariationsMatrixDetails();
                                    clsProductVariationsMatrixDetails.ProductID = ProductID;
                                    clsProductVariationsMatrixDetails.MatrixID = ProductBaseMatrixID;
									clsProductVariationsMatrixDetails.VariationID = VariationID;
									clsProductVariationsMatrixDetails.Description = reader.GetAttribute("Description");
									clsProductVariationsMatrix.SaveVariation(clsProductVariationsMatrixDetails);
								}
							}
							else
							{
								Label1.Text = "<b>Reader Name:<b>" + reader.Name + "<br />";
							}
							break;
						case XmlNodeType.Text:
							Label1.Text = "<b>" + reader.LocalName + ":<b>" + reader.Value + "<br />";
							break;
					}       
				}
				reader.Close();
				
				clsStock.CommitAndDispose();
				Label1.Text = "<b>Transaction No.: " + strStockTransactionNo + " has been successfully transferred.<br />";
			}
			else
			{
				Response.Write("Please select a file to upload.");
			}

		}
Beispiel #6
0
		private bool Delete()
		{
			bool boRetValue = false;
			string stIDs = "";

			foreach(DataListItem item in lstItem.Items)
			{
				HtmlInputCheckBox chkList = (HtmlInputCheckBox) item.FindControl("chkList");
				if (chkList!=null)
				{
					if (chkList.Checked == true)
					{
						stIDs += chkList.Value + ",";		
						boRetValue = true;
					}
				}
			}
			if (boRetValue)
			{
				Variation clsVariation = new Variation();
				clsVariation.Delete( stIDs.Substring(0,stIDs.Length-1));
				clsVariation.CommitAndDispose();
			}

			return boRetValue;
		}
Beispiel #7
0
		private void LoadList()
		{	
			Variation clsVariation = new Variation();
			DataClass clsDataClass = new DataClass();

			string SortField = "VariationType";
			if (Request.QueryString["sortfield"]!=null)
			{	SortField = Common.Decrypt(Request.QueryString["sortfield"].ToString(), Session.SessionID);	}

            System.Data.SqlClient.SortOrder sortoption = System.Data.SqlClient.SortOrder.Ascending;
			if (Request.QueryString["sortoption"]!=null)
            { sortoption = (System.Data.SqlClient.SortOrder)Enum.Parse(typeof(SortOption), Common.Decrypt(Request.QueryString["sortoption"], Session.SessionID), true); }

			if (Request.QueryString["Search"]==null)
			{
				PageData.DataSource = clsVariation.ListAsDataTable(SortField, sortoption).DefaultView;
			}
			else
			{						
				string SearchKey = Common.Decrypt((string)Request.QueryString["search"],Session.SessionID);
				PageData.DataSource = clsDataClass.DataReaderToDataTable(clsVariation.Search(SearchKey, SortField, sortoption)).DefaultView;
			}

			clsVariation.CommitAndDispose();

			int iPageSize = Convert.ToInt16(Session["PageSize"]) ;
			
			PageData.AllowPaging = true;
			PageData.PageSize = iPageSize;
			try
			{
				PageData.CurrentPageIndex = Convert.ToInt16(cboCurrentPage.SelectedItem.Value) - 1;				
				lstItem.DataSource = PageData;
				lstItem.DataBind();
			}
			catch
			{
				PageData.CurrentPageIndex = 1;
				lstItem.DataSource = PageData;
				lstItem.DataBind();
			}			
			
			cboCurrentPage.Items.Clear();
			for (int i=0; i < PageData.PageCount;i++)
			{
				int iValue = i + 1;
				cboCurrentPage.Items.Add(new ListItem(iValue.ToString(),iValue.ToString()));
				if (PageData.CurrentPageIndex == i)
				{	cboCurrentPage.Items[i].Selected = true;}
				else
				{	cboCurrentPage.Items[i].Selected = false;}
			}
			lblDataCount.Text = " of " + " " + PageData.PageCount;
		}
Beispiel #8
0
        protected void lstItem_ItemCommand(object sender, DataListCommandEventArgs e)
        {
            HtmlInputCheckBox chkList = (HtmlInputCheckBox)e.Item.FindControl("chkList");
            string stParam = string.Empty;
            switch (e.CommandName)
            {
                case "imgItemDelete":
                    Variation clsVariation  = new Variation();
                    clsVariation.Delete(chkList.Value);
                    clsVariation.CommitAndDispose();

                    LoadList();
                    break;
                case "imgItemEdit":
                    stParam = "?task=" + Common.Encrypt("edit", Session.SessionID) + "&id=" + Common.Encrypt(chkList.Value, Session.SessionID);
                    Response.Redirect("Default.aspx" + stParam);
                    break;
            }
        }
        private void LoadVariation()
        {
            Variation clsVariation = new Variation();
            cboVariationType.DataTextField = "VariationType";
            cboVariationType.DataValueField = "VariationID";
            cboVariationType.DataSource = clsVariation.ListAsDataTable().DefaultView;
            cboVariationType.DataBind();
            cboVariationType.SelectedIndex = 0;

            clsVariation.CommitAndDispose();	
        }
        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;
            }
        }