//Thêm loại món ăn vào danh sách public Boolean InsertTable(TableDTO lst) { try { TABLES_INFO newDishType = new TABLES_INFO() { Id = Guid.NewGuid(), NAME = lst.NAME, CODE = lst.code, WAITER_ID = (from a in Context.WAITER_INFO where a.NAME == lst.WaiterName select a.Id).SingleOrDefault() }; Context.TABLES_INFO.AddObject(newDishType); Context.SaveChanges(); return true; } catch (Exception ex) { throw ex; } }
public Boolean UpdateTable(TableDTO lst) { try { TABLES_INFO query = (from p in Context.TABLES_INFO where p.Id == lst.ID select p).SingleOrDefault(); query.NAME = lst.NAME; query.CODE = lst.code; query.WAITER_ID=(from a in Context.WAITER_INFO where a.NAME==lst.WaiterName select a.Id).SingleOrDefault(); Context.SaveChanges(); return true; } catch (Exception ex) { throw ex; } }
private void tsbSave_Click(object sender, System.EventArgs e) { TableDTO dt = new TableDTO(); if (FormState == FormStateType.New) { dt.NAME = textBox2.Text.Trim(); dt.code = Convert.ToInt32(textBox3.Text); dt.WaiterName = comboBox1.SelectedValue.ToString(); repT.InsertTable(dt); } else if (FormState == FormStateType.Edit) { dt.ID = PKEY; dt.NAME = textBox2.Text.Trim(); dt.code = Convert.ToInt32(textBox3.Text); dt.WaiterName = comboBox1.SelectedText; repT.UpdateTable(dt); } FormState = FormStateType.Normal; tsbSave.Enabled = false; tsbCancel.Enabled = false; tbsAddNew.Enabled = true; tsbEdit.Enabled = true; tsbDelete.Enabled = true; LoadDataBanan(); }