public async Task <NewErrorModel> GetExcelReport(string taskId, string applyManId) { try { //EFHelper<Purchase> eFHelper = new EFHelper<Purchase>(); //System.Linq.Expressions.Expression<Func<Purchase, bool>> where = p => p.TaskId == taskId; //List<Purchase> purchases = eFHelper.GetListBy(where); using (DDContext context = new DDContext()) { var SelectPurchaseList = from p in context.Purchase where p.TaskId == taskId select new { p.TaskId, p.DrawingNo, p.Name, p.Count, p.MaterialScience, p.Unit, p.SingleWeight, p.AllWeight, p.Sorts, p.NeedTime, p.Mark }; DataTable dtpurchaseTables = DtLinqOperators.CopyToDataTable(SelectPurchaseList); string path = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet/图纸BOM导出模板.xlsx"); string time = DateTime.Now.ToString("yyyyMMddHHmmss"); string newPath = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet") + "\\图纸BOM数据" + time + ".xlsx"; System.IO.File.Copy(path, newPath); if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtpurchaseTables, 0, 1)) { DingTalkServersController dingTalkServersController = new DingTalkServersController(); //上盯盘 var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/图纸BOM数据" + time + ".xlsx"); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = applyManId; var result = await dingTalkServersController.SendFileMessage(fileSendModel); return(new NewErrorModel() { error = new Error(0, "已推送至钉钉!", "") { }, }); } else { return(new NewErrorModel() { error = new Error(1, "文件有误!", "") { }, }); } } } catch (Exception ex) { throw ex; } }
public async Task <object> PrintAndSend([FromBody] PrintModel printAndSendModel) { try { string TaskId = printAndSendModel.TaskId; string UserId = printAndSendModel.UserId; PDFHelper pdfHelper = new PDFHelper(); using (DDContext context = new DDContext()) { //获取表单信息 Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First(); string FlowId = tasks.FlowId.ToString(); //判断流程是否已结束 List <Tasks> tasksList = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.State == 0 && t.IsSend == false).ToList(); if (tasksList.Count > 0) { return(new NewErrorModel() { error = new Error(1, "流程尚未结束", "") { }, }); } List <Maintain> GoDownList = context.Maintain.Where(u => u.TaskId == TaskId).ToList(); var SelectGoDownList = from g in GoDownList select new { g.CodeNo, g.Name, g.Standard, g.Unit, g.Count, g.Price, g.MaintainContent, g.NeedTime, g.Mark }; DataTable dtSourse = DtLinqOperators.CopyToDataTable(SelectGoDownList); //ClassChangeHelper.ToDataTable(SelectPurchaseList); List <NodeInfo> NodeInfoList = context.NodeInfo.Where(u => u.FlowId == FlowId && u.NodeId != 0 && u.IsSend != true && u.NodeName != "结束").ToList(); foreach (NodeInfo nodeInfo in NodeInfoList) { if (string.IsNullOrEmpty(nodeInfo.NodePeople)) { string strNodePeople = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyMan; string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = strNodePeople + " " + ApplyTime; } else { string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = nodeInfo.NodePeople + " " + ApplyTime; } } DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList); string FlowName = context.Flows.Where(f => f.FlowId.ToString() == FlowId).First().FlowName.ToString(); //绘制BOM表单PDF List <string> contentList = new List <string>() { "序号", "物料编码", "物料名称", "规格型号", "单位", "数量", "单价(预计)", "维修内容", "需用时间", "备注" }; float[] contentWithList = new float[] { 50, 60, 60, 60, 60, 60, 60, 60, 60, 100 }; string projectName = tasks.ProjectName.ToString(); string projectNo = tasks.ProjectId.ToString(); string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime, projectName, projectNo, "2", 300, 650, contentList, contentWithList, dtSourse, dtApproveView, null, null); string RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path); List <string> newPaths = new List <string>(); RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\'); newPaths.Add(RelativePath); string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, FlowName + DateTime.Now.ToString("yyyyMMddHHmmss")); //文件压缩打包 IonicHelper.CompressMulti(newPaths, SavePath, false); //上传盯盘获取MediaId SavePath = string.Format(@"~\UploadFile\Ionic\{0}", Path.GetFileName(SavePath)); DingTalkServersController dingTalkServersController = new DingTalkServersController(); var resultUploadMedia = await dingTalkServersController.UploadMedia(SavePath); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = UserId; var result = await dingTalkServersController.SendFileMessage(fileSendModel); return(new NewErrorModel() { error = new Error(0, result, "") { }, }); } } catch (Exception ex) { throw ex; } }
public async Task <NewErrorModel> PrintAndSend(PrintAndSendModel printAndSendModel) { try { string TaskId = printAndSendModel.TaskId; string UserId = printAndSendModel.UserId; string OldPath = printAndSendModel.OldPath; PDFHelper pdfHelper = new PDFHelper(); using (DDContext context = new DDContext()) { //获取表单信息 Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First(); string FlowId = tasks.FlowId.ToString(); string ProjectId = tasks.ProjectId; //判断流程是否已结束 List <Tasks> tasksList = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.IsSend != true && t.State == 0).ToList(); if (tasksList.Count > 0) { return(new NewErrorModel() { error = new Error(1, "流程未结束!", "") { }, }); } List <Purchase> PurchaseList = context.Purchase.Where(u => u.TaskId == TaskId).ToList(); var SelectPurchaseList = from p in PurchaseList select new { p.DrawingNo, p.Name, p.Count, p.MaterialScience, p.Unit, p.SingleWeight, p.AllWeight, p.Sorts, p.NeedTime, p.Mark }; DataTable dtSourse = DtLinqOperators.CopyToDataTable(SelectPurchaseList); //ClassChangeHelper.ToDataTable(SelectPurchaseList); List <NodeInfo> NodeInfoList = context.NodeInfo.Where(u => u.FlowId == FlowId && u.NodeId != 0 && u.NodeName != "结束" && u.IsSend != true).ToList(); foreach (NodeInfo nodeInfo in NodeInfoList) { if (string.IsNullOrEmpty(nodeInfo.NodePeople)) { string strNodePeople = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyMan; string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = strNodePeople + " " + ApplyTime; } else { string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = nodeInfo.NodePeople + " " + ApplyTime; } } DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList); string FlowName = context.Flows.Where(f => f.FlowId.ToString() == FlowId).First().FlowName.ToString(); ProjectInfo projectInfo = context.ProjectInfo.Where(p => p.ProjectId == ProjectId).First(); string ProjectName = projectInfo.ProjectName; string ProjectNo = projectInfo.ProjectId; //绘制BOM表单PDF List <string> contentList = new List <string>() { "序号", "代号", "名称", "数量", "材料", "单位", "单重", "总重", "类别", "需用日期", "备注" }; float[] contentWithList = new float[] { 50, 80, 80, 30, 60, 30, 60, 60, 60, 60, 60 }; string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime, ProjectName, ProjectNo, "1", 380, 710, contentList, contentWithList, dtSourse, dtApproveView, null); string RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path); string[] Paths = OldPath.Split(','); List <string> newPaths = new List <string>(); RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\'); newPaths.Add(RelativePath); foreach (string pathChild in Paths) { string AbPath = AppDomain.CurrentDomain.BaseDirectory + pathChild.Substring(2, pathChild.Length - 2); //PDF盖章 保存路径 newPaths.Add( pdfHelper.PDFWatermark(AbPath, string.Format(@"{0}\UploadFile\PDFPrint\{1}", AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(pathChild)), string.Format(@"{0}\Content\images\受控章.png", AppDomain.CurrentDomain.BaseDirectory), 100, 100) ); } string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, "图纸审核" + DateTime.Now.ToString("yyyyMMddHHmmss")); //文件压缩打包 IonicHelper.CompressMulti(newPaths, SavePath, false); //上传盯盘获取MediaId DingTalkServersController otherController = new DingTalkServersController(); SavePath = string.Format(@"~\UploadFile\Ionic\{0}", Path.GetFileName(SavePath)); var resultUploadMedia = await otherController.UploadMedia(SavePath); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = UserId; var result = await otherController.SendFileMessage(fileSendModel); return(new NewErrorModel() { error = new Error(0, "已推送至钉钉!", "") { }, }); } } catch (Exception ex) { throw ex; } }
public NewErrorModel PrintAndSendPurcahse(Tasks tasks, string strpath) { try { DDContext context = new DDContext(); List <PurchaseTable> PurchaseTableList = context.PurchaseTable.Where(u => u.TaskId == tasks.TaskId.ToString()).ToList(); var SelectPurchaseList = from p in PurchaseTableList select new { p.CodeNo, p.Name, p.Standard, p.Unit, p.Count, p.Price, p.Purpose, p.UrgentDate, p.Mark }; DataTable dtSourse = DtLinqOperators.CopyToDataTable(SelectPurchaseList); //ClassChangeHelper.ToDataTable(SelectPurchaseList); List <NodeInfo> NodeInfoList = context.NodeInfo.Where(u => u.FlowId == tasks.FlowId.ToString() && u.NodeId != 0 && u.IsSend != true && u.NodeName != "结束").ToList(); foreach (NodeInfo nodeInfo in NodeInfoList) { if (string.IsNullOrEmpty(nodeInfo.NodePeople)) { string strNodePeople = context.Tasks.Where(q => q.TaskId.ToString() == tasks.TaskId.ToString() && q.NodeId == nodeInfo.NodeId).First().ApplyMan; string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == tasks.TaskId.ToString() && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = strNodePeople + " " + ApplyTime; } else { string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == tasks.TaskId.ToString() && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = nodeInfo.NodePeople + " " + ApplyTime; } } DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList); string FlowName = context.Flows.Where(f => f.FlowId.ToString() == tasks.FlowId.ToString()).First().FlowName.ToString(); ProjectInfo projectInfo = context.ProjectInfo.Where(p => p.ProjectId == tasks.ProjectId).First(); string ProjectName = projectInfo.ProjectName; string ProjectNo = projectInfo.ProjectId; //绘制BOM表单PDF List <string> contentList = new List <string>() { "序号", "物料编码", "物料名称", "规格型号", "单位", "数量", "单价", "用途", "需用日期", "备注" }; float[] contentWithList = new float[] { 50, 60, 60, 60, 60, 60, 60, 60, 60, 60 }; PDFHelper pdfHelper = new PDFHelper(); string path = pdfHelper.GeneratePDF(FlowName, tasks.TaskId.ToString(), tasks.ApplyMan, tasks.Dept, tasks.ApplyTime, ProjectName, ProjectNo, "2", 300, 650, contentList, contentWithList, dtSourse, dtApproveView, null); string RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path); List <string> newPaths = new List <string>(); RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\'); newPaths.Add(RelativePath); //string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, FlowName + DateTime.Now.ToString("yyyyMMddHHmmss")); //文件压缩打包 IonicHelper.CompressMulti(newPaths, strpath, false); return(new NewErrorModel() { error = new Error(0, "", "") { }, }); } catch (Exception ex) { throw ex; } }
public async Task <string> PrintAndSend([FromBody] PrintAndSendModel printAndSendModel) { try { string TaskId = printAndSendModel.TaskId; string UserId = printAndSendModel.UserId; PDFHelper pdfHelper = new PDFHelper(); using (DDContext context = new DDContext()) { //获取表单信息 Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First(); string FlowId = tasks.FlowId.ToString(); string ProjectId = tasks.ProjectId; //判断是否有权限触发按钮 //string PeopleId = context.Roles.Where(r=>r.RoleName=="采购管理员").First().UserId; //if (UserId != PeopleId) //{ // return JsonConvert.SerializeObject(new ErrorModel // { // errorCode = 1, // errorMessage = "没有权限" // }); //} //判断流程是否已结束 List <Tasks> tasksList = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.State == 0 && t.IsSend == false).ToList(); if (tasksList.Count > 0) { return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 2, errorMessage = "流程未结束" })); } List <PurchaseTable> PurchaseTableList = context.PurchaseTable.Where(u => u.TaskId == TaskId).ToList(); var SelectPurchaseList = from p in PurchaseTableList select new { p.CodeNo, p.Name, p.Standard, p.Unit, p.Count, p.Price, p.Purpose, p.UrgentDate, p.Mark }; DataTable dtSourse = DtLinqOperators.CopyToDataTable(SelectPurchaseList); //ClassChangeHelper.ToDataTable(SelectPurchaseList); List <NodeInfo> NodeInfoList = context.NodeInfo.Where(u => u.FlowId == FlowId && u.NodeId != 0 && u.IsSend != true && u.NodeName != "结束").ToList(); foreach (NodeInfo nodeInfo in NodeInfoList) { if (string.IsNullOrEmpty(nodeInfo.NodePeople)) { string strNodePeople = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyMan; string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = strNodePeople + " " + ApplyTime; } else { string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = nodeInfo.NodePeople + " " + ApplyTime; } } DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList); string FlowName = context.Flows.Where(f => f.FlowId.ToString() == FlowId).First().FlowName.ToString(); ProjectInfo projectInfo = context.ProjectInfo.Where(p => p.ProjectId == ProjectId).First(); string ProjectName = projectInfo.ProjectName; string ProjectNo = projectInfo.ProjectId; //绘制BOM表单PDF List <string> contentList = new List <string>() { "序号", "物料编码", "物料名称", "规格型号", "单位", "数量", "单价", "用途", "需用日期", "备注" }; float[] contentWithList = new float[] { 50, 60, 60, 60, 60, 60, 60, 60, 60, 60 }; string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime, ProjectName, ProjectNo, "2", 300, 650, contentList, contentWithList, dtSourse, dtApproveView, null); string RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path); List <string> newPaths = new List <string>(); RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\'); newPaths.Add(RelativePath); string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, FlowName + DateTime.Now.ToString("yyyyMMddHHmmss")); //文件压缩打包 IonicHelper.CompressMulti(newPaths, SavePath, false); //上传盯盘获取MediaId SavePath = string.Format(@"~\UploadFile\Ionic\{0}", Path.GetFileName(SavePath)); DingTalkServersController dingTalkServersController = new DingTalkServersController(); var resultUploadMedia = await dingTalkServersController.UploadMedia(SavePath); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = UserId; var result = await dingTalkServersController.SendFileMessage(fileSendModel); return(result); } } catch (Exception ex) { return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 3, errorMessage = ex.Message })); } }
public async Task <NewErrorModel> PrintAndSend([FromBody] PrintAndSendModel printAndSendModel) { try { string TaskId = printAndSendModel.TaskId; string UserId = printAndSendModel.UserId; PDFHelper pdfHelper = new PDFHelper(); using (DDContext context = new DDContext()) { //获取表单信息 Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First(); string FlowId = tasks.FlowId.ToString(); string ProjectId = tasks.ProjectId; //判断流程是否已结束 List <Tasks> tasksList = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.State == 0 && t.IsSend == false).ToList(); if (tasksList.Count > 0) { return(new NewErrorModel() { error = new Error(1, "流程未结束!", "") { }, }); } ProjectClosure purchaseTableList = context.ProjectClosure.Where(u => u.TaskId == TaskId).FirstOrDefault(); Dictionary <string, string> keyValuePairsHead = new Dictionary <string, string>(); keyValuePairsHead.Add("项目类别", purchaseTableList.ProjectType); keyValuePairsHead.Add("项目负责人", purchaseTableList.ResponsibleMan); keyValuePairsHead.Add("小组成员", purchaseTableList.TeamMembers); keyValuePairsHead.Add("项目周期", purchaseTableList.StartTime + "-" + purchaseTableList.EndTime); keyValuePairsHead.Add("项目实际开发周期", purchaseTableList.ActualCycleStart + "-" + purchaseTableList.ActualCycleEnd); keyValuePairsHead.Add("是否有横向合作单位", purchaseTableList.IsTransverse == true ? "是" : "否"); if (purchaseTableList.IsTransverse == true) { keyValuePairsHead.Add("合同金额", purchaseTableList.ContractAmount); keyValuePairsHead.Add("合同编码", purchaseTableList.ContractNo); keyValuePairsHead.Add("实际到账", purchaseTableList.ActualMoney); } keyValuePairsHead.Add("是否有申报纵向项目", purchaseTableList.IsPortrait == true ? "是" : "否"); List <PrintPDFModel> printPDFModels = new List <PrintPDFModel>(); printPDFModels.Add(new PrintPDFModel() { Name = "立项书或建议书", Count = CalCounts(purchaseTableList.SuggestBook1).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "评审PPT", Count = CalCounts(purchaseTableList.PPT2).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "需求规格说明书、产品总体设计书", Count = CalCounts(purchaseTableList.DemandBook3).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "机械设计图纸", Count = CalCounts(purchaseTableList.Drawing4).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "电气图纸", Count = CalCounts(purchaseTableList.Electrical5).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "BOM表", Count = CalCounts(purchaseTableList.Bom6).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "软件源代码", Count = CalCounts(purchaseTableList.SourceCode7).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "使用说明书/操作手册/技术方案/规格说明书", Count = CalCounts(purchaseTableList.UseBook8).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "合作协议", Count = CalCounts(purchaseTableList.CooperationAgreement9).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "产品(样机/成品)图片/影像", Count = CalCounts(purchaseTableList.Product10).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "阶段性整理的问题的分析、解决方案及计划表", Count = CalCounts(purchaseTableList.Solution11).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "项目采购清单、借用清单、领料清单、入库清单、借用清单、维修清单", Count = context.DetailedList.Where(t => t.TaskId == TaskId && t.Type.Contains("零部件采购")).ToList().Count.ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "受理知识产权清单", Count = context.DetailedList.Where(t => t.TaskId == TaskId && t.Type.Contains("知识产权")).ToList().Count.ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "纵向项目申请/中期检查/验收资料", Count = CalCounts(purchaseTableList.AcceptanceData14).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "其他过程文档、设计报告、评审报告、项目计划、设计更改报告等", Count = CalCounts(purchaseTableList.ProcessDocumentation15).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "项目终止情况报告", Count = CalCounts(purchaseTableList.TerminationReport16).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "装箱单", Count = CalCounts(purchaseTableList.PackingList17).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "客户验收单", Count = CalCounts(purchaseTableList.AcceptanceSlip18).ToString() }); printPDFModels.Add(new PrintPDFModel() { Name = "转化/应用单位情况表", Count = "1" }); printPDFModels.Add(new PrintPDFModel() { Name = "项目经费使用情况表", Count = "1" }); DataTable dtSourse = DtLinqOperators.CopyToDataTable(printPDFModels); //ClassChangeHelper.ToDataTable(SelectPurchaseList); List <NodeInfo> NodeInfoList = context.NodeInfo.Where(u => u.FlowId == FlowId && u.NodeId != 0 && u.IsSend != true && u.NodeName != "结束").ToList(); foreach (NodeInfo nodeInfo in NodeInfoList) { if (string.IsNullOrEmpty(nodeInfo.NodePeople)) { string strNodePeople = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyMan; string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = strNodePeople + " " + ApplyTime; } else { string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = nodeInfo.NodePeople + " " + ApplyTime; } } DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList); string FlowName = context.Flows.Where(f => f.FlowId.ToString() == FlowId).First().FlowName.ToString(); ProjectInfo projectInfo = context.ProjectInfo.Where(p => p.ProjectId == ProjectId).First(); string ProjectName = projectInfo.ProjectName; string ProjectNo = projectInfo.ProjectId; //绘制BOM表单PDF List <string> contentList = new List <string>() { "序号", "文件类别", "份数" }; float[] contentWithList = new float[] { 50, 350, 60, }; string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime, ProjectName, ProjectNo, "2", 300, 650, contentList, contentWithList, dtSourse, dtApproveView, null, keyValuePairsHead); string RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path); List <string> newPaths = new List <string>(); RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\'); newPaths.Add(RelativePath); string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, FlowName + DateTime.Now.ToString("yyyyMMddHHmmss")); //文件压缩打包 IonicHelper.CompressMulti(newPaths, SavePath, false); //上传盯盘获取MediaId SavePath = string.Format(@"~\UploadFile\Ionic\{0}", Path.GetFileName(SavePath)); DingTalkServersController dingTalkServersController = new DingTalkServersController(); var resultUploadMedia = await dingTalkServersController.UploadMedia(SavePath); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = UserId; var result = await dingTalkServersController.SendFileMessage(fileSendModel); return(new NewErrorModel() { error = new Error(0, result, "") { }, }); } } catch (Exception ex) { throw ex; } }
public async Task <string> GetReport(string TaskId, string UserId) { try { PDFHelper pdfHelper = new PDFHelper(); using (DDContext context = new DDContext()) { //获取表单信息 Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First(); string FlowId = tasks.FlowId.ToString(); string ProjectId = tasks.ProjectId; //判断流程是否已结束 List <Tasks> tasksList = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.IsSend != true && t.State == 0).ToList(); if (tasksList.Count > 0) { return(JsonConvert.SerializeObject( new NewErrorModel() { error = new Error(0, "流程尚未结束", "") { }, })); } List <Receiving> ReceivingList = context.Receiving.Where(u => u.TaskId == TaskId).ToList(); DataTable dtSourse = DtLinqOperators.CopyToDataTable(ReceivingList); List <NodeInfo> NodeInfoList = context.NodeInfo.Where(u => u.FlowId == FlowId && u.NodeId != 0 && u.NodeName != "结束" && !u.NodeName.Contains("抄送")).ToList(); foreach (NodeInfo nodeInfo in NodeInfoList) { if (string.IsNullOrEmpty(nodeInfo.NodePeople)) { List <Tasks> taskList = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).ToList(); foreach (var task in taskList) { nodeInfo.NodePeople += " " + task.ApplyMan + " " + task.ApplyTime; } } else { string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = nodeInfo.NodePeople + " " + ApplyTime; } } DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList); string FlowName = context.Flows.Where(f => f.FlowId.ToString() == FlowId).First().FlowName.ToString(); Dictionary <string, string> dic = new Dictionary <string, string>(); Receiving receiving = context.Receiving.Where(r => r.TaskId == TaskId).SingleOrDefault(); dic.Add("申请人", tasks.ApplyMan); dic.Add("流水号", tasks.TaskId.ToString()); dic.Add("标题", tasks.Title); dic.Add("收文编号", receiving.ReceivingNo); dic.Add("来文单位", receiving.ReceivingUnit); dic.Add("文件文号", receiving.FileNo); dic.Add("收文时间", receiving.ReceivingTime); dic.Add("主要内容", receiving.MainIdea); dic.Add("拟办意见", receiving.Suggestion); dic.Add("领导阅示", receiving.Leadership); dic.Add("承办部门阅办情况", receiving.Review.Replace("~", " ")); dic.Add("办理落实情况", receiving.HandleImplementation.Replace("~", " ")); string path = pdfHelper.GeneratePDF(FlowName, null, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime, "", "", "", "2", 380, 710, null, null, dtSourse, dtApproveView, dic); string RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path); List <string> newPaths = new List <string>(); RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\'); newPaths.Add(RelativePath); string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, "文件阅办单" + DateTime.Now.ToString("yyyyMMddHHmmss")); //文件压缩打包 IonicHelper.CompressMulti(newPaths, SavePath, false); //上传盯盘获取MediaId SavePath = string.Format(@"~\UploadFile\Ionic\{0}", Path.GetFileName(SavePath)); DingTalkServersController dingTalkServersController = new DingTalkServersController(); var resultUploadMedia = await dingTalkServersController.UploadMedia(SavePath); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = UserId; var result = await dingTalkServersController.SendFileMessage(fileSendModel); return(JsonConvert.SerializeObject( new NewErrorModel() { error = new Error(0, "获取成功,请在钉钉工作通知中查收!", "") { }, data = result })); } } catch (Exception ex) { return(JsonConvert.SerializeObject( new NewErrorModel() { error = new Error(1, ex.Message, "") { }, })); } }
public async Task <NewErrorModel> PrintExcel(string taskId, string UserId) { try { using (DDContext context = new DDContext()) { List <PurchaseTable> purchaseTables = context.PurchaseTable.Where(p => p.TaskId == taskId).ToList(); //DataTable dtpurchaseTables = ClassChangeHelper.ToDataTable(purchaseTables); var SelectPurchaseList = from p in purchaseTables select new { p.Id, p.TaskId, p.CodeNo, p.Name, Type = p.Standard, p.Unit, p.Count, p.Price, p.Purpose, p.UrgentDate, p.Mark, p.SendPosition, p.PurchaseMan, p.purchaseType }; DataTable dtpurchaseTables = DtLinqOperators.CopyToDataTable(SelectPurchaseList); string path = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet/采购导出模板.xlsx"); string time = DateTime.Now.ToString("yyyyMMddHHmmss"); string newPath = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet") + "\\采购单" + time + ".xlsx"; File.Copy(path, newPath); if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtpurchaseTables, 0, 1)) { DingTalkServersController dingTalkServersController = new DingTalkServersController(); //上盯盘 var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/采购单" + time + ".xlsx"); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = UserId; var result = await dingTalkServersController.SendFileMessage(fileSendModel); return(new NewErrorModel() { error = new Error(0, result, "Excel已推送至您的钉钉") { }, }); } else { return(new NewErrorModel() { error = new Error(1, "文件有误", "") { }, }); } } } catch (Exception ex) { return(new NewErrorModel() { error = new Error(2, ex.Message, "") { }, }); } }
public async Task <NewErrorModel> PrintPDF(DDContext context, string ApplyManId, string TaskId, string UserId) { try { //获取表单信息 Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First(); string FlowId = tasks.FlowId.ToString(); string ProjectId = tasks.ProjectId; //项目或合同Id PDFHelper pdfHelper = new PDFHelper(); List <PurchaseTable> purchaseTableList = context.PurchaseTable.Where(u => u.TaskId == TaskId).ToList(); var SelectPurchaseListOne = from p in purchaseTableList where p.PurchaseManId == ApplyManId select new { p.CodeNo, p.Name, p.Standard, p.Price, //预计价格 p.Unit, p.Count, p.UrgentDate, //需用日期 p.SendPosition, //送货地点 p.Purpose, p.Mark }; DataTable dtSourse = DtLinqOperators.CopyToDataTable(SelectPurchaseListOne); List <NodeInfo> NodeInfoList = context.NodeInfo.Where(u => u.FlowId == FlowId && u.NodeId != 0 && u.IsSend != true && u.NodeName != "结束").ToList(); foreach (NodeInfo nodeInfo in NodeInfoList) { //临时用作备注 nodeInfo.PreNodeId = context.Tasks.Where(t => t.TaskId.ToString() == tasks.TaskId.ToString() && t.NodeId == nodeInfo.NodeId).FirstOrDefault().Remark; if (!string.IsNullOrEmpty(nodeInfo.NodePeople)) { if (nodeInfo.NodePeople.Length > 3) { nodeInfo.NodePeople = nodeInfo.NodePeople.Substring(0, 3); } } if (nodeInfo.NodeName.ToString() == "采购员采购") { nodeInfo.NodePeople = ""; } if (string.IsNullOrEmpty(nodeInfo.NodePeople)) { string strNodePeople = ""; string ApplyTime = ""; if (nodeInfo.NodeName.ToString() == "采购员采购") { strNodePeople = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId && q.ApplyManId == ApplyManId).First().ApplyMan; ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId && q.ApplyManId == ApplyManId).First().ApplyTime; } else { strNodePeople = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyMan; ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; } nodeInfo.NodePeople = strNodePeople + " " + ApplyTime; } else { string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = nodeInfo.NodePeople + " " + ApplyTime; } } DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList); NodeInfoList.Clear(); string FlowName = context.Flows.Where(f => f.FlowId.ToString() == FlowId).First().FlowName.ToString(); string ProjectName = ""; string ProjectNo = ""; if (FlowId == "24") //零部件 { ProjectInfo projectInfo = context.ProjectInfo.Where(p => p.ProjectId == ProjectId).First(); ProjectName = projectInfo.ProjectName; ProjectNo = projectInfo.ProjectId; } else { Models.DingModels.Contract contract = context.Contract.Where(p => p.ContractNo == ProjectId).First(); ProjectName = contract.ContractName; ProjectNo = contract.ContractNo; } //绘制BOM表单PDF List <string> contentList = new List <string>() { "序号", "物料编码", "物料名称", "规格型号", "预计单价", "单位", "数量", "需用日期", "送货地点", "用途", "备注" }; float[] contentWithList = new float[] { 50, 60, 60, 100, 40, 40, 40, 60, 40, 40, 60 }; string Name = ""; if (FlowId == "24") //零部件采购 { Name = "项目"; } else { if (FlowId == "26") //成品采购 { Name = "合同"; } } string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime, Name, ProjectName, ProjectNo, "2", 300, 650, contentList, contentWithList, dtSourse, dtApproveView, null); string RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path); List <string> newPaths = new List <string>(); RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\'); newPaths.Add(RelativePath); string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, FlowName + DateTime.Now.ToString("yyyyMMddHHmmss")); //文件压缩打包 IonicHelper.CompressMulti(newPaths, SavePath, false); //上传盯盘获取MediaId SavePath = string.Format(@"~\UploadFile\Ionic\{0}", Path.GetFileName(SavePath)); DingTalkServersController dingTalkServersController = new DingTalkServersController(); var resultUploadMedia = await dingTalkServersController.UploadMedia(SavePath); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = UserId; var result = await dingTalkServersController.SendFileMessage(fileSendModel); return(new NewErrorModel() { data = result, error = new Error(0, "推送成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(2, ex.Message, "") { }, }); } }
public async Task <object> GetPrintPDF(string TaskId, string UserId) { try { PDFHelper pdfHelper = new PDFHelper(); using (DDContext context = new DDContext()) { //获取表单信息 Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First(); string FlowId = tasks.FlowId.ToString(); //判断流程是否已结束 List <Tasks> tasksList = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.State == 0 && t.IsSend == false).ToList(); if (tasksList.Count > 0) { return(JsonConvert.SerializeObject(new NewErrorModel { error = new Error(1, "流程尚未结束", "") { }, })); } List <GiftTable> giftTables = context.GiftTable.Where(u => u.TaskId == TaskId).ToList(); var giftTableList = from g in giftTables select new { g.GiftName, g.GiftCount }; List <NodeInfo> NodeInfoList = context.NodeInfo.Where(u => u.FlowId == FlowId && u.NodeId != 0 && u.IsSend != true && u.NodeName != "结束").ToList(); //绘制BOM表单PDF List <string> contentList = new List <string>() { "序号", "礼品名称", "数量" }; float[] contentWithList = new float[] { 50, 500, 100 }; //Dictionary<string, string> keyValuePairs = new Dictionary<string, string>(); //keyValuePairs.Add("用途及使用说明", tasks.Remark); foreach (NodeInfo nodeInfo in NodeInfoList) { if (string.IsNullOrEmpty(nodeInfo.NodePeople)) { string strNodePeople = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyMan; string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = strNodePeople + " " + ApplyTime; } else { string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime; nodeInfo.NodePeople = nodeInfo.NodePeople + " " + ApplyTime; } } DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList); DataTable dtGiftTables = DtLinqOperators.CopyToDataTable(giftTableList); string FlowName = context.Flows.Where(f => f.FlowId.ToString() == FlowId).First().FlowName.ToString(); string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime, null, null, "2", 300, 650, contentList, contentWithList, dtGiftTables, dtApproveView, null); string RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path); List <string> newPaths = new List <string>(); RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\'); newPaths.Add(RelativePath); string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, FlowName + DateTime.Now.ToString("yyyyMMddHHmmss")); //文件压缩打包 IonicHelper.CompressMulti(newPaths, SavePath, false); //上传盯盘获取MediaId SavePath = string.Format(@"~\UploadFile\Ionic\{0}", Path.GetFileName(SavePath)); DingTalkServersController dingTalkServersController = new DingTalkServersController(); var resultUploadMedia = await dingTalkServersController.UploadMedia(SavePath); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = UserId; var result = await dingTalkServersController.SendFileMessage(fileSendModel); return(result); } } catch (Exception ex) { throw ex; } }