public void SubmitWorkItemForm(ProfileSanitationCarWorkItemEntity entity, string keyValue) { if (!string.IsNullOrEmpty(keyValue)) { entity.Modify(keyValue); workItemService.Update(entity); } else { entity.Create(); workItemService.Insert(entity); } }
/// <summary> /// 单条 /// 批量导入 /// </summary> /// <param name="entity"></param> /// <param name="skipWhere"></param> /// <param name="coverWhere"></param> public void BatchCarWorkItemSubmitFrom(ProfileSanitationCarWorkItemEntity entity, Func <ProfileSanitationCarWorkItemEntity, ProfileSanitationCarWorkItemEntity, bool> skipWhere, Func <ProfileSanitationCarWorkItemEntity, ProfileSanitationCarWorkItemEntity, bool> coverWhere) { if (skipWhere != null) { Func <ProfileSanitationCarWorkItemEntity, bool> dbskipWhere = db => skipWhere(db, entity); var dbSkipQuery = this.workItemService.dbcontext.Set <ProfileSanitationCarWorkItemEntity>().Where(dbskipWhere); if (dbSkipQuery.Count() > 0) { return; } } if (coverWhere != null) { Func <ProfileSanitationCarWorkItemEntity, bool> dbCoverWhere = db => coverWhere(db, entity); var dbCoverQuery = this.workItemService.dbcontext.Set <ProfileSanitationCarWorkItemEntity>().Where(dbCoverWhere); if (dbCoverQuery.Count() > 0) { var dbEntity = dbCoverQuery.FirstOrDefault(); dbEntity.Note = entity.Note; dbEntity.Subscript = entity.Subscript; dbEntity.WorkAddress = entity.WorkAddress; dbEntity.WorkName = entity.WorkName; dbEntity.WorkShift = entity.WorkShift; dbEntity.WorkTime = entity.WorkTime; dbEntity.Modify(dbEntity.F_Id); this.workItemService.Update(dbEntity); return; } } entity.Create(); this.workItemService.Insert(entity); }
public void SubmitForm(ProfileSanitationCarEntity entity, string keyValue, ProfileCarWorkItemContracts[] works) { using (var db = new RepositoryBase().BeginTrans()) { if (!string.IsNullOrEmpty(keyValue))//修改 { db.Update <ProfileSanitationCarEntity>(entity); #region 查看有没有要删除项 var workItemDbIds = db.IQueryable <ProfileSanitationCarWorkItemEntity>().Where(d => d.WorkShift == entity.WorkShift).Select(d => d.F_Id).ToArray(); var workItemIds = works.Select(d => d.id).ToArray(); string[] delworkItems = workItemDbIds.Except(workItemIds).ToArray(); foreach (var item in delworkItems) { db.Delete <ProfileSanitationCarWorkItemEntity>(db.FindEntity <ProfileSanitationCarWorkItemEntity>(item)); } #endregion ProfileSanitationCarWorkItemEntity workEntity = null; foreach (var item in works) { workEntity = new ProfileSanitationCarWorkItemEntity(); workEntity.WorkShift = entity.WorkShift; workEntity.Subscript = item.subscript; workEntity.WorkTime = item.time; workEntity.WorkName = item.rinseName; workEntity.WorkAddress = item.rinseAddress; workEntity.Note = item.Note; if (string.IsNullOrEmpty(item.id) || item.id.Equals("-1")) { workEntity.Create(); db.Insert <ProfileSanitationCarWorkItemEntity>(workEntity); } else { workEntity.F_Id = item.id; workEntity.Modify(item.id); db.Update <ProfileSanitationCarWorkItemEntity>(workEntity); } } } else { db.Insert <ProfileSanitationCarEntity>(entity); ProfileSanitationCarWorkItemEntity workEntity = null; foreach (var item in works) { workEntity = new ProfileSanitationCarWorkItemEntity(); workEntity.WorkShift = entity.WorkShift; workEntity.Subscript = item.subscript; workEntity.WorkTime = item.time; workEntity.WorkName = item.rinseName; workEntity.WorkAddress = item.rinseAddress; workEntity.Note = item.Note; workEntity.Create(); db.Insert <ProfileSanitationCarWorkItemEntity>(workEntity); } } db.Commit(); } }
public ActionResult SummitCarWorkItemImport(string CityId, string CountyId, string projectId, int isRename = 1) { projectId = "dd1bbf6b-bcea-4cad-851b-1be4adf71860"; string path = @"C:\Users\zps\Desktop\聚力环境测评系统样版\聚力环境测评系统样版\"; string fileName = "1班次作业明细.xls"; #region 导出 if (FileHelper.IsExistFile(Path.Combine(path, fileName))) { using (ExcelHelper exHelp = new ExcelHelper(Path.Combine(path, fileName))) { var datatable = exHelp.ExcelToDataTable(fileName, true); ProfileSanitationCarWorkItemEntity[] models = new ProfileSanitationCarWorkItemEntity[datatable.Rows.Count]; ProfileSanitationCarWorkItemEntity model; for (int i = 0; i < datatable.Rows.Count; i++) { try { var workShift = datatable.Rows[i]["作业班次"].ToString(); var xh = datatable.Rows[i]["序号"].ToString(); var workTime = datatable.Rows[i]["作业时间"].ToString(); var workName = datatable.Rows[i]["作业点名称"].ToString(); var workAddress = datatable.Rows[i]["作业点地址"].ToString(); var workNode = datatable.Rows[i]["备注"].ToString(); model = new ProfileSanitationCarWorkItemEntity() { Note = workNode, WorkName = workName, WorkAddress = workAddress, WorkTime = workTime, WorkShift = workShift, Subscript = int.Parse(xh) }; models[i] = model; } catch { } } var thapp = new ProfileAmenitiesConstructionSiteApp(); foreach (var item in models) { try { if (item == null) { continue; } App.SubmitWorkItemForm(item, string.Empty); } catch { } } } } #endregion return(Success("ss")); }