private void btn_Click(object sender, EventArgs e) { if (!validate()) { return; } if (id != 0) { HanhKhach hk = _hanhKhach.getById(id); hk.MaKhach = txt_id.Text; hk.Ten = txt_name.Text; hk.Email = txt_email.Text; hk.SDT = txt_phone.Text; _hanhKhach.Update(hk); MessageBox.Show("Sửa thành công Hành Khách có ID: " + hk.KhachId, "Hành Khách"); txt_id.Focus(); } else { HanhKhach hk = new HanhKhach(); hk.MaKhach = txt_id.Text; hk.Ten = txt_name.Text; hk.Email = txt_email.Text; hk.SDT = txt_phone.Text; _hanhKhach.Add(hk); MessageBox.Show("Đã thêm thành công", "Hành Khách"); txt_id.Text = ""; txt_email.Text = ""; txt_phone.Text = ""; txt_name.Text = ""; txt_id.Focus(); } }
private void btn_Click(object sender, EventArgs e) { if (!validate()) { return; } if (id != 0) { HanhKhach hk = _hanhKhach.getById(id); hk.MaKhach = txt_id.Text; hk.Ten = txt_name.Text; hk.Email = txt_email.Text; hk.SDT = txt_phone.Text; hk.CMND = txt_cmnd.Text; hk.DiaChi = txt_diachi.Text; hk.Passport = txt_passport.Text; if (Radio_GT.Checked == true) { hk.GioiTinh = Radio_GT.Text; } else { hk.GioiTinh = Radio_GT1.Text; } _hanhKhach.Update(hk); MessageBox.Show("Sửa thành công Hành Khách có ID: " + hk.KhachId, "Hành Khách"); txt_id.Focus(); } else { HanhKhach hk = new HanhKhach(); hk.MaKhach = txt_id.Text; hk.Ten = txt_name.Text; hk.Email = txt_email.Text; hk.SDT = txt_phone.Text; hk.CMND = txt_cmnd.Text; hk.DiaChi = txt_diachi.Text; hk.Passport = txt_passport.Text; if (Radio_GT.Checked == true) { hk.GioiTinh = Radio_GT.Text; } else { hk.GioiTinh = Radio_GT1.Text; } _hanhKhach.Add(hk); MessageBox.Show("Đã thêm thành công", "Hành Khách"); txt_id.Text = ""; txt_email.Text = ""; txt_phone.Text = ""; txt_name.Text = ""; txt_cmnd.Text = ""; txt_diachi.Text = ""; txt_passport.Text = ""; Radio_GT.Checked = true; txt_id.Focus(); } }