//根据查询SQL,产生提供给报表生成需要的 XML 数据,字段值为空也产生数据 public static void FullGenNodeXmlData(HttpResponse Response, string QuerySQL, bool ToCompress) { MyDbCommand ReportDataCommand = new MyDbCommand(QuerySQL, ReportConn); MyDbDataReader ReportDataReader = ReportDataCommand.ExecuteReader(); string Text = XMLReportData.FromDataReader(ReportDataReader); GridReportDataResponse.Response(Response, Text, ToCompress ? ResponseDataType.ZipBinary : ResponseDataType.PlainText); }
public virtual string GeneralUpdateRef <T>(T t, List <string> columns, ref IDbDataParameter[] paraArr) { if (columns.Count == 0) { throw new ArgumentException("no columns"); } InitDbChar(); string where = ""; Type type = typeof(T); List <OleDbParameter> list = new List <OleDbParameter>(); string dBDatbelName = type.Name; string sql = string.Format("update {0}{1}{2} set ", _BeginChar, dBDatbelName, _EndChar); PropertyInfo[] piArr = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo pi in piArr) { if (pi.GetCustomAttributes(typeof(PrimaryKeyAttribute), true).Length > 0) { string __fff = GetDefaultValue(pi.PropertyType, pi.GetValue(t, null)).ToString(); if (pi.PropertyType == typeof(string)) { __fff = string.Format("'{0}'", __fff); } where = string.Format(" where {0}{1}{2}={3} ", _BeginChar, pi.Name, _EndChar, __fff); } if (pi.GetCustomAttributes(typeof(AutoIncreaseAttribute), true).Length == 0) { if (!columns.Contains(pi.Name)) { continue; } sql += string.Format("{0}{1}{2}={3}{1},", _BeginChar, pi.Name, _EndChar, _ParameterChar); object val = GetDefaultValue(pi.PropertyType, pi.GetValue(t, null)); OleDbParameter olp = new OleDbParameter(string.Format("{0}{1}", _ParameterChar, pi.Name), val); olp.OleDbType = Convert2DbType(val); list.Add(olp); } } if (string.IsNullOrEmpty(where)) { throw new ArgumentException("lost primarykey"); } sql = sql.TrimEnd(',') + where; paraArr = list.ToArray(); MyDbCommand cmd = new MyDbCommand(sql, paraArr); MyDbCommand.Current = cmd; return(sql); }
//获取 Count(*) SQL 查询到的数据行数。参数 QuerySQL 指定获取报表数据的查询SQL public static int BatchGetDataCount(string QuerySQL) { int Total = 0; MyDbCommand ReportDataCommand = new MyDbCommand(QuerySQL, ReportConn); MyDbDataReader ReportDataReader = ReportDataCommand.ExecuteReader(); if (ReportDataReader.Read()) { Total = ReportDataReader.GetInt32(0); } return(Total); }
public virtual string GeneralInsertRef <T>(T t, ref IDbDataParameter[] paraArr) { InitDbChar(); Type type = typeof(T); string dBDatbelName = type.Name;; PropertyInfo[] piArr = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); string sqlColumn = string.Format("insert into {0}{1}{2} (", _BeginChar, dBDatbelName, _EndChar); string sqlParam = "("; List <OleDbParameter> list = new List <OleDbParameter>(); foreach (PropertyInfo pi in piArr) { if (pi.GetCustomAttributes(typeof(AutoIncreaseAttribute), true).Length > 0) { continue; } sqlColumn += string.Format("{0}{1}{2},", _BeginChar, pi.Name, _EndChar); sqlParam += string.Format("{0}{1},", _ParameterChar, pi.Name); object val = GetDefaultValue(pi.PropertyType, pi.GetValue(t, null)); OleDbParameter olp = new OleDbParameter(string.Format("{0}{1}", _ParameterChar, pi.Name), val); olp.OleDbType = Convert2DbType(val); list.Add(olp); } sqlColumn = sqlColumn.TrimEnd(','); sqlParam = sqlParam.TrimEnd(','); string sql = sqlColumn + ")values" + sqlParam + ")"; paraArr = list.ToArray(); MyDbCommand cmd = new MyDbCommand(sql, paraArr); MyDbCommand.Current = cmd; return(sql); }