Inheritance: InternalDataCollectionBase
Beispiel #1
0
 public EnumerablePermuter_Freq(DataColumnCollection pContext, RunModeEnum pRunMode, ref string[] pStratavarList, ref List<string> pSelectClauses)
 {
     this.RunMode = pRunMode;
     this.StrataVarList = pStratavarList;
     this.SelectClaues = pSelectClauses;
     this.Columns = pContext;
 }
Beispiel #2
0
        /****** View with Source Object ******/


        private ADODB.Recordset ConvertToRecordset(DataTable inTable)
        {
            ADODB.Recordset result = new ADODB.Recordset();
            result.CursorLocation = ADODB.CursorLocationEnum.adUseClient;

            ADODB.Fields resultFields = result.Fields;
            System.Data.DataColumnCollection inColumns = inTable.Columns;

            foreach (DataColumn inColumn in inColumns)
            {
                resultFields.Append(inColumn.ColumnName
                                    , TranslateType(inColumn.DataType)
                                    , inColumn.MaxLength
                                    , inColumn.AllowDBNull ? ADODB.FieldAttributeEnum.adFldIsNullable : ADODB.FieldAttributeEnum.adFldUnspecified
                                    , null);
            }

            result.Open(System.Reflection.Missing.Value
                        , System.Reflection.Missing.Value
                        , ADODB.CursorTypeEnum.adOpenStatic
                        , ADODB.LockTypeEnum.adLockOptimistic, 0);

            foreach (DataRow dr in inTable.Rows)
            {
                result.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);

                for (int columnIndex = 0; columnIndex < inColumns.Count; columnIndex++)
                {
                    resultFields[columnIndex].Value = dr[columnIndex];
                }
            }

            return(result);
        }
 /// <summary>
 /// 初始化新的实体创建参数
 /// </summary>
 /// <param name="index">索引</param>
 /// <param name="row">当前数据行</param>
 /// <param name="columns">数据列集合</param>
 /// <param name="extraArg">额外参数</param>
 internal EntityCreatingArgs(Int32 index, DataRow row, DataColumnCollection columns, Object extraArg)
 {
     this._index = index;
     this._row = row;
     this._columns = columns;
     this._extraArg = extraArg;
 }
Beispiel #4
0
        /// <summary>
        /// Generate the INSERT statement
        /// </summary>
        /// <param name="tablename"></param>
        /// <param name="columns"></param>
        /// <param name="dataRow"></param>
        /// <returns></returns>
        public string CreateInsertStatement(string tablename, System.Data.DataColumnCollection columns, System.Data.DataRow dataRow)
        {
            StringBuilder col = new StringBuilder();
            StringBuilder val = new StringBuilder();

            for (int i = 0; i < columns.Count; i++)
            {
                // ignore primary keys
                if (columns[i].AutoIncrement)
                {
                    continue;
                }

                string columnName = columns[i].ColumnName;
                string value      = dataRow[columnName].ToString();

                if (i > 0)
                {
                    col.Append(",");
                    val.Append(",");
                }

                col.Append(MakeSafeColumnName(columnName));
                val.Append(OneDataValue(value, columns[columnName]));
            }

            return(String.Format("insert into [{0}] ({1}) values ({2});", tablename, col.ToString(), val.ToString()));
        }
        private void ApplyFormatRules(DataColumnCollection DCols, DataRow dRow, ListViewItem lvItem)
        {
            if (this.iSearchConfig.ResultFormatRules.Count < 1)
                return;

                object[] colvalues = dRow.ItemArray;

                for (int i = 0; i < DCols.Count; i++)
                {

                   foreach (SearchResultFormatRule srFormatRule in this.iSearchConfig.ResultFormatRules)
                   {

                       if ((DCols[i].ColumnName == srFormatRule.MatchField) && (colvalues[i].ToString() == srFormatRule.MatchValue))
                       {
                           /* rules match ! */
                           if (srFormatRule.Type == SearchResultFormatRule.RuleType.Colour)
                           {
                               /* Colour means to change the colour of text only */
                               lvItem.ForeColor = Color.FromName(srFormatRule.Colour); //( srFormatRule.Colour;
                           }

                       }
                   }
                }
        }
Beispiel #6
0
		public DataTable()
		{
			Columns = new DataColumnCollection(this);
			Rows = new DataRowCollection(this);
			Locale = CultureInfo.CurrentCulture;
			DefaultView = new DataView(this);
		}
Beispiel #7
0
 private static bool CompareColumn(System.Data.DataColumnCollection dcA, System.Data.DataColumnCollection dcB)
 {
     if (dcA.Count == dcB.Count)
     {
         foreach (DataColumn dc in dcA)
         {
             //找相同字段名称
             if (dcB.IndexOf(dc.ColumnName) > -1)
             {
                 //测试数据类型
                 if (dc.DataType != dcB[dcB.IndexOf(dc.ColumnName)].DataType)
                 {
                     return(false);
                 }
             }
             else
             {
                 return(false);
             }
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #8
0
        /// <summary>批量导入DataTable  
        /// 批量导入DataTable  
        /// </summary>  
        /// <param name="dt">DataTable数据表</param>  
        /// <param name="tblName">表名</param>  
        /// <param name="dtColumn">数据列集合</param>  
        /// <return>Boolean值:true成功,false失败</return>  
        public static Boolean insertTbl(DataTable dt, String tblName, DataColumnCollection dtColumn)
        {
            try
            {
                using (SqlBulkCopy sqlBC = new SqlBulkCopy(connString))
                {
                    //一次批量的插入的数据量
                    sqlBC.BatchSize = 1000;
                    //超时之前操作完成所允许的秒数,如果超时则事务不会提交 ,数据将回滚,所有已复制的行都会从目标表中移除
                    sqlBC.BulkCopyTimeout = 60;

                    //设置要批量写入的表
                    sqlBC.DestinationTableName = tblName;

                    //自定义的datatable和数据库的字段进行对应
                    //sqlBC.ColumnMappings.Add("id", "tel");
                    //sqlBC.ColumnMappings.Add("name", "neirong");
                    for (int i = 0; i < dtColumn.Count; i++)
                    {
                        sqlBC.ColumnMappings.Add(dtColumn[i].ColumnName.ToString(), dtColumn[i].ColumnName.ToString());
                    }
                    //批量写入
                   VipSoft.Common.NPOI2.ExcelUtils.printDT(dt);
                    sqlBC.WriteToServer(dt);
                }
            }
            catch(Exception e)
            {
                Console.Write(e.Message);
                return false;
            }
            return true;
        }
 public CourseRubricObject(DataColumnCollection columns, DataRow row)
 {
     this.id = columns.Contains("id") ? Convert.ToInt32(row["id"]) : -1;
     this.courseId = columns.Contains("course_id") ? Convert.ToInt32(row["course_id"]) : -1;
     this.courseName = columns.Contains("course_name") ? Convert.ToString(row["course_name"]) : "-";
     this.rubricName = columns.Contains("rubric_name") ? Convert.ToString(row["rubric_name"]) : "-";
 }
Beispiel #10
0
 /// <summary>
 /// 单行数据转为Json
 /// </summary>
 /// <param name="row"></param>
 /// <param name="columns"></param>
 /// <returns></returns>
 /// <remarks></remarks>
 public static string DataRowToJson(DataRow row, DataColumnCollection columns)
 {
     StringBuilder json = new StringBuilder("{");
     for (int i = 0; i <= columns.Count - 1; i++)
     {
         DataColumn c = columns[i];
         if (c.DataType.Name == "String")
         {
             json.AppendFormat("\"{0}\":\"{1}\"", c.ColumnName, row[c.ColumnName].ToString().Replace(@"\", @"\\").Replace("'", "\'").Replace("\"", "\\\""));
         }
         else if (c.DataType.Name == "DateTime")
         {
             json.AppendFormat("\"{0}\":\"{1}\"", c.ColumnName, row[c.ColumnName].ToString());
         }
         else if (c.DataType.Name == "Boolean")
         {
             json.AppendFormat("\"{0}\":\"{1}\"", c.ColumnName, (Convert.ToBoolean(row[c.ColumnName]) ? "true" : "false"));
         }
         else if (c.DataType.Name == "Byte[]")
         {
             json.AppendFormat("\"{0}\":\"{1}\"", c.ColumnName, Encoding.UTF8.GetString((byte[])row[c.ColumnName]));
         }
         else
         {
             json.AppendFormat("\"{0}\":{1}", c.ColumnName, (row[c.ColumnName].Equals(DBNull.Value) ? "\"\"" : row[c.ColumnName].ToString()));
         }
         json.Append((i < columns.Count - 1 ? "," : "}"));
     }
     return json.ToString();
 }
Beispiel #11
0
        /// <summary>
        /// Gets the json list by row.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns></returns>
        /// <Remarks>
        /// Created Time: 08-10-14 12:38
        /// Created By: jack_que
        /// Last Modified Time:  
        /// Last Modified By: 
        /// </Remarks>
        public static Dictionary<string, string> getJsonListByRow(DataRow row, DataColumnCollection columns, string format)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();

            foreach (DataColumn column in columns)
            {
                string columnName = column.ColumnName.ToLower();
                object value = row[column];
                string valueString = string.Empty;

                if (column.DataType.FullName.Equals("System.DateTime") && !value.ToString().Equals(string.Empty))
                {
                    valueString = ((DateTime)value).ToString(format);
                }
                else if (column.DataType.FullName.Equals("System.Decimal") && !value.ToString().Equals(string.Empty))
                {
                    valueString = GetDecimalString(value, columnName);
                }
                else
                {
                    valueString = value.ToString();
                }
                dic.Add(columnName, valueString);
            }

            return dic;
        }
Beispiel #12
0
        public static List <T> MapDataTableToObjectList <T>(DataTable dt) where T : new()
        {
            System.Data.DataColumnCollection columns = dt.Columns;
            int iColumnCount = columns.Count;
            int i;
            int j;
            T   ttype = new T();

            System.Reflection.PropertyInfo[] publicProperties = ttype.GetType().GetProperties();
            List <T> result = new List <T>();

            try
            {
                foreach (DataRow currentRow in dt.Rows)
                {
                    for (i = 0; i < iColumnCount; i++)
                    {
                        for (j = 0; j < publicProperties.Length; j++)
                        {
                            if (columns[i].ColumnName == publicProperties[j].Name)
                            {
                                publicProperties[j].SetValue(ttype, currentRow[i], null);
                            }
                        }
                    }
                    result.Add(ttype);
                    ttype = new T();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }
Beispiel #13
0
        public static UserProfileUpdateStatus UpdateUserProfileByAccount(UserProfileManager upm, string account, DataRow userInfo, DataColumnCollection columns)
        {
            upm.AssertNotNull("upm");
            userInfo.AssertNotNull("userInfo");
            columns.AssertNotNull("columns");

            bool exists = upm.UserExists(account);

            UserProfile profile = exists ? upm.GetUserProfile(account) : upm.CreateUserProfile(account);

            foreach (string colName in from DataColumn column in columns select column.ColumnName)
            {
                bool editable = profile[colName].Property.IsAdminEditable;

                if (editable)
                {
                    try
                    {
                        profile[colName].Value = userInfo[colName];
                    }
                    catch
                    {
                    }
                }

            }

            profile.Commit();

            return exists ? UserProfileUpdateStatus.Updated : UserProfileUpdateStatus.NewlyAdded;
        }
Beispiel #14
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="row">The row definition.</param>
 /// <param name="name">The table name.</param>
 /// <param name="rowCount">The number of rows in the table.</param>
 /// <param name="columns">Information on the column tables.</param>
 public DatabaseTableInfo(DataRow row, string name, int rowCount,
     DataColumnCollection columns)
 {
     Name = name;
     Data = row;
     RowCount = rowCount;
     Columns = columns;
 }
Beispiel #15
0
 public DynamicDataSet(Func<DataRow> dataRow, DataColumnCollection dataColumns)
 {
     this._dataRow = dataRow;
     _dataColumns = new List<DataColumn>();
     foreach (var col in this._dataColumns)
     {
         _dataColumns.Add(col);
     }
 }
Beispiel #16
0
 //
 private string AssumeColumn(DataColumnCollection col)
 {
     int ColumnsCount = col.Count;
     List<string> header = new List<string>();
     for (int i = 0; i < ColumnsCount; i++){
       header.Add(col[i].Caption);
     }
     return AssumeLine(header.ToArray());
 }
Beispiel #17
0
 private bool RowEqual(DataRow rowA, DataRow rowB, DataColumnCollection columns)
 {
     bool result = true;
     for (int i = 0; i < columns.Count; i++)
     {
         result &= ColumnEqual(rowA[columns[i].ColumnName], rowB[columns[i].ColumnName]);
     }
     return result;
 }
Beispiel #18
0
 public void Init(DataColumnCollection columns)
 {
     Columns = columns;
     this.listBoxControl1.Items.Clear();
     foreach (DataColumn column in this.Columns)
     {
         this.listBoxControl1.Items.Add(column.ColumnName);
     }
 }
 public ClassInSchoolObject(DataColumnCollection columns, DataRow row)
 {
     this.id = columns.Contains("id") ? Convert.ToInt32(row["id"]) : -1;
     this.classId = (columns.Contains("class_id") && !row.IsNull("class_id")) ? Convert.ToInt32(row["class_id"]) : -1;
     this.schoolId = (columns.Contains("school_id") && !row.IsNull("school_id")) ? Convert.ToInt32(row["school_id"]) : -1;
     this.teacherId = (columns.Contains("teacher_id") && !row.IsNull("teacher_id")) ? Convert.ToInt32(row["teacher_id"]) : -1;
     this.className = (columns.Contains("class_name") && !row.IsNull("class_name")) ? Convert.ToString(row["class_name"]) : "-";
     this.schoolName = (columns.Contains("school_name") && !row.IsNull("school_name")) ? Convert.ToString(row["school_name"]) : "-";
     this.teacherName = (columns.Contains("teacher") && !row.IsNull("teacher")) ? Convert.ToString(row["teacher"]) : "-";
 }
Beispiel #20
0
        public static List <System.Data.DataColumn> ToList(this System.Data.DataColumnCollection columns)
        {
            List <System.Data.DataColumn> retour = new List <System.Data.DataColumn>();

            foreach (System.Data.DataColumn item in columns)
            {
                retour.Add(item);
            }
            return(retour);
        }
 private static Row CreateHeaderRow(DataColumnCollection columns)
 {
     Row header = new Row();
     for (int i = 0; i < columns.Count; i++)
     {
         Cell cell = CreateCell(i + 1, 1, columns[i].ColumnName, CellValues.String);
         header.Append(cell);
     }
     return header;
 }
 public void InsertIntoTempTable(int iBatchID, DataColumnCollection columns, DataRow dr)
 {
     List<SqlParameter> parameters = new List<SqlParameter>();
     parameters.Add(new SqlParameter("@BatchID", iBatchID));
     foreach (DataColumn dc in columns)
     {
         parameters.Add(new SqlParameter("@" + dc.ColumnName, dr[dc.ColumnName].ToString()));
     }
     ExecuteNonQuery("spN_ins_RegistrationUploads", parameters.ToArray(), CommandType.StoredProcedure);
 }
Beispiel #23
0
        protected static string GetColumnNames(DataColumnCollection columns)
        {
            var result = new List<string>();

            foreach (DataColumn column in columns)
            {
                result.Add(column.ColumnName);
            }

            return string.Join(",", result);
        }
        DataTable GetColumns(DataColumnCollection coll)
        {
            var r = new DataTable();
            r.Columns.Add("N");
            foreach (DataColumn c in coll)
            {
                r.Rows.Add(c.ColumnName);
            }

            return r;
        }
Beispiel #25
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ds">
        /// A <see cref="DataSet"/>
        /// </param>
        public ResultSet(DataSet ds)
        {
            if (ds != null && ds.Tables != null && ds.Tables.Count > 0) {
                DataTable dt = ds.Tables [0]; // only one table is returned with query results.
                Rows = dt.Rows;
                Columns = dt.Columns;
            }

            // Expose values as public properties to access them on json objects.
            PopulatingPublicProperties ();
        }
Beispiel #26
0
        //public static Int32 ToInt32(this DataRow dr,DataColumnCollection dc, string field)
        //{
        //    if (dc.Contains(field))
        //    {
        //        return ToInt32(dr[field].ToString());
        //    }
        //    else
        //    {
        //        return 0;
        //    }
        //}

        public static string ToString(this DataRow dr, DataColumnCollection dc, string field)
        {
            if (dc.Contains(field))
            {
                return dr[field].ToString();
            }
            else
            {
                return "";
            }
        }
 /// <summary>
 /// Checks if the columnList names are included in columns names.
 /// </summary>
 /// <param name="columnList">column list names</param>
 /// <param name="columns">DataColumn collection</param>
 /// <returns>True if all are included, otherwise false</returns>
 public static bool ExistColumn(string[] columnList, DataColumnCollection columns)
 {
     foreach (string column in columnList)
     {
         if (!columns.Contains(column))
         {
             return false;
         }
     }
     return true;
 }
        /// <summary>
        /// 将一个数据行的所有键值关系复制到NameValueCollection中。
        /// </summary>
        /// <param name="row">一个数据行</param>
        /// <param name="columns">要使用和引用的数据字段集合</param>
        /// <returns></returns>
        public static NameValueCollection ToNameValueCollection(DataRow row, DataColumnCollection columns)
        {
            NameValueCollection result = new NameValueCollection();

            for (int i = 0; i < columns.Count; i++)
            {
                result[columns[i].ColumnName] = row[columns[i].ColumnName].ToString();
            }

            return result;
        }
        public void InsertIntoTempTable(int iClass, DataColumnCollection columns, DataRow dr)
        {
            List<SqlParameter> parameters = new List<SqlParameter>();
            parameters.Add(new SqlParameter("@Class", iClass));

            foreach (DataColumn dc in columns)
            {
                parameters.Add(new SqlParameter("@" + dc.ColumnName, dr[dc.ColumnName].ToString()));
            }
            ExecuteNonQuery("spN_ins_PracticeTestQuestion", parameters.ToArray(), CommandType.StoredProcedure);
        }
Beispiel #30
0
 public ResultSetRow(DataRow row, DataColumnCollection columnsSpec)
 {
     if (row != null && columnsSpec != null) {
         int columnsCount = columnsSpec.Count;
         ColumnsList = new object[columnsCount];
         for (int i=0; i<columnsCount; i++) {
             DataColumn column = columnsSpec [i];
             object val = row [column];
             ColumnsList [i] = val;
         }
     }
 }
        public void MapColumns(DataColumnCollection columns)
        {

            QRColumnNames obj;

            foreach(var column in columns.Cast<DataColumn>()
                                           .Select((value, index) => new { index = index, value = value })
                                           .Where(x => QRColumnNames.TryParse(x.value.ColumnName, true, out obj))
                                           .Select(x => new {cnmae=x.value.ColumnName,idx=x.index}))
                template.Add(column.idx, CreateAct(column.cnmae));

        }
Beispiel #32
0
 public static DataTable newDataTable(DataColumnCollection columns, List<DataRow> rows)
 {
     DataTable newDt = new DataTable();
     foreach (DataColumn column in columns)
     {
         newDt.Columns.Add(column.ColumnName);
     }
     foreach(DataRow row in rows) {
         copyRow(newDt,row);
     }
     return newDt;
 }
Beispiel #33
0
        public GradeObject(DataColumnCollection columns, DataRow row)
        {
            this.grade = columns.Contains("grade") ? Convert.ToInt32(row["grade"]) : -1;
            this.rubricId = columns.Contains("rubric_id") ? Convert.ToInt32(row["rubric_id"]) : -1;
            this.studentId = columns.Contains("student_id") ? Convert.ToInt32(row["student_id"]) : -1;
            this.teacherId = columns.Contains("teacher_id") ? Convert.ToInt32(row["teacher_id"]) : -1;
            this.date = (columns.Contains("date") && !row.IsNull("date")) ? Convert.ToString(row["date"]) : "-";
            this.note = (columns.Contains("note") && !row.IsNull("note")) ? Convert.ToString(row["note"]) : "-";

            if (!this.date.Equals("-"))
                this.date = this.date.Substring(0, this.date.IndexOf(' ') + 1);
        }
Beispiel #34
0
        public void AssignValue(DataRow newRow, DataRow dataRow, DataColumnCollection columns)
        {
            foreach (DataColumn dataColumn in columns)
            {
                var val = dataRow[dataColumn.ColumnName];

                if (val == null)
                    newRow[dataColumn.ColumnName] = dataColumn.DefaultValue;
                else
                    newRow[dataColumn.ColumnName] = ConvertValue(val,dataColumn.DataType);
            }
        }
Beispiel #35
0
        // DataRowをHashtableに変換
        private static Hashtable changeHashtable(
        DataColumnCollection cols,
        DataRow row)
        {
            Hashtable hash = new Hashtable();

              foreach(DataColumn col in cols){
            hash[col.Caption]
              = ((DBNull.Value==row[col.Caption])?"":row[col.Caption]);
              }

              return hash;
        }
Beispiel #36
0
        /// <summary>
        /// DataTable에 쿼리파라메터 정보를 만든다.
        /// </summary>
        /// <param name="dt">DataTable</param>
        /// <param name="index">시작인덱스</param>
        /// <returns>IDataParameter 배열</returns>
        public virtual IDataParameter[] GetParameters(DataTable dt, int index)
        {
            System.Data.DataColumnCollection cCol = dt.Columns;

            IDataParameter[] param = GetParameters(cCol.Count);

            for (int i = index; i < cCol.Count; i++)
            {
                param[i] = GetParameter("@" + cCol[i].ColumnName, Convert.DBNull);
            }

            return(param);
        }
Beispiel #37
0
        public virtual IDataParameter[] SetParameterValue(IDataParameter[] param, DataTable dt, int index)
        {
            if (param == null || param.Length == 0)
            {
                return(param);
            }
            System.Data.DataColumnCollection cCol = dt.Columns;

            for (int i = index; i < cCol.Count; i++)
            {
                param[i].Value = dt.Rows[index][cCol[i].ColumnName];
            }

            return(param);
        }
Beispiel #38
0
        /// <summary>
        /// DataTable转换为实体对象
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="dt">要转换的DataTable</param>
        /// <returns>转换后的实体对象</returns>
        public static T ConvertToEntity <T>(DataTable dt) where T : new()
        {
            System.Data.DataColumnCollection columns = dt.Columns;
            DataRow row          = dt.Rows[0];
            int     iColumnCount = columns.Count;
            int     i;
            int     j;
            T       t = new T();
            Type    elementType;

            elementType = t.GetType();
            System.Reflection.PropertyInfo[] publicProperties = elementType.GetProperties();
            for (i = 0; i < iColumnCount; i++)
            {
                for (j = 0; j < publicProperties.Length; j++)
                {
                    if (columns[i].ColumnName.ToLower() == publicProperties[j].Name.ToLower())
                    {
                        if (publicProperties[j].PropertyType == typeof(int))
                        {
                            int num = 0;
                            try
                            {
                                num = Convert.ToInt32(row[i]);
                            }
                            catch
                            {
                            }
                            publicProperties[j].SetValue(t, num, null);
                        }
                        else
                        {
                            if (publicProperties[j].PropertyType == typeof(string) && row[i] == System.DBNull.Value)
                            {
                                publicProperties[j].SetValue(t, "", null);
                            }
                            else
                            {
                                object value = row[i] == System.DBNull.Value ? null : row[i];
                                publicProperties[j].SetValue(t, value, null);
                            }
                        }
                    }
                }
            }
            return(t);
        }
        private void UpdateADODBRecordset_from_ADODataTable(DataTable inTable, ref ADODB.Recordset adoRs)
        {
            ADODB.Fields adoFields = adoRs.Fields;
            System.Data.DataColumnCollection inColumns = inTable.Columns;
            //Delete
            if (adoRs.RecordCount > 0)
            {
                adoRs.MoveFirst();
            }
            while (!adoRs.EOF)
            {
                adoRs.Delete();
                adoRs.MoveNext();
            }
            //Add
            foreach (DataRow dr in inTable.Rows)
            {
                // Proceso las que no estan borradas
                if (dr.RowState != DataRowState.Deleted)
                {
                    adoRs.AddNew(System.Reflection.Missing.Value,
                                 System.Reflection.Missing.Value);

                    for (int columnIndex = 0; columnIndex < inColumns.Count; columnIndex++)
                    {
                        ADODB.Field field = adoFields[columnIndex];
                        try
                        {
                            adoFields[columnIndex].Value = dr[columnIndex];
                        }
                        catch (Exception ex)
                        {
                            string message = string.Format("Error al actualizar la columna {0}.{1}: {2}", inTable.TableName, field.Name, ex.Message);
                            throw new XTangoException(message);
                        }
                    }
                }
            }
        }
Beispiel #40
0
 /// <summary>
 /// Writes header row of a worksheet in XLS file
 /// </summary>
 /// <param name="dcc"></param>
 public void XlsWriteTableHeader(System.Data.DataColumnCollection dcc, int settings)
 {
     for (int i = 0; i < dcc.Count; i++)
     {
         System.Data.DataColumn dc = dcc[i];
         string width = (this.StripHtml(dc.ColumnName).Length * 7).ToString();
         if (settings == 1)
         {
             width = "120";
         }
         if (i == 0)
         {
             width = "180";
         }
         this.WriteLine("<Column ss:Index=\"" + (i + 1).ToString() +
                        "\" ss:AutoFitWidth=\"0\" ss:Width=\"" + width + "\"/>");
     }
     this.WriteLine("   <Row ss:AutoFitHeight=\"0\" ss:Height=\"90\">");
     for (int i = 0; i < dcc.Count; i++)
     {
         System.Data.DataColumn dc = dcc[i];
         string text  = this.StripHtml(dc.ColumnName);
         string style = "s42";
         if (settings == 1)
         {
             style = "s22";
         }
         if (i == 0)
         {
             style = "s41";
             text  = "CANON";
         }
         this.WriteLine("    <Cell ss:StyleID=\"" + style + "\"><Data ss:Type=\"String\">" +
                        text + "</Data></Cell>");
     }
     this.WriteLine("   </Row>");
 }
Beispiel #41
0
        public static void Update_ADODB_from_ADO(DataTable inTable, ref ADODB.Recordset adoRs)
        {
            // ADODB.Recordset result = adoRs.Clone(ADODB.LockTypeEnum.adLockOptimistic);
            ADODB.Fields adoFields = adoRs.Fields;
            System.Data.DataColumnCollection inColumns = inTable.Columns;
            //Delete
            adoRs.MoveFirst();
            while (!adoRs.EOF)
            {
                adoRs.Delete();
                adoRs.MoveNext();
            }
            //Add
            foreach (DataRow dr in inTable.Rows)
            {
                adoRs.AddNew(System.Reflection.Missing.Value,
                             System.Reflection.Missing.Value);

                for (int columnIndex = 0; columnIndex < inColumns.Count; columnIndex++)
                {
                    adoFields[columnIndex].Value = dr[columnIndex];
                }
            }
        }
Beispiel #42
0
        public static ADODB.Recordset ConvertToRecordset(DataTable dt)
        {
            ADODB.Recordset rs = new ADODB.Recordset();
            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;

            ADODB.Fields RsFld = rs.Fields;
            System.Data.DataColumnCollection DtCols = dt.Columns;

            foreach (DataColumn DtCol in DtCols)
            {
                RsFld.Append(DtCol.ColumnName
                             , CAdo.ConvertDotNetTypeToAdoType(DtCol.DataType)
                             , DtCol.MaxLength
                             , DtCol.AllowDBNull ? ADODB.FieldAttributeEnum.adFldIsNullable :
                             ADODB.FieldAttributeEnum.adFldUnspecified
                             , null);
            }

            rs.Open(System.Reflection.Missing.Value
                    , System.Reflection.Missing.Value
                    , ADODB.CursorTypeEnum.adOpenStatic
                    , ADODB.LockTypeEnum.adLockOptimistic, 0);

            foreach (DataRow dr in dt.Rows)
            {
                rs.AddNew(System.Reflection.Missing.Value,
                          System.Reflection.Missing.Value);

                for (int cl = 0; cl < DtCols.Count; cl++)
                {
                    RsFld[cl].Value = dr[cl];
                }
            }

            return(rs);
        }
Beispiel #43
0
        private void LoadTopMostTable(DataTable table)
        {
            DataColumn           columnSchema;
            bool                 flag3     = this.isTableLevel || (this.dataSet.DataSetName != table.TableName);
            DataRow              parentRow = null;
            bool                 flag      = false;
            int                  num3      = this.dataReader.Depth - 1;
            int                  count     = this.childRowsStack.Count;
            DataColumnCollection columns   = table.Columns;

            object[] foundColumns = new object[columns.Count];
            foreach (XmlAttribute attribute in this.topMostNode.Attributes)
            {
                columnSchema = this.nodeToSchemaMap.GetColumnSchema(attribute, this.FIgnoreNamespace(attribute)) as DataColumn;
                if ((columnSchema != null) && (columnSchema.ColumnMapping == MappingType.Attribute))
                {
                    XmlNode firstChild = attribute.FirstChild;
                    foundColumns[columnSchema.Ordinal] = columnSchema.ConvertXmlToObject(this.GetInitialTextFromNodes(ref firstChild));
                    flag = true;
                }
            }
            while (num3 < this.dataReader.Depth)
            {
                DataTable table2;
                object    obj2;
                switch (this.dataReader.NodeType)
                {
                case XmlNodeType.Element:
                {
                    obj2         = this.nodeToSchemaMap.GetColumnSchema(table, this.dataReader, this.FIgnoreNamespace(this.dataReader));
                    columnSchema = obj2 as DataColumn;
                    if (columnSchema == null)
                    {
                        goto Label_017F;
                    }
                    if (foundColumns[columnSchema.Ordinal] != null)
                    {
                        break;
                    }
                    this.LoadColumn(columnSchema, foundColumns);
                    flag = true;
                    continue;
                }

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                {
                    string s = this.dataReader.ReadString();
                    columnSchema = table.xmlText;
                    if ((columnSchema != null) && (foundColumns[columnSchema.Ordinal] == null))
                    {
                        foundColumns[columnSchema.Ordinal] = columnSchema.ConvertXmlToObject(s);
                    }
                    continue;
                }

                case XmlNodeType.EntityReference:
                    throw ExceptionBuilder.FoundEntity();

                default:
                    goto Label_01F2;
                }
                this.dataReader.Read();
                continue;
Label_017F:
                table2 = obj2 as DataTable;
                if (table2 != null)
                {
                    this.LoadTable(table2, true);
                    flag = true;
                }
                else if (!this.ProcessXsdSchema())
                {
                    if (!flag && !flag3)
                    {
                        return;
                    }
                    this.dataReader.Read();
                }
                continue;
Label_01F2:
                this.dataReader.Read();
            }
            this.dataReader.Read();
            for (int i = foundColumns.Length - 1; i >= 0; i--)
            {
                if (foundColumns[i] == null)
                {
                    columnSchema = columns[i];
                    if ((columnSchema.AllowDBNull && (columnSchema.ColumnMapping != MappingType.Hidden)) && !columnSchema.AutoIncrement)
                    {
                        foundColumns[i] = DBNull.Value;
                    }
                }
            }
            parentRow = table.Rows.AddWithColumnEvents(foundColumns);
            while (count < this.childRowsStack.Count)
            {
                DataRow row   = (DataRow)this.childRowsStack.Pop();
                bool    flag2 = row.RowState == DataRowState.Unchanged;
                row.SetNestedParentRow(parentRow, false);
                if (flag2)
                {
                    row.oldRecord = row.newRecord;
                }
            }
        }
Beispiel #44
0
 /// <summary>
 /// 动态给控件绑定数据源
 /// </summary>
 /// <param name="lcGroup"></param>
 /// <param name="modelSource"></param>
 /// <param name="dataColumnCollection"></param>
 public static void VoucherDataBindings(LayoutControlGroup lcGroup, BindingSource modelSource, System.Data.DataColumnCollection dataColumnCollection)
 {
     foreach (BaseLayoutItem baseItem in lcGroup.Items)
     {
         LayoutControlItem item = baseItem as LayoutControlItem;
         if (item.Control != null && dataColumnCollection.Contains(item.CustomizationFormText))
         {
             item.Control.DataBindings.Add(new Binding("EditValue", modelSource, item.CustomizationFormText, true));
         }
     }
 }
Beispiel #45
0
        private void LoadTable(DataTable table, bool isNested)
        {
            DataColumn           xmlText;
            DataRow              row     = null;
            int                  depth   = this.dataReader.Depth;
            int                  count   = this.childRowsStack.Count;
            DataColumnCollection columns = table.Columns;

            object[] foundColumns = new object[columns.Count];
            int      pos          = -1;
            string   str3         = string.Empty;
            string   str2         = null;
            bool     flag         = false;

            for (int i = this.dataReader.AttributeCount - 1; i >= 0; i--)
            {
                this.dataReader.MoveToAttribute(i);
                xmlText = this.nodeToSchemaMap.GetColumnSchema(table, this.dataReader, this.FIgnoreNamespace(this.dataReader)) as DataColumn;
                if ((xmlText != null) && (xmlText.ColumnMapping == MappingType.Attribute))
                {
                    foundColumns[xmlText.Ordinal] = xmlText.ConvertXmlToObject(this.dataReader.Value);
                }
                if (this.isDiffgram)
                {
                    if (!(this.dataReader.NamespaceURI == "urn:schemas-microsoft-com:xml-diffgram-v1"))
                    {
                        goto Label_0161;
                    }
                    string localName = this.dataReader.LocalName;
                    if (localName != null)
                    {
                        if (!(localName == "id"))
                        {
                            if (localName == "hasChanges")
                            {
                                goto Label_0124;
                            }
                            if (localName == "hasErrors")
                            {
                                goto Label_0136;
                            }
                        }
                        else
                        {
                            str3 = this.dataReader.Value;
                        }
                    }
                }
                continue;
Label_0124:
                str2 = this.dataReader.Value;
                continue;
Label_0136:
                flag = (bool)Convert.ChangeType(this.dataReader.Value, typeof(bool), CultureInfo.InvariantCulture);
                continue;
Label_0161:
                if (this.dataReader.NamespaceURI == "urn:schemas-microsoft-com:xml-msdata")
                {
                    if (this.dataReader.LocalName == "rowOrder")
                    {
                        pos = (int)Convert.ChangeType(this.dataReader.Value, typeof(int), CultureInfo.InvariantCulture);
                    }
                    else if (this.dataReader.LocalName.StartsWith("hidden", StringComparison.Ordinal))
                    {
                        xmlText = columns[XmlConvert.DecodeName(this.dataReader.LocalName.Substring(6))];
                        if ((xmlText != null) && (xmlText.ColumnMapping == MappingType.Hidden))
                        {
                            foundColumns[xmlText.Ordinal] = xmlText.ConvertXmlToObject(this.dataReader.Value);
                        }
                    }
                }
            }
            if (this.dataReader.Read() && (depth < this.dataReader.Depth))
            {
                while (depth < this.dataReader.Depth)
                {
                    DataTable table3;
                    object    obj2;
                    switch (this.dataReader.NodeType)
                    {
                    case XmlNodeType.Element:
                    {
                        obj2    = this.nodeToSchemaMap.GetColumnSchema(table, this.dataReader, this.FIgnoreNamespace(this.dataReader));
                        xmlText = obj2 as DataColumn;
                        if (xmlText == null)
                        {
                            goto Label_02DE;
                        }
                        if (foundColumns[xmlText.Ordinal] != null)
                        {
                            break;
                        }
                        this.LoadColumn(xmlText, foundColumns);
                        continue;
                    }

                    case XmlNodeType.Text:
                    case XmlNodeType.CDATA:
                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                    {
                        string s = this.dataReader.ReadString();
                        xmlText = table.xmlText;
                        if ((xmlText != null) && (foundColumns[xmlText.Ordinal] == null))
                        {
                            foundColumns[xmlText.Ordinal] = xmlText.ConvertXmlToObject(s);
                        }
                        continue;
                    }

                    case XmlNodeType.EntityReference:
                        throw ExceptionBuilder.FoundEntity();

                    default:
                        goto Label_0379;
                    }
                    this.dataReader.Read();
                    continue;
Label_02DE:
                    table3 = obj2 as DataTable;
                    if (table3 != null)
                    {
                        this.LoadTable(table3, true);
                    }
                    else if (!this.ProcessXsdSchema())
                    {
                        DataTable tableForNode = this.nodeToSchemaMap.GetTableForNode(this.dataReader, this.FIgnoreNamespace(this.dataReader));
                        if (tableForNode != null)
                        {
                            this.LoadTable(tableForNode, false);
                        }
                        else
                        {
                            this.dataReader.Read();
                        }
                    }
                    continue;
Label_0379:
                    this.dataReader.Read();
                }
                this.dataReader.Read();
            }
            if (this.isDiffgram)
            {
                row = table.NewRow(table.NewUninitializedRecord());
                row.BeginEdit();
                for (int j = foundColumns.Length - 1; j >= 0; j--)
                {
                    xmlText = columns[j];
                    xmlText[row.tempRecord] = (foundColumns[j] != null) ? foundColumns[j] : DBNull.Value;
                }
                row.EndEdit();
                table.Rows.DiffInsertAt(row, pos);
                if (str2 == null)
                {
                    row.oldRecord = row.newRecord;
                }
                if ((str2 == "modified") || flag)
                {
                    table.RowDiffId[str3] = row;
                }
            }
            else
            {
                for (int k = foundColumns.Length - 1; k >= 0; k--)
                {
                    if (foundColumns[k] == null)
                    {
                        xmlText = columns[k];
                        if ((xmlText.AllowDBNull && (xmlText.ColumnMapping != MappingType.Hidden)) && !xmlText.AutoIncrement)
                        {
                            foundColumns[k] = DBNull.Value;
                        }
                    }
                }
                row = table.Rows.AddWithColumnEvents(foundColumns);
            }
            while (count < this.childRowsStack.Count)
            {
                DataRow row2  = (DataRow)this.childRowsStack.Pop();
                bool    flag2 = row2.RowState == DataRowState.Unchanged;
                row2.SetNestedParentRow(row, false);
                if (flag2)
                {
                    row2.oldRecord = row2.newRecord;
                }
            }
            if (isNested)
            {
                this.childRowsStack.Push(row);
            }
        }
Beispiel #46
0
 string IDataImport.CreateInsertStatement(string tablename, System.Data.DataColumnCollection columns, System.Data.DataRow dataRow)
 {
     return(CreateInsertStatement(tablename, columns, dataRow));
 }
Beispiel #47
0
 protected internal DataRow(DataRowBuilder builder)
 {
     this.tempRecord = builder._record;
     this._table     = builder._table;
     this._columns   = this._table.Columns;
 }
Beispiel #48
0
 public DataTable()
 {
     Columns = new DataColumnCollection(this);
     Rows    = new DataRowCollection(this);
 }
Beispiel #49
0
 internal DataRow(DataColumnCollection columns)
 {
     Columns = columns;
     data    = new List <object>(Columns.Count);
     Element = new HTMLTableRowElement();
 }