1. 程式人生 > >根據dataTable動態生成grid++report 的方法

根據dataTable動態生成grid++report 的方法

footer paper 日期 text int 6.0 station eight 類型

/// <summary>
/// 生成grid++report模板
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public int GenerateNurModel(DataTable dt)
{

BNuringList BNu=new BNuringList ();
string NurName = dt.Rows[0]["NurName"].ToString();
string NurName1 = dt.Rows[0]["NurName1"].ToString();
string SpellNurName = GetSpellCode(NurName);
string SpellNurName1 = GetSpellCode(NurName1);
DataTable fielddt = BNu.FliterTree("-1",dt);
string filepath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
filepath += "H11111\\rpt\\" + SpellNurName + "(" + SpellNurName1 + ")" + ".grf";
//@"F:\" + NurName +"("+NurName1+")"+ ".grf"
// MessageBox.Show(filepath);
FileInfo myFile = new FileInfo(filepath);
StreamWriter sw = myFile.CreateText();
string str = "Object Report \r\n"
+ "Version=‘6.2.0.0‘\r\n"
+ " Title=‘" + NurName + "‘\r\n"
+ " PrintAsDesignPaper=F \r\n"
+ " Object Font\r\n"
+ " Name=‘宋體‘\r\n"
+ " Size=105000,0\r\n"
+ " Weight=400\r\n"
+ " Charset=134\r\n"
+ " End\r\n"
+ " Object Printer\r\n"
+ " Oriention=Landscape\r\n"
+ " LeftMargin=1\r\n"
+ " TopMargin=2\r\n"
+ " RightMargin=1\r\n"
+ " BottomMargin=2\r\n"
+ " End\r\n";
str += " Object DetailGrid\r\n"
+ " CenterView=T\r\n"
+ " AppendBlankRow=T\r\n"
+ " Object Recordset\r\n"
+ " ConnectionString=‘Provider=SQLOLEDB.1;Persist Security Info=True;User"
+ "ID=sa;Initial Catalog=HISONE_V5;Data Source=DPT0103;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=DPT0103;Use Encryption for Data=False;Tag with column collation when possible=False‘\r\n";
//生成字段域
str += "Items Field\r\n";
string ColumnContentCell = "";
string ItemsColumn = "";
string ColumnTitleCell = "";
string paramater = "";
for (int i = 0; i < fielddt.Rows.Count; i++)
{
string field = fielddt.Rows[i]["DataName"].ToString();
str += "Item\r\n"
+ " Name=‘" + EnCode16ASI(field) + "‘\r\n"//生成字段EnCode16ASI
+" End\r\n";

ItemsColumn += "Item\r\n"
+" Name=‘"+fielddt.Rows[i]["DataName"].ToString()+"‘\r\n"
+" Width=1\r\n"
+" End\r\n";

ColumnContentCell += "Item\r\n"
+ " Column=‘" + fielddt.Rows[i]["DataName"].ToString() + "‘\r\n"
//+ " DataField=‘" + fielddt.Rows[i]["DataName"].ToString() + "‘\r\n"
+ " FreeCell=T\r\n"
+ "CanGrow=T\r\n"
+"CanShrink=T\r\n"
+"Items Control\r\n"
+" Item\r\n"
+ " Type=FieldBox\r\n" //修改他的輸入框類型 列如:PictureBox
+" Name=‘PictureBox"+i+"‘\r\n"
+" Dock=Fill\r\n"
+ " DataField=‘" + EnCode16ASI(field) + "‘\r\n"//綁定字段和列
+" End\r\n"
+"End\r\n"
+" End\r\n";

}
str += "End \r\n End\r\n";
str += "Items Column\r\n" + ItemsColumn + "End \r\n";
str += "Object ColumnContent\r\n"
+ "Height=0.73\r\n"
+ " Object Font\r\n"
+ " Name=‘宋體‘\r\n"
+ " Size=90000,0\r\n"
+ " Weight=400\r\n"
+ " Charset=134\r\n"
+ " End\r\n"
+ " Items ColumnContentCell\r\n";
str += ColumnContentCell;
str += "End \r\n End\r\n";
//生成多表頭
ColumnTitleCell += "Object ColumnTitle\r\n"
+ " Height=2.77813\r\n"
+ " Object Font\r\n"
+ " Name=‘宋體‘\r\n"
+ " Bold=T\r\n"
+ " Charset=134\r\n"
+ " End\r\n";

ColumnTitleCell+= StringMulTitle(dt, 0);
ColumnTitleCell += "End\r\n";
str += ColumnTitleCell;
paramater+="Object PageHeader\r\n"
+ " Height=0\r\n"
+ " End\r\n"
+ " Object PageFooter\r\n"
+ " Height=1.00542\r\n"
+ " Items Control\r\n"
+ " Item\r\n"
+ " Type=RichTextBox\r\n"
+ " Name=‘RichTextBox1‘\r\n"
+ " Left=16.5894\r\n"
+ " Top=1.40229\r\n"
+ " Width=2.4\r\n"
+ " Height=0.5\r\n"
+ " End\r\n"
+ " Item\r\n"
+ " Type=MemoBox\r\n"
+ " Name=‘MemoBox2‘\r\n"
+ " Left=0.79375\r\n"
+ " Top=0.211667\r\n"
+ " Width=26.0085\r\n"
+ " Height=0.608542\r\n"
+ " TextAlign=MiddleCenter\r\n"
+ " Text=‘第 [#SystemVar(PageNumber)#] 頁‘\r\n"
+ " End\r\n"
+ " End\r\n"
+ "End\r\n"
+ "Items Parameter\r\n"
+ " Item\r\n"
+ " Name=‘病區‘\r\n"
+ " End\r\n"
+ " Item\r\n"
+ " Name=‘床號‘\r\n"
+ " End\r\n"
+ " Item\r\n"
+ " Name=‘姓名‘\r\n"
+ " End\r\n"
+ " Item\r\n"
+ " Name=‘性別‘\r\n"
+ " End\r\n"
+ " Item\r\n"
+ " Name=‘年齡‘\r\n"
+ " End\r\n"
+ " Item\r\n"
+ " Name=‘住院號‘\r\n"
+ " End\r\n"
+ " Item\r\n"
+ " Name=‘入院日期‘\r\n"
+ " End\r\n"
+ " Item\r\n"
+ " Name=‘診斷‘\r\n"
+ " End\r\n"
+ " Item\r\n"
+ " Name=‘科別‘\r\n"
+ " End\r\n"
+ "End\r\n"
+ "Items ReportHeader\r\n"
+ " Item\r\n"
+ " Name=‘ReportHeader1‘\r\n"
+ " Height=2.59292\r\n"
+ " Items Control\r\n"
+ " Item\r\n"
+ " Type=MemoBox\r\n"
+ " Name=‘科別‘\r\n"
+ " Top=1.5875\r\n"
+ " Width=26.8023\r\n"
+ " Height=1.00542\r\n"
+ " Text=‘科別:[#科別#] 病區:[#病區#] 床號:[#床號#] 姓名:[#姓名#] 性別:[#性別#] 年齡:[#年齡#] 住院號:[#住院號#] 入院日期:[#入院日期#] 診斷:[#診斷#]‘\r\n"
+ " End\r\n"
+ " Item\r\n"
+ " Type=MemoBox\r\n"
+ " Name=‘MemoBox1‘\r\n"
+ " Dock=Top\r\n"
+ " Center=Horizontal\r\n"
+ " Height=1.5875\r\n"
+ " Object Font\r\n"
+ " Name=‘宋體‘\r\n"
+ " Size=157500,0\r\n"
+ " Bold=T\r\n"
+ " Charset=134\r\n"
+ " End\r\n"
+ " TextAlign=MiddleCenter\r\n"
+ " Text=‘"+NurName+"‘\r\n"
+ " End\r\n"
+ " End\r\n"
+ " RepeatOnPage=T\r\n"
+ " End\r\n"
+ "End\r\n";
str += paramater;
str += "End";
sw.WriteLine(str);
sw.Close();
return 0;

}

根據dataTable動態生成grid++report 的方法