Пример #1
0
        private void empbutton_Click(object sender, EventArgs e)
        {
            BaseItemForm bform = new BaseItemForm();

            bform.ItemHelper = (p) =>
            {
                this.empBTN.Tag  = p.Cells["id"].Value.ToString();
                this.empBTN.Text = p.Cells["name"].Value.ToString();
            };
            bform.DataHelper = (dv) =>
            {
                using (haiEntities ddb = new haiEntities())
                {
                    var list = ddb.v_emp.ToList();
                    dv.DataSource                    = list;
                    dv.Columns["id"].Visible         = false;
                    dv.Columns["parid"].Visible      = false;
                    dv.Columns["name"].HeaderText    = "姓名";
                    dv.Columns["sex"].HeaderText     = "性别";
                    dv.Columns["address"].HeaderText = "地址";
                    dv.Columns["phone"].HeaderText   = "手机";
                    dv.Columns["parname"].HeaderText = "上级";
                    dv.AutoResizeColumns();
                }
            };
            bform.FilterHelper = (p, q, m) =>
            {
                List <v_emp> list    = m.DataSource as List <v_emp>;
                var          newlist = list.Where(
                    u =>
                {
                    Type t   = u.GetType();
                    string s = t.GetProperty(p).GetValue(u).ToString();
                    if (s.IndexOf(q) < 0)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }).ToList();
                m.DataSource = newlist;
            };
            bform.ShowDialog();
        }
Пример #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            BaseItemForm bform = new BaseItemForm();

            bform.ItemHelper = (p) =>
            {
                this.productBTN.Tag  = p;//.Cells["pid"].Value.ToString();
                this.productBTN.Text = p.Cells["pname"].Value.ToString();
                this.priceTB.Text    = p.Cells["price"].Value.ToString();
            };
            bform.DataHelper = (dv) =>
            {
                using (haiEntities ddb = new haiEntities())
                {
                    var ds = ddb.products.ToList();
                    dv.DataSource                     = ds;
                    dv.Columns["pid"].Visible         = false;
                    dv.Columns["pname"].HeaderText    = "产品名";
                    dv.Columns["price"].HeaderText    = "价格";
                    dv.Columns["standard"].HeaderText = "规格";
                    dv.Columns["price"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    dv.Columns["price"].DefaultCellStyle.Format    = "N2";
                    dv.AutoResizeColumns();
                }
            };
            bform.FilterHelper = (p, q, m) =>
            {
                List <products> list    = m.DataSource as List <products>;
                var             newlist = list.Where(
                    u =>
                {
                    Type t   = u.GetType();
                    string s = t.GetProperty(p).GetValue(u).ToString();
                    if (s.IndexOf(q) < 0)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }).ToList();
                m.DataSource = newlist;
            };
            bform.ShowDialog();
        }