예제 #1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtcustomer_ID.Text == "" || txtcustomer_name.Text == "")
            {
                MessageBox.Show("Mã khách hàng và tên khách hàng không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (txtcustomer_ID.TextLength > 10)
            {
                MessageBox.Show("Mã khách hàng không được quá 10 kí tự", "Thông  báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                try
                {
                    dc.Customer_ID      = txtcustomer_ID.Text;
                    dc.Customer_name    = txtcustomer_name.Text;
                    dc.Customer_age     = int.Parse(txtcustomer_age.Text);
                    dc.Customer_address = txtcustomer_address.Text;
                    if (rdbnam.Checked)
                    {
                        dc.Customer_gender = "Nam";
                    }
                    else
                    {
                        dc.Customer_gender = "Nữ";
                    }
                    dc.Customer_phone = txtcustomer_phone.Text;

                    bc.update_Customer(dc.Customer_ID, dc.Customer_name, dc.Customer_age, dc.Customer_address, dc.Customer_gender, dc.Customer_phone);
                    MessageBox.Show("Đã cập nhật thành công");
                    Customer_Load(sender, e);
                }

                catch (FormatException ex)
                {
                    MessageBox.Show("Không sửa được. Lỗi rồi!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                catch (SqlException ex)
                {
                    if (ex.Message.Contains("PRIMARY KEY"))
                    {
                        MessageBox.Show("Trùng mã rồi!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }