FineUI 官方论坛
标题:
lodop打印程序:附件里有程序改成js这样程序
[打印本页]
作者:
shouzhi2007
时间:
2014-9-29 10:02
标题:
lodop打印程序:附件里有程序改成js这样程序
本帖最后由 shouzhi2007 于 2014-9-29 11:06 编辑
public static string GetPrintHtmlJS(string title, string strKacode, string strFixedCode, string strName, string strSpecification, string strMoney, string strDept, string strUseTime, string strPlace, string strNumber, string strListStatus, string strListUnit, string strUseUser, string strDes, int layout, string top, string left, string width, string height, string strHtml)
{
var sb = new StringBuilder();
sb.AppendLine(" function PrintTable(title,layout,strHtml) {");
sb.AppendLine(" LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));");
sb.AppendLine(" LODOP.NewPage();");
sb.AppendLine(" LODOP.PRINT_INITA(0,0,378,186, '" + title + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(2,41,300,33,"非生产用固定资产条");");
sb.AppendLine(" LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑");");
sb.AppendLine(" LODOP.SET_PRINT_STYLEA(0,"FontSize",16);");
sb.AppendLine(" LODOP.SET_PRINT_STYLEA(0,"Alignment",2);");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(77,196,65,17,"卡片编码");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(96,196,65,17,"使用部门");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(115,197,65,17,"启用日期");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(134,196,65,17,"序号");");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(151,6,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(153,78,292,17,'" + strPlace + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(133,265,105,17,'" + strNumber + "'+"-1");");
sb.AppendLine(" LODOP.PREVIEW();");
sb.AppendLine(" };");
sb.AppendFormat("window.setTimeout(function(){{PrintTable('{0}',{1},'{2}');}},100);", title, strKacode, strFixedCode, strName, strSpecification, strMoney, strDept, strUseTime, strPlace, strNumber, strListStatus, strListUnit, strUseUser, strDes, layout, HttpUtility.JavaScriptStringEncode(strHtml));
return sb.ToString();
}
protected void btnPrint_Click(object sender, EventArgs e)
{
List<int> ids = GetSelectedDataKeyIDs(Grid1);
for (int i = 1; i < ids.Count; i++)
{
Non_FixedAssets current = DB.Non_FixedAssetss.Where(eq => ids.Contains(eq.ID)).FirstOrDefault();
if (current == null)
{
// 参数错误,首先弹出Alert对话框然后关闭弹出窗口
Alert.Show("参数错误!", String.Empty, ActiveWindow.GetHideReference());
return;
}
var title = "资产条";
var strKacode = current.Non_KaCode;
var strFixedCode = current.Non_FixedCode;
var strName = current.Non_Name;
var strSpecification = current.Non_Specification;
var strDept = current.Non_Dept;
var strTable = "";
PageContext.RegisterStartupScript(FixedAssets_non.GetPrintHtmlJS(title, strKacode, strFixedCode, strName, strSpecification, strMoney, strDept, strUseTime, strPlace, strNumber, strListStatus, strListUnit, strUseUser, strDes, 1, "10", "15", ""96%"", "88", strTable));
}
}
复制代码
这个C#代码,改成类似:以下JS代
<script language="javascript" type="text/javascript">
var LODOP; //声明为全局变量
function MyPreview() {
LODOP=getLodop();
LODOP.PRINT_INIT("打印控件Lodop功能演示_多页预览");
LODOP.SET_PRINT_PAGESIZE(1,500,508,"");
CreateAllPages();
LODOP.PREVIEW();
};
function CreateAllPages(){
for (i = 1; i < 8; i++) {
LODOP.NewPage();
LODOP.ADD_PRINT_RECT(10,18,128,160,0,1);
LODOP.ADD_PRINT_TEXT(31,33,111,20,"商品编号:"+document.getElementById("BH"+i).value);
LODOP.ADD_PRINT_TEXT(69,33,111,20,"商品名称:"+document.getElementById("MC"+i).value);
LODOP.ADD_PRINT_TEXT(107,33,111,20,"商品数量:"+document.getElementById("SL"+i).value);
LODOP.ADD_PRINT_TEXT(146,33,111,20,"商品单价:"+document.getElementById("DJ"+i).value);
}
};
</script>
复制代码
图片效果
作者:
xxdddail
时间:
2014-9-29 12:10
支持一下!!顶!!
作者:
shouzhi2007
时间:
2014-10-1 10:31
搞定了
作者:
shouzhi2007
时间:
2014-10-1 10:32
public static string GetPrintHtmlJS(List<int> ids)
{
var sb = new StringBuilder();
sb.AppendLine(" function PrintTable() {");
sb.AppendLine(" LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));");
sb.AppendLine(" LODOP.PRINT_INITA(0,0,378,186, "非生产用固定资产条");");
sb.AppendLine(" LODOP.SET_PRINT_PAGESIZE(0,1000,500,"");");
var fSumvalue = 0;
var PrintTime = 1;
//取到ids的批量值
for (int i = 0; i < ids.Count; i++)
{
//从LIST里取值,并强制转化为int型
int id = int.Parse(ids[i].ToString());
//通过ID查询出值
Non_FixedAssets current = DB.Non_FixedAssetss.Where(eq => eq.ID == id).FirstOrDefault();
var strKacode = current.Non_KaCode;
var strFixedCode = current.Non_FixedCode;
var strName = current.Non_Name;
var strSpecification = current.Non_Specification;
var strDept = current.Non_Dept;
var strUseTime = current.Non_UseTime;
var strPlace = current.Non_Place;
var strNumber = current.Non_Number;
var strListStatus = current.Non_Status;
var strListUnit = current.Non_Unit;
var strUseUser = current.Non_UseUser;
var strMoney = current.Non_Money;
var strDes = current.Non_DES;
fSumvalue = fSumvalue + int.Parse(strNumber);
if (fSumvalue < 50)
{
for (int y = 1; y < int.Parse(strNumber)+1; y++)
{
//可以用NewPage函数直接强制在新一页的固定位置输出。
sb.AppendLine(" LODOP.NewPage();");
//以下都是设置
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(2,41,300,33,"非生产用固定资产条");");
sb.AppendLine(" LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑");");
sb.AppendLine(" LODOP.SET_PRINT_STYLEA(0,"FontSize",16);");
sb.AppendLine(" LODOP.SET_PRINT_STYLEA(0,"Alignment",2);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(56,6,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(56,75,298,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(37,6,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(37,75,298,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(75,263,110,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(75,194,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(75,75,120,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(75,6,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(94,263,110,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(94,194,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(94,75,120,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(94,6,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(113,263,110,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(113,194,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(113,75,120,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(113,6,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(132,263,110,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(132,194,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(132,75,120,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(132,6,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(152,8,65,17,"存放地点");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(39,9,65,17,"资产名称");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(77,9,65,17,"资产编码");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(96,9,65,17,"资产原值");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(115,9,65,17,"责任人");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(134,9,65,17,"数量");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(58,9,65,17,"规格型号");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(77,196,65,17,"卡片编码");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(96,196,65,17,"使用部门");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(115,197,65,17,"启用日期");");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(134,196,65,17,"序号");");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(151,6,70,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_RECT(151,75,298,20,0,1);");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(76,79,115,17,'" + strFixedCode + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(39,79,291,17, '" + strName + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(115,79,115,17,'" + strUseUser + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(96,79,115,17,'" + strMoney + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(134,79,115,17,'" + strNumber + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(57,80,291,17,'" + strSpecification + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(78,266,105,17,'" + strKacode + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(97,265,105,17,'" + strDept + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(116,265,105,17,'" + strUseTime + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(153,78,292,17,'" + strPlace + "');");
sb.AppendLine(" LODOP.ADD_PRINT_TEXT(133,265,105,17,'" + strNumber + "'+"-"+'"+y+"');");
}
}
else {
Alert.ShowInTop("大姐啊!你选择单条数据,数量已经达到:" + fSumvalue + ",所选择的数量大于50,暂时不会打印了!");
}
// Non_FixedAssets current1 = DB.Non_FixedAssetss.Where(eq => ids.Contains(eq.ID)).FirstOrDefault();
//打印次数
current.Non_PrintTimes += PrintTime;
//更新打印次数
DB.SaveChanges();
}
if (fSumvalue < 50) {
//打印预览
Alert.ShowInTop("你已经选择了:" + ids.Count + "条数量!会打印:" + fSumvalue + "次!");
sb.AppendLine(" LODOP.PREVIEW();");
}
else
{
Alert.ShowInTop("大姐啊!你选择了:" + ids.Count + "条数据,但数量已经达到:" + fSumvalue + ",所选择的数量大于50,暂时不会打印了!");
}
sb.AppendLine(" };");
sb.AppendFormat("window.setTimeout(function(){{PrintTable();}},100);", ids);
return sb.ToString();
}
protected void btnPrint_Click(object sender, EventArgs e)
{
//从表格里得到LIST的值
List<int> ids = GetSelectedDataKeyIDs(Grid1);
PageContext.RegisterStartupScript(FixedAssets_non.GetPrintHtmlJS(ids));
}
复制代码
欢迎光临 FineUI 官方论坛 (https://fineui.com/bbs/)
Powered by Discuz! X3.4