/// <summary> /// 更新一条数据 /// </summary> public bool Update(ClassLibrary1.Model.Department model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Department set "); strSql.Append("CreateTime=@CreateTime,"); strSql.Append("DepartmentName=@DepartmentName,"); strSql.Append("ResPeople=@ResPeople,"); strSql.Append("Phone=@Phone,"); strSql.Append("IsDeleted=@IsDeleted,"); strSql.Append("AddTime=@AddTime,"); strSql.Append("AddPeople=@AddPeople"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@CreateTime", SqlDbType.DateTime2, 8), new SqlParameter("@DepartmentName", SqlDbType.VarChar, 255), new SqlParameter("@ResPeople", SqlDbType.VarChar, 255), new SqlParameter("@Phone", SqlDbType.VarChar, 255), new SqlParameter("@IsDeleted", SqlDbType.Int, 4), new SqlParameter("@AddTime", SqlDbType.VarChar, 255), new SqlParameter("@AddPeople", SqlDbType.VarChar, 255), new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@DepartmentUuid", SqlDbType.UniqueIdentifier, 16) }; parameters[0].Value = model.CreateTime; parameters[1].Value = model.DepartmentName; parameters[2].Value = model.ResPeople; parameters[3].Value = model.Phone; parameters[4].Value = model.IsDeleted; parameters[5].Value = model.AddTime; parameters[6].Value = model.AddPeople; parameters[7].Value = model.ID; parameters[8].Value = model.DepartmentUuid; int rows = DbHelperSql.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ClassLibrary1.Model.Department DataRowToModel(DataRow row) { ClassLibrary1.Model.Department model = new ClassLibrary1.Model.Department(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["CreateTime"] != null && row["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(row["CreateTime"].ToString()); } if (row["DepartmentUuid"] != null && row["DepartmentUuid"].ToString() != "") { model.DepartmentUuid = new Guid(row["DepartmentUuid"].ToString()); } if (row["DepartmentName"] != null) { model.DepartmentName = row["DepartmentName"].ToString(); } if (row["ResPeople"] != null) { model.ResPeople = row["ResPeople"].ToString(); } if (row["Phone"] != null) { model.Phone = row["Phone"].ToString(); } if (row["IsDeleted"] != null && row["IsDeleted"].ToString() != "") { model.IsDeleted = int.Parse(row["IsDeleted"].ToString()); } if (row["AddTime"] != null) { model.AddTime = row["AddTime"].ToString(); } if (row["AddPeople"] != null) { model.AddPeople = row["AddPeople"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(ClassLibrary1.Model.Department model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Department("); strSql.Append("CreateTime,DepartmentUuid,DepartmentName,ResPeople,Phone,IsDeleted,AddTime,AddPeople)"); strSql.Append(" values ("); strSql.Append("@CreateTime,@DepartmentUuid,@DepartmentName,@ResPeople,@Phone,@IsDeleted,@AddTime,@AddPeople)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CreateTime", SqlDbType.DateTime2, 8), new SqlParameter("@DepartmentUuid", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@DepartmentName", SqlDbType.VarChar, 255), new SqlParameter("@ResPeople", SqlDbType.VarChar, 255), new SqlParameter("@Phone", SqlDbType.VarChar, 255), new SqlParameter("@IsDeleted", SqlDbType.Int, 4), new SqlParameter("@AddTime", SqlDbType.VarChar, 255), new SqlParameter("@AddPeople", SqlDbType.VarChar, 255) }; parameters[0].Value = model.CreateTime; parameters[1].Value = model.DepartmentUuid; parameters[2].Value = model.DepartmentName; parameters[3].Value = model.ResPeople; parameters[4].Value = model.Phone; parameters[5].Value = model.IsDeleted; parameters[6].Value = model.AddTime; parameters[7].Value = model.AddPeople; object obj = DbHelperSql.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ClassLibrary1.Model.Department GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,CreateTime,DepartmentUuid,DepartmentName,ResPeople,Phone,IsDeleted,AddTime,AddPeople from Department "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; ClassLibrary1.Model.Department model = new ClassLibrary1.Model.Department(); DataSet ds = DbHelperSql.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }