Article From:https://www.cnblogs.com/jiuyueBlog/p/9122979.html

First, add a reference below the corresponding folder, as shown below.

If there is no download, the package is downloaded.

In advance, create.Frx files under local folders, like this,

 

And then write under the trigger event

//Print preview

private void btn_Preview_Click(object sender, EventArgs e)
{
string path = GetReportPath();    //This method is to get the.Frx file under the absolute path
if (string.IsNullOrWhiteSpace(path)) { return; }
FastReport.Report _report = new FastReport.Report();
_report.Load(path);
_report.PrintSettings.ShowDialog = true;
EnvironmentSettings FPEnvironmentSettings = new EnvironmentSettings();
FPEnvironmentSettings.ReportSettings.ShowProgress = true;
_report.RegisterData(GetPrintData());  //GetPrintData()The method is to create print styles and fill in the data to print, and bind the data source.

if (IsDesgin)
{
_report.Design();
}
else
{
_report.Show();
}
}

 

//Printing

private void btn_Print_Click(object sender, EventArgs e)
{
string path = GetReportPath();
if (string.IsNullOrWhiteSpace(path)) { return; }
FastReport.Report _report = new FastReport.Report();
_report.Load(path);
_report.PrintSettings.ShowDialog = true;
EnvironmentSettings FPEnvironmentSettings = new EnvironmentSettings();
FPEnvironmentSettings.ReportSettings.ShowProgress = true;
_report.RegisterData(GetPrintData());
_report.Print();
}

 

//Global static variable

public static String g_FolderPath = System.AppDomain.CurrentDomain.BaseDirectory + ReportConst.REPORT_SAVE_DIR + “\\”;

private bool IsDesgin = false;

//Rewrite this method

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.O | Keys.K))
{
if (IsDesgin) { IsDesgin = false; }
else
{
IsDesgin = true;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}

 

//Get the.Frx file path

public string GetReportPath()
{
return g_FolderPath + “HD_” + “Electronic handover class “+”.Frx “;
}

 

//Binding the data source to be printed

private DataSet GetPrintData()
{
DataSet dataSetPrint = new DataSet();   //Create a DataSet dataset first
DataTable _EleCtronicHandover = new DataTable(“Electronic handover information “;” / / create a table to print.
#region Shift information
_EleCtronicHandover.Columns.Add(“The handover “, typeof (string));
_EleCtronicHandover.Columns.Add(“Shift time “, typeof (string));
_EleCtronicHandover.Columns.Add(“The successor “, typeof (string));
_EleCtronicHandover.Columns.Add(“The relay time “, typeof (string));
_EleCtronicHandover.Columns.Add(“The number of original patients “, typeof (string));
_EleCtronicHandover.Columns.Add(“The number of new admission “, typeof (string));
_EleCtronicHandover.Columns.Add(“The number of existing patients “, typeof (string));
_EleCtronicHandover.Columns.Add(“The number of discharge “, typeof (string));
_EleCtronicHandover.Columns.Add(“The number of critically ill, “typeof (string)”);
_EleCtronicHandover.Columns.Add(“The number of sick people “, typeof (string));
_EleCtronicHandover.Columns.Add(“The number of operations “, typeof (string));
_EleCtronicHandover.Columns.Add(“ICU”The number”, typeof (string));
_EleCtronicHandover.Columns.Add(“The number of transfers “, typeof (string));
_EleCtronicHandover.Columns.Add(“The number of transfers “, typeof (string));
_EleCtronicHandover.Columns.Add(“Date “, typeof (string));
_EleCtronicHandover.Columns.Add(“The handover class records ID “, typeof (string));
DataRow dr = _EleCtronicHandover.NewRow();
using (var proxy = new ElectronicHandoverProxy())
{
HD_ELECTRONIC_HANDOVER electronichandover = proxy.GetElectronicHandoverByDate(date_DATE.DateTime.ToShortDateString());
if (electronichandover != null)
{        //Fill the table with data
dr[“The handover person “] = electronichandover.HANDOVER;
dr[“Shift time “] = electronichandover.SHIFT_TIME;
dr[“The successor “] = electronichandover.SUCCESSOR;
dr[“Succession time] = electronichandover.SUCCESSION_TIME;
dr[“The original patient number] = electronichandover.ORIGINAL_PATIENTS_NUM;
dr[“New admission] = electronichandover.NEW_ADMISSION_NUM;
dr[“The existing number of patients is] = electronichandover.EXISTING_PATIENTS_NUM;
dr[“The number of discharge “] = electronichandover.DISCHARGE_NUM;
dr[“The number of people dying is] = electronichandover.CRITICALLY_ILL_NUM;
dr[“The number of seriously ill persons = = electronichandover.BE_CRITICALLY_ILL_NUM;
dr[“The number of operations “] = electronichandover.OPERATION_NUM;
dr[“ICUThe number “] = electronichandover.ICU_NUM;
dr[“Transfer number] = electronichandover.CHANGE_INTO_NUM;
dr[“The number of transfers “] = electronichandover.TURN_OUT_NUM;
dr[“Date] = electronichandover.ELECTRONIC_HANDOVER_DATE;
dr[“The shift record is ID “] = electronichandover.ELECTRONIC_HANDOVER_ID;
}
}
_EleCtronicHandover.Rows.Add(dr);     //Table fields are added into the table
dataSetPrint.Tables.Add(_EleCtronicHandover);    Add the table to the created DataSet
#endregion

#region Patient information
DataTable _DtPatient = new DataTable(“Patient information); create a different table to print.
_DtPatient.Columns.Add(“The hospitalization number “, typeof (string));
_DtPatient.Columns.Add(“Bed number “, typeof (string));
_DtPatient.Columns.Add(“The name “, typeof (string));
_DtPatient.Columns.Add(“Sex “, typeof (string));
_DtPatient.Columns.Add(“Age “, typeof (string));
_DtPatient.Columns.Add(“The date of admission “, typeof (string));
_DtPatient.Columns.Add(“Admission diagnosis “, typeof (string));
_DtPatient.Columns.Add(“The content of the shift “, typeof (string));
_DtPatient.Columns.Add(“The content of the successor “, typeof (string));
_DtPatient.Columns.Add(“The type of patient ID “, typeof (string));
_DtPatient.Columns.Add(“The name of the disease type “, typeof (string));
_DtPatient.Columns.Add(“Create time “, typeof (string));
_DtPatient.Columns.Add(“The creator “, typeof (string));
_DtPatient.Columns.Add(“Shift record ID “, typeof (string));
_DtPatient.Columns.Add(“Section ID “, typeof (string));
_DtPatient.Columns.Add(“The medical record ID “, typeof (string));
_DtPatient.Columns.Add(“Query date “, typeof (string));
_DtPatient.Columns.Add(“Patient information ID “, typeof (string));
#endregion

var PatientList = gdvPatientList.DataSource as List<HD_PATIENT_INFORMATION>;     //Get the data of the current GridView
if (PatientList == null && PatientList.Count <= 0) { return null; }
foreach (HD_PATIENT_INFORMATION item in PatientList)
{
DataRow _dr = _DtPatient.NewRow();
_dr[“The hospitalization number “] = item.INPATIENT_NUM;
_dr[“Bed number “] = item.BED_NUM;
_dr[“Name “] = item.NAME;
_dr[“Sex “] = item.SEX;
_dr[“Age “] = item.AGE;
_dr[“Admission date “] = item.ADMISSION_DATE;
_dr[“Admission diagnosis “] = item.ADMISSION_DIAGNOSIS;
_dr[“The content of the shift “] = item.SHIFT_CONTENT;
_dr[“Replacement content “] = item.SUCCESSION_CONTENT;
_dr[“Patient type ID “] = item.DISEASE_TYPE_ID;
_dr[“The name of the disease type “] = item.DISEASE_TYPE;
_dr[“Create time “] = item.CREATION_TIME;
_dr[“The creator “] = item.CREATER;
_dr[“Shift record ID “] = item.ELECTRONIC_HANDOVER_ID;
_dr[“Section ID “] = item.DEPT_ID;
_dr[“The medical record ID “] = item.MR_ID;
_dr[“Query date “] = item.SELECT_DATE;
_dr[“Patient information ID “] = item.HD_PATIENT_INFORMATION_ID;
_DtPatient.Rows.Add(_dr);
}
dataSetPrint.Tables.Add(_DtPatient);     //The way is the same.
return dataSetPrint;   //Return the completed set of data sets DataSet
}

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *