Ejemplo n.º 1
0
        private object GetDefaultValue(InputItem ii)
        {
            if (string.IsNullOrEmpty(ii.DefaultValue))
            {
                return(null);
            }

            if (ii.DefaultValue.IndexOf("[") < 0 && ii.DefaultValue.IndexOf("]") < 0)
            {
                return(ii.DefaultValue);
            }

            if (ii.DefaultValue.IndexOf("[SQL:") >= 0)
            {
                //sql语句处理
                IDBQuery thridDbHelper = _dbHelper;

                if (string.IsNullOrEmpty(ii.DBAlias) == false)
                {
                    string strErr = "";
                    thridDbHelper = SqlHelper.GetThridDBHelper(ii.DBAlias, _dbHelper, ref strErr);
                    if (thridDbHelper == null)
                    {
                        MessageBox.Show("录入项 [" + ii.Name + "] 对应的数据源不能创建。", "提示");
                        return(null);
                    }
                }

                if (thridDbHelper != null)
                {
                    string    sql      = "Select (" + ii.DefaultValue.Replace("[SQL:", "").Replace("]", "") + ") as Result from dual";
                    DataTable dtResult = thridDbHelper.ExecuteSQL(sql);

                    if (dtResult == null || dtResult.Rows.Count <= 0)
                    {
                        return(null);
                    }

                    return(dtResult.Rows[0]["Result"]);
                }
                else
                {
                    MessageBox.Show("尚未初始化数据查询对象。", "提示");
                    return(null);
                }
            }
            else if (ii.DefaultValue.IndexOf("[CS:") >= 0)
            {
                //csharp代码处理
                return(null);
            }
            else
            {
                return(ii.DefaultValue);
            }
        }
Ejemplo n.º 2
0
 public void CopyFrom(InputItem liSource)
 {
     Name           = liSource.Name;
     ControlType    = liSource.ControlType;
     DefaultValue   = liSource.DefaultValue;
     DBAlias        = liSource.DBAlias;
     DataFrom       = liSource.DataFrom;
     ExtPro         = liSource.ExtPro;
     IsWhereReplace = liSource.IsWhereReplace;
     LinkControl    = liSource.LinkControl;
     Tag            = liSource.Tag;
     Parent         = liSource.Parent;
     StartIndex     = liSource.StartIndex;
 }
Ejemplo n.º 3
0
        private void butSure_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateData() == false)
                {
                    return;
                }

                WhereItem result = new WhereItem();

                result.Name      = txtWhereItemName.Text;
                result.LinkType  = cbxLinkType.Text;
                result.Condition = rtbWhereContext.Text;


                foreach (TabPage tc in tabItems.TabPages)
                {
                    InputItem ii = new InputItem();
                    ii.CopyFrom(_wi.InputItems[tc.Name]);

                    if (string.IsNullOrEmpty(ii.ControlType))
                    {
                        ii.ControlType = QueryConstDefine.Txt;
                    }


                    result.AddInputItem(ii, ii.StartIndex);
                }

                result.SourceFmt = result.SaveWhereToString();

                _wi = result;

                _isOk = true;

                this.Close();
            }
            catch (Exception ex)
            {
                MsgBox.ShowException(ex, this);
            }
        }
Ejemplo n.º 4
0
        public void CopyFrom(WhereItem wi)
        {
            Name       = wi.Name;
            LinkType   = wi.LinkType;
            Condition  = wi.Condition;
            Tag        = wi.Tag;
            SourceFmt  = wi.SourceFmt;
            StartIndex = wi.StartIndex;

            InputItems.Clear();

            foreach (InputItem ii in wi.InputItems.Values)
            {
                InputItem curNew = new InputItem();
                curNew.CopyFrom(ii);

                InputItems.Add(ii.Name, curNew);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取链接控件的值
        /// </summary>
        /// <param name="ii"></param>
        /// <returns></returns>
        private object GetLinkContrlValue(InputItem ii)
        {
            switch (ii.ControlType)
            {
            case QueryConstDefine.Txt:
                string textvalue = (ii.LinkControl as TextBox).Text;
                if (string.IsNullOrEmpty(textvalue))
                {
                    return(null);
                }


                return(textvalue.Split('-')[0]);

            case QueryConstDefine.Cbx:
                string cbxvalue = "";

                object value = (ii.LinkControl as ComboBox).SelectedValue;
                if (value != null && value is string)
                {
                    cbxvalue = value.ToString();
                }

                if (string.IsNullOrEmpty(cbxvalue))
                {
                    cbxvalue = (ii.LinkControl as ComboBox).Text;
                }

                if (string.IsNullOrEmpty(cbxvalue))
                {
                    return(null);
                }

                return(cbxvalue.Split('-')[0]);

            case QueryConstDefine.Dtp:
                return((ii.LinkControl as DateTimePicker).Value);

            default:
                return(null);
            }
        }
Ejemplo n.º 6
0
        private void tabItems_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (_isCondationChange)
                {
                    return;
                }

                _isTabChanging = true;

                ClearQueryTag();

                if (_wi.InputItems.ContainsKey(tabItems.SelectedTab.Name) == false)
                {
                    return;
                }

                InputItem qt = _wi.InputItems[tabItems.SelectedTab.Name];

                cbxControlType.Text  = qt.ControlType;
                rtbDataFrom.Text     = qt.DataFrom;
                txtExtPros.Text      = qt.ExtPro;
                txtDefaultValue.Text = qt.DefaultValue;

                chkReplace.Checked = qt.IsWhereReplace;
            }
            catch (Exception ex)
            {
                MsgBox.ShowException(ex, this);
            }
            finally
            {
                _isTabChanging = false;
            }
        }
Ejemplo n.º 7
0
        //private void OnKeyPress(object sender, KeyPressEventArgs e)
        //{
        //    if (e.KeyChar == (char)Keys.Enter)
        //    {
        //        SendKeys.Send("{tab}");
        //    }
        //}

        public Control AddInputControl(InputItem ii, string controlName)
        {
            LayoutControlItem lci = null;

            string ctlName      = controlName;
            object defaultValue = GetDefaultValue(ii);



            switch (ii.ControlType.ToUpper())
            {
            case QueryConstDefine.Cbx:
                ComboBox cbx = new ComboBox();
                cbx.Name = ctlName;

                //cbx.KeyPress += OnKeyPress;

                //从数据源加载数据
                DataTable dtData = GetDataForm(ii);
                if (dtData != null)
                {
                    if (dtData.Columns.Count > 1)
                    {
                        if (dtData.Columns.IndexOf("数据值") >= 0)
                        {
                            cbx.ValueMember = "数据值";
                        }
                        else
                        {
                            cbx.ValueMember = dtData.Columns[0].ColumnName;
                        }

                        if (dtData.Columns.IndexOf("数据描述") >= 0)
                        {
                            cbx.DisplayMember = "数据描述";
                        }
                        else
                        {
                            cbx.ValueMember = dtData.Columns[1].ColumnName;
                        }
                    }
                    else
                    {
                        cbx.DisplayMember = dtData.Columns[0].ColumnName;
                        cbx.ValueMember   = dtData.Columns[0].ColumnName;
                    }

                    cbx.DataSource = dtData;
                }

                lci = lcDemo.Root.AddItem(ctlName, cbx);
                lci.ShowInCustomizationForm = false;
                lci.Text = ii.Name;


                if (defaultValue != null)
                {
                    //设置默认值
                    int selIndex = cbx.Items.IndexOf(defaultValue);
                    if (selIndex < 0)
                    {
                        selIndex = cbx.FindString(Convert.ToString(defaultValue));
                    }

                    if (selIndex >= 0)
                    {
                        cbx.SelectedIndex = selIndex;
                    }
                    else
                    {
                        cbx.Text = ii.DefaultValue;
                    }
                }
                else
                {
                    cbx.SelectedIndex = cbx.Items.Count - 1;
                }


                return(cbx);

            case QueryConstDefine.Txt:
                TextBox tb = new TextBox();
                tb.Name = ctlName;
                tb.Text = Convert.ToString(defaultValue);    //设置默认值

                //tb.KeyPress += OnKeyPress;

                lci = lcDemo.Root.AddItem(ctlName, tb);
                lci.ShowInCustomizationForm = false;
                lci.Text = ii.Name;

                return(tb);

            case QueryConstDefine.Dtp:
                DateTimePicker dtp = new DateTimePicker();
                dtp.Name = ctlName;

                //dtp.KeyPress += OnKeyPress;

                try
                {
                    if (defaultValue != null)
                    {
                        //设置默认值
                        dtp.Value = Convert.ToDateTime(defaultValue);
                    }
                }
                catch
                { }

                lci = lcDemo.Root.AddItem(ctlName, dtp);
                lci.ShowInCustomizationForm = false;
                lci.Text = ii.Name;

                return(dtp);

            default:
                return(null);
            }
        }
Ejemplo n.º 8
0
        private DataTable GetDataForm(InputItem ii)
        {
            if (string.IsNullOrEmpty(ii.DataFrom))
            {
                return(null);
            }

            string datafrom = ii.DataFrom;

            //判断是否查询语句
            if (datafrom.ToUpper().IndexOf("SELECT ") >= 0)
            {
                //查询语句处理
                QueryCore qc = new QueryCore();

                qc.OnRequestSystemPar += RequestSystemPar;

                qc.LoadFromString(ii.DataFrom);

                string sql = "";
                Dictionary <string, object> dataPars = new Dictionary <string, object>();
                qc.CreateQuerySql(out sql, out dataPars);

                if (string.IsNullOrEmpty(sql))
                {
                    MessageBox.Show("录入项 [" + ii.Name + "] 对应的数据来源无效。", "提示");
                    return(null);
                }

                IDBQuery thridDbHelper = _dbHelper;

                if (string.IsNullOrEmpty(ii.DBAlias) == false)
                {
                    string strErr = "";
                    thridDbHelper = SqlHelper.GetThridDBHelper(ii.DBAlias, _dbHelper, ref strErr);
                    if (thridDbHelper == null)
                    {
                        MessageBox.Show("录入项 [" + ii.Name + "] 对应的数据源不能创建。", "提示");
                        return(null);
                    }
                }

                if (thridDbHelper != null)
                {
                    DataTable dtResult = thridDbHelper.ExecuteSQL(sql, dataPars);

                    DataRow drNull = dtResult.NewRow();
                    dtResult.Rows.Add(drNull);

                    return(dtResult);
                }
                else
                {
                    MessageBox.Show("尚未初始化数据查询对象。", "提示");
                    return(null);
                }
            }
            else
            {
                //字符串处理
                string[] aryDatas = (datafrom + ";").Split(';');

                DataTable dtData = new DataTable();

                dtData.Columns.Add("数据值", typeof(string));
                dtData.Columns.Add("数据描述", typeof(string));

                foreach (string dataItem in aryDatas)
                {
                    if (string.IsNullOrEmpty(dataItem))
                    {
                        continue;
                    }

                    DataRow dr = dtData.NewRow();

                    string[] parseData = (dataItem + "-" + dataItem).Split('-');
                    dr["数据值"]  = parseData[0];
                    dr["数据描述"] = parseData[1];

                    dtData.Rows.Add(dr);
                }

                DataRow drNull = dtData.NewRow();
                dtData.Rows.Add(drNull);

                return(dtData);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 同步关联控件
        /// </summary>
        public void SyncLinkControl()
        {
            if (LinkControl == null)
            {
                return;
            }

            LinkControl.BeginLayout();
            try
            {
                //清理不存在的控件
                for (int i = LinkControl.Items.Count - 1; i >= 0; i--)
                {
                    Control ctl = LinkControl.Items[i];
                    if (ctl.Name.Contains(CONST_USER_CONTROL_TAG) == false)
                    {
                        continue;
                    }

                    string ctlName = ctl.Name.Replace(CONST_USER_CONTROL_TAG, "");

                    InputItem ii = FindInput(ctlName);

                    if (ii == null)
                    {
                        LinkControl.RemoveControl(ctl.Name);
                    }
                    else
                    {
                        ii.LinkControl = ctl;
                    }
                }

                //新增录入控件
                foreach (WhereItem wi in _whereItems.Values)
                {
                    foreach (InputItem ii in wi.InputItems.Values)
                    {
                        //非系统参数控件创建
                        if (ii.LinkControl == null && ii.Name.Contains(QueryConstDefine.SystemTag) == false)
                        {
                            //判断控件是否存在
                            Control ctlInput = LinkControl.FindControl(CONST_USER_CONTROL_TAG + ii.Name);

                            if (ctlInput != null)
                            {
                                ii.LinkControl = ctlInput;
                                continue;
                            }

                            ctlInput       = LinkControl.AddInputControl(ii, CONST_USER_CONTROL_TAG + ii.Name);
                            ii.LinkControl = ctlInput;
                        }
                    }
                }
            }
            finally
            {
                LinkControl.EndLayout();
            }
        }
Ejemplo n.º 10
0
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                //tabItems.TabPages.Clear();
                if (_isTabChanging)
                {
                    return;
                }

                _isCondationChange = true;


                string     source = rtbWhereContext.Text;
                MatchInfos inputs = QueryHelper.GetMinMatchData(source, "[", "]");

                for (int i = _wi.InputItems.Values.Count - 1; i >= 0; i--)
                {
                    InputItem iiDel = _wi.InputItems.Values.ElementAt(i);
                    if (source.IndexOf("[" + iiDel.Name + "]") < 0)
                    {
                        _wi.InputItems.Remove(iiDel.Name);
                    }
                }

                //删除不存在的tab
                for (int i = tabItems.TabPages.Count - 1; i >= 0; i--)
                {
                    if (inputs.Contains(tabItems.TabPages[i].Name) == false)
                    {
                        tabItems.TabPages.RemoveAt(i);
                    }
                }



                InputControlEnable(true);


                foreach (MatchInfo input in inputs)
                {
                    if (string.IsNullOrEmpty(input.MatchContext))
                    {
                        continue;
                    }

                    if (tabItems.TabPages.IndexOfKey(input.MatchContext) >= 0)
                    {
                        continue;
                    }

                    if (input.MatchContext.IndexOf("系统_") >= 0)
                    {
                        continue;
                    }

                    tabItems.TabPages.Add(input.MatchContext, input.MatchContext);

                    if (_wi.InputItems.ContainsKey(input.MatchContext) == false)
                    {
                        InputItem curInput = new InputItem();
                        curInput.Name = input.MatchContext;

                        _wi.AddInputItem(curInput, input.StartIndex);
                    }
                }



                if (tabItems.TabPages.Count > 0)
                {
                    tabItems.SelectedIndex = 0;
                }
                else
                {
                    //清除数据
                    cbxControlType.SelectedIndex = 0;
                    rtbDataFrom.Text             = "";
                    txtExtPros.Text      = "";
                    txtDefaultValue.Text = "";
                    chkReplace.Checked   = false;
                }

                InputControlEnable((tabItems.TabPages.Count <= 0) ? false : true);

                rtbWhereContext.Focus();
            }
            catch (Exception ex)
            {
                MsgBox.ShowException(ex, this);
            }
            finally
            {
                _isCondationChange = false;
            }
        }
Ejemplo n.º 11
0
        public void LoadWhereFromString(string whereitem)
        {
            if (string.IsNullOrEmpty(whereitem))
            {
                return;
            }

            SourceFmt = whereitem;

            string tmp = whereitem;

            int indexStart = tmp.IndexOf("<wi=");

            if (indexStart < 0)
            {
                return;
            }

            indexStart = indexStart + 4;
            int indexEnd = tmp.IndexOf(":", indexStart + 1);

            Name = tmp.Substring(indexStart, indexEnd - indexStart);

            tmp = tmp.Substring(indexEnd + 1);

            indexStart = tmp.IndexOf(@"连接类型=""");
            if (indexStart < 0)
            {
                LinkType = "";
                indexEnd = -1;
            }
            else
            {
                indexStart = indexStart + 5;
                indexEnd   = tmp.IndexOf(",", indexStart + 1);

                LinkType = tmp.Substring(indexStart, indexEnd - indexStart).Replace(@"""", "");
            }

            tmp = tmp.Substring(indexEnd + 1).Replace("/wi>", "");

            string curCondation = tmp;

            //配置录入项
            MatchInfos inputs = QueryHelper.GetMinMatchData(tmp, "[", "]", '"', '"');

            foreach (MatchInfo input in inputs)
            {
                string[] pros = input.MatchContext.Split(',');

                InputItem ii = new InputItem();
                ii.Name = pros[0];

                curCondation = curCondation.Replace(input.MatchContext, ii.Name);

                ii.ControlType    = FindPro(pros, "类型", "文本框");
                ii.DBAlias        = FindPro(pros, "数据源");
                ii.DataFrom       = FindPro(pros, "数据来源");
                ii.ExtPro         = FindPro(pros, "扩展属性");
                ii.DefaultValue   = FindPro(pros, "默认值");
                ii.IsWhereReplace = (FindPro(pros, "条件替换") == "1" ? true : false);
                //ii.StartIndex = input.StartIndex;

                ii.Parent = this;

                InputItems.Add(ii.Name, ii, input.StartIndex);
            }

            Condition = curCondation;
        }
Ejemplo n.º 12
0
        public void AddInputItem(InputItem ii, int startIndex)
        {
            ii.Parent = this;

            InputItems.Add(ii.Name, ii, startIndex);
        }