/// <summary> /// 增加一条数据 带有事物 /// </summary> public int Add(Hi.Model.BD_DefDoc model, SqlTransaction Tran) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [BD_DefDoc]("); strSql.Append("[CompID],[AtCode],[AtName],[ts],[modifyuser])"); strSql.Append(" values ("); strSql.Append("@CompID,@AtCode,@AtName,@ts,@modifyuser)"); strSql.Append(";select @@Identity"); SqlParameter[] parameters = { new SqlParameter("@CompID", SqlDbType.Int), new SqlParameter("@AtCode", SqlDbType.VarChar, 50), new SqlParameter("@AtName", SqlDbType.VarChar, 50), new SqlParameter("@ts", SqlDbType.DateTime), new SqlParameter("@modifyuser", SqlDbType.Int) }; parameters[0].Value = model.CompID; if (model.AtCode != null) { parameters[1].Value = model.AtCode; } else { parameters[1].Value = DBNull.Value; } if (model.AtName != null) { parameters[2].Value = model.AtName; } else { parameters[2].Value = DBNull.Value; } if (model.ts != DateTime.MinValue) { parameters[3].Value = model.ts; } else { parameters[3].Value = DBNull.Value; } parameters[4].Value = model.modifyuser; if (Tran != null) { return(SqlHelper.GetInt(SqlHelper.GetSingle(strSql.ToString(), Tran, parameters))); } return(SqlHelper.GetInt(SqlHelper.GetSingle(SqlHelper.LocalSqlServer, strSql.ToString(), parameters))); }
/// <summary> /// 由一行数据得到一个实体 /// </summary> private Hi.Model.BD_DefDoc GetModel(DataRow r) { Hi.Model.BD_DefDoc model = new Hi.Model.BD_DefDoc(); model.ID = SqlHelper.GetInt(r["ID"]); model.CompID = SqlHelper.GetInt(r["CompID"]); model.AtCode = SqlHelper.GetString(r["AtCode"]); model.AtName = SqlHelper.GetString(r["AtName"]); model.AtType = SqlHelper.GetString(r["AtType"]); 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_DefDoc model, System.Data.SqlClient.SqlTransaction Tran) { return(dal.Add(model, Tran)); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Hi.Model.BD_DefDoc model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update [BD_DefDoc] set "); strSql.Append("[CompID]=@CompID,"); strSql.Append("[AtCode]=@AtCode,"); strSql.Append("[AtName]=@AtName,"); strSql.Append("[AtType]=@AtType,"); 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("@CompID", SqlDbType.Int), new SqlParameter("@AtCode", SqlDbType.VarChar, 50), new SqlParameter("@AtName", SqlDbType.VarChar, 50), new SqlParameter("@AtType", 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.CompID; if (model.AtCode != null) { parameters[2].Value = model.AtCode; } else { parameters[2].Value = DBNull.Value; } parameters[3].Value = model.AtName; if (model.AtType != null) { parameters[4].Value = model.AtType; } else { parameters[4].Value = DBNull.Value; } if (model.ts != DateTime.MinValue) { parameters[5].Value = model.ts; } else { parameters[5].Value = DBNull.Value; } parameters[6].Value = model.dr; parameters[7].Value = model.modifyuser; return(SqlHelper.ExecuteSql(SqlHelper.LocalSqlServer, strSql.ToString(), parameters) > 0); }