Esempio n. 1
0
        public override void DoRefresh()
        {
            using (db = new haiEntities())
            {
                var ds = db.v_orders.ToList();
                this.dgv.DataSource = ds;

                this.dgv.Columns["oid"].Visible = false;
                this.dgv.Columns["eid"].Visible = false;

                this.dgv.Columns["odate"].HeaderText    = "日期";
                this.dgv.Columns["ename"].HeaderText    = "员工";
                this.dgv.Columns["total"].HeaderText    = "金额";
                this.dgv.Columns["rowcount"].HeaderText = "行数";
                this.dgv.Columns["maxprice"].HeaderText = "最高价";
                this.dgv.Columns["minprice"].HeaderText = "最低价";
                this.dgv.Columns["todo"].HeaderText     = "备注";

                this.dgv.Columns["total"].DefaultCellStyle.Alignment    = DataGridViewContentAlignment.MiddleRight;
                this.dgv.Columns["total"].DefaultCellStyle.Format       = "N2";
                this.dgv.Columns["rowcount"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                this.dgv.Columns["rowcount"].DefaultCellStyle.Format    = "N0";
                this.dgv.Columns["maxprice"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                this.dgv.Columns["maxprice"].DefaultCellStyle.Format    = "N2";
                this.dgv.Columns["minprice"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                this.dgv.Columns["minprice"].DefaultCellStyle.Format    = "N2";

                this.dgv.AutoResizeColumns();
            }
        }
Esempio n. 2
0
        public override void DoDelete()
        {
            using (db = new haiEntities())
            {
                if (this.dgv.Rows.Count <= 0 || this.dgv.SelectedRows.Count <= 0)
                {
                    return;
                }
                if (DialogResult.Yes != MessageBox.Show("确定要删除该行", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    return;
                }
                Guid   guid = Guid.Parse(this.dgv.SelectedRows[0].Cells["oid"].Value.ToString());
                orders ord  = new orders();
                ord.oid = guid;
                db.orders.Attach(ord);
                db.Entry(ord).State = System.Data.Entity.EntityState.Deleted;

                var rows = db.orderows.Where(p => p.oid == guid);
                db.orderows.RemoveRange(rows);
                db.SaveChanges();
                MessageBox.Show("操作成功!");
                this.DoRefresh();
            }
        }
Esempio n. 3
0
 protected override void LoadIfC()
 {
     using (db = new haiEntities())
     {
         this.Text += "--新增";
     }
 }
Esempio n. 4
0
 public override void DoDelete()
 {
     using (db = new haiEntities())
     {
         if (this.dgv.Rows.Count <= 0 || this.dgv.SelectedRows.Count <= 0)
         {
             return;
         }
         Guid      guid = Guid.Parse(this.dgv.SelectedRows[0].Cells["id"].Value.ToString());
         employees emp  = new employees();
         emp.id = guid;
         db.employees.Attach(emp);
         db.Entry(emp).State = System.Data.Entity.EntityState.Deleted;
         //var emp = db.employees.SingleOrDefault(p => p.id == guid);
         //if (emp != null)
         //{
         if (DialogResult.Yes != MessageBox.Show("确定要删除该行", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
         {
             return;
         }
         //db.employees.Remove(emp);
         db.SaveChanges();
         MessageBox.Show("操作成功!");
         this.DoRefresh();
     }
     //}
 }
Esempio n. 5
0
 protected override void LoadIfU()
 {
     using (db = new haiEntities())
     {
         this.Text                 += "--更新";
         this.empBTN.Text           = Dgvr.Cells["ename"].Value.ToString();
         this.empBTN.Tag            = Dgvr.Cells["eid"].Value.ToString();
         this.todoTB.Text           = Dgvr.Cells["todo"].Value.ToString();
         this.dateTimePicker1.Value = DateTime.Parse(Dgvr.Cells["odate"].Value.ToString());
         //MessageBox.Show(Dgvr.Cells["oid"].Value.ToString());
         Guid guid = Guid.Parse(Dgvr.Cells["oid"].Value.ToString());
         var  list = db.orderows.Where(p => p.oid == guid).ToList();
         foreach (var item in list)
         {
             var product = db.products.FirstOrDefault(q => q.pid == item.pid);
             this.dgv.Rows.Add(new object[] {
                 item.pid
                 , product.pname
                 , product.standard
                 , item.price, item.count, item.price * item.count, item.todo
             });
             this.dgv.AutoResizeColumns();
         }
     }
 }
Esempio n. 6
0
 protected override void Sav()
 {
     base.Sav();
     if (this.IsChecked)
     {
         using (db = new haiEntities())
         {
             if (this.Curd == ECurdOption.U)
             {
                 orders ord = new orders();
                 var    oid = Guid.Parse(this.Dgvr.Cells["oid"].Value.ToString());
                 ord.oid   = oid;
                 ord.eid   = Guid.Parse(this.empBTN.Tag.ToString());
                 ord.odate = this.dateTimePicker1.Value;
                 ord.todo  = this.todoTB.Text;
                 db.orders.Attach(ord);
                 db.Entry(ord).State = System.Data.Entity.EntityState.Modified;
                 db.orderows.RemoveRange(db.orderows.Where(p => p.oid == oid));
                 foreach (DataGridViewRow r in this.dgv.Rows)
                 {
                     orderows ordr = new orderows();
                     ordr.oid   = oid;
                     ordr.pid   = Guid.Parse(r.Cells["guidColumn"].Value.ToString());
                     ordr.price = decimal.Parse(r.Cells["priceColumn"].Value.ToString());
                     ordr.count = int.Parse(r.Cells["countColumn"].Value.ToString());
                     ordr.todo  = r.Cells["todoColumn"].Value.ToString();
                     db.orderows.Add(ordr);
                 }
                 db.SaveChanges();
                 this.ParForm.DoRefresh();
                 this.Close();
             }
             else
             {
                 var    oid = Guid.NewGuid();
                 orders ord = new orders();
                 ord.oid   = oid;
                 ord.eid   = Guid.Parse(this.empBTN.Tag.ToString());
                 ord.odate = this.dateTimePicker1.Value;
                 ord.todo  = this.todoTB.Text;
                 db.orders.Add(ord);
                 foreach (DataGridViewRow r in this.dgv.Rows)
                 {
                     orderows ordr = new orderows();
                     ordr.oid   = oid;
                     ordr.pid   = Guid.Parse(r.Cells["guidColumn"].Value.ToString());
                     ordr.price = decimal.Parse(r.Cells["priceColumn"].Value.ToString());
                     ordr.count = int.Parse(r.Cells["countColumn"].Value.ToString());
                     ordr.todo  = r.Cells["todoColumn"].Value.ToString();
                     db.orderows.Add(ordr);
                 }
                 db.SaveChanges();
                 MessageBox.Show("操作成功");
                 this.ParForm.DoRefresh();
                 FormClear();
             }
         }
     }
 }
Esempio n. 7
0
 protected override void LoadIfC()
 {
     using (db = new haiEntities())
     {
         this.Text += "--新增";
         this.parCBB.DataSource    = db.employees.OrderBy(p => p.name).ToList();
         this.parCBB.DisplayMember = "name";
         this.parCBB.ValueMember   = "id";
     }
 }
Esempio n. 8
0
 public override void DoRefresh()
 {
     using (db = new haiEntities())
     {
         var ds = db.products.ToList();
         this.dgv.DataSource                     = ds;
         this.dgv.Columns["pid"].Visible         = false;
         this.dgv.Columns["pname"].HeaderText    = "产品名";
         this.dgv.Columns["price"].HeaderText    = "价格";
         this.dgv.Columns["standard"].HeaderText = "规格";
         this.dgv.Columns["price"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
         this.dgv.Columns["price"].DefaultCellStyle.Format    = "N2";
         this.dgv.AutoResizeColumns();
     }
 }
Esempio n. 9
0
 public override void DoRefresh()
 {
     using (db = new haiEntities())
     {
         var ds = db.v_emp.ToList();
         this.dgv.DataSource                    = ds;
         this.dgv.Columns["id"].Visible         = false;
         this.dgv.Columns["parid"].Visible      = false;
         this.dgv.Columns["name"].HeaderText    = "姓名";
         this.dgv.Columns["sex"].HeaderText     = "性别";
         this.dgv.Columns["address"].HeaderText = "地址";
         this.dgv.Columns["phone"].HeaderText   = "手机";
         this.dgv.Columns["parname"].HeaderText = "上级";
         this.dgv.AutoResizeColumns();
     }
 }
Esempio n. 10
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();
        }
Esempio n. 11
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();
        }
Esempio n. 12
0
 protected override void Sav()
 {
     base.Sav();
     if (this.IsChecked)
     {
         using (db = new haiEntities())
         {
             if (this.Curd == ECurdOption.U)
             {
                 employees emp = new employees();
                 emp.id      = Guid.Parse(Dgvr.Cells["id"].Value.ToString());
                 emp.name    = this.nameTB.Text;
                 emp.phone   = this.phoneTB.Text;
                 emp.address = this.addressTB.Text;
                 emp.parid   = Guid.Parse(this.parCBB.SelectedValue.ToString());
                 emp.sex     = this.sexCBB.Text;
                 db.employees.Attach(emp);
                 db.Entry(emp).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 this.ParForm.DoRefresh();
                 this.Close();
             }
             else
             {
                 employees emp = new employees();
                 emp.id      = Guid.NewGuid();
                 emp.name    = this.nameTB.Text;
                 emp.phone   = this.phoneTB.Text;
                 emp.address = this.addressTB.Text;
                 emp.parid   = Guid.Parse(this.parCBB.SelectedValue.ToString());
                 emp.sex     = this.sexCBB.Text;
                 db.employees.Add(emp);
                 db.SaveChanges();
                 MessageBox.Show("操作成功");
                 this.ParForm.DoRefresh();
                 FormClear();
             }
         }
     }
 }
Esempio n. 13
0
 protected override void LoadIfU()
 {
     using (db = new haiEntities())
     {
         this.Text          += "--更新";
         this.nameTB.Text    = Dgvr.Cells["name"].Value.ToString();
         this.phoneTB.Text   = Dgvr.Cells["phone"].Value.ToString();
         this.addressTB.Text = Dgvr.Cells["address"].Value.ToString();
         this.sexCBB.Text    = Dgvr.Cells["sex"].Value.ToString();
         var list = db.employees.OrderBy(p => p.name).ToList();
         this.parCBB.DataSource    = list;
         this.parCBB.DisplayMember = "name";
         this.parCBB.ValueMember   = "id";
         foreach (var item in list)
         {
             if (item.id == Guid.Parse(Dgvr.Cells["parid"].Value.ToString()))
             {
                 this.parCBB.SelectedItem = item;
             }
         }
     }
 }
Esempio n. 14
0
        protected override void Sav()
        {
            base.Sav();
            using (db = new haiEntities())
            {
                if (this.IsChecked)
                {
                    if (this.Curd == ECurdOption.U)
                    {
                        products pd = new products();
                        pd.pid      = Guid.Parse(this.Dgvr.Cells["pid"].Value.ToString());
                        pd.pname    = this.pnameTB.Text;
                        pd.standard = this.standardTB.Text;
                        pd.price    = MyFuncs.StringToDcimal(this.priceTB.Text);
                        db.products.Attach(pd);
                        db.Entry(pd).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();

                        this.ParForm.DoRefresh();
                        this.Close();
                    }
                    if (this.Curd == ECurdOption.C)
                    {
                        products pd = new products();
                        pd.pid      = Guid.NewGuid();
                        pd.pname    = this.pnameTB.Text;
                        pd.standard = this.standardTB.Text;
                        pd.price    = MyFuncs.StringToDcimal(this.priceTB.Text);
                        db.products.Add(pd);
                        db.SaveChanges();
                        this.ParForm.DoRefresh();
                        MessageBox.Show("操作成功");
                        FormClear();
                    }
                }
            }
        }
Esempio n. 15
0
        public override void DoDelete()
        {
            if (this.dgv.Rows.Count <= 0 || this.dgv.SelectedRows.Count <= 0)
            {
                return;
            }
            Guid guid = Guid.Parse(this.dgv.SelectedRows[0].Cells["pid"].Value.ToString());

            using (db = new haiEntities())
            {
                var product = db.products.SingleOrDefault(p => p.pid == guid);
                if (product != null)
                {
                    if (DialogResult.Yes != MessageBox.Show("确定要删除该行", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                    {
                        return;
                    }
                    db.products.Remove(product);
                    db.SaveChanges();
                    MessageBox.Show("操作成功!");
                    this.DoRefresh();
                }
            }
        }