private void btndlt_Click(object sender, EventArgs e) { if (dataGridView1.CurrentRow != null) { if (MessageBox.Show("Bạn Muốn Xóa Thông Tin Khách Hàng Này?", "Chú Ý !!!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var result = SQLProvider.Execute("DELETE FROM [dbo].[Transaction] WHERE CustomerId = @CustomerId;" + "DELETE FROM [dbo].[Account] WHERE CustomerId = @CustomerId; " + "DELETE FROM [dbo].[User] WHERE CustomerId = @CustomerId; " + "DELETE FROM [dbo].[Customer] WHERE CustomerId = @CustomerId; " , paramters: new Dictionary <string, object> { { "CustomerId", dataGridView1.CurrentRow.Cells[0].Value } }); if (result) { //show lên 1 cái form MessageBox.Show("Xóa Thành Công", "Xóa", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadCustomer(); } else { MessageBox.Show("Xóa Không Thành Công", "Lỗi !!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void button8_Click(object sender, EventArgs e) { Customer ctm = new Customer(); if (textName.Text == "") { MessageBox.Show("Please Enter the First Name", "Confirmation"); return; } if (textLName.Text == "") { MessageBox.Show("Please Enter the Last Name", "Confirmation"); return; } if (textNumber.Text == "") { MessageBox.Show("Please Enter the idnumber", "Confirmation"); return; } if (textPlace.Text == "") { MessageBox.Show("Please Enter the Place", "Confirmation"); return; } if (textAddress.Text == "") { MessageBox.Show("Please Enter the Adress", "Confirmation"); return; } if (textPhone.Text == "") { MessageBox.Show("Please Enter the Phone Number", "Confirmation"); return; } if (textPhone.Text != "") { try { int phone = int.Parse(textPhone.Text); } catch (Exception) { MessageBox.Show("the phone number must be a number", "Confirmation"); return; } } if (textPhone.Text != "") { try { UInt64 phone = UInt64.Parse(textPhone.Text); } catch (Exception) { MessageBox.Show("Phone number don't contain special characters", "confirmation"); return; } } string query = @"INSERT INTO Customer (FirstName, LastName, IDNumber, IDPlace, IDDate,Address,Phone) VALUES (@FirstName, @LastName, @IDNumber, @IDPlace, @IDDate,@Address,@Phone)"; if (customerrow != null) { query = @"UPDATE Customer SET FirstName = @FirstName, LastName = @LastName, IDNumber = @IDNumber, IDPlace = @IDPlace, IDDate = @IDDate,Address=@Address,Phone=@Phone WHERE CustomerId = @CustomerId"; } var parameters = new Dictionary <string, object> { { "FirstName", textName.Text }, { "LastName", textLName.Text }, { "IDNumber", textNumber.Text }, { "IDPlace", textPlace.Text }, { "IDDate", dateIDDate.Value }, { "Address", textAddress.Text }, { "Phone", textPhone.Text } }; if (customerrow != null) { parameters.Add("CustomerId", (int)customerrow["CustomerId"]); } var result = SQLProvider.Execute(query, paramters: parameters); if (result) { MessageBox.Show("Save Customer successful.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } else { MessageBox.Show("Save Customer failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }