/// <summary> /// 增加一条数据 /// </summary> public bool Add(OrderItem model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into order_item("); strSql.Append("order_id,material_id,count,state,type,total_price,style_id,style_name,craft,add_time,delivery_time,remark,delivery_remark)"); strSql.Append(" values ("); strSql.Append("?order_id,?material_id,?count,?state,?type,?total_price,?style_id,?style_name,?craft,?add_time,?delivery_time,?remark,?delivery_remark)"); MySqlParameter[] parameters = { new MySqlParameter("?order_id", MySqlDbType.Int32,10), new MySqlParameter("?material_id", MySqlDbType.Int32,10), new MySqlParameter("?count", MySqlDbType.Int32,10), new MySqlParameter("?state", MySqlDbType.Enum), new MySqlParameter("?type", MySqlDbType.Enum), new MySqlParameter("?total_price", MySqlDbType.Decimal,12), new MySqlParameter("?style_id", MySqlDbType.Int32,11), new MySqlParameter("?style_name", MySqlDbType.VarChar,50), new MySqlParameter("?craft", MySqlDbType.Int32,10), new MySqlParameter("?add_time", MySqlDbType.DateTime), new MySqlParameter("?delivery_time", MySqlDbType.DateTime), new MySqlParameter("?remark", MySqlDbType.Text), new MySqlParameter("?delivery_remark", MySqlDbType.Text)}; parameters[0].Value = model.OrderID; parameters[1].Value = model.MaterialID; parameters[2].Value = model.Count; parameters[3].Value = model.State; parameters[4].Value = model.Type; parameters[5].Value = model.Total; parameters[6].Value = model.StyleID; parameters[7].Value = model.StyleName; parameters[8].Value = model.CraftID; parameters[9].Value = model.AddTime; parameters[10].Value = model.DeliveryTime; parameters[11].Value = model.Remark; parameters[12].Value = model.DeliveryRemark; int rows = MysqlHelper.ExecuteNonQuery(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
public OrderItem ToOrderItem(int orderid) { OrderItem orderItem = new OrderItem(); orderItem.OrderID = orderid; orderItem.AddTime = DateTime.Now; orderItem.Count = Count; orderItem.CraftID = Craft; orderItem.MaterialID = MaterialID; //orderItem.Remark = Remark; orderItem.State = OrderItemState.MakingUp; orderItem.StyleID = Style; orderItem.Type = Type; orderItem.StyleName = StyleName; orderItem.Total = Total; return orderItem; }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(OrderItem model) { return dal.Add(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(OrderItem model) { return dal.Update(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public OrderItem DataRowToModel(DataRow row) { OrderItem model = new OrderItem(); if (row != null) { foreach (DataColumn col in row.Table.Columns) { if (row[col] != null && row[col].ToString() != "") { switch (col.ColumnName) { case "id": model.ItemID = int.Parse(row[col].ToString()); break; case "order_id": model.OrderID = int.Parse(row[col].ToString()); break; case "material_id": model.MaterialID = int.Parse(row[col].ToString()); break; case "material_name": model.MaterialName = row[col].ToString(); break; case "count": model.Count = int.Parse(row[col].ToString()); break; case "state": model.State = row[col].ToString(); break; case "type": model.Type = row[col].ToString(); break; case "total_price": model.Total = decimal.Parse(row[col].ToString()); break; case "style_id": model.StyleID = int.Parse(row[col].ToString()); break; case "style_name": model.StyleName = row[col].ToString(); break; case "craft": model.CraftID = int.Parse(row[col].ToString()); break; case "add_time": model.AddTime = DateTime.Parse(row[col].ToString()); break; case "delivery_time": model.DeliveryTime = DateTime.Parse(row[col].ToString()); break; case "remark": model.Remark =row[col].ToString(); break; case "delivery_remark": model.DeliveryRemark = row[col].ToString(); break; } } } } return model; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(OrderItem model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update order_item set "); strSql.Append("order_id=?order_id,"); strSql.Append("material_id=?material_id,"); strSql.Append("count=?count,"); strSql.Append("state=?state,"); strSql.Append("type=?type,"); strSql.Append("total_price=?total_price,"); strSql.Append("style_id=?style_id,"); strSql.Append("style_name=?style_name,"); strSql.Append("craft=?craft,"); strSql.Append("add_time=?add_time,"); strSql.Append("delivery_time=?delivery_time,"); strSql.Append("remark=?remark,"); strSql.Append("delivery_remark=?delivery_remark"); strSql.Append(" where id=?id"); MySqlParameter[] parameters = { new MySqlParameter("?order_id", MySqlDbType.Int32,10), new MySqlParameter("?material_id", MySqlDbType.Int32,10), new MySqlParameter("?count", MySqlDbType.Int32,10), new MySqlParameter("?state", MySqlDbType.Enum), new MySqlParameter("?type", MySqlDbType.Enum), new MySqlParameter("?total_price", MySqlDbType.Decimal,12), new MySqlParameter("?style_id", MySqlDbType.Int32,11), new MySqlParameter("?style_name", MySqlDbType.VarChar,50), new MySqlParameter("?craft", MySqlDbType.Int32,10), new MySqlParameter("?add_time", MySqlDbType.DateTime), new MySqlParameter("?delivery_time", MySqlDbType.DateTime), new MySqlParameter("?remark", MySqlDbType.Text), new MySqlParameter("?delivery_remark", MySqlDbType.Text), new MySqlParameter("?id", MySqlDbType.Int32,10)}; parameters[0].Value = model.OrderID; parameters[1].Value = model.MaterialID; parameters[2].Value = model.Count; parameters[3].Value = model.State; parameters[4].Value = model.Type; parameters[5].Value = model.Total; parameters[6].Value = model.StyleID; parameters[7].Value = model.StyleName; parameters[8].Value = model.CraftID; parameters[9].Value = model.AddTime; parameters[10].Value = model.DeliveryTime; parameters[11].Value = model.Remark; parameters[12].Value = model.DeliveryRemark; parameters[13].Value = model.ItemID; int rows = MysqlHelper.ExecuteNonQuery(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public OrderItem GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id,order_id,material_id,count,state,type,total_price,style_id,style_name,craft,add_time,delivery_time,remark,delivery_remark from order_item "); strSql.Append(" where id=?id"); MySqlParameter[] parameters = { new MySqlParameter("?id", MySqlDbType.Int32) }; parameters[0].Value = id; OrderItem model = new OrderItem(); DataSet ds = MysqlHelper.ExecuteDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }