public frmKhamThem(BenhNhan_Info bn, LanKham_Info lk, DoiTuong_Info dt, BacSi_Info bs)
 {
     this.bn = bn;
     this.lk = lk;
     this.dt = dt;
     this.bs = bs;
     InitializeComponent();
 }
        private void btn_KhamThem_Click(object sender, EventArgs e)
        {
            if (GridBenhNhan.ActiveRow != null)
            {
                BenhNhan_Info bn = new BenhNhan_Info();
                bn.DiaChi    = txtDiaChi.Text;
                bn.DienThoai = txtDienThoai.Text;
                bn.GioiTinh  = txtGT.Text == "Nam" ? true : false;
                bn.HoTen     = txtHoTen.Text;
                bn.Tuoi      = Convert.ToInt32(txtTuoi.Text);
                LanKham_Info lk = new LanKham_Info();
                lk.NgayKham  = Convert.ToDateTime(txtNgayKham.Text);
                lk.SoBH      = txtMaTheBHYT.Text;
                lk.SoKham    = Convert.ToInt32(txtMaBenhAn.Text);
                lk.LanKhamID = Convert.ToInt32(GridBenhNhan.ActiveRow.Cells["LanKhamID"].Value);
                if (GridBenhNhan.ActiveRow.Cells["BacSiGuiID"].Value.ToString() == "")
                {
                    lk.BacSiGuiID = 0;
                }
                else
                {
                    lk.BacSiGuiID = Convert.ToInt32(GridBenhNhan.ActiveRow.Cells["BacSiGuiID"].Value);
                }
                DoiTuong_Info dt = new DoiTuong_Info();
                dt.TenDoiTuong = txtDoiTuong.Text;
                BacSi_Info bs = new BacSi_Info();
                bs.HoTen = GridBenhNhan.ActiveRow.Cells["HoTenBacSi"].Value.ToString();


                frmKhamThem f = new frmKhamThem(bn, lk, dt, bs);
                f.ShowDialog();
                grid_DV.DataSource = LoadDV(lk.LanKhamID.ToString());
            }

            else
            {
                MessageBox.Show("Chọn bệnh nhân để khám thêm");
            }
        }
        private void btn_Luu_Click(object sender, EventArgs e)
        {
            bool flag = CheckValue();

            if (flag)
            {
                BenhNhan_Info benhNhan_Info = new BenhNhan_Info(0, txtHoTenBenhNhan.Text, txtDiaChi.Text, txtSoDienThoai.Text, Convert.ToInt32(txtNamSinh.Value), Convert.ToDateTime(new DateTime(DateTime.Now.Year - Convert.ToInt32(txtNamSinh.Value), DateTime.Now.Month, DateTime.Now.Day, 1, 0, 0)), Convert.ToBoolean(cbx_GioiTinh.Text));
                benhNhan_Info.Insert();
                LanKham_Info lanKham_Info = new LanKham_Info(0, benhNhan_Info.Ma, Convert.ToInt32(cbx_BacSiGui.Value), Convert.ToInt32(cbx_MaDoiTuong.Text), txtMaTheBHYT.Text, txtChuanDoan.Text, Convert.ToDateTime(cdt_Ngayvaovien.Value), "", Convert.ToInt32(txtSoKham.Text));
                lanKham_Info.Insert();
                IEnumerator ienumerator = ((DataTable)gridDSDichVuKe.DataSource).Rows.GetEnumerator();
                foreach (DataRow dataRow in ((DataTable)gridDSDichVuKe.DataSource).Rows)
                {
                    DichVu_LanKham_Info dichVu_LanKham_Info = new DichVu_LanKham_Info(0, Convert.ToInt32(dataRow["DichVuID"].ToString()), lanKham_Info.Ma, Convert.ToInt32(dataRow["BacSiGuiID"].ToString()), Convert.ToInt32(dataRow["SoLuong"].ToString()), Convert.ToDecimal(dataRow["DonGia"].ToString()), 0, Convert.ToDateTime(cdt_Ngayvaovien.Value), DateTime.Now, 0);
                    dichVu_LanKham_Info.Insert();
                }

                TienNop_LanKham_Info tn = new TienNop_LanKham_Info(0, lanKham_Info.LanKhamID, Convert.ToDecimal(txtTongChiPhi.Value), "");
                tn.Insert();


                DataTable dataTable = DB_SQL.EXECUTE_SQL("select max(SoKham) as SoKham from LanKham");
                flag = dataTable.Rows[0]["SoKham"].ToString() != "";
                if (!flag)
                {
                    txtSoKham.Text = "1";
                }
                else
                {
                    int i = Convert.ToInt32(dataTable.Rows[0]["SoKham"].ToString()) + 1;
                    txtSoKham.Text = i.ToString();
                }
                MessageBox.Show("Cập nhật thành công!", "Thông báo", MessageBoxButtons.OK);
                txtSoKham.Focus();
                // In biên lai

                DataTable ds = dsDichVuKe, temp;
                temp = dsDichVuKe.Copy();
                temp.Clear();
                foreach (DataRow r in ds.Rows)
                {
                    if (check_as(temp, "PhongID", r["PhongID"].ToString()))
                    {
                        DataRow rt = temp.NewRow();
                        rt["PhongID"] = r["PhongID"].ToString();
                        temp.Rows.Add(rt);
                        DataView v = ds.DefaultView;
                        v.RowFilter = "TenPhong='" + r["TenPhong"].ToString() + "'";
                        DataTable ds1 = v.ToTable();
                        decimal   t   = 0;
                        foreach (DataRow k in ds1.Rows)
                        {
                            t += Convert.ToDecimal(k["SoLuong"].ToString()) * Convert.ToDecimal(k["DonGia"].ToString());
                        }

                        string[]      ParamName  = { "@NgayThu", "@HoVaTen", "@Tuoi", "@DiaChi", "@TenDoiTuong", "@SoTien", "@BangChu", "@SoKham", "@Phong" };
                        object[]      ParamValue = { Convert.ToDateTime(cdt_Ngayvaovien.Value), txtHoTenBenhNhan.Text,          txtNamSinh.Value.ToString()
                                                     ,                                               txtDiaChi.Text,                 txtTenDoiTuong.Text,t,
                                                     Util.FormHandler.txtVND(Convert.ToDecimal(t)),  lanKham_Info.SoKham.ToString(), r["TenPhong"].ToString() };
                        frmReportMain report = new frmReportMain(11, v.ToTable(), ParamName, ParamValue);
                        report.Show();
                    }
                }
                txtTongChiPhi.Value = 0;

                clear();
                load();
            }
        }