/// <summary> /// 添加记录信息行 有事务 /// </summary> /// <param name="id">标识列的值(条件列,可扩展)</param> /// <param name="columns">需要的列数组</param> /// <param name="changetype">操作的类型(删除或修改)</param> public void AddRecordtran(SqlTransaction tran, string id, string[] columns, ChangeType changetype) { StringBuilder sqlbuilder = new StringBuilder(); sqlbuilder.Append("select "); if (columns.Length > 0) { for (int i = 0; i <= columns.Length - 2; i++) { sqlbuilder.Append(columns[i]); sqlbuilder.Append(","); } // 最后不要加逗点 sqlbuilder.Append(columns[columns.Length - 1]); } else { sqlbuilder.Append(" * "); } sqlbuilder.Append(" from "); sqlbuilder.Append(_tablename); sqlbuilder.Append(" where "); sqlbuilder.Append(_identity); sqlbuilder.Append(" = "); sqlbuilder.Append("'"); sqlbuilder.Append(id); sqlbuilder.Append("'"); SqlCommand cmd = new SqlCommand(sqlbuilder.ToString(), tran.Connection); cmd.Transaction = tran; SqlDataReader reader = cmd.ExecuteReader(); //SqlDataReader reader = DBHelper.ExecuteReader(sqlbuilder.ToString()); string ss = sqlbuilder.ToString(); ss = ""; bool isVisible = false; string columnName = string.Empty; while (reader.Read()) { // 添加列信息 if (this.State == RemarkState.StartHeader) { _remarkbuilder.Append("<tr align='center'>"); // 操作类型标题列 _remarkbuilder.Append("<th style='white-space:nowrap'>操作类型</th>"); for (int i = 0; i <= reader.FieldCount - 1; i++) { columnName = GetColumnName(reader.GetName(i)); //columnName = DsSystem.TableMap.Columns.GetColumnName(reader.GetName(i), out isVisible); // if (!isVisible) // { // hashNoVisible .Add (i , i); // continue ; // } // 添加字段名称记录信息 _remarkbuilder.Append("<th style='white-space:nowrap'>"); _remarkbuilder.Append(columnName); // 字段名称 _remarkbuilder.Append("</th>"); } _remarkbuilder.Append("</tr>"); this.State = RemarkState.StartItem; // 改变状态 } if (this.State == RemarkState.StartItem) { // 添加记录行信息 _remarkbuilder.Append("<tr align='center'>"); // 操作类型列 _remarkbuilder.Append("<td style='white-space:nowrap'>"); _remarkbuilder.Append(Enum.GetName(changetype.GetType(), changetype)); // 字段名称 _remarkbuilder.Append("</td>"); for (int i = 0; i <= reader.FieldCount - 1; i++) { if (hashNoVisible.Contains(i)) { continue; } _remarkbuilder.Append("<td style='white-space:nowrap'>"); if (hashDP.Contains(i)) { _remarkbuilder.Append(reader[i] == null ? " " : decipher(reader[i].ToString().Trim(), hashDP[i].ToString().ToLower())); // 字段名称 } else { _remarkbuilder.Append(reader[i] == null ? " " : reader[i].ToString().Trim()); // 字段名称 } _remarkbuilder.Append("</td>"); } _remarkbuilder.Append("</tr>"); this._item++; // 记录行加加 } } reader.Close(); }