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> GetExcelReport(string taskId, string applyManId) { try { //EFHelper<Purchase> eFHelper = new EFHelper<Purchase>(); //System.Linq.Expressions.Expression<Func<Purchase, bool>> where = p => p.TaskId == taskId; //List<Purchase> purchases = eFHelper.GetListBy(where); using (DDContext context = new DDContext()) { var SelectPurchaseList = from p in context.Purchase where p.TaskId == taskId select new { p.TaskId, p.DrawingNo, p.Name, p.Count, p.MaterialScience, p.Unit, p.SingleWeight, p.AllWeight, p.Sorts, p.NeedTime, p.Mark }; DataTable dtpurchaseTables = DtLinqOperators.CopyToDataTable(SelectPurchaseList); string path = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet/图纸BOM导出模板.xlsx"); string time = DateTime.Now.ToString("yyyyMMddHHmmss"); string newPath = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet") + "\\图纸BOM数据" + time + ".xlsx"; System.IO.File.Copy(path, newPath); if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtpurchaseTables, 0, 1)) { DingTalkServersController dingTalkServersController = new DingTalkServersController(); //上盯盘 var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/图纸BOM数据" + time + ".xlsx"); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = applyManId; var result = await dingTalkServersController.SendFileMessage(fileSendModel); return(new NewErrorModel() { error = new Error(0, "已推送至钉钉!", "") { }, }); } else { return(new NewErrorModel() { error = new Error(1, "文件有误!", "") { }, }); } } } catch (Exception ex) { throw ex; } }
public async Task <object> 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) { }, }); } }
public async Task <NewErrorModel> PrintsProjectFunding(List <ProjectFunding> items, string userId, string templetName, string fileName, int column, int row, string copyPath = "", string sheetName = "Sheet1") { if (items == null) { return(new NewErrorModel() { error = new Error(0, "暂无数据", "") { }, }); } DataTable dtpurchaseTables = ClassChangeHelper.ToDataTable(items, new List <string>() { "Id", "TaskId" }); string path = HttpContext.Current.Server.MapPath(string.Format("~/UploadFile/Excel/Templet/{0}.xlsx", templetName)); string time = DateTime.Now.ToString("yyyyMMddHHmmss"); string newPath = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet") + "\\" + fileName + time + ".xlsx"; File.Copy(path, newPath); if (copyPath == "") { if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtpurchaseTables, column, row)) { DingTalkServersController dingTalkServersController = new DingTalkServersController(); //上盯盘 var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/" + fileName + time + ".xlsx"); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = userId; var result = await dingTalkServersController.SendFileMessage(fileSendModel); //删除文件 File.Delete(newPath); return(new NewErrorModel() { error = new Error(0, result, "") { }, }); } else { return(new NewErrorModel() { error = new Error(1, "文件有误", "") { }, }); } } else { ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtpurchaseTables, column, row); string pathTest = Path.GetDirectoryName(copyPath); if (!Directory.Exists(pathTest)) { Directory.CreateDirectory(pathTest); } File.Copy(newPath, copyPath, true); return(new NewErrorModel() { error = new Error(0, "复制成功!", "") { }, }); } }
public async Task <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; } }
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; } }
public async Task <NewErrorModel> PrintExcel(string taskId, string UserId) { try { using (DDContext context = new DDContext()) { List <PurchaseTable> purchaseTables = context.PurchaseTable.Where(p => p.TaskId == taskId).ToList(); //DataTable dtpurchaseTables = ClassChangeHelper.ToDataTable(purchaseTables); var SelectPurchaseList = from p in purchaseTables select new { p.Id, p.TaskId, p.CodeNo, p.Name, Type = p.Standard, p.Unit, p.Count, p.Price, p.Purpose, p.UrgentDate, p.Mark, p.SendPosition, p.PurchaseMan, p.purchaseType }; DataTable dtpurchaseTables = DtLinqOperators.CopyToDataTable(SelectPurchaseList); string path = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet/采购导出模板.xlsx"); string time = DateTime.Now.ToString("yyyyMMddHHmmss"); string newPath = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet") + "\\采购单" + time + ".xlsx"; File.Copy(path, newPath); if (ExcelHelperByNPOI.UpdateExcel(newPath, "Sheet1", dtpurchaseTables, 0, 1)) { DingTalkServersController dingTalkServersController = new DingTalkServersController(); //上盯盘 var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/采购单" + time + ".xlsx"); //推送用户 FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia); fileSendModel.UserId = UserId; var result = await dingTalkServersController.SendFileMessage(fileSendModel); return(new NewErrorModel() { error = new Error(0, result, "Excel已推送至您的钉钉") { }, }); } else { return(new NewErrorModel() { error = new Error(1, "文件有误", "") { }, }); } } } catch (Exception ex) { return(new NewErrorModel() { error = new Error(2, ex.Message, "") { }, }); } }
public async Task <NewErrorModel> 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> 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; } }