/// <summary> /// 增加一条数据 /// </summary> public int Add(Entity.DepartmentEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [OA_Department]("); strSql.Append("DName)"); strSql.Append(" values ("); strSql.Append("@DName)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@DName", SqlDbType.VarChar, 20) }; parameters[0].Value = model.DName; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Entity.DepartmentEntity GetEntity(int Did) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Did,DName from [OA_Department] "); strSql.Append(" where Did=@Did "); SqlParameter[] parameters = { new SqlParameter("@Did", SqlDbType.Int, 4) }; parameters[0].Value = Did; Entity.DepartmentEntity model = new Entity.DepartmentEntity(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Did"].ToString() != "") { model.Did = int.Parse(ds.Tables[0].Rows[0]["Did"].ToString()); } model.DName = ds.Tables[0].Rows[0]["DName"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Entity.DepartmentEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update [OA_Department] set "); strSql.Append("DName=@DName"); strSql.Append(" where Did=@Did "); SqlParameter[] parameters = { new SqlParameter("@Did", SqlDbType.Int, 4), new SqlParameter("@DName", SqlDbType.VarChar, 20) }; parameters[0].Value = model.Did; parameters[1].Value = model.DName; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// ��������б� /// </summary> public List<Entity.DepartmentEntity> DataTableToList(DataTable dt) { List<Entity.DepartmentEntity> modelList = new List<Entity.DepartmentEntity>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Entity.DepartmentEntity model; for (int n = 0; n < rowsCount; n++) { model = new Entity.DepartmentEntity(); if (dt.Rows[n]["Did"].ToString() != "") { model.Did = int.Parse(dt.Rows[n]["Did"].ToString()); } model.DName = dt.Rows[n]["DName"].ToString(); modelList.Add(model); } } return modelList; }
/// <summary> /// 获得数据列表 /// </summary> public List <Entity.DepartmentEntity> DataTableToList(DataTable dt) { List <Entity.DepartmentEntity> modelList = new List <Entity.DepartmentEntity>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Entity.DepartmentEntity model; for (int n = 0; n < rowsCount; n++) { model = new Entity.DepartmentEntity(); if (dt.Rows[n]["Did"].ToString() != "") { model.Did = int.Parse(dt.Rows[n]["Did"].ToString()); } model.DName = dt.Rows[n]["DName"].ToString(); modelList.Add(model); } } return(modelList); }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public Entity.DepartmentEntity GetEntity(int Did) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Did,DName from [OA_Department] "); strSql.Append(" where Did=@Did "); SqlParameter[] parameters = { new SqlParameter("@Did", SqlDbType.Int,4)}; parameters[0].Value = Did; Entity.DepartmentEntity model = new Entity.DepartmentEntity(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Did"].ToString() != "") { model.Did = int.Parse(ds.Tables[0].Rows[0]["Did"].ToString()); } model.DName = ds.Tables[0].Rows[0]["DName"].ToString(); return model; } else { return null; } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Entity.DepartmentEntity model) { dal.Update(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Entity.DepartmentEntity model) { return(dal.Add(model)); }