public async Task <object> Save([FromBody] ErrorLogs ErrorLog)
        {
            try
            {
                EFHelper <ErrorLogs> eFHelper = new EFHelper <ErrorLogs>();
                ErrorLog.ApplyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                eFHelper.Add(ErrorLog);
                //钉钉推送超管

                string[] SaIds = System.Configuration.ConfigurationManager.AppSettings["administrator"].Split(',');
                DingTalkServersController dingTalkServersController = new DingTalkServersController();

                foreach (var SaId in SaIds)
                {
                    await dingTalkServersController.sendOaMessage(SaId, "报错反馈", "系统报错", "eapp://util/errorPage/errorPage");
                }

                return(new NewErrorModel()
                {
                    error = new Error(0, "保存成功!", "")
                    {
                    },
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        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, "")
                    {
                    },
                });
            }
        }
        public async Task <NewErrorModel> Bintang(string authCode)
        {
            try
            {
                DingTalkServersController dingTalkServersController = new DingTalkServersController();
                string accessToken = await GetAccessToken();

                string userId = await GetUserId(accessToken, authCode);

                string accessTokenT = await GetAccessToken();

                UserInfoMobileModel userInfo = await GetUserInfo(accessTokenT, userId);

                string DeptInfo = await dingTalkServersController.departmentQuaryByUserId(userInfo.userid);

                DeptModel dept = JsonConvert.DeserializeObject <DeptModel>(DeptInfo);

                if (dept.errcode == 0)
                {
                    userInfo.dept = dept.name;
                }
                else
                {
                    userInfo.dept = dept.errmsg;
                }

                return(new NewErrorModel()
                {
                    data = userInfo,
                    error = new Error(0, "读取成功!", "")
                    {
                    },
                });
            }
            catch (Exception ex)
            {
                return(new NewErrorModel()
                {
                    error = new Error(2, ex.Message, "")
                    {
                    },
                });
            }
        }
        public async Task <NewErrorModel> SendMsg(string projectId)
        {
            try
            {
                DDContext context = new DDContext();
                DingTalkServersController dingTalkServersController = new DingTalkServersController();
                ProjectInfo projectInfo = context.ProjectInfo.Where(p => p.ProjectId == projectId).FirstOrDefault();
                await dingTalkServersController.SendProjectMsg(projectInfo.ResponsibleManId,
                                                               string.Format("亲,您的{0}项目即将在{1}到期,请尽快完成项目并申请结题。", projectInfo.ProjectName, projectInfo.EndTime), string.Format("eapp://page/approveDetail/projectDetail/projectDetail?projectId={0}", projectInfo.ProjectId));

                return(new NewErrorModel()
                {
                    error = new Error(0, "通知成功!", "")
                    {
                    },
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <string> GetReport(string TaskId, string UserId)
        {
            try
            {
                PDFHelper pdfHelper = new PDFHelper();
                using (DDContext context = new DDContext())
                {
                    //获取表单信息
                    Tasks  tasks     = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First();
                    string FlowId    = tasks.FlowId.ToString();
                    string ProjectId = tasks.ProjectId;

                    //判断流程是否已结束
                    List <Tasks> tasksList = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.IsSend != true && t.State == 0).ToList();
                    if (tasksList.Count > 0)
                    {
                        return(JsonConvert.SerializeObject(
                                   new NewErrorModel()
                        {
                            error = new Error(0, "流程尚未结束", "")
                            {
                            },
                        }));
                    }

                    List <Receiving> ReceivingList = context.Receiving.Where(u => u.TaskId == TaskId).ToList();
                    DataTable        dtSourse      = DtLinqOperators.CopyToDataTable(ReceivingList);
                    List <NodeInfo>  NodeInfoList  = context.NodeInfo.Where(u => u.FlowId == FlowId && u.NodeId != 0 && u.NodeName != "结束" && !u.NodeName.Contains("抄送")).ToList();
                    foreach (NodeInfo nodeInfo in NodeInfoList)
                    {
                        if (string.IsNullOrEmpty(nodeInfo.NodePeople))
                        {
                            List <Tasks> taskList = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).ToList();
                            foreach (var task in taskList)
                            {
                                nodeInfo.NodePeople += "  " + task.ApplyMan + "  " + task.ApplyTime;
                            }
                        }
                        else
                        {
                            string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime;
                            nodeInfo.NodePeople = nodeInfo.NodePeople + "  " + ApplyTime;
                        }
                    }

                    DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList);
                    string    FlowName      = context.Flows.Where(f => f.FlowId.ToString() == FlowId).First().FlowName.ToString();

                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    Receiving receiving             = context.Receiving.Where(r => r.TaskId == TaskId).SingleOrDefault();
                    dic.Add("申请人", tasks.ApplyMan);
                    dic.Add("流水号", tasks.TaskId.ToString());
                    dic.Add("标题", tasks.Title);
                    dic.Add("收文编号", receiving.ReceivingNo);
                    dic.Add("来文单位", receiving.ReceivingUnit);
                    dic.Add("文件文号", receiving.FileNo);
                    dic.Add("收文时间", receiving.ReceivingTime);
                    dic.Add("主要内容", receiving.MainIdea);
                    dic.Add("拟办意见", receiving.Suggestion);
                    dic.Add("领导阅示", receiving.Leadership);
                    dic.Add("承办部门阅办情况", receiving.Review.Replace("~", "     "));
                    dic.Add("办理落实情况", receiving.HandleImplementation.Replace("~", "     "));
                    string path = pdfHelper.GeneratePDF(FlowName, null, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime, "",
                                                        "", "", "2", 380, 710, null, null, dtSourse, dtApproveView, dic);
                    string        RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path);
                    List <string> newPaths     = new List <string>();
                    RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\');
                    newPaths.Add(RelativePath);
                    string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, "文件阅办单" + DateTime.Now.ToString("yyyyMMddHHmmss"));
                    //文件压缩打包
                    IonicHelper.CompressMulti(newPaths, SavePath, false);
                    //上传盯盘获取MediaId
                    SavePath = string.Format(@"~\UploadFile\Ionic\{0}", Path.GetFileName(SavePath));
                    DingTalkServersController dingTalkServersController = new DingTalkServersController();
                    var resultUploadMedia = await dingTalkServersController.UploadMedia(SavePath);

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

                    return(JsonConvert.SerializeObject(
                               new NewErrorModel()
                    {
                        error = new Error(0, "获取成功,请在钉钉工作通知中查收!", "")
                        {
                        },
                        data = result
                    }));
                }
            }
            catch (Exception ex)
            {
                return(JsonConvert.SerializeObject(
                           new NewErrorModel()
                {
                    error = new Error(1, ex.Message, "")
                    {
                    },
                }));
            }
        }
示例#6
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;
            }
        }
        public async Task <object> QuaryPrintExcel(DateTime startTime, DateTime endTime, int pageIndex, int pageSize, string applyManId, string key = "", bool IsSend = false, bool IsPublic = true)
        {
            try
            {
                using (DDContext context = new DDContext())
                {
                    FlowInfoServer    flowInfoServer = new FlowInfoServer();
                    List <Car>        cars           = context.Car.ToList();
                    List <Tasks>      tasksNew       = FlowInfoServer.ReturnUnFinishedTaskId(IsPublic == true ? "13" : "14"); //公车任务流13
                    List <TasksState> tasksStates    = context.TasksState.ToList();
                    List <Tasks>      tasks          = new List <Tasks>();

                    //foreach (var item in tasksNew)
                    //{
                    //    if (flowInfoServer.GetTasksState(item.TaskId.ToString()) == "已完成")
                    //    {
                    //        tasks.Add(item);
                    //    }
                    //}

                    foreach (var item in tasksNew)
                    {
                        if (tasksStates.Where(t => t.TaskId.ToString() == item.TaskId.ToString()).FirstOrDefault().State == "已完成")
                        {
                            tasks.Add(item);
                        }
                    }
                    List <CarTable> carTables = context.CarTable.ToList();
                    if (IsPublic)
                    {
                        var Quary = from ct in carTables
                                    join t in tasks on ct.TaskId equals t.TaskId.ToString()
                                    join c in cars on ct.CarId equals c.Id.ToString()
                                        where t.NodeId.ToString() == "0" && ct.StartTime > startTime && ct.EndTime < endTime && ct.IsPublicCar == IsPublic &&
                                    (!(string.IsNullOrEmpty(key)) ? (t.ApplyMan.Contains(key) || t.Dept.Contains(key) || t.TaskId.ToString() == key || c.Name.Contains(key)) : t.ApplyMan != null)
                                    select new
                        {
                            TaskId                = t.TaskId,
                            Dept                  = t.Dept,
                            ApplyMan              = t.ApplyMan,
                            UseTime               = ct.StartTime.ToString() + "---" + ct.EndTime.ToString(),
                            Name                  = c.Name + "(" + c.CarNumber + ")",
                            MainContent           = ct.MainContent,
                            UseKilometres         = ct.UseKilometres,
                            UnitPricePerKilometre = c.UnitPricePerKilometre,
                            FactKilometre         = ct.FactKilometre,
                            AllPrice              = float.Parse(ct.FactKilometre) * float.Parse(c.UnitPricePerKilometre.ToString()),
                            //Remark = t.Remark
                        };

                        var takeQuary = Quary.Skip((pageIndex - 1) * pageSize).Take(pageSize);
                        if (IsSend && Quary.Count() > 0)  //生成报表推送用户
                        {
                            //DataTable dtpurchaseTables = DtLinqOperators.CopyToDataTable(Quary);

                            DataTable dtReturn = new DataTable();
                            // column names
                            PropertyInfo[] oProps = null;
                            // Could add a check to verify that there is an element 0
                            foreach (var rec in Quary)
                            {
                                // Use reflection to get property names, to create Table, Only first time, others will follow
                                if (oProps == null)
                                {
                                    oProps = ((Type)rec.GetType()).GetProperties();
                                    foreach (PropertyInfo pi in oProps)
                                    {
                                        Type colType = pi.PropertyType; if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable <>)))
                                        {
                                            colType = colType.GetGenericArguments()[0];
                                        }
                                        dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
                                    }
                                }
                                DataRow dr = dtReturn.NewRow(); foreach (PropertyInfo pi in oProps)
                                {
                                    dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue(rec, null);
                                }
                                dtReturn.Rows.Add(dr);
                            }

                            string path    = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFile/Excel/Templet/用车通用模板(公车).xlsx");
                            string time    = DateTime.Now.ToString("yyyyMMddHHmmss");
                            string newPath = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFile/Excel/Templet") + "\\用车数据(公车)" + time + ".xlsx";
                            System.IO.File.Copy(path, newPath);
                            if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtReturn, 0, 2))
                            {
                                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);

                                return(new NewErrorModel()
                                {
                                    error = new Error(0, "已推送至钉钉!", "")
                                    {
                                    },
                                });
                            }
                        }
                        else
                        {
                            return(new NewErrorModel()
                            {
                                count = Quary.Count(),
                                data = takeQuary,
                                error = new Error(0, "读取成功!", "")
                                {
                                },
                            });
                        }
                    }

                    else
                    {
                        var QuaryPri = from ct in carTables
                                       join t in tasks on ct.TaskId equals t.TaskId.ToString()
                                           where t.NodeId.ToString() == "0" && ct.StartTime > startTime && ct.EndTime < endTime && ct.IsPublicCar == IsPublic &&
                                       (!(string.IsNullOrEmpty(key)) ? (t.ApplyMan.Contains(key) || t.Dept.Contains(key)) : t.ApplyMan != null)
                                       select new
                        {
                            TaskId          = t.TaskId,
                            Dept            = t.Dept,
                            ApplyMan        = t.ApplyMan,
                            UseTime         = ct.StartTime.ToString() + "---" + ct.EndTime.ToString(),
                            MainContent     = ct.MainContent,
                            UseKilometres   = ct.UseKilometres,
                            StartKilometres = ct.StartKilometres == null ? "" : ct.StartKilometres,
                            EndKilometres   = ct.EndKilometres == null ? "" : ct.EndKilometres,
                        };
                        var takeQuaryPri = QuaryPri.Skip((pageIndex - 1) * pageSize).Take(pageSize);

                        if (IsSend && QuaryPri.Count() > 0)  //生成报表推送用户
                        {
                            //DataTable dtpurchaseTables = DtLinqOperators.CopyToDataTable(Quary);

                            DataTable dtReturn = new DataTable();
                            // column names
                            PropertyInfo[] oProps = null;
                            // Could add a check to verify that there is an element 0
                            foreach (var rec in QuaryPri)
                            {
                                // Use reflection to get property names, to create Table, Only first time, others will follow
                                if (oProps == null)
                                {
                                    oProps = ((Type)rec.GetType()).GetProperties();
                                    foreach (PropertyInfo pi in oProps)
                                    {
                                        Type colType = pi.PropertyType; if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable <>)))
                                        {
                                            colType = colType.GetGenericArguments()[0];
                                        }
                                        dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
                                    }
                                }
                                DataRow dr = dtReturn.NewRow(); foreach (PropertyInfo pi in oProps)
                                {
                                    dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue(rec, null);
                                }
                                dtReturn.Rows.Add(dr);
                            }
                            string path    = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFile/Excel/Templet/用车通用模板(私车).xlsx");
                            string time    = DateTime.Now.ToString("yyyyMMddHHmmss");
                            string newPath = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFile/Excel/Templet") + "\\用车数据(私车)" + time + ".xlsx";
                            System.IO.File.Copy(path, newPath);
                            if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtReturn, 0, 2))
                            {
                                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);

                                return(new NewErrorModel()
                                {
                                    error = new Error(0, "已推送至钉钉!", "")
                                    {
                                    },
                                });
                            }
                        }
                        else
                        {
                            return(new NewErrorModel()
                            {
                                count = QuaryPri.Count(),
                                data = takeQuaryPri,
                                error = new Error(0, "读取成功!", "")
                                {
                                },
                            });
                        }
                    }
                }
                return("");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#8
0
        public async Task <object> Query(string applyManId, DateTime startTime, DateTime endTime, bool IsSend = false, string projectId = null, string key = null)
        {
            try
            {
                using (DDContext context = new DDContext())
                {
                    List <Pick>  picks    = context.Pick.ToList();
                    List <Tasks> tasks    = FlowInfoServer.ReturnUnFinishedTaskIdByFlowName("领料申请");
                    List <Tasks> tasksNew = tasks.Where(t => t.NodeId.ToString() == "0").ToList();
                    tasksNew = tasksNew.Where(t =>
                                              (projectId == null ? 1 == 1 : t.ProjectId == projectId) &&
                                              (DateTime.Parse(t.ApplyTime) > startTime && DateTime.Parse(t.ApplyTime) < endTime)).ToList(); //过滤审批后的流程
                    List <Roles> roles = context.Roles.Where(r => r.RoleName == "领料管理人员" && r.UserId == applyManId).ToList();

                    if (roles.Count > 0 ? true : false)  //领料管理员
                    {
                        if (IsSend)
                        {
                            var Query = from t in tasksNew
                                        join p in picks on
                                        t.TaskId.ToString() equals p.TaskId
                                            where
                                        key != null ?
                                        (t.ApplyMan.Contains(key) || t.Dept.Contains(key) || p.fName.Contains(key)) : 1 == 1
                                        select new
                            {
                                t.ProjectName,
                                t.ApplyMan,
                                t.ApplyTime,
                                t.TaskId,
                                p.fName,
                                p.fNumber,
                                p.fModel,
                                p.fFullName,
                                p.fQty,
                                p.fPrice,
                                p.fAmount,
                                p.unitName,
                                t.Remark
                            };
                            DataTable      dtReturn = new DataTable();
                            PropertyInfo[] oProps   = null;
                            foreach (var rec in Query)
                            {
                                if (oProps == null)
                                {
                                    oProps = ((Type)rec.GetType()).GetProperties();
                                    foreach (PropertyInfo pi in oProps)
                                    {
                                        Type colType = pi.PropertyType; if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable <>)))
                                        {
                                            colType = colType.GetGenericArguments()[0];
                                        }
                                        dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
                                    }
                                }
                                DataRow dr = dtReturn.NewRow(); foreach (PropertyInfo pi in oProps)
                                {
                                    dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue(rec, null);
                                }
                                dtReturn.Rows.Add(dr);
                            }
                            string path    = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFile/Excel/Templet/领料数据统计模板.xlsx");
                            string time    = DateTime.Now.ToString("yyyyMMddHHmmss");
                            string newPath = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFile/Excel/Templet") + "\\领料数据统计" + time + ".xlsx";
                            System.IO.File.Copy(path, newPath);
                            if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtReturn, 0, 1))
                            {
                                DingTalkServersController dingTalkServersController = new DingTalkServersController();
                                //上盯盘
                                var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/领料数据统计" + time + ".xlsx");

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

                                return(new NewErrorModel()
                                {
                                    error = new Error(0, "已推送至钉钉", "")
                                    {
                                    },
                                });
                            }
                        }
                        else
                        {
                            var Query = from t in tasksNew
                                        join p in picks on
                                        t.TaskId.ToString() equals p.TaskId
                                            where
                                        key != null ?
                                        (t.ApplyMan.Contains(key) || t.Dept.Contains(key) || p.fName.Contains(key)) : 1 == 1
                                        select new
                            {
                                t.ProjectName,
                                t.ApplyMan,
                                t.ApplyTime,
                                t.TaskId,
                                p.fName,
                                p.fNumber,
                                p.fModel,
                                p.fFullName,
                                p.fQty,
                                p.fPrice,
                                p.fAmount,
                                p.unitName,
                                t.Remark
                            };
                            return(new NewErrorModel()
                            {
                                data = Query,
                                error = new Error(0, "查询成功", "")
                                {
                                },
                            });
                        }
                    }
                    else
                    {
                        List <ProjectInfo> projectInfos = context.ProjectInfo.
                                                          Where(p => p.ResponsibleManId == applyManId).ToList();
                        if (projectInfos.Count > 0)
                        {
                            if (IsSend)
                            {
                                var Query = from pi in projectInfos
                                            join t in tasksNew on pi.ProjectId equals t.ProjectId
                                            join p in picks on t.TaskId.ToString()
                                            equals p.TaskId
                                            select new
                                {
                                    t.ProjectName,
                                    t.ApplyMan,
                                    t.ApplyTime,
                                    t.TaskId,
                                    p.fName,
                                    p.fNumber,
                                    p.fModel,
                                    p.fFullName,
                                    p.fQty,
                                    p.fPrice,
                                    p.fAmount,
                                    p.unitName,
                                    t.Remark
                                };
                                DataTable      dtReturn = new DataTable();
                                PropertyInfo[] oProps   = null;
                                foreach (var rec in Query)
                                {
                                    if (oProps == null)
                                    {
                                        oProps = ((Type)rec.GetType()).GetProperties();
                                        foreach (PropertyInfo pi in oProps)
                                        {
                                            Type colType = pi.PropertyType; if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable <>)))
                                            {
                                                colType = colType.GetGenericArguments()[0];
                                            }
                                            dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
                                        }
                                    }
                                    DataRow dr = dtReturn.NewRow(); foreach (PropertyInfo pi in oProps)
                                    {
                                        dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue(rec, null);
                                    }
                                    dtReturn.Rows.Add(dr);
                                }
                                string path    = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFile/Excel/Templet/领料数据统计模板.xlsx");
                                string time    = DateTime.Now.ToString("yyyyMMddHHmmss");
                                string newPath = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFile/Excel/Templet") + "\\领料数据统计" + time + ".xlsx";
                                System.IO.File.Copy(path, newPath);
                                if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtReturn, 0, 1))
                                {
                                    DingTalkServersController dingTalkServersController = new DingTalkServersController();
                                    //上盯盘
                                    var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/领料数据统计" + time + ".xlsx");

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

                                    return(new NewErrorModel()
                                    {
                                        error = new Error(0, "已推送至钉钉", "")
                                        {
                                        },
                                    });
                                }
                            }
                            else
                            {
                                var Query = from pi in projectInfos
                                            join t in tasksNew on pi.ProjectId equals t.ProjectId
                                            join p in picks on t.TaskId.ToString()
                                            equals p.TaskId
                                            select new
                                {
                                    t.ProjectName,
                                    t.ApplyMan,
                                    t.ApplyTime,
                                    t.TaskId,
                                    p.fName,
                                    p.fNumber,
                                    p.fModel,
                                    p.fFullName,
                                    p.fQty,
                                    p.fPrice,
                                    p.fAmount,
                                    p.unitName,
                                    t.Remark
                                };
                                return(new NewErrorModel()
                                {
                                    data = Query,
                                    error = new Error(0, "查询成功", "")
                                    {
                                    },
                                });
                            }
                        }
                    }
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(new NewErrorModel()
                {
                    error = new Error(1, ex.Message, null)
                    {
                    },
                });
            }
        }
示例#9
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;
            }
        }
示例#10
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;
            }
        }
示例#11
0
        public async Task <NewErrorModel> PrintExcel(string taskId, string UserId)
        {
            try
            {
                using (DDContext context = new DDContext())
                {
                    List <PurchaseTable> purchaseTables = context.PurchaseTable.Where(p => p.TaskId == taskId).ToList();
                    //DataTable dtpurchaseTables = ClassChangeHelper.ToDataTable(purchaseTables);
                    var SelectPurchaseList = from p in purchaseTables
                                             select new
                    {
                        p.Id,
                        p.TaskId,
                        p.CodeNo,
                        p.Name,
                        Type = p.Standard,
                        p.Unit,
                        p.Count,
                        p.Price,
                        p.Purpose,
                        p.UrgentDate,
                        p.Mark,
                        p.SendPosition,
                        p.PurchaseMan,
                        p.purchaseType
                    };
                    DataTable dtpurchaseTables = DtLinqOperators.CopyToDataTable(SelectPurchaseList);


                    string path    = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet/采购导出模板.xlsx");
                    string time    = DateTime.Now.ToString("yyyyMMddHHmmss");
                    string newPath = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet") + "\\采购单" + time + ".xlsx";
                    File.Copy(path, newPath);
                    if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtpurchaseTables, 0, 1))
                    {
                        DingTalkServersController dingTalkServersController = new DingTalkServersController();
                        //上盯盘
                        var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/采购单" + time + ".xlsx");

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

                        return(new NewErrorModel()
                        {
                            error = new Error(0, result, "Excel已推送至您的钉钉")
                            {
                            },
                        });
                    }
                    else
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, "文件有误", "")
                            {
                            },
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new NewErrorModel()
                {
                    error = new Error(2, ex.Message, "")
                    {
                    },
                });
            }
        }
示例#12
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 <NewErrorModel> Modify(ProcessingProgressModel processingProgressModel)
        {
            try
            {
                using (DDContext context = new DDContext())
                {
                    DingTalkServersController dingTalkServersController = new DingTalkServersController();
                    foreach (var item in processingProgressModel.processingProgresses)
                    {
                        string eappUrl = string.Format("eapp://page/start/productionMonitoring/productionMonitoring?taskid={0}&companyId={1}", item.TaskId, item.CompanyId);
                        //判断当前修改权限
                        NewErrorModel errorModel = GetPower(processingProgressModel.applyManId, item.TaskId);
                        List <int>    vs         = (List <int>)errorModel.data;

                        if (vs.Contains(1) && vs.Contains(3)) //  0 生产加工进度发起人 1 生产加工进度分配人 2 没权限(设计人员) 3.实际记录人
                        {
                            context.Entry <ProcessingProgress>(item).State = System.Data.Entity.EntityState.Modified;
                            if (!string.IsNullOrEmpty(item.SpeedOfProgress)) //获取工作进度表状态
                            {
                                //推送制表人
                                await dingTalkServersController.SendProcessingProgress(item.TabulatorId, 2, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);

                                //推送设计人员
                                await dingTalkServersController.SendProcessingProgress(item.DesignerId, 2, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);
                            }
                            context.SaveChanges();
                            return(new NewErrorModel()
                            {
                                error = new Error(0, "修改成功!", "")
                                {
                                },
                            });
                        }

                        if (vs.Count == 1 && vs.Contains(1)) //  0 生产加工进度发起人 1 生产加工进度分配人 2 没权限(设计人员) 3.实际记录人
                        {
                            context.Entry <ProcessingProgress>(item).State = System.Data.Entity.EntityState.Modified;
                            if (!string.IsNullOrEmpty(item.SpeedOfProgress)) //获取工作进度表状态
                            {
                                //推送实际记录人
                                await dingTalkServersController.SendProcessingProgress(item.NoteTakerId, 3, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);
                            }
                        }
                        if (vs.Count == 1 && vs.Contains(0))  //制表人 暂时不通知(添加的时候通知了)
                        {
                            context.Entry <ProcessingProgress>(item).State = System.Data.Entity.EntityState.Modified;
                        }
                        if (vs.Count == 1 && vs.Contains(2)) //  0 生产加工进度发起人 1 生产加工进度分配人 2 没权限(设计人员) 3.实际记录人
                        {
                            if (item.IsAlreadyRead == true)
                            {
                                item.FinishTime = DateTime.Now.ToString("yyyy-MM-dd");
                            }
                            //修改已读状态
                            context.Entry <ProcessingProgress>(item).State = System.Data.Entity.EntityState.Modified;

                            //推送制表人
                            await dingTalkServersController.SendProcessingProgress(item.TabulatorId, 1, processingProgressModel.applyMan, item.Bom
                                                                                   , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);

                            //推送分配人
                            await dingTalkServersController.SendProcessingProgress(item.HeadOfDepartmentsId, 1, processingProgressModel.applyMan, item.Bom
                                                                                   , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);
                        }
                        if (/*vs.Count == 1 &&*/ vs.Contains(3)) //  0 生产加工进度发起人 1 生产加工进度分配人 2 没权限(设计人员) 3.实际记录人
                        {
                            context.Entry <ProcessingProgress>(item).State = System.Data.Entity.EntityState.Modified;
                            if (!string.IsNullOrEmpty(item.SpeedOfProgress)) //获取工作进度表状态
                            {
                                //推送制表人
                                await dingTalkServersController.SendProcessingProgress(item.TabulatorId, 0, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);

                                //推送设计人员
                                await dingTalkServersController.SendProcessingProgress(item.DesignerId, 0, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);

                                //推送分配人
                                await dingTalkServersController.SendProcessingProgress(item.HeadOfDepartmentsId, 0, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);
                            }
                        }
                    }
                    context.SaveChanges();
                }
                return(new NewErrorModel()
                {
                    error = new Error(0, "修改成功!", "")
                    {
                    },
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#14
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, "")
                    {
                    },
                });
            }
        }
        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;
            }
        }
        public async Task <NewErrorModel> Save(ProcessingProgressModel processingProgressModel)
        {
            try
            {
                if (processingProgressModel.CompanyId == 0)  //研究院
                {
                    DDContext dDContext = new DDContext();
                    string    eappUrl   = string.Format("eapp://page/start/productionMonitoring/productionMonitoring?taskid={0}&companyId={1}", processingProgressModel.processingProgresses[0].TaskId, processingProgressModel.CompanyId);
                    if (dDContext.Roles.Where(r => r.RoleName == "生产加工进度发起人" && r.UserId == processingProgressModel.applyManId).ToList().Count == 0)
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, "没有权限上传!", "")
                            {
                            },
                        });
                    }

                    List <Models.DingModels.ProjectInfo> projectInfos = dDContext.ProjectInfo.ToList();

                    if (processingProgressModel.IsExcelUpload)
                    {
                        foreach (var processingProgresse in processingProgressModel.processingProgresses)
                        {
                            //校对数据
                            if (!string.IsNullOrEmpty(processingProgresse.TaskId))
                            {
                                processingProgresse.CompanyId = processingProgressModel.CompanyId.ToString();
                                List <ProcessingProgress> ProcessingProgressList = dDContext.ProcessingProgress.Where(p => p.TaskId == processingProgresse.TaskId && p.CompanyId == processingProgressModel.CompanyId.ToString()).ToList();
                                if (ProcessingProgressList.Count > 0)
                                {
                                    return(new NewErrorModel()
                                    {
                                        error = new Error(1, string.Format("保存失败,系统中已存在流水号 {0} 的数据", processingProgresse.TaskId), "")
                                        {
                                        },
                                    });
                                }
                                if (projectInfos.Where(p => p.ProjectId == processingProgresse.ProjectId &&
                                                       p.ProjectName == processingProgresse.ProjectName).ToList().Count == 0)
                                {
                                    return(new NewErrorModel()
                                    {
                                        error = new Error(1, string.Format("保存失败,项目Id {0} 、 项目名 {1} 与系统中的数据不吻合!", processingProgresse.ProjectId, processingProgresse.ProjectName), "")
                                        {
                                        },
                                    });
                                }
                                else
                                {
                                    if (projectInfos.Where(p => p.ProjectId == processingProgresse.ProjectId &&
                                                           p.ProjectName == p.ProjectName && p.ProjectType == processingProgresse.ProjectType &&
                                                           p.ProjectSmallType == processingProgresse.ProjectSmallType).ToList().Count == 0)
                                    {
                                        return(new NewErrorModel()
                                        {
                                            error = new Error(1, string.Format("保存失败,项目Id {0} 、 项目名 {1} 与系统中的大类、小类不吻合!", processingProgresse.ProjectId, processingProgresse.ProjectName), "")
                                            {
                                            },
                                        });
                                    }
                                    else
                                    {
                                        List <Models.DingModels.Tasks> tasksDesigner          = dDContext.Tasks.Where(t => t.ApplyMan.Contains(processingProgresse.Designer)).ToList();
                                        List <Models.DingModels.Tasks> tasksNoteTaker         = dDContext.Tasks.Where(t => t.ApplyMan.Contains(processingProgresse.NoteTaker)).ToList();
                                        List <Models.DingModels.Tasks> tasksHeadOfDepartments = dDContext.Tasks.Where(t => t.ApplyMan.Contains(processingProgresse.HeadOfDepartments)).ToList();
                                        List <Models.DingModels.Tasks> tasksTabulator         = dDContext.Tasks.Where(t => t.ApplyMan.Contains(processingProgresse.Tabulator)).ToList();
                                        if (tasksDesigner.Count == 0 || tasksNoteTaker.Count == 0 || tasksHeadOfDepartments.Count == 0 || tasksTabulator.Count == 0)
                                        {
                                            if (tasksTabulator.Count == 0)
                                            {
                                                return(new NewErrorModel()
                                                {
                                                    error = new Error(1, string.Format("保存失败,系统中找不到:制表人 {0} 的Id   !", processingProgresse.Tabulator), "")
                                                    {
                                                    },
                                                });
                                            }
                                            if (tasksDesigner.Count == 0)
                                            {
                                                return(new NewErrorModel()
                                                {
                                                    error = new Error(1, string.Format("保存失败,系统中找不到:设计员 {0} 的Id   !", processingProgresse.NoteTaker), "")
                                                    {
                                                    },
                                                });
                                            }
                                            if (tasksNoteTaker.Count == 0)
                                            {
                                                return(new NewErrorModel()
                                                {
                                                    error = new Error(1, string.Format("保存失败,系统中找不到:记录员 {0} 的Id   !", processingProgresse.Designer), "")
                                                    {
                                                    },
                                                });
                                            }
                                            if (tasksHeadOfDepartments.Count == 0)
                                            {
                                                return(new NewErrorModel()
                                                {
                                                    error = new Error(1, string.Format("保存失败,系统中找不到:部门负责人 {0} 的Id   !", processingProgresse.HeadOfDepartments), "")
                                                    {
                                                    },
                                                });
                                            }
                                        }
                                        else
                                        {
                                            processingProgresse.TabulatorId         = tasksTabulator[0].ApplyManId;
                                            processingProgresse.DesignerId          = tasksDesigner[0].ApplyManId;
                                            processingProgresse.NoteTakerId         = tasksNoteTaker[0].ApplyManId;
                                            processingProgresse.HeadOfDepartmentsId = tasksHeadOfDepartments[0].ApplyManId;
                                            processingProgresse.CreateTime          = DateTime.Now.ToString("yyyy-MM-dd");
                                            dDContext.ProcessingProgress.Add(processingProgresse);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!processingProgressModel.IsExcelUpload)  //操作界面添加
                    {
                        List <ProcessingProgress> ProcessingProgressList = new List <ProcessingProgress>();

                        foreach (ProcessingProgress processingProgresse in processingProgressModel.processingProgresses)
                        {
                            List <ProcessingProgress> ProcessingProgressListNew = dDContext.ProcessingProgress.Where(p => p.TaskId == processingProgresse.TaskId && p.CompanyId == processingProgressModel.CompanyId.ToString()).ToList();
                            if (ProcessingProgressListNew.Count > 0)
                            {
                                return(new NewErrorModel()
                                {
                                    error = new Error(1, string.Format("保存失败,系统中已存在流水号 {0} 的数据", processingProgresse.TaskId), "")
                                    {
                                    },
                                });
                            }
                            processingProgresse.CompanyId = processingProgressModel.CompanyId.ToString();
                            Roles roles = dDContext.Roles.Where(r => r.RoleName == "生产加工进度分配人").FirstOrDefault();
                            //推送钉钉消息给设计人员和部门负责人(胡工)
                            DingTalkServersController dingTalkServersController = new DingTalkServersController();
                            await dingTalkServersController.SendProcessingProgress(processingProgresse.DesignerId, 0, processingProgressModel.applyMan, processingProgresse.Bom
                                                                                   , processingProgresse.TaskId, processingProgresse.CompanyName, processingProgresse.SpeedOfProgress, processingProgresse.IsAlreadyRead, eappUrl);

                            await dingTalkServersController.SendProcessingProgress(roles.UserId, 0, processingProgressModel.applyMan, processingProgresse.Bom
                                                                                   , processingProgresse.TaskId, processingProgresse.CompanyName, processingProgresse.SpeedOfProgress, processingProgresse.IsAlreadyRead, eappUrl);

                            processingProgresse.CreateTime = DateTime.Now.ToString("yyyy-MM-dd");
                            ProcessingProgressList.Add(processingProgresse);
                        }
                        dDContext.ProcessingProgress.AddRange(ProcessingProgressList);
                    }
                    dDContext.SaveChanges();
                    return(new NewErrorModel()
                    {
                        error = new Error(0, string.Format("保存成功!共计{0}条数据 ", processingProgressModel.processingProgresses.Count), "")
                        {
                        },
                    });
                }
                else  //华数
                {
                    DDContext   dDContext   = new DDContext();
                    DDContextHs dDContextHs = new DDContextHs();
                    string      eappUrl     = string.Format("eapp://page/start/productionMonitoring/productionMonitoring?taskid={0}&companyId={1}", processingProgressModel.processingProgresses[0].TaskId, processingProgressModel.CompanyId);
                    if (dDContext.Roles.Where(r => r.RoleName == "生产加工进度发起人" && r.UserId == processingProgressModel.applyManId).ToList().Count == 0)
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, "没有权限上传!", "")
                            {
                            },
                        });
                    }

                    List <Models.DingModelsHs.ProjectInfo> projectInfos = dDContextHs.ProjectInfo.ToList();
                    if (processingProgressModel.IsExcelUpload)  //操作界面添加
                    {
                        foreach (var processingProgresse in processingProgressModel.processingProgresses)
                        {
                            //校对数据
                            if (!string.IsNullOrEmpty(processingProgresse.TaskId))
                            {
                                processingProgresse.CompanyId = processingProgressModel.CompanyId.ToString();
                                List <ProcessingProgress> ProcessingProgressList = dDContext.ProcessingProgress.Where(p => p.TaskId == processingProgresse.TaskId).ToList();
                                if (ProcessingProgressList.Count > 0)
                                {
                                    return(new NewErrorModel()
                                    {
                                        error = new Error(1, string.Format("保存失败,系统中已存在流水号 {0} 的数据", processingProgresse.TaskId), "")
                                        {
                                        },
                                    });
                                }
                                if (projectInfos.Where(p => p.ProjectId == processingProgresse.ProjectId &&
                                                       p.ProjectName == processingProgresse.ProjectName).ToList().Count == 0)
                                {
                                    return(new NewErrorModel()
                                    {
                                        error = new Error(1, string.Format("保存失败,项目Id {0} 、 项目名 {1} 与系统中的数据不吻合!", processingProgresse.ProjectId, processingProgresse.ProjectName), "")
                                        {
                                        },
                                    });
                                }
                                else
                                {
                                    //华数不校对项目类别
                                    //  if (projectInfos.Where(p => p.ProjectId == processingProgresse.ProjectId &&
                                    //p.ProjectName == p.ProjectName && p.ProjectType == processingProgresse.ProjectType
                                    //&& p.ProjectSmallType == processingProgresse.ProjectSmallType).ToList().Count == 0)
                                    //  {
                                    //      return new NewErrorModel()
                                    //      {
                                    //          error = new Error(1, string.Format("保存失败,项目Id {0} 、 项目名 {1} 与系统中的大类、小类不吻合!", processingProgresse.ProjectId, processingProgresse.ProjectName), "") { },
                                    //      };
                                    //  }
                                    //  else
                                    //  {
                                    List <Models.DingModelsHs.Tasks> tasksDesigner          = dDContextHs.Tasks.Where(t => t.ApplyMan.Contains(processingProgresse.Designer)).ToList();
                                    List <Models.DingModelsHs.Tasks> tasksNoteTaker         = dDContextHs.Tasks.Where(t => t.ApplyMan.Contains(processingProgresse.NoteTaker)).ToList();
                                    List <Models.DingModelsHs.Tasks> tasksHeadOfDepartments = dDContextHs.Tasks.Where(t => t.ApplyMan.Contains(processingProgresse.HeadOfDepartments)).ToList();
                                    List <Models.DingModelsHs.Tasks> tasksTabulator         = dDContextHs.Tasks.Where(t => t.ApplyMan.Contains(processingProgresse.Tabulator)).ToList();
                                    if (tasksDesigner.Count == 0 || tasksNoteTaker.Count == 0 || tasksHeadOfDepartments.Count == 0 || tasksTabulator.Count == 0)
                                    {
                                        if (tasksTabulator.Count == 0)
                                        {
                                            return(new NewErrorModel()
                                            {
                                                error = new Error(1, string.Format("保存失败,系统中找不到:制表人 {0} 的Id   !", processingProgresse.Tabulator), "")
                                                {
                                                },
                                            });
                                        }
                                        if (tasksDesigner.Count == 0)
                                        {
                                            return(new NewErrorModel()
                                            {
                                                error = new Error(1, string.Format("保存失败,系统中找不到:设计员 {0} 的Id   !", processingProgresse.NoteTaker), "")
                                                {
                                                },
                                            });
                                        }
                                        if (tasksNoteTaker.Count == 0)
                                        {
                                            return(new NewErrorModel()
                                            {
                                                error = new Error(1, string.Format("保存失败,系统中找不到:记录员 {0} 的Id   !", processingProgresse.Designer), "")
                                                {
                                                },
                                            });
                                        }
                                        if (tasksHeadOfDepartments.Count == 0)
                                        {
                                            return(new NewErrorModel()
                                            {
                                                error = new Error(1, string.Format("保存失败,系统中找不到:部门负责人 {0} 的Id   !", processingProgresse.HeadOfDepartments), "")
                                                {
                                                },
                                            });
                                        }
                                    }
                                    else
                                    {
                                        processingProgresse.TabulatorId         = tasksTabulator[0].ApplyManId;
                                        processingProgresse.DesignerId          = tasksDesigner[0].ApplyManId;
                                        processingProgresse.NoteTakerId         = tasksNoteTaker[0].ApplyManId;
                                        processingProgresse.HeadOfDepartmentsId = tasksHeadOfDepartments[0].ApplyManId;
                                        processingProgresse.CreateTime          = DateTime.Now.ToString("yyyy-MM-dd");
                                        dDContext.ProcessingProgress.Add(processingProgresse);
                                    }
                                }
                            }
                        }
                    }
                    if (!processingProgressModel.IsExcelUpload)  //操作界面添加
                    {
                        List <ProcessingProgress> ProcessingProgressList = new List <ProcessingProgress>();
                        foreach (var processingProgresse in processingProgressModel.processingProgresses)
                        {
                            List <ProcessingProgress> ProcessingProgressListNew = dDContext.ProcessingProgress.Where(p => p.TaskId == processingProgresse.TaskId && p.CompanyId == processingProgressModel.CompanyId.ToString()).ToList();
                            if (ProcessingProgressListNew.Count > 0)
                            {
                                return(new NewErrorModel()
                                {
                                    error = new Error(1, string.Format("保存失败,系统中已存在流水号 {0} 的数据", processingProgresse.TaskId), "")
                                    {
                                    },
                                });
                            }
                            processingProgresse.CompanyId = processingProgressModel.CompanyId.ToString();
                            Roles roles = dDContext.Roles.Where(r => r.RoleName == "生产加工进度分配人").FirstOrDefault();
                            //推送钉钉消息给设计人员和部门负责人(胡工)
                            DingTalkServersController dingTalkServersController = new DingTalkServersController();
                            await dingTalkServersController.SendProcessingProgress(processingProgresse.DesignerId, 0, processingProgressModel.applyMan, processingProgresse.Bom
                                                                                   , processingProgresse.TaskId, processingProgresse.CompanyName, processingProgresse.SpeedOfProgress, processingProgresse.IsAlreadyRead, eappUrl);

                            await dingTalkServersController.SendProcessingProgress(roles.UserId, 0, processingProgressModel.applyMan, processingProgresse.Bom
                                                                                   , processingProgresse.TaskId, processingProgresse.CompanyName, processingProgresse.SpeedOfProgress, processingProgresse.IsAlreadyRead, eappUrl);

                            processingProgresse.CreateTime = DateTime.Now.ToString("yyyy-MM-dd");
                            ProcessingProgressList.Add(processingProgresse);
                        }
                        dDContext.ProcessingProgress.AddRange(ProcessingProgressList);
                    }
                    dDContext.SaveChanges();
                    return(new NewErrorModel()
                    {
                        error = new Error(0, string.Format("保存成功!共计{0}条数据 ", processingProgressModel.processingProgresses.Count), "")
                        {
                        },
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#17
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>();

                        int iCount = 12;  //设置每个文件夹最大文件数量
                        int i      = 0;
                        foreach (var item in ListPath)
                        {
                            if (ListAbPath.Count < iCount)
                            {
                                ListAbPath.Add(HttpContext.Current.Server.MapPath(item));
                            }
                            if (ListAbPath.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(ListAbPath, 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);

                                ListAbPath.Clear();
                            }
                        }
                    }

                    return(new NewErrorModel()
                    {
                        error = new Error(0, "已推送至钉钉!", "")
                        {
                        },
                    });
                }
            }
            catch (Exception ex)
            {
                return(new NewErrorModel()
                {
                    error = new Error(1, ex.Message, "")
                    {
                    },
                });
            }
        }
示例#18
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, "复制成功!", "")
                    {
                    },
                });
            }
        }
示例#19
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;
            }
        }
        public async Task <object> GetAllPDF(string taskId, string applyManId)
        {
            try
            {
                using (DDContext context = new DDContext())
                {
                    string strUrl        = "";
                    Tasks  tasksQuery    = context.Tasks.Where(t => t.TaskId.ToString() == taskId && t.NodeId == 0).FirstOrDefault();
                    string strFilePDFUrl = tasksQuery.FilePDFUrl;
                    string strFileUrl    = tasksQuery.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);

                        Dictionary <int, List <string> > keyValuePairs = CheckPathLength(ListPath);
                        int i = 0;
                        foreach (var item in keyValuePairs)
                        {
                            i++;
                            string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip",
                                                            AppDomain.CurrentDomain.BaseDirectory,
                                                            "流水号" + taskId + "图纸打包第" + i + "份" +
                                                            DateTime.Now.ToString("yyyyMMddHHmmss"));
                            //文件压缩打包
                            IonicHelper.CompressMulti(item.Value, SavePath, false);
                            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);
                        }
                    }

                    return(new NewErrorModel()
                    {
                        error = new Error(0, "已推送至钉钉!", "")
                        {
                        },
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#21
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;
            }
        }
        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
                }));
            }
        }
示例#23
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 <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;
            }
        }
示例#25
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;
            }
        }
示例#26
0
        public async Task <NewErrorModel> GetExcelReport(string taskId, string applyManId)
        {
            try
            {
                //EFHelper<Purchase> eFHelper = new EFHelper<Purchase>();
                //System.Linq.Expressions.Expression<Func<Purchase, bool>> where = p => p.TaskId == taskId;
                //List<Purchase> purchases = eFHelper.GetListBy(where);
                using (DDContext context = new DDContext())
                {
                    var SelectPurchaseList = from p in context.Purchase
                                             where p.TaskId == taskId
                                             select new
                    {
                        p.TaskId,
                        p.DrawingNo,
                        p.Name,
                        p.Count,
                        p.MaterialScience,
                        p.Unit,
                        p.SingleWeight,
                        p.AllWeight,
                        p.Sorts,
                        p.NeedTime,
                        p.Mark
                    };

                    DataTable dtpurchaseTables = DtLinqOperators.CopyToDataTable(SelectPurchaseList);
                    string    path             = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet/图纸BOM导出模板.xlsx");
                    string    time             = DateTime.Now.ToString("yyyyMMddHHmmss");
                    string    newPath          = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet") + "\\图纸BOM数据" + time + ".xlsx";
                    System.IO.File.Copy(path, newPath);
                    if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtpurchaseTables, 0, 1))
                    {
                        DingTalkServersController dingTalkServersController = new DingTalkServersController();
                        //上盯盘
                        var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/图纸BOM数据" + time + ".xlsx");

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

                        return(new NewErrorModel()
                        {
                            error = new Error(0, "已推送至钉钉!", "")
                            {
                            },
                        });
                    }
                    else
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, "文件有误!", "")
                            {
                            },
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <NewErrorModel> Print(string applyManId)
        {
            try
            {
                using (DDContext context = new DDContext())
                {
                    //项目管理员
                    bool IsProjectControl = context.Roles.Where(r => r.UserId == applyManId && r.RoleName == "项目管理员" && r.IsEnable == true).ToList().Count() > 0 ? true : false;
                    if (IsProjectControl)
                    {
                        List <ProjectInfo> projectInfos = context.ProjectInfo.ToList();
                        var Query = from p in projectInfos
                                    select new
                        {
                            p.ProjectName,
                            p.ProjectType,
                            p.ProjectSmallType,
                            p.ProjectState,
                            p.ApplyMan,
                            p.ApplyManId,
                            p.CompanyName,
                            p.CreateTime,
                            p.DeptName,
                            p.StartTime,
                            p.EndTime,
                            p.ProjectId,
                            p.ResponsibleMan,
                            p.ResponsibleManId,
                            p.FilePath,
                            p.IsEnable,
                            p.TeamMembers,
                            p.TeamMembersId,
                            p.CooperativeUnit
                        };
                        DataTable      dtReturn = new DataTable();
                        PropertyInfo[] oProps   = null;
                        foreach (var rec in Query)
                        {
                            if (oProps == null)
                            {
                                oProps = ((Type)rec.GetType()).GetProperties();
                                foreach (PropertyInfo pi in oProps)
                                {
                                    Type colType = pi.PropertyType; if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable <>)))
                                    {
                                        colType = colType.GetGenericArguments()[0];
                                    }
                                    dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
                                }
                            }
                            DataRow dr = dtReturn.NewRow(); foreach (PropertyInfo pi in oProps)
                            {
                                dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue(rec, null);
                            }
                            dtReturn.Rows.Add(dr);
                        }
                        string path    = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFile/Excel/Templet/项目数据统计模板.xlsx");
                        string time    = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string newPath = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFile/Excel/Templet") + "\\项目数据统计" + time + ".xlsx";
                        System.IO.File.Copy(path, newPath);
                        if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtReturn, 0, 1))
                        {
                            DingTalkServersController dingTalkServersController = new DingTalkServersController();
                            //上盯盘
                            var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/项目数据统计" + time + ".xlsx");

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

                            return(new NewErrorModel()
                            {
                                error = new Error(0, "已推送至钉钉", "")
                                {
                                },
                            });
                        }
                        else
                        {
                            return(new NewErrorModel()
                            {
                                error = new Error(1, "Excel模板有误!", "")
                                {
                                },
                            });
                        }
                    }
                    else
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, "没有操作权限!", "")
                            {
                            },
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }