/// <summary> /// 根据部门Id查询部门信息 /// </summary> /// <param name="departId"></param> /// <returns></returns> public static Depart GetDepartGetById(int departId) { string sql = "select * from DepartInfo where DepartId=" + departId; using (SqlDataReader reader = DBHelper.GetReader(sql)) { if (reader.Read()) { Depart depart = new Depart(); depart.DepartId = (int)reader["DepartId"]; depart.DepartName = (string)reader["DepartName"]; string PrincipalUser = (string)reader["PrincipalUser"]; depart.ConnectTelNo = (long)reader["ConnectTelNo"]; depart.ConnectMobileTelNo = (long)reader["ConnectMobileTelNo"]; depart.Faxes = (long)reader["Faxes"]; int branchId = (int)reader["BranchId"]; reader.Close(); depart.Branch = BranchService.GetBranchById(branchId); depart.PrincipalUser = UserService.GetUserById(PrincipalUser); return(depart); } else { reader.Close(); return(null); } } }
private static IList <Depart> GetAllDepartBySql(string sql) { IList <Depart> list = new List <Depart>(); using (DataTable dt = DBHelper.GetDataSet(sql)) { foreach (DataRow row in dt.Rows) { Depart depart = new Depart(); depart.DepartId = (int)row["DepartId"]; depart.DepartName = (string)row["DepartName"]; depart.ConnectTelNo = (long)row["ConnectTelNo"]; depart.ConnectMobileTelNo = (long)row["ConnectMobileTelNo"]; depart.Faxes = (long)row["Faxes"]; depart.PrincipalUser = UserService.GetUserById(row["PrincipalUser"].ToString()); depart.Branch = BranchService.GetBranchById(Convert.ToInt32(row["BranchId"])); list.Add(depart); } return(list); } }