/// <summary> /// 增加一条数据 /// </summary> public int Add(BookShop.Model.Orders model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Orders("); strSql.Append("OrderId,OrderDate,UserId,TotalPrice,State)"); strSql.Append(" values ("); strSql.Append("@OrderId,@OrderDate,@UserId,@TotalPrice,@State)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@OrderDate", SqlDbType.DateTime), new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@TotalPrice", SqlDbType.Decimal, 9), new SqlParameter("@State", SqlDbType.Int, 4), new SqlParameter("@OrderId", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.OrderDate; parameters[1].Value = model.User.Id; parameters[2].Value = model.TotalPrice; parameters[3].Value = model.State; parameters[4].Value = model.OrderId; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(BookShop.Model.Orders model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Orders set "); strSql.Append("OrderDate=@OrderDate,"); strSql.Append("UserId=@UserId,"); strSql.Append("TotalPrice=@TotalPrice,"); strSql.Append("PostAddress=@PostAddress,"); strSql.Append("State=@State"); strSql.Append(" where OrderId=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.NVarChar, 50), new SqlParameter("@OrderDate", SqlDbType.DateTime), new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@TotalPrice", SqlDbType.Decimal, 9), new SqlParameter("@PostAddress", SqlDbType.NVarChar, 255), new SqlParameter("@State", SqlDbType.Int, 4) }; parameters[0].Value = model.OrderId; parameters[1].Value = model.OrderDate; parameters[2].Value = model.User.Id; parameters[3].Value = model.TotalPrice; parameters[4].Value = model.PostAddress; parameters[5].Value = model.State; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Orders DataRowToModel(DataRow row) { BookShop.Model.Orders model=new BookShop.Model.Orders(); if (row != null) { if(row["OrderId"]!=null) { model.OrderId=row["OrderId"].ToString(); } if(row["OrderDate"]!=null && row["OrderDate"].ToString()!="") { model.OrderDate=DateTime.Parse(row["OrderDate"].ToString()); } if(row["UserId"]!=null && row["UserId"].ToString()!="") { model.UserId=int.Parse(row["UserId"].ToString()); } if(row["TotalPrice"]!=null && row["TotalPrice"].ToString()!="") { model.TotalPrice=decimal.Parse(row["TotalPrice"].ToString()); } if(row["PostAddress"]!=null) { model.PostAddress=row["PostAddress"].ToString(); } if(row["state"]!=null && row["state"].ToString()!="") { model.state=int.Parse(row["state"].ToString()); } } return model; }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(BookShop.Model.Orders model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Orders("); strSql.Append("OrderId,OrderDate,UserId,TotalPrice,PostAddress,state)"); strSql.Append(" values ("); strSql.Append("@OrderId,@OrderDate,@UserId,@TotalPrice,@PostAddress,@state)"); SqlParameter[] parameters = { new SqlParameter("@OrderId", SqlDbType.NVarChar, 50), new SqlParameter("@OrderDate", SqlDbType.DateTime), new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@TotalPrice", SqlDbType.Decimal, 9), new SqlParameter("@PostAddress", SqlDbType.NVarChar, 255), new SqlParameter("@state", SqlDbType.Int, 4) }; parameters[0].Value = model.OrderId; parameters[1].Value = model.OrderDate; parameters[2].Value = model.UserId; parameters[3].Value = model.TotalPrice; parameters[4].Value = model.PostAddress; parameters[5].Value = model.state; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Orders DataRowToModel(DataRow row) { BookShop.Model.Orders model = new BookShop.Model.Orders(); if (row != null) { if (row["OrderId"] != null) { model.OrderId = row["OrderId"].ToString(); } if (row["OrderDate"] != null && row["OrderDate"].ToString() != "") { model.OrderDate = DateTime.Parse(row["OrderDate"].ToString()); } if (row["UserId"] != null && row["UserId"].ToString() != "") { model.UserId = int.Parse(row["UserId"].ToString()); } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") { model.TotalPrice = decimal.Parse(row["TotalPrice"].ToString()); } if (row["PostAddress"] != null) { model.PostAddress = row["PostAddress"].ToString(); } if (row["state"] != null && row["state"].ToString() != "") { model.state = int.Parse(row["state"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Orders GetModel(string orderId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 OrderId,OrderDate,UserId,TotalPrice,PostAddress,State from Orders "); strSql.Append(" where OrderId=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.NVarChar, 50) }; parameters[0].Value = orderId; BookShop.Model.Orders model = new BookShop.Model.Orders(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["OrderId"].ToString() != "") { model.OrderId = ds.Tables[0].Rows[0]["OrderId"].ToString(); } if (ds.Tables[0].Rows[0]["OrderDate"].ToString() != "") { model.OrderDate = DateTime.Parse(ds.Tables[0].Rows[0]["OrderDate"].ToString()); } if (ds.Tables[0].Rows[0]["UserId"].ToString() != "") { int UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString()); model.User = userServices.GetModel(UserId); } if (ds.Tables[0].Rows[0]["TotalPrice"].ToString() != "") { model.TotalPrice = decimal.Parse(ds.Tables[0].Rows[0]["TotalPrice"].ToString()); } if (ds.Tables[0].Rows[0]["PostAddress"].ToString() != "") { model.PostAddress = (ds.Tables[0].Rows[0]["PostAddress"].ToString()); } if (ds.Tables[0].Rows[0]["State"].ToString() != "") { model.State = int.Parse(ds.Tables[0].Rows[0]["State"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(BookShop.Model.Orders model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Orders set "); strSql.Append("OrderDate=@OrderDate,"); strSql.Append("UserId=@UserId,"); strSql.Append("TotalPrice=@TotalPrice,"); strSql.Append("PostAddress=@PostAddress,"); strSql.Append("state=@state"); strSql.Append(" where OrderId=@OrderId "); SqlParameter[] parameters = { new SqlParameter("@OrderDate", SqlDbType.DateTime), new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@TotalPrice", SqlDbType.Decimal, 9), new SqlParameter("@PostAddress", SqlDbType.NVarChar, 255), new SqlParameter("@state", SqlDbType.Int, 4), new SqlParameter("@OrderId", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.OrderDate; parameters[1].Value = model.UserId; parameters[2].Value = model.TotalPrice; parameters[3].Value = model.PostAddress; parameters[4].Value = model.state; parameters[5].Value = model.OrderId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Orders GetModel(string OrderId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 OrderId,OrderDate,UserId,TotalPrice,PostAddress,state from Orders "); strSql.Append(" where OrderId=@OrderId "); SqlParameter[] parameters = { new SqlParameter("@OrderId", SqlDbType.NVarChar, 50) }; parameters[0].Value = OrderId; BookShop.Model.Orders model = new BookShop.Model.Orders(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Orders GetModel(string OrderId) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 OrderId,OrderDate,UserId,TotalPrice,PostAddress,state from Orders "); strSql.Append(" where OrderId=@OrderId "); SqlParameter[] parameters = { new SqlParameter("@OrderId", SqlDbType.NVarChar,50) }; parameters[0].Value = OrderId; BookShop.Model.Orders model=new BookShop.Model.Orders(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }