• 打印功能


    1.页面

    2 后台

    /// <summary>
    /// 打印
    /// </summary>
    /// <param name="sHospitalID"></param>
    /// <param name="sDepartmentID"></param>
    /// <param name="sExamType"></param>
    /// <param name="sYear"></param>
    /// <returns></returns>
    [AjaxMethod]
    public string GetHTML(string sYear,string sHiddenExamType)
    {
    DataTable dtStatistics = GetMaskulinTotal(sYear, sHiddenExamType, true);
    return new SystemManage().GetHTML(dtStatistics, "XXX统计", string.Format("{0}-01", sYear), string.Format("{0}-12", sYear),40);
    }

    3.核心

    /// <summary>
    /// 打印方法重载 添加自定义单元格高度
    /// </summary>
    /// <param name="dtData"></param>
    /// <param name="sTitle"></param>
    /// <param name="sStartDate"></param>
    /// <param name="sEndDate"></param>
    /// <returns></returns>
    public string GetHTML(DataTable dtData, string sTitle, string sStartDate, string sEndDate,int height)
    {
    if (dtData == null) return null;
    StringBuilder strBuil = new StringBuilder();
    strBuil.Append(string.Format(" <table width='96%' border='0' cellspacing='0' cellpadding='0' style='margin-top:0px;' valign='top'><tr><td align='left' style=''>时间范围:{0}~{1}</td><td style='' align='right'>打印日期:{2}</td></tr><tr><td colspan='2' style='font-size:14px;' align='center'>{3}{4} {5}</td></tr></table>",
    sStartDate, sEndDate, DateTime.Now.ToTimeString(), UserInfo.HospitalName, UserInfo.DepartmentName, sTitle));
    strBuil.Append("<table cellpadding='0' align='center' cellspacing='0' width='96%' style='border-right:solid 1px #000;border-bottom:solid 1px #000;margin-bottom:0px;'><tr>");

    //取所有列名
    for (int i = 0; i < dtData.Columns.Count; i++)
    {
    strBuil.Append("<td align='center' style='border-top: solid 1px #000;border-left: solid 1px #000; height:"+height+"px;'>" + dtData.Columns[i].Caption + "</td>");

    }
    strBuil.Append("</tr>");
    //取每行数据
    for (int j = 0; j < dtData.Rows.Count; j++)
    {
    strBuil.Append("<tr>");
    for (int i = 0; i < dtData.Columns.Count; i++)
    {
    string sContent = dtData.Rows[j][i].ToString();
    //避免内容为空时打印出来没有边线的情况
    if (string.IsNullOrEmpty(sContent))
    {
    sContent = "&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    strBuil.Append("<td align='center' style='border-top: solid 1px #000;border-left: solid 1px #000; height:" + height + "px;'>" + sContent + "</td>");
    }
    strBuil.Append("</tr>");
    }
    strBuil.Append("</table>");
    return strBuil.ToString();
    }

    4思路 点击打印按钮 响应前台JS方法 前台JS方法调用后台异步刷新方法 返回打印内容table 赋值给页面上隐藏域.html(x.value) 最后调用JS打印方法Print() 方法 完成操作 

  • 相关阅读:
    【leetcode】1403. Minimum Subsequence in Non-Increasing Order
    【leetcode】1399. Count Largest Group
    【leetcode】1396. Design Underground System
    【leetcode】1395. Count Number of Teams
    【leetcode】1394. Find Lucky Integer in an Array
    【leetcode】1391. Check if There is a Valid Path in a Grid
    【leetcode】1390. Four Divisors
    【leetcode】1389. Create Target Array in the Given Order
    modelsim仿真基本流程
    Quartus调用MOdelsim仿真过程
  • 原文地址:https://www.cnblogs.com/sunlunhao/p/4685484.html
Copyright © 2020-2023  润新知