protected Model.ConfigLogModel AutoBindDataReader(SqlDataReader dr, params string[] fields) { var model = new Model.ConfigLogModel(); if (DbTool.HasFields("Id", fields)) { model.Id = DbTool.ConvertObject <System.Int32>(dr["Id"]); } if (DbTool.HasFields("ConfigId", fields)) { model.ConfigId = DbTool.ConvertObject <System.Int32>(dr["ConfigId"]); } if (DbTool.HasFields("UserId", fields)) { model.UserId = DbTool.ConvertObject <System.Int32>(dr["UserId"]); } if (DbTool.HasFields("Title", fields)) { model.Title = DbTool.ConvertObject <System.String>(dr["Title"]); } if (DbTool.HasFields("Note", fields)) { model.Note = DbTool.ConvertObject <System.String>(dr["Note"]); } if (DbTool.HasFields("CTime", fields)) { model.CTime = DbTool.ConvertObject <System.DateTime>(dr["CTime"]); } return(model); }
public int AddConfig(Model.ConfigModel model, Model.ConfigLogModel mdlog) { int rtn = 0; using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString)) { if (conn.State != ConnectionState.Open) { conn.Open(); } using (SqlTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [Config]"); strSql.Append("(TId,KId,Title,Val,Types,States,Sort,Remark)"); strSql.Append(" values (@TId,@KId,@Title,@Val,@Types,@States,@Sort,@Remark)"); strSql.Append(";select SCOPE_IDENTITY()"); SqlParameter[] parameters = { new SqlParameter("@TId", DbTool.FixSqlParameter(model.TId)), new SqlParameter("@KId", DbTool.FixSqlParameter(model.KId)) , new SqlParameter("@Title", DbTool.FixSqlParameter(model.Title)) , new SqlParameter("@Val", DbTool.FixSqlParameter(model.Val)) , new SqlParameter("@Types", DbTool.FixSqlParameter(model.Types)) , new SqlParameter("@States", DbTool.FixSqlParameter(model.States)) , new SqlParameter("@Sort", DbTool.FixSqlParameter(model.Sort)) , new SqlParameter("@Remark", DbTool.FixSqlParameter(model.Remark)) }; rtn += SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql.ToString(), parameters); StringBuilder strSql2 = new StringBuilder(); strSql2.Append("insert into [ConfigLog]"); strSql2.Append("(ConfigId,UserId,Title,Note,CTime)"); strSql2.Append(" values (@ConfigId,@UserId,@Title,@Note,@CTime)"); strSql2.Append(";select SCOPE_IDENTITY()"); SqlParameter[] parameters2 = { new SqlParameter("@ConfigId", DbTool.FixSqlParameter(mdlog.ConfigId)) , new SqlParameter("@UserId", DbTool.FixSqlParameter(mdlog.UserId)) , new SqlParameter("@Title", DbTool.FixSqlParameter(mdlog.Title)) , new SqlParameter("@Note", DbTool.FixSqlParameter(mdlog.Note)) , new SqlParameter("@CTime", DbTool.FixSqlParameter(mdlog.CTime)) }; rtn += SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql2.ToString(), parameters2); trans.Commit(); return(rtn); } catch (Exception) { trans.Rollback(); rtn = 0; } } } return(0); }
protected void BindDataReader(Model.ConfigLogModel model, SqlDataReader dr) { model.Id = DbTool.ConvertObject <System.Int32>(dr["Id"]); model.ConfigId = DbTool.ConvertObject <System.Int32>(dr["ConfigId"]); model.UserId = DbTool.ConvertObject <System.Int32>(dr["UserId"]); model.Title = DbTool.ConvertObject <System.String>(dr["Title"]); model.Note = DbTool.ConvertObject <System.String>(dr["Note"]); model.CTime = DbTool.ConvertObject <System.DateTime>(dr["CTime"]); }
public int DelConfig(Model.ConfigModel model, Model.ConfigLogModel mdlog) { int rtn = 0; using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString)) { if (conn.State != ConnectionState.Open) { conn.Open(); } using (SqlTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from Config "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", model.Id) }; rtn += SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql.ToString(), parameters); StringBuilder strSql2 = new StringBuilder(); strSql2.Append("insert into [ConfigLog]"); strSql2.Append("(ConfigId,UserId,Title,Note,CTime)"); strSql2.Append(" values (@ConfigId,@UserId,@Title,@Note,@CTime)"); strSql2.Append(";select SCOPE_IDENTITY()"); SqlParameter[] parameters2 = { new SqlParameter("@ConfigId", DbTool.FixSqlParameter(mdlog.ConfigId)) , new SqlParameter("@UserId", DbTool.FixSqlParameter(mdlog.UserId)) , new SqlParameter("@Title", DbTool.FixSqlParameter(mdlog.Title)) , new SqlParameter("@Note", DbTool.FixSqlParameter(mdlog.Note)) , new SqlParameter("@CTime", DbTool.FixSqlParameter(mdlog.CTime)) }; rtn += SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql2.ToString(), parameters2); trans.Commit(); return(rtn); } catch (Exception) { trans.Rollback(); rtn = 0; } } } return(0); }
public Model.ConfigLogModel GetModel(int Id) { string sql = "select top 1 * from ConfigLog where Id =" + Id; Model.ConfigLogModel model = new Model.ConfigLogModel(); SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, sql.ToString()); if (dr.Read()) { //var fields = DbTool.GetReaderFieldNames(dr); //model = AutoBindDataReader(dr, fields); BindDataReader(model, dr); } dr.Close(); return(model); }
public List <Model.ConfigLogModel> GetModelList() { List <Model.ConfigLogModel> result = new List <Model.ConfigLogModel>(); string sql = "select * from ConfigLog where 1=1"; Model.ConfigLogModel model = new Model.ConfigLogModel(); SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, sql.ToString()); //var fields = DbTool.GetReaderFieldNames(dr); while (dr.Read()) { //model = AutoBindDataReader(dr, fields); model = new Model.ConfigLogModel(); BindDataReader(model, dr); result.Add(model); } dr.Close(); return(result); }
public int Add(Model.ConfigLogModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [ConfigLog]"); strSql.Append("(ConfigId,UserId,Title,Note,CTime)"); strSql.Append(" values (@ConfigId,@UserId,@Title,@Note,@CTime)"); strSql.Append(";select SCOPE_IDENTITY()"); SqlParameter[] parameters = { new SqlParameter("@ConfigId", DbTool.FixSqlParameter(model.ConfigId)) , new SqlParameter("@UserId", DbTool.FixSqlParameter(model.UserId)) , new SqlParameter("@Title", DbTool.FixSqlParameter(model.Title)) , new SqlParameter("@Note", DbTool.FixSqlParameter(model.Note)) , new SqlParameter("@CTime", DbTool.FixSqlParameter(model.CTime)) }; return(DbTool.ConvertObject <int>(SqlHelper.ExecuteScalar(conn, CommandType.Text, strSql.ToString(), parameters), 0)); }
public int Update(Model.ConfigLogModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ConfigLog set "); strSql.Append("ConfigId=@ConfigId,UserId=@UserId,Title=@Title,Note=@Note,CTime=@CTime "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@ConfigId", DbTool.FixSqlParameter(model.ConfigId)) , new SqlParameter("@UserId", DbTool.FixSqlParameter(model.UserId)) , new SqlParameter("@Title", DbTool.FixSqlParameter(model.Title)) , new SqlParameter("@Note", DbTool.FixSqlParameter(model.Note)) , new SqlParameter("@CTime", DbTool.FixSqlParameter(model.CTime)) , new SqlParameter("@Id", model.Id) }; return(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters)); }