Esempio n. 1
0
        public override void SetParameter(EventBase even)
        {
            DataListRefreshDev _event = even as DataListRefreshDev;
            DataListRefreshDevEditorAdapter adapter = this.HostAdapter as DataListRefreshDevEditorAdapter;
            string     dataEntityId = adapter.ParameterPanels.General.DataEntityId;
            DataEntity dataEntity   = _dataEntityComponentService.GetDataEntity(dataEntityId);

            this._wheres = new BindingList <DataListRefreshEvent.WhereItem>(_event.Where);
            this._warningTable.Clear();
            bool warningRow;

            foreach (DataListRefreshEvent.WhereItem where in _event.Where)
            {
                warningRow = false;
                DataItemEntity dataItemEntityDev = dataEntity.Items.GetEntityById(where.DataItem);
                if (dataItemEntityDev == null)
                {
                    where.DataItemName = String.Empty;
                    warningRow         = true;
                }
                else
                {
                    where.DataItemName = dataItemEntityDev.Name;
                }
                where.SourceName =
                    StringParserLogic.DataSourceVisibleString(this.HostAdapter.HostFormEntity, where.Source.ToString(), out warningRow);
                this._warningTable.Add(where, warningRow);
            }
            this.dataGridViewWhere.DataSource = this._wheres;
        }
Esempio n. 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DataListRefreshDevEditorAdapter adapter = this.HostAdapter as DataListRefreshDevEditorAdapter;

            using (FormEventDataItemDataSet formEventDataItemDataSet =
                       new FormEventDataItemDataSet(this.HostAdapter.HostFormEntity))
            {
                formEventDataItemDataSet.DataEntityId                = adapter.ParameterPanels.General.DataEntityId;
                formEventDataItemDataSet.AllowDataSourceType         = DataListRefreshDev.AllowWhereSetDataSourceType;
                formEventDataItemDataSet.AllowFormElementControlType = DataListRefreshDev.AllowWhereSetFormElementControlType;
                if (formEventDataItemDataSet.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                DataListRefreshEvent.WhereItem where = new DataListRefreshEvent.WhereItem()
                {
                    DataItem     = formEventDataItemDataSet.SelectedDataItemId,
                    DataItemName = formEventDataItemDataSet.SelectedDataItemName,
                    Source       = new DataSource(formEventDataItemDataSet.SelectedDataSourceString),
                    SourceName   = formEventDataItemDataSet.SelectedDataSourceVisibleString,
                    MatchType    = EnumMatchType.Equal
                };
                this._wheres.Add(where);
            }
        }
        private void btnGetSqlRegex_Click(object sender, EventArgs e)
        {
            DataListRefreshDevEditorAdapter adapter = this.HostAdapter as DataListRefreshDevEditorAdapter;

            this.txtSqlRegex.Text = String.Empty;
            string dataEntityId = adapter.ParameterPanels.General.DataEntityId;

            if (dataEntityId == String.Empty || dataEntityId == null)
            {
                return;
            }
            UIElementDataListEntity dataListEntity =
                this.HostAdapter.HostFormEntity.Elements.GetFormElementById(
                    adapter.ParameterPanels.General.DataListId) as UIElementDataListEntity;

            if (dataListEntity == null)
            {
                return;
            }
            string sqlRegex = String.Empty;

            sqlRegex +=
                @"SELECT Count(Id) FROM {Table};
SELECT {Field} FROM {Table} WHERE 1=1 {Where};
WITH tableOrder AS
(
    SELECT Id,{Field},
    ROW_NUMBER() OVER (order by Id) AS RowNumber
    FROM {Table} WHERE 1=1 {Where}
) 
SELECT *
FROM tableOrder
WHERE RowNumber BETWEEN @rowNumberStart AND @rowNumberEnd
ORDER BY Id;
";
            DataEntity dataEntity = _dataEntityComponentService.GetDataEntity(dataEntityId);
            string     tableName  = dataEntity.Code;

            sqlRegex = sqlRegex.Replace("{Table}", "[" + tableName + "]");
            foreach (UIElementDataListTextBoxColumnEntity column in dataListEntity.DataColumns)
            {
                sqlRegex = sqlRegex.Replace("{Field}", "[" + column.GetDataItemCode() + "],{Field}");
            }
            sqlRegex = sqlRegex.Replace(",{Field}", "");
            if (adapter.ParameterPanels.Where.Wheres == null || adapter.ParameterPanels.Where.Wheres.Count == 0)
            {
                sqlRegex = sqlRegex.Replace("{Where}", String.Empty);
                this.txtSqlRegex.SetContent(sqlRegex.Replace("WHERE 1=1", String.Empty));
                return;
            }
            sqlRegex += Environment.NewLine;
            string strWhere     = String.Empty;
            string dataItemName = String.Empty;
            string valueName    = String.Empty;

            foreach (DataListRefreshEvent.WhereItem whereItem in adapter.ParameterPanels.Where.Wheres)
            {
                DataItemEntity item = dataEntity.Items.GetEntityById(whereItem.DataItem);
                Debug.Assert(item != null, "没有找到指定的数据项实体");
                dataItemName = item.Code;
                if (whereItem.Source.ToString().Split('.')[0] == "FormElement")
                {
                    valueName = "{FormElement." +
                                this.HostAdapter.HostFormEntity.FindFormElementById(whereItem.Source.ToString().Split('.')[1]).Code + "}";
                }
                else
                {
                    valueName = "{System." +
                                ((EnumSystemDataSource)Convert.ToInt32(whereItem.Source.ToString().Split('.')[1])).ToString() + "}";
                }
                strWhere += " AND " +
                            CommonOperater.CombineFieldAndValue(dataItemName, valueName, whereItem.MatchType);
            }
            sqlRegex = sqlRegex.Replace("{Where}", strWhere);
            this.txtSqlRegex.SetContent(sqlRegex.Replace("1=1" + Environment.NewLine + Environment.NewLine + " AND ",
                                                         Environment.NewLine));
        }