public CResult <bool> InsertMaintainItem(WebMaintainItem model) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("model", model); if (string.IsNullOrEmpty(model.ProjectID)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { if (context.Project.Any(t => t.IsValid && t.ID == model.ProjectID) == false) { return(new CResult <bool>(false, ErrorCode.ProjectNotExist)); } if (context.MaintainItem.Any(t => t.Name.ToUpper() == model.Name.ToUpper() && t.ProjectID == model.ProjectID && t.IsValid)) { return(new CResult <bool>(false, ErrorCode.MaintainItemExist)); } var entity = new MaintainItem(); entity.CreateDate = DateTime.Now; entity.CreateUserID = model.CreateUserID; entity.ID = Guid.NewGuid().ToString(); entity.Name = model.Name; entity.IsValid = true; entity.Note = model.Note; entity.ProjectID = model.ProjectID; context.MaintainItem.Add(entity); return(context.Save()); } }
/// <summary> /// 设置维修项 /// </summary> /// <param name="maintainItem">维修项</param> public void SetMaintainItem(MaintainItem maintainItem) { MaintainItem = maintainItem; }
public CResult <bool> ImportMaintainItemFromExcel(HttpPostedFileBase file, string projectID, string operatorUserID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); if (string.IsNullOrEmpty(projectID) || string.IsNullOrEmpty(operatorUserID)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } var fileName = string.Format("{0}{1}", Guid.NewGuid().ToString(), Path.GetExtension(file.FileName)); var filePath = FileHelper.SaveFile(file, SystemInfo.TempFileFolder, fileName); if (string.IsNullOrEmpty(filePath)) { return(new CResult <bool>(false, ErrorCode.SystemError)); } var dataTable = ExcelHelper.ExcelToDataTable(filePath, 0); if (dataTable.Rows.Count == 0) { return(new CResult <bool>(false, ErrorCode.FileContainNoData)); } var WebMaintainItemList = new List <WebMaintainItem>(); foreach (DataRow row in dataTable.Rows) { int i = 0; var WebMaintainItem = new WebMaintainItem(); WebMaintainItem.Name = row[i++].ToString(); WebMaintainItem.Note = row[i++].ToString(); WebMaintainItemList.Add(WebMaintainItem); } var nameList = WebMaintainItemList.Select(t => t.Name).Distinct().ToList(); if (nameList.Count < WebMaintainItemList.Count) { return(new CResult <bool>(false, ErrorCode.MaintainItemExist)); } using (var context = new DeviceMgmtEntities()) { if (context.Project.Any(t => t.IsValid && t.ID == projectID) == false) { return(new CResult <bool>(false, ErrorCode.ProjectNotExist)); } if (context.User.Any(t => t.IsValid && t.UserID == operatorUserID) == false) { return(new CResult <bool>(false, ErrorCode.UserNotExist)); } if (context.MaintainItem.Any(t => t.ProjectID == projectID && t.IsValid && nameList.Contains(t.Name))) { return(new CResult <bool>(false, ErrorCode.MaintainItemExist)); } var currentTime = DateTime.Now; foreach (var WebMaintainItem in WebMaintainItemList) { var item = new MaintainItem() { CreateDate = currentTime, CreateUserID = operatorUserID, ID = Guid.NewGuid().ToString(), IsValid = true, Name = WebMaintainItem.Name, Note = WebMaintainItem.Note, ProjectID = projectID, }; context.MaintainItem.Add(item); } LogHelper.Info("importList", WebMaintainItemList); return(context.Save()); } }