/// <summary> /// 页面控件赋值 /// </summary> /// <param name="Code"></param> protected void Evaluate(string Code) { if (!string.IsNullOrEmpty(Code)) { product = _HSProduct.LoadHSProductByHSCode(Code); if (product != null) { Txt_HSCode.Text = product.HSCode; Txt_HSName.Text = product.HSName; Txt_DiscountTax.Text = product.DiscountTax.ToString(); Txt_GeneralTax.Text = product.GeneralTax.ToString(); Txt_ExportTax.Text = product.ExportTax.ToString(); Txt_ConsumeTax.Text = product.ConsumeTax.ToString(); Txt_RiseTax.Text = product.RiseTax.ToString(); Txt_CertificateSign.Text = product.CertificateSign; Txt_PricingSign.Text = product.PricingSign; Txt_TaxDemandSign.Text = product.TaxDemandSign; Txt_Remark.Text = product.Remark; Gv_Productiy.DataSource = product.HSProperty; Gv_Productiy.DataBind(); Session["product"] = product; } } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Addparoduct_Click(object sender, EventArgs e) { if (Txt_HSCode.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('HS编码不能为空!')", true); Txt_HSCode.Focus(); } else if (Txt_HSName.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('商品名称不能为空!')", true); Txt_HSName.Focus(); } else if (Txt_DiscountTax.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('优惠税率不能为空!')", true); Txt_DiscountTax.Focus(); } else if (Txt_GeneralTax.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('普通税率不能为空!')", true); Txt_GeneralTax.Focus(); } else if (Txt_ExportTax.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('出口税率不能为空!')", true); Txt_ExportTax.Focus(); } else if (Txt_ConsumeTax.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('消费税率不能为空!')", true); Txt_ConsumeTax.Focus(); } else if (Txt_RiseTax.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('增值税率不能为空!')", true); Txt_RiseTax.Focus(); } else { if (!Regex.IsMatch(Txt_DiscountTax.Text.Trim(), RTax)) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('优惠税率只能输入0.01-1的数字且小数点后保留2位!')", true); Txt_DiscountTax.Focus(); } else if (!Regex.IsMatch(Txt_GeneralTax.Text.Trim(), RTax)) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('普通税率只能输入0.01-1的数字且小数点后保留2位!')", true); Txt_GeneralTax.Focus(); } else if (!Regex.IsMatch(Txt_ExportTax.Text.Trim(), RTax)) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('出口税率只能输入0.01-1的数字且小数点后保留2位!')", true); Txt_ExportTax.Focus(); } else if (!Regex.IsMatch(Txt_ConsumeTax.Text.Trim(), RTax)) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('消费税率只能输入0.01-1的数字且小数点后保留2位!')", true); Txt_ConsumeTax.Focus(); } else if (!Regex.IsMatch(Txt_RiseTax.Text.Trim(), RTax)) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('增值税率只能输入0.01-1的数字且小数点后保留2位!')", true); Txt_RiseTax.Focus(); } else { if (Checking(Txt_HSCode.Text.Trim().ToUpper(), 0)) { if (Checking(Txt_HSName.Text.Trim().ToUpper(), 1)) { if (Session["product"] == null) { product = new HSProduct(); product.HSID = Guid.NewGuid(); } else { product = (HSProduct)Session["product"]; } product.HSCode = Txt_HSCode.Text.Trim().ToUpper(); product.HSName = Txt_HSName.Text.Trim().ToUpper(); product.DiscountTax = decimal.Parse(Txt_DiscountTax.Text.Trim()); product.GeneralTax = decimal.Parse(Txt_GeneralTax.Text.Trim()); product.ExportTax = decimal.Parse(Txt_ExportTax.Text.Trim()); product.ConsumeTax = decimal.Parse(Txt_ConsumeTax.Text.Trim()); product.RiseTax = decimal.Parse(Txt_RiseTax.Text.Trim()); product.CertificateSign = Txt_CertificateSign.Text.Trim(); product.PricingSign = Txt_PricingSign.Text.Trim(); product.TaxDemandSign = Txt_TaxDemandSign.Text.Trim(); product.Remark = Txt_Remark.Text.Trim(); _HSProduct.AddHSProduct(product); if (product.HSProperty.Count != 0) { foreach (HSProperty HSpt in product.HSProperty) { if (HSpt.ChangeTracker.State == ObjectState.Unchanged) { HSpt.ChangeTracker.State = ObjectState.Added; } _HSProperty.AddHSProperty(HSpt); } } ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('添加成功!')", true); Session.Remove("product"); InitialControl(this.Controls); Gv_Productiy.DataSource = null; Gv_Productiy.DataBind(); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('该名称已经存请重新输入!')", true); Txt_HSName.Focus(); } } else { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('该编码已经存在请重新输入!')", true); Txt_HSCode.Focus(); } } } }
/// <summary> /// 属性名添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Add_Click(object sender, EventArgs e) { if (Txt_Property.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('属性名不能为空!')", true); Txt_Property.Focus(); } else if (Checking(Txt_Property.Text.Trim(), 2)) { if (Session["product"] != null) { product = (HSProduct)Session["product"]; } else { product = new HSProduct(); product.HSID = Guid.NewGuid(); } //if (product == null) //{ // product = new HSProduct(); // product.HSID = Guid.NewGuid(); //} HSProperty property = new HSProperty(); property.HSPID = Guid.NewGuid(); property.HSID = product.HSID; property.PropertyName = Txt_Property.Text.Trim(); property.ChineseRemark = Txt_ChineseRemark.Text.Trim(); //_HSProperty.AddHSProperty(property); product.HSProperty.Add(property); Session.Remove("product"); Session["product"] = product; Gv_Productiy.DataSource = product.HSProperty; Gv_Productiy.DataBind(); if (Gv_Productiy.Rows.Count > 0) { DVProperty.Visible = true; } else { DVProperty.Visible = false; } Txt_ChineseRemark.Text = string.Empty; Txt_Property.Text = string.Empty; } else { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('属性名已经存在,请重新输入!')", true); Txt_Property.Focus(); } }
/// <summary> /// 删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Close_Click(object sender, EventArgs e) { if (product == null) { product = (HSProduct)Session["product"]; } bool Ok = false; for (int i = Gv_Productiy.Rows.Count - 1; i > -1; i--) { string Bar = string.Empty; if (((CheckBox)Gv_Productiy.Rows[i].FindControl("chkId")).Checked) { Ok = true; Bar = Gv_Productiy.DataKeys[i].Value.ToString(); foreach (HSProperty hs in product.HSProperty) { if (hs.HSID == Guid.Parse(Bar)) { property = hs; } } product.HSProperty.Remove(property); Session["product"] = product; } } if (Ok == true) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('删除成功!')", true); if (product.HSProperty.Count == 0) { btn_Close.Visible = false; } Gv_Productiy.DataSource = product.HSProperty; Gv_Productiy.DataBind(); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('请选择要移除的记录!')", true); } }
private void FixupHSProduct(HSProduct previousValue, bool skipKeys = false) { if (IsDeserializing) { return; } if (previousValue != null && previousValue.HSRelations.Contains(this)) { previousValue.HSRelations.Remove(this); } if (HSProduct != null) { if (!HSProduct.HSRelations.Contains(this)) { HSProduct.HSRelations.Add(this); } HSID = HSProduct.HSID; } else if (!skipKeys) { HSID = null; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("HSProduct") && (ChangeTracker.OriginalValues["HSProduct"] == HSProduct)) { ChangeTracker.OriginalValues.Remove("HSProduct"); } else { ChangeTracker.RecordOriginalValue("HSProduct", previousValue); } if (HSProduct != null && !HSProduct.ChangeTracker.ChangeTrackingEnabled) { HSProduct.StartTracking(); } } }
/// <summary> /// 修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Gv_Productiy_RowUpdating(object sender, GridViewUpdateEventArgs e) { string HScode=ViewState["HSCode"].ToString(); if (HScode == Txt_HSCode.Text.Trim().ToUpper()) { property = _HSProperty.FindHSPropertyByHSPID(Gv_Productiy.DataKeys[e.RowIndex].Value.ToString()); property.PropertyName = ((TextBox)Gv_Productiy.Rows[e.RowIndex].FindControl("Txt_PropertyName")).Text.Trim(); property.ChineseRemark = ((TextBox)Gv_Productiy.Rows[e.RowIndex].FindControl("Txt_ChineseRemark")).Text.Trim(); _HSProperty.ModifyProperty(property); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!')</script>"); product = _HSProduct.FindHSProductByHSCode(HScode); Gv_Productiy.EditIndex = -1; Gv_Productiy.DataSource = product.HSProperty; Gv_Productiy.DataBind(); Session.Remove("product"); Session["product"] = product; } }
/// <summary> /// 取消 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Gv_Productiy_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { if (product == null) { product = (HSProduct)Session["product"]; } Gv_Productiy.EditIndex = -1; Gv_Productiy.DataSource = product.HSProperty; Gv_Productiy.DataBind(); }
/// <summary> /// 删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Close_Click(object sender, EventArgs e) { bool Ok = false; for (int i = Gv_Productiy.Rows.Count - 1; i > -1; i--) { string Bar = string.Empty; if (((CheckBox)Gv_Productiy.Rows[i].FindControl("chkId")).Checked) { Ok = true; Bar = Gv_Productiy.DataKeys[i].Value.ToString(); HSProperty hsproperty = _HSProperty.FindHSPropertyByHSPID(Bar); _HSProperty.RemoveHSProperty(hsproperty); } } if (Ok == true) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('删除成功!')", true); product = _HSProduct.LoadHSProductByHSCode(Request.QueryString["HSCode"]); Session.Remove("product"); Session["product"] = product; if (product.HSProperty.Count == 0) { btn_Close.Visible = false; } Gv_Productiy.DataSource = product.HSProperty; Gv_Productiy.DataBind(); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('请选择要移除的记录!')", true); } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Addparoduct_Click(object sender, EventArgs e) { if (product == null) { product = (HSProduct)Session["product"]; } if (Txt_HSCode.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('HS编码不能为空!')", true); Txt_HSCode.Focus(); } else if (Txt_HSName.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('商品名称不能为空!')", true); Txt_HSName.Focus(); } else if (Txt_DiscountTax.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('优惠税率不能为空!')", true); Txt_DiscountTax.Focus(); } else if (Txt_GeneralTax.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('普通税率不能为空!')", true); Txt_GeneralTax.Focus(); } else if (Txt_ExportTax.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('出口税率不能为空!')", true); Txt_ExportTax.Focus(); } else if (Txt_ConsumeTax.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('消费税率不能为空!')", true); Txt_ConsumeTax.Focus(); } else if (Txt_RiseTax.Text.Trim() == "") { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('增值税率不能为空!')", true); Txt_RiseTax.Focus(); } else { if (!Regex.IsMatch(Txt_DiscountTax.Text.Trim(), RTax)) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('优惠税率只能输入0.01-1的数字且小数点后保留2位!')", true); Txt_DiscountTax.Focus(); } else if (!Regex.IsMatch(Txt_GeneralTax.Text.Trim(), RTax)) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('普通税率只能输入0.01-1的数字且小数点后保留2位!')", true); Txt_GeneralTax.Focus(); } else if (!Regex.IsMatch(Txt_ExportTax.Text.Trim(), RTax)) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('出口税率只能输入0.01-1的数字且小数点后保留2位!')", true); Txt_ExportTax.Focus(); } else if (!Regex.IsMatch(Txt_ConsumeTax.Text.Trim(), RTax)) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('消费税率只能输入0.01-1的数字且小数点后保留2位!')", true); Txt_ConsumeTax.Focus(); } else if (!Regex.IsMatch(Txt_RiseTax.Text.Trim(), RTax)) { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('增值税率只能输入0.01-1的数字且小数点后保留2位!')", true); Txt_RiseTax.Focus(); } else { //if (Checking(Txt_HSCode.Text.Trim().ToUpper(), 0)) //{ // if (Checking(Txt_HSName.Text.Trim().ToUpper(), 1)) // { product.HSCode = Txt_HSCode.Text.Trim().ToUpper(); product.HSName = Txt_HSName.Text.Trim().ToUpper(); product.DiscountTax = decimal.Parse(Txt_DiscountTax.Text.Trim()); product.GeneralTax = decimal.Parse(Txt_GeneralTax.Text.Trim()); product.ExportTax = decimal.Parse(Txt_ExportTax.Text.Trim()); product.ConsumeTax = decimal.Parse(Txt_ConsumeTax.Text.Trim()); product.RiseTax = decimal.Parse(Txt_RiseTax.Text.Trim()); product.CertificateSign = Txt_CertificateSign.Text.Trim(); product.PricingSign = Txt_PricingSign.Text.Trim(); product.TaxDemandSign = Txt_TaxDemandSign.Text.Trim(); product.Remark = Txt_Remark.Text.Trim(); _HSProduct.ModifyHSProduct(product); //foreach (HSProperty pt in product.HSProperty) //{ // _HSProperty.AddHSProperty(pt); //} ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "Url()", true); InitialControl(this.Controls); // } // else // { // ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('该名称已经存请重新输入!')", true); // Txt_HSName.Focus(); // } //} //else //{ // ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('该编码已经存在请重新输入!')", true); // Txt_HSCode.Focus(); //} } } }
/// <summary> /// 修改 /// </summary> /// <param name="product">海关商品</param> public void ModifyHSProduct(HSProduct product) { if (product == null) throw new ArgumentNullException("HSProduct is null"); IUnitOfWork unitOfWork = _HSProductRepository.UnitOfWork; _HSProductRepository.Modify(product); //complete changes in this unit of work unitOfWork.CommitAndRefreshChanges(); }
/// <summary> /// 新增海关商品 /// </summary> /// <param name="product">商品</param> public void AddHSProduct(HSProduct product) { if (product == null) throw new ArgumentNullException("HSProduct is null"); IUnitOfWork unitOfWork = _HSProductRepository.UnitOfWork; _HSProductRepository.Add(product); //complete changes in this unit of work unitOfWork.Commit(); }