private void SetReportParameter(ReportDocument currentCrpt) { foreach (DataRow dr in ReportParameterTable.Rows) { if (Utility.sDbnull(dr[colType]) == vParameterType) { try { if (!currentCrpt.IsSubreport) { currentCrpt.SetParameterValue(Utility.sDbnull(dr[colName]), dr[colValue]); } else { Crpt.SetParameterValue(Utility.sDbnull(dr[colName]), dr[colValue], currentCrpt.Name); } } catch (Exception) { } } else if (Utility.sDbnull(dr[colType]) == vFormulaFieldsType) { try { currentCrpt.DataDefinition.FormulaFields[Utility.sDbnull(dr[colName])].Text = Utility.sDbnull(dr[colValue]); } catch (Exception) { } } } }
public void Print(bool Quick, string printerName) { try { if (Crpt == null && !string.IsNullOrEmpty(StrCode)) { Crpt = GetCrptFromAssembly(StrCode); } if (ValidData()) { bool hasSubReport = CheckHasSubReport(Crpt); if (!hasSubReport) { Crpt.SetDataSource(ReportSourceTable); if (Utility.sDbnull(printDateTime) != null) { Crpt.SetParameterValue("PrintDate", printDateTime); } //if(SysPara.ParamaterReport.ToUpper() == "THANHNHAN") //{ // var sFullName = // new Select(TblUser.Columns.SFullName).From(TblUser.Schema.Name).Where( // TblUser.Columns.PkSuid).IsEqualTo(Utilities.gv_sUID).ExecuteScalar(); // if (sFullName != null) // { // Crpt.SetParameterValue("sTenUser", sFullName); // } // else // { // Crpt.SetParameterValue("sTenUser"," "); // } //} ReportDocument reportDocument = new ReportDocument(); string tieude = "", reportname = ""; SetReportParameter(Crpt); var oForm = new frmPrintPreview(FormPreviewTitle, Crpt, true, true); oForm.ReportSourceTable = ReportSourceTable; // FieldObject mv_oRptFieldObj = Crpt.ReportDefinition.ReportObjects["Field150181"] as FieldObject; // Crpt.PrintToPrinter(); if (Quick) { oForm.crptTrinhKyName = Path.GetFileName(reportname); //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,); //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}'", Crpt.GetClassName()); 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(); //object objuserName = // new Select(TblUser.Columns.SFullName).From(TblUser.Schema).Where(TblUser.Columns.PkSuid). // IsEqualTo(Utilities.gv_sUID).ExecuteScalar(); 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"] = ManagementUnit.gv_sParentBranchName; row["BranchName"] = ManagementUnit.gv_sBranchName; 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); } else { var oForm = new frmPrintPreview(FormPreviewTitle, Crpt, true, true); oForm.ShowDialog(); oForm.Dispose(); } } } } catch (Exception ex) { Utility.ShowMsg(ex.Message); } }