protected virtual void AddFields(int i, string name, PropertyInfo propertyInfo)
 {
     ColumnNames.Add(name, propertyInfo);
     ColumnIndex.Add(i, propertyInfo);
     IndexToName.Add(i, name);
     NameToIndex.Add(name, i);
 }
Exemplo n.º 2
0
 private void SetSubItemText(ListViewItem item, ColumnIndex columnIndex, string text)
 {
     var subItem = item.SubItems[(int)columnIndex];
     if (subItem.Text != text) {
         subItem.Text = text;
     }
 }
 protected override void Dispose(bool disposing)
 {
     ColumnNames.Clear();
     ColumnIndex.Clear();
     IndexToName.Clear();
     NameToIndex.Clear();
 }
Exemplo n.º 4
0
 /// <summary>
 /// 数据有效性校验
 /// </summary>
 /// <param name="columnIndex"></param>
 /// <param name="column"></param>
 /// <param name="value"></param>
 /// <param name="row"></param>
 /// <returns></returns>
 private static RowStates Validate(ColumnIndex columnIndex, Column column, object value, IRow row)
 {
     if ((value == null || string.IsNullOrEmpty(value.ToString())) && column.Required)
     //如果格式化的值为null且该列为必需,则本行数据为空或无效,跳过。
     {
         //非映射列直接返回空行定义
         if (columnIndex.Index < 0)
         {
             return(RowStates.Empty);
         }
         object cellValue = GetCellValue(row.GetCell(columnIndex.Index));
         if (cellValue == null || string.IsNullOrWhiteSpace(cellValue.ToString()))
         {
             //如果单元格的值为空,则定义为空行
             return(RowStates.Empty);
         }
         //如果单元格的值不为空,则定义为无效行,添加到跳过的数据集中
         if (Skipped != null)
         {
             Skipped.Add(new KeyValuePair <string, string>(column.Caption, cellValue.ToString()));
         }
         return(RowStates.Invalid);
     }
     return(RowStates.Valid);
 }
 /// <summary>
 /// Returns a standard textual representation of the cell.
 /// </summary>
 public override string ToString()
 {
     return
         ("DataGridViewNumericUpDownCell { ColumnIndex=" +
          ColumnIndex.ToString(CultureInfo.CurrentCulture) + ", RowIndex=" +
          RowIndex.ToString(CultureInfo.CurrentCulture) + " }");
 }
Exemplo n.º 6
0
            /// <summary>
            /// Writes the node as XML
            /// </summary>
            /// <param name="writer">The XML writer</param>
            public void WriteTo(XmlWriter writer)
            {
                writer.WriteStartElement("node");
                if (MatchLabel != null)
                {
                    writer.WriteAttributeString("matches", MatchLabel);
                }

                if (Split.HasValue)
                {
                    writer.WriteAttributeString("split", Split.Value.ToString());
                }
                if (ColumnIndex >= 0)
                {
                    writer.WriteAttributeString("column", ColumnIndex.ToString());
                }
                if (Classification != null)
                {
                    writer.WriteAttributeString("classification", Classification);
                }

                if (Children != null)
                {
                    foreach (var child in Children)
                    {
                        child.WriteTo(writer);
                    }
                }
                writer.WriteEndElement();
            }
Exemplo n.º 7
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            DataRow    dataRow     = DataRow.Get(context);
            DataColumn dataColumn  = DataColumn.Get(context);
            Int32      columnIndex = ColumnIndex.Get(context);
            string     columnName  = ColumnName.Get(context);
            object     value       = null;

            try
            {
                if (dataColumn != null)
                {
                    value = dataRow[dataColumn];
                }
                else if (columnName != null && columnName != "")
                {
                    value = dataRow[columnName];
                }
                else
                {
                    value = dataRow[columnIndex];
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "获取行数据失败", e.Message);
                throw e;
            }

            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }
Exemplo n.º 8
0
        public GridVector Measure(GridMeasure available, GridLayoutModel model)
        {
            var row    = RowIndex.From(1);
            var column = ColumnIndex.From(1);

            return(GridVector.Create(row, column));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Remove reference to SqlDataReader instance and clears the column name dictionary (used by DBSqlServerCommand)
        /// </summary>
        internal void Cleanup()
        {
            SqlDataReader = null;

            ColumnIndex?.Clear();  // This method fills the internal array with zeros to help the gc
            ColumnIndex = null;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Gets the index for a column name
        /// </summary>
        /// <param name="columnName">Column name (case insensitive)</param>
        /// <returns>Index for the specified column name</returns>
        private int GetColumnIndex(string columnName)
        {
            if (ColumnIndex is null)
            {
                ColumnIndex = new Dictionary <string, int>(SqlDataReader.FieldCount);
            }

            if (ColumnIndex.TryGetValue(columnName, out int index))
            {
                return(index);
            }

            try
            {
                index = SqlDataReader.GetOrdinal(columnName);

                ColumnIndex[columnName] = index;

                return(index);
            }
            catch (IndexOutOfRangeException)
            {
                throw new ArgumentOutOfRangeException(
                          paramName: nameof(columnName),
                          message: string.Format(DBSqlServerLocalizedText.DBSqlServerDataReader_ColumnNotFound, columnName));
            }
        }
Exemplo n.º 11
0
        protected override void Execute(CodeActivityContext context)
        {
            DataTable  dataTable   = DataTable.Get(context);
            DataColumn dataColumn  = DataColumn.Get(context);
            string     columnName  = ColumnName.Get(context);
            Int32      columnIndex = ColumnIndex.Get(context);
            string     SortColName = null;
            string     SortText    = null;

            if (dataColumn != null)
            {
                SortColName = dataColumn.ColumnName;
            }
            else if (columnName != null && columnName != "")
            {
                SortColName = columnName;
            }
            else
            {
                SortColName = dataTable.Columns[columnIndex].ColumnName;
            }

            SortText = SortType == SortTypes.增序 ? SortColName + "ASC" : SortColName + "DESC";
            dataTable.DefaultView.Sort = SortText;
            DataTable dtNew = dataTable.DefaultView.ToTable();

            OutDataTable.Set(context, dtNew);
        }
Exemplo n.º 12
0
        private void IndexColumns()
        {
            // assume first row is header with names
            var header = _sheet.Rows[0];

            for (var index = 0; index < header.Cells.Length; index++)
            {
                var name = header.TextCells[index];
                if (!String.IsNullOrWhiteSpace(name))
                {
                    var column = _columns.FirstOrDefault(x => String.Compare(x, name, true) == 0);
                    if (column == null)
                    {
                        UnknownColumns.Add(column);                         // unknown column
                    }
                    else
                    {
                        ColumnIndex.Add(column, index);
                    }
                }
            }

            // figure out which columns are missing
            foreach (var col in _columns)
            {
                if (!ColumnIndex.ContainsKey(col))
                {
                    MissingColumns.Add(col);
                }
            }
        }
Exemplo n.º 13
0
 public override int GetHashCode()
 {
     if (Category != null)
     {
         return(ColumnIndex.GetHashCode() ^ Category.GetHashCode());
     }
     return(ColumnIndex.GetHashCode() ^ Split.GetHashCode());
 }
Exemplo n.º 14
0
        public override int GetHashCode()
        {
            int hashCode = 196471078;

            hashCode = hashCode * -1521134295 + ColumnIndex.GetHashCode();
            hashCode = hashCode * -1521134295 + RowIndex.GetHashCode();
            return(hashCode);
        }
        protected override void Execute(CodeActivityContext context)
        {
            var    inputDataTable = InputDataTable.Get(context);
            var    columnIndex    = ColumnIndex.Get(context);
            double result         = Utils.ColumnActionOnDataTable(inputDataTable, columnIndex, "MAX");

            MaximumValue.Set(context, result);
        }
Exemplo n.º 16
0
 public T GetValue <T>(object[] rowValues, string columnName)
 {
     if (ColumnIndex.TryGetValue(columnName, out var index) && rowValues.Length > index)
     {
         return((T)rowValues[index]);
     }
     return(default(T));
 }
Exemplo n.º 17
0
        private void SetSubItemText(ListViewItem item, ColumnIndex columnIndex, string text)
        {
            var subItem = item.SubItems[(int)columnIndex];

            if (subItem.Text != text)
            {
                subItem.Text = text;
            }
        }
Exemplo n.º 18
0
        public bool ContainsColumn(string columnName)
        {
            if (ColumnIndex != null)
            {
                return(ColumnIndex.ContainsKey(columnName));
            }

            return(Columns.Any(c => c.Name == columnName));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
        /// </returns>
        public override int GetHashCode()
        {
            int hash = 17;

            hash = (hash * 23) + ColumnIndex.GetHashCode();
            hash = (hash * 23) + RowIndex.GetHashCode();
            hash = (hash * 23) + State.GetHashCode();

            return(hash);
        }
Exemplo n.º 20
0
        private void SetSubItemText(ThreadWatcher watcher, ColumnIndex columnIndex, string text)
        {
            ListViewItem item    = (ListViewItem)watcher.Tag;
            var          subItem = item.SubItems[(int)columnIndex];

            if (subItem.Text != text)
            {
                subItem.Text = text;
            }
        }
Exemplo n.º 21
0
        public static string Get(Excel.ListRow listRow, ColumnIndex columnIndex)
        {
            if (null == listRow)
            {
                throw new ArgumentNullException("listRow");
            }

            Excel.Range range = listRow.Range[1, columnIndex];
            string      text  = range.Text;

            return(text.Trim());
        }
Exemplo n.º 22
0
 private DateTime?ExtractDateTime(XlsRowData row, string column)
 {
     if (ColumnIndex.ContainsKey(column))
     {
         var index = ColumnIndex[column];
         return(TypeConvert.ToDateTimeNull(row.Cells[index]));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 23
0
 private double ExtractDouble(XlsRowData row, string column)
 {
     if (ColumnIndex.ContainsKey(column))
     {
         var index = ColumnIndex[column];
         return(TypeConvert.ToDouble(row.Cells[index]));
     }
     else
     {
         return(0);
     }
 }
Exemplo n.º 24
0
 private string ExtractText(XlsRowData row, string column)
 {
     if (ColumnIndex.ContainsKey(column))
     {
         var index = ColumnIndex[column];
         return(row.TextCells[index]);
     }
     else
     {
         return(String.Empty);
     }
 }
Exemplo n.º 25
0
            /// <summary>
            /// 指定したカラムを更新
            /// </summary>
            /// <param name="index"></param>
            public void UpdateItem(ColumnIndex index)
            {
                switch (index)
                {
                case ColumnIndex.Locked:
                    SubItems[(int)ColumnIndex.Locked].Text = Info.Locked.ToString();
                    break;

                default:
                    throw new ArgumentOutOfRangeException("unknown update index");
                }
            }
Exemplo n.º 26
0
        void Initialize()
        {
            _inner.CellClick += (sender, ev) =>
            {
                var row    = RowIndex.From(ev.RowIndex);
                var column = ColumnIndex.From(ev.ColumnIndex);
                var index  = GridVector.Create(row, column);

                foreach (var elementKey in _layoutModel.Locate(index))
                {
                    var vCell = _lastGrid.FindCell(elementKey);
                    if (vCell == null)
                    {
                        continue;
                    }

                    var action = vCell.Attributes["A_ON_CLICK"] as Action;
                    if (action == null)
                    {
                        continue;
                    }

                    _dispatch(vCell.ElementKey, action);
                }
            };

            _inner.CellValueChanged += (sender, ev) =>
            {
                var row    = RowIndex.From(ev.RowIndex);
                var column = ColumnIndex.From(ev.ColumnIndex);
                var index  = GridVector.Create(row, column);

                foreach (var elementKey in _layoutModel.Locate(index))
                {
                    var vCell = _lastGrid.FindCell(elementKey);
                    if (vCell == null)
                    {
                        continue;
                    }

                    var action = vCell.Attributes["A_ON_CHANGED"] as Action <object>;
                    if (action == null)
                    {
                        continue;
                    }

                    var value = _inner.Rows[row.Row].Cells[column.Column].Value;

                    _dispatch(vCell.ElementKey, () => action(value));
                }
            };
        }
        private IQueryable <USER> OrderUsers(IQueryable <USER> source, ColumnIndex colIndex, Boolean asc)
        {
            switch (colIndex)
            {
            case ColumnIndex.NAME:
                source = asc ? source.OrderBy(s => s.LOGIN) : source.OrderByDescending(s => s.LOGIN);
                break;

            case ColumnIndex.STATUS:
                source = asc ? source.OrderBy(s => s.STATUS) : source.OrderByDescending(s => s.STATUS);
                break;
            }

            return(source);
        }
Exemplo n.º 28
0
        /// <summary>
        /// 格式化
        /// </summary>
        /// <param name="column"></param>
        /// <param name="columnIndex"></param>
        /// <param name="dr"></param>
        /// <param name="columnIndices"></param>
        /// <param name="columns"></param>
        /// <param name="dcs"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private static object Format(Column column, ColumnIndex columnIndex, DataRow dr,
                                     IEnumerable <ColumnIndex> columnIndices, IEnumerable <Column> columns, DataColumnCollection dcs,
                                     object value = null)
        {
            //非DataTable映射列
            if (!column.Intrinsic)
            {
                return(Format(column, dr, columnIndices, columns, dcs));
            }
            //读取DataTable中的值
            if (value == null)
            {
                value = dr[columnIndex.Field];
            }
            //将DBNull转换为null
            if (value == DBNull.Value)
            {
                value = null;
            }
            //格式化
            switch (column.FormatType)
            {
            case ColumnFormatTypes.Relate:
                var relateColumnIndex = columnIndices.First(ci => ci.Field == column.RelateField);
                var relateValue       = Format(columns.First(cm => cm.Field == column.RelateField), relateColumnIndex, dr,
                                               columnIndices, columns, dcs);
                return(column.Generate(value, relateValue));

            case ColumnFormatTypes.MultiRelate:
                var relateValues = new object[column.RelateFields.Length];
                for (var i = 0; i < column.RelateFields.Length; i++)
                {
                    var relateField        = column.RelateFields[i];
                    var relateIColumnIndex = columnIndices.First(ci => ci.Field == relateField);
                    relateValues[i] = Format(columns.First(cm => cm.Field == relateField), relateIColumnIndex, dr,
                                             columnIndices, columns, dcs);
                }
                return(column.Generate(value, relateValues));

            case ColumnFormatTypes.Normal:
                return(column.Generate(value));

            case ColumnFormatTypes.None:
            default:
                return(value);
            }
        }
Exemplo n.º 29
0
        private IQueryable <User> OrderUsers(IQueryable <User> source, ColumnIndex colIndex, Boolean asc)
        {
            switch (colIndex)
            {
            case ColumnIndex.NAME:
                source = asc ? source.OrderBy(s => s.Login) :
                         source.OrderByDescending(s => s.Login);
                break;

            case ColumnIndex.STATUS:
                source = asc ? source.OrderBy(s => s.Status.ToString()) :
                         source.OrderByDescending(s => s.Status.ToString());
                break;
            }

            return(source);
        }
Exemplo n.º 30
0
        public ActionResult GetEstimates(Int32 page            = 1, ColumnIndex colIndex  = ColumnIndex.DATE,
                                         Boolean asc           = false, Int32?userId      = null,
                                         EstimateType?estimate = null, String articleName = null,
                                         DateTime?dateStart    = null, DateTime?dateEnd   = null)
        {
            var curUser = GetUserInfo();
            IQueryable <UserEstimate> data = dbContext.UserEstimate.Where(c => (userId == null || c.AuthorId == userId))
                                             .Where(e => e.Article.Status == ArticleStatus.APPROVED);

            if (dateStart != null)
            {
                var filter = dateStart.Value.Date;
                data = data.Where(c => c.InsertDate > filter);
            }

            if (dateEnd != null)
            {
                var filter = dateEnd.Value.Date.AddDays(1);
                data = data.Where(c => c.InsertDate < filter);
            }

            if (estimate != null)
            {
                data = data.Where(c => c.Estimate == estimate);
            }

            if (articleName != null)
            {
                data = data.Where(c => c.Article.Name.IndexOf(articleName, NO_CASE_COMPARISON) != -1);
            }

            Int32 dataCount = data.Count();
            var   ests      = OrderEstimates(data, colIndex, asc)
                              .Skip((page - 1) * PAGE_LENGTH).Take(PAGE_LENGTH).ToArray();

            return(Ok(new
            {
                data = ests,
                dataCount = dataCount,
                articleNames = ests.Select(c => c.Article).Distinct().ToDictionary(k => k.Id, v => v.Name),
                userNames = ests.Select(c => c.Author).Distinct().ToDictionary(k => k.Id, v => v.Login),
                pageLength = PAGE_LENGTH
            }));
        }
Exemplo n.º 31
0
        /// <summary>
        /// 格式化
        /// </summary>
        /// <param name="column"></param>
        /// <param name="columnIndex"></param>
        /// <param name="row"></param>
        /// <param name="columnIndices"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        private static object Format(Column column, ColumnIndex columnIndex, IRow row, IEnumerable <ColumnIndex> columnIndices,
                                     IEnumerable <Column> columns)
        {
            //额外列
            if (!column.Intrinsic)
            {
                return(Format(column, row, columns, columnIndices));
            }
            //读取原始单元格值
            var cellValue = GetCellValue(row.GetCell(columnIndex.Index), column.ResultType);

            //如果定义为预读取, 则优先读取缓存
            if (column.PreRead)
            {
                return(ReadCache(column, row, columnIndices, columns, cellValue));
            }
            //返回格式化后的值
            return(Format(column, row, columnIndices, columns, cellValue));
        }
 private void SetSubItemText(ThreadWatcher watcher, ColumnIndex columnIndex, string text)
 {
     ListViewItem item = ((WatcherExtraData)watcher.Tag).ListViewItem;
     var subItem = item.SubItems[(int)columnIndex];
     if (subItem.Text != text) {
         subItem.Text = text;
     }
 }
Exemplo n.º 33
0
		/// <summary>
		/// Gets the column name for the given index.
		/// </summary>
		/// <param name="column"> A <see cref="ColumnIndex"/>. </param>
		/// <returns> The column's name. </returns>
		public string GetColumnName(ColumnIndex column)
		{
			return dataSet.GetColumnName(this[column]);
		}
 private void SetSubItemText(ThreadWatcher watcher, ColumnIndex columnIndex, string text)
 {
     ListViewItem item = ((WatcherExtraData)watcher.Tag).ListViewItem;
     var subItem = item.SubItems[(int)columnIndex];
     if (subItem.Text != text) {
         subItem.Text = text;
         if (!_isLoadingThreadsFromFile) lvThreads.Sort();
     }
 }
Exemplo n.º 35
0
		/// <summary>
		/// Access the indices by column name.
		/// </summary>
		public int this[ColumnIndex column]
		{
			get	{return columns[(int)column];}
			set
			{
				columns[(int)column] = value;
				MakeDirty();
			}
		}