Exemplo n.º 1
0
 public IFilter <P> WithSearchFields(params string[] fields)
 {
     foreach (var f in fields)
     {
         if (!SearchFields.Contains(f))
         {
             SearchFields.Add(f);
         }
     }
     return(this);
 }
Exemplo n.º 2
0
        //动态产生用户操作界面
        public void Generate_Controls(bool isSearch = false)
        {
            // top of textboxes
            int current_top  = 10;
            int current_left = 80;

            int currentsearch_top  = 20;
            int currentsearch_left = 10;

            // index used to match between each textbox and the properate column in grid
            int my_index = 14;

            int mysearch_index = 4;

            // iterate the grid and create textbox for each column
            int y = 0;

            _allValidator.Clear();
            foreach (DataGridViewColumn col in dataGridView1.Columns)
            {
                if (FilterGenerateControl(col))
                {
                    continue;
                }

                // generate textboxes only for visible columns

                if (isSearch || col.Visible == true)
                {
                    my_index++;
                    // increase the top each time for space between textboxes
                    current_top += 30;

                    //// create a second column of textboxes (not all of them in 1 long column)
                    if (my_index % 14 == 0)
                    {
                        current_top = 40; current_left += 350;
                    }
                    Control c;
                    switch (col.ValueType.ToString())
                    {
                    case "System.String":
                        c = new CoolTextBox();
                        if (col.Name == "Pwd")
                        {
                            var cc = c as CoolTextBox;
                            cc.IsPwd = true;
                        }
                        if (_InitFieldValues.ContainsKey("Rareword"))
                        {
                            foreach (ListItem r in _InitFieldValues["Rareword"])
                            {
                                ((CoolTextBox)c).Items.Add(new AutoCompleteEntry(r.Name, r.ID));
                            }
                        }
                        break;

                    case "System.Boolean":
                        c = new CheckBox();
                        if (col.Name == "Enabled")
                        {
                            ((CheckBox)c).Checked = true;
                        }
                        //WFZ
                        if (col.Name == "Year_exam")
                        {
                            ((CheckBox)c).Checked = true;
                        }
                        if (col.Name == "Pro_work_exam")
                        {
                            ((CheckBox)c).Checked = true;
                        }
                        break;

                    case "System.DateTime":
                    case "System.Nullable`1[System.DateTime]":
                        c = new DateTimePicker();
                        break;

                    case "System.Guid":
                        c = new ComboBox();
                        break;

                    default:
                        c = new CoolTextBox();
                        if (_InitFieldValues.ContainsKey("Rareword"))
                        {
                            foreach (ListItem r in _InitFieldValues["Rareword"])
                            {
                                ((CoolTextBox)c).Items.Add(new AutoCompleteEntry(r.Name, r.ID));
                            }
                        }
                        //if (col.Name == "SalesManageFee" || col.Name == "PurchaseTaxReturn")
                        //{
                        //    (CoolTextBox)c.item = "0";
                        //}
                        break;
                    }

                    switch (col.Name)
                    {
                    case "Description":
                    case "Decription":
                        c = new RichTextBox();
                        ((RichTextBox)c).Height = 80;
                        c.Top        = current_top;
                        current_top += 80;
                        break;

                    default:
                        c.Top = current_top;
                        break;
                    }
                    if (_InitFieldValues.ContainsKey(col.Name))
                    {
                        c     = new ComboBox();
                        c.Top = current_top;
                    }
                    RichTextBox l = new RichTextBox();
                    l.ReadOnly  = true;
                    l.Multiline = false;
                    l.Height    = 12;

                    l.ScrollBars  = RichTextBoxScrollBars.None;
                    l.BorderStyle = BorderStyle.None;
                    l.Text        = col.HeaderCell.Value.ToString() + ":";
                    l.Top         = current_top;
                    l.Left        = current_left;

                    if (GridDataSourceType == DataSoruceType.SupplyUnit)
                    {
                        l.Width = 150;
                        c.Width = 130;
                    }
                    else
                    {
                        l.Width = 100;
                        c.Width = 180;
                    }

                    c.Left = current_left + l.Width;

                    c.Name = col.Name;


                    if (isSearch)
                    {
                        l.BackColor = Color.AliceBlue;
                        if (SearchFields.Contains(col.Name))
                        {
                            mysearch_index++;
                            if (mysearch_index % 4 == 0)
                            {
                                currentsearch_top += 30; currentsearch_left = 10;
                            }
                            l.Top   = currentsearch_top;
                            l.Left  = currentsearch_left;
                            l.Width = 60;
                            switch (col.Name)
                            {
                            case "Enabled":
                                c = new ComboBox();
                                break;
                            }
                            c.Name = _SEARCHPREFIX + col.Name;
                            c.Left = currentsearch_left + l.Width;
                            c.Top  = currentsearch_top;
                            if (GridDataSourceType == DataSoruceType.UserLog)
                            {
                                c.Width = 280;
                            }
                            else
                            {
                                c.Width = 180;
                            }

                            InitControlOptions(c, true);
                            if (!(c is CheckBox))
                            {
                                this.bugsBoxFocusColorProvider1.SetFocusBackColor(c, System.Drawing.Color.MediumBlue);
                                this.bugsBoxFocusColorProvider1.SetFocusForeColor(c, System.Drawing.Color.White);
                            }
                            searchGroupBox.Controls.Add(l);
                            searchGroupBox.Controls.Add(c);
                            currentsearch_left += l.Width + c.Width + 10;
                        }
                    }
                    else
                    {
                        c.TabIndex  = 0;
                        l.TabIndex  = 1;
                        l.BackColor = Color.White;
                        //处理验证
                        HandelValidation(l, c, col.HeaderCell.Value.ToString());
                        InitControlOptions(c);
                        if (!(c is CheckBox))
                        {
                            this.bugsBoxFocusColorProvider1.SetFocusBackColor(c, System.Drawing.Color.MediumBlue);
                            this.bugsBoxFocusColorProvider1.SetFocusForeColor(c, System.Drawing.Color.White);
                        }
                        tabPageEdit.Controls.Add(l);
                        tabPageEdit.Controls.Add(c);
                        y++;
                    }
                }
            }

            //修改自己密码

            if (GridDataSourceType == DataSoruceType.User && listRU == null)
            {
                foreach (Control c in _tabPageEdit.Controls)
                {
                    if (!(c is CoolTextBox || c is RichTextBox))
                    {
                        c.Enabled = false;
                    }
                }
            }

            //add按钮
            if (GridDataSourceType == DataSoruceType.User)
            {
                //    //btnEdu.Text = "参加培训情况";
                //    //btnPhyExam.Text = "参加体检情况";
                //    btnPhyExam.Width = 120;
                //    btnEdu.Width = 120;
                //    System.Drawing.Point p = new Point(250, 70 * 13 / 2);//
                //    btnEdu.Location = p;
                //    System.Drawing.Point p2 = new Point(450, 70 * 13 / 2);//
                //    btnPhyExam.Location = p2;
                //    tabPageEdit.Controls.Add(btnEdu);
                //    tabPageEdit.Controls.Add(btnPhyExam);

                //    btnEdu.Click += new System.EventHandler(btnEdu_click);//
                //    //btnPhyExam.Click += new System.EventHandler(btnPhyExam_click);//
            }

            if (isSearch)
            {
                if (GridDataSourceType == DataSoruceType.UserLog)
                {
                    FromToDateTime f = new FromToDateTime();
                    f.Left = 10;
                    f.Top  = 15;
                    searchGroupBox.Controls.Add(f);
                    currentsearch_top += 20;
                }
                searchGroupBox.Height = currentsearch_top + 40;
            }
        }