print.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using gjjy.util;
using System.Data.SQLite;
using System.Data;
using System.IO;
using System.Collections;
using gjjy.Entity;
namespace gjjy
{
class print
{
public void printzb(string bh){
//单证号传给制证页面
string zwjyzsbh = "";
string zsfwdp = "";
string zsfwdc = "";
string zsfwdxian = "";
string yxqy = "";
string yxqm = "";
string yxqd = "";
string shdw = "";
string shdwlxr = "";
string shdwdz = "";
string shdwsheng = "";
string shdwshi = "";
string shdwxian = "";
string shdwdh = "";
string fhdw = "";
string fhdwdh = "";
string fhdwdz = "";
string fhdwsheng = "";
string fhdwshi = "";
string fhdwxian = "";
string fhdwlxr = "";
string hwmc = "";
string ycd = "";
string pzmc = "";
string sl = "";
string ysgj = "";
string qydddz = "";
string qyddsheng = "";
string qyddshi = "";
string qyddxian = "";
string ywddsheng = "";
string ywddshi = "";
string ywddxian = "";
string ywdddz = "";
string bzfs = "";
string js = "";
string zwcpsy = "";
string cdjyhgzfxk = "";
string cjhgzh = "";
string dyjyfxk = "";
string djsbid = "";
string clff = "";
string hxywjnd = "";
string cxsjhwd = "";
string jyy = "";
string qfrqy = "";
string qfrqm = "";
string qfrqd = "";
string zsid = "";
string zslb = "";
string pash = "";
string pashimg = "";
using (SQLiteConnection con = new SQLiteConnection(Constants.DATA_SOURCE))
{
con.Open();
using (SQLiteCommand cmd = new SQLiteCommand())
{
cmd.Connection = con;
cmd.CommandText = string.Format(@"select zs.[zwjyzsbh] as zwjyzsbh,
zs.[lb] as zslb,
(select org.org_short_name from sys_orgtable org where zs.zsfwdp = org.org_id) as zsfwdp,
(select org.org_short_name from sys_orgtable org where zs.zsfwdc = org.org_id) as zsfwdc,
(select org.org_short_name from sys_orgtable org where zs.zsfwdxian = org.org_id) as zsfwdxian,
substr(zs.[yxq],0,5) yxqy,
substr(zs.[yxq],6,2) yxqm,
substr(zs.[yxq],9,2) yxqd,
(select enp.[name] from jy_enterprise enp where enp.[id] = zs.[shdw]) as shdw,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[shdwp] ) as shdwsheng,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[shdwc] ) as shdwshi,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[shdwxian] ) as shdwxian,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[shdwx] ) as shdwx,
zs.[shdwdz] as shdwdz,
zs.[shdw_dh] as shdwdh,
zs.[shdw_lxr] as shdwlxr,
(select enp.[name] from jy_enterprise enp where enp.[id] = zs.[fhdw]) as fhdw,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[fhdwp] ) as fhdwsheng,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[fhdwc] ) as fhdwshi,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[fhdwxian] ) as fhdwxian,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[fhdwx] ) as fhdwx,
zs.[fhdw_dz] as fhdwdz,
zs.[fhdw_dh] as fhdwdh,
zs.[fhdw_lxr] as fhdwlxr,
(select dic.name from jy_dic_crop dic where dic.[id] = zs.[hwmc]) as hwmc,
zs.[zwycd] as ycd,
zs.[zwpzmc] as pzmc,
zs.[sl] as sl,
(select dic.name from sys_dic dic where dic.[code] = zs.sl_dw)as sldw,
(select dic.name from sys_dic dic where dic.[code] = zs.ysgj) as ysgj,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[qyddp] ) as qyddsheng,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[qyddc] ) as qyddshi,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[qyddxian] ) as qyddxian,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[qyddx] ) || zs.[qydd] as qydsx,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[ywddp] ) as ywddsheng,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[ywddc] ) as ywddshi,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[ywddxian] ) as ywddxian,
(select dics.[name] from jy_dic_district dics where dics.[id] = zs.[ywddx] ) || zs.[ywdd] as ywdsx,
(select dic.name from sys_dic dic where dic.[code] = zs.[bzfs]) as bzfs,
zs.[js] as js,
zs.[zwcpsy] as zwcpsy,
zs.[cdjyhgzfxk] as cdjyhgzfxk,
zs.[cjhgzh] as cjhgzh ,
zs.[dyjyfxk] as dyjyfxk,
zs.[djsb_id] as djsbid,
zs.[clff] as clff,
zs.[hxywjnd] as hxywjnd,
zs.[cxsjhwd] as cxsjhwd,
(select u.username from userinfo u where u.[userid]=zs.[jyy]) as jyy,
substr(zs.[qfrq],0,5) qfrqy,
substr(zs.[qfrq],6,2) qfrqm,
substr(zs.[qfrq],9,2) qfrqd,
zs.[id] as zsid
from offline_jy_dyjy_zwjyzs zs left join offline_jy_dyjy_zwjyzs_pzsl zsmx on zs.[id] = zsmx.pid
where zs.[zwjyzsbh] ='" + bh + "'");
using (SQLiteDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read())
{
zwjyzsbh = dr["zwjyzsbh"].ToString();
zsfwdp = dr["zsfwdp"].ToString();
if (dr["zsfwdxian"].ToString().Equals(""))
{
zsfwdc = dr["zsfwdc"].ToString();
}else{
zsfwdc = dr["zsfwdxian"].ToString();
}
zsfwdxian = dr["zsfwdxian"].ToString();
yxqy = dr["yxqy"].ToString();
yxqm = dr["yxqm"].ToString();
yxqd = dr["yxqd"].ToString();
shdw = dr["shdw"].ToString();
shdwdh = dr["shdwdh"].ToString();
shdwlxr = dr["shdwlxr"].ToString();
shdwsheng = dr["shdwsheng"].ToString();
shdwshi = dr["shdwshi"].ToString();
shdwxian = dr["shdwxian"].ToString();
if ("市辖区" == shdwshi || "县" == shdwshi)
{
shdwshi = "";
}
shdwdz = shdwsheng + shdwshi + shdwxian + dr["shdwx"].ToString() + dr["shdwdz"].ToString();
fhdw = dr["fhdw"].ToString();
fhdwdh = dr["fhdwdh"].ToString();
fhdwlxr = dr["fhdwlxr"].ToString();
fhdwsheng = dr["fhdwsheng"].ToString();
fhdwshi = dr["fhdwshi"].ToString();
fhdwxian = dr["fhdwxian"].ToString();
if ("市辖区" == fhdwshi || "县" == fhdwshi)
{
fhdwshi = "";
}
fhdwdz = fhdwsheng + fhdwshi + fhdwxian +dr["fhdwx"].ToString() + dr["fhdwdz"].ToString();
hwmc = dr["hwmc"].ToString();
ycd = dr["ycd"].ToString();
pzmc = dr["pzmc"].ToString();
sl = dr["sl"].ToString()+dr["sldw"].ToString();
ysgj = dr["ysgj"].ToString();
qyddsheng = dr["qyddsheng"].ToString();
qyddshi = dr["qyddshi"].ToString();
qyddxian = dr["qyddxian"].ToString();
if ("市辖区" == qyddshi || "县" == qyddshi)
{
qyddshi = "";
}
qydddz = qyddsheng + qyddshi + qyddxian + dr["qydsx"].ToString();
ywddsheng = dr["ywddsheng"].ToString();
ywddshi = dr["ywddshi"].ToString();
ywddxian = dr["ywddxian"].ToString();
if ("市辖区" == ywddshi || "县" == ywddshi)
{
ywddshi = "";
}
ywdddz = ywddsheng + ywddshi + ywddxian + dr["ywdsx"].ToString();
bzfs = dr["bzfs"].ToString();
js = dr["js"].ToString();
zwcpsy = dr["zwcpsy"].ToString();
cdjyhgzfxk = dr["cdjyhgzfxk"].ToString();
cjhgzh = dr["cjhgzh"].ToString();
djsbid = dr["djsbid"].ToString();
dyjyfxk = dr["dyjyfxk"].ToString();
clff = dr["clff"].ToString();
hxywjnd = dr["hxywjnd"].ToString();
cxsjhwd = dr["cxsjhwd"].ToString();
jyy = dr["jyy"].ToString();
qfrqy = dr["qfrqy"].ToString();
qfrqm = dr["qfrqm"].ToString();
qfrqd = dr["qfrqd"].ToString();
zsid = dr["zsid"].ToString();
zslb = dr["zslb"].ToString();
}
}
}
}
using (SQLiteConnection con = new SQLiteConnection(Constants.DATA_SOURCE))
{
con.Open();
using (SQLiteCommand cmd = new SQLiteCommand())
{
cmd.Connection = con;
cmd.CommandText = string.Format(@"select zsmx.[pzycd] as ycd from offline_jy_dyjy_zwjyzs zs ,offline_jy_dyjy_zwjyzs_pzsl zsmx
where zs.[zwjyzsbh] = '" + zsid + "' and zs.[id]= zsmx.[pid]");
using (SQLiteDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read())
{
if (null != dr["ycd"].ToString() || "" != dr["ycd"].ToString())
{
ycd = "见附件";
}
}
}
}
}
gjjy.NVelocityHelper.VelocityHelper vh = new gjjy.NVelocityHelper.VelocityHelper();
vh.Init(@"template");//指定模板文件的相对路径
vh.Put("title", "员工信息");
vh.Put("zwjyzsbh", zwjyzsbh);
vh.Put("zsfwdp", zsfwdp);
vh.Put("zsfwdc", zsfwdc);
vh.Put("zsfwdxian", zsfwdxian);
vh.Put("yxqy", yxqy);
vh.Put("yxqm", yxqm);
vh.Put("yxqd", yxqd);
vh.Put("shdw", shdw);
vh.Put("shdwdz", shdwdz);
vh.Put("shdwdh", shdwdh);
vh.Put("shdwlxr", shdwlxr);
vh.Put("fhdw", fhdw);
vh.Put("fhdwdz", fhdwdz);
vh.Put("fhdwdh", fhdwdh);
vh.Put("fhdwlxr", fhdwlxr);
vh.Put("hwmc", hwmc);
vh.Put("ycd", ycd);
vh.Put("pzmc", pzmc);
vh.Put("sl", sl);
vh.Put("ysgj", ysgj);
vh.Put("qydddz", qydddz);
vh.Put("ywdddz", ywdddz);
vh.Put("bzfs", bzfs);
vh.Put("js", js);
if (zwcpsy == "1")
{
vh.Put("zwcpsy", "√");
vh.Put("zwcpsy1", "");
}
else {
vh.Put("zwcpsy", "");
vh.Put("zwcpsy1", "√");
}
if (cdjyhgzfxk == "1")
{
vh.Put("cdjyhgzfxk", "√");
vh.Put("cjhgzh", cjhgzh);
vh.Put("dyjyfxk", "");
}
else {
vh.Put("cdjyhgzfxk", "");
vh.Put("cjhgzh", "");
vh.Put("dyjyfxk", "");
}
if (dyjyfxk == "1")
{
vh.Put("cdjyhgzfxk", "");
vh.Put("cjhgzh", "");
vh.Put("dyjyfxk", "√");
}
else
{
vh.Put("cdjyhgzfxk", "");
vh.Put("cjhgzh", "");
vh.Put("dyjyfxk", "");
}
vh.Put("clff", clff);
vh.Put("hxywjnd", hxywjnd);
vh.Put("cxsjhwd", cxsjhwd);
vh.Put("jyy", jyy);
vh.Put("qfrqy", qfrqy);
vh.Put("qfrqm", qfrqm);
vh.Put("qfrqd", qfrqd);
vh.Put("zslb", zslb);
pash = Directory.GetCurrentDirectory();
// String pash = System.IO.Path.GetDirectoryName("page.htm"); //返回文件所在目录
if (zslb.Equals("1"))
{
pashimg = pash + "\\template\\JY_DYJY_SNZWJYZS.jpg";
pashimg=pashimg.Replace("\\", "/");
}
else {
pashimg = pash + "\\template\\JY_DYJY_SJZWJYZS.jpg";
pashimg=pashimg.Replace("\\", "/");
}
pash = pash.Replace("\\", "/");
vh.Put("pash", pash);
vh.Put("pashimg", pashimg);
//使用tp1.htm模板显示
String htm = vh.Display("page.htm");
FrmWebBrowser frmView = new FrmWebBrowser();
frmView.webBrowser1.DocumentText = htm;
//frmView.Show();
}
public void printmx(string bh) {
//单证号传给制证页面
string zwjyzsbh = "";
string hwmc = "";
string zwpzmc = "";
string dysl = "";
string dysldw = "";
string sheng = "";
string shi = "";
string xian = "";
string pzycd = "";
string qfrqy = "";
string qfrqm = "";
string qfrqd = "";
string qfjg = "";
Double sl = 0;
string pash = "";
string recno = "";
string id = "";
ArrayList aems = new ArrayList();
using (SQLiteConnection con = new SQLiteConnection(Constants.DATA_SOURCE))
{
con.Open();
using (SQLiteCommand cmd = new SQLiteCommand())
{
cmd.Connection = con;
cmd.CommandText = string.Format(@"select zs.[zwjyzsbh] as zwjyzsbh,
(select dic.name from jy_dic_crop dic where dic.[id] = zs.[hwmc]) as hwmc,
(select org.org_name from sys_orgtable org where zs.qfjg = org.org_id) as qfjg,
zs.[sl] as sl,
zsmx.[dysl] as dysl,
zsmx.[dysl_dw] as dysldw,
zsmx.[zwpzmc] as zwpzmc,
substr(zs.[qfrq],0,5) qfrqy,
substr(zs.[qfrq],6,2) qfrqm,
substr(zs.[qfrq],9,2) qfrqd,
(select name from jy_dic_district dics where dics.[id] = zsmx.[sheng]) as sheng,
(select name from jy_dic_district dics where dics.[id] = zsmx.[shi]) as shi,
(select name from jy_dic_district dics where dics.[id] = zsmx.[xian]) as xian,
zs.[id] as zsid
from offline_jy_dyjy_zwjyzs zs,offline_jy_dyjy_zwjyzs_pzsl zsmx
where zs.[zwjyzsbh] ='" + bh + "'and zs.id = zsmx.pid");
using (SQLiteDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
int i = 0;
while (dr.Read())
{ i++;
zwjyzsbh = dr["zwjyzsbh"].ToString();
hwmc = dr["hwmc"].ToString();
zwpzmc = dr["zwpzmc"].ToString();
dysl = dr["dysl"].ToString();
sl = sl + Convert.ToDouble(dysl);
dysldw = dr["dysldw"].ToString();
sheng = dr["sheng"].ToString();
shi = dr["shi"].ToString();
xian = dr["xian"].ToString();
qfrqy = dr["qfrqy"].ToString();
qfrqm = dr["qfrqm"].ToString();
qfrqd = dr["qfrqd"].ToString();
qfjg = dr["qfjg"].ToString();
ZwjyzsPzsl mx = new ZwjyzsPzsl();
if ("市辖区" == shi || "县" == shi)
{
shi = "";
}
mx.sheng = sheng;
mx.shi = shi;
mx.xian = xian;
mx.zwpzmc = zwpzmc;
mx.id = i.ToString();
mx.dysl = Convert.ToDouble(dysl);
aems.Add(mx);
}
}
}
}
gjjy.NVelocityHelper.VelocityHelper vh = new gjjy.NVelocityHelper.VelocityHelper();
vh.Init(@"template");//指定模板文件的相对路径
vh.Put("title", "员工信息");
vh.Put("zwjyzsbh", zwjyzsbh);
vh.Put("hwmc", hwmc);
vh.Put("sl", sl);
vh.Put("dysldw", dysldw);
vh.Put("qfrqy", qfrqy);
vh.Put("qfrqm", qfrqm);
vh.Put("qfrqd", qfrqd);
vh.Put("qfjg", qfjg);
vh.Put("recno", recno);
vh.Put("aems", aems);
pash = Directory.GetCurrentDirectory();
vh.Put("pash", pash);
//使用tp1.htm模板显示
String htm = vh.Display("my.htm");
FrmWebBrowser frmView = new FrmWebBrowser();
frmView.webBrowser1.DocumentText = htm;
//frmView.Show();
}
}
}
NVelocityHelper.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using NVelocity;
using NVelocity.App;
using NVelocity.Exception;
using NVelocity.Runtime;
using System.IO;
using Commons.Collections;
using NVelocity.Context;
namespace gjjy
{
class NVelocityHelper
{ ///
/// NVelocity模板工具类 VelocityHelper
///
public class VelocityHelper
{
private VelocityEngine velocity = null;
private IContext context = null;
///
/// 构造函数
///
///模板文件夹路径
public VelocityHelper(string templatDir)
{
Init(templatDir);
}
///
/// 无参数构造函数
///
public VelocityHelper() { ;}
///
/// 初始话NVelocity模块
///
///模板文件夹路径
public void Init(string templatDir)
{
//创建VelocityEngine实例对象
velocity = new VelocityEngine();
//使用设置初始化VelocityEngine
ExtendedProperties props = new ExtendedProperties();
props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");
props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatDir);
props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
velocity.Init(props);
//为模板变量赋值
context = new VelocityContext();
}
///
/// 给模板变量赋值
///
///模板变量
///模板变量值
public void Put(string key, object value)
{
if (context == null)
context = new VelocityContext();
context.Put(key, value);
}
///
/// 显示模板
///
///模板文件名
public String Display(string templatFileName)
{
//从文件中读取模板
Template template = velocity.GetTemplate(templatFileName);
//合并模板
StringWriter writer = new StringWriter();
template.Merge(context, writer);
return writer.ToString();
}
}
}
}
建立FrmWebBrowser输出框类
-->视图-->工具箱-->
-->拖动到form2中-->设置属性-->
FrmWebBrowser.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace gjjy
{
public partial class FrmWebBrowser : Form
{
public FrmWebBrowser()
{
InitializeComponent();
}
private void FrmWebBrowser_Load(object sender, EventArgs e)
{
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void FrmWebBrowser_Load_1(object sender, EventArgs e)
{
}
}
}
在Debug下建立模板工程,
建立模板htm文档。