private void RadioCheckedChanged(object sender, EventArgs e)
        {
            LoadDataToFormDevEditorAdapter adapter = this.HostAdapter as LoadDataToFormDevEditorAdapter;

            adapter.ParameterPanels.Load.Loads.Clear();
            adapter.ParameterPanels.DataEntity.DataEntityAllowEmpty = !radioButtonDataEntity.Checked;
        }
示例#2
0
        private void btnGetSqlRegex_Click(object sender, EventArgs e)
        {
            LoadDataToFormDevEditorAdapter adapter = this.HostAdapter as LoadDataToFormDevEditorAdapter;

            this.txtSqlRegex.Text = String.Empty;
            if (adapter.ParameterPanels.DataEntity.DataEntityId == String.Empty)
            {
                return;
            }
            string                dataEntityId = adapter.ParameterPanels.DataEntity.DataEntityId;
            DataEntity            dataEntity   = _dataEntityComponentService.GetDataEntity(dataEntityId);
            List <DataItemEntity> dataItems    = dataEntity.Items.ToList();
            string                sqlRegex     = "SELECT {Field} FROM {Table} WHERE 1=1";
            string                tableName    = dataEntity.Code;

            sqlRegex = sqlRegex.Replace("{Table}", "[" + tableName + "]");
            string dataItemName;

            foreach (LoadDataToFormDev.LoadItem load in adapter.ParameterPanels.Load.Loads)
            {
                List <DataItemEntity> items =
                    (from c in dataItems where c.Id.Equals(load.DataItem) select c).ToList();
                Debug.Assert(items.Count == 1, "没有找到指定的数据项实体");
                dataItemName = items[0].Code;
                sqlRegex     = sqlRegex.Replace("{Field}", "[" + dataItemName + "],{Field}");
            }
            sqlRegex = sqlRegex.Replace(",{Field}", "");
            sqlRegex = sqlRegex.Replace("{Field}", "*");
            if (adapter.ParameterPanels.DataEntity.Wheres.Count == 0)
            {
                this.txtSqlRegex.SetContent(sqlRegex.Replace("WHERE 1=1", String.Empty));
                return;
            }
            sqlRegex += Environment.NewLine;
            string valueName = String.Empty;

            foreach (LoadDataToFormEvent.WhereItem whereItem in adapter.ParameterPanels.DataEntity.Wheres)
            {
                List <DataItemEntity> items =
                    (from c in dataItems where c.Id.Equals(whereItem.DataItem) select c).ToList();
                Debug.Assert(items.Count == 1, "没有找到指定的数据项实体");
                dataItemName = items[0].Code;
                if (whereItem.Source.Type == EnumEventDataSource.FormElement)
                {
                    valueName = "{FormElement." +
                                this.HostAdapter.HostFormEntity.FindFormElementById(whereItem.Source.Source).Code + "}";
                }
                else
                {
                    valueName = "{System." +
                                ((EnumSystemDataSource)Convert.ToInt32(whereItem.Source.Source)).ToString() + "}";
                }
                sqlRegex += Environment.NewLine + " AND " + CommonOperater.CombineFieldAndValue(
                    dataItemName, valueName, whereItem.MatchType);
            }
            this.txtSqlRegex.SetContent(sqlRegex.Replace("1=1" + Environment.NewLine + Environment.NewLine + " AND ",
                                                         Environment.NewLine));
        }
        /// <summary>
        /// 自动填充加载设置,将数据项加载到对应的编辑控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLoadAll_Click(object sender, EventArgs e)
        {
            LoadDataToFormDevEditorAdapter adapter = this.HostAdapter as LoadDataToFormDevEditorAdapter;

            this._loads.Clear();
            this._warningTable.Clear();

            DataEntity dataEntity = _dataEntityComponentService.GetDataEntity(adapter.ParameterPanels.DataEntity.DataEntityId);

            IUIElementEditControl iFormElementEditControl;

            foreach (UIElement formElement in this.HostAdapter.HostFormEntity.Elements)
            {
                iFormElementEditControl = formElement as IUIElementEditControl;
                //没有实现IFormElementEditControl接口,认为不是编辑控件
                if (iFormElementEditControl == null)
                {
                    continue;
                }

                if (String.IsNullOrEmpty(iFormElementEditControl.DataItemId))
                {
                    continue;
                }

                string[] ids          = iFormElementEditControl.DataItemId.Split('.');
                string   dataEntityId = ids[0];
                string   dataItemId   = ids[1];

                if (dataEntityId != dataEntity.Id)
                {
                    continue;
                }

                DataItemEntity dataItemEntity = dataEntity.Items.GetEntityById(dataItemId);
                if (dataItemEntity == null)
                {
                    continue;
                }

                LoadDataToFormEvent.LoadItem load = new LoadDataToFormEvent.LoadItem()
                {
                    DataItem     = dataItemId,
                    DataItemName = dataItemEntity.Name,
                    Source       = new DataSource(StringParserLogic.DataSourceString(formElement)),
                    SourceName   = StringParserLogic.DataSourceVisibleString(formElement)
                };

                this._loads.Add(load);

                this._warningTable.Add(load, false);
            }
        }
        /// <summary>
        /// 添加加载数据设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddLoad_Click(object sender, EventArgs e)
        {
            LoadDataToFormDevEditorAdapter adapter = this.HostAdapter as LoadDataToFormDevEditorAdapter;

            if (adapter.ParameterPanels.General.Mode == LoadDataToFormEvent.EnumLoadDataToFormMode.DataEntity &&
                adapter.ParameterPanels.DataEntity.DataEntityId == String.Empty)
            {
                MessageBox.Show(
                    Language.Current.UserControlEventEditorPanel_LoadDataToForm_Load_MessageChooseDataEntityFirst,
                    CommonLanguage.Current.MessageCaption_Notice,
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            using (FormEventDataItemDataSet formEventDataItemDataSet = new FormEventDataItemDataSet(this.HostAdapter.HostFormEntity))
            {
                formEventDataItemDataSet.DataSourceLabel             = Language.Current.FormEventDataItemDataSet_LabelDataSource_LoadTo;
                formEventDataItemDataSet.AllowDataSourceType         = LoadDataToFormDev.AllowLoadDataDataSourceType;
                formEventDataItemDataSet.AllowFormElementControlType = LoadDataToFormDev.AllowFormElementControlType;

                if (adapter.ParameterPanels.General.Mode == LoadDataToFormEvent.EnumLoadDataToFormMode.DataEntity)
                {
                    formEventDataItemDataSet.DataEntityId = adapter.ParameterPanels.DataEntity.DataEntityId;
                }
                else
                {
                    formEventDataItemDataSet.DataEntityId = null;
                }

                if (formEventDataItemDataSet.ShowDialog() == DialogResult.OK)
                {
                    LoadDataToFormEvent.LoadItem load = new LoadDataToFormEvent.LoadItem()
                    {
                        DataItem     = formEventDataItemDataSet.SelectedDataItemId,
                        DataItemName = formEventDataItemDataSet.SelectedDataItemName,
                        Source       = new DataSource(formEventDataItemDataSet.SelectedDataSourceString),
                        SourceName   = formEventDataItemDataSet.SelectedDataSourceVisibleString
                    };

                    this._loads.Add(load);
                }
            }
        }