protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["HAWB"] != null) { hawb = (HAWB)Session["HAWB"]; if (Request.QueryString["type"] != "" && Request.QueryString["type"]!=null) { type = Request.QueryString["type"]; gv_Box.DataSource = hawb.HAWBBoxes; gv_Box.DataBind(); GV_item.DataSource = hawb.HAWBItems; GV_item.DataBind(); } else { item = new HAWBItem(); box = new HAWBBox(); gv_item(); gv_box(); } Evaluate(); ViewState["UrlReferrer"] = Request.UrlReferrer.ToString(); } } }
protected void but_AddItem_Click(object sender, EventArgs e) { if (type != "") { foreach (HAWBItem it in hawb.HAWBItems) { item.ItemID = it.ItemID; AddItem(); } } else { item = new HAWBItem(); item.ItemID = Guid.NewGuid(); AddItem(); } }
protected void Page_Load(object sender, EventArgs e) { hawb = (HAWB)Session["HAWB"]; if (!IsPostBack) { if (Session["HAWB"] != null) { if (Request.QueryString["type"] == "Amend")//修改页面显示 { type = Request.QueryString["type"]; ViewState["type"] = type; But_AddHAWB.Text = "保 存"; gv_Box.DataSource = hawb.HAWBBoxes; gv_Box.DataBind(); GV_item.DataSource = hawb.HAWBItems; GV_item.DataBind(); } else //新建页面显示 { item = new HAWBItem(); box = new HAWBBox(); gv_item(); gv_box(); But_AddHAWB.Text = "创 建"; } Evaluate(); BoxType(); ViewState["UrlReferrer"] = Request.UrlReferrer.ToString(); } else { Response.Write("<script>alert('请先填写用户信息!');location='HAWBAdd.aspx'</script>"); } } }
public void TestAddHAWB() { //实力化一个虚假运单对象 HAWB HAWBObj = new HAWB { HID=Guid.NewGuid(), BarCode = "2010", //条形码 Carrier = "中国航空", //承运单位 SettleType = 0, //预算方式 ServiceType = 0, //快件或包裹 CreateTime = DateTime.Now, //创建日期 Status = 0, //运单状态 ShipperName = "沈志伟", //发件人姓名或者公司 ShipperContactor = "沈志伟", //发件人姓名 ShipperCountry = "01", //发件人国家 ShipperRegion = "021", //发件人区号 ShipperAddress = "test address", //发件人地址 ShipperZipCode = "200435", //发件人邮编 ShipperTel = "13817011234", //发件人联系电话 ConsigneeContactor = "李宏", //收件人姓名 ConsigneeCountry = "02", //收件人国家 ConsigneeRegion = "022", //收件人区号 ConsigneeAddress = "Japan address", //收件人地址 ConsigneeZipCode = "201011", //收件人邮编 ConsigneeTel = "120120", //收件人联系电话 WeightType = 2, //计重方式 TotalVolume = 10, //总体积 TotalWeight = 10, //总重量 Piece = 10, //件数 IsInternational = true //是否是国际运单 }; //定义盒子 HAWBBox HAWBBox01 = new HAWBBox { BoxType = 0, //盒子类型 Weight = 10, //重量 TransCurrency = 0, //运费货币 Piece = 10 //件数 }; HAWBBox HAWBBox02 = new HAWBBox { BoxType = 0, //盒子类型 Weight = 20, //重量 TransCurrency = 0, //运费货币 Piece = 20 //件数 }; //定义货物 HAWBItem HAWBItem01 = new HAWBItem { Name = "货物01", //货物名称 Piece = 10, //货物件数 UnitAmount = 10, //单价 TotalAmount = 10 //总价 }; HAWBItem HAWBItem02 = new HAWBItem { Name = "货物02", //货物名称 Piece = 20, //货物件数 UnitAmount = 20, //单价 TotalAmount = 20 //总价 }; //定义企业用户 User user01 = new User { LoginName = "test001", //注册名 Password = "******", //密码 RealName = "张三", //真实姓名 //Department = "研发部", //部门名称 //PostCode = "200435", //邮政编码 Phone = "110", //电话 //CountryCode = "01", //国家编号 //RegionCode = "01", //区域编号 //Address = "XXX路XXX号", //地址 UpdateTime = DateTime.Now, //更新日期 CreateTime = DateTime.Now, //创建日期 Operator = "沈志伟", //操作人 FeeDiscountType = 0, //费用折扣类型 FeeDiscountRate = 1, //费用折扣率 WeightDiscountType = 0, //重量折扣类型 WeightDiscountRate = 1, //重量折扣率 SettleType = 0, //结算类型 WeightCalType = 0, //计量方式 Status = 0 //可用状态 }; //in HAWBObj.HAWBBoxes.Add(HAWBBox01); //HAWBObj.HAWBBox.Add(HAWBBox02); //HAWBObj.HAWBItems.Add(HAWBItem01); //HAWBObj.HAWBItem.Add(HAWBItem02); HAWBObj.User = user01; //begin _HAWBManagementService.AddHAWB(HAWBObj); }
/// <summary> /// 添加包裹 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void but_AddItem_Click(object sender, EventArgs e) { item = new HAWBItem(); item.ItemID = Guid.NewGuid(); AddItem(); }
/// <summary> /// 物品移除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GV_item_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Delete") { int inex = Convert.ToInt16(e.CommandArgument); Guid id = Guid.Parse(GV_item.DataKeys[inex].Value.ToString()); foreach (HAWBItem it in hawb.HAWBItems) { if (it.ItemID == id) { item = it; } } hawb.HAWBItems.Remove(item); Session["HAWB"] = hawb; GV_item.DataSource = hawb.HAWBItems; GV_item.DataBind(); } }
/// <summary> /// 物品更新 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GV_item_RowUpdating(object sender, GridViewUpdateEventArgs e) { int inex = Convert.ToInt16(e.RowIndex); Guid id = Guid.Parse(GV_item.DataKeys[inex].Value.ToString()); foreach (HAWBItem it in hawb.HAWBItems) { if (it.ItemID == id) { item = it; } } if (((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPiece") as TextBox).Text.Trim() == "") { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('物品件数不能为空!')</script>"); ((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPiece") as TextBox).Focus(); } else if (((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemName") as TextBox).Text.Trim() == "") { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('物品名称不能为空!')</script>"); ((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemName") as TextBox).Focus(); } else if (((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPice") as TextBox).Text.Trim() == "") { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('物品价值不能为空!')</script>"); ((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPice") as TextBox).Focus(); } else { if (!Regex.IsMatch(((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPiece") as TextBox).Text.Trim(), intPattern)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('件数只能输入整数!')</script>"); ((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPiece") as TextBox).Focus(); } else if (!Regex.IsMatch(((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPice") as TextBox).Text.Trim(), decimalPattern)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('价值只能整数或小数且小数点后保留2位!')</script>"); ((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPice") as TextBox).Focus(); } else if (int.Parse(((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPiece") as TextBox).Text.Trim()) * decimal.Parse(((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPice") as TextBox).Text.Trim()) > 100) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('总计价值超过100美金不能添加!')</script>"); ((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPiece") as TextBox).Focus(); } else if (int.Parse(((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPiece") as TextBox).Text) * decimal.Parse(((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPice") as TextBox).Text) + ReturnTotal(4) > 100 && GV_item.Rows.Count > 1) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('总计价值超过100美金不能添加!')</script>"); ((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPiece") as TextBox).Focus(); } else { item.Name = ((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemName") as TextBox).Text.Trim(); item.Piece = int.Parse(((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPiece") as TextBox).Text.Trim()); item.Remark = ((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemType") as TextBox).Text.Trim(); item.UnitAmount = decimal.Parse(((TextBox)GV_item.Rows[e.RowIndex].FindControl("txt_ItemPice") as TextBox).Text.Trim()); hawb.HAWBItems.Add(item); GV_item.EditIndex = -1; Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('更新成功!')</script>"); GV_item.DataSource = hawb.HAWBItems; GV_item.DataBind(); } } }