Beispiel #1
0
        private void tabPage_Search(
            string kw, string modelName, DataFileInfoSelectTop info,
            TabPageCustom page, ListViewModelItem grid,
            Label lbl_PageCurrent, Label lbl_PageTotal, Label lbl_TotalRecord)
        {
            //grid.DataSource = null;

            string predicate = "";

            if (string.IsNullOrEmpty(kw))
            {
                page.SearchRequest = null;
                page.SearchResult  = null;

                page.PageCurrent     = 1;
                lbl_PageCurrent.Text = page.PageCurrent.ToString();
                int countPage = (int)(info.TotalRecord / selectTop) + (info.TotalRecord % selectTop == 0 ? 0 : 1);
                lbl_PageTotal.Text   = countPage.ToString();
                lbl_TotalRecord.Text = "Records: " + info.DataSelectTop.Count.ToString() + " / " + info.TotalRecord.ToString() + " ";
                grid.SetDataBinding(info.Fields, info.DataSelectTop);
            }
            else
            {
                StringBuilder wh_Contain = new StringBuilder();
                for (int k = 0; k < info.Fields.Length; k++)
                {
                    var dp = info.Fields[k];
                    wh_Contain.Append(dp.Name + (dp.Type.Name == "String" ? string.Empty : ".ToString()") + ".Contains(@0) ");
                    if (k < info.Fields.Length - 1)
                    {
                        wh_Contain.Append(" || ");
                    }
                }

                List <object> lp = new List <object>();
                predicate = wh_Contain.ToString();
                lp.Add(kw);

                SearchRequest sr = new SearchRequest(selectTop, 1, predicate, lp.Count == 0 ? null : lp.ToArray());
                SearchResult  rs = db.Search(modelName, sr);

                page.SearchRequest = sr;
                page.SearchResult  = rs;

                if (rs != null)
                {
                    page.PageCurrent     = rs.PageNumber;
                    lbl_PageCurrent.Text = page.PageCurrent.ToString();
                    int countPage = (int)(rs.Total / selectTop) + (rs.Total % selectTop == 0 ? 0 : 1);
                    lbl_PageTotal.Text   = countPage.ToString();
                    lbl_TotalRecord.Text = "Records: " + rs.IDs.Length.ToString() + " / " + info.TotalRecord.ToString() + " ";
                    grid.SetDataBinding(info.Fields, (IList)rs.Message);
                }
            }
        }
Beispiel #2
0
        private void tabPage_Next(
            string modelName, DataFileInfoSelectTop info,
            TabPageCustom page, ListViewModelItem grid,
            Label lbl_PageCurrent, Label lbl_PageTotal, Label lbl_TotalRecord)
        {
            SearchRequest sr = page.SearchRequest;
            SearchResult  rs = page.SearchResult;

            if (sr == null)
            {
                int PageNumber = page.PageCurrent + 1;
                if (PageNumber > int.Parse(lbl_PageTotal.Text))
                {
                    return;
                }

                page.PageCurrent     = PageNumber;
                lbl_PageCurrent.Text = page.PageCurrent.ToString();
                grid.SetDataBinding(info.Fields, db.GetSelectPage(modelName, PageNumber, selectTop));
            }
            else
            {
                sr.PageNumber = sr.PageNumber + 1;
                if (sr.PageNumber > int.Parse(lbl_PageTotal.Text))
                {
                    return;
                }

                rs = db.Search(modelName, sr);

                page.SearchRequest = sr;
                page.SearchResult  = rs;

                if (rs != null)
                {
                    page.PageCurrent     = rs.PageNumber;
                    lbl_PageCurrent.Text = page.PageCurrent.ToString();
                    lbl_TotalRecord.Text = "Records: " + rs.IDs.Length.ToString() + " / " + info.TotalRecord.ToString() + " ";
                    grid.SetDataBinding(info.Fields, (IList)rs.Message);
                }
            }
        }
Beispiel #3
0
        private void tabPage_CreateUI(string modelName)
        {
            var info = db.GetInfoSelectTop(modelName, selectTop);

            if (info == null)
            {
                tab.TabPages.Add(new TabPageCustom());
            }
            else
            {
                TabPageCustom page = new TabPageCustom(info.Fields)
                {
                    BackColor = Color.White,
                };

                #region [ === BOX FILTER === ]

                int hi = (((info.Fields.Length / 3) + (info.Fields.Length % 3 == 0 ? 0 : 1) + 0) * 27);
                if (info.Fields.Length < 4)
                {
                    hi = 27;
                }
                FlowLayoutPanel boi_Filter = new FlowLayoutPanel()
                {
                    Visible = false, Dock = DockStyle.Top, Height = hi, AutoScroll = false, Padding = new Padding(0), BackColor = App.ColorBg
                };
                boi_Filter.FlowDirection = FlowDirection.LeftToRight;
                boi_Filter.MouseDown    += Label_MouseDown;

                for (int k = 1; k <= info.Fields.Length; k++)
                {
                    var dp = info.Fields[k - 1];

                    Label lbl = new Label()
                    {
                        Name = "lbl" + k.ToString(), Text = dp.Name, AutoSize = false, Width = 120, ForeColor = Color.White, TextAlign = ContentAlignment.MiddleRight
                    };
                    ComboBox cbo = new ComboBox()
                    {
                        Name = "cbo" + k.ToString(), Width = 80, BackColor = App.ColorControl, DropDownStyle = ComboBoxStyle.DropDownList
                    };
                    if (dp.Type.Name == "String")
                    {
                        for (int ki = 0; ki < OpString.Length; ki++)
                        {
                            cbo.Items.Add(OpString[ki]);
                        }
                    }
                    else
                    {
                        for (int ki = 0; ki < OpNumber.Length; ki++)
                        {
                            cbo.Items.Add(OpNumber[ki]);
                        }
                    }
                    TextBox txt = new TextBox()
                    {
                        Name = "txt" + k.ToString(), Width = 80, BackColor = App.ColorControl, BorderStyle = BorderStyle.FixedSingle
                    };
                    boi_Filter.Controls.AddRange(new Control[] {
                        lbl,
                        cbo,
                        txt,
                    });

                    if (k != 0 && k % 3 == 0)
                    {
                        Label sp = new Label()
                        {
                            Text = "", AutoSize = false, Width = App.Width - App.col_Left_Width, Height = 1,
                        };
                        boi_Filter.Controls.Add(sp);
                    }
                }//end for fields

                #endregion

                #region [ === BOX SEARCH - SHOW | HIDE FILTER === ]

                Panel boi_Action = new Panel()
                {
                    Dock = DockStyle.Top, Height = 27, AutoScroll = false, Padding = new Padding(0, 5, 10, 3), BackColor = App.ColorBg
                };
                boi_Action.MouseDown += Label_MouseDown;
                TextBox txt_Keyword = new TextBox()
                {
                    Dock = DockStyle.Right, Width = 166, BorderStyle = BorderStyle.FixedSingle, BackColor = App.ColorControl
                };
                ButtonCustom btn_Search = new ButtonCustom()
                {
                    Text = "Search", Dock = DockStyle.Right, FlatStyle = System.Windows.Forms.FlatStyle.Flat, Width = 60, TextAlign = System.Drawing.ContentAlignment.MiddleCenter, BackColor = Color.Gray, ForeColor = Color.White,
                };
                ButtonCustom btn_Filter = new ButtonCustom()
                {
                    Text = "Filter", Dock = DockStyle.Right, FlatStyle = System.Windows.Forms.FlatStyle.Flat, Width = 50, TextAlign = System.Drawing.ContentAlignment.MiddleCenter, BackColor = Color.Gray, ForeColor = Color.White,
                };

                boi_Action.Controls.AddRange(new Control[] {
                    txt_Keyword,
                    new Label()
                    {
                        Dock = DockStyle.Right, AutoSize = false, Width = 2, Height = 20, BackColor = App.ColorBg
                    },
                    btn_Search,
                    new Label()
                    {
                        Dock = DockStyle.Right, AutoSize = false, Width = 2, Height = 20, BackColor = App.ColorBg
                    },
                    btn_Filter,
                });

                #endregion

                #region [ === GRID === ]

                var grid = new ListViewModelItem()
                {
                    Dock = DockStyle.Fill
                };
                grid.SetDataBinding(info.Fields, info.DataSelectTop);

                #endregion

                #region [ === BOX FOOTER === ]

                Panel boi_Footer = new Panel()
                {
                    Dock = DockStyle.Bottom, Height = 18, AutoScroll = false, Padding = new Padding(0), BackColor = App.ColorBg
                };
                boi_Footer.MouseDown += Label_MouseDown;

                Label lbl_TotalRecord = new Label()
                {
                    Dock = DockStyle.Left, Text = "Records: " + info.DataSelectTop.Count.ToString() + " / " + info.TotalRecord.ToString() + " ", AutoSize = false, Width = 199, Height = 18, Padding = new Padding(0), Font = new Font(new FontFamily("Arial"), 7F, FontStyle.Regular), ForeColor = Color.WhiteSmoke, TextAlign = ContentAlignment.MiddleLeft
                };
                Label lbl_Port = new Label()
                {
                    Dock = DockStyle.Left, Text = "Port HTTP: " + info.PortHTTP.ToString(), AutoSize = false, Width = 110, Height = 18, Padding = new Padding(4, 0, 0, 0), Font = new Font(new FontFamily("Arial"), 7F, FontStyle.Regular), ForeColor = Color.WhiteSmoke, TextAlign = ContentAlignment.MiddleLeft
                };
                //ButtonCustom btn_Search = new ButtonCustom() { Text = "search", Dock = DockStyle.Right, FlatStyle = System.Windows.Forms.FlatStyle.Flat, Width = 80, TextAlign = System.Drawing.ContentAlignment.MiddleCenter, BackColor = Color.Gray, ForeColor = Color.White, };
                ButtonCustom btn_PagePrev = new ButtonCustom()
                {
                    Text = "<<<", Dock = DockStyle.Right, FlatStyle = System.Windows.Forms.FlatStyle.Flat, Width = 80, TextAlign = System.Drawing.ContentAlignment.MiddleCenter, BackColor = App.ColorBg, ForeColor = Color.White,
                };
                ButtonCustom btn_PageNext = new ButtonCustom()
                {
                    Text = ">>>", Dock = DockStyle.Right, FlatStyle = System.Windows.Forms.FlatStyle.Flat, Width = 80, TextAlign = System.Drawing.ContentAlignment.MiddleCenter, BackColor = App.ColorBg, ForeColor = Color.White,
                };
                Label spa = new Label()
                {
                    Text = "", AutoSize = false, Width = App.Width, Height = 1,
                };
                Label lbl_PageCurrent = new Label()
                {
                    Text = "1", Dock = DockStyle.Right, AutoSize = false, Width = 30, ForeColor = Color.White, TextAlign = ContentAlignment.MiddleCenter
                };
                Label lbl_PageSP = new Label()
                {
                    Text = " | ", Dock = DockStyle.Right, AutoSize = false, Width = 30, ForeColor = Color.White, TextAlign = ContentAlignment.MiddleCenter
                };
                Label lbl_PageTotal = new Label()
                {
                    Text = "1", Dock = DockStyle.Right, AutoSize = false, Width = 30, ForeColor = Color.White, TextAlign = ContentAlignment.MiddleCenter
                };
                lbl_PageTotal.Text = ((int)(info.TotalRecord / selectTop) + (info.TotalRecord % selectTop == 0 ? 0 : 1)).ToString();

                boi_Footer.Controls.AddRange(new Control[] {
                    lbl_TotalRecord,
                    lbl_Port,

                    btn_PagePrev,
                    lbl_PageCurrent,
                    lbl_PageSP,
                    lbl_PageTotal,
                    btn_PageNext,
                });

                #endregion

                page.Controls.AddRange(new Control[] { boi_Filter, boi_Action, grid, boi_Footer, });

                tab.TabPages.Add(page);
                boi_Filter.BringToFront();
                boi_Action.BringToFront();
                grid.BringToFront();

                btn_Filter.Click += (se, ev) => { if (boi_Filter.Visible)
                                                  {
                                                      boi_Filter.Visible = false;
                                                  }
                                                  else
                                                  {
                                                      boi_Filter.Visible = true;
                                                  } };
                //////////////////////////////////////////////////
                btn_PageNext.Click += (se, ev) => tabPage_Next(modelName, info, page, grid, lbl_PageCurrent, lbl_PageTotal, lbl_TotalRecord);
                btn_PagePrev.Click += (se, ev) => tabPage_Prev(modelName, info, page, grid, lbl_PageCurrent, lbl_PageTotal, lbl_TotalRecord);
                //////////////////////////////////////////////////
                txt_Keyword.KeyDown += (se, ev) =>
                {
                    if (ev.KeyCode == Keys.Enter)
                    {
                        tabPage_Search(txt_Keyword.Text, modelName, info, page, grid, lbl_PageCurrent, lbl_PageTotal, lbl_TotalRecord);
                    }
                };
                btn_Search.Click += (se, ev) => tabPage_Search(txt_Keyword.Text, modelName, info, page, grid, lbl_PageCurrent, lbl_PageTotal, lbl_TotalRecord);
                page.OnLoadData  += () =>
                {
                    info = db.GetInfoSelectTop(modelName, selectTop);
                    tabPage_Search(txt_Keyword.Text, modelName, info, page, grid, lbl_PageCurrent, lbl_PageTotal, lbl_TotalRecord);
                };
            }//end bind info Model
        }