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(); } }
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(); } //} }
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(); } } } }
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(); } } } }
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(); } } } }