public object Ding(string taskId) { try { using (DDContext context = new DDContext()) { FlowInfoServer flowInfoServer = new FlowInfoServer(); if (flowInfoServer.GetTasksState(taskId) == "已完成") { return(new ErrorModel { errorCode = 0, errorMessage = "流程已完成" }); } else { Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == taskId && t.IsSend != true && t.State == 0).OrderBy(s => s.NodeId).First(); return(new { tasks.ApplyMan, tasks.ApplyManId }); } } } catch (Exception ex) { return(new ErrorModel { errorCode = 1, errorMessage = ex.Message }); } }
public NewErrorModel Ding(string taskId) { try { using (DDContext context = new DDContext()) { FlowInfoServer flowInfoServer = new FlowInfoServer(); if (flowInfoServer.GetTasksState(taskId) == "已完成") { return(new NewErrorModel() { error = new Error(0, "流程已完成!", "") { }, }); } else { Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == taskId && t.IsSend != true && t.State == 0).OrderBy(s => s.NodeId).FirstOrDefault(); return(new NewErrorModel() { data = tasks, error = new Error(0, "流程被退回!", "") { }, }); } } } catch (Exception ex) { throw ex; } }
public object GetMonthReport(string StartTime, string EndTime, string UserId) { try { using (DDContext context = new DDContext()) { //查询时间段内的数据 List <CarTable> carTables = context.CarTable.Where(c => c.StartTime > DateTime.Parse(StartTime) && c.EndTime < DateTime.Parse(EndTime)).ToList(); //更新实际行驶路程 foreach (CarTable carTable in carTables) { if (!string.IsNullOrEmpty(carTable.OccupyCarId)) { CarTable catTb = context.CarTable.Find(carTable.OccupyCarId); catTb.UseKilometres = (Int32.Parse(catTb.UseKilometres) - Int32.Parse(carTable.UseKilometres)).ToString(); context.Entry <CarTable>(catTb).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } //计算公里数 List <CarTable> carTableList = context.CarTable.ToList(); List <Tasks> tasksList = FlowInfoServer.ReturnUnFinishedTaskId("13"); //公车任务流 List <Tasks> taskList = new List <Tasks>(); List <Car> carList = context.Car.ToList(); foreach (Tasks tasks in tasksList) { if (tasks.NodeId == 0) { taskList.Add(tasks); } } var Quary = from t in taskList join c in carTableList on t.TaskId.ToString() equals c.TaskId join cars in carList on c.CarId equals cars.Id.ToString() select new { t.Dept, t.ApplyMan, c.StartTime, c.EndTime, cars.Name, c.MainContent, c.UseKilometres, cars.UnitPricePerKilometre, Price = Int32.Parse(c.UseKilometres) * cars.UnitPricePerKilometre }; return(JsonConvert.SerializeObject(Quary)); } } catch (Exception ex) { throw ex; } }
public object GetOfficeSuppliesTable(DateTime startTime, DateTime endTime) { try { using (DDContext context = new DDContext()) { List <Tasks> tasks = FlowInfoServer.ReturnUnFinishedTaskId("1"); List <OfficeModels> officeModeldList = new List <OfficeModels>(); foreach (var task in tasks) { if (task.NodeId == 0) { if (DateTime.Parse(task.ApplyTime) > startTime && DateTime.Parse(task.ApplyTime) < endTime) { officeModeldList.Add(new OfficeModels() { taskId = task.TaskId.ToString(), applyMan = task.ApplyMan, dept = task.Dept }); } } } List <OfficeSupplies> officeSupplies = context.OfficeSupplies.ToList(); var Quary = from t in officeModeldList join o in officeSupplies on t.taskId equals o.TaskId select new { t.taskId, t.applyMan, t.dept, o.CodeNo, o.Count, o.Unit, o.ExpectPrice, o.Id, o.Mark, o.Name, o.Price, o.Purpose, o.Standard, o.UrgentDate }; return(Quary); } } catch (Exception ex) { return(JsonConvert.SerializeObject(new ErrorModel { errorCode = 1, errorMessage = ex.Message })); } }
public NewErrorModel Query(string ProjectName, string ProjectType) { try { DDContext context = new DDContext(); List <Tasks> tasksList = FlowInfoServer.ReturnUnFinishedTaskId("6").Where(t => t.NodeId == 0 && t.ProjectName == ProjectName && t.ProjectType == ProjectType).ToList(); List <Purchase> PurchaseList = context.Purchase.ToList(); var Query = from t in tasksList join p in PurchaseList on t.TaskId.ToString() equals p.TaskId select new { OldId = p.Id, TaskId = p.TaskId, BomId = p.BomId, DrawingNo = p.DrawingNo, CodeNo = p.CodeNo, Name = p.Name, Count = p.Count, MaterialScience = p.MaterialScience, Unit = p.Unit, Brand = p.Brand, Sorts = p.Sorts, Mark = p.Mark, IsDown = p.IsDown, SingleWeight = p.SingleWeight, AllWeight = p.AllWeight, NeedTime = p.NeedTime, ChangeType = p.ChangeType, }; return(new NewErrorModel() { data = Query, error = new Error(0, "读取成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(1, ex.Message, "") { }, }); } }
public NewErrorModel ReadFlowInfo(string projectId) { try { DDContext context = new DDContext(); List <FlowModel> FlowModelList = new List <FlowModel>(); List <Flows> flowsList = context.Flows.Where(t => t.FlowName.Contains("采购") || t.FlowName.Contains("借入") || t.FlowName.Contains("知识产权") || t.FlowName.Contains("入库") || t.FlowName.Contains("领料")).ToList(); foreach (var flows in flowsList) { string FlowId = flows.FlowId.ToString(); string FlowName = flows.FlowName.ToString(); List <Tasks> tasksList = FlowInfoServer.ReturnUnFinishedTaskId(FlowId).Where(t => t.ProjectId == projectId).ToList(); List <Tasks> tasksListQuery = tasksList.Where(t => t.FlowId.ToString() == FlowId && t.NodeId == 0).ToList(); ProjectInfo createProject = context.ProjectInfo.Where(c => c.ProjectId == projectId).FirstOrDefault(); if (createProject != null) { foreach (var item in tasksListQuery) { FlowModelList.Add(new FlowModel() { Type = FlowName, ApplyMan = item.ApplyMan, ApplyManId = item.ApplyManId, ApplyTime = item.ApplyTime, OldtaskId = item.TaskId.ToString() }); } } } return(new NewErrorModel() { data = FlowModelList, error = new Error(0, "读取成功!", "") { }, }); } catch (Exception ex) { throw ex; } }
public object Quary(string key) { try { DDContext context = new DDContext(); List <object> list = new List <object>(); List <Tasks> tasksList = FlowInfoServer.ReturnUnFinishedTaskId("6").Where(t => t.NodeId == 0).ToList(); List <Tasks> tasksListNew = new List <Tasks>(); List <TasksState> tasksState = context.TasksState.ToList(); foreach (var item in tasksList) { if (tasksState.Where(t => t.TaskId == item.TaskId.ToString()).FirstOrDefault().State == "已完成") { tasksListNew.Add(item); } } var quaryList = context.Tasks.Where(t => (t.TaskId.ToString().Contains(key) || t.ProjectName.Contains(key) || t.Title.Contains(key) || t.ApplyMan.Contains(key)) && t.NodeId == 0 && t.FlowId == 6).OrderBy(t => t.TaskId).Select(t => new TasksPurcahse { Id = t.Id, TaskId = t.TaskId, ApplyMan = t.ApplyMan, ApplyManId = t.ApplyManId, ApplyTime = t.ApplyTime, Dept = t.Dept, FilePDFUrl = t.FilePDFUrl, FileUrl = t.FileUrl, FlowId = t.FlowId, ImageUrl = t.ImageUrl, IsBacked = t.IsBacked, IsEnable = t.IsEnable, IsPost = t.IsPost, IsSend = t.IsSend, MediaId = t.MediaId, MediaIdPDF = t.MediaIdPDF, NodeId = t.NodeId, OldFilePDFUrl = t.OldFilePDFUrl, OldFileUrl = t.OldFileUrl, OldImageUrl = t.OldImageUrl, PdfState = t.PdfState, ProjectId = t.ProjectId, ProjectName = t.ProjectName, Title = t.Title, PurchaseList = context.Purchase.Where(p => p.TaskId == t.TaskId.ToString()).ToList() }); foreach (var item in quaryList) { foreach (var tasks in tasksListNew) { if (item.TaskId == tasks.TaskId) { list.Add(item); } } } return(new NewErrorModel() { data = list, error = new Error(0, "复制成功!", "") { }, }); } catch (Exception ex) { throw ex; } }
public NewErrorModel ReadDefault(string projectId) { try { DDContext context = new DDContext(); ProjectInfo projectInfo = context.ProjectInfo.Where(p => p.ProjectId == projectId).FirstOrDefault(); if (projectInfo != null) { if (projectInfo.ProjectState != "在研") { return(new NewErrorModel() { error = new Error(1, "只有在研项目才能发起!", "") { }, }); } } //立项数据(附件) string FlowId = context.Flows.Where(t => t.FlowName == "立项申请").First().FlowId.ToString(); List <Tasks> tasksList = FlowInfoServer.ReturnUnFinishedTaskId(FlowId); List <Tasks> tasksListQuery = tasksList.Where(t => t.FlowId.ToString() == FlowId && t.NodeId == 0).ToList(); CreateProject createProject = context.CreateProject.Where(c => c.ProjectId == projectId).FirstOrDefault(); if (createProject != null) { Tasks tasks = tasksListQuery.Where(t => t.TaskId.ToString() == createProject.TaskId).FirstOrDefault(); if (tasks == null) { return(new NewErrorModel() { data = null, error = new Error(1, "该流程没有走过立项申请的数据!", "") { }, }); } FileUrlModel fileUrlModel = new FileUrlModel() { fileName = tasks.OldFileUrl, fileUrl = tasks.FileUrl, mediaId = tasks.MediaId, }; return(new NewErrorModel() { data = fileUrlModel, error = new Error(0, "读取成功!", "") { }, }); } else { return(new NewErrorModel() { data = "", error = new Error(0, "暂无数据!", "") { }, }); } } 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 object ReadDefault(string ApplyManId, string TaskId) { try { //Dictionary<string, string> keyValuePairs = new Dictionary<string, string>(); //keyValuePairs.Add("FBillNo", "88"); //string result = HttpPost("http://wuliao5222.55555.io:35705/api/GoDown/GetGodownInfoByFBillNo", // keyValuePairs); HttpWebResponse httpWebResponse = CreateGetHttpResponse("http://wuliao5222.55555.io:35705/api/Pick/GetAll", 5000, null, null); StreamReader reader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8); string content = reader.ReadToEnd(); NewErrorModel newErrorModel = new NewErrorModel() { data = new List <GodownModel>() { }, }; newErrorModel = JsonConvert.DeserializeObject <NewErrorModel>(content); using (DDContext context = new DDContext()) { List <GodownModel> goDowns = JsonConvert.DeserializeObject <List <GodownModel> >(newErrorModel.data.ToString());; Flows flows = context.Flows.Where(f => f.FlowName.Contains("采购")).First(); List <Tasks> tasks = FlowInfoServer.ReturnUnFinishedTaskId(flows.FlowId.ToString()); List <Tasks> taskQuery = tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 1).ToList(); List <PurchaseTable> PurchaseTables = new List <PurchaseTable>(); foreach (var task in taskQuery) { PurchaseTables.AddRange(context.PurchaseTable.Where(g => g.TaskId == task.TaskId.ToString())); } List <GodownModel> GodownModelList = new List <GodownModel>(); foreach (var goDown in goDowns) { foreach (var PurchaseTable in PurchaseTables) { if (goDown.fNumber == PurchaseTable.CodeNo) { GodownModelList.Add(goDown); } } } return(new NewErrorModel() { count = GodownModelList.Count, data = GodownModelList, error = new Error(0, "读取成功!", "") { }, }); } } catch (Exception ex) { return(new NewErrorModel() { error = new Error(1, ex.Message, "") { }, }); } }
public object GetOfficeSuppliesTable(DateTime startTime, DateTime endTime) { try { using (DDContext context = new DDContext()) { List <Tasks> tasks = FlowInfoServer.ReturnUnFinishedTaskId("1").Where(t => t.NodeId == 0).ToList(); List <Tasks> tasksSucced = new List <Tasks>(); FlowInfoServer flowInfoServer = new FlowInfoServer(); foreach (var item in tasks) { if (flowInfoServer.GetTasksState(item.TaskId.ToString()) == "已完成") { tasksSucced.Add(item); } } List <OfficeModels> officeModeldList = new List <OfficeModels>(); foreach (var task in tasksSucced) { //if (task.NodeId == 0) //{ if (DateTime.Parse(task.ApplyTime) > startTime && DateTime.Parse(task.ApplyTime) < endTime) { officeModeldList.Add(new OfficeModels() { taskId = task.TaskId.ToString(), applyMan = task.ApplyMan, dept = task.Dept }); } //} } List <OfficeSupplies> officeSupplies = context.OfficeSupplies.Where(o => o.IsDelete != true).ToList(); var Quary = from t in officeModeldList join o in officeSupplies on t.taskId equals o.TaskId select new { t.taskId, t.applyMan, t.dept, o.CodeNo, o.Count, o.Unit, o.ExpectPrice, o.Id, o.Mark, o.Name, o.Price, o.Purpose, o.Standard, o.UrgentDate, }; return(Quary); } } 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; } }
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; } }