当前位置: 首页>>代码示例>>C#>>正文


C# IRecord.SetValue方法代码示例

本文整理汇总了C#中IRecord.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# IRecord.SetValue方法的具体用法?C# IRecord.SetValue怎么用?C# IRecord.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRecord的用法示例。


在下文中一共展示了IRecord.SetValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateColumnValuesInRecord

        /// <summary>
        /// Sets a database record values with values retrieved from data file.
        /// </summary>
        /// <param name="rowValues"></param>
        /// <param name="record"></param>
        private bool UpdateColumnValuesInRecord(string[] rowValues, IRecord record, bool isResolvedForeignKeysChecked)
        {
            int j = 0;
                bool isRecordUpdated = false;
                ColumnCount = 1;
                foreach (string data in rowValues)
                {
                    ColumnCount++;
                    if (j > this.ImportList.Count - 1)
                    {
                        return isRecordUpdated;
                    }
                    try
                    {
                        if (this.ColumnNameList[j].ToString() != "" && ((CheckBox)this.ImportList[j]).Checked)
                        {
                            ForeignKey fkColumn = null;
                            BaseColumn currentColumn = this.DBTable.TableDefinition.ColumnList.GetByAnyName((string)this.ColumnNameList[j]);
                            if (isResolvedForeignKeysChecked)
                                fkColumn = this.DBTable.TableDefinition.GetForeignKeyByColumnName(currentColumn.InternalName);
                            String colValue = "";

                            // Check if the foreign key has DFKA. If so, then check the calue from csv file agains the DFKA column in the parent/foreign key table.
                            // If a match is found retrieve its ID and set that as value to be insterted in the current table where you are adding records.
                            if (fkColumn != null)
                            {

                                TableDefinition originalTableDef = fkColumn.PrimaryKeyTableDefinition;
                                BaseTable originalBaseTable = originalTableDef.CreateBaseTable();
                                WhereClause wc = null;
                                ArrayList records = new ArrayList();
                                BaseColumn pkColumn = (BaseColumn)originalTableDef.PrimaryKey.Columns[0];//Index is zero because we handle only those tables which has single PK column not composite keys.
                                if (fkColumn.PrimaryKeyDisplayColumns != null && fkColumn.PrimaryKeyDisplayColumns != "" && (!fkColumn.PrimaryKeyDisplayColumns.Trim().StartsWith("=")))
                                {
                                    wc = new WhereClause(originalTableDef.ColumnList.GetByAnyName(fkColumn.PrimaryKeyDisplayColumns), BaseFilter.ComparisonOperator.EqualsTo, data);

                                } else if (fkColumn.PrimaryKeyDisplayColumns != null && fkColumn.PrimaryKeyDisplayColumns != "" && (fkColumn.PrimaryKeyDisplayColumns.Trim().StartsWith("="))) {
                                    string primaryKeyDisplay = GetDFKA(fkColumn);
                                    if (primaryKeyDisplay != null) {
                                        wc = new WhereClause(originalTableDef.ColumnList.GetByAnyName(primaryKeyDisplay), BaseFilter.ComparisonOperator.EqualsTo, data);
                                    }
                                    else {
                                        wc = new WhereClause(pkColumn, BaseFilter.ComparisonOperator.EqualsTo, data);
                                    }
                                }
                                else
                                {
                                    // if the foreign key does not have DFKA then just check in the foreign key table if the id exists. If not create a record with the specified ID
                                    // before adding to current table
                                    wc = new WhereClause(pkColumn, BaseFilter.ComparisonOperator.EqualsTo, data);

                                }
                                BaseClasses.Data.BaseFilter join = null;
                                records = originalBaseTable.GetRecordList(join, wc.GetFilter(), null, null, 0, 100);
                                if (records.Count > 0)
                                {
                                    // take the first record and retrieve its ID.
                                    BaseRecord rec = (BaseRecord)records[0];

                                    colValue = (rec.GetValue(pkColumn)).ToString();

                                }
                                else
                                {
                                    //  IF there is not match found then you have to create a record in the foreign key table with DFKA value and then retreive its ID
                                    if (data != null & data != "")
                                    {

                                        IRecord tempRec;
                                        if (fkColumn.PrimaryKeyDisplayColumns != null && fkColumn.PrimaryKeyDisplayColumns != "" && (!fkColumn.PrimaryKeyDisplayColumns.Trim().StartsWith("=")))
                                        {
                                            tempRec = originalBaseTable.CreateRecord();
                                            TableDefinition tableDef = originalBaseTable.TableDefinition;
                                            foreach (BaseColumn newCol in tableDef.Columns)
                                            {
                                                if (fkColumn.PrimaryKeyDisplayColumns == newCol.InternalName)
                                                {
                                                    tempRec.SetValue(data, newCol.UniqueName);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            tempRec = originalBaseTable.CreateRecord(data);
                                        }
                                        tempRec.Save();
                                        colValue = (tempRec.GetValue(pkColumn)).ToString();
                                    }
                                   // colValue = data;
                                }
                            }
                            else
                            {
                                colValue = data;
                            }
//.........这里部分代码省略.........
开发者ID:ciswebb,项目名称:FPC-Estimate-App,代码行数:101,代码来源:ImportDataItems.cs


注:本文中的IRecord.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。