/// <summary> /// 更新一条数据 /// </summary> public bool Update(Hi.Model.BD_DisArea model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update [BD_DisArea] set "); strSql.Append("[CompanyID]=@CompanyID,"); strSql.Append("[ParentID]=@ParentID,"); strSql.Append("[Areacode]=@Areacode,"); strSql.Append("[AreaName]=@AreaName,"); strSql.Append("[Deep]=@Deep,"); strSql.Append("[SortIndex]=@SortIndex,"); strSql.Append("[ts]=@ts,"); strSql.Append("[dr]=@dr,"); strSql.Append("[modifyuser]=@modifyuser"); strSql.Append(" where [ID]=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int), new SqlParameter("@CompanyID", SqlDbType.Int), new SqlParameter("@ParentID", SqlDbType.Int), new SqlParameter("@Areacode", SqlDbType.VarChar, 32), new SqlParameter("@AreaName", SqlDbType.VarChar, 50), new SqlParameter("@Deep", SqlDbType.Int), new SqlParameter("@SortIndex", SqlDbType.VarChar, 50), new SqlParameter("@ts", SqlDbType.DateTime), new SqlParameter("@dr", SqlDbType.SmallInt), new SqlParameter("@modifyuser", SqlDbType.Int) }; parameters[0].Value = model.ID; parameters[1].Value = model.CompanyID; parameters[2].Value = model.ParentID; if (model.Areacode != null) { parameters[3].Value = model.Areacode; } else { parameters[3].Value = DBNull.Value; } parameters[4].Value = model.AreaName; parameters[5].Value = model.Deep; if (model.SortIndex != null) { parameters[6].Value = model.SortIndex; } else { parameters[6].Value = DBNull.Value; } parameters[7].Value = model.ts; parameters[8].Value = model.dr; parameters[9].Value = model.modifyuser; return(SqlHelper.ExecuteSql(SqlHelper.LocalSqlServer, strSql.ToString(), parameters) > 0); }
/// <summary> /// 由一行数据得到一个实体 /// </summary> private Hi.Model.BD_DisArea GetModel(DataRow r) { Hi.Model.BD_DisArea model = new Hi.Model.BD_DisArea(); model.ID = SqlHelper.GetInt(r["ID"]); model.CompanyID = SqlHelper.GetInt(r["CompanyID"]); model.ParentID = SqlHelper.GetInt(r["ParentID"]); model.Areacode = SqlHelper.GetString(r["Areacode"]); model.AreaName = SqlHelper.GetString(r["AreaName"]); model.Deep = SqlHelper.GetInt(r["Deep"]); model.SortIndex = SqlHelper.GetString(r["SortIndex"]); model.ts = SqlHelper.GetDateTime(r["ts"]); model.dr = SqlHelper.GetInt(r["dr"]); model.modifyuser = SqlHelper.GetInt(r["modifyuser"]); return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Hi.Model.BD_DisArea model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [BD_DisArea]("); strSql.Append("[CompanyID],[ParentID],[Areacode],[AreaName],[Deep],[SortIndex],[ts],[modifyuser])"); strSql.Append(" values ("); strSql.Append("@CompanyID,@ParentID,@Areacode,@AreaName,@Deep,@SortIndex,@ts,@modifyuser)"); strSql.Append(";select @@Identity"); SqlParameter[] parameters = { new SqlParameter("@CompanyID", SqlDbType.Int), new SqlParameter("@ParentID", SqlDbType.Int), new SqlParameter("@Areacode", SqlDbType.VarChar, 32), new SqlParameter("@AreaName", SqlDbType.VarChar, 50), new SqlParameter("@Deep", SqlDbType.Int), new SqlParameter("@SortIndex", SqlDbType.VarChar, 50), new SqlParameter("@ts", SqlDbType.DateTime), new SqlParameter("@modifyuser", SqlDbType.Int) }; parameters[0].Value = model.CompanyID; parameters[1].Value = model.ParentID; if (model.Areacode != null) { parameters[2].Value = model.Areacode; } else { parameters[2].Value = DBNull.Value; } parameters[3].Value = model.AreaName; parameters[4].Value = model.Deep; if (model.SortIndex != null) { parameters[5].Value = model.SortIndex; } else { parameters[5].Value = DBNull.Value; } parameters[6].Value = model.ts; parameters[7].Value = model.modifyuser; return(SqlHelper.GetInt(SqlHelper.GetSingle(SqlHelper.LocalSqlServer, strSql.ToString(), parameters))); }