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

417 lines
23 KiB
C#
Raw Normal View History

2024-11-19 09:45:27 +08:00
namespace BLL
{
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Linq;
/// <summary>
/// 通用方法类。
/// </summary>
public static class PrinterDocService
{
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static void PrinterDocMethod(string menuId, string id, string name)
{
System.Web.HttpContext.Current.Response.ClearContent();
string htmlStr = string.Empty;
2026-06-15 19:05:39 +08:00
if (menuId == Const.ProjectTestRecordMenuId)
2024-11-19 09:45:27 +08:00
{
htmlStr = GetTestRecordHtml(id);
}
else if (menuId == Const.SendCardMenuId)
{
htmlStr = GetSendCardHtml(id);
}
if (!string.IsNullOrEmpty(htmlStr))
{
string filename = name + Funs.GetNewFileName();
2026-06-15 19:05:39 +08:00
System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename="
2024-11-19 09:45:27 +08:00
+ 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();
}
}
#region
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
public static string GetTestRecordHtml(string testRecordId)
{
2025-08-04 18:04:41 +08:00
Model.CNPCDB db = Funs.DB;
2024-11-19 09:45:27 +08:00
StringBuilder sb = new StringBuilder();
var getTestRecord = TestRecordService.GetTestRecordById(testRecordId);
if (getTestRecord != null)
{
var getTestItems = from x in Funs.DB.Training_TestRecordItem
2026-06-15 19:05:39 +08:00
where x.TestRecordId == testRecordId
select x;
2024-11-19 09:45:27 +08:00
sb.Append("<meta http-equiv=\"content-type\" content=\"application/word; charset=UTF-8\"/>");
sb.Append("<table width=\"100% \" cellspacing=\"0\" rules=\"all\" border=\"0\" style=\"border-collapse:collapse;font-size: 12pt;\">");
sb.Append("<tr style=\"height: 35px\">");
2025-02-05 17:57:14 +08:00
sb.AppendFormat("<td align=\"center\" style=\"width: 100%; font-size: 12pt; font-weight: bold;\">{0}</td> ", "中国天辰" + ProjectService.GetProjectNameByProjectId(getTestRecord.ProjectId));
2024-11-19 09:45:27 +08:00
sb.Append("</tr>");
sb.Append("<tr style=\"height:35px\">");
2026-06-15 19:05:39 +08:00
var getTrainTypeName = (from x in db.Training_TestPlan
2024-11-19 09:45:27 +08:00
join z in db.Training_Plan on x.PlanId equals z.PlanId
join t in db.Base_TrainType on z.TrainTypeId equals t.TrainTypeId
where x.TestPlanId == getTestRecord.TestPlanId
select t.TrainTypeName).FirstOrDefault();
sb.AppendFormat("<td align=\"center\" style=\"width: 100%; font-size: 12pt; font-weight: bold;\">{0}</td> ", getTrainTypeName ?? "" + "培训试题");
sb.Append("</tr>");
sb.Append("</table>");
sb.Append("<table width=\"100% \" cellspacing=\"0\" rules=\"all\" border=\"0\" style=\"border-collapse:collapse;font-size: 10.5pt;\">");
2026-06-15 19:05:39 +08:00
sb.Append("<tr style=\"height: 35px\">");
2024-11-19 09:45:27 +08:00
string unitName = "";
string workPostName = "";
string testName = "";
string idCard = "";
var person = Funs.DB.SitePerson_Person.FirstOrDefault(e => e.PersonId == getTestRecord.TestManId);
if (person != null)
{
unitName = BLL.UnitService.GetUnitNameByUnitId(person.UnitId);
workPostName = WorkPostService.getWorkPostNamesWorkPostIds(person.WorkPostId);
testName = person.PersonName;
idCard = person.IdentityCard;
}
2026-06-15 19:05:39 +08:00
sb.AppendFormat("<td align=\"left\" style=\"width:53%; \">{0}</td> ", "单位名称:" + unitName);
sb.AppendFormat("<td align=\"left\" style=\"width:25%;\">{0}</td> ", "工种/职务:" + workPostName);
2024-11-19 09:45:27 +08:00
sb.AppendFormat("<td align=\"left\" style=\"width:22%;\">{0}</td> ", "日期:" + string.Format("{0:yyyy-MM-dd}", getTestRecord.TestStartTime));
2026-06-15 19:05:39 +08:00
2024-11-19 09:45:27 +08:00
sb.Append("</tr>");
sb.Append("</table>");
sb.Append("<table width=\"100% \" cellspacing=\"0\" rules=\"all\" border=\"0\" style=\"border-collapse:collapse;font-size: 10.5pt;\">");
sb.Append("<tr style=\"height: 35px\">");
sb.AppendFormat("<td align=\"left\" style=\"width:25%; \">{0}</td> ", "姓名:" + testName);
sb.AppendFormat("<td align=\"left\" style=\"width:50%;\">{0}</td> ", "身份证号:" + idCard);
sb.AppendFormat("<td align=\"left\" style=\"width:25%;\">{0}</td> ", "分数:" + (getTestRecord.TestScores ?? 0).ToString());
sb.Append("</tr>");
sb.Append("</table>");
sb.Append("<table width=\"100% \" cellspacing=\"0\" rules=\"all\" border=\"0\" style=\"border-collapse:collapse;font-size: 10.5pt;\">");
///单项选择题
sb.Append("<tr style=\"height: 30px\">");
sb.AppendFormat("<td align=\"left\" style=\"width:100%; font-weight: bold;\">{0}</td> ", "一、单项选择题 (每题2分,共50分)");
sb.Append("</tr>");
2026-06-15 19:05:39 +08:00
var getSingleItem = getTestItems.Where(x => x.TestType == "1").ToList();
2024-11-19 09:45:27 +08:00
if (getSingleItem.Count > 0)
{
int num = 1;
foreach (var item in getSingleItem)
{
sb.Append("<tr style=\"height: 30px\">");
2026-06-15 19:05:39 +08:00
string Avstracts = item.Abstracts.Replace(" ", "").Replace(" ", "").Replace("", "(").Replace("", ")").Replace("()", "(" + item.SelectedItem + ")");
2024-11-19 09:45:27 +08:00
sb.AppendFormat("<td align=\"left\" style=\"width:100%;\">{0}</td> ", num + "、" + Avstracts);
sb.Append("</tr>");
sb.Append("<tr style=\"height: 30px\">");
string str = string.Empty;
if (!string.IsNullOrEmpty(item.AItem))
{
str += "A." + item.AItem;
}
if (!string.IsNullOrEmpty(item.BItem))
{
str += "&nbsp;&nbsp;B." + item.BItem;
}
if (!string.IsNullOrEmpty(item.CItem))
{
str += "&nbsp;&nbsp;C." + item.CItem;
}
if (!string.IsNullOrEmpty(item.DItem))
{
str += "&nbsp;&nbsp;D." + item.DItem;
}
sb.AppendFormat("<td align=\"left\" style=\"width:100%; \">{0}</td> ", str);
sb.Append("</tr>");
num++;
}
}
///多项选择题
sb.Append("<tr style=\"height: 30px\">");
sb.AppendFormat("<td align=\"left\" style=\"width: 100%; font-weight: bold; \">{0}</td> ", "二、多项选择题 (每题3分,共30分)");
sb.Append("</tr>");
var getMultipleItem = getTestItems.Where(x => x.TestType == "2").ToList();
if (getMultipleItem.Count > 0)
{
int num = 1;
foreach (var item in getMultipleItem)
{
2026-06-15 19:05:39 +08:00
string Avstracts = item.Abstracts.Replace(" ", "").Replace(" ", "").Replace("", "(").Replace("", ")").Replace("()", "(" + item.SelectedItem + ")");
2024-11-19 09:45:27 +08:00
sb.AppendFormat("<td align=\"left\" style=\"width:100%; \">{0}</td> ", num + "、" + Avstracts);
sb.Append("</tr>");
sb.Append("<tr style=\"height:30px\">");
string str = string.Empty;
if (!string.IsNullOrEmpty(item.AItem))
{
str += "A." + item.AItem;
}
if (!string.IsNullOrEmpty(item.BItem))
{
str += "&nbsp;&nbsp;B." + item.BItem;
}
if (!string.IsNullOrEmpty(item.CItem))
{
str += "&nbsp;&nbsp;C." + item.CItem;
}
if (!string.IsNullOrEmpty(item.DItem))
{
str += "&nbsp;&nbsp;D." + item.DItem;
}
sb.AppendFormat("<td align=\"left\" style=\"width: 100%; \">{0}</td> ", str);
sb.Append("</tr>");
num++;
}
}
///判断题
sb.Append("<tr style=\"height: 30px\">");
sb.AppendFormat("<td align=\"left\" style=\"width: 100%; font-weight: bold;\">{0}</td> ", "三、判断题 (每题1分,共20分)");
sb.Append("</tr>");
var getIsTrueItem = getTestItems.Where(x => x.TestType == "3").ToList();
if (getIsTrueItem.Count > 0)
{
int num = 1;
foreach (var item in getIsTrueItem)
{
sb.Append("<tr style=\"height: 30px\">");
var Avstracts = item.Abstracts;
if (Avstracts.IndexOf("(") > -1)
{
Avstracts = Avstracts.Replace("(", "" + item.SelectedItem == "A" ? "(√" : "(×");
}
else
{
if (Avstracts.IndexOf("") > -1)
Avstracts = Avstracts.Replace("", "" + item.SelectedItem == "A" ? "(√" : "(×");
}
sb.AppendFormat("<td align=\"left\" style=\"width: 100%; \">{0}</td> ", num + "、" + Avstracts);
sb.Append("</tr>");
num++;
}
}
sb.Append("</table>");
sb.Append("<table width=\"100% \" cellspacing=\"0\" rules=\"all\" border=\"0\" style=\"border-collapse:collapse;font-size: 10.5pt;\">");
var attachFile = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == testRecordId);
if (attachFile != null && !string.IsNullOrEmpty(attachFile.AttachUrl))
{
List<string> listUrl = Funs.GetStrListByStr(attachFile.AttachUrl, ',');
int count = listUrl.Count();
sb.Append("<tr>");
if (count > 0)
{
string imgStr0 = "<img width='100' height='100' src='" + (Funs.SGGLUrl + listUrl[0]).Replace('\\', '/') + "'></img>&nbsp;&nbsp;";
string imgStr1 = "<img width='100' height='100' src='" + (Funs.SGGLUrl + listUrl[0]).Replace('\\', '/') + "'></img>&nbsp;&nbsp;";
if (count >= 2)
{
int cout2 = count / 2;
imgStr1 = "<img width='100' height='100' src='" + (Funs.SGGLUrl + listUrl[cout2]).Replace('\\', '/') + "'></img>&nbsp;&nbsp;";
}
string imgStr2 = "<img width='100' height='100' src='" + (Funs.SGGLUrl + listUrl[count - 1]).Replace('\\', '/') + "'></img>&nbsp;&nbsp;";
sb.AppendFormat("<td align=\"center\" style=\"width: 30%; \">{0}</td> ", imgStr0);
sb.AppendFormat("<td align=\"center\" style=\"width: 30%; \">{0}</td> ", imgStr1);
sb.AppendFormat("<td align=\"center\" style=\"width: 30%; \">{0}</td> ", imgStr2);
}
else
{
sb.AppendFormat("<td align=\"center\" style=\"width: 30%; \">{0}</td> ", "");
2026-06-15 19:05:39 +08:00
}
2024-11-19 09:45:27 +08:00
sb.Append("</tr>");
}
sb.Append("</table>");
///图片
}
return sb.ToString();
}
#endregion
#region
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
public static string GetSendCardHtml(string personIds)
{
2025-08-04 18:04:41 +08:00
Model.CNPCDB db = Funs.DB;
2024-11-19 09:45:27 +08:00
StringBuilder sb = new StringBuilder();
sb.Append("<meta http-equiv=\"content-type\" content=\"application/word; charset=UTF-8\"/>");
sb.Append("<table width=\"100% \" cellspacing=\"0\" rules=\"all\" border=\"0\" style=\"border-collapse:collapse;\">");
List<string> pList = Funs.GetStrListByStr(personIds, ',');
if (pList.Count() > 0)
{
string imgStrUrl = "<img width='60' height='50' src='" + (Funs.SGGLUrl + "Images/SUBimages/CNCEC.png").Replace('\\', '/') + "'></img>";
for (int pageIndex = 1; pageIndex * 2 <= pList.Count() + 1; pageIndex++)
{
string projectName = "";
string unitName1 = "";
string unitName2 = "";
string workName1 = "";
string workName2 = "";
string personName1 = "";
string personName2 = "";
string cardNo1 = "";
string cardNo2 = "";
string photoUrl1 = "";
string photoUrl2 = "";
string QRUrl1 = "";
string QRUrl2 = "";
var getDataList = pList.Skip(2 * (pageIndex - 1)).Take(2).ToList();
int i = 0;
foreach (var item in getDataList)
{
var getPerson = PersonService.GetPersonById(item);
if (getPerson != null)
{
string qrurl = string.Empty;
if (!string.IsNullOrEmpty(getPerson.QRCodeAttachUrl) && CreateQRCodeService.isHaveImage(getPerson.QRCodeAttachUrl))
{
2026-06-15 19:05:39 +08:00
qrurl = getPerson.QRCodeAttachUrl;
2024-11-19 09:45:27 +08:00
}
else
{
qrurl = CreateQRCodeService.CreateCode_Simple(getPerson.IdentityCard);
getPerson.QRCodeAttachUrl = qrurl;
db.SubmitChanges();
}
projectName = ProjectService.GetShortNameByProjectId(getPerson.ProjectId);
if (i == 0)
{
unitName1 = UnitService.GetUnitNameByUnitId(getPerson.UnitId);
workName1 = WorkPostService.getWorkPostNameById(getPerson.WorkPostId);
personName1 = getPerson.PersonName;
cardNo1 = getPerson.CardNo;
2026-06-15 19:05:39 +08:00
photoUrl1 = getPerson.PhotoUrl;
2024-11-19 09:45:27 +08:00
QRUrl1 = qrurl;
}
else
{
unitName2 = UnitService.GetUnitNameByUnitId(getPerson.UnitId);
workName2 = WorkPostService.getWorkPostNameById(getPerson.WorkPostId);
personName2 = getPerson.PersonName;
cardNo2 = getPerson.CardNo;
photoUrl2 = getPerson.PhotoUrl;
QRUrl2 = qrurl;
}
i++;
}
}
2026-06-15 19:05:39 +08:00
2024-11-19 09:45:27 +08:00
sb.Append("<tr >");
sb.Append("<td align=\"left\" style=\"width: 49%;\" >");
sb.Append("<table width=\"100% \" cellspacing=\"0\" rules=\"all\" border=\"0\" style=\"border-collapse:collapse;\">");
sb.Append("<tr style=\"height: 40px\">");
sb.AppendFormat("<td align=\"center\" style=\"width: 25%;\" rowspan=\"2\">{0}</td> ", imgStrUrl);
sb.AppendFormat("<td align=\"center\" style=\"width: 50%;font-size: 11pt;font-weight: bold;\">{0}</td> ", "中国天辰工程有限公司");
string imgStrQRUrl1 = "<img width='60' height='50' src='" + (Funs.SGGLUrl + QRUrl1).Replace('\\', '/') + "'></img>";
sb.AppendFormat("<td align=\"center\" style=\"width: 25%;\" rowspan=\"2\">{0}</td> ", imgStrQRUrl1);
sb.Append("</tr>");
sb.Append("<tr style=\"height: 30px\" valign=\"top\">");
sb.AppendFormat("<td align=\"center\" style=\" font-size: 9pt; font-weight: bold;\">{0}</td> ", projectName);
sb.Append("</tr>");
sb.Append("</table>");
sb.Append("<table width=\"100% \" cellspacing=\"0\" rules=\"all\" border=\"0\" style=\"border-collapse:collapse;font-size: 9pt;background-color:#5b9bd5\">");
sb.Append("<tr style=\"height: 25PX\">");
sb.AppendFormat("<td align=\"right\" style=\"width: 20%;\" >{0}</td> ", "单位:");
2026-06-15 19:05:39 +08:00
sb.AppendFormat("<td align=\"left\" style=\"width: 55%;\" >{0}</td> ", unitName1);
2024-11-19 09:45:27 +08:00
string imgStrphotoUrl1 = "<img width='85' height='110' src='" + (Funs.SGGLUrl + photoUrl1).Replace('\\', '/') + "'></img>";
2026-06-15 19:05:39 +08:00
sb.AppendFormat("<td align=\"center\" style=\"width: 25%;\" rowspan=\"5\">{0}</td> ", imgStrphotoUrl1);
2024-11-19 09:45:27 +08:00
sb.Append("</tr>");
sb.Append("<tr style=\"height: 25PX\">");
2026-06-15 19:05:39 +08:00
sb.AppendFormat("<td align=\"right\" >{0}</td> ", "岗位:");
sb.AppendFormat("<td align=\"left\" >{0}</td> ", workName1);
2024-11-19 09:45:27 +08:00
sb.Append("</tr>");
sb.Append("<tr style=\"height: 25PX\">");
sb.AppendFormat("<td align=\"right\" >{0}</td> ", "姓名:");
sb.AppendFormat("<td align=\"left\" >{0}</td> ", personName1);
sb.Append("</tr>");
sb.Append("<tr style=\"height: 25PX\">");
sb.AppendFormat("<td align=\"right\" >{0}</td> ", "编号:");
2026-06-15 19:05:39 +08:00
sb.AppendFormat("<td align=\"left\" >{0}</td> ", cardNo1);
2024-11-19 09:45:27 +08:00
sb.Append("</tr>");
sb.Append("<tr style=\"height: 25PX\">");
sb.AppendFormat("<td align=\"right\" >{0}</td> ", "");
sb.AppendFormat("<td align=\"left\" >{0}</td> ", "");
sb.Append("</tr>");
sb.Append("</table>");
sb.Append("</td >");
sb.AppendFormat("<td align=\"center\" style=\"width: 2%;\">{0}</td> ", "");
sb.Append("<td align=\"right\" style=\"width: 49%;\">");
if (!string.IsNullOrEmpty(personName2))
{
sb.Append("<table width=\"100% \" cellspacing=\"0\" rules=\"all\" border=\"0\" style=\"border-collapse:collapse;\">");
sb.Append("<tr style=\"height: 40px\">");
sb.AppendFormat("<td align=\"center\" style=\"width: 25%;\" rowspan=\"2\">{0}</td> ", imgStrUrl);
sb.AppendFormat("<td align=\"center\" style=\"width: 50%;font-size: 11pt;font-weight: bold;\">{0}</td> ", "中国天辰工程有限公司");
string imgStrQRUrl2 = "<img width='60' height='50' src='" + (Funs.SGGLUrl + QRUrl2).Replace('\\', '/') + "'></img>";
sb.AppendFormat("<td align=\"center\" style=\"width: 25%;\" rowspan=\"2\">{0}</td> ", imgStrQRUrl2);
sb.Append("</tr>");
sb.Append("<tr style=\"height: 30px\">");
sb.AppendFormat("<td align=\"center\" valign=\"top\" style=\" font-size: 9pt; font-weight: bold;\">{0}</td> ", projectName);
sb.Append("</tr>");
sb.Append("</table>");
sb.Append("<table width=\"100% \" cellspacing=\"0\" rules=\"all\" border=\"0\" style=\"border-collapse:collapse;font-size: 9pt;background-color:#5b9bd5;\">");
sb.Append("<tr style=\"height: 25PX\">");
sb.AppendFormat("<td align=\"right\" style=\"width: 20%;\" >{0}</td> ", "单位:");
sb.AppendFormat("<td align=\"left\" style=\"width: 55%;\" >{0}</td> ", unitName2);
string imgStrphotoUrl2 = "<img width='85' height='110' src='" + (Funs.SGGLUrl + photoUrl2).Replace('\\', '/') + "'></img>";
sb.AppendFormat("<td align=\"center\" style=\"width: 25%;\" rowspan=\"5\">{0}</td> ", imgStrphotoUrl2);
sb.Append("</tr>");
sb.Append("<tr style=\"height: 25PX\">");
sb.AppendFormat("<td align=\"right\" >{0}</td> ", "岗位:");
sb.AppendFormat("<td align=\"left\" >{0}</td> ", workName2);
sb.Append("</tr>");
sb.Append("<tr style=\"height: 25PX\">");
sb.AppendFormat("<td align=\"right\" >{0}</td> ", "姓名:");
sb.AppendFormat("<td align=\"left\" >{0}</td> ", personName2);
sb.Append("</tr>");
sb.Append("<tr style=\"height: 25PX\">");
sb.AppendFormat("<td align=\"right\" >{0}</td> ", "编号:");
sb.AppendFormat("<td align=\"left\" >{0}</td> ", cardNo2);
sb.Append("</tr>");
sb.Append("<tr style=\"height: 25PX\">");
sb.AppendFormat("<td align=\"right\" >{0}</td> ", "");
sb.AppendFormat("<td align=\"left\" >{0}</td> ", "");
sb.Append("</tr>");
sb.Append("</table>");
}
sb.Append("</td >");
sb.Append("</tr>");
sb.Append("<tr style=\"height:15px\">");
sb.AppendFormat("<td align=\"right\" style=\"width: 100%\" colspan=\"3\">{0}</td> ", "");
sb.Append("<tr >");
}
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
}
}