Пример #1
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);

            if (dataColumn != null)
            {
                dataTable.Columns.Remove(dataColumn);
            }
            else if (columnName == null || columnName == "")
            {
                dataTable.Columns.RemoveAt(columnIndex);
            }
            else
            {
                dataTable.Columns.Remove(columnName);
            }
        }
Пример #2
0
        protected override void Execute(CodeActivityContext context)
        {
            DataTable  dataTable         = DataTable.Get(context);
            string     lookupValue       = LookupValue.Get(context);
            DataColumn dataColumn        = DataColumn.Get(context);
            DataColumn targetDataColumn  = TargetDataColumn.Get(context);
            Int32      columnIndex       = ColumnIndex.Get(context);
            Int32      targetColumnIndex = ColumnIndex.Get(context);
            string     columnName        = ColumnName.Get(context);
            string     targetColumnName  = TargetColumnName.Get(context);

            object cellValue = null;
            Int32  rowIndex  = 0;

            try
            {
                int beginIndex = 0, endInex = 0;

                DataColumn beginColumn = new DataColumn();
                if (dataColumn != null)
                {
                    beginIndex = dataTable.Columns.IndexOf(dataColumn);
                }
                else if (columnName != null && columnName != "")
                {
                    beginIndex = dataTable.Columns.IndexOf(columnName);
                }
                else
                {
                    beginIndex = columnIndex;
                }
                if (targetDataColumn != null)
                {
                    endInex = dataTable.Columns.IndexOf(targetDataColumn);
                }
                else if (targetColumnName != null && targetColumnName != "")
                {
                    endInex = dataTable.Columns.IndexOf(targetColumnName);
                }
                else
                {
                    endInex = targetColumnIndex;
                }

                if (beginIndex < 0 || endInex < 0 || beginIndex > endInex)
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "数据表列索引有误,请检查开始列与结束列");
                    return;
                }

                DataRowCollection dataRows = dataTable.Rows;
                for (int index = beginIndex; index < endInex; index++)
                {
                    foreach (DataRow datarow in dataRows)
                    {
                        object data    = datarow[index];
                        string dataStr = data as string;
                        if (dataStr.Equals(lookupValue))
                        {
                            rowIndex  = dataRows.IndexOf(datarow);
                            cellValue = data;
                            break;
                        }
                    }
                }
                if (CellValue != null)
                {
                    CellValue.Set(context, cellValue);
                }
                if (RowIndex != null)
                {
                    RowIndex.Set(context, rowIndex);
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "查找数据表失败", e.Message);
            }
        }