private void cmdExportToExcel_Click(object sender, EventArgs e)
        {
            try
            {
                int trangthai = -1;
                if (radTatca.Checked)
                {
                    trangthai = -1;
                }
                if (radDathuchien.Checked)
                {
                    trangthai = 1;
                }
                if (radChuathuchien.Checked)
                {
                    trangthai = 0;
                }
                DataTable dtDanhsach =
                    SPs.BaocaoThongkedanhsachThuchienchucnang(dtFromDate.Value, dtToDate.Value,
                                                              Utility.Int16Dbnull(cboDoituongKCB.SelectedValue, -1),
                                                              Utility.sDbnull(cboKhoa.SelectedValue, "KKB"), Args,
                                                              Utility.Int32Dbnull(txtdichvu.MyID, -1), trangthai).GetDataSet().Tables[0];
                if (dtDanhsach.Rows.Count > 0)
                {
                    Utility.SetDataSourceForDataGridEx(grdResult, dtDanhsach, false, true, "1=1", "");
                    string    reportcode    = "";
                    string    duongdan      = "";
                    string    codintion     = "";
                    DataTable dt            = new DataTable();
                    int       idxRow        = 0;
                    int       idxColSh      = 0;
                    var       book          = new C1XLBook();
                    XLSheet   sheet         = book.Sheets[0];
                    string    getTime       = "";
                    string    pathDirectory = "";
                    switch (Args.Substring(0, 2))
                    {
                    case "SA":
                        reportcode = "baocao_thongkedanhsach_sieuam";
                        duongdan   = Utility.GetPathExcel(reportcode);
                        book       = new C1XLBook();
                        book.Load(duongdan);
                        book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular);
                        sheet            = book.Sheets[0];
                        dt        = dtDanhsach;
                        idxRow    = 7;
                        idxColSh  = 0;
                        codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}",
                                                  dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"),
                                                  cboDoituongKCB.Text);
                        sheet[3, idxColSh].SetValue(Convert.ToString(codintion),
                                                    HamDungChung.styleStringCenter(book));
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book));
                            sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_khoaphong"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["ket_qua"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book));
                            idxRow = idxRow + 1;
                        }
                        getTime       = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss"));
                        pathDirectory = AppDomain.CurrentDomain.BaseDirectory +
                                        "TemplateExcel\\ExportExcel\\";
                        if (!Directory.Exists(pathDirectory))
                        {
                            Directory.CreateDirectory(pathDirectory);
                        }

                        book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" +
                                  reportcode +
                                  getTime + ".xls");
                        Process.Start(
                            new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory +
                                                 "\\TemplateExcel\\ExportExcel\\" +
                                                 reportcode + getTime + ".xls"));
                        break;

                    case "XQ":
                        reportcode = "baocao_thongkedanhsach_xquang";
                        duongdan   = Utility.GetPathExcel(reportcode);
                        book       = new C1XLBook();
                        book.Load(duongdan);
                        book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular);
                        sheet            = book.Sheets[0];
                        dt        = dtDanhsach;
                        idxRow    = 7;
                        idxColSh  = 0;
                        codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}",
                                                  dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"),
                                                  cboDoituongKCB.Text);
                        sheet[3, idxColSh].SetValue(Convert.ToString(codintion),
                                                    HamDungChung.styleStringCenter(book));
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book));
                            sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_khoaphong"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["ket_qua"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book));
                            idxRow = idxRow + 1;
                        }
                        getTime       = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss"));
                        pathDirectory = AppDomain.CurrentDomain.BaseDirectory +
                                        "TemplateExcel\\ExportExcel\\";
                        if (!Directory.Exists(pathDirectory))
                        {
                            Directory.CreateDirectory(pathDirectory);
                        }

                        book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" +
                                  reportcode +
                                  getTime + ".xls");
                        Process.Start(
                            new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory +
                                                 "\\TemplateExcel\\ExportExcel\\" +
                                                 reportcode + getTime + ".xls"));
                        break;
                        break;

                    case "DT":

                        break;

                    case "NS":
                        reportcode = "baocao_thongkedanhsach_noisoi";
                        duongdan   = Utility.GetPathExcel(reportcode);
                        book.Load(duongdan);
                        book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular);
                        dt        = dtDanhsach;
                        idxRow    = 7;
                        idxColSh  = 0;
                        codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}",
                                                  dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"),
                                                  cboDoituongKCB.Text);
                        sheet[3, idxColSh].SetValue(Convert.ToString(codintion),
                                                    HamDungChung.styleStringCenter(book));
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book));
                            sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_khoaphong"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["ket_qua"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book));
                            idxRow = idxRow + 1;
                        }
                        getTime       = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss"));
                        pathDirectory = AppDomain.CurrentDomain.BaseDirectory +
                                        "TemplateExcel\\ExportExcel\\";
                        if (!Directory.Exists(pathDirectory))
                        {
                            Directory.CreateDirectory(pathDirectory);
                        }
                        book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" +
                                  reportcode +
                                  getTime + ".xls");
                        Process.Start(
                            new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory +
                                                 "\\TemplateExcel\\ExportExcel\\" +
                                                 reportcode + getTime + ".xls"));
                        break;

                    case "PT":
                        reportcode = "baocao_thongkedanhsach_pttt";
                        duongdan   = Utility.GetPathExcel(reportcode);
                        book       = new C1XLBook();
                        book.Load(duongdan);
                        book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular);
                        sheet            = book.Sheets[0];
                        dt        = dtDanhsach;
                        idxRow    = 7;
                        idxColSh  = 0;
                        codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}",
                                                  dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"),
                                                  cboDoituongKCB.Text);
                        sheet[3, idxColSh].SetValue(Convert.ToString(codintion),
                                                    HamDungChung.styleStringCenter(book));
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book));
                            sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["phuongphap_vocam"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["ngay_thuchien"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["loai_phauthuat"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(dt.Rows[i]["bacsy_gayme"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book));
                            idxRow = idxRow + 1;
                        }
                        getTime       = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss"));
                        pathDirectory = AppDomain.CurrentDomain.BaseDirectory +
                                        "TemplateExcel\\ExportExcel\\";
                        if (!Directory.Exists(pathDirectory))
                        {
                            Directory.CreateDirectory(pathDirectory);
                        }

                        book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" +
                                  reportcode +
                                  getTime + ".xls");
                        Process.Start(
                            new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory +
                                                 "\\TemplateExcel\\ExportExcel\\" +
                                                 reportcode + getTime + ".xls"));
                        break;

                    case "TT":
                        reportcode = "baocao_thongkedanhsach_tt";
                        duongdan   = Utility.GetPathExcel(reportcode);
                        book       = new C1XLBook();
                        book.Load(duongdan);
                        book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular);
                        sheet            = book.Sheets[0];
                        dt        = dtDanhsach;
                        idxRow    = 7;
                        idxColSh  = 0;
                        codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}",
                                                  dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"),
                                                  cboDoituongKCB.Text);
                        sheet[3, idxColSh].SetValue(Convert.ToString(codintion),
                                                    HamDungChung.styleStringCenter(book));
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book));
                            sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["phuongphap_vocam"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["ngay_thuchien"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["loai_phauthuat"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(dt.Rows[i]["bacsy_gayme"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book));
                            idxRow = idxRow + 1;
                        }
                        getTime       = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss"));
                        pathDirectory = AppDomain.CurrentDomain.BaseDirectory +
                                        "TemplateExcel\\ExportExcel\\";
                        if (!Directory.Exists(pathDirectory))
                        {
                            Directory.CreateDirectory(pathDirectory);
                        }

                        book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" +
                                  reportcode +
                                  getTime + ".xls");
                        Process.Start(
                            new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory +
                                                 "\\TemplateExcel\\ExportExcel\\" +
                                                 reportcode + getTime + ".xls"));
                        break;

                    default:
                        reportcode = "baocao_thongkedanhsach_tt";
                        duongdan   = Utility.GetPathExcel(reportcode);
                        book       = new C1XLBook();
                        book.Load(duongdan);
                        book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular);
                        sheet            = book.Sheets[0];
                        dt        = dtDanhsach;
                        idxRow    = 7;
                        idxColSh  = 0;
                        codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}",
                                                  dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"),
                                                  cboDoituongKCB.Text);
                        sheet[3, idxColSh].SetValue(Convert.ToString(codintion),
                                                    HamDungChung.styleStringCenter(book));
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book));
                            sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleNumber(book));
                            sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["phuongphap_vocam"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["ngay_thuchien"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["loai_phauthuat"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(dt.Rows[i]["bacsy_gayme"]), HamDungChung.styleStringLeft(book));
                            sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book));
                            idxRow = idxRow + 1;
                        }
                        getTime       = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss"));
                        pathDirectory = AppDomain.CurrentDomain.BaseDirectory +
                                        "TemplateExcel\\ExportExcel\\";
                        if (!Directory.Exists(pathDirectory))
                        {
                            Directory.CreateDirectory(pathDirectory);
                        }

                        book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" +
                                  reportcode +
                                  getTime + ".xls");
                        Process.Start(
                            new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory +
                                                 "\\TemplateExcel\\ExportExcel\\" +
                                                 reportcode + getTime + ".xls"));
                        break;
                    }
                }
                else
                {
                    Utility.ShowMsg("Không có dữ liệu để báo cáo!");
                }
                //  ExcelUtlity.ExportGridEx(grdResult);
            }
            catch (Exception exception)
            {
                Utility.ShowMsg("Lỗi:" + exception.Message);
            }
        }
        private void cmdInPhieu_Click(object sender, EventArgs e)
        {
            int trangthai = -1;

            if (radTatca.Checked)
            {
                trangthai = -1;
            }
            if (radDathuchien.Checked)
            {
                trangthai = 1;
            }
            if (radChuathuchien.Checked)
            {
                trangthai = 0;
            }
            DataTable dtDanhsach =
                SPs.BaocaoThongkedanhsachThuchienchucnang(dtFromDate.Value, dtToDate.Value,
                                                          Utility.Int16Dbnull(cboDoituongKCB.SelectedValue, -1),
                                                          Utility.sDbnull(cboKhoa.SelectedValue, "KKB"), Args,
                                                          Utility.Int32Dbnull(txtdichvu.MyID, -1), trangthai)
                .GetDataSet().Tables[0];

            Utility.SetDataSourceForDataGridEx(grdResult, dtDanhsach, false, false, "", "");
            THU_VIEN_CHUNG.CreateXML(dtDanhsach, "baocao_thongkedanhsach_chucnang.XML");
            if (dtDanhsach.Rows.Count <= 0)
            {
                Utility.ShowMsg("Không có dữ liệu để báo cáo!");
                return;
            }
            Utility.UpdateLogotoDatatable(ref dtDanhsach);
            string reportCode = "";

            switch (Args.Substring(0, 2))
            {
            case "SA":
                reportCode = "baocao_thongkedanhsach_sieuam";
                break;

            case "XQ":
                reportCode = "baocao_thongkedanhsach_xquang";
                break;

            case "DT":
                reportCode = "baocao_thongkedanhsach_dientim";
                break;

            case "NS":
                reportCode = "baocao_thongkedanhsach_noisoi";
                break;

            case "PT":
                reportCode = "baocao_thongkedanhsach_pttt";
                break;

            default:
                reportCode = "baocao_thongkedanhsach_noisoi";
                break;
            }
            string Condition =
                string.Format("Từ ngày {0} đến {1} - Đối tượng : {2} - Khoa KCB :{3}",
                              dtFromDate.Text, dtToDate.Text,
                              cboDoituongKCB.SelectedIndex >= 0
                                  ? Utility.sDbnull(cboDoituongKCB.Text)
                                  : "Tất cả",
                              cboKhoa.SelectedIndex > 0
                                  ? Utility.sDbnull(cboKhoa.Text)
                                  : "Tất cả");
            ReportDocument crpt = Utility.GetReport(reportCode, ref tieude, ref reportname);

            if (crpt == null)
            {
                return;
            }

            string StaffName = globalVariables.gv_strTenNhanvien;

            if (string.IsNullOrEmpty(globalVariables.gv_strTenNhanvien))
            {
                StaffName = globalVariables.UserName;
            }
            try
            {
                var objForm = new frmPrintPreview(tieude, crpt, true, dtDanhsach.Rows.Count <= 0 ? false : true);
                crpt.SetDataSource(dtDanhsach);
                objForm.mv_sReportFileName = Path.GetFileName(reportname);
                objForm.mv_sReportCode     = reportCode;
                crpt.SetParameterValue("StaffName", StaffName);
                crpt.SetParameterValue("ParentBranchName", globalVariables.ParentBranch_Name);
                crpt.SetParameterValue("BranchName", globalVariables.Branch_Name);
                crpt.SetParameterValue("Address", globalVariables.Branch_Address);
                crpt.SetParameterValue("Phone", globalVariables.Branch_Phone);
                crpt.SetParameterValue("FromDateToDate", Condition);
                crpt.SetParameterValue("sTitleReport", tieude);
                crpt.SetParameterValue("sCurrentDate", Utility.FormatDateTimeWithThanhPho(dtNgayInPhieu.Value));
                crpt.SetParameterValue("BottomCondition", THU_VIEN_CHUNG.BottomCondition());
                Utility.SetParameterValue(crpt, "txtTrinhky",
                                          Utility.getTrinhky(objForm.mv_sReportFileName, globalVariables.SysDate));
                objForm.crptViewer.ReportSource = crpt;
                objForm.ShowDialog();
            }
            catch (Exception exception)
            {
                Utility.ShowMsg("Lỗi:" + exception.Message);
            }
            finally
            {
                Utility.FreeMemory(crpt);
            }
        }