/// <summary> /// 得到一个对象实体 /// </summary> public Hownet.Model.Users GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,Name,Password,TrueName,Phone,Email,EmployeeID,DepartmentID,State,JobsID from Users "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Hownet.Model.Users model = new Hownet.Model.Users(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } model.Name = ds.Tables[0].Rows[0]["Name"].ToString(); if (ds.Tables[0].Rows[0]["Password"].ToString() != "") { model.Password = (byte[])ds.Tables[0].Rows[0]["Password"]; } model.TrueName = ds.Tables[0].Rows[0]["TrueName"].ToString(); model.Phone = ds.Tables[0].Rows[0]["Phone"].ToString(); model.Email = ds.Tables[0].Rows[0]["Email"].ToString(); if (ds.Tables[0].Rows[0]["EmployeeID"].ToString() != "") { model.EmployeeID = int.Parse(ds.Tables[0].Rows[0]["EmployeeID"].ToString()); } if (ds.Tables[0].Rows[0]["DepartmentID"].ToString() != "") { model.DepartmentID = int.Parse(ds.Tables[0].Rows[0]["DepartmentID"].ToString()); } if (ds.Tables[0].Rows[0]["State"].ToString() != "") { model.State = int.Parse(ds.Tables[0].Rows[0]["State"].ToString()); } if (ds.Tables[0].Rows[0]["JobsID"].ToString() != "") { model.JobsID = int.Parse(ds.Tables[0].Rows[0]["JobsID"].ToString()); } model.A = 1; return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Hownet.Model.Users model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Users set "); strSql.Append("Name=@Name,"); strSql.Append("Password=@Password,"); strSql.Append("TrueName=@TrueName,"); strSql.Append("Phone=@Phone,"); strSql.Append("Email=@Email,"); strSql.Append("EmployeeID=@EmployeeID,"); strSql.Append("DepartmentID=@DepartmentID,"); strSql.Append("State=@State,"); strSql.Append("JobsID=@JobsID"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@Password", SqlDbType.Binary, 20), new SqlParameter("@TrueName", SqlDbType.NVarChar, 50), new SqlParameter("@Phone", SqlDbType.NVarChar, 50), new SqlParameter("@Email", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeeID", SqlDbType.Int, 4), new SqlParameter("@DepartmentID", SqlDbType.Int, 4), new SqlParameter("@State", SqlDbType.Int, 4), new SqlParameter("@JobsID", SqlDbType.Int, 4), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.Name; parameters[1].Value = model.Password; parameters[2].Value = model.TrueName; parameters[3].Value = model.Phone; parameters[4].Value = model.Email; parameters[5].Value = model.EmployeeID; parameters[6].Value = model.DepartmentID; parameters[7].Value = model.State; parameters[8].Value = model.JobsID; parameters[9].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Hownet.Model.Users model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Users("); strSql.Append("Name,Password,TrueName,Phone,Email,EmployeeID,DepartmentID,State,JobsID)"); strSql.Append(" values ("); strSql.Append("@Name,@Password,@TrueName,@Phone,@Email,@EmployeeID,@DepartmentID,@State,@JobsID)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@Password", SqlDbType.Binary, 20), new SqlParameter("@TrueName", SqlDbType.NVarChar, 50), new SqlParameter("@Phone", SqlDbType.NVarChar, 50), new SqlParameter("@Email", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeeID", SqlDbType.Int, 4), new SqlParameter("@DepartmentID", SqlDbType.Int, 4), new SqlParameter("@State", SqlDbType.Int, 4), new SqlParameter("@JobsID", SqlDbType.Int, 4) }; parameters[0].Value = model.Name; parameters[1].Value = model.Password; parameters[2].Value = model.TrueName; parameters[3].Value = model.Phone; parameters[4].Value = model.Email; parameters[5].Value = model.EmployeeID; parameters[6].Value = model.DepartmentID; parameters[7].Value = model.State; parameters[8].Value = model.JobsID; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }