private void btInsertThucDon_Click(object sender, EventArgs e) { int idCate = Convert.ToInt16(cbMenuCate.SelectedValue.ToString()); ENTITY.Menu mn = new ENTITY.Menu(); MenuDAL mnDAL = new MenuDAL(); mn.IdCategory = idCate; if (txtMaMon.TextLength != 0) { MessageBox.Show("Không cần nhập mã món", " Lỗi "); } else { if (txtTenMon.TextLength == 0) { MessageBox.Show("Chưa nhập tên món", " Lỗi "); } else { mn.Name = txtTenMon.Text; if (txtGia.TextLength == 0) { MessageBox.Show("Chưa nhập giá ", " Lỗi "); } else { mn.Price = Convert.ToInt32(txtGia.Text.ToString()); try { if (rbCon.Checked == false && rbHet.Checked == false) { MessageBox.Show("Chưa chọn tình trạng món ăn", " Lỗi "); } else { if (rbCon.Checked == true) { mn.Status = "Còn"; } else if (rbHet.Checked == true) { mn.Status = "Hết"; } mnDAL.insertMenu(mn); // dgvmenu.DataSource = mnDAL.LoadDSMenuByCate(idCate); HienThiDSMenu(); } } catch { } } } } }
private void btEditThucDon_Click(object sender, EventArgs e) { int idCate = Convert.ToInt16(cbMenuCate.SelectedValue.ToString()); ENTITY.Menu mn = new ENTITY.Menu(); mn.Id = Convert.ToInt16(txtMaMon.Text); MenuDAL mnDAL = new MenuDAL(); if (txtMaMon.Text != mn.Id.ToString()) { MessageBox.Show("Không được sửa mã món", " Lỗi "); } else { if (txtTenMon.TextLength == 0) { MessageBox.Show("Chưa nhập tên món", " Lỗi "); } else { mn.Name = txtTenMon.Text; if (txtGia.TextLength == 0) { MessageBox.Show("Chưa nhập giá ", " Lỗi "); } else { mn.Price = Convert.ToInt32(txtGia.Text.ToString()); if (rbCon.Checked == false && rbHet.Checked == false) { MessageBox.Show("Chưa chọn tình trạng món ăn", " Lỗi "); } else { if (rbCon.Checked == true) { mn.Status = "Còn"; } else if (rbHet.Checked == true) { mn.Status = "Hết"; } mnDAL.UpdateMenu(mn.Name, mn.Price, mn.Status, mn.Id); MessageBox.Show("Bạn đã sửa món thành công", "thông báo"); // dgvmenu.DataSource = mnDAL.LoadDSMenuByCate(idCate); HienThiDSMenu(); } } } } }
public async void UpdateMenu(string name, int price, string status, int idMenu) { HttpClient client = new HttpClient(); StringBaseAdd s = new StringBaseAdd(); client.BaseAddress = new Uri(s.url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); ENTITY.Menu mn = new ENTITY.Menu(); mn.Name = name; mn.Price = price; mn.Status = status; mn.Id = idMenu; HttpResponseMessage responsePost = await client.PutAsJsonAsync("api/Menu", mn); }