void cmdgetPatient_Click(object sender, EventArgs e)
        {
            frm_DSACH_BN_TKIEM _DSACH_BN_TKIEM = new frm_DSACH_BN_TKIEM("ALL");

            if (_DSACH_BN_TKIEM.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtMaluotkham.Text = _DSACH_BN_TKIEM.MaLuotkham;
                txtMaluotkham_KeyDown(txtMaluotkham, new KeyEventArgs(Keys.Enter));
            }
        }
        /// <summary>
        /// hàm thực hienej phím tắt của form hiện tại
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frm_Dangky_Kiemnghiem_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F3)
            {
                if (this.ActiveControl != null && this.ActiveControl.Name == txtTEN_BN.Name && Utility.DoTrim(txtTEN_BN.Text)!="")
                {
                    frm_DSACH_BN_TKIEM Timkiem_Benhnhan = new frm_DSACH_BN_TKIEM();
                    Timkiem_Benhnhan.AutoSearch = true;
                    Timkiem_Benhnhan.FillAndSearchData(false, "", "", Utility.DoTrim(txtTEN_BN.Text), "", "", "-1");
                    if (Timkiem_Benhnhan.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {

                        isAutoFinding = true;
                        FindPatient(Timkiem_Benhnhan.IdBenhnhan.ToString());
                        isAutoFinding = false;
                    }
                }
                else if (this.ActiveControl != null && this.ActiveControl.Name == txtSoDT.Name && Utility.DoTrim(txtSoDT.Text) != "")
                {
                    frm_DSACH_BN_TKIEM Timkiem_Benhnhan = new frm_DSACH_BN_TKIEM();
                    Timkiem_Benhnhan.AutoSearch = true;
                    Timkiem_Benhnhan.FillAndSearchData(false, "", "", "", "", Utility.DoTrim(txtSoDT.Text), "-1");
                    if (Timkiem_Benhnhan.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        isAutoFinding = true;
                        FindPatient(Timkiem_Benhnhan.IdBenhnhan.ToString());
                        isAutoFinding = false;
                    }
                }
                return;
            }

            if (e.Control && e.KeyCode == Keys.D)
            {

                _MaDoituongKcb = "DV";
                cboDoituongKCB.SelectedIndex = Utility.GetSelectedIndex(cboDoituongKCB, _MaDoituongKcb);
                return;
            }
            if (e.Control && e.KeyCode == Keys.B)
            {
                _MaDoituongKcb = "BHYT";
                cboDoituongKCB.SelectedIndex = Utility.GetSelectedIndex(cboDoituongKCB, _MaDoituongKcb);
                return;
            }

            string ngay_kham = globalVariables.SysDate.ToString("dd/MM/yyyy");
            if (e.Control && e.KeyCode == Keys.K)
            {
                if (!NotPayment(txtMaBN.Text.Trim(), ref ngay_kham))
                {
                    m_enAction = action.Add;
                    SinhMaLanKham();
                    chkPhongchuyenmon.Focus();
                }
                else
                {
                    //nếu là ngày hiện tại thì đặt về trạng thái sửa
                    if (ngay_kham == globalVariables.SysDate.ToString("dd/MM/yyyy"))
                    {
                        Utility.ShowMsg(
                            "Khách hàng đang có lần đăng ký chưa được thanh toán. Cần thanh toán hết các lần đến khám bệnh của Khách hàng trước khi thêm lần đăng ký mới.Nhấn OK để hệ thống quay về trạng thái sửa thông tin BN");
                        m_enAction = action.Update;
                        AllowTextChanged = false;
                        LoadThongtinBenhnhan();
                        txtTEN_BN.Focus();
                    }
                    else //Không cho phép thêm lần đăng ký khác nếu chưa thanh toán lần đăng ký của ngày hôm trước
                    {
                        Utility.ShowMsg(
                            "Khách hàng đang có lần đăng ký chưa được thanh toán. Cần thanh toán hết các lần đến khám bệnh của Khách hàng trước khi thêm lần đăng ký mới. Nhấn OK để hệ thống chuyển về trạng thái thêm mới Khách hàng");
                        cmdThemMoiBN_Click(cmdThemMoiBN, new EventArgs());
                    }
                }
                return;
            }
            if (e.Control && e.KeyCode == Keys.F)
            {
                txtMaBN.SelectAll();
                txtMaBN.Focus();
            }

            if (e.KeyCode == Keys.F11) Utility.ShowMsg(this.ActiveControl.Name);
            if (e.KeyCode == Keys.Escape && this.ActiveControl != null && this.ActiveControl.GetType()!=txtDiachi.GetType())
            {

                Close();
            }
            if (e.KeyCode == Keys.S && e.Control) cmdSave.PerformClick();
            if (e.KeyCode == Keys.N && e.Control) cmdThemMoiBN.PerformClick();
            if (e.KeyCode == Keys.Enter)
            {
                SendKeys.Send("{TAB}");
            }
        }
        public void txtMaluotkham_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter && Utility.DoTrim(txtMaluotkham.Text) != "")
                {
                    AllowTextChanged = false;
                    var dtPatient = new DataTable();

                        objLuotkham = null;
                        string _patient_Code = Utility.AutoFullPatientCode(txtMaluotkham.Text);
                        ClearControls();

                        dtPatient = new KCB_THAMKHAM().TimkiemBenhnhan(txtMaluotkham.Text,
                                                       -1,(byte)1, 0);

                        DataRow[] arrPatients = dtPatient.Select(KcbLuotkham.Columns.MaLuotkham + "='" + _patient_Code + "'");
                        if (arrPatients.GetLength(0) <= 0)
                        {
                            if (dtPatient.Rows.Count > 1)
                            {
                                var frm = new frm_DSACH_BN_TKIEM();
                                frm.MaLuotkham = txtMaluotkham.Text;
                                frm.dtPatient = dtPatient;
                                frm.ShowDialog();
                                if (!frm.has_Cancel)
                                {
                                    txtMaluotkham.Text = frm.MaLuotkham;
                                }
                            }
                        }
                        else
                        {
                            txtMaluotkham.Text = _patient_Code;
                        }
                        DataTable dt_Patient = new KCB_THAMKHAM().TimkiemThongtinBenhnhansaukhigoMaBN(txtMaluotkham.Text, -1,"ALL");
                        if (dt_Patient != null && dt_Patient.Rows.Count > 0)
                        {

                            txtIdBn.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.IdBenhnhan], "");
                            objLuotkham = new Select().From(KcbLuotkham.Schema).Where(KcbLuotkham.Columns.IdBenhnhan).IsEqualTo(txtIdBn.Text)
                                .And(KcbLuotkham.Columns.MaLuotkham).IsEqualTo(txtMaluotkham.Text)
                                .ExecuteSingle<KcbLuotkham>();
                            dtpNgaynhapvien.Value = objLuotkham.NgayNhapvien.Value;
                            txtTenBN.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.TenBenhnhan], "");
                            txttuoi.Text = Utility.sDbnull(dt_Patient.Rows[0]["Tuoi"], "");
                            txtgioitinh.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.GioiTinh], "");
                            txtDiachi.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.DiaChi], "");
                            txtmatheBhyt.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.MatheBhyt], "");

                            txtKhoanoitru.Text = Utility.sDbnull(dt_Patient.Rows[0]["ten_khoaphong_noitru"], "");
                            txtBuong.Text = Utility.sDbnull(dt_Patient.Rows[0][NoitruDmucBuong.Columns.TenBuong], "");
                            txtGiuong.Text = Utility.sDbnull(dt_Patient.Rows[0][NoitruDmucGiuongbenh.Columns.TenGiuong], "");

                            txtIdkhoanoitru.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdKhoanoitru], "-1");
                            txtIdravien.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdRavien], "-1");
                            txtidBuong.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdBuong], "-1");
                            txtidgiuong.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdGiuong], "-1");
                            cmdChuyen.Enabled = true;
                            if (objLuotkham.TrangthaiNoitru == 0)
                            {
                                Utility.ShowMsg("Bệnh nhân chưa vào nội trú nên không thể lập phiếu ra viện. Đề nghị bạn kiểm tra lại");
                                cmdChuyen.Enabled = false;
                                return;
                            }
                            cmdChuyen.Enabled = objLuotkham != null && objLuotkham.TrangthaiNoitru <= 3;
                            LoadData();
                            dtpNgayravien.Focus();
                        }

                }
            }
            catch (Exception)
            {
                Utility.ShowMsg("Có lỗi trong quá trình lấy thông tin bệnh nhân");
            }
            finally
            {

                AllowTextChanged = true;
            }
        }
 void cmdgetPatient_Click(object sender, EventArgs e)
 {
     frm_DSACH_BN_TKIEM _DSACH_BN_TKIEM = new frm_DSACH_BN_TKIEM();
     if (_DSACH_BN_TKIEM.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         txtMaluotkham.Text = _DSACH_BN_TKIEM.MaLuotkham;
         txtMaluotkham_KeyDown(txtMaluotkham, new KeyEventArgs(Keys.Enter));
     }
 }
        private void txtPatient_Code_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                var dtPatient = new DataTable();
                if (e.KeyCode == Keys.Enter)
                {
                    Utility.FreeLockObject(m_strMaLuotkham);
                    string _patient_Code = Utility.AutoFullPatientCode(txtPatient_Code.Text);
                    ClearControl();
                    txtPatient_Code.Text = _patient_Code;
                    if (grdList.RowCount > 0 && PropertyLib._ThamKhamProperties.Timtrenluoi)
                    {
                        DataRow[] arrData_tempt = null;
                        arrData_tempt =
                            m_dtDanhsachbenhnhanthamkham.Select(KcbLuotkham.Columns.MaLuotkham + "='" + _patient_Code +
                                                                "'");
                        if (arrData_tempt.Length > 0)
                        {
                            string _status = radChuaKham.Checked ? "0" : "1";
                            string regStatus = Utility.sDbnull(arrData_tempt[0][KcbDangkyKcb.Columns.TrangThai], "0");
                            if (_status != regStatus)
                            {
                                if (regStatus == "1") radDaKham.Checked = true;
                                else
                                    radChuaKham.Checked = true;
                            }
                            Utility.GotoNewRowJanus(grdList, KcbLuotkham.Columns.MaLuotkham, _patient_Code);
                            if (Utility.isValidGrid(grdList)) grdList_DoubleClick(grdList, new EventArgs());
                            return;
                        }
                    }

                    dtPatient = _KCB_THAMKHAM.TimkiemBenhnhan(txtPatient_Code.Text,
                                                              Utility.Int32Dbnull(cboPhongKhamNgoaiTru.SelectedValue, -1),
                                                              0, 0);

                    DataRow[] arrPatients = dtPatient.Select(KcbLuotkham.Columns.MaLuotkham + "='" + _patient_Code + "'");
                    if (arrPatients.GetLength(0) <= 0)
                    {
                        if (dtPatient.Rows.Count > 1)
                        {
                            var frm = new frm_DSACH_BN_TKIEM();
                            frm.MaLuotkham = txtPatient_Code.Text;
                            frm.dtPatient = dtPatient;
                            frm.ShowDialog();
                            if (!frm.has_Cancel)
                            {
                                txtPatient_Code.Text = frm.MaLuotkham;
                            }
                        }
                    }
                    else
                    {
                        txtPatient_Code.Text = _patient_Code;
                    }
                    DataTable dt_Patient = _KCB_THAMKHAM.TimkiemThongtinBenhnhansaukhigoMaBN
                        (txtPatient_Code.Text, Utility.Int32Dbnull(cboPhongKhamNgoaiTru.SelectedValue, -1),
                         globalVariables.MA_KHOA_THIEN);

                    grdList.DataSource = null;
                    grdList.DataSource = dt_Patient;
                    if (dt_Patient.Rows.Count > 0)
                    {
                        grdList.MoveToRowIndex(0);
                        grdList.CurrentRow.BeginEdit();
                        grdList.CurrentRow.Cells["MAUSAC"].Value = 1;
                        grdList.CurrentRow.EndEdit();
                        if (dt_ICD_PHU != null) dt_ICD_PHU.Rows.Clear();
                        GetData();
                        txtPatient_Code.SelectAll();
                    }
                    else
                    {
                        string sPatientTemp = txtPatient_Code.Text;
                        m_strMaLuotkham = "";
                        objLuotkham = null;
                        objkcbdangky = null;
                        objBenhnhan = null;
                        ClearControl();

                        txtPatient_Code.Text = sPatientTemp;
                        txtPatient_Code.SelectAll();
                        //Utility.SetMsg(lblMsg, "Không tìm thấy bệnh nhân có mã lần khám đang chọn",true);
                    }
                    txtMach.SelectAll();
                }
            }
            catch (Exception)
            {
                Utility.ShowMsg("Có lỗi trong quá trình lấy thông tin bệnh nhân");
            }
            finally
            {
                ModifyCommmands();
            }
        }
        /// <summary>
        /// hàm thực hienej phím tắt của form hiện tại
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frm_QlyLsuthaydoiDoituongKCB_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F3)
            {
                if (this.ActiveControl != null && this.ActiveControl.Name == txtTEN_BN.Name && Utility.DoTrim(txtTEN_BN.Text) != "")
                {
                    frm_DSACH_BN_TKIEM Timkiem_Benhnhan = new frm_DSACH_BN_TKIEM();
                    Timkiem_Benhnhan.AutoSearch = true;
                    Timkiem_Benhnhan.FillAndSearchData(false, "", "", Utility.DoTrim(txtTEN_BN.Text), "", "", "-1");
                    if (Timkiem_Benhnhan.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        ucBHYT1.ClearNoiDKKCBBD();
                        isAutoFinding = true;
                        FindPatient(Timkiem_Benhnhan.IdBenhnhan.ToString());
                        isAutoFinding = false;
                    }
                }
                else if (this.ActiveControl != null && this.ActiveControl.Name == txtCMT.Name && Utility.DoTrim(txtCMT.Text) != "")
                {
                    frm_DSACH_BN_TKIEM Timkiem_Benhnhan = new frm_DSACH_BN_TKIEM();
                    Timkiem_Benhnhan.AutoSearch = true;
                    Timkiem_Benhnhan.FillAndSearchData(false, "", "", "", Utility.DoTrim(txtCMT.Text), "", "-1");
                    if (Timkiem_Benhnhan.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        ucBHYT1.ClearNoiDKKCBBD();
                        isAutoFinding = true;
                        FindPatient(Timkiem_Benhnhan.IdBenhnhan.ToString());
                        isAutoFinding = false;
                    }
                }

                return;
            }

            if (e.Control && e.KeyCode == Keys.D)
            {

                _MaDoituongKcb = "DV";
                cboDoituongKCB.SelectedIndex = Utility.GetSelectedIndex(cboDoituongKCB, _MaDoituongKcb);
                return;
            }
            if (e.Control && e.KeyCode == Keys.B)
            {
                _MaDoituongKcb = "BHYT";
                cboDoituongKCB.SelectedIndex = Utility.GetSelectedIndex(cboDoituongKCB, _MaDoituongKcb);
                return;
            }
            if (e.Control && (e.KeyCode == Keys.C || e.KeyCode == Keys.P))
            {
                AllowTextChanged = false;
                txtDiachi.Text = ucBHYT1.txtDiachi_bhyt.Text;
                AllowTextChanged = true;
                return;
            }

            string ngay_kham = globalVariables.SysDate.ToString("dd/MM/yyyy");

            if (e.Control && e.KeyCode == Keys.F)
            {
                txtMaBN.SelectAll();
                txtMaBN.Focus();
            }

            //if (e.KeyCode == Keys.F1)
            //{
            //    tabControl1.SelectedTab = tabControl1.TabPages[0];
            //    return;
            //}
            //if (e.KeyCode == Keys.F2)
            //{
            //    tabControl1.SelectedTab = tabControl1.TabPages[1];
            //    return;
            //}
            if (e.KeyCode == Keys.F11) Utility.ShowMsg(this.ActiveControl.Name);
            if (e.KeyCode == Keys.Escape && this.ActiveControl != null
                && (
                this.ActiveControl.GetType() != txtDiachi.GetType()
                || this.ActiveControl.GetType() != txtNoichuyenden.GetType()
                ))
            {

                Close();
            }
            if (e.KeyCode == Keys.S && e.Control) cmdSave.PerformClick();
            if (e.KeyCode == Keys.N && e.Control) cmdExit.PerformClick();
            if (e.KeyCode == Keys.Enter) SendKeys.Send("{TAB}");
        }
        private void txtPatient_Code_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                var dtPatient = new DataTable();
                if (e.KeyCode == Keys.Enter)
                {
                    string _patient_Code = Utility.AutoFullPatientCode(txtPatient_Code.Text);
                    ClearControl();
                    dtPatient = _KCB_THAMKHAM.TimkiemBenhnhan(txtPatient_Code.Text,
                                                   -1,(byte)1, 0);

                    DataRow[] arrPatients = dtPatient.Select(KcbLuotkham.Columns.MaLuotkham + "='" + _patient_Code + "'");
                    if (arrPatients.GetLength(0) <= 0)
                    {
                        if (dtPatient.Rows.Count > 1)
                        {
                            var frm = new frm_DSACH_BN_TKIEM();
                            frm.MaLuotkham = txtPatient_Code.Text;
                            frm.dtPatient = dtPatient;
                            frm.ShowDialog();
                            if (!frm.has_Cancel)
                            {
                                txtPatient_Code.Text = frm.MaLuotkham;
                            }
                        }
                        else
                            txtPatient_Code.Text = _patient_Code;
                    }
                    else
                    {
                        txtPatient_Code.Text = _patient_Code;
                    }
                    objLuotkham = Utility.getKcbLuotkham(txtPatient_Code.Text);

                    if (objLuotkham!=null)
                    {
                        cmdInphoiBHYT.Visible = THU_VIEN_CHUNG.IsBaoHiem(objLuotkham.IdLoaidoituongKcb);
                        AllowTextChanged = false;
                        GetData();
                        txtPatient_Code.SelectAll();
                        if (objLuotkham.TrangthaiNoitru == 0)
                        {
                            Utility.ShowMsg("Bệnh nhân chưa nhập viện nội trú nên bạn không thể lập phiếu ra viện được. Đề nghị bạn kiểm tra lại");

                        }
                        //Kiểm tra lần nhập viện hoặc chuyển khoa gần nhất phải được phân buồng giường trước khi ra viện
                        NoitruPhanbuonggiuong objNoitruPhanbuonggiuong = NoitruPhanbuonggiuong.FetchByID(objLuotkham.IdRavien);
                        bool isValid = Utility.Int16Dbnull(objNoitruPhanbuonggiuong.IdBuong, 0) > 0 && Utility.Int16Dbnull(objNoitruPhanbuonggiuong.IdBuong, 0) > 0;
                        if (!isValid)
                        {
                            Utility.ShowMsg("Hệ thống phát hiện Bệnh nhân chưa được phân buồng giường cho lần chuyển khoa gần nhất nên bạn không thể tổng hợp ra viện được.");
                        }
                        cmdRavien.Enabled = cmdTonghop.Enabled = isValid && objLuotkham.TrangthaiNoitru > 0;
                    }
                    else
                    {
                        string sPatientTemp = txtPatient_Code.Text;
                        ClearControl();
                        ModifyCommmands();
                        txtPatient_Code.Text = sPatientTemp;
                        Utility.ShowMsg("Không tìm được Bệnh nhân nào có mã lượt khám " + txtPatient_Code.Text);
                        txtPatient_Code.SelectAll();
                        cmdRavien.Enabled = cmdTonghop.Enabled = false;

                    }

                }
            }
            catch (Exception)
            {
                Utility.ShowMsg("Có lỗi trong quá trình lấy thông tin bệnh nhân");
            }
            finally
            {
                AllowTextChanged = true;
            }
        }
Beispiel #8
0
        public void txtMaluotkham_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter && Utility.DoTrim(txtMaluotkham.Text) != "")
                {
                    AllowTextChanged = false;
                    var dtPatient = new DataTable();

                    objLuotkham = null;
                    string _patient_Code = Utility.AutoFullPatientCode(txtMaluotkham.Text);
                    ClearControls();

                    dtPatient = new KCB_THAMKHAM().TimkiemBenhnhan(txtMaluotkham.Text,
                                                                   -1, 1, 0);

                    DataRow[] arrPatients = dtPatient.Select(KcbLuotkham.Columns.MaLuotkham + "='" + _patient_Code + "'");
                    if (arrPatients.GetLength(0) <= 0)
                    {
                        if (dtPatient.Rows.Count > 1)
                        {
                            var frm = new frm_DSACH_BN_TKIEM("ALL");
                            frm.MaLuotkham = txtMaluotkham.Text;
                            frm.dtPatient  = dtPatient;
                            frm.ShowDialog();
                            if (!frm.has_Cancel)
                            {
                                txtMaluotkham.Text = frm.MaLuotkham;
                            }
                        }
                    }
                    else
                    {
                        txtMaluotkham.Text = _patient_Code;
                    }
                    DataTable dt_Patient =
                        new KCB_THAMKHAM().NoitruTimkiemThongtinBenhnhansaukhigoMaBN(txtMaluotkham.Text, -1, "ALL");
                    if (dt_Patient != null && dt_Patient.Rows.Count > 0)
                    {
                        txtIdBn.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.IdBenhnhan], "");
                        objLuotkham  =
                            new Select().From(KcbLuotkham.Schema)
                            .Where(KcbLuotkham.Columns.IdBenhnhan)
                            .IsEqualTo(txtIdBn.Text)
                            .And(KcbLuotkham.Columns.MaLuotkham).IsEqualTo(txtMaluotkham.Text)
                            .ExecuteSingle <KcbLuotkham>();
                        dtpNgaynhapvien.Value = objLuotkham.NgayNhapvien.Value;
                        txtTenBN.Text         = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.TenBenhnhan], "");
                        txttuoi.Text          = Utility.sDbnull(dt_Patient.Rows[0]["Tuoi"], "");
                        txtgioitinh.Text      = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.GioiTinh], "");
                        txtDiachi.Text        = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.DiaChi], "");
                        txtmatheBhyt.Text     = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.MatheBhyt], "");
                        txtKhoanoitru.Text    = Utility.sDbnull(dt_Patient.Rows[0]["ten_khoaphong_noitru"], "");
                        txtBuong.Text         = Utility.sDbnull(dt_Patient.Rows[0][NoitruDmucBuong.Columns.TenBuong], "");
                        txtGiuong.Text        = Utility.sDbnull(dt_Patient.Rows[0][NoitruDmucGiuongbenh.Columns.TenGiuong], "");
                        txtBenhchinh.SetCode(Utility.sDbnull(dt_Patient.Rows[0]["mabenh_chinh"], ""));
                        txtIdkhoanoitru.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdKhoanoitru], "-1");
                        txtIdravien.Text     = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdRavien], "-1");
                        txtidBuong.Text      = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdBuong], "-1");
                        txtidgiuong.Text     = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdGiuong], "-1");
                        cmdChuyen.Enabled    = true;
                        if (objLuotkham.TrangthaiNoitru == 0)
                        {
                            Utility.ShowMsg(
                                "Bệnh nhân chưa vào nội trú nên không thể lập phiếu ra viện. Đề nghị bạn kiểm tra lại");
                            cmdChuyen.Enabled = false;
                            return;
                        }
                        cmdChuyen.Enabled = objLuotkham != null && objLuotkham.TrangthaiNoitru <= 3;
                        LoadData();
                        dtpNgayravien.Focus();
                    }
                }
            }
            catch (Exception)
            {
                Utility.ShowMsg("Có lỗi trong quá trình lấy thông tin bệnh nhân");
            }
            finally
            {
                AllowTextChanged = true;
            }
        }
        private void txtPatient_Code_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                var dtPatient = new DataTable();
                if (e.KeyCode == Keys.Enter)
                {
                    string _patient_Code = Utility.AutoFullPatientCode(txtmaluotkham.Text);
                    ClearControl();
                    txtmaluotkham.Text = _patient_Code;
                    dtPatient = _KCB_THAMKHAM.TimkiemBenhnhan(txtmaluotkham.Text,
                                                   -1,(byte)2, 0);

                    string PatientCodeFilter = globalVariables.SysDate.Year.ToString().Substring(2, 2) +
                                               txtPatient_Code.Text.PadLeft(6, '0');
                    DataRow[] arrPatients = dtPatient.Select(KcbLuotkham.Columns.MaLuotkham + "='" + PatientCodeFilter + "'");
                    if (arrPatients.GetLength(0) <= 0)
                    {
                        if (dtPatient.Rows.Count > 1)
                        {
                            var frm = new frm_DSACH_BN_TKIEM();
                            frm.MaLuotkham = txtmaluotkham.Text;
                            frm.dtPatient = dtPatient;
                            frm.ShowDialog();
                            if (!frm.has_Cancel)
                            {
                                txtmaluotkham.Text = frm.MaLuotkham;
                            }
                        }
                    }
                    else
                    {
                        txtmaluotkham.Text = PatientCodeFilter;
                    }
                    DataTable dt_Patient = _KCB_THAMKHAM.TimkiemThongtinBenhnhansaukhigoMaBN(txtmaluotkham.Text,
                                                              -1,globalVariables.MA_KHOA_THIEN);
                    grdList.DataSource = null;
                    grdList.DataSource = dt_Patient;
                    if (dt_Patient.Rows.Count > 0)
                    {
                        grdList.MoveToRowIndex(0);
                        grdList.CurrentRow.BeginEdit();
                        grdList.CurrentRow.Cells["MAUSAC"].Value = 1;
                        grdList.CurrentRow.EndEdit();
                        AllowTextChanged = false;
                        if (dt_ICD_PHU != null) dt_ICD_PHU.Rows.Clear();
                        GetData();
                        txtPatient_Code.SelectAll();
                    }
                    else
                    {
                        string sPatientTemp = txtPatient_Code.Text;
                        ClearControl();

                        txtmaluotkham.Text = sPatientTemp;
                        txtmaluotkham.SelectAll();
                    }
                }
            }
            catch (Exception)
            {
                Utility.ShowMsg("Có lỗi trong quá trình lấy thông tin bệnh nhân");
            }
            finally
            {
                AllowTextChanged = true;
            }
        }
        public void txtMaluotkham_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter && Utility.DoTrim(txtMaluotkham.Text) != "")
                {
                    var dtPatient = new DataTable();

                        objLuotkham = null;
                        string _patient_Code = Utility.AutoFullPatientCode(txtMaluotkham.Text);
                        ClearControls();

                        dtPatient = new KCB_THAMKHAM().TimkiemBenhnhan(txtMaluotkham.Text,
                                                       -1,0, 0);

                        DataRow[] arrPatients = dtPatient.Select(KcbLuotkham.Columns.MaLuotkham + "='" + _patient_Code + "'");
                        if (arrPatients.GetLength(0) <= 0)
                        {
                            if (dtPatient.Rows.Count > 1)
                            {
                                var frm = new frm_DSACH_BN_TKIEM();
                                frm.MaLuotkham = txtMaluotkham.Text;
                                frm.dtPatient = dtPatient;
                                frm.ShowDialog();
                                if (!frm.has_Cancel)
                                {
                                    txtMaluotkham.Text = frm.MaLuotkham;
                                }
                            }
                        }
                        else
                        {
                            txtMaluotkham.Text = _patient_Code;
                        }
                        DataTable dt_Patient = new KCB_THAMKHAM().TimkiemThongtinBenhnhansaukhigoMaBN(txtMaluotkham.Text, -1, globalVariables.MA_KHOA_THIEN);
                        if (dt_Patient != null && dt_Patient.Rows.Count > 0)
                        {

                            txtIdBn.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.IdBenhnhan], "");
                            objLuotkham = new Select().From(KcbLuotkham.Schema).Where(KcbLuotkham.Columns.IdBenhnhan).IsEqualTo(txtIdBn.Text)
                                .And(KcbLuotkham.Columns.MaLuotkham).IsEqualTo(txtMaluotkham.Text)
                                .ExecuteSingle<KcbLuotkham>();
                            txtTenBN.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.TenBenhnhan], "");
                            txttuoi.Text = Utility.sDbnull(dt_Patient.Rows[0]["Tuoi"], "");
                            txtgioitinh.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.GioiTinh], "");
                            txtDiaChi.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbDanhsachBenhnhan.Columns.DiaChi], "");
                            txtmatheBhyt.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.MatheBhyt], "");

                            txtKhoanoitru.Text = Utility.sDbnull(dt_Patient.Rows[0]["ten_khoaphong_noitru"], "");
                            txtBuong.Text = Utility.sDbnull(dt_Patient.Rows[0][NoitruDmucBuong.Columns.TenBuong], "");
                            txtGiuong.Text = Utility.sDbnull(dt_Patient.Rows[0][NoitruDmucGiuongbenh.Columns.TenGiuong], "");

                            txtIdkhoanoitru.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdKhoanoitru], "-1");
                            txtIdravien.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdRavien], "-1");
                            txtidBuong.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdBuong], "-1");
                            txtidgiuong.Text = Utility.sDbnull(dt_Patient.Rows[0][KcbLuotkham.Columns.IdGiuong], "-1");

                            objPhieuchuyenvien = new Select().From(KcbPhieuchuyenvien.Schema)
                               .Where(KcbPhieuchuyenvien.Columns.IdBenhnhan).IsEqualTo(txtIdBn.Text)
                               .And(KcbPhieuchuyenvien.Columns.MaLuotkham).IsEqualTo(txtMaluotkham.Text)
                               .ExecuteSingle<KcbPhieuchuyenvien>();
                            if (objPhieuchuyenvien != null)
                            {
                                txtId.Text = objPhieuchuyenvien.IdPhieu.ToString();
                                txtNoichuyenden.SetId(objPhieuchuyenvien.IdBenhvienChuyenden);
                                txtdauhieucls._Text = objPhieuchuyenvien.DauhieuCls;
                                txtketquaCls.Text = objPhieuchuyenvien.KetquaXnCls;
                                txtChandoan.Text = objPhieuchuyenvien.ChanDoan;
                                txtThuocsudung.Text = objPhieuchuyenvien.ThuocSudung;
                                txtTrangthainguoibenh._Text = objPhieuchuyenvien.TrangthaiBenhnhan;
                                txtHuongdieutri._Text = objPhieuchuyenvien.HuongDieutri;
                                txtphuongtienvc._Text = objPhieuchuyenvien.PhuongtienChuyen;
                                txtNguoivanchuyen.Text = objPhieuchuyenvien.TenNguoichuyen;
                                cboDoctorAssign.SelectedIndex = Utility.GetSelectedIndex(cboDoctorAssign,Utility.sDbnull( objPhieuchuyenvien.IdBacsiChuyenvien,"-1"));
                                cmdPrint.Enabled = true;
                                cmdHuy.Enabled = true;
                            }
                            else
                            {
                                cmdPrint.Enabled = false;
                                cmdHuy.Enabled = false;
                            }
                            m_enAct = objPhieuchuyenvien == null ? action.Insert : action.Update;
                            if (m_enAct == action.Insert)
                                cmdPrint.Enabled = false;
                            else
                                cmdPrint.Enabled = true;
                            dtNgaychuyenvien.Focus();
                        }

                }
            }
            catch (Exception)
            {
                Utility.ShowMsg("Có lỗi trong quá trình lấy thông tin bệnh nhân");
            }
            finally
            {

                AllowTextChanged = true;
            }
        }
        /// <summary>
        /// hàm thực hienej phím tắt của form hiện tại
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frm_Taobenhnhancapcuu_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F3)
            {
                if (this.ActiveControl != null && this.ActiveControl.Name == txtTEN_BN.Name && Utility.DoTrim(txtTEN_BN.Text)!="")
                {
                    frm_DSACH_BN_TKIEM Timkiem_Benhnhan = new frm_DSACH_BN_TKIEM();
                    Timkiem_Benhnhan.AutoSearch = true;
                    Timkiem_Benhnhan.FillAndSearchData(false, "", "", Utility.DoTrim(txtTEN_BN.Text), "", "", "-1");
                    if (Timkiem_Benhnhan.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        ucBHYT1.ClearNoiDKKCBBD();
                        isAutoFinding = true;
                        FindPatient(Timkiem_Benhnhan.IdBenhnhan.ToString());
                        isAutoFinding = false;
                    }
                }
                else if (this.ActiveControl != null && this.ActiveControl.Name == txtCMT.Name && Utility.DoTrim(txtCMT.Text) != "")
                {
                    frm_DSACH_BN_TKIEM Timkiem_Benhnhan = new frm_DSACH_BN_TKIEM();
                    Timkiem_Benhnhan.AutoSearch = true;
                    Timkiem_Benhnhan.FillAndSearchData(false, "", "", "", Utility.DoTrim(txtCMT.Text), "", "-1");
                    if (Timkiem_Benhnhan.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        ucBHYT1.ClearNoiDKKCBBD();
                        isAutoFinding = true;
                        FindPatient(Timkiem_Benhnhan.IdBenhnhan.ToString());
                        isAutoFinding = false;
                    }
                }
                else if (this.ActiveControl != null && this.ActiveControl.Name == txtSoDT.Name && Utility.DoTrim(txtSoDT.Text) != "")
                {
                    frm_DSACH_BN_TKIEM Timkiem_Benhnhan = new frm_DSACH_BN_TKIEM();
                    Timkiem_Benhnhan.AutoSearch = true;
                    Timkiem_Benhnhan.FillAndSearchData(false, "", "", "", "", Utility.DoTrim(txtSoDT.Text), "-1");
                    if (Timkiem_Benhnhan.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        ucBHYT1.ClearNoiDKKCBBD();
                        isAutoFinding = true;
                        FindPatient(Timkiem_Benhnhan.IdBenhnhan.ToString());
                        isAutoFinding = false;
                    }
                }
                return;
            }

            if (e.Control && e.KeyCode == Keys.D)
            {

                _MaDoituongKcb = "DV";
                cboDoituongKCB.SelectedIndex = Utility.GetSelectedIndex(cboDoituongKCB, _MaDoituongKcb);
                return;
            }
            if (e.Control && e.KeyCode == Keys.B)
            {
                _MaDoituongKcb = "BHYT";
                cboDoituongKCB.SelectedIndex = Utility.GetSelectedIndex(cboDoituongKCB, _MaDoituongKcb);
                return;
            }
            if (e.Control && (e.KeyCode == Keys.C || e.KeyCode == Keys.P))
            {
                AllowTextChanged = false;
                txtDiachi._Text = ucBHYT1.txtDiachi_bhyt.Text;
                AllowTextChanged = true;
                return;
            }

            string ngay_kham = globalVariables.SysDate.ToString("dd/MM/yyyy");
            if (e.Control && e.KeyCode == Keys.K)
            {
                if (!NotPayment(txtMaBN.Text.Trim(), ref ngay_kham))
                {
                    m_enAction = action.Add;
                    SinhMaLanKham();
                    txtKhoanoitru.Focus();
                }
                else
                {
                    //nếu là ngày hiện tại thì đặt về trạng thái sửa
                    if (ngay_kham == globalVariables.SysDate.ToString("dd/MM/yyyy"))
                    {
                        Utility.ShowMsg(
                            "Bệnh nhân đang có lần khám chưa được thanh toán. Cần thanh toán hết các lần đến khám bệnh của Bệnh nhân trước khi thêm lần khám mới.Nhấn OK để hệ thống quay về trạng thái sửa thông tin BN");
                        m_enAction = action.Update;
                        AllowTextChanged = false;
                        LoadThongtinBenhnhan();
                        txtTEN_BN.Focus();
                    }
                    else //Không cho phép thêm lần khám khác nếu chưa thanh toán lần khám của ngày hôm trước
                    {
                        Utility.ShowMsg(
                            "Bệnh nhân đang có lần khám chưa được thanh toán. Cần thanh toán hết các lần đến khám bệnh của Bệnh nhân trước khi thêm lần khám mới. Nhấn OK để hệ thống chuyển về trạng thái thêm mới Bệnh nhân");
                        cmdThemMoiBN_Click(cmdThemMoiBN, new EventArgs());
                    }
                }
                return;
            }
            if (e.Control && e.KeyCode == Keys.F)
            {
                txtMaBN.SelectAll();
                txtMaBN.Focus();
            }

            if (e.KeyCode == Keys.F1)
            {
                tabControl1.SelectedTab = tabControl1.TabPages[0];
                return;
            }
            if (e.KeyCode == Keys.F2)
            {
                tabControl1.SelectedTab = tabControl1.TabPages[1];
                return;
            }
            if (e.KeyCode == Keys.F11) Utility.ShowMsg(this.ActiveControl.Name);
            if (e.KeyCode == Keys.Escape && this.ActiveControl != null
                && (
                this.ActiveControl.GetType()!=txtDantoc.GetType()
                || this.ActiveControl.GetType()!=txtGia.GetType()
                ))
            {

                Close();
            }
            if (e.KeyCode == Keys.S && e.Control) cmdSave.PerformClick();
            if (e.KeyCode == Keys.N && e.Control) cmdThemMoiBN.PerformClick();
            if (this.ActiveControl != null && this.ActiveControl.Name != ucTamung1.Name && e.KeyCode == Keys.Enter) SendKeys.Send("{TAB}");
        }