/// <summary> /// 获得数据列表 /// </summary> public List<ObjectGroup> DataTableToList(DataTable dt) { List<ObjectGroup> modelList = new List<ObjectGroup>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { ObjectGroup model; for (int n = 0; n < rowsCount; n++) { model = new ObjectGroup(); if(dt.Rows[n]["ID"]!=null && dt.Rows[n]["ID"].ToString()!="") { model.ID=int.Parse(dt.Rows[n]["ID"].ToString()); } if(dt.Rows[n]["Code"]!=null && dt.Rows[n]["Code"].ToString()!="") { model.Code=dt.Rows[n]["Code"].ToString(); } if(dt.Rows[n]["Name"]!=null && dt.Rows[n]["Name"].ToString()!="") { model.Name=dt.Rows[n]["Name"].ToString(); } if(dt.Rows[n]["TypeCode"]!=null && dt.Rows[n]["TypeCode"].ToString()!="") { model.TypeCode=dt.Rows[n]["TypeCode"].ToString(); } if(dt.Rows[n]["OrganID"]!=null && dt.Rows[n]["OrganID"].ToString()!="") { model.OrganID=int.Parse(dt.Rows[n]["OrganID"].ToString()); } modelList.Add(model); } } return modelList; }
/// <summary> /// 增加一条数据 /// </summary> public int Add(ObjectGroup model) { //StringBuilder strSql = new StringBuilder(); //strSql.Append("insert into ObjectGroup("); //strSql.Append("Code,Name,TypeCode,OrganID)"); //strSql.Append(" values ("); //strSql.Append("@Code,@Name,@TypeCode,@OrganID)"); //strSql.Append(";select @@IDENTITY"); //SqlParameter[] parameters = { // new SqlParameter("@name", model.Name), // new SqlParameter("@typeCode", model.TypeCode), // new SqlParameter("@organID", model.OrganID)}; //parameters[0].Value = model.Code; //parameters[1].Value = model.Name; //parameters[2].Value = model.TypeCode; //parameters[3].Value = model.OrganID; //object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); //if (obj == null) //{ // return 0; //} //else //{ // return Convert.ToInt32(obj); //} SqlParameter[] parameters = { new SqlParameter("@name", model.Name), new SqlParameter("@typeCode", model.TypeCode), new SqlParameter("@InputBy", model.InputBy), new SqlParameter("@organID", model.OrganID)}; int re=0; DbHelperSQL.RunProcedure("Proc_AddObjectGroup", parameters,out re); return re; }
/// <summary> /// 增加一条数据 /// </summary> public int Add(ObjectGroup model) { return dal.Add(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ObjectGroup model) { return dal.Update(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ObjectGroup model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ObjectGroup set "); strSql.Append("Name=@Name,"); strSql.Append("TypeCode=@TypeCode"); strSql.Append(" where Code=@Code"); SqlParameter[] parameters = { new SqlParameter("@Name",model.Name), new SqlParameter("@TypeCode", model.TypeCode), new SqlParameter("@Code",model.Code)}; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public ObjectGroup GetModel(string code) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from ObjectGroup"); strSql.Append(" where Code=@Code"); SqlParameter[] parameters = { new SqlParameter("@Code", SqlDbType.VarChar,20) }; parameters[0].Value = code; ObjectGroup model = new ObjectGroup(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["Code"] != null && ds.Tables[0].Rows[0]["Code"].ToString() != "") { model.Code = ds.Tables[0].Rows[0]["Code"].ToString(); } if (ds.Tables[0].Rows[0]["Name"] != null && ds.Tables[0].Rows[0]["Name"].ToString() != "") { model.Name = ds.Tables[0].Rows[0]["Name"].ToString(); } if (ds.Tables[0].Rows[0]["TypeCode"] != null && ds.Tables[0].Rows[0]["TypeCode"].ToString() != "") { model.TypeCode = ds.Tables[0].Rows[0]["TypeCode"].ToString(); } if (ds.Tables[0].Rows[0]["OrganID"] != null && ds.Tables[0].Rows[0]["OrganID"].ToString() != "") { model.OrganID = int.Parse(ds.Tables[0].Rows[0]["OrganID"].ToString()); } return model; } else { return null; } }