/// <summary> /// 更新一条数据 /// </summary> public bool Update(SchSystem.Model.SchUserDept model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update SchUserDept set "); strSql.Append("DeptId=@DeptId,"); strSql.Append("UserName=@UserName,"); strSql.Append("RecTime=@RecTime,"); strSql.Append("RecUser=@RecUser,"); strSql.Append("LastRecTime=@LastRecTime,"); strSql.Append("LastRecUser=@LastRecUser"); strSql.Append(" where AutoId=@AutoId"); SqlParameter[] parameters = { new SqlParameter("@DeptId", SqlDbType.Int, 4), new SqlParameter("@UserName", SqlDbType.VarChar, 20), new SqlParameter("@RecTime", SqlDbType.SmallDateTime), new SqlParameter("@RecUser", SqlDbType.VarChar, 50), new SqlParameter("@LastRecTime", SqlDbType.DateTime), new SqlParameter("@LastRecUser", SqlDbType.VarChar, 20), new SqlParameter("@AutoId", SqlDbType.Int, 4) }; parameters[0].Value = model.DeptId; parameters[1].Value = model.UserName; parameters[2].Value = model.RecTime; parameters[3].Value = model.RecUser; parameters[4].Value = model.LastRecTime; parameters[5].Value = model.LastRecUser; parameters[6].Value = model.AutoId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SchSystem.Model.SchUserDept DataRowToModel(DataRow row) { SchSystem.Model.SchUserDept model = new SchSystem.Model.SchUserDept(); if (row != null) { if (row["AutoId"] != null && row["AutoId"].ToString() != "") { model.AutoId = int.Parse(row["AutoId"].ToString()); } if (row["DeptId"] != null && row["DeptId"].ToString() != "") { model.DeptId = int.Parse(row["DeptId"].ToString()); } if (row["UserName"] != null) { model.UserName = row["UserName"].ToString(); } if (row["RecTime"] != null && row["RecTime"].ToString() != "") { model.RecTime = DateTime.Parse(row["RecTime"].ToString()); } if (row["RecUser"] != null) { model.RecUser = row["RecUser"].ToString(); } if (row["LastRecTime"] != null && row["LastRecTime"].ToString() != "") { model.LastRecTime = DateTime.Parse(row["LastRecTime"].ToString()); } if (row["LastRecUser"] != null) { model.LastRecUser = row["LastRecUser"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SchSystem.Model.SchUserDept model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into SchUserDept("); strSql.Append("DeptId,UserName,RecTime,RecUser,LastRecTime,LastRecUser)"); strSql.Append(" values ("); strSql.Append("@DeptId,@UserName,@RecTime,@RecUser,@LastRecTime,@LastRecUser)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@DeptId", SqlDbType.Int, 4), new SqlParameter("@UserName", SqlDbType.VarChar, 20), new SqlParameter("@RecTime", SqlDbType.SmallDateTime), new SqlParameter("@RecUser", SqlDbType.VarChar, 50), new SqlParameter("@LastRecTime", SqlDbType.DateTime), new SqlParameter("@LastRecUser", SqlDbType.VarChar, 20) }; parameters[0].Value = model.DeptId; parameters[1].Value = model.UserName; parameters[2].Value = model.RecTime; parameters[3].Value = model.RecUser; parameters[4].Value = model.LastRecTime; parameters[5].Value = model.LastRecUser; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SchSystem.Model.SchUserDept GetModel(int AutoId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 AutoId,DeptId,UserName,RecTime,RecUser,LastRecTime,LastRecUser from SchUserDept "); strSql.Append(" where AutoId=@AutoId"); SqlParameter[] parameters = { new SqlParameter("@AutoId", SqlDbType.Int, 4) }; parameters[0].Value = AutoId; SchSystem.Model.SchUserDept model = new SchSystem.Model.SchUserDept(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }