/// <summary> /// 更新一条数据 /// </summary> public bool Update(MultiColorPen.Model.order_detail model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update order_detail set "); strSql.Append("commodity_id=?commodity_id,"); strSql.Append("commodity_name=?commodity_name,"); strSql.Append("commodity_price=?commodity_price,"); strSql.Append("commodity_unit=?commodity_unit,"); strSql.Append("commodity_count=?commodity_count,"); strSql.Append("order_number=?order_number,"); strSql.Append("is_del=?is_del,"); strSql.Append("mark=?mark"); strSql.Append(" where id=?id"); MySqlParameter[] parameters = { new MySqlParameter("?commodity_id", MySqlDbType.Int32, 11), new MySqlParameter("?commodity_name", MySqlDbType.VarChar, 50), new MySqlParameter("?commodity_price", MySqlDbType.Decimal, 10), new MySqlParameter("?commodity_unit", MySqlDbType.VarChar, 255), new MySqlParameter("?commodity_count", MySqlDbType.Int32, 10), new MySqlParameter("?order_number", MySqlDbType.VarChar, 30), new MySqlParameter("?is_del", MySqlDbType.VarChar, 2), new MySqlParameter("?mark", MySqlDbType.VarChar, 150), new MySqlParameter("?id", MySqlDbType.Int32, 11) }; parameters[0].Value = model.commodity_id; parameters[1].Value = model.commodity_name; parameters[2].Value = model.commodity_price; parameters[3].Value = model.commodity_unit; parameters[4].Value = model.commodity_count; parameters[5].Value = model.order_number; parameters[6].Value = model.is_del; parameters[7].Value = model.mark; parameters[8].Value = model.id; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public MultiColorPen.Model.order_detail DataRowToModel(DataRow row) { MultiColorPen.Model.order_detail model = new MultiColorPen.Model.order_detail(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["commodity_id"] != null && row["commodity_id"].ToString() != "") { model.commodity_id = int.Parse(row["commodity_id"].ToString()); } if (row["commodity_name"] != null) { model.commodity_name = row["commodity_name"].ToString(); } if (row["commodity_price"] != null && row["commodity_price"].ToString() != "") { model.commodity_price = decimal.Parse(row["commodity_price"].ToString()); } if (row["commodity_unit"] != null) { model.commodity_unit = row["commodity_unit"].ToString(); } if (row["commodity_count"] != null && row["commodity_count"].ToString() != "") { model.commodity_count = int.Parse(row["commodity_count"].ToString()); } if (row["order_number"] != null) { model.order_number = row["order_number"].ToString(); } if (row["is_del"] != null) { model.is_del = row["is_del"].ToString(); } if (row["mark"] != null) { model.mark = row["mark"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(MultiColorPen.Model.order_detail model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into order_detail("); strSql.Append("commodity_id,commodity_name,commodity_price,commodity_unit,commodity_count,order_number,is_del,mark)"); strSql.Append(" values ("); strSql.Append("?commodity_id,?commodity_name,?commodity_price,?commodity_unit,?commodity_count,?order_number,?is_del,?mark)"); MySqlParameter[] parameters = { new MySqlParameter("?commodity_id", MySqlDbType.Int32, 11), new MySqlParameter("?commodity_name", MySqlDbType.VarChar, 50), new MySqlParameter("?commodity_price", MySqlDbType.Decimal, 10), new MySqlParameter("?commodity_unit", MySqlDbType.VarChar, 255), new MySqlParameter("?commodity_count", MySqlDbType.Int32, 10), new MySqlParameter("?order_number", MySqlDbType.VarChar, 30), new MySqlParameter("?is_del", MySqlDbType.VarChar, 2), new MySqlParameter("?mark", MySqlDbType.VarChar, 150) }; parameters[0].Value = model.commodity_id; parameters[1].Value = model.commodity_name; parameters[2].Value = model.commodity_price; parameters[3].Value = model.commodity_unit; parameters[4].Value = model.commodity_count; parameters[5].Value = model.order_number; parameters[6].Value = model.is_del; parameters[7].Value = model.mark; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public MultiColorPen.Model.order_detail GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id,commodity_id,commodity_name,commodity_price,commodity_unit,commodity_count,order_number,is_del,mark from order_detail "); strSql.Append(" where id=?id"); MySqlParameter[] parameters = { new MySqlParameter("?id", MySqlDbType.Int32) }; parameters[0].Value = id; MultiColorPen.Model.order_detail model = new MultiColorPen.Model.order_detail(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public string SaveOrder(string json, string orderInfo) { //json = json.Replace("[","").Replace("]",""); orderInfo = orderInfo.Replace("[", "").Replace("]", ""); var bllOrder = new MultiColorPen.BLL.order_info(); var bllDetail = new MultiColorPen.BLL.order_detail(); var bllCommo = new MultiColorPen.BLL.commodity(); var bllCustomer = new MultiColorPen.BLL.customer(); bool isSuccess = true; string orderNumber = "";//订单编号 JArray jArray = JArray.Parse(json); var oldOrderInfo = new MultiColorPen.Model.order_info(); ResultInfo result = new ResultInfo(false); JObject jo = JObject.Parse(orderInfo); //解析order信息 if (jo["orderId"].ToString() == "-1") //新增订单 { orderNumber = "ORDER" + DateTime.Now.ToString("yyyyMMddHHmmss"); } else { oldOrderInfo = bllOrder.GetModel((int)jo["orderId"]); //获取旧的订单信息 orderNumber = oldOrderInfo.number; //编辑时使用旧的订单编号 oldOrderInfo.is_del = "1"; if (!bllOrder.Update(oldOrderInfo)) //删除旧的订单信息 { isSuccess = false; } if (!bllDetail.DeleteByWhere(" order_number='" + orderNumber + "'")) //删除详细商品的对应数据 { isSuccess = false; } } foreach (var jj in jArray) { JObject jdata = (JObject)jj; var commodityModel = bllCommo.GetModel((int)jdata["name"]); var orderDetailModel = new MultiColorPen.Model.order_detail(); orderDetailModel.commodity_count = (int)jdata["count"]; orderDetailModel.commodity_id = (int)jdata["name"]; orderDetailModel.commodity_price = commodityModel.price; orderDetailModel.commodity_unit = commodityModel.unit; orderDetailModel.order_number = orderNumber; orderDetailModel.commodity_name = commodityModel.name; orderDetailModel.mark = jdata["mark"].ToString(); orderDetailModel.is_del = "0"; if (!bllDetail.Add(orderDetailModel)) //插入商品详情 { isSuccess = false; } } var customerModel = bllCustomer.GetModel((int)jo["customerId"]); var orderModel = new MultiColorPen.Model.order_info(); orderModel.create_time = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"); orderModel.customer_id = (int)jo["customerId"]; orderModel.customer_address = customerModel.address; orderModel.customer_name = customerModel.name; orderModel.customer_person = customerModel.person; orderModel.customer_tel = customerModel.tel; orderModel.delivery_time = jo["deliverTime"].ToString(); orderModel.is_del = "0"; orderModel.status = "已下单"; orderModel.number = orderNumber; orderModel.mark = jo["orderMark"].ToString(); if (!bllOrder.Add(orderModel)) //插入订单信息 { isSuccess = false; } if (isSuccess) { result.IsSucceed = true; result.Message = "操作成功!"; } else { result.IsSucceed = false; result.Message = "修改失败!"; } return(JsonConvert.SerializeObject(result)); }