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
                }));
            }
        }
示例#2
0
        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;
            }
        }
示例#3
0
        public async Task <NewErrorModel> GetPrintPDF([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();

                    TasksState tasksState = context.TasksState.Where(t => t.TaskId == TaskId).FirstOrDefault();
                    if (tasksState.State != "已完成")
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, string.Format("流程{0}!", tasksState.State), "")
                            {
                            },
                        });
                    }
                    CarTable ct = context.CarTable.Where(u => u.TaskId == TaskId).FirstOrDefault();
                    if (printAndSendModel.IsPublic)
                    {
                        ct.CarId = context.Car.Where(c => c.Id.ToString() == ct.CarId).FirstOrDefault().CarNumber;
                    }
                    Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();

                    if (printAndSendModel.IsPublic)
                    {
                        keyValuePairs.Add("驾驶人", ct.DrivingMan);
                        keyValuePairs.Add("车牌号", ct.CarId);
                        keyValuePairs.Add("同行人数", ct.PeerNumber);
                        keyValuePairs.Add("用车事由", ct.MainContent);
                        keyValuePairs.Add("计划行车路线", ct.PlantTravelWay);
                        keyValuePairs.Add("实际行车路线", ct.FactTravelWay);
                        keyValuePairs.Add("出发时间", ct.StartTime.ToString());
                        keyValuePairs.Add("归来时间", ct.EndTime.ToString());
                        keyValuePairs.Add("实际行驶公里数", ct.FactKilometre);
                        keyValuePairs.Add("总行驶公里数", ct.UseKilometres);
                    }
                    else
                    {
                        keyValuePairs.Add("驾驶人", ct.DrivingMan);
                        keyValuePairs.Add("同行人数", ct.PeerNumber);
                        keyValuePairs.Add("用车事由", ct.MainContent);
                        keyValuePairs.Add("计划行车路线", ct.PlantTravelWay);
                        keyValuePairs.Add("实际行车路线", ct.FactTravelWay);
                        keyValuePairs.Add("出发时间", ct.StartTime.ToString());
                        keyValuePairs.Add("归来时间", ct.EndTime.ToString());
                        keyValuePairs.Add("总行驶公里数", ct.UseKilometres);
                    }

                    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();


                    string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime,
                                                        null, null, "2", 300, 650, null, null, null, dtApproveView, keyValuePairs);
                    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)
            {
                throw ex;
            }
        }
示例#4
0
        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;
            }
        }
示例#5
0
        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();

                    //判断流程是否已结束
                    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, "流程未结束!", "")
                            {
                            },
                        });
                    }

                    TechnicalSupport technicalSupport = context.TechnicalSupport.Where(u => u.TaskId == TaskId).First();
                    string           ProjectId        = technicalSupport.ProjectNo;
                    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;

                    Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();
                    keyValuePairs.Add("项目负责人", technicalSupport.ResponsibleMan);
                    keyValuePairs.Add("项目名称", technicalSupport.ProjectName);
                    keyValuePairs.Add("项目编号", technicalSupport.ProjectNo);
                    keyValuePairs.Add("项目组成员", technicalSupport.TeamMembers);
                    keyValuePairs.Add("测试项目技术支持部门", technicalSupport.DeptName);
                    keyValuePairs.Add("其他工程师", technicalSupport.OtherEngineers == "" ? "无" : technicalSupport.OtherEngineers);
                    keyValuePairs.Add("客户名称", technicalSupport.Customer);
                    keyValuePairs.Add("紧急程度", technicalSupport.EmergencyLevel);
                    keyValuePairs.Add("要求完成时间", technicalSupport.TimeRequired);
                    keyValuePairs.Add("所属公司", technicalSupport.CompanyName);
                    keyValuePairs.Add("测试项目周期", technicalSupport.StartTime + "-" + technicalSupport.EndTime);



                    Dictionary <string, string> keyValuePairsDb = new Dictionary <string, string>();
                    keyValuePairs.Add("客户项目整体概况", technicalSupport.ProjectOverview);
                    keyValuePairs.Add("技术支持内容要点", technicalSupport.MainPoints);
                    keyValuePairs.Add("处理方案", technicalSupport.TechnicalProposal);


                    string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime,
                                                        ProjectName, ProjectNo, "2", 300, 650, null, null, null, dtApproveView, keyValuePairs, keyValuePairsDb);
                    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([FromBody] PrintAndSendModel printAndSendModel)
        {
            try
            {
                string TaskId = printAndSendModel.TaskId;
                string UserId = printAndSendModel.UserId;
                using (DDContext context = new DDContext())
                {
                    //判断流程是否已结束
                    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 <Roles> roles = context.Roles.Where(r => r.RoleName.Contains("物料采购员")).ToList();

                    //获取表单信息
                    Tasks  tasksApplyMan = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First();
                    string FlowId        = tasksApplyMan.FlowId.ToString();

                    string NodeId = "";
                    if (FlowId == "24")  //零部件
                    {
                        NodeId = "7";
                    }
                    else
                    {
                        NodeId = "6";
                    }

                    List <Tasks> tasks     = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId.ToString() == NodeId).ToList();
                    List <Roles> rolesList = new List <Roles>();
                    foreach (var task in tasks)
                    {
                        foreach (var role in roles)
                        {
                            if (task.ApplyManId == role.UserId)
                            {
                                rolesList.Add(role);
                            }
                        }
                    }
                    foreach (var item in rolesList)
                    {
                        await PrintPDF(context, item.UserId, TaskId, UserId);
                    }

                    return(new NewErrorModel()
                    {
                        error = new Error(0, "打印推送成功!", "")
                        {
                        },
                    });
                }
            }
            catch (Exception ex)
            {
                return(new NewErrorModel()
                {
                    error = new Error(2, ex.Message, "")
                    {
                    },
                });
            }
        }
示例#7
0
        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();
                    //判断流程是否已结束
                    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, "流程尚未结束", "")
                            {
                            },
                        });
                    }

                    MaterialRelease ct = context.MaterialRelease.Where(u => u.TaskId == TaskId).FirstOrDefault();

                    Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();


                    keyValuePairs.Add("单位名称", ct.Company);
                    keyValuePairs.Add("车牌号", ct.CarNo);
                    keyValuePairs.Add("联系方式", ct.Tel);
                    keyValuePairs.Add("物品名称", ct.Name);
                    keyValuePairs.Add("数量", ct.Count);
                    keyValuePairs.Add("单位", ct.Unit);
                    keyValuePairs.Add("放行理由", ct.Cause);
                    keyValuePairs.Add("放行日期", ct.Date);
                    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();


                    string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime,
                                                        null, null, "2", 300, 650, null, null, null, dtApproveView, keyValuePairs);
                    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
                    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;
            }
        }