public void addTrinhKy_OnFormLoad()
        {
            try
            {
                LoadPrintNumberByReportCode();

                mv_oRptFieldObj = GetTrinhky(this.crptViewer.ParameterFieldInfo);
                mv_oNguoiKy = new cls_SignInfor(string.IsNullOrEmpty(mv_sReportFileName) ? RptDoc.ToString() : mv_sReportFileName, "");
                if (mv_oNguoiKy != null)
                {
                    if (mv_oNguoiKy._TonTai)
                    {
                        this.Text += " Ton tai TK";
                        SetParamAgain();
                    }
                    else
                    {
                        this.Text += " Ko Ton tai TK";
                        string sPvalue = "";
                        Utility.SetParameterValue(RptDoc, "txtTrinhky", sPvalue);
                    }
                }
                else
                {
                    Utility.ShowMsg("No Trình ký");
                }
                this.crptViewer.ReportSource = RptDoc;
            }
            catch (Exception ex)
            {
                mv_oRptText = null;
                Utility.CatchException("addTrinhKy_OnFormLoad-->", ex);
                this.cmdTrinhKy.Visible = false;
            }
        }
        public void Print(bool Quick,string printerName)
        {
            string path = "";// =SystemReports.GetPathReport(StrCode);
            try
            {
                if (Crpt == null && !string.IsNullOrEmpty(StrCode))
                {

                    ReportDocument crptDocument=new ReportDocument();
                    crptDocument.Load(path);
                    Crpt = crptDocument; //GetCrptFromAssembly(StrCode);
                   // Crpt = GetCrptFromAssembly(StrCode);
                }

                if (ValidData())
                {
                    bool hasSubReport = CheckHasSubReport(Crpt);
                    var oForm = new frmPrintPreview("Phiếu KQ Xét nghiệm", Crpt, true, ReportSourceTable.Rows.Count <= 0 ? false : true);
                    oForm.crptTrinhKyName = Path.GetFileName(path);
                    if (!hasSubReport)
                    {
                        Crpt.SetDataSource(ReportSourceTable);
                        SetReportParameter(Crpt);
                       // var oForm = new frmPrintPreview(FormPreviewTitle, Crpt, true, true);

                    if (SysPara.ParamaterReport != null)
                        {
                            if (SysPara.ParamaterReport == "THANHNHAN")
                            {
                                var patientId = Utility.Int32Dbnull(ReportSourceTable.Rows[0]["Patient_ID"]);
                                var dtAssignDoctor =
                                    new Select(TTestInfo.Columns.AssignId, LUser.Columns.UserName).From(TTestInfo.Schema.Name).InnerJoin
                                        (LUser.UserIdColumn, TTestInfo.AssignIdColumn).Where(TTestInfo.Columns.PatientId).IsEqualTo(patientId).And(TTestInfo.Columns.TestTypeId).In(testTypeList).ExecuteDataSet().Tables[0];

                                if (dtAssignDoctor.Rows.Count > 0)
                                {

                                    Crpt.SetParameterValue("sBacSyChiDinh", "BÁC SỸ CHỈ ĐỊNH");
                                    Crpt.SetParameterValue("sTenBacSyChiDinh", Utility.sDbnull(dtAssignDoctor.Rows[0]["User_Name"]));
                                }
                                //else
                                //{
                                //    Crpt.SetParameterValue("sBacSyChiDinh", "");
                                //    Crpt.SetParameterValue("sTenBacSyChiDinh", "");
                                //}

                                var sFullName =
                                    new Select(SysUser.Columns.SFullName).From(SysUser.Schema.Name).Where(SysUser.Columns.PkSuid)
                                        .IsEqualTo(globalVariables.UserName).ExecuteScalar();
                                if (!string.IsNullOrEmpty(Utility.sDbnull(sFullName)))
                                {
                                    Crpt.SetParameterValue("sTenUser", sFullName);
                                }
                                //else
                                //{
                                //    Crpt.SetParameterValue("sTenUser","");
                                //}
                            }
                        }

                        oForm.crptViewer.ReportSource = Crpt;
                        // FieldObject mv_oRptFieldObj = Crpt.ReportDefinition.ReportObjects["Field150181"] as FieldObject;
                        // Crpt.PrintToPrinter();
                        if (Quick)
                        {
                            //    mv_oNguoiKy = new VietBaIT.LABLink.Reports.Class.cls_SignInfor(mv_oRptFieldObj, "", Crpt.ToString(), Crpt.DataDefinition.FormulaFields["Formula_1"].Text);
                            //  mv_oNguoiKy = new cls_SignInfor(Crpt.ToString(), "", ReportSourceTable);
                            //  mv_oNguoiKy = newcls_SignInfor(string.IsNullOrEmpty(oForm.crptTrinhKyName) , Crpt.ToString(),oForm.crptTrinhKyName, "", "");
                            mv_oNguoiKy = new cls_SignInfor_new(string.IsNullOrEmpty(oForm.crptTrinhKyName) ? oForm.crptTrinhKyName : oForm.crptTrinhKyName, "");
                            //      mv_oNguoiKy = newcls_SignInfor(" ", "", Crpt, ReportSourceTable);
                            //chkPrint_CheckedChanged(chkPrint, New System.EventArgs)
                            if (mv_oNguoiKy._TonTai)
                            {
                                Crpt.DataDefinition.FormulaFields["Formula_1"].Text = Strings.Chr(34) +
                                                                                      mv_oNguoiKy.mv_NOI_DUNG.Replace(
                                                                                          "&NHANVIEN",
                                                                                          globalVariables.UserName)
                                                                                          .Replace("\t",
                                                                                              Strings.Chr(34) +
                                                                                              "&Chr(13)&" +
                                                                                              Strings.Chr(34)) +
                                                                                      Strings.Chr(34);
                            }
                            else
                            {
                                Crpt.DataDefinition.FormulaFields["Formula_1"].Text = "";
                            }
                            Crpt.PrintOptions.PrinterName = printerName;
                            Crpt.PrintToPrinter(0, true, 0, 0);
                            Crpt.Dispose();
                            CleanTemporaryFolders();
                        }
                        else
                        {
                            oForm.ShowDialog();
                            oForm.Dispose();
                        }
                    }
                    else
                    {
                        //DataTable dt = new Select().From(TblTrinhky.Schema.Name).Where(TblTrinhky.Columns.ReportName).
                        //                            IsEqualTo(Crpt.GetClassName()).ExecuteDataSet().Tables[0];

                        string sql = string.Format("SELECT * \n"
                                                   + "FROM   Sys_Trinhky With (NOLOCK) \n"
                                                   + "WHERE  ReportName = N'{0}'", oForm.crptTrinhKyName);

                        var x = new InlineQuery().ExecuteAsCollection<SysTrinhkyCollection>(sql);

                        if (x.Count > 0)
                            Utility.GetDataRow(ReportParameterTable, colName, "Formula_1")[colValue] = Strings.Chr(34) +
                                                                                                       Utility.sDbnull(
                                                                                                           x[0]
                                                                                                               .ObjectContent) +
                                                                                                       Strings.Chr(34);

                        Crpt.SetDataSource(ReportSourceTable);
                        SetReportParameter(Crpt);
                        if (!ReportSourceTable.Columns.Contains("ParentBranchName"))
                            ReportSourceTable.Columns.Add("ParentBranchName");
                        if (!ReportSourceTable.Columns.Contains("BranchName"))
                            ReportSourceTable.Columns.Add("BranchName");

                        DataTable dtHematology = ReportSourceTable.Clone();
                        DataTable dtOther = ReportSourceTable.Clone();
                        DataTable dtImages = ReportSourceTable.Clone();
                           string sql2 = string.Format("SELECT Sys_Users.sFullName \n"
                                                    + "FROM   Sys_Users  WITH (NOLOCK)  \n"
                                                    + "WHERE  Sys_Users.PK_sUID = '{0}'", globalVariables.UserName);

                        var objuserName = new InlineQuery().ExecuteScalar<string>(sql2);

                        string sNguoiDung = objuserName == null ? "" : objuserName;
                        foreach (DataRow row in ReportSourceTable.Rows)
                        {
                            row["ParentBranchName"] = globalVariables.ParentBranch_Name;
                            row["BranchName"] = globalVariables.Branch_Name;
                            row["Nguoidung"] = sNguoiDung;

                            if (row["isHematology"].ToString() == "1")
                            {
                                if (row["Data_Sequence"].ToString().Contains("-"))
                                {
                                    string pvSImgPath = row["Test_Result"].ToString();
                                    if (File.Exists(pvSImgPath))
                                    {
                                        //row["BarcodeImg"] = Utility.bytGetImage(pvSImgPath);
                                        var bitmap = new Bitmap(pvSImgPath);
                                        Invert(ref bitmap);
                                        row["BarcodeImg"] = Utility.ConvertImageToByteArray(bitmap, ImageFormat.Tiff);
                                        dtImages.ImportRow(row);
                                    }
                                }
                                else dtHematology.ImportRow(row);
                            }
                            else dtOther.ImportRow(row);
                        }

                        // đẹt me lam rieng cho noi tiet to su bo no(.)

                        // cho cai kho A5
                        if (StrCode == "A5")
                        {

                            Crpt.Subreports["NoiTiet_A5_General_crpt_DetailTestReport_ALL_New_Sub_Hematology_Images.rpt"
                                ].SetDataSource(dtImages);
                            Crpt.Subreports["NoiTiet_A5_General_crpt_DetailTestReport_ALL_New_Sub_Hematology.rpt"]
                                .SetDataSource(dtHematology);
                            Crpt.Subreports["NoiTiet_A5_General_crpt_DetailTestReport_ALL_New_Sub_Other.rpt"]
                                .SetDataSource(dtOther);
                            SetReportParameter(
                                Crpt.Subreports["NoiTiet_A5_General_crpt_DetailTestReport_ALL_New_Sub_Other.rpt"]);
                            SetReportParameter(
                                Crpt.Subreports["NoiTiet_A5_General_crpt_DetailTestReport_ALL_New_Sub_Hematology.rpt"]);
                            //Crpt.SetParameterValue("PrintDate", printDateTime, Crpt.Subreports["NoiTiet_A5_General_crpt_DetailTestReport_ALL_New_Sub_Hematology.rpt"].Name);
                            //Crpt.SetParameterValue("PrintDate", printDateTime, Crpt.Subreports["NoiTiet_A5_General_crpt_DetailTestReport_ALL_New_Sub_Other.rpt"].Name);

                            SetReportParameter(Crpt);
                        }
                            // cho cai kho A4
                        else if (StrCode == "A4")
                        {
                            SetReportParameter(
                                Crpt.Subreports["NoiTiet_A4_General_crpt_DetailTestReport_ALL_New_Sub_Other.rpt"]);
                            SetReportParameter(
                                Crpt.Subreports["NoiTiet_A4_General_crpt_DetailTestReport_ALL_New_Sub_Hematology.rpt"]);

                            Crpt.Subreports["NoiTiet_A4_General_crpt_DetailTestReport_ALL_New_Sub_Hematology_Images.rpt"
                                ].SetDataSource(dtImages);
                            Crpt.Subreports["NoiTiet_A4_General_crpt_DetailTestReport_ALL_New_Sub_Hematology.rpt"]
                                .SetDataSource(dtHematology);
                            Crpt.Subreports["NoiTiet_A4_General_crpt_DetailTestReport_ALL_New_Sub_Other.rpt"]
                                .SetDataSource(dtOther);
                            SetReportParameter(Crpt);
                            //  Crpt.SetParameterValue("Nguoidung", sNguoiDung);
                        }
                            //neu deo khai bao A4 hay A5 thi mac dinh lay cai nay nhung pai dung cai bao cao ko an cut no chay dc.
                        else if (StrCode == "LABREPORT")
                        {
                            SetReportParameter(
                                Crpt.Subreports["NoiTiet_A4_General_crpt_DetailTestReport_ALL_New_Sub_Other.rpt"]);
                            SetReportParameter(
                                Crpt.Subreports["NoiTiet_A4_General_crpt_DetailTestReport_ALL_New_Sub_Hematology.rpt"]);
                            Crpt.Subreports["NoiTiet_A4_General_crpt_DetailTestReport_ALL_New_Sub_Hematology_Images.rpt"
                                ].SetDataSource(dtImages);
                            Crpt.Subreports["NoiTiet_A4_General_crpt_DetailTestReport_ALL_New_Sub_Hematology.rpt"]
                                .SetDataSource(dtHematology);
                            Crpt.Subreports["NoiTiet_A4_General_crpt_DetailTestReport_ALL_New_Sub_Other.rpt"]
                                .SetDataSource(dtOther);
                            SetReportParameter(Crpt);
                        }
                      //  if (Quick) Crpt.PrintToPrinter(0, false, 0, 0);
                        if (Quick)
                        {
                            //    mv_oNguoiKy = new VietBaIT.LABLink.Reports.Class.cls_SignInfor(mv_oRptFieldObj, "", Crpt.ToString(), Crpt.DataDefinition.FormulaFields["Formula_1"].Text);
                            //  mv_oNguoiKy = new cls_SignInfor(Crpt.ToString(), "", ReportSourceTable);
                            //  mv_oNguoiKy = newcls_SignInfor(string.IsNullOrEmpty(oForm.crptTrinhKyName) , Crpt.ToString(),oForm.crptTrinhKyName, "", "");
                            mv_oNguoiKy =
                                new cls_SignInfor_new(
                                    string.IsNullOrEmpty(oForm.crptTrinhKyName)
                                        ? oForm.crptTrinhKyName
                                        : oForm.crptTrinhKyName, "");
                            //      mv_oNguoiKy = newcls_SignInfor(" ", "", Crpt, ReportSourceTable);
                            //chkPrint_CheckedChanged(chkPrint, New System.EventArgs)
                            if (mv_oNguoiKy._TonTai)
                            {
                                Crpt.DataDefinition.FormulaFields["Formula_1"].Text = Strings.Chr(34) +
                                                                                      mv_oNguoiKy.mv_NOI_DUNG.Replace(
                                                                                          "&NHANVIEN",
                                                                                          globalVariables.UserName)
                                                                                          .Replace("\t",
                                                                                              Strings.Chr(34) +
                                                                                              "&Chr(13)&" +
                                                                                              Strings.Chr(34)) +
                                                                                      Strings.Chr(34);
                            }
                            else
                            {
                                Crpt.DataDefinition.FormulaFields["Formula_1"].Text = "";
                            }

                            Crpt.PrintOptions.PrinterName = printerName;
                            Crpt.PrintToPrinter(0, true, 0, 0);
                            Crpt.Dispose();
                            CleanTemporaryFolders();
                        }
                        else
                        {
                          //  var oForm = newfrmPrintPreview("Phiếu KQ Xét nghiệm", Crpt, true, ReportSourceTable.Rows.Count <= 0 ? false : true);
                         //   oForm.crptTrinhKyName = Path.GetFileName(path);

                            oForm.ShowDialog();
                            oForm.Dispose();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.ShowMsg(ex.Message);
            }
        }
        public void addTrinhKy_OnFormLoad()
        {
            //Ham nay XuanDT them vao
            try
            {
                //doan gan cac bien: doan nay co the phai thay doi ten bien cho phu hop
                mv_oRptDoc = RptDoc;
                mv_oViewDoc = this.crptViewer;
                //ket thuc doan gan bien

                mv_oRptFieldObj = GetTrinhky(RptDoc.ParameterFields);
              //  if (mv_oRptFieldObj == null) return;
                mv_oNguoiKy = new cls_SignInfor(string.IsNullOrEmpty(crptTrinhKyName) ? mv_oRptDoc.ToString() : crptTrinhKyName, "");
                //chkPrint_CheckedChanged(chkPrint, New System.EventArgs)
                if (mv_oNguoiKy._TonTai)
                {
                    SetParamAgain(RptDoc.ParameterFields);
                    //if (mv_bSetContent)
                    //{

                    //    mv_oRptDoc.ReportDefinition.ReportObjects["txtTrinhky"]..Text = mv_oNguoiKy.mv_NOI_DUNG.Replace("&NHANVIEN", globalVariables.gv_strTenNhanvien);

                    //}
                    //else
                    //{
                    //    mv_oRptDoc.DataDefinition.FormulaFields["Formula_1"].Text = "";
                    //}

                }
                else
                {
                    SetParamAgain(RptDoc.ParameterFields);
                    if (string.IsNullOrEmpty(crptTrinhKyName))
                        mv_oNguoiKy = new cls_SignInfor(mv_oRptFieldObj, "", RptDoc.ToString(), "");
                    else
                    {
                        mv_oNguoiKy = new cls_SignInfor(mv_oRptFieldObj, "", crptTrinhKyName, "");
                    }

                }
                mv_oViewDoc.ReportSource = RptDoc;
            }
            catch (Exception ex)
            {
                mv_oRptText = null;
                //an nut tuy chon di
                log.Error("Loi trong qua trinh load thong tin trih ky={0}", ex);
                this.cmdTrinhKy.Visible = false;
            }
        }