public async Task <object> 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);

                    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, "")
                            {
                            },
                        });
                    }
                    else
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, "文件有误", "")
                            {
                            },
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new NewErrorModel()
                {
                    error = new Error(1, ex.Message, "")
                    {
                    },
                });
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
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;
            }
        }
        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
                }));
            }
        }
Exemplo n.º 6
0
        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;
            }
        }
Exemplo n.º 7
0
        public async Task <NewErrorModel> PrintsProjectFunding(List <ProjectFunding> items, string userId, string templetName, string fileName, int column,
                                                               int row, string copyPath = "", string sheetName = "Sheet1")
        {
            if (items == null)
            {
                return(new NewErrorModel()
                {
                    error = new Error(0, "暂无数据", "")
                    {
                    },
                });
            }
            DataTable dtpurchaseTables = ClassChangeHelper.ToDataTable(items, new List <string>()
            {
                "Id", "TaskId"
            });
            string path    = HttpContext.Current.Server.MapPath(string.Format("~/UploadFile/Excel/Templet/{0}.xlsx", templetName));
            string time    = DateTime.Now.ToString("yyyyMMddHHmmss");
            string newPath = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet") + "\\" + fileName + time + ".xlsx";

            File.Copy(path, newPath);

            if (copyPath == "")
            {
                if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtpurchaseTables, column, row))
                {
                    DingTalkServersController dingTalkServersController = new DingTalkServersController();
                    //上盯盘
                    var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/" + fileName + time + ".xlsx");

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

                    //删除文件
                    File.Delete(newPath);
                    return(new NewErrorModel()
                    {
                        error = new Error(0, result, "")
                        {
                        },
                    });
                }
                else
                {
                    return(new NewErrorModel()
                    {
                        error = new Error(1, "文件有误", "")
                        {
                        },
                    });
                }
            }
            else
            {
                ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtpurchaseTables, column, row);
                string pathTest = Path.GetDirectoryName(copyPath);
                if (!Directory.Exists(pathTest))
                {
                    Directory.CreateDirectory(pathTest);
                }
                File.Copy(newPath, copyPath, true);
                return(new NewErrorModel()
                {
                    error = new Error(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, "")
                    {
                    },
                }));
            }
        }
Exemplo n.º 9
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;
            }
        }
Exemplo n.º 10
0
        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, "")
                    {
                    },
                });
            }
        }
Exemplo n.º 11
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> Read(string applyManId, int pageIndex, int pageSize, string projectType = "",
                                               string projectSmallType = "", string taskId = "", string key = "", bool IsPrint = false, int companyId = 3)
        {
            try
            {
                DDContext context = new DDContext();
                List <ProcessingProgress> processingProgresses =
                    context.ProcessingProgress.Where(t => t.TabulatorId.Contains(applyManId) ||
                                                     t.DesignerId.Contains(applyManId) || t.HeadOfDepartmentsId.Contains(applyManId) ||
                                                     t.NoteTakerId.Contains(applyManId)).ToList();
                if (companyId != 3)
                {
                    processingProgresses = processingProgresses.Where(p => p.CompanyId == companyId.ToString()).ToList();
                }
                processingProgresses = processingProgresses.Where(t =>
                                                                  (taskId != "" ? t.TaskId == taskId : 1 == 1)).ToList();
                processingProgresses = processingProgresses.Where(t =>
                                                                  (key != "" ? (t.ProjectName.Contains(key) || (t.Bom.Contains(key) || (t.Designer.Contains(key) || (t.NoteTaker.Contains(key))))) : 1 == 1)).ToList();

                processingProgresses = processingProgresses.Where(t =>
                                                                  (projectType != "" ? t.ProjectType == projectType : 1 == 1) &&
                                                                  (projectSmallType != "" ? t.ProjectSmallType == projectSmallType : 1 == 1)).OrderBy(t => t.SpeedOfProgress).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
                foreach (var item in processingProgresses)
                {
                    NewErrorModel errorModel = GetPower(applyManId, item.TaskId);
                    item.Power = (List <int>)errorModel.data;
                }
                if (IsPrint == false)
                {
                    return(new NewErrorModel()
                    {
                        count = processingProgresses.Count,
                        data = processingProgresses,
                        error = new Error(0, "读取成功!", "")
                        {
                        },
                    });
                }
                else
                {
                    DataTable dtpurchaseTables = ClassChangeHelper.ToDataTable(processingProgresses, new List <string>()
                    {
                        "DesignerId", "CompanyId", "HeadOfDepartmentsId", "NoteTakerId", "TabulatorId", "CreateTime", "FinishTime", "Power"
                    });
                    string path    = HttpContext.Current.Server.MapPath(string.Format("~/UploadFile/Excel/Templet/{0}.xlsx", "生产加工进度表模板"));
                    string time    = DateTime.Now.ToString("yyyyMMddHHmmss");
                    string newPath = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet") + "\\" + "生产加工进度表" + time + ".xlsx";
                    File.Copy(path, newPath, true);
                    if (ExcelHelperByNPOI.UpdateExcel(newPath, "研究院+华数", dtpurchaseTables, 0, 3))
                    {
                        DingTalkServersController dingTalkServersController = new DingTalkServersController();
                        //上盯盘
                        var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/" + "生产加工进度表" + time + ".xlsx");

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

                        //删除文件
                        File.Delete(newPath);
                        return(new NewErrorModel()
                        {
                            error = new Error(0, result, "")
                            {
                            },
                        });
                    }
                    else
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, "文件有误", "")
                            {
                            },
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 13
0
        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, "流程尚未结束", "")
                            {
                            },
                        });
                    }

                    CreateProject createProject = context.CreateProject.Where(u => u.TaskId == TaskId).First();


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

                    Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();
                    keyValuePairs.Add("项目名称", createProject.ProjectName);
                    keyValuePairs.Add("项目编号", createProject.ProjectId);
                    keyValuePairs.Add("承担部门", createProject.DeptName);
                    keyValuePairs.Add("公司名称", createProject.CompanyName);
                    keyValuePairs.Add("合作单位", string.IsNullOrEmpty(createProject.Customer)?"无":
                                      createProject.Customer);

                    keyValuePairs.Add("项目类型", createProject.ProjectType + "-" + createProject.ProjectSmallType);
                    keyValuePairs.Add("项目负责人", createProject.ResponsibleMan);
                    keyValuePairs.Add("项目组成员", createProject.TeamMembers);
                    keyValuePairs.Add("是否评审", createProject.IsReview == true ? "是" : "否");

                    string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime,
                                                        null, null, "2", 300, 650, null, null, null, dtApproveView, null, 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()
                    {
                        error = new Error(0, result, "")
                        {
                        },
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 14
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;
            }
        }
Exemplo n.º 15
0
        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;
            }
        }
Exemplo n.º 16
0
        public async Task <NewErrorModel> GetReport(DateTime dateStartTime, DateTime dateEndTime, string userId, string key = "")
        {
            try
            {
                using (DDContext context = new DDContext())
                {
                    List <Evection> evectionsPro = new List <Evection>();
                    List <Tasks>    tasks        = FlowInfoServer.ReturnUnFinishedTaskIdByFlowName("外出申请").Where(t => t.NodeId == 0).ToList();
                    List <Evection> evections    = context.Evection.ToList();
                    List <Evection> evectionPro  = new List <Evection>();
                    List <Evection> evectionProP = new List <Evection>();
                    DateTime        dateTime     = new DateTime();
                    foreach (var item in evections)
                    {
                        if (DateTime.TryParse(item.BeginTime, out dateTime))
                        {
                            if (DateTime.Parse(item.BeginTime) > dateStartTime && DateTime.Parse(item.EndTime) < dateEndTime)
                            {
                                evectionPro.Add(item);
                            }
                        }
                    }
                    foreach (var task in tasks)
                    {
                        foreach (var evection in evectionPro)
                        {
                            if (task.TaskId.ToString() == evection.TaskId)
                            {
                                //借用字段
                                evection.Duration = task.ApplyMan;
                                evectionProP.Add(evection);
                            }
                        }
                    }

                    DataTable dtpurchaseTables = ClassChangeHelper.ToDataTable(evectionProP, new List <string>()
                    {
                        "Id", "EvectionManId", "LocationPlace"
                    });
                    string path    = HttpContext.Current.Server.MapPath(string.Format("~/UploadFile/Excel/Templet/{0}.xlsx", "外出数据导出模板"));
                    string time    = DateTime.Now.ToString("yyyyMMddHHmmss");
                    string newPath = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet") + "\\" + "外出数据" + time + ".xlsx";
                    File.Copy(path, newPath, true);

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

                        //删除文件
                        File.Delete(newPath);
                    }
                    return(new NewErrorModel()
                    {
                        error = new Error(0, "推送成功!", "")
                        {
                        },
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }