Files
SGGL_SHJ/SGGL/BLL/Common/PrinterDocService.cs
T

82 lines
3.9 KiB
C#
Raw Normal View History

namespace BLL
2022-09-05 16:36:31 +08:00
{
using System.Collections.Generic;
using System.Linq;
using System.Text;
/// <summary>
/// 人员上岗证打印服务。
2022-09-05 16:36:31 +08:00
/// </summary>
public static class PrinterDocService
{
/// <summary>
/// 输出人员上岗证打印内容。
2022-09-05 16:36:31 +08:00
/// </summary>
public static void PrinterDocMethod(string menuId, string id, string name)
{
System.Web.HttpContext.Current.Response.ClearContent();
string htmlStr = menuId == Const.SendCardMenuId ? GetSendCardHtml(id) : string.Empty;
if (!string.IsNullOrEmpty(htmlStr))
{
string filename = name + Funs.GetNewFileName();
System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename="
+ System.Web.HttpUtility.UrlEncode(filename, Encoding.UTF8) + ".doc");
System.Web.HttpContext.Current.Response.ContentType = "application/word";
System.Web.HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
System.Web.HttpContext.Current.Response.Write(htmlStr);
System.Web.HttpContext.Current.Response.End();
}
}
2022-09-05 16:36:31 +08:00
/// <summary>
/// 生成人员上岗证打印表格。
/// </summary>
public static string GetSendCardHtml(string personIds)
{
Model.SGGLDB db = Funs.DB;
StringBuilder sb = new StringBuilder();
sb.Append("<meta http-equiv=\"content-type\" content=\"application/word; charset=UTF-8\"/>");
sb.Append("<table width=\"100%\" cellspacing=\"0\" border=\"0\" style=\"border-collapse:collapse;\">");
List<string> personIdList = Funs.GetStrListByStr(personIds, ',');
foreach (string personId in personIdList)
2022-09-05 16:36:31 +08:00
{
Model.SitePerson_Person sitePerson = SitePerson_PersonService.GetSitePersonById(personId);
if (sitePerson == null)
2022-09-05 16:36:31 +08:00
{
continue;
2022-09-05 16:36:31 +08:00
}
Model.Person_Persons person = Person_PersonsService.GetPerson_PersonsByIdCard(sitePerson.IdentityCard);
if (person == null)
2022-09-05 16:36:31 +08:00
{
continue;
2022-09-05 16:36:31 +08:00
}
string qrUrl = person.QRCodeAttachUrl;
if (string.IsNullOrEmpty(qrUrl) || !CreateQRCodeService.isHaveImage(qrUrl))
2022-09-05 16:36:31 +08:00
{
qrUrl = CreateQRCodeService.CreateCode_Simple(sitePerson.IdentityCard);
person.QRCodeAttachUrl = qrUrl;
db.SubmitChanges();
2022-09-05 16:36:31 +08:00
}
sb.Append("<tr style=\"height:180px;\">");
sb.Append("<td align=\"center\" style=\"width:30%;\">");
sb.AppendFormat("<img width='85' height='110' src='{0}'></img>", (Funs.SGGLUrl + person.PhotoUrl).Replace('\\', '/'));
sb.Append("</td>");
sb.Append("<td align=\"left\" style=\"width:45%;font-size:10pt;line-height:28px;\">");
sb.AppendFormat("公司:{0}<br />", "赛鼎工程有限公司");
sb.AppendFormat("项目:{0}<br />", ProjectService.GetShortNameByProjectId(sitePerson.ProjectId));
sb.AppendFormat("单位:{0}<br />", UnitService.GetUnitNameByUnitId(sitePerson.UnitId));
sb.AppendFormat("岗位:{0}<br />", WorkPostService.getWorkPostNameById(sitePerson.WorkPostId));
sb.AppendFormat("姓名:{0}<br />编号:{1}", sitePerson.PersonName, sitePerson.CardNo);
sb.Append("</td>");
sb.AppendFormat("<td align=\"center\" style=\"width:25%;\"><img width='60' height='50' src='{0}'></img></td>", (Funs.SGGLUrl + qrUrl).Replace('\\', '/'));
2022-09-05 16:36:31 +08:00
sb.Append("</tr>");
}
sb.Append("</table>");
2022-09-05 16:36:31 +08:00
return sb.ToString();
}
}
}