protected void btn_save_Click(object sender, EventArgs e) { using (CostarDataContext linq = new CostarDataContext()) { int ShippingOptionID = MyCommon.ToInt(Request["ShippingOptionID"]); StoreShippingOption shipping; if (this.HiddenField1.Value == "add") { shipping = new StoreShippingOption(); } else { shipping = linq.StoreShippingOptions.Where(c => c.ShippingOptionID == ShippingOptionID).SingleOrDefault(); } shipping.Name = this.txt_Name.Text; shipping.Instruction = this.txt_Description.Text; shipping.IsActive = this.CheckBox_Active.Checked; decimal price = 0; decimal.TryParse(this.txt_Price.Text, out price); switch (this.ddl_Per.SelectedValue) { case "0": shipping.PerItemFlatRate = price; shipping.PerKGRate = null; shipping.PerOrderFlatRate = null; break; case "1": shipping.PerItemFlatRate = null; shipping.PerKGRate = null; shipping.PerOrderFlatRate = price; break; case "2": shipping.PerItemFlatRate = null; shipping.PerKGRate = price; shipping.PerOrderFlatRate = null; break; } if (this.HiddenField1.Value == "add") { linq.StoreShippingOptions.InsertOnSubmit(shipping); } linq.SubmitChanges(); MyCommon.Alert("保存成功.", "StoreShippingManage.aspx"); } }
protected void btn_continue_Click(object sender, EventArgs e) { if (!this.ProductYes.Checked && !this.ProductNo.Checked) { MyCommon.Alert("请选择产品属性."); return; } if (this.ProductYes.Checked) { int Variant1 = MyCommon.ToInt(this.ddl_Vaiant1.SelectedValue); int Variant2 = MyCommon.ToInt(this.ddl_Vaiant2.SelectedValue); if (Variant1 == 0 && Variant2 == 0) { ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>alert('请选择属性.');</script>"); return; } if (_StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value)).Variant1TypeID == Variant1 && _StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value)).Variant2TypeID == Variant2) { ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>alert('选择的属性与现有属性相同,请重新选择.');</script>"); return; } if (Variant1 == Variant2) { ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>alert('选择的两种属性相同,请重新选择.');</script>"); return; } if (Variant1 > 0) { if (_StoreVariantTypeOptions.GetStoreVariantTypeOptionByVariantTypeID(Variant1).Count == 0) { string name = _StoreVariantTypes.GetStoreVariantTypeByID(Variant1).GroupName; ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>alert('属性1[" + name + "]中无数据,请添加.');</script>"); VaiantNo.Style.Value = "display: none;"; VaiantYes.Style.Value = "display: block;"; div_detail.Style.Value = "display: block;"; return; } } if (Variant2 > 0) { if (_StoreVariantTypeOptions.GetStoreVariantTypeOptionByVariantTypeID(Variant2).Count == 0) { string name = _StoreVariantTypes.GetStoreVariantTypeByID(Variant2).GroupName; ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>alert('属性2[" + name + "]中无数据,请添加.');</script>"); VaiantNo.Style.Value = "display: none;"; VaiantYes.Style.Value = "display: block;"; div_detail.Style.Value = "display: block;"; return; } } } StoreProductInventory inv = new StoreProductInventory(); inv.ProductID = MyCommon.ToLong(this.HiddenField_proId.Value); inv.QtyAvail = 0; inv.QtySold = 0; inv.QtyOnHold = 0; inv.SortOrder = 0; if (this.ProductNo.Checked) { _StoreProductInventoy.DelProductInventoryByProduct(MyCommon.ToLong(this.HiddenField_proId.Value)); inv.QtyAvail = MyCommon.ToInt(this.ProductNum.Text); _StoreProductInventoy.SaveProductInventory(inv); StoreProduct product = _StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value)); product.Variant1TypeID = null; product.Variant2TypeID = null; _StoreProduct.SaveProduct(product); MyCommon.Alert("保存库存数量成功.", "ProductList.aspx"); } if (this.ProductYes.Checked) { int Variant1 = MyCommon.ToInt(this.ddl_Vaiant1.SelectedValue); int Variant2 = MyCommon.ToInt(this.ddl_Vaiant2.SelectedValue); //当修改一个属性,清空库存 if (_StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value)).Variant1TypeID != Variant1 || _StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value)).Variant2TypeID != Variant2) { _StoreProductInventoy.DelProductInventoryByProduct(MyCommon.ToLong(this.HiddenField_proId.Value)); } _StoreProductInventoy.SaveProductInventory(inv); StoreProduct product = _StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value)); if (Variant1 == 0) { product.Variant1TypeID = null; } else { product.Variant1TypeID = Variant1; } if (Variant2 == 0) { product.Variant2TypeID = null; } else { product.Variant2TypeID = Variant2; } _StoreProduct.SaveProduct(product); ShowVariant(Variant1, Variant2); BindRepeater(MyCommon.ToInt(this.HiddenField_proId.Value)); VaiantNo.Style.Value = "display: none;"; VaiantYes.Style.Value = "display: block;"; ProductNum.Text = "0"; } }