예제 #1
0
		private void btnSubmit_ServerClick(object sender, EventArgs e)
		{
			BPProducts bp = new BPProducts();
			BEProducts.tbl_ProductsRow Product;
			DSProducts = new BEProducts();
			if (ProductID == 0)
			{
				// Add new product
				Product = DSProducts.tbl_Products.Newtbl_ProductsRow();
				hdnProductInventoryLevel.Value = txtProductInventoryLevel.Text;
			}
			else
			{
				// Edit a Product
				DSProducts = bp.SelectProductsByID(ProductID);
				Product = DSProducts.tbl_Products.FindByProductID(ProductID);				
			}
			//all content to be updated/inserted between here
			Editor ProductDescription = edtProductDescription;
			string strProductDescription = Request.Form[ProductDescription.Editor_HiddenField].ToString();

			Product.ProductName = txtProductName.Text;
			Product.ProductDescription = strProductDescription;
			Product.ProductCategoryID = Convert.ToInt32(ddlProductCategories.SelectedValue);
			if(Product.ProductCategoryID == -1)
			{
				Product.ProductCategoryID = 0;
			}
			if(txtProductPrice.Text != "")
			{
				Product.ProductPrice = Convert.ToDecimal(txtProductPrice.Text);
			}
			else
			{
				Product.ProductPrice = 0;
			}
			if(txtProductSalePrice.Text != "")
			{
				Product.ProductSalePrice = Convert.ToDecimal(txtProductSalePrice.Text);
			}
			else
			{
				Product.ProductPrice = 0;
			}
			if (dtStart.SelectedDate != DateTime.MinValue)
			{
				Product.ProductSaleStartDate = Convert.ToDateTime(dtStart.SelectedDate);
			}
			else
			{
				Product.ProductSaleStartDate = DateTime.Now;
			}
			if (dtEnd.SelectedDate != DateTime.MinValue)
			{
				Product.ProductSaleEndDate = Convert.ToDateTime(dtEnd.SelectedDate);
			}
			else
			{
				Product.ProductSaleEndDate = DateTime.Now;
			}
			Product.ProductChargeTax = chkProductChargeTax.Checked;
			Product.ProductSize = txtProductSize.Text;
			Product.ProductInventoryLevel = Convert.ToInt32(hdnProductInventoryLevel.Value);
			if(txtProductReorderLevel.Text !="")
			{
				Product.ProductReorderLevel = Convert.ToInt32(txtProductReorderLevel.Text);
			}
			else
			{
				Product.ProductReorderLevel = 0;
			}
			if(txtShippingSurcharge.Text != "")
			{
				Product.ProductShippingSurcharge = Convert.ToDecimal(txtShippingSurcharge.Text);
			}
			else
			{
				Product.ProductShippingSurcharge = 0;
			}
			ImageWizard ddlImageSelector = Page.FindControl("ddlImageSelector") as ImageWizard;
			if (ddlImageSelector.SelectedImage > 0)
			{
				Product.ProductImageID = Convert.ToInt32(ddlImageSelector.SelectedImage);
			}
			else
			{
				Product.SetProductImageIDNull();
			}

			Product.ProductActive = chkProductActive.Checked;
			Product.DateModified = DateTime.Now;
			Product.ModifiedByAdminID = Convert.ToInt32(CarrielUser.CarrielIdentity.MemberID);
			//all content to be updated/inserted between here			
			if (ProductID == 0)
			{
				//Add new Application Category
				Product.DateCreated = DateTime.Now;

				DSProducts.tbl_Products.Addtbl_ProductsRow(Product);
			}
			bp.Update(DSProducts);
			int tmpProductID = Product.ProductID;

			if (hdnShippingMethodsChanged.Value == "true" || ProductID == 0)
			{
				DSProducts.Merge(bp.SelectProductShippingMethodsByProductID(tmpProductID));
				hdnShippingMethodsChanged.Value = "false";
				BEProducts.tbl_ProductShippingMethodsRow dr;

				for(int i = 0; i < dlCheckBoxes.Items.Count; i++)
				{
					HtmlInputCheckBox tmpChk = dlCheckBoxes.Items[i].FindControl("checkBox") as HtmlInputCheckBox;
					if (ProductID == 0)
					{
						dr = DSProducts.tbl_ProductShippingMethods.Newtbl_ProductShippingMethodsRow();				
						dr.ProductID = tmpProductID;
						dr.ShippingMethodID = Convert.ToInt32(tmpChk.Attributes["ShippingMethodID"]);
						dr.ShippingRegionID = Convert.ToInt32(tmpChk.Attributes["ShippingRegionID"]);
						dr.ProductShippingMethodActive = tmpChk.Checked;
						DSProducts.tbl_ProductShippingMethods.Addtbl_ProductShippingMethodsRow(dr);
					}
					else
					{
						dr = DSProducts.tbl_ProductShippingMethods.FindByProductShippingMethodID(Convert.ToInt32(tmpChk.Attributes["ProductShippingMethodID"]));
						if(dr.ProductShippingMethodActive != tmpChk.Checked)
						{
							dr.ProductShippingMethodActive = tmpChk.Checked;
						}
					}
				}
			}
			bp.UpdateProductShippingMethods(DSProducts);

			//CreateResizedImage(BEImages DSImages, int ImageID, string prefix, int width, int height, Page page)
			if (!Product.IsProductImageIDNull())
			{
				MWUtility.CreateResizedImage(Product.ProductImageID, "p", "tn", imageSize, thumbSize, this);
			}
			//save Document

			//exit page
			if (ProductID == 0)
			{
				Response.Redirect("EditProducts.aspx?ProductID=" + Product.ProductID);
			}
			else
			{
				Response.Redirect("BrowseProducts.aspx");
			}
		}