private void PerformAction()
        {
            try
            {

                if (objBenhnhan != null)
                {
                    if (INPHIEU_CLICK)
                    {
                        goto INPHIEU;
                    }
                    if (PropertyLib._ThanhtoanProperties.Hoitruockhithanhtoan)
                        if (!Utility.AcceptQuestion("Bạn có muốn thanh toán cho bệnh nhân này không", "Thông báo thanh toán", true))
                        {
                            return;
                        }

                    //Nếu thanh toán khi in phôi thì không cần hỏi
                INPHIEU:
                    bool IN_HOADON = false;
                    string ErrMsg = "";
                    long IdHdonLog = -1;
                    IN_HOADON = Utility.DecimaltoDbnull(txtSoTienCanNop.Text, 0) > 0;
                    if (IN_HOADON)
                    {

                    }

                    List<KcbThanhtoanChitiet> lstItems = Taodulieuthanhtoanchitiet(ref ErrMsg);
                    if (lstItems == null)
                    {
                        Utility.ShowMsg("Lỗi khi tạo dữ liệu thanh toán chi tiết. Liên hệ đơn vị cung cấp phần mềm để được hỗ trợ\n" + ErrMsg);
                        return;
                    }
                    TongtienCK_chitiet = Utility.DecimaltoDbnull(txtTienChietkhau.Text);
                    if (chkChietkhauthem.Checked || TongtienCK_chitiet > 0)
                    {
                        frm_ChietkhauTrenHoadon _ChietkhauTrenHoadon = new frm_ChietkhauTrenHoadon();
                        _ChietkhauTrenHoadon.TongCKChitiet = Utility.DecimaltoDbnull(txtTienChietkhau.Text);
                        _ChietkhauTrenHoadon.TongtienBN = Utility.DecimaltoDbnull(txtSoTienCanNop.Text) + Utility.DecimaltoDbnull(txtTienChietkhau.Text);
                        _ChietkhauTrenHoadon.ShowDialog();
                        if (!_ChietkhauTrenHoadon.m_blnCancel)
                        {
                            TongtienCK = _ChietkhauTrenHoadon.TongtienCK;
                            TongtienCK_Hoadon = _ChietkhauTrenHoadon.TongCKHoadon;
                            ma_ldoCk = _ChietkhauTrenHoadon.ma_ldoCk;
                        }
                        else
                        {
                            if (TongtienCK_chitiet > 0)
                            {
                                Utility.ShowMsg("Bạn vừa thực hiện hủy thao tác nhập thông tin chiết khấu. Yêu cầu bạn nhập lý do chiết khấu(Do tiền chiết khấu >0). Mời bạn bấm lại nút thanh toán để bắt đầu lại");
                                return;
                            }
                            else
                            {
                                if (!Utility.AcceptQuestion("Bạn vừa thực hiện hủy thao tác nhập thông tin chiết khấu. Bạn có muốn tiếp tục thanh toán không cần chiết khấu hay không?"))
                                {
                                    return;
                                }
                            }
                        }
                    }
                    ActionResult actionResult = _THANHTOAN.ThanhtoanDonthuoctaiquay(CreatePayment(), objBenhnhan, lstItems, ref v_Payment_ID, -1, false);

                    switch (actionResult)
                    {
                        case ActionResult.Success:
                            LaydanhsachLichsuthanhtoan();
                            GetDataChiTiet();
                            Utility.GotoNewRowJanus(grdPayment, KcbThanhtoan.Columns.IdThanhtoan, v_Payment_ID.ToString());
                            if (v_Payment_ID <= 0)
                            {
                                grdPayment.MoveFirst();
                            }
                            //Tạm rem phần hóa đơn đỏ lại
                            if (IN_HOADON && PropertyLib._MayInProperties.TudonginhoadonSaukhiThanhtoan)
                            {
                                int KCB_THANHTOAN_KIEUINHOADON = Utility.Int32Dbnull(THU_VIEN_CHUNG.Laygiatrithamsohethong("KCB_THANHTOAN_KIEUINHOADON", "1", false));
                                if (KCB_THANHTOAN_KIEUINHOADON == 1 || KCB_THANHTOAN_KIEUINHOADON == 3)
                                    InHoadon();
                                if (KCB_THANHTOAN_KIEUINHOADON == 2 || KCB_THANHTOAN_KIEUINHOADON == 3)
                                    new INPHIEU_THANHTOAN_NGOAITRU().InBienlaiQuaythuoc(false, v_Payment_ID);
                            }
                            if (THU_VIEN_CHUNG.Laygiatrithamsohethong("KCB_THANHTOAN_SUDUNGHOADONDO", "0", false)=="1")
                            {

                            }
                            if (PropertyLib._ThanhtoanProperties.HienthidichvuNgaysaukhithanhtoan)
                            {
                                ShowPaymentDetail(v_Payment_ID);
                            }
                            break;
                        case ActionResult.Error:
                            Utility.ShowMsg("Lỗi trong quá trình thanh toán", "Thông báo lỗi", MessageBoxIcon.Error);
                            break;
                    }
                    IN_HOADON = false;
                    INPHIEU_CLICK = false;
                }
            }
            catch (Exception exception)
            {

            }
            finally
            {
                TongtienCK = 0m;
                TongtienCK_chitiet = 0m;
                TongtienCK_Hoadon = 0m;
                ma_ldoCk = "";
                ModifyPresCommand();
                ModifyCommand();
            }
        }
        private void PerformAction()
        {
            try
            {
                objLuotkham = Utility.getKcbLuotkham(Utility.Int64Dbnull(txtPatient_ID.Text), Utility.DoTrim(txtPatient_Code.Text));
                if (objLuotkham != null)
                {
                    if (INPHIEU_CLICK)
                    {
                        goto INPHIEU;
                    }
                    if (PropertyLib._ThanhtoanProperties.Hoitruockhithanhtoan)
                        if (!Utility.AcceptQuestion("Bạn có muốn thanh toán cho bệnh nhân này không", "Thông báo thanh toán", true))
                        {
                            return;
                        }

                    //Nếu thanh toán khi in phôi thì không cần hỏi
                INPHIEU:
                    bool IN_HOADON = false;
                    string ErrMsg = "";
                    long IdHdonLog = -1;
                    IN_HOADON = Utility.DecimaltoDbnull(txtSoTienCanNop.Text, 0) > 0;
                    if (IN_HOADON)
                    {
                        if (chkLayHoadon.Checked)//nếu lấy hóa đơn đỏ mới kiểm tra
                        {
                            if (THU_VIEN_CHUNG.Laygiatrithamsohethong("KCB_THANHTOAN_SUDUNGHOADONDO", "0", false)=="1")//Chỉ khi dùng hóa đơn đỏ mới kiểm tra tiếp.
                            {
                                if (grdHoaDonCapPhat.RowCount<=0)
                                {
                                    uiTabHoadon_chiphi.SelectedTab = tabpageHoaDon;
                                    Utility.ShowMsg("Bạn cần khai báo quyển hóa đơn đỏ trước khi sử dụng tính năng thanh toán với hóa đơn đỏ");
                                    return;
                                }
                                if (!Utility.isValidGrid(grdHoaDonCapPhat))
                                {
                                    uiTabHoadon_chiphi.SelectedTab = tabpageHoaDon;
                                    Utility.ShowMsg("Mời bạn chọn quyển hóa đơn thanh toán");
                                    return;
                                }
                                if (!checkSerie(ref IdHdonLog))
                                {
                                    return;
                                }
                            }
                        }
                    }

                    List<KcbThanhtoanChitiet> lstItems = Taodulieuthanhtoanchitiet(ref ErrMsg);
                    if (lstItems == null)
                    {
                        Utility.ShowMsg("Lỗi khi tạo dữ liệu thanh toán chi tiết. Liên hệ đơn vị cung cấp phần mềm để được hỗ trợ\n" + ErrMsg);
                        return;
                    }
                    TongtienCK_chitiet = Utility.DecimaltoDbnull(txtTienChietkhau.Text);
                    if (chkChietkhauthem.Checked || TongtienCK_chitiet > 0)
                    {
                        frm_ChietkhauTrenHoadon _ChietkhauTrenHoadon = new frm_ChietkhauTrenHoadon();
                        _ChietkhauTrenHoadon.TongCKChitiet = Utility.DecimaltoDbnull(txtTienChietkhau.Text);
                        _ChietkhauTrenHoadon.TongtienBN = Utility.DecimaltoDbnull(txtSoTienCanNop.Text) + Utility.DecimaltoDbnull(txtTienChietkhau.Text);
                        _ChietkhauTrenHoadon.ShowDialog();
                        if (!_ChietkhauTrenHoadon.m_blnCancel)
                        {
                            TongtienCK = _ChietkhauTrenHoadon.TongtienCK;
                            TongtienCK_Hoadon = _ChietkhauTrenHoadon.TongCKHoadon;
                            ma_ldoCk = _ChietkhauTrenHoadon.ma_ldoCk;
                        }
                        else
                        {
                            if (TongtienCK_chitiet > 0)
                            {
                                Utility.ShowMsg("Bạn vừa thực hiện hủy thao tác nhập thông tin chiết khấu. Yêu cầu bạn nhập lý do chiết khấu(Do tiền chiết khấu >0). Mời bạn bấm lại nút thanh toán để bắt đầu lại");
                                return;
                            }
                            else
                            {
                                if (!Utility.AcceptQuestion("Bạn vừa thực hiện hủy thao tác nhập thông tin chiết khấu. Bạn có muốn tiếp tục thanh toán không cần chiết khấu hay không?","Xác nhận chiết khấu",true))
                                {
                                    return;
                                }
                            }
                        }
                    }
                    decimal TTBN_Chitrathucsu = 0;
                     ErrMsg = "";
                    ActionResult actionResult = _THANHTOAN.ThanhtoanChiphiDVuKCB(TaophieuThanhtoan(), objLuotkham, lstItems, ref v_Payment_ID, IdHdonLog, chkLayHoadon.Checked && THU_VIEN_CHUNG.Laygiatrithamsohethong("KCB_THANHTOAN_SUDUNGHOADONDO", "0", false) == "1", ref TTBN_Chitrathucsu, ref ErrMsg);

                    IN_HOADON = TTBN_Chitrathucsu > 0;
                    switch (actionResult)
                    {
                        case ActionResult.Success:
                            LaydanhsachLichsuthanhtoan_phieuchi();
                            GetDataChiTiet();
                            Utility.GotoNewRowJanus(grdPayment, KcbThanhtoan.Columns.IdThanhtoan, v_Payment_ID.ToString());
                            if (v_Payment_ID <= 0)
                            {
                                grdPayment.MoveFirst();
                            }
                            txtPatient_Code.Focus();
                            txtPatient_Code.SelectAll();
                            //Tạm rem phần hóa đơn đỏ lại
                            if (IN_HOADON && PropertyLib._MayInProperties.TudonginhoadonSaukhiThanhtoan)
                            {
                                int KCB_THANHTOAN_KIEUINHOADON = Utility.Int32Dbnull(THU_VIEN_CHUNG.Laygiatrithamsohethong("KCB_THANHTOAN_KIEUINHOADON", "1", false));
                                if (KCB_THANHTOAN_KIEUINHOADON == 1 || KCB_THANHTOAN_KIEUINHOADON == 3)
                                    InHoadon();
                                if (KCB_THANHTOAN_KIEUINHOADON == 2 || KCB_THANHTOAN_KIEUINHOADON == 3)
                                    new INPHIEU_THANHTOAN_NGOAITRU().InBienlai(false, v_Payment_ID, objLuotkham);
                            }
                            if (THU_VIEN_CHUNG.Laygiatrithamsohethong("KCB_THANHTOAN_SUDUNGHOADONDO", "0", false)=="1")
                            {
                                grdHoaDonCapPhat.CurrentRow.BeginEdit();
                                grdHoaDonCapPhat.CurrentRow.Cells[HoadonCapphat.Columns.SerieHientai].Value = Utility.sDbnull(txtSerie.Text);
                                grdHoaDonCapPhat.CurrentRow.EndEdit();
                                txtSerie.Text = Utility.sDbnull(Utility.Int32Dbnull(txtSerie.Text) + 1);
                                txtSerie.Text = txtSerie.Text.PadLeft(Utility.sDbnull(txtSerieDau.Text).Length, '0');
                            }
                            if (PropertyLib._ThanhtoanProperties.HienthidichvuNgaysaukhithanhtoan)
                            {
                                ShowPaymentDetail(v_Payment_ID);
                            }
                            break;
                        case ActionResult.Error:
                            Utility.ShowMsg("Lỗi trong quá trình thanh toán", "Thông báo lỗi", MessageBoxIcon.Error);
                            break;
                        case ActionResult.Cancel:
                            Utility.ShowMsg(ErrMsg);
                            break;
                    }
                    IN_HOADON = false;
                    INPHIEU_CLICK = false;
                }
            }
            catch (Exception exception)
            {

            }
            finally
            {
                TongtienCK = 0m;
                TongtienCK_chitiet = 0m;
                TongtienCK_Hoadon = 0m;
                ma_ldoCk = "";
                ModifyCommand();
            }
        }
        private void PerformAction()
        {
            try
            {
                objLuotkham = CreatePatientExam();
                if (objLuotkham != null)
                {
                    if (INPHIEU_CLICK)
                    {
                        goto INPHIEU;
                    }
                    if (PropertyLib._ThanhtoanProperties.Hoitruockhithanhtoan)
                        if (!Utility.AcceptQuestion("Bạn có muốn thanh toán cho bệnh nhân này không", "Thông báo thanh toán", true))
                        {
                            return;
                        }

                    //Nếu thanh toán khi in phôi thì không cần hỏi
                INPHIEU:
                    bool IN_HOADON = false;
                    string ErrMsg = "";
                    IN_HOADON = Utility.DecimaltoDbnull(txtSoTienCanNop.Text, 0) > 0;
                    List<KcbThanhtoanChitiet> lstItems = Taodulieuthanhtoanchitiet(ref ErrMsg);
                    if (lstItems == null)
                    {
                        Utility.ShowMsg("Lỗi khi tạo dữ liệu thanh toán chi tiết. Liên hệ đơn vị cung cấp phần mềm để được hỗ trợ\n" + ErrMsg);
                        return;
                    }
                    TongtienCK_chitiet=Utility.DecimaltoDbnull(txtTienChietkhau.Text);
                    if (chkChietkhauthem.Checked || TongtienCK_chitiet > 0)
                    {
                        frm_ChietkhauTrenHoadon _ChietkhauTrenHoadon = new frm_ChietkhauTrenHoadon();
                        _ChietkhauTrenHoadon.TongCKChitiet = Utility.DecimaltoDbnull(txtTienChietkhau.Text);
                        _ChietkhauTrenHoadon.TongtienBN = Utility.DecimaltoDbnull(txtSoTienCanNop.Text) + Utility.DecimaltoDbnull(txtTienChietkhau.Text);
                        _ChietkhauTrenHoadon.ShowDialog();
                        if (!_ChietkhauTrenHoadon.m_blnCancel)
                        {
                            TongtienCK = _ChietkhauTrenHoadon.TongtienCK;
                            TongtienCK_Hoadon = _ChietkhauTrenHoadon.TongCKHoadon;
                            ma_ldoCk = _ChietkhauTrenHoadon.ma_ldoCk;
                        }
                        else
                        {
                            Utility.ShowMsg("Bạn vừa thực hiện hủy thao tác nhập thông tin chiết khấu. Yêu cầu bạn nhập lý do chiết khấu(Do tiền chiết khấu >0). Mời bạn bấm lại nút thanh toán để bắt đầu lại");
                            return;
                        }
                    }
                    ActionResult actionResult = _THANHTOAN.Payment4SelectedItems( CreatePayment(),
                        objLuotkham, lstItems.ToArray(), ref v_Payment_ID);
                    //Tạm rem phần hóa đơn đỏ lại
                    //if (IN_HOADON)
                    //{
                    //    if (grdHoaDonCapPhat.CurrentRow == null)
                    //    {
                    //        Utility.ShowMsg("Mời bạn chọn quyển hóa đơn thanh toán");
                    //        return;
                    //    }
                    //}

                    switch (actionResult)
                    {
                        case ActionResult.Success:
                            Utility.EnableButton(cmdThanhToan, false);
                            LaydanhsachLichsuthanhtoan_phieuchi();
                            GetDataChiTiet();
                            Utility.GotoNewRowJanus(grdPayment, KcbThanhtoan.Columns.IdThanhtoan, v_Payment_ID.ToString());
                            if (v_Payment_ID <= 0)
                            {
                                grdPayment.MoveFirst();
                            }
                            if (PropertyLib._MayInProperties.TudonginhoadonSaukhiThanhtoan)
                            {
                            }
                            txtPatient_Code.Focus();
                            txtPatient_Code.SelectAll();
                            //Tạm rem phần hóa đơn đỏ lại
                            if (IN_HOADON && PropertyLib._MayInProperties.TudonginhoadonSaukhiThanhtoan)
                            {
                                if (PropertyLib._MayInProperties.Kieuinhoadon == 1 || PropertyLib._MayInProperties.Kieuinhoadon == 3)
                                    InHoadon();
                                if (PropertyLib._MayInProperties.Kieuinhoadon == 2 || PropertyLib._MayInProperties.Kieuinhoadon == 3)
                                    new INPHIEU_THANHTOAN_NGOAITRU().InBienlai(false, v_Payment_ID, objLuotkham);
                            }
                            break;
                        case ActionResult.Error:
                            Utility.ShowMsg("Lỗi trong quá trình thanh toán", "Thông báo lỗi", MessageBoxIcon.Error);
                            break;
                    }
                    IN_HOADON = false;
                    INPHIEU_CLICK = false;

                }
            }
            catch (Exception exception)
            {
                Utility.EnableButton(cmdThanhToan, true);
            }
            finally
            {
                TongtienCK = 0m;
                TongtienCK_chitiet = 0m;
                TongtienCK_Hoadon = 0m;
                ma_ldoCk = "";
                ModifyCommand();
            }
        }