/// <summary> /// 由一行数据得到一个实体 /// </summary> private Hi.Model.YZT_Logistics GetModel(DataRow r) { Hi.Model.YZT_Logistics model = new Hi.Model.YZT_Logistics(); model.Id = SqlHelper.GetInt(r["Id"]); model.LibraryID = SqlHelper.GetInt(r["LibraryID"]); model.ComPName = SqlHelper.GetString(r["ComPName"]); model.LogisticsNo = SqlHelper.GetString(r["LogisticsNo"]); model.CarUser = SqlHelper.GetString(r["CarUser"]); model.CarNo = SqlHelper.GetString(r["CarNo"]); model.Car = SqlHelper.GetString(r["Car"]); model.Context = SqlHelper.GetString(r["Context"]); model.Type = SqlHelper.GetInt(r["Type"]); model.CreateUserID = SqlHelper.GetInt(r["CreateUserID"]); model.CreateDate = SqlHelper.GetDateTime(r["CreateDate"]); model.ts = SqlHelper.GetDateTime(r["ts"]); model.dr = SqlHelper.GetInt(r["dr"]); model.modifyuser = SqlHelper.GetInt(r["modifyuser"]); return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Hi.Model.YZT_Logistics model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [YZT_Logistics]("); strSql.Append("[LibraryID],[ComPName],[LogisticsNo],[CarUser],[CarNo],[Car],[Context],[Type],[CreateUserID],[ts],[modifyuser])"); strSql.Append(" values ("); strSql.Append("@LibraryID,@ComPName,@LogisticsNo,@CarUser,@CarNo,@Car,@Context,@Type,@CreateUserID,@ts,@modifyuser)"); strSql.Append(";select @@Identity"); SqlParameter[] parameters = { new SqlParameter("@LibraryID", SqlDbType.Int), new SqlParameter("@ComPName", SqlDbType.VarChar, 50), new SqlParameter("@LogisticsNo", SqlDbType.VarChar, 50), new SqlParameter("@CarUser", SqlDbType.VarChar, 50), new SqlParameter("@CarNo", SqlDbType.VarChar, 50), new SqlParameter("@Car", SqlDbType.VarChar, 50), new SqlParameter("@Context", SqlDbType.Text), new SqlParameter("@Type", SqlDbType.Int), new SqlParameter("@CreateUserID", SqlDbType.Int), new SqlParameter("@ts", SqlDbType.DateTime), new SqlParameter("@modifyuser", SqlDbType.Int) }; parameters[0].Value = model.LibraryID; if (model.ComPName != null) { parameters[1].Value = model.ComPName; } else { parameters[1].Value = DBNull.Value; } if (model.LogisticsNo != null) { parameters[2].Value = model.LogisticsNo; } else { parameters[2].Value = DBNull.Value; } if (model.CarUser != null) { parameters[3].Value = model.CarUser; } else { parameters[3].Value = DBNull.Value; } if (model.CarNo != null) { parameters[4].Value = model.CarNo; } else { parameters[4].Value = DBNull.Value; } if (model.Car != null) { parameters[5].Value = model.Car; } else { parameters[5].Value = DBNull.Value; } if (model.Context != null) { parameters[6].Value = model.Context; } else { parameters[6].Value = DBNull.Value; } parameters[7].Value = model.Type; parameters[8].Value = model.CreateUserID; if (model.ts != DateTime.MinValue) { parameters[9].Value = model.ts; } else { parameters[9].Value = DBNull.Value; } parameters[10].Value = model.modifyuser; return(SqlHelper.GetInt(SqlHelper.GetSingle(SqlHelper.LocalSqlServer, strSql.ToString(), parameters))); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Hi.Model.YZT_Logistics model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update [YZT_Logistics] set "); strSql.Append("[LibraryID]=@LibraryID,"); strSql.Append("[ComPName]=@ComPName,"); strSql.Append("[LogisticsNo]=@LogisticsNo,"); strSql.Append("[CarUser]=@CarUser,"); strSql.Append("[CarNo]=@CarNo,"); strSql.Append("[Car]=@Car,"); strSql.Append("[Context]=@Context,"); strSql.Append("[Type]=@Type,"); strSql.Append("[CreateUserID]=@CreateUserID,"); strSql.Append("[CreateDate]=@CreateDate,"); strSql.Append("[ts]=@ts,"); strSql.Append("[dr]=@dr,"); strSql.Append("[modifyuser]=@modifyuser"); strSql.Append(" where [Id]=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int), new SqlParameter("@LibraryID", SqlDbType.Int), new SqlParameter("@ComPName", SqlDbType.VarChar, 50), new SqlParameter("@LogisticsNo", SqlDbType.VarChar, 50), new SqlParameter("@CarUser", SqlDbType.VarChar, 50), new SqlParameter("@CarNo", SqlDbType.VarChar, 50), new SqlParameter("@Car", SqlDbType.VarChar, 50), new SqlParameter("@Context", SqlDbType.Text), new SqlParameter("@Type", SqlDbType.Int), new SqlParameter("@CreateUserID", SqlDbType.Int), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@ts", SqlDbType.DateTime), new SqlParameter("@dr", SqlDbType.Int), new SqlParameter("@modifyuser", SqlDbType.Int) }; parameters[0].Value = model.Id; parameters[1].Value = model.LibraryID; if (model.ComPName != null) { parameters[2].Value = model.ComPName; } else { parameters[2].Value = DBNull.Value; } if (model.LogisticsNo != null) { parameters[3].Value = model.LogisticsNo; } else { parameters[3].Value = DBNull.Value; } if (model.CarUser != null) { parameters[4].Value = model.CarUser; } else { parameters[4].Value = DBNull.Value; } if (model.CarNo != null) { parameters[5].Value = model.CarNo; } else { parameters[5].Value = DBNull.Value; } if (model.Car != null) { parameters[6].Value = model.Car; } else { parameters[6].Value = DBNull.Value; } if (model.Context != null) { parameters[7].Value = model.Context; } else { parameters[7].Value = DBNull.Value; } parameters[8].Value = model.Type; parameters[9].Value = model.CreateUserID; parameters[10].Value = model.CreateDate; if (model.ts != DateTime.MinValue) { parameters[11].Value = model.ts; } else { parameters[11].Value = DBNull.Value; } parameters[12].Value = model.dr; parameters[13].Value = model.modifyuser; return(SqlHelper.ExecuteSql(SqlHelper.LocalSqlServer, strSql.ToString(), parameters) > 0); }