private void btnThem_Click(object sender, EventArgs e) { if (txbTaiKhoan.TextInput == "" || txbMatKhau.TextInput == "") { if (txbTaiKhoan.TextInput == "") { txbTaiKhoan.onFocusBorderColor = Color.Red; ShowErrorTaiKhoan("Vui lòng không để trống tài khoản"); } if (txbMatKhau.TextInput == "") { txbMatKhau.onFocusBorderColor = Color.Red; ShowErrorMatKhau("Vui lòng không để trống mật khẩu"); } } else { if (txbMatKhau.TextInput.Length < 3) { ShowErrorMatKhau("Mật khẩu phải lớn hơn 3 kí tự"); } else { HideError(); int loai = ((KeyValuePair <int, string>)cbxLoai.SelectedItem).Key; string tenTaiKhoan = txbTaiKhoan.TextInput; string matkhau = txbMatKhau.TextInput; TaikhoanDAO.Instance.ThemTaiKhoan(tenTaiKhoan, matkhau, loai); NotificationAlert.SuccessAlert success = new SuccessAlert(); success.Alert("Thêm thành công"); success.ShowDialog(); } } }
private void BtnSua_Click(object sender, EventArgs e) { int idLoai = (int)formup.cbxLoai.SelectedValue; string ten = formup.txbTen.TextInput; int gia = 0; int id = 0; Int32.TryParse(formup.txbID.TextInput, out id); formup.txbID.BackColor = Color.FromArgb(160, 160, 160); Int32.TryParse(formup.txbGia.TextInput, out gia); ThucAnDAO.Instance.UpdateFood(ten, gia, idLoai, id); NotificationAlert.SuccessAlert tt = new SuccessAlert(); tt.Alert("Cập nhật thành công"); tt.ShowDialog(); LoadDataFood(); }
//Xử lý sửa xóa món ăn private void dataFood_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { int c = dataFood.CurrentCell.RowIndex; bool f = true; var SenderGrid = (DataGridView)sender; //Xóa if (SenderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0 && e.ColumnIndex == 1) { int id = (int)dataFood.Rows[c].Cells[2].Value; DataTable table = ThucAnDAO.Instance.LayidThucAn(); foreach (DataRow r in table.Rows) { if (id == (int)r["idTA"]) { MessageBox.Show("Món Ăn đang được đặt không thể thực hiện chức năng này"); f = false; } } if (f == true) { DialogResult rs = MessageBox.Show("Dữ liệu không thể khôi phục! Bạn có chắc muốn xóa", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (rs == DialogResult.Yes) { ThucAnDAO.Instance.XoaMonAn(id); NotificationAlert.SuccessAlert al = new SuccessAlert(); al.Alert("Xóa thành công"); al.ShowDialog(); LoadDataFood(); } } } //Sửa else if (SenderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0 && e.ColumnIndex == 0) { bool flag = true; int id = (int)dataFood.Rows[c].Cells[2].Value; DataTable tb = ThucAnDAO.Instance.LayidThucAn(); foreach (DataRow r in tb.Rows) { if (id == (int)r["idTA"]) { MessageBox.Show("Món Ăn đang được đặt không thể thực hiện chức năng này"); flag = false; } } DataTable table = ThucAnDAO.Instance.ShowThucAnTuId(id); foreach (DataRow row in table.Rows) { formup.txbTen.TextInput = row["tenTA"].ToString(); formup.txbGia.TextInput = row["gia"].ToString(); } formup.btnSua.Visible = true; formup.txbID.TextInput = id.ToString(); formup.txbID.Enabled = false; formup.panelID.Visible = true; if (flag == true) { formup.btnSua.Click += BtnSua_Click; formup.ShowDialog(); } } } catch { MessageBox.Show("Không tồn tại dữ liệu"); } }