📄 ordermodfy.aspx.cs
字号:
}
}
/// <summary>
/// 修改信息,订单信息,产品信息更新增加
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void add_Click(object sender, EventArgs e)
{
YXShop.Model.Orders order = new YXShop.Model.Orders();
decimal carriage = 0;//计算运费
#region 增加产品
YXShop.Model.LineItem orderModel = null;
if (SelectProduct1.PID > 0)
{
List<YXShop.Model.Product> productModel = product.GetId(SelectProduct1.PID);
if (productModel.Count == 1)
{
orderModel = new YXShop.Model.LineItem();
orderModel.OrderId = orderId;
orderModel.ProductID = SelectProduct1.PID;
orderModel.ProductName = productModel[0].Pro_Name;
orderModel.UnitPrice = productModel[0].Pro_ShopPrice;
orderModel.Quantity = 1;
orderModel.ProIntegral = productModel[0].Pro_Integral;
orderModel.MarketPrice = productModel[0].Pro_MarketPrice;
#region 计算运费
decimal weight = 0;//获取商品重量
weight = this.wieht(Convert.ToInt32(SelectProduct1.PID));
YXShop.BLL.YXShop_Deliver databd = new YXShop.BLL.YXShop_Deliver();
YXShop.Model.Orders dataOrder = bll.GetId(orderId);
string Courier = dataOrder.Courier;
List<YXShop.Model.YXShop_Deliver> datamb = databd.GetList("D_ID=" + Courier + "");
if (datamb.Count > 0)
{
if (weight < Convert.ToDecimal(datamb[0].D_InceptWeight))
{
carriage = Convert.ToDecimal(datamb[0].D_InceptPrice);
}
else if (weight > Convert.ToDecimal(datamb[0].D_InceptWeight))
{
carriage = Convert.ToDecimal(datamb[0].D_InceptPrice) + Convert.ToDecimal(((weight - Convert.ToDecimal(datamb[0].D_InceptWeight)) / Convert.ToDecimal(datamb[0].D_AddWeightLadder)).ToString("f2")) * Convert.ToDecimal(datamb[0].D_AddPriceLadder);
}
}
#endregion
}
else
{
//该产品不存在
}
}
#endregion
#region 订单信息收集
if (string.IsNullOrEmpty(orderId))
return;//err
order.OrderId = orderId;
order.ConsigneeName = WebUtility.replaceStr(TextBox1.Text.Trim());
order.ConsigneeTel = WebUtility.replaceStr(TextBox2.Text.Trim());
order.ConsigneeAddress = WebUtility.replaceStr(TextBox3.Text.Trim());
order.ConsigneeZip = WebUtility.replaceStr(TextBox4.Text.Trim());
order.ConsigneeEmail = WebUtility.replaceStr(TextBox5.Text.Trim());
order.ConsigneePhone = WebUtility.replaceStr(TextBox6.Text.Trim());
order.ShopDate = shopDate.Date;
order.Courier = DropDownList2.SelectedItem.Value;
order.PaymentType = Convert.ToInt32(DropDownList1.SelectedValue);
order.TotalPrice = Convert.ToDecimal(string.IsNullOrEmpty(Label12.Text) != true ? Label12.Text : "0") + Convert.ToDecimal(orderModel == null ? 0 : orderModel.UnitPrice);
#region 计算实际价
decimal FactPrice = 0;
YXShop.BLL.OrderInvoice databo = new YXShop.BLL.OrderInvoice();
YXShop.BLL.InvoiceManage datai = new YXShop.BLL.InvoiceManage();
List<YXShop.Model.OrderInvoice> data = databo.GetListByColumn("OrderID", orderId);
if (data.Count > 0)
{
int InvoiceTy = Convert.ToInt32(data[0].InvoiceType);
List<YXShop.Model.InvoiceManage> dataim = datai.GetId(InvoiceTy);
if (dataim.Count > 0)
{
FactPrice = Convert.ToDecimal(orderModel == null ? 0 : orderModel.UnitPrice) * ((Convert.ToDecimal(dataim[0].IM_Tax.ToString().Replace("%", "")) + 100) / 100);
}
//比如我的产品价格1000元:开了国税发票后=1000*(5%+100%)+运费20元=1070元
}
#endregion
order.FactPrice = Convert.ToDecimal(string.IsNullOrEmpty(Label11.Text) != true ? Label11.Text : "0") + FactPrice + carriage;
#endregion
try
{
//bll.UpdateOrders(order);
if (orderModel != null)
{
orderItem.Create(orderModel);
}
bll.UpdateOrders(order);
Response.Redirect("orderModfy.aspx?OrderID=" + orderId, true);
}
catch
{
}
}
#region 获取产品重量
protected decimal wieht(int id)
{
YXShop.BLL.Product datap = new YXShop.BLL.Product();
List<YXShop.Model.Product> data = datap.GetId(id);
if (data.Count > 0)
{
if (data[0].Pro_WeightUnit.ToString() == "0")
{
return Convert.ToDecimal(data[0].Pro_Weight) / 1000;
}
else
{
return Convert.ToDecimal(data[0].Pro_Weight);
}
}
return 0;
}
#endregion
/// <summary>
/// 删除指定项
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Del_Click(object sender, EventArgs e)
{
LinkButton lBtn = (LinkButton)sender;
int productID = 0;
if (lBtn != null)
{
productID = Convert.ToInt32(lBtn.CommandArgument);
}
if (!string.IsNullOrEmpty(orderId))
{
orderItem.Del(orderId, productID);
}
Response.Redirect("orderModfy.aspx?OrderID=" + orderId, true);
}
protected void productInfo_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton button = (LinkButton)e.Item.FindControl("del");
if (button != null)
{
button.Attributes.Add("onclick", "return confirm (\"确定要删除此项记录吗?\");");
}
HiddenField hField = (HiddenField)e.Item.FindControl("Pid");
TextBox tBox = (TextBox)e.Item.FindControl("quantity");
if (tBox != null)
{
if (hField != null)
{
tBox.Attributes.Add("onblur", "change(this," + hField.Value + ")");
}
else
{
tBox.Attributes.Add("onblur", "change(this)");
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("orderInfo.aspx?OrderID=" + orderId, true);
}
[AjaxPro.AjaxMethod]
protected void UpdateProductNum(int ProductID,string OrderID, int Quantity)
{
if (string.IsNullOrEmpty(OrderID))
{
OrderID = orderId;
}
OrderID = YXShop.Common.WebUtility.replaceStr(OrderID);
YXShop.BLL.LineItem lineBll = new YXShop.BLL.LineItem();
lineBll.Update(ProductID, OrderID, Quantity);
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
HiddenField hid = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("HiddenField1");
if (hid != null)
{
int ProductID = Convert.ToInt32(hid.Value);
string OrderID = e.NewValues[0].ToString();
int Oldqun = Convert.ToInt32(e.OldValues[5]);
decimal proPrice = Convert.ToDecimal(e.NewValues[3]);
if (isSignlessInteger(e.NewValues[5]))
{
int qun = Convert.ToInt32(e.NewValues[5]);
SqlDataSource1.UpdateCommand = String.Format("Update YXShop_LineItem set Quantity={0} where OrderID='{1}' and ProductID={2}", qun, OrderID, ProductID);
YXShop.BLL.Orders orderBll = new YXShop.BLL.Orders();
List<YXShop.Model.Orders> orderList = orderBll.GetListByColumn("OrderID", orderId);
if (orderList != null && orderList.Count > 0)
{
YXShop.Model.Orders orderModel = orderList[0];
orderModel.TotalPrice += (qun - Oldqun) * proPrice;
orderModel.FactPrice += (qun - Oldqun) * proPrice;
try
{
orderBll.Amend(orderModel);
}
catch { }
}
}
else
{
YXShop.Common.alert.show("数量请填写正整数!");
}
}
}
/// <summary>
/// 是否为正整数
/// </summary>
/// <param name="numStr"></param>
/// <returns></returns>
private bool isSignlessInteger(string numStr)
{
if (string.IsNullOrEmpty(numStr))
return false;
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("^[1-9]\\d*$");
return reg.IsMatch(numStr);
}
private bool isSignlessInteger(object numObj)
{
if (numObj == null)
return false;
else
return isSignlessInteger(numObj.ToString());
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
if (!PowerTree.PowerPass.isPass("006001015", PowerTree.PowerPanel.PowerType.update))
{
bp = new BasePage();
bp.PageError("对不起,你没有修改订单商品数量的权限!", "../index.aspx");
}
GridView1.EditIndex = e.NewEditIndex;
TextBox tBox = (TextBox)GridView1.Rows[e.NewEditIndex].FindControl("TextBox1");
if (tBox != null)
{
tBox.Enabled = false;
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
if (!PowerTree.PowerPass.isPass("006001016", PowerTree.PowerPanel.PowerType.del))
{
bp = new BasePage();
bp.PageError("对不起,你没有删除单个订单商品的权限!", "../index.aspx");
}
HiddenField hid = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("HiddenField1");
Label lab = (Label)GridView1.Rows[e.RowIndex].FindControl("Label1");
if (hid != null && lab != null)
{
int ProductID = Convert.ToInt32(hid.Value);
string OrderID = lab.Text;
SqlDataSource1.DeleteCommand = String.Format("Delete YXShop_LineItem where OrderID='{0}' and ProductID={1}", OrderID, ProductID);
}
else
{
SqlDataSource1.DeleteCommand = "";
}
}
protected void GridView1_DataBound(object sender, EventArgs e)
{
Label11.Text = TotalPrice.ToString();
//Label12.Text = TotalPrice.ToString();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -