Example #1
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if ((TextBoxMaKH.Text.Trim() == ""))
            {
                MessageBox.Show("NhapID", " Add ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string   id     = TextBoxMaKH.Text;
                string   name   = TextBoxNameKH.Text;
                DateTime datebd = DatetimeBD.Value;
                string   phone  = TextBoxPhone.Text;
                string   adrs   = TextBoxDC.Text;
                string   LBGT   = "Male";
                int      mk;
                string   TPhong = ComboBoxPhong.SelectedValue.ToString();
                if (radioButtonFemale.Checked)
                {
                    LBGT = "Female";
                }
                MemoryStream pic      = new MemoryStream();
                SqlCommand   command5 = new SqlCommand("Select MKPhong From TTPhong where MaPhong  like'" + TPhong + "%'");
                DataTable    table5   = phong.getshowkh(command5);
                mk = (int)table5.Rows[0]["MKPhong"];
                if (verif())
                {
                    pictureBox1.Image.Save(pic, pictureBox1.Image.RawFormat);
                    if (phong.insertPhong(id, name, LBGT, adrs, phone, TPhong, datebd, pic))
                    {
                        phong.updateTPhong(TPhong);
                        phong.insertKHForQL(id, name, LBGT, adrs, phone, TPhong, datebd, pic);
                        MessageBox.Show("Thành Công", "Thêm Khách Hàng", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        MessageBox.Show("Mật Khẩu Phòng là: " + mk, "Thêm Khách Hàng", MessageBoxButtons.OK);

                        Close();
                    }
                    else
                    {
                        MessageBox.Show("Thất Bại", "Thêm Khách Hàng", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Thiếu gì đó", "Thêm Khách Hàng", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }