Example #1
0
        public async Task <object> 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();
                    //判断流程是否已结束
                    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, "流程尚未结束", "")
                            {
                            },
                        }));
                    }

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

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


                    keyValuePairs.Add("外出人员", tasks.ApplyMan + (string.IsNullOrEmpty(ct.EvectionMan) ? "" : "," + ct.EvectionMan));
                    keyValuePairs.Add("外出地点", ct.Place);
                    keyValuePairs.Add("开始时间", ct.BeginTime);
                    keyValuePairs.Add("结束时间", ct.EndTime);
                    keyValuePairs.Add("外出事由", ct.Content);
                    keyValuePairs.Add("时长", ct.Duration);

                    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(result);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        public async Task <object> PrintAndSend([FromBody] PrintModel printAndSendModel)
        {
            try
            {
                string       TaskId    = printAndSendModel.TaskId;
                string       UserId    = printAndSendModel.UserId;
                PDFHelperNew pdfHelper = new PDFHelperNew();
                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 <Borrow> GoDownList = context.Borrow.Where(u => u.TaskId == TaskId).ToList();

                    var SelectGoDownList = from g in GoDownList
                                           select new
                    {
                        g.Supplier,
                        g.Name,
                        g.CodeNo,
                        g.Standard,
                        g.Unit,
                        g.Count,
                        g.Price,
                        g.Purpose,
                        Time = g.Standard + "-" + g.EndTime,
                        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, 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)
            {
                return(new NewErrorModel()
                {
                    error = new Error(1, ex.Message, "")
                    {
                    },
                });
            }
        }
Example #3
0
        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();
                    string    ProjectName   = context.ProjectInfo.Where(p => p.ProjectId == ProjectId).First().ProjectName;

                    //绘制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.ApplyTime,
                                                        ProjectName, "2", 300, 650, contentList, contentWithList, dtSourse, dtApproveView);
                    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
                }));
            }
        }
Example #4
0
        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, "")
                    {
                    },
                }));
            }
        }
Example #5
0
        public async Task <object> GetAllPDF(string taskId, string applyManId)
        {
            try
            {
                using (DDContext context = new DDContext())
                {
                    string strUrl        = "";
                    string strFilePDFUrl = context.Tasks.Where(t => t.TaskId.ToString() == taskId && t.NodeId == 0).FirstOrDefault().FilePDFUrl;
                    string strFileUrl    = context.Tasks.Where(t => t.TaskId.ToString() == taskId && t.NodeId == 0).FirstOrDefault().FileUrl;

                    if (!string.IsNullOrEmpty(strFileUrl))
                    {
                        strUrl = strFilePDFUrl + "," + strFileUrl;
                    }
                    else
                    {
                        strUrl = strFilePDFUrl;
                    }

                    string[] FilePDFUrl = strUrl.Split(',');
                    if (FilePDFUrl.Length > 0)
                    {
                        List <string> ListPath = new List <string>(FilePDFUrl);
                        //List<string> ListAbPath = new List<string>();
                        List <string> ListNewPath = new List <string>();
                        int           iCount      = 12; //设置每个文件夹最大文件数量
                        int           i           = 0;
                        foreach (var item in ListPath)
                        {
                            if (ListNewPath.Count < iCount)
                            {
                                string newPathName = (HttpContext.Current.Server.MapPath(item).Substring(0, HttpContext.Current.Server.MapPath(item).Length - 18)) +
                                                     System.IO.Path.GetExtension(HttpContext.Current.Server.MapPath(item));
                                File.Copy(HttpContext.Current.Server.MapPath(item), newPathName, true);

                                ListNewPath.Add(newPathName);
                                //ListNewPath.Add(HttpContext.Current.Server.MapPath(item));
                            }
                            if (ListNewPath.Count == iCount || ListPath.IndexOf(item) == ListPath.Count - 1)
                            {
                                i++;
                                string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip",
                                                                AppDomain.CurrentDomain.BaseDirectory,
                                                                "流水号" + taskId + "图纸打包第" + i + "份" +
                                                                DateTime.Now.ToString("yyyyMMddHHmmss"));

                                //文件压缩打包
                                IonicHelper.CompressMulti(ListNewPath, SavePath, false);

                                //FileStream filestream = new FileStream((SavePath), FileMode.Open);
                                //byte[] bt = new byte[filestream.Length];
                                ////调用read读取方法
                                //filestream.Read(bt, 0, bt.Length);
                                //string base64Str = Convert.ToBase64String(bt);
                                //filestream.Close();
                                //return new NewErrorModel()
                                //{
                                //    data = "data:application/zip;base64," + base64Str,
                                //    error = new Error(0, "下载成功!", "") { },
                                //};

                                DingTalkServersController dingTalkServersController = new DingTalkServersController();
                                SavePath = "~\\" + FileHelper.RelativePath(HttpContext.Current.Server.MapPath("~/"), SavePath);



                                //上盯盘
                                var resultUploadMedia = await dingTalkServersController.UploadMedia(SavePath);

                                //推送用户
                                FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia);
                                fileSendModel.UserId = applyManId;
                                var result = await dingTalkServersController.SendFileMessage(fileSendModel);

                                if (ListNewPath.Count > 0)
                                {
                                    //ListNewPath.Add(SavePath);
                                    foreach (var items in ListNewPath)
                                    {
                                        File.Delete(items);
                                    }
                                }

                                ListNewPath.Clear();
                            }
                        }
                    }


                    return(new NewErrorModel()
                    {
                        error = new Error(0, "已推送至钉钉!", "")
                        {
                        },
                    });
                }
            }
            catch (Exception ex)
            {
                return(new NewErrorModel()
                {
                    error = new Error(1, ex.Message, "")
                    {
                    },
                });
            }
        }