/// <summary> /// 打印报表预览 /// </summary> /// <param name="dt_print"></param> /// <param name="str_Path"></param> private void Print(DataTable dt_print, string str_Path) { DataTable dt = new DataTable(); //处理ds1 dt = this.dtx(dt_print); ReportDocument myReport = new ReportDocument(); List<string> L_Fname = new List<string>(); //输入中文字段名 for (int i = 0; i < dataGridView2.Columns.Count; i++) { string str_dpName = dataGridView2.Columns[i].HeaderText; L_Fname.Add(str_dpName); } Form_Crt_test form_test = new Form_Crt_test(); form_test.Str_Path = str_Path; form_test.L_Fname = L_Fname; form_test.Dt = dt; form_test.Show(); }
private void button_Print_Click(object sender, EventArgs e) { string str_CrtPath = Application.StartupPath + "/CReporter/CRt_Out2.rpt"; string str_OutIdPath = Application.StartupPath + "/OutId.xml"; Ds_Out dsOut = new Ds_Out(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path); XmlNode xnRoot = xmlDoc.SelectSingleNode("List"); int i = 1; dsOut.Tables[0].Rows.Add(); foreach (XmlNode xn in xnRoot.ChildNodes) { XmlNodeList oList = xn.ChildNodes; dsOut.Tables[0].Rows[0]["MName"+i] = oList[0].InnerText; dsOut.Tables[0].Rows[0]["MType" + i] = oList[1].InnerText; dsOut.Tables[0].Rows[0]["OSNum" + i] = oList[4].InnerText; dsOut.Tables[0].Rows[0]["Munit" + i] = oList[5].InnerText; dsOut.Tables[0].Rows[0]["MPrice" + i] = oList[2].InnerText; dsOut.Tables[0].Rows[0]["OSTotalPrice" + i] = oList[9].InnerText; dsOut.Tables[0].Rows[0]["OSRemark" + i] = oList[12].InnerText; dsOut.Tables[0].Rows[0]["FCName" + i] = oList[13].InnerText; i++; } XmlNodeList oList1 = xnRoot.ChildNodes[0].ChildNodes; //设置打印单号: XmlDocument outDoc = new XmlDocument(); outDoc.Load(str_OutIdPath); XmlNode xnIdRoot = outDoc.SelectSingleNode("Out"); XmlNodeList idList = xnIdRoot.ChildNodes; XmlNode xnId = idList[0]; XmlNode xnDate = idList[1]; List<string> L_info = new List<string>();//设置报表公式字段 L_info.Add(oList1[6].InnerText); L_info.Add(oList1[11].InnerText); L_info.Add(oList1[6].InnerText); L_info.Add(oList1[8].InnerText); L_info.Add(oList1[10].InnerText); L_info.Add(xnDate.InnerText+ xnId.InnerText); Form_Crt_test form_out = new Form_Crt_test(L_info,str_CrtPath); form_out.Str_Path = str_CrtPath; form_out.Ds = dsOut; form_out.Show(); }