コード例 #1
0
 public bool Create(ref ValidationErrors errors, SysModuleOperateModel model)
 {
     try
     {
         SysModuleOperate entity = m_Rep.GetById(model.Id);
         if (entity != null)
         {
             errors.Add(Suggestion.PrimaryRepeat);
             return false;
         }
         entity = new SysModuleOperate();
         entity.Id = model.Id;
         entity.Name = model.Name;
         entity.KeyCode = model.KeyCode;
         entity.ModuleId = model.ModuleId;
         entity.IsValid = model.IsValid;
         entity.Sort = model.Sort;
         if (m_Rep.Create(entity) == 1)
         {
             return true;
         }
         else
         {
             errors.Add(Suggestion.InsertFail);
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
コード例 #2
0
        void ValidateNeedsLabels(Issue issue, ValidationErrors validationErrors, Repository repository)
        {
            var lastActivityOnIssue = issue.UpdatedAt; //todo: does this include comments?

            if (issue.Labels.Any(l => l.Name == "Type: Bug") && !issue.Labels.Any(l => l.Name.StartsWith("Needs:")))
            {
                if (lastActivityOnIssue < DateTime.UtcNow.AddDays(-3))
                {
                    validationErrors.Add(new ValidationError
                    {
                        Reason = "This bug doesn't seem to be triaged, use one of the `Needs: X` labels to remember what the next steps are",
                        Issue = issue,
                        Repository = repository
                    });
                }

                return;
            }

            if (issue.Labels.Any(l => l.Name == "Needs: Triage") && lastActivityOnIssue < DateTime.UtcNow.AddDays(-3))
            {
                validationErrors.Add(new ValidationError
                {
                    Reason = "Issue needs triage but hasn't been updated for 3 days",
                    Issue = issue,
                    Repository = repository
                });
            }

            if (issue.Labels.Any(l => l.Name == "Needs: Reproduction") && lastActivityOnIssue < DateTime.UtcNow.AddDays(-7))
            {
                validationErrors.Add(new ValidationError
                {
                    Reason = "Issue needs a repro but hasn't been touched in the last 7 days",
                    Issue = issue,
                    Repository = repository
                });
            }

            if (issue.Labels.Any(l => l.Name == "Needs: Scheduling") && lastActivityOnIssue < DateTime.UtcNow.AddMonths(-3))
            {
                validationErrors.Add(new ValidationError
                {
                    Reason = "Issue needs scheduling but hasn't been touched in the last 3 months",
                    Issue = issue,
                    Repository = repository
                });
            }
        }
コード例 #3
0
ファイル: IsIntegerInRange.cs プロジェクト: aregsar/rapido
 public override void Validate(string value, ValidationErrors errors)
 {
     if (RequiredValidator.IsPresent(value))
     {
         int result = int.MaxValue;
         if (!int.TryParse(value, out result))
         {
             errors.Add(Key,ErrorMessage);
         }
         else
         {
             if (result > _maxValue || result < _minValue)
                 errors.Add(Key,ErrorMessageOutOfRange);
         }
     }
 }
コード例 #4
0
 public bool Delete(ref ValidationErrors errors, string id)
 {
     try
     {
         //检查是否有下级
         if (dbContainer.SysModules.AsQueryable().Where(a => a.SysModule2.Id == id).Count() > 0)
         {
             errors.Add("有下属关联,请先删除下属!");
             return false;
         }
         m_Rep.Delete(dbContainer, id);
         if (dbContainer.SaveChanges() > 0)
         {
             //清理无用的项
             dbContainer.P_Sys_ClearUnusedRightOperate();
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
コード例 #5
0
ファイル: RequiredValidator.cs プロジェクト: aregsar/rapido
 public override void Validate(string value, ValidationErrors errors)
 {
     if (!IsPresent(value))
     {
         errors.Add(Key,ErrorMessage);
     }
 }
コード例 #6
0
ファイル: SysMenuBLL.cs プロジェクト: vipsms/right
        /// <summary>
        /// 创建一个菜单
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个菜单</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysMenu entity)
        {
            int count = 1;

            foreach (string item in entity.SysOperationId.GetIdSort())
            {
                SysOperation sys = new SysOperation { Id = item };
                db.SysOperation.Attach(sys);
                entity.SysOperation.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                //创建后重置菜单编码
                List<int> flags = new List<int>();//层级
                GetMenus2(null, flags);
                db.SaveChanges();
                return true;
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return false;
        }
コード例 #7
0
 public void Validate(string password, string salt, string hashedPassword, ValidationErrors errors)
 {
     if (RequiredValidator.IsPresent(password))//dont check salt and hashedPassword IsPresent
     {
         if (!new StringHasher().ComputedHashUsingGivenSaltMatchesGivenHash( password, salt, hashedPassword))
             errors.Add(Key, ErrorMessage);                
     }
 }
コード例 #8
0
 public override void Validate(string value, ValidationErrors errors)
 {
     if (RequiredValidator.IsPresent(value))
     {
         if(value.Length > _maxLength || value.Length < _minLength)
             errors.Add(Key,ErrorMessage);
     }
 }
コード例 #9
0
ファイル: GuidStringValidator.cs プロジェクト: aregsar/rapido
        public override void Validate(string guidstring, ValidationErrors errors)
        {
            Guid guid;

            if (!Guid.TryParse(guidstring, out guid))
            {
                errors.Add(Key, ErrorMessage);
            }
        }
コード例 #10
0
ファイル: RegexValidator.cs プロジェクト: aregsar/rapido
        public override void Validate(string value, ValidationErrors errors)
        {
            if (RequiredValidator.IsPresent(value))
            {
                Regex regex = new Regex(_pattern);

                if (!regex.IsMatch(value.Trim()))
                    errors.Add(Key,ErrorMessage);
            }
        }
コード例 #11
0
 public bool Create(ref ValidationErrors errors, SysModuleModel model)
 {
     try
     {
         SysModule entity = m_Rep.GetById(model.Id);
         if (entity != null)
         {
             errors.Add(Suggestion.PrimaryRepeat);
             return false;
         }
         entity = new SysModule();
         entity.Id = model.Id;
         entity.Name = model.Name;
         entity.EnglishName = model.EnglishName;
         entity.ParentId = model.ParentId;
         entity.Url = model.Url;
         entity.Iconic = model.Iconic;
         entity.Sort = model.Sort;
         entity.Remark = model.Remark;
         entity.Enable = model.Enable;
         entity.CreatePerson = model.CreatePerson;
         entity.CreateTime = model.CreateTime;
         entity.IsLast = model.IsLast;
         if (m_Rep.Create(entity) == 1)
         {
             //分配给角色
             dbContainer.P_Sys_InsertSysRight();
             return true;
         }
         else
         {
             errors.Add(Suggestion.InsertFail);
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
コード例 #12
0
ファイル: SysDocumentTalkBLL.cs プロジェクト: vipsms/right
 /// <summary>
 /// 创建一个文档评论
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">一个文档评论</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, SysDocumentTalk entity)
 {
     try
     {
         repository.Create(entity);
         return true;
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return false;
 }
コード例 #13
0
 public bool Create(ref ValidationErrors errors, SysRoleModel model)
 {
     try
     {
         SysRole entity = m_Rep.GetById(model.Id);
         if (entity != null)
         {
             errors.Add(Suggestion.PrimaryRepeat);
             return false;
         }
         entity = new SysRole();
         entity.Id = model.Id;
         entity.Name = model.Name;
         entity.Description = model.Description;
         entity.CreateTime = model.CreateTime;
         entity.CreatePerson = model.CreatePerson;
         if (m_Rep.Create(entity) == 1)
         {
             //分配给角色
             dbContainer.P_Sys_InsertSysRight();
             //清理无用的项
             dbContainer.P_Sys_ClearUnusedRightOperate();
             return true;
         }
         else
         {
             errors.Add(Suggestion.InsertFail);
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
コード例 #14
0
        /// <summary>
        /// 创建一个实体
        /// </summary>
        /// <param name="errors">持久的错误信息</param>
        /// <param name="model">模型</param>
        /// <returns>是否成功</returns>
        public bool Create(ref ValidationErrors errors,SysSampleModel model)
        {
            try
            {
                SysSample entity = Rep.GetById(model.ID);
                if (entity != null)
                {
                    errors.Add("主键重复");
                    return false;
                }
                entity = new SysSample();
                entity.ID = model.ID;
                entity.Name = model.Name;
                entity.Age = model.Age;
                entity.Bir = model.Bir;
                entity.Photo = model.Photo;
                entity.Note = model.Note;
                entity.CreatTime = model.CreatTime;

                if (Rep.Create(entity) == 1)
                {
                    return true;
                }
                else
                {
                    errors.Add("插入失败");
                    return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }
コード例 #15
0
ファイル: CompareValidator.cs プロジェクト: aregsar/rapido
        public void Validate(string val, string compareVal, ValidationErrors errors)
        {
            if (RequiredValidator.IsPresent(val))//dont check compareVal IsPresent
            {
                if (!errors.ExistFor(Key))
                {
                    //only if there are no errors for val, do the compare
                    //so need to call this after running all validations of val to achieve this effect
                    if (val != compareVal)
                    {
                        errors.Add(Key,ErrorMessage);
                    }
                }
            }

        }
コード例 #16
0
 public bool Delete(ref ValidationErrors errors, string id)
 {
     try
     {
         if (m_Rep.Delete(id) == 1)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
コード例 #17
0
ファイル: SysDepartmentBLL.cs プロジェクト: vipsms/right
        /// <summary>
        /// 创建一个部门
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个部门</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysDepartment entity)
        {
            int count = 1;

            foreach (string item in entity.SysDocumentId.GetIdSort())
            {
                SysDocument sys = new SysDocument { Id = item };
                db.SysDocument.Attach(sys);
                entity.SysDocument.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return false;
        }
コード例 #18
0
        public bool ValidatePostalCode()
        {
            bool result = true;

            // check if required...
            if (CountryValidationRules.IsPostalCodeRequired &&
                string.IsNullOrEmpty(Customer.BillingProfile.Address.PostalCode))
            {
                result = false;
                ValidationErrors.Add("Postal code required for the country " + Customer.BillingProfile.Address.Country);
            }
            // if postal code format provided, then check if valid...
            if (!string.IsNullOrEmpty(CountryValidationRules.PostalCodeRegex))
            {
                if (!Regex.IsMatch(Customer.BillingProfile.Address.PostalCode,
                                   CountryValidationRules.PostalCodeRegex))
                {
                    result = false;
                    ValidationErrors.Add("Postal code invalid for the country " + Customer.BillingProfile.Address.Country);
                }
            }

            return(result);
        }
コード例 #19
0
        protected virtual void SetDataAnnotationAttributeErrors()
        {
            if (_isValidatedBefore)
            {
                return;
            }

            _isValidatedBefore = true;

            var modelState = ActionContext.Controller.As <Controller>().ModelState;

            if (modelState.IsValid)
            {
                return;
            }

            foreach (var state in modelState)
            {
                foreach (var error in state.Value.Errors)
                {
                    ValidationErrors.Add(new ValidationResult(error.ErrorMessage, new[] { state.Key }));
                }
            }
        }
コード例 #20
0
ファイル: SysNoticeBLL.cs プロジェクト: ioriwellings/rights-1
 /// <summary>
 ///  创建通知中心集合
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entitys">通知中心集合</param>
 /// <returns></returns>
 public bool EditCollection(ref ValidationErrors validationErrors, IQueryable <SysNotice> entitys)
 {
     try
     {
         if (entitys != null)
         {
             int count = entitys.Count();
             if (count == 1)
             {
                 return(this.Edit(ref validationErrors, entitys.FirstOrDefault()));
             }
             else if (count > 1)
             {
                 using (TransactionScope transactionScope = new TransactionScope())
                 {
                     repository.Edit(db, entitys);
                     if (count == repository.Save(db))
                     {
                         transactionScope.Complete();
                         return(true);
                     }
                     else
                     {
                         Transaction.Current.Rollback();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
コード例 #21
0
ファイル: StudentIEPModel.cs プロジェクト: thilehoffer/CSM
        public override void DoValidation()
        {
            if (!ScheduledDate.HasValue)
            {
                ValidationErrors.Add("Scheduled Date is required");
            }

            if (!ScheduledDateTime.HasValue)
            {
                ValidationErrors.Add("Scheduled Time is required");
            }


            if (DateOfMeetingTime.HasValue && !DateOfMeeting.HasValue)
            {
                ValidationErrors.Add("The date of the meeting is required because the time was set.");
            }

            if (IsCurrent && Data.Queries.DoesStudentHaveAnotherCurrentIEP(StudentId, StudentIEPId))
            {
                ValidationErrors.Add("This student already has current IEP. Uncheck Current IEP");
            }
            base.DoValidation();
        }
コード例 #22
0
 /// <summary>
 ///  创建计量标准装置检定/校准信息集合
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entitys">计量标准装置检定/校准信息集合</param>
 /// <returns></returns>
 public bool CreateCollection(ref ValidationErrors validationErrors, IQueryable <METERING_STANDARD_DEVICE_CHECK> entitys)
 {
     try
     {
         if (entitys != null)
         {
             int count = entitys.Count();
             if (count == 1)
             {
                 return(this.Create(ref validationErrors, entitys.FirstOrDefault()));
             }
             else if (count > 1)
             {
                 //using (TransactionScope transactionScope = new TransactionScope())
                 {
                     repository.Create(db, entitys);
                     if (count == repository.Save(db))
                     {
                         //transactionScope.Complete();
                         return(true);
                     }
                     else
                     {
                         //Transaction.Current.Rollback();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
コード例 #23
0
        /// <summary>
        /// Checks all properties for DataAnnotations attributes.
        /// </summary>
        protected virtual void SetDataAnnotationAttributeErrors(object validatingObject)
        {
            var properties = TypeDescriptor.GetProperties(validatingObject).Cast <PropertyDescriptor>();

            foreach (var property in properties)
            {
                var validationAttributes = property.Attributes.OfType <ValidationAttribute>().ToArray();

                if (validationAttributes.IsNullOrEmpty())
                {
                    continue;
                }

                var validationContext = new ValidationContext(validatingObject)
                {
                    DisplayName = property.DisplayName,
                    MemberName  = property.Name
                };

                foreach (var attribute in validationAttributes)
                {
                    var result = attribute.GetValidationResult(property.GetValue(validatingObject), validationContext);

                    if (result != null)
                    {
                        ValidationErrors.Add(result);
                    }
                }
            }

            if (validatingObject is IValidatableObject)
            {
                var results = (validatingObject as IValidatableObject).Validate(new ValidationContext(validatingObject));
                ValidationErrors.AddRange(results);
            }
        }
コード例 #24
0
 /// <summary>
 /// 创建一个AspNetRoles
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entity">一个AspNetRoles</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, AspNetRoles entity)
 {
     try
     {
         using (TransactionScope transactionScope = new TransactionScope())
         {
             if (Create(ref validationErrors, db, entity))
             {
                 transactionScope.Complete();
                 return(true);
             }
             else
             {
                 Transaction.Current.Rollback();
             }
         }
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
コード例 #25
0
        public virtual void Modify(ref ValidationErrors errors, Apps.Models.SCV.SHIPPING.SHIPPING_CONTAINER_HIS_MODEL model, params string[] updateProperties)
        {
            Apps.Models.SHIPPING_CONTAINER_HIS entity = m_Rep.GetById(model.ID);
            if (entity == null)
            {
                errors.Add(Resource.Disable);
                return;
            }
            if (updateProperties.Count() <= 0)
            {
                entity.ID = model.ID;
                entity.INTERNAL_CONTAINER_NUM = model.INTERNAL_CONTAINER_NUM;
                entity.CONTAINER_ID           = model.CONTAINER_ID;
                entity.WEIGHT              = model.WEIGHT;
                entity.WEIGHT_NUM          = model.WEIGHT_NUM;
                entity.UPDATE_USER         = model.UPDATE_USER;
                entity.UPDATE_DATATIME     = model.UPDATE_DATATIME;
                entity.UPDATE_USERNAME     = model.UPDATE_USERNAME;
                entity.UPDATE_USERTRUENAME = model.UPDATE_USERTRUENAME;
                entity.TRACKING_NUMBER     = model.TRACKING_NUMBER;
            }
            else
            {
                Type type  = typeof(Apps.Models.SCV.SHIPPING.SHIPPING_CONTAINER_HIS_MODEL);
                Type typeE = typeof(Apps.Models.SHIPPING_CONTAINER_HIS);
                foreach (var item in updateProperties)
                {
                    System.Reflection.PropertyInfo pi  = type.GetProperty(item);
                    System.Reflection.PropertyInfo piE = typeE.GetProperty(item);
                    piE.SetValue(entity, pi.GetValue(model), null);
                }
            }


            m_Rep.Modify(entity, updateProperties);
        }
コード例 #26
0
ファイル: SysMenuBLL.cs プロジェクト: vipsms/right
 /// <summary>
 /// 创建一个菜单
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entity">一个菜单</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, SysMenu entity)
 {
     try
     {
         using (TransactionScope transactionScope = new TransactionScope())
         {
             if (Create(ref validationErrors, db, entity))
             {
                 transactionScope.Complete();
                 return true;
             }
             else
             {
                 Transaction.Current.Rollback();
             }
         }
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return false;
 }
コード例 #27
0
ファイル: SysPersonBLL.cs プロジェクト: zhxy323/SHIYANSHI
 /// <summary>
 /// 编辑一个人员
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entity">一个人员</param>
 /// <returns>是否编辑成功</returns>
 public bool Edit(ref ValidationErrors validationErrors, SysPerson entity)
 {
     try
     {
         //using (TransactionScope transactionScope = new TransactionScope())
         {
             if (Edit(ref validationErrors, db, entity))
             {
                 //transactionScope.Complete();
                 return(true);
             }
             else
             {
                 //Transaction.Current.Rollback();
             }
         }
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
コード例 #28
0
 public virtual bool Delete(ref ValidationErrors errors, string[] deleteCollection)
 {
     try
     {
         if (deleteCollection != null)
         {
             if (m_Rep.Delete(deleteCollection) == deleteCollection.Length)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return(false);
     }
 }
コード例 #29
0
        private bool Validate()
        {
            var validationErrors = new ValidationErrors();

            if (string.IsNullOrEmpty(_model.SecretCode))
            {
                validationErrors.Add(string.Format(TextResources.Required_IsMandatory,
                                                   TextResources.AuthorizationCode));
            }
            else if (string.IsNullOrEmpty(_model.Password))
            {
                validationErrors.Add(string.Format(TextResources.Required_IsMandatory, TextResources.NewPassword));
            }
            else if (_model.Password.Trim().Length < 5)
            {
                validationErrors.Add(string.Format(TextResources.Validation_LengthMustBeMoreThan,
                                                   TextResources.Password, 5));
            }
            else if (_model.Password.Trim().Length > 100)
            {
                validationErrors.Add(string.Format(TextResources.Validation_LengthMustBeLessThan,
                                                   TextResources.Password, 100));
            }
            else if (string.IsNullOrEmpty(_model.ConfirmPassword))
            {
                validationErrors.Add(string.Format(TextResources.Required_IsMandatory,
                                                   TextResources.ConfirmPassword));
            }
            else if (_model.Password.Trim() != _model.ConfirmPassword.Trim())
            {
                validationErrors.Add(TextResources.MessagePasswordAndConfirmPasswordNotMatch);
            }

            if (validationErrors.Count() > 0)
            {
                _model.SetActivityResource(showError: true, errorMessage: validationErrors.Show(CommonConstants.SPACE));
            }
            return(validationErrors.Count() == 0);
        }
コード例 #30
0
        private bool Validate()
        {
            var validationErrors = new ValidationErrors();

            if (string.IsNullOrEmpty(EntryUsername?.Text))
            {
                validationErrors.Add(string.Format(TextResources.Required_IsMandatory, TextResources.Username));
            }
            else if (!Regex.IsMatch((EntryUsername?.Text ?? "").Trim(), CommonConstants.EMAIL_VALIDATION_REGEX))
            {
                validationErrors.Add(string.Format(TextResources.Validation_IsInvalid, TextResources.Username));
            }
            if (string.IsNullOrEmpty(EntryPassword?.Text))
            {
                validationErrors.Add(string.Format(TextResources.Required_IsMandatory, TextResources.Password));
            }
            else if (string.IsNullOrWhiteSpace(EntryPassword.Text))
            {
                validationErrors.Add(string.Format(TextResources.Validation_IsInvalid, TextResources.Password));
            }
            else if (EntryPassword.Text.Trim().Length < 5)
            {
                validationErrors.Add(string.Format(TextResources.Validation_LengthMustBeMoreThan,
                                                   TextResources.Password, 5));
            }
            else if (EntryPassword.Text.Trim().Length > 50)
            {
                validationErrors.Add(string.Format(TextResources.Validation_LengthMustBeLessThan,
                                                   TextResources.Password, 50));
            }
            if (validationErrors.Count() > 0)
            {
                _model.SetActivityResource(showError: true,
                                           errorMessage: validationErrors.Count() > 2
                        ? TextResources.Required_AllInputs
                        : validationErrors.Show(CommonConstants.SPACE));
            }
            return(validationErrors.Count() == 0);
        }
コード例 #31
0
        public virtual void Modify(ref ValidationErrors errors, Apps.Models.SCV.DOWNLOAD.DOWNLOAD_SHIPMENT_HEADER_FAILED_MODEL model, params string[] updateProperties)
        {
            Apps.Models.DOWNLOAD_SHIPMENT_HEADER_FAILED entity = m_Rep.GetById(model.INTERFACE_RECORD_ID);
            if (entity == null)
            {
                errors.Add(Resource.Disable);
                return;
            }
            if (updateProperties.Count() <= 0)
            {
                entity.INTERFACE_RECORD_ID   = model.INTERFACE_RECORD_ID;
                entity.INTERFACE_ACTION_CODE = model.INTERFACE_ACTION_CODE;
                entity.INTERFACE_CONDITION   = model.INTERFACE_CONDITION;
                entity.PROCESS_STAMP         = model.PROCESS_STAMP;
                entity.WAREHOUSE             = model.WAREHOUSE;
                entity.COMPANY                   = model.COMPANY;
                entity.INTERNAL_LOAD_NUM         = model.INTERNAL_LOAD_NUM;
                entity.SHIPMENT_ID               = model.SHIPMENT_ID;
                entity.ERP_ORDER                 = model.ERP_ORDER;
                entity.LEADING_STS               = model.LEADING_STS;
                entity.TRAILING_STS              = model.TRAILING_STS;
                entity.PROCESS_TYPE              = model.PROCESS_TYPE;
                entity.SHIPMENT_TYPE             = model.SHIPMENT_TYPE;
                entity.ROUTE                     = model.ROUTE;
                entity.SHIP_TO                   = model.SHIP_TO;
                entity.SHIP_TO_NAME              = model.SHIP_TO_NAME;
                entity.SHIP_TO_ADDRESS1          = model.SHIP_TO_ADDRESS1;
                entity.SHIP_TO_ADDRESS2          = model.SHIP_TO_ADDRESS2;
                entity.SHIP_TO_DISTRICT          = model.SHIP_TO_DISTRICT;
                entity.SHIP_TO_CITY              = model.SHIP_TO_CITY;
                entity.SHIP_TO_STATE             = model.SHIP_TO_STATE;
                entity.SHIP_TO_COUNTRY           = model.SHIP_TO_COUNTRY;
                entity.SHIP_TO_POSTAL_CODE       = model.SHIP_TO_POSTAL_CODE;
                entity.SHIP_TO_ATTENTION_TO      = model.SHIP_TO_ATTENTION_TO;
                entity.SHIP_TO_PHONE_NUM         = model.SHIP_TO_PHONE_NUM;
                entity.SHIP_TO_FAX_NUM           = model.SHIP_TO_FAX_NUM;
                entity.SHIP_TO_EMAIL_ADDRESS     = model.SHIP_TO_EMAIL_ADDRESS;
                entity.PRIORITY                  = model.PRIORITY;
                entity.USER_STAMP                = model.USER_STAMP;
                entity.DATE_TIME_STAMP           = model.DATE_TIME_STAMP;
                entity.REQUESTED_DELIVERY_DATE   = model.REQUESTED_DELIVERY_DATE;
                entity.REQUESTED_DELIVERY_TYPE   = model.REQUESTED_DELIVERY_TYPE;
                entity.SCHEDULED_SHIP_DATE       = model.SCHEDULED_SHIP_DATE;
                entity.ACTUAL_SHIP_DATE_TIME     = model.ACTUAL_SHIP_DATE_TIME;
                entity.ACTUAL_DELIVERY_DATE_TIME = model.ACTUAL_DELIVERY_DATE_TIME;
                entity.DELIVERY_NOTE             = model.DELIVERY_NOTE;
                entity.REJECTION_NOTE            = model.REJECTION_NOTE;
                entity.INTERNAL_WAVE_NUM         = model.INTERNAL_WAVE_NUM;
                entity.SHIP_DOCK                 = model.SHIP_DOCK;
                entity.ALLOCATE_COMPLETE         = model.ALLOCATE_COMPLETE;
                entity.TOTAL_QTY                 = model.TOTAL_QTY;
                entity.TOTAL_WEIGHT              = model.TOTAL_WEIGHT;
                entity.WEIGHT_UM                 = model.WEIGHT_UM;
                entity.TOTAL_VOLUME              = model.TOTAL_VOLUME;
                entity.VOLUME_UM                 = model.VOLUME_UM;
                entity.TOTAL_LINES               = model.TOTAL_LINES;
                entity.TOTAL_CONTAINERS          = model.TOTAL_CONTAINERS;
                entity.CARRIER                   = model.CARRIER;
                entity.CARRIER_SERVICE           = model.CARRIER_SERVICE;
                entity.USER_DEF1                 = model.USER_DEF1;
                entity.USER_DEF2                 = model.USER_DEF2;
                entity.USER_DEF3                 = model.USER_DEF3;
                entity.USER_DEF4                 = model.USER_DEF4;
                entity.USER_DEF5                 = model.USER_DEF5;
                entity.USER_DEF6                 = model.USER_DEF6;
                entity.USER_DEF7                 = model.USER_DEF7;
                entity.USER_DEF8                 = model.USER_DEF8;
                entity.BACK_ORDER_NUM            = model.BACK_ORDER_NUM;
                entity.LAST_WAVE_NUM             = model.LAST_WAVE_NUM;
                entity.GROUP_NUM                 = model.GROUP_NUM;
                entity.GROUP_INDEX               = model.GROUP_INDEX;
                entity.SIGN_VALUE                = model.SIGN_VALUE;
                entity.SHIPMENT_SUB_TYPE         = model.SHIPMENT_SUB_TYPE;
                entity.SHIPMENT_CATEGORY1        = model.SHIPMENT_CATEGORY1;
                entity.SHIPMENT_CATEGORY2        = model.SHIPMENT_CATEGORY2;
                entity.SHIPMENT_CATEGORY3        = model.SHIPMENT_CATEGORY3;
                entity.SHIPMENT_CATEGORY4        = model.SHIPMENT_CATEGORY4;
                entity.SHIPMENT_CATEGORY5        = model.SHIPMENT_CATEGORY5;
                entity.SHIPMENT_CATEGORY6        = model.SHIPMENT_CATEGORY6;
                entity.SHIPMENT_CATEGORY7        = model.SHIPMENT_CATEGORY7;
                entity.SHIPMENT_CATEGORY8        = model.SHIPMENT_CATEGORY8;
                entity.SHIP_TO_MOBILE            = model.SHIP_TO_MOBILE;
            }
            else
            {
                Type type  = typeof(Apps.Models.SCV.DOWNLOAD.DOWNLOAD_SHIPMENT_HEADER_FAILED_MODEL);
                Type typeE = typeof(Apps.Models.DOWNLOAD_SHIPMENT_HEADER_FAILED);
                foreach (var item in updateProperties)
                {
                    System.Reflection.PropertyInfo pi  = type.GetProperty(item);
                    System.Reflection.PropertyInfo piE = typeE.GetProperty(item);
                    piE.SetValue(entity, pi.GetValue(model), null);
                }
            }


            m_Rep.Modify(entity, updateProperties);
        }
コード例 #32
0
ファイル: SysMenuBLL.cs プロジェクト: zhxy323/SHIYANSHI
        /// <summary>
        /// 编辑一个菜单
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个菜单</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysMenu entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int count = 1;

            List <string> addSysOperationId    = new List <string>();
            List <string> deleteSysOperationId = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.SysOperationId.GetIdSort(), entity.SysOperationIdOld.GetIdSort(), ref addSysOperationId, ref deleteSysOperationId);
            List <SysOperation> listEntitySysOperation = new List <SysOperation>();

            if (deleteSysOperationId != null && deleteSysOperationId.Count() > 0)
            {
                foreach (var item in deleteSysOperationId)
                {
                    SysOperation sys = new SysOperation {
                        Id = item
                    };
                    listEntitySysOperation.Add(sys);
                    entity.SysOperation.Add(sys);
                }
            }

            SysMenu editEntity = repository.Edit(db, entity);


            if (addSysOperationId != null && addSysOperationId.Count() > 0)
            {
                foreach (var item in addSysOperationId)
                {
                    SysOperation sys = new SysOperation {
                        Id = item
                    };
                    db.SysOperation.Attach(sys);
                    editEntity.SysOperation.Add(sys);
                    count++;
                }
            }
            if (deleteSysOperationId != null && deleteSysOperationId.Count() > 0)
            {
                foreach (SysOperation item in listEntitySysOperation)
                {
                    editEntity.SysOperation.Remove(item);
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                //修改后重置菜单编码
                List <int> flags = new List <int>();//层级
                GetMenus2(null, flags);
                db.SaveChanges();
                return(true);
            }
            else
            {
                validationErrors.Add("编辑菜单出错了");
            }
            return(false);
        }
コード例 #33
0
        public bool ImportExcelData(string oper, string filePath, ref ValidationErrors errors)
        {
            bool rtn = true;

            var targetFile = new FileInfo(filePath);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(filePath);

            using (XLWorkbook wb = new XLWorkbook(filePath))
            {
                //第一个Sheet
                using (IXLWorksheet wws = wb.Worksheets.First())
                {
                    //对应列头
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.ReturnOrderDNum, "退货单号");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.HeadId, "头表ID");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.ReturnQty, "退货数量");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.Remark, "备注");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.PrintStaus, "打印状态");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.PrintDate, "打印日期");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.PrintMan, "打印人");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.ConfirmStatus, "确认状态");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.ConfirmMan, "确认人");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.ConfirmDate, "确认时间");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.Attr1, "");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.Attr2, "");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.Attr3, "");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.Attr4, "");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.Attr5, "");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.CreatePerson, "创建人");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.CreateTime, "创建时间");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.ModifyPerson, "修改人");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.ModifyTime, "修改时间");
                    excelFile.AddMapping <WMS_ReturnOrder_DModel>(x => x.BatchId, "");

                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_ReturnOrder_DModel>(0);

                    //开启事务
                    using (DBContainer db = new DBContainer())
                    {
                        var tran     = db.Database.BeginTransaction(); //开启事务
                        int rowIndex = 0;

                        //检查数据正确性
                        foreach (var row in excelContent)
                        {
                            rowIndex += 1;
                            string errorMessage = String.Empty;
                            var    model        = new WMS_ReturnOrder_DModel();
                            model.Id = row.Id;
                            model.ReturnOrderDNum = row.ReturnOrderDNum;
                            model.HeadId          = row.HeadId;
                            model.ReturnQty       = row.ReturnQty;
                            model.Remark          = row.Remark;
                            model.PrintStaus      = row.PrintStaus;
                            model.PrintDate       = row.PrintDate;
                            model.PrintMan        = row.PrintMan;
                            model.ConfirmStatus   = row.ConfirmStatus;
                            model.ConfirmMan      = row.ConfirmMan;
                            model.ConfirmDate     = row.ConfirmDate;
                            model.Attr1           = row.Attr1;
                            model.Attr2           = row.Attr2;
                            model.Attr3           = row.Attr3;
                            model.Attr4           = row.Attr4;
                            model.Attr5           = row.Attr5;
                            model.CreatePerson    = row.CreatePerson;
                            model.CreateTime      = row.CreateTime;
                            model.ModifyPerson    = row.ModifyPerson;
                            model.ModifyTime      = row.ModifyTime;
                            model.BatchId         = row.BatchId;

                            if (!String.IsNullOrEmpty(errorMessage))
                            {
                                rtn = false;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                            }

                            //执行额外的数据校验
                            try
                            {
                                AdditionalCheckExcelData(ref model);
                            }
                            catch (Exception ex)
                            {
                                rtn          = false;
                                errorMessage = ex.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                            }

                            //写入数据库
                            WMS_ReturnOrder_D entity = new WMS_ReturnOrder_D();
                            entity.Id = model.Id;
                            entity.ReturnOrderDNum = model.ReturnOrderDNum;
                            entity.HeadId          = model.HeadId;
                            entity.ReturnQty       = model.ReturnQty;
                            entity.Remark          = model.Remark;
                            entity.PrintStaus      = model.PrintStaus;
                            entity.PrintDate       = model.PrintDate;
                            entity.PrintMan        = model.PrintMan;
                            entity.ConfirmStatus   = model.ConfirmStatus;
                            entity.ConfirmMan      = model.ConfirmMan;
                            entity.ConfirmDate     = model.ConfirmDate;
                            entity.Attr1           = model.Attr1;
                            entity.Attr2           = model.Attr2;
                            entity.Attr3           = model.Attr3;
                            entity.Attr4           = model.Attr4;
                            entity.Attr5           = model.Attr5;
                            entity.CreatePerson    = model.CreatePerson;
                            entity.CreateTime      = model.CreateTime;
                            entity.ModifyPerson    = model.ModifyPerson;
                            entity.ModifyTime      = model.ModifyTime;
                            entity.BatchId         = model.BatchId;
                            entity.CreatePerson    = oper;
                            entity.CreateTime      = DateTime.Now;
                            entity.ModifyPerson    = oper;
                            entity.ModifyTime      = DateTime.Now;

                            db.WMS_ReturnOrder_D.Add(entity);
                            try
                            {
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                rtn = false;
                                //将当前报错的entity状态改为分离,类似EF的回滚(忽略之前的Add操作)
                                db.Entry(entity).State = System.Data.Entity.EntityState.Detached;
                                errorMessage           = ex.InnerException.InnerException.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                            }
                        }

                        if (rtn)
                        {
                            tran.Commit();  //必须调用Commit(),不然数据不会保存
                        }
                        else
                        {
                            tran.Rollback();    //出错就回滚
                        }
                    }
                }
                wb.Save();
            }

            return(rtn);
        }
コード例 #34
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <WMS_InvRecordModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.PartId, "物料编码");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.QTY, "数量");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.InvId, "库房编码");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.SubInvId, "SubInvId");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.BillId, "单据ID");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.SourceBill, "单据来源");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.OperateDate, "操作时间");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.Lot, "Lot");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.Type, "出入库类型");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.OperateMan, "操作人");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.Stock_InvId, "备料库存");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.StockStatus, "备料状态:1-不适用(直接修改库存现有量);2-已备料;3-无效备料(取消备料后将2改成3);4-取消备料(当前操作是取消备料)");

            //SheetName
            var excelContent = excelFile.Worksheet <WMS_InvRecordModel>(0);
            int rowIndex     = 1;

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new WMS_InvRecordModel();
                entity.Id          = row.Id;
                entity.PartId      = row.PartId;
                entity.QTY         = row.QTY;
                entity.InvId       = row.InvId;
                entity.SubInvId    = row.SubInvId;
                entity.BillId      = row.BillId;
                entity.SourceBill  = row.SourceBill;
                entity.OperateDate = row.OperateDate;
                entity.Lot         = row.Lot;
                entity.Type        = row.Type;
                entity.OperateMan  = row.OperateMan;
                entity.Stock_InvId = row.Stock_InvId;
                entity.StockStatus = row.StockStatus;

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
コード例 #35
0
        /// <summary>
        /// 设置一个部门
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="entity">一个部门</param>
        /// <returns>是否设置成功</returns>
        public bool SetSysDepartment(ref ValidationErrors validationErrors, SysDocument entity)
        {
            bool bResult = false;
            int  count   = 0;

            using (TransactionScope transactionScope = new TransactionScope())
            {
                try
                {
                    SysDocument editEntity = repository.GetById(db, entity.Id);

                    List <string> addSysDepartmentId    = new List <string>();
                    List <string> deleteSysDepartmentId = new List <string>();
                    if (entity.SysDepartmentId != null)
                    {
                        addSysDepartmentId = entity.SysDepartmentId.Split(',').ToList();
                    }
                    if (entity.SysDepartmentIdOld != null)
                    {
                        deleteSysDepartmentId = entity.SysDepartmentIdOld.Split(',').ToList();
                    }
                    DataOfDiffrent.GetDiffrent(addSysDepartmentId, deleteSysDepartmentId, ref addSysDepartmentId, ref deleteSysDepartmentId);

                    if (addSysDepartmentId != null && addSysDepartmentId.Count() > 0)
                    {
                        foreach (var item in addSysDepartmentId)
                        {
                            SysDepartment sys = new SysDepartment {
                                Id = item
                            };
                            db.SysDepartment.Attach(sys);
                            editEntity.SysDepartment.Add(sys);
                            count++;
                        }
                    }
                    if (deleteSysDepartmentId != null && deleteSysDepartmentId.Count() > 0)
                    {
                        List <SysDepartment> listEntity = new List <SysDepartment>();
                        foreach (var item in deleteSysDepartmentId)
                        {
                            SysDepartment sys = new SysDepartment {
                                Id = item
                            };
                            listEntity.Add(sys);
                            db.SysDepartment.Attach(sys);
                        }
                        foreach (SysDepartment item in listEntity)
                        {
                            editEntity.SysDepartment.Remove(item);//查询数据库
                            count++;
                        }
                    }

                    if (count > 0 && count == repository.Save(db))
                    {
                        transactionScope.Complete();
                        bResult = true;
                    }
                    else if (count == 0)
                    {
                        validationErrors.Add("数据没有改变");
                    }
                }
                catch (Exception ex)
                {
                    Transaction.Current.Rollback();
                    ExceptionsHander.WriteExceptions(ex);
                    validationErrors.Add("编辑出错了。原因" + ex.Message);
                }
            }

            return(bResult);
        }
コード例 #36
0
ファイル: SysDepartmentBLL.cs プロジェクト: vipsms/right
        /// <summary>
        /// 编辑一个部门
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个部门</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysDepartment entity)
        {
            /*
                           * 不操作 原有 现有
                           * 增加   原没 现有
                           * 删除   原有 现没
                           */
            if (entity == null)
            {
                return false;
            }
            int count = 1;

            List<string> addSysDocumentId = new List<string>();
            List<string> deleteSysDocumentId = new List<string>();
            DataOfDiffrent.GetDiffrent(entity.SysDocumentId.GetIdSort(), entity.SysDocumentIdOld.GetIdSort(), ref addSysDocumentId, ref deleteSysDocumentId);
            List<SysDocument> listEntitySysDocument = new List<SysDocument>();
            if (deleteSysDocumentId != null && deleteSysDocumentId.Count() > 0)
            {
                foreach (var item in deleteSysDocumentId)
                {
                    SysDocument sys = new SysDocument { Id = item };
                    listEntitySysDocument.Add(sys);
                    entity.SysDocument.Add(sys);
                }
            }

            SysDepartment editEntity = repository.Edit(db, entity);

            if (addSysDocumentId != null && addSysDocumentId.Count() > 0)
            {
                foreach (var item in addSysDocumentId)
                {
                    SysDocument sys = new SysDocument { Id = item };
                    db.SysDocument.Attach(sys);
                    editEntity.SysDocument.Add(sys);
                    count++;
                }
            }
            if (deleteSysDocumentId != null && deleteSysDocumentId.Count() > 0)
            {
                foreach (SysDocument item in listEntitySysDocument)
                {
                    editEntity.SysDocument.Remove(item);
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("编辑部门出错了");
            }
            return false;
        }
コード例 #37
0
 public bool Create(ref ValidationErrors errors, SysUserModel model)
 {
     try
     {
         SysUser entity = m_Rep.GetById(model.Id);
         if (entity != null)
         {
             errors.Add(Suggestion.PrimaryRepeat);
             return(false);
         }
         entity              = new SysUser();
         entity.Address      = model.Address;
         entity.Attach       = model.Attach;
         entity.Birthday     = model.Birthday;
         entity.Card         = model.Card;
         entity.City         = model.City;
         entity.CreatePerson = model.CreatePerson;
         entity.CreateTime   = model.CreateTime;
         entity.Degree       = model.Degree;
         entity.DepId        = model.DepId;
         entity.EmailAddress = model.EmailAddress;
         entity.Expertise    = model.Expertise;
         entity.Id           = model.Id;
         entity.JobState     = model.JobState;
         entity.JoinDate     = model.JoinDate;
         entity.Marital      = model.Marital;
         entity.MobileNumber = model.MobileNumber;
         entity.Nationality  = model.Nationality;
         entity.Native       = model.Native;
         entity.OtherContact = model.OtherContact;
         entity.Password     = model.Password;
         entity.PhoneNumber  = model.PhoneNumber;
         entity.Photo        = model.Photo;
         entity.Political    = model.Political;
         entity.PosId        = model.PosId;
         entity.Professional = model.Professional;
         entity.Province     = model.Province;
         entity.QQ           = model.QQ;
         entity.School       = model.School;
         entity.Sex          = model.Sex;
         entity.State        = model.State;
         entity.TrueName     = model.TrueName;
         entity.UserName     = model.UserName;
         entity.Village      = model.Village;
         if (m_Rep.Create(entity) == 1)
         {
             return(true);
         }
         else
         {
             errors.Add(Suggestion.InsertFail);
             return(false);
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHandler.WriteException(ex);
         return(false);
     }
 }
コード例 #38
0
        public bool Edit(ref ValidationErrors errors, SysModuleModel model)
        {
            try
            {
                SysModule entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Suggestion.Disable);
                    return false;
                }
                entity.Name = model.Name;
                entity.EnglishName = model.EnglishName;
                entity.ParentId = model.ParentId;
                entity.Url = model.Url;
                entity.Iconic = model.Iconic;
                entity.Sort = model.Sort;
                entity.Remark = model.Remark;
                entity.Enable = model.Enable;
                entity.IsLast = model.IsLast;

                if (m_Rep.Edit(entity) == 1)
                {
                    return true;
                }
                else
                {
                    errors.Add(Suggestion.EditFail);
                    return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }
コード例 #39
0
  /// <summary>
 /// 编辑一个附件
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entity">一个附件</param>
 /// <returns></returns>
 public bool Edit(ref ValidationErrors validationErrors, FileUploader entity)
 {
     try
     { 
         repository.Edit(db, entity);
         repository.Save(db);
         return true;
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);                
     }
     return false;
 }
コード例 #40
0
 public bool Create(ref ValidationErrors errors, SysUserModel model)
 {
     try
     {
         SysUser entity = m_Rep.GetById(model.Id);
         if (entity != null)
         {
             errors.Add(Suggestion.PrimaryRepeat);
             return false;
         }
         entity = new SysUser();
         entity.Id = model.Id;
         entity.UserName = model.UserName;
         entity.Password = model.Password;
         entity.TrueName = model.TrueName;
         entity.Card = model.Card;
         entity.MobileNumber = model.MobileNumber;
         entity.PhoneNumber = model.PhoneNumber;
         entity.QQ = model.QQ;
         entity.EmailAddress = model.EmailAddress;
         entity.OtherContact = model.OtherContact;
         entity.Province = model.Province;
         entity.City = model.City;
         entity.Village = model.Village;
         entity.Address = model.Address;
         entity.State = model.State;
         entity.CreateTime = model.CreateTime;
         entity.CreatePerson = model.CreatePerson;
         entity.Sex = model.Sex;
         entity.Birthday = model.Birthday;
         entity.JoinDate = model.JoinDate;
         entity.Marital = model.Marital;
         entity.Political = model.Political;
         entity.Nationality = model.Nationality;
         entity.Native = model.Native;
         entity.School = model.School;
         entity.Professional = model.Professional;
         entity.Degree = model.Degree;
         entity.DepId = model.DepId;
         entity.PosId = model.PosId;
         entity.Expertise = model.Expertise;
         entity.JobState = model.JobState;
         entity.Photo = model.Photo;
         entity.Attach = model.Attach;
         if (m_Rep.Create(entity) == 1)
         {
             return true;
         }
         else
         {
             errors.Add(Suggestion.InsertFail);
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
コード例 #41
0
 public bool Delete(ref ValidationErrors errors, string[] deleteCollection)
 {
     try
     {
         if (deleteCollection != null)
         {
             using (TransactionScope transactionScope = new TransactionScope())
             {
                 m_Rep.Delete(dbContainer, deleteCollection);
                 if (dbContainer.SaveChanges() == deleteCollection.Length)
                 {
                     transactionScope.Complete();
                     return true;
                 }
                 else
                 {
                     Transaction.Current.Rollback();
                     return false;
                 }
             }
         }
         return false;
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
コード例 #42
0
ファイル: SysPersonBLL.cs プロジェクト: Bryanlhx/permisson
        /// <summary>
        /// 创建一个人员
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个人员</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysPerson entity)
        {
            int count = 1;
            if (CheckName(entity.Name))
            {
                validationErrors.Add("用户名已被占用,请换一个新的用户名");
                return false;
            }
            foreach (string item in entity.SysRoleId.GetIdSort())
            {
                SysRole sys = new SysRole { Id = item };
                db.SysRole.Attach(sys);
                entity.SysRole.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return false;
        }
コード例 #43
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <WMS_ReturnOrderModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.ReturnOrderNum, "退货单号");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.AIID, "到货检验单ID");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.ReInspectID, "重新送检单ID");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.PartID, "物料编码");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.SupplierId, "代理商编码");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.InvId, "库存编码");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.SubInvId, "SubInvId");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.Lot, "Lot");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.ReturnQty, "应退货数量");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.AdjustQty, "实际退货数量");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.Status, "单据状态:有效/无效");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.Remark, "退货说明");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.PrintStaus, "打印状态");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.PrintDate, "打印时间");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.PrintMan, "打印人");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.ConfirmStatus, "确认状态");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.ConfirmMan, "确认人");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.ConfirmDate, "确认时间");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.Attr1, "Attr1");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.Attr2, "Attr2");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.Attr3, "Attr3");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.Attr4, "Attr4");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.Attr5, "Attr5");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.CreatePerson, "创建人");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.CreateTime, "创建时间");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.ModifyPerson, "修改人");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.ModifyTime, "修改时间");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.BatchId, "BatchId");
            excelFile.AddMapping <WMS_ReturnOrderModel>(x => x.ReturnOderType, "退货单类型");

            //SheetName
            var excelContent = excelFile.Worksheet <WMS_ReturnOrderModel>(0);
            int rowIndex     = 1;

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new WMS_ReturnOrderModel();
                entity.Id             = row.Id;
                entity.ReturnOrderNum = row.ReturnOrderNum;
                entity.AIID           = row.AIID;
                entity.ReInspectID    = row.ReInspectID;
                entity.PartID         = row.PartID;
                entity.SupplierId     = row.SupplierId;
                entity.InvId          = row.InvId;
                entity.SubInvId       = row.SubInvId;
                entity.Lot            = row.Lot;
                entity.ReturnQty      = row.ReturnQty;
                entity.AdjustQty      = row.AdjustQty;
                entity.Status         = row.Status;
                entity.Remark         = row.Remark;
                entity.PrintStaus     = row.PrintStaus;
                entity.PrintDate      = row.PrintDate;
                entity.PrintMan       = row.PrintMan;
                entity.ConfirmStatus  = row.ConfirmStatus;
                entity.ConfirmMan     = row.ConfirmMan;
                entity.ConfirmDate    = row.ConfirmDate;
                entity.Attr1          = row.Attr1;
                entity.Attr2          = row.Attr2;
                entity.Attr3          = row.Attr3;
                entity.Attr4          = row.Attr4;
                entity.Attr5          = row.Attr5;
                entity.CreatePerson   = row.CreatePerson;
                entity.CreateTime     = row.CreateTime;
                entity.ModifyPerson   = row.ModifyPerson;
                entity.ModifyTime     = row.ModifyTime;
                entity.BatchId        = row.BatchId;
                entity.ReturnOderType = row.ReturnOderType;

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
コード例 #44
0
ファイル: SysDocumentTalkBLL.cs プロジェクト: vipsms/right
 /// <summary>
 /// 删除一个文档评论
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="id">一文档评论的主键</param>
 /// <returns></returns>  
 public bool Delete(ref ValidationErrors validationErrors, string id)
 {
     try
     {
         return repository.Delete(id) == 1;
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return false;
 }
コード例 #45
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <Flow_StepModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <Flow_StepModel>(x => x.Name, "Name");
            excelFile.AddMapping <Flow_StepModel>(x => x.Remark, "Remark");
            excelFile.AddMapping <Flow_StepModel>(x => x.Sort, "Sort");
            excelFile.AddMapping <Flow_StepModel>(x => x.FormId, "FormId");
            excelFile.AddMapping <Flow_StepModel>(x => x.FlowRule, "FlowRule");
            excelFile.AddMapping <Flow_StepModel>(x => x.IsCustom, "IsCustom");
            excelFile.AddMapping <Flow_StepModel>(x => x.IsAllCheck, "IsAllCheck");
            excelFile.AddMapping <Flow_StepModel>(x => x.Execution, "Execution");
            excelFile.AddMapping <Flow_StepModel>(x => x.CompulsoryOver, "CompulsoryOver");
            excelFile.AddMapping <Flow_StepModel>(x => x.IsEditAttr, "IsEditAttr");

            //SheetName
            var excelContent = excelFile.Worksheet <Flow_StepModel>(0);
            int rowIndex     = 1;

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new Flow_StepModel();
                entity.Id             = row.Id;
                entity.Name           = row.Name;
                entity.Remark         = row.Remark;
                entity.Sort           = row.Sort;
                entity.FormId         = row.FormId;
                entity.FlowRule       = row.FlowRule;
                entity.IsCustom       = row.IsCustom;
                entity.IsAllCheck     = row.IsAllCheck;
                entity.Execution      = row.Execution;
                entity.CompulsoryOver = row.CompulsoryOver;
                entity.IsEditAttr     = row.IsEditAttr;

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
コード例 #46
0
ファイル: SysDocumentTalkBLL.cs プロジェクト: vipsms/right
        /// <summary>
        /// 删除文档评论集合
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="deleteCollection">文档评论的集合</param>
        /// <returns></returns>    
        public bool DeleteCollection(ref ValidationErrors validationErrors, string[] deleteCollection)
        {
            try
            {
                if (deleteCollection != null)
                {
                        using (TransactionScope transactionScope = new TransactionScope())
                        {
                            repository.Delete(db, deleteCollection);
                            if (deleteCollection.Length == repository.Save(db))
                            {
                                transactionScope.Complete();
                                return true;
                            }
                            else
                            {
                                Transaction.Current.Rollback();
                            }
                        }
                    }

            }
            catch (Exception ex)
            {
                validationErrors.Add(ex.Message);
                ExceptionsHander.WriteExceptions(ex);
            }
            return false;
        }
コード例 #47
0
        public virtual void Modify(ref ValidationErrors errors, Apps.Models.Sys.SysUserModel model, params string[] updateProperties)
        {
            SysUser entity = m_Rep.GetById(model.Id);

            if (entity == null)
            {
                errors.Add(Resource.Disable);
                return;
            }
            if (updateProperties.Count() <= 0)
            {
                entity.Id       = model.Id;
                entity.UserName = model.UserName;
                entity.Password = model.Password;
                entity.PasswordExpirationTime = model.PasswordExpirationTime;
                entity.TrueName     = model.TrueName;
                entity.Card         = model.Card;
                entity.MobileNumber = model.MobileNumber;
                entity.PhoneNumber  = model.PhoneNumber;
                entity.QQ           = model.QQ;
                entity.EmailAddress = model.EmailAddress;
                entity.OtherContact = model.OtherContact;
                entity.Province     = model.Province;
                entity.City         = model.City;
                entity.Village      = model.Village;
                entity.Address      = model.Address;
                entity.State        = model.State;
                entity.CreateTime   = model.CreateTime;
                entity.CreatePerson = model.CreatePerson;
                entity.Sex          = model.Sex;
                entity.Birthday     = model.Birthday;
                entity.JoinDate     = model.JoinDate;
                entity.Marital      = model.Marital;
                entity.Political    = model.Political;
                entity.Nationality  = model.Nationality;
                entity.Native       = model.Native;
                entity.School       = model.School;
                entity.Professional = model.Professional;
                entity.Degree       = model.Degree;
                entity.DepId        = model.DepId;
                entity.PosId        = model.PosId;
                entity.Expertise    = model.Expertise;
                entity.Photo        = model.Photo;
                entity.Attach       = model.Attach;
                entity.Lead         = model.Lead;
                entity.LeadName     = model.LeadName;
            }
            else
            {
                Type type  = typeof(Apps.Models.Sys.SysUserModel);
                Type typeE = typeof(Apps.Models.SysUser);
                foreach (var item in updateProperties)
                {
                    System.Reflection.PropertyInfo pi  = type.GetProperty(item);
                    System.Reflection.PropertyInfo piE = typeE.GetProperty(item);
                    piE.SetValue(entity, pi.GetValue(model), null);
                }
            }


            m_Rep.Modify(entity, updateProperties);
        }
コード例 #48
0
        /// <summary>
        /// 编辑一个菜单
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个菜单</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysMenu entity)
        {  /*                       
                           * 不操作 原有 现有
                           * 增加   原没 现有
                           * 删除   原有 现没
                           */
            if (entity == null)
            {
                return false;
            }
            int count = 1;
            SysMenu editEntity = repository.Edit(db, entity);

            List<string> addSysOperationId = new List<string>();
            List<string> deleteSysOperationId = new List<string>();
            DataOfDiffrent.GetDiffrent(entity.SysOperationId.GetIdSort(), entity.SysOperationIdOld.GetIdSort(), ref addSysOperationId, ref deleteSysOperationId);
            if (addSysOperationId != null && addSysOperationId.Count() > 0)
            {
                foreach (var item in addSysOperationId)
                {
                    SysOperation sys = new SysOperation { Id = item };
                    db.SysOperation.Attach(sys);
                    editEntity.SysOperation.Add(sys);
                    count++;
                }
            }
            if (deleteSysOperationId != null && deleteSysOperationId.Count() > 0)
            {
                List<SysOperation> listEntity = new List<SysOperation>();
                foreach (var item in deleteSysOperationId)
                {
                    SysOperation sys = new SysOperation { Id = item };
                    listEntity.Add(sys);
                    db.SysOperation.Attach(sys);
                }
                foreach (SysOperation item in listEntity)
                {
                    editEntity.SysOperation.Remove(item);//查询数据库
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                //修改后重置菜单编码
                List<int> flags = new List<int>();//层级
                GetMenus2(null, flags);
                db.SaveChanges();
                return true;
            }
            else
            {
                validationErrors.Add("编辑菜单出错了");
            }
            return false;
        }
コード例 #49
0
        /// <summary>
        /// 编辑一个文档管理
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个文档管理</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysDocument entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int count = 1;

            List <string> addSysPersonId    = new List <string>();
            List <string> deleteSysPersonId = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.SysPersonId.GetIdSort(), entity.SysPersonIdOld.GetIdSort(), ref addSysPersonId, ref deleteSysPersonId);
            List <SysPerson> listEntitySysPerson = new List <SysPerson>();

            if (deleteSysPersonId != null && deleteSysPersonId.Count() > 0)
            {
                foreach (var item in deleteSysPersonId)
                {
                    SysPerson sys = new SysPerson {
                        Id = item
                    };
                    listEntitySysPerson.Add(sys);
                    entity.SysPerson.Add(sys);
                }
            }

            List <string> addSysDepartmentId    = new List <string>();
            List <string> deleteSysDepartmentId = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.SysDepartmentId.GetIdSort(), entity.SysDepartmentIdOld.GetIdSort(), ref addSysDepartmentId, ref deleteSysDepartmentId);
            List <SysDepartment> listEntitySysDepartment = new List <SysDepartment>();

            if (deleteSysDepartmentId != null && deleteSysDepartmentId.Count() > 0)
            {
                foreach (var item in deleteSysDepartmentId)
                {
                    SysDepartment sys = new SysDepartment {
                        Id = item
                    };
                    listEntitySysDepartment.Add(sys);
                    entity.SysDepartment.Add(sys);
                }
            }

            SysDocument editEntity = repository.Edit(db, entity);


            if (addSysPersonId != null && addSysPersonId.Count() > 0)
            {
                foreach (var item in addSysPersonId)
                {
                    SysPerson sys = new SysPerson {
                        Id = item
                    };
                    db.SysPerson.Attach(sys);
                    editEntity.SysPerson.Add(sys);
                    count++;
                }
            }
            if (deleteSysPersonId != null && deleteSysPersonId.Count() > 0)
            {
                foreach (SysPerson item in listEntitySysPerson)
                {
                    editEntity.SysPerson.Remove(item);
                    count++;
                }
            }


            if (addSysDepartmentId != null && addSysDepartmentId.Count() > 0)
            {
                foreach (var item in addSysDepartmentId)
                {
                    SysDepartment sys = new SysDepartment {
                        Id = item
                    };
                    db.SysDepartment.Attach(sys);
                    editEntity.SysDepartment.Add(sys);
                    count++;
                }
            }
            if (deleteSysDepartmentId != null && deleteSysDepartmentId.Count() > 0)
            {
                foreach (SysDepartment item in listEntitySysDepartment)
                {
                    editEntity.SysDepartment.Remove(item);
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("编辑文档管理出错了");
            }
            return(false);
        }
コード例 #50
0
ファイル: SysDocumentTalkBLL.cs プロジェクト: vipsms/right
 /// <summary>
 ///  创建文档评论集合
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entitys">文档评论集合</param>
 /// <returns></returns>
 public bool CreateCollection(ref ValidationErrors validationErrors, IQueryable<SysDocumentTalk> entitys)
 {
     try
     {
         if (entitys != null)
         {
             int count = entitys.Count();
             if (count == 1)
             {
                 return this.Create(ref validationErrors, entitys.FirstOrDefault());
             }
             else if (count > 1)
             {
                 using (TransactionScope transactionScope = new TransactionScope())
                 {
                     repository.Create(db, entitys);
                     if (count == repository.Save(db))
                     {
                         transactionScope.Complete();
                         return true;
                     }
                     else
                     {
                         Transaction.Current.Rollback();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return false;
 }
コード例 #51
0
        public bool ImportExcelData(string oper, string filePath, ref ValidationErrors errors)
        {
            bool rtn = true;

            var targetFile = new FileInfo(filePath);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(filePath);

            using (XLWorkbook wb = new XLWorkbook(filePath))
            {
                //第一个Sheet
                using (IXLWorksheet wws = wb.Worksheets.First())
                {
                    //对应列头
                    excelFile.AddMapping <WMS_POModel>(x => x.PO, "采购订单(必输)");
                    excelFile.AddMapping <WMS_POModel>(x => x.PODate, "采购日期(必输格式:YYYY-MM-DD)");
                    excelFile.AddMapping <WMS_POModel>(x => x.SupplierShortName, "供应商简称(必输)");
                    excelFile.AddMapping <WMS_POModel>(x => x.PartCode, "物料编码(必输)");
                    excelFile.AddMapping <WMS_POModel>(x => x.QTY, "数量(必输)");
                    excelFile.AddMapping <WMS_POModel>(x => x.PlanDate, "计划到货日期");
                    excelFile.AddMapping <WMS_POModel>(x => x.POType, "采购订单类型");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Status, "状态");
                    excelFile.AddMapping <WMS_POModel>(x => x.Remark, "说明");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Attr1, "");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Attr2, "");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Attr3, "");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Attr4, "");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Attr5, "");
                    //excelFile.AddMapping<WMS_POModel>(x => x.CreatePerson, "创建人");
                    //excelFile.AddMapping<WMS_POModel>(x => x.CreateTime, "创建时间");
                    //excelFile.AddMapping<WMS_POModel>(x => x.ModifyPerson, "修改人");
                    //excelFile.AddMapping<WMS_POModel>(x => x.ModifyTime, "修改时间");

                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_POModel>(0);

                    //开启事务
                    using (DBContainer db = new DBContainer())
                    {
                        var tran     = db.Database.BeginTransaction(); //开启事务
                        int rowIndex = 0;

                        //检查数据正确性
                        foreach (var row in excelContent)
                        {
                            rowIndex += 1;
                            string errorMessage = String.Empty;
                            var    model        = new WMS_POModel();
                            model.Id                = row.Id;
                            model.PO                = row.PO;
                            model.PODate            = row.PODate;
                            model.SupplierShortName = row.SupplierShortName;
                            model.PartCode          = row.PartCode;
                            model.QTY               = row.QTY;
                            model.PlanDate          = row.PlanDate;
                            model.POType            = row.POType;
                            model.Status            = "有效";
                            model.Remark            = row.Remark;
                            //model.Attr1 = row.Attr1;
                            //model.Attr2 = row.Attr2;
                            //model.Attr3 = row.Attr3;
                            //model.Attr4 = row.Attr4;
                            //model.Attr5 = row.Attr5;
                            //model.CreatePerson = row.CreatePerson;
                            //model.CreateTime = row.CreateTime;
                            //model.ModifyPerson = row.ModifyPerson;
                            //model.ModifyTime = row.ModifyTime;

                            if (!String.IsNullOrEmpty(errorMessage))
                            {
                                rtn = false;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                            }

                            //执行额外的数据校验
                            try
                            {
                                AdditionalCheckExcelData(db, ref model);
                            }
                            catch (Exception ex)
                            {
                                rtn          = false;
                                errorMessage = ex.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                            }

                            //写入数据库
                            WMS_PO entity = new WMS_PO();
                            entity.Id           = model.Id;
                            entity.PO           = model.PO;
                            entity.PODate       = model.PODate;
                            entity.SupplierId   = model.SupplierId;
                            entity.PartId       = model.PartId;
                            entity.QTY          = model.QTY;
                            entity.PlanDate     = model.PlanDate;
                            entity.POType       = model.POType;
                            entity.Status       = "有效";
                            entity.Remark       = model.Remark;
                            entity.Attr1        = model.Attr1;
                            entity.Attr2        = model.Attr2;
                            entity.Attr3        = model.Attr3;
                            entity.Attr4        = model.Attr4;
                            entity.Attr5        = model.Attr5;
                            entity.CreatePerson = oper;
                            entity.CreateTime   = DateTime.Now;
                            entity.ModifyPerson = oper;
                            entity.ModifyTime   = DateTime.Now;

                            db.WMS_PO.Add(entity);
                            try
                            {
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                rtn = false;
                                //将当前报错的entity状态改为分离,类似EF的回滚(忽略之前的Add操作)
                                db.Entry(entity).State = System.Data.Entity.EntityState.Detached;
                                errorMessage           = ex.InnerException.InnerException.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                            }
                        }

                        if (rtn)
                        {
                            tran.Commit();  //必须调用Commit(),不然数据不会保存
                        }
                        else
                        {
                            tran.Rollback();    //出错就回滚
                        }
                    }
                }
                wb.Save();
            }

            return(rtn);
        }
        public virtual void Modify(ref ValidationErrors errors, Apps.Models.SCV.AR.AR_DOWNLOAD_ITEM_UNIT_OF_MEASURE_MODEL model, params string[] updateProperties)
        {
            Apps.Models.AR_DOWNLOAD_ITEM_UNIT_OF_MEASURE entity = m_Rep.GetById(model.INTERFACE_RECORD_ID);
            if (entity == null)
            {
                errors.Add(Resource.Disable);
                return;
            }
            if (updateProperties.Count() <= 0)
            {
                entity.INTERFACE_RECORD_ID   = model.INTERFACE_RECORD_ID;
                entity.INTERFACE_LINK_ID     = model.INTERFACE_LINK_ID;
                entity.INTERFACE_ACTION_CODE = model.INTERFACE_ACTION_CODE;
                entity.INTERFACE_CONDITION   = model.INTERFACE_CONDITION;
                entity.PROCESS_STAMP         = model.PROCESS_STAMP;
                entity.ITEM                 = model.ITEM;
                entity.COMPANY              = model.COMPANY;
                entity.SEQUENCE1            = model.SEQUENCE1;
                entity.SEQUENCE2            = model.SEQUENCE2;
                entity.SEQUENCE3            = model.SEQUENCE3;
                entity.SEQUENCE4            = model.SEQUENCE4;
                entity.SEQUENCE5            = model.SEQUENCE5;
                entity.QUANTITY_UM1         = model.QUANTITY_UM1;
                entity.QUANTITY_UM2         = model.QUANTITY_UM2;
                entity.QUANTITY_UM3         = model.QUANTITY_UM3;
                entity.QUANTITY_UM4         = model.QUANTITY_UM4;
                entity.QUANTITY_UM5         = model.QUANTITY_UM5;
                entity.CONVERSION_QTY1      = model.CONVERSION_QTY1;
                entity.CONVERSION_QTY2      = model.CONVERSION_QTY2;
                entity.CONVERSION_QTY3      = model.CONVERSION_QTY3;
                entity.CONVERSION_QTY4      = model.CONVERSION_QTY4;
                entity.CONVERSION_QTY5      = model.CONVERSION_QTY5;
                entity.LENGTH1              = model.LENGTH1;
                entity.LENGTH2              = model.LENGTH2;
                entity.LENGTH3              = model.LENGTH3;
                entity.LENGTH4              = model.LENGTH4;
                entity.LENGTH5              = model.LENGTH5;
                entity.WIDTH1               = model.WIDTH1;
                entity.WIDTH2               = model.WIDTH2;
                entity.WIDTH3               = model.WIDTH3;
                entity.WIDTH4               = model.WIDTH4;
                entity.WIDTH5               = model.WIDTH5;
                entity.HEIGHT1              = model.HEIGHT1;
                entity.HEIGHT2              = model.HEIGHT2;
                entity.HEIGHT3              = model.HEIGHT3;
                entity.HEIGHT4              = model.HEIGHT4;
                entity.HEIGHT5              = model.HEIGHT5;
                entity.DIMENSION_UM1        = model.DIMENSION_UM1;
                entity.DIMENSION_UM2        = model.DIMENSION_UM2;
                entity.DIMENSION_UM3        = model.DIMENSION_UM3;
                entity.DIMENSION_UM4        = model.DIMENSION_UM4;
                entity.DIMENSION_UM5        = model.DIMENSION_UM5;
                entity.WEIGHT1              = model.WEIGHT1;
                entity.WEIGHT2              = model.WEIGHT2;
                entity.WEIGHT3              = model.WEIGHT3;
                entity.WEIGHT4              = model.WEIGHT4;
                entity.WEIGHT5              = model.WEIGHT5;
                entity.WEIGHT_UM1           = model.WEIGHT_UM1;
                entity.WEIGHT_UM2           = model.WEIGHT_UM2;
                entity.WEIGHT_UM3           = model.WEIGHT_UM3;
                entity.WEIGHT_UM4           = model.WEIGHT_UM4;
                entity.WEIGHT_UM5           = model.WEIGHT_UM5;
                entity.USER_STAMP           = model.USER_STAMP;
                entity.DATE_TIME_STAMP      = model.DATE_TIME_STAMP;
                entity.TREAT_FULL_PCT       = model.TREAT_FULL_PCT;
                entity.MOVEMENT_CLS         = model.MOVEMENT_CLS;
                entity.ITEM_CLASS           = model.ITEM_CLASS;
                entity.TREAT_AS_LOOSE       = model.TREAT_AS_LOOSE;
                entity.GROUP_DURING_CHECKIN = model.GROUP_DURING_CHECKIN;
            }
            else
            {
                Type type  = typeof(Apps.Models.SCV.AR.AR_DOWNLOAD_ITEM_UNIT_OF_MEASURE_MODEL);
                Type typeE = typeof(Apps.Models.AR_DOWNLOAD_ITEM_UNIT_OF_MEASURE);
                foreach (var item in updateProperties)
                {
                    System.Reflection.PropertyInfo pi  = type.GetProperty(item);
                    System.Reflection.PropertyInfo piE = typeE.GetProperty(item);
                    piE.SetValue(entity, pi.GetValue(model), null);
                }
            }


            m_Rep.Modify(entity, updateProperties);
        }
コード例 #53
0
        public bool ImportExcelData(string oper, string filePath, ref ValidationErrors errors)
        {
            bool rtn = true;

            var targetFile = new FileInfo(filePath);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(filePath);

            using (XLWorkbook wb = new XLWorkbook(filePath))
            {
                //第一个Sheet
                using (IXLWorksheet wws = wb.Worksheets.First())
                {
                    //对应列头
                    excelFile.AddMapping <WMS_Product_EntryModel>(x => x.ProductBillNum, "入库单号(业务)(必输)");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.EntryBillNum, "入库单号(系统)");
                    excelFile.AddMapping <WMS_Product_EntryModel>(x => x.Department, "本货部门");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.Partid, "物料");
                    excelFile.AddMapping <WMS_Product_EntryModel>(x => x.PartCode, "物料编码(必输)");
                    excelFile.AddMapping <WMS_Product_EntryModel>(x => x.ProductQty, "数量(必输)");
                    excelFile.AddMapping <WMS_Product_EntryModel>(x => x.Lot, "批次(格式:YYYY-MM-DD)");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.InvId, "库存");
                    excelFile.AddMapping <WMS_Product_EntryModel>(x => x.InvName, "库房");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.SubInvId, "子库存");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.Remark, "备注");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.Attr1, "");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.Attr2, "");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.Attr3, "");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.Attr4, "");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.Attr5, "");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.CreatePerson, "创建人");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.CreateTime, "创建时间");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.ModifyPerson, "修改人");
                    //excelFile.AddMapping<WMS_Product_EntryModel>(x => x.ModifyTime, "修改时间");

                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_Product_EntryModel>(0);

                    //开启事务
                    using (DBContainer db = new DBContainer())
                    {
                        var    tran           = db.Database.BeginTransaction(); //开启事务
                        int    rowIndex       = 0;
                        string productBillNum = "Z" + DateTime.Now.ToString("yyyyMMddHHmmssff");

                        //检查数据正确性
                        foreach (var row in excelContent)
                        {
                            rowIndex += 1;
                            string errorMessage = String.Empty;
                            var    model        = new WMS_Product_EntryModel();
                            model.Id             = row.Id;
                            model.ProductBillNum = productBillNum;
                            //productBillNum = row.ProductBillNum;
                            model.EntryBillNum = row.EntryBillNum;
                            model.Department   = row.Department;
                            //model.Partid = row.Partid;
                            model.PartCode   = row.PartCode;
                            model.ProductQty = row.ProductQty;
                            model.Lot        = row.Lot;
                            //model.InvId = row.InvId;
                            model.InvName = row.InvName;
                            //model.SubInvId = row.SubInvId;
                            model.Remark       = row.Remark;
                            model.Attr1        = row.Attr1;
                            model.Attr2        = row.Attr2;
                            model.Attr3        = row.Attr3;
                            model.Attr4        = row.Attr4;
                            model.Attr5        = row.Attr5;
                            model.CreatePerson = row.CreatePerson;
                            model.CreateTime   = row.CreateTime;
                            model.ModifyPerson = row.ModifyPerson;
                            model.ModifyTime   = row.ModifyTime;

                            if (!String.IsNullOrEmpty(errorMessage))
                            {
                                rtn = false;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                            }

                            //执行额外的数据校验
                            try
                            {
                                AdditionalCheckExcelData(db, ref model);
                            }
                            catch (Exception ex)
                            {
                                rtn          = false;
                                errorMessage = ex.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                            }

                            //写入数据库
                            WMS_Product_Entry entity = new WMS_Product_Entry();
                            entity.Id             = model.Id;
                            entity.ProductBillNum = model.ProductBillNum;
                            //entity.ProductBillNum = "ZZJ" + DateTime.Now.ToString("yyyyMMddHHmmssff");
                            entity.EntryBillNum = model.EntryBillNum;
                            //entity.EntryBillNum = "ZZJ" + DateTime.Now.ToString("yyyyMMddHHmmssff");
                            entity.Department = "总装车间";
                            entity.Partid     = model.Partid;
                            entity.ProductQty = model.ProductQty;
                            entity.InvId      = model.InvId;
                            entity.Lot        = model.Lot;
                            //entity.SubInvId = model.SubInvId;
                            entity.Remark = model.Remark;
                            //entity.Attr1 = model.Attr1;
                            //entity.Attr2 = model.Attr2;
                            //entity.Attr3 = model.Attr3;
                            //entity.Attr4 = model.Attr4;
                            //entity.Attr5 = model.Attr5;
                            entity.CreatePerson = oper;
                            entity.CreateTime   = DateTime.Now;
                            entity.ModifyPerson = oper;
                            entity.ModifyTime   = DateTime.Now;

                            db.WMS_Product_Entry.Add(entity);
                            try
                            {
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                rtn = false;
                                //将当前报错的entity状态改为分离,类似EF的回滚(忽略之前的Add操作)
                                db.Entry(entity).State = System.Data.Entity.EntityState.Detached;
                                errorMessage           = ex.InnerException.InnerException.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                            }
                        }

                        if (rtn)
                        {
                            //全部保存成功后,调用存储过程“P_WMS_ProcessProductEntry”入库。
                            ObjectParameter returnValue = new ObjectParameter("ReturnValue", typeof(string));
                            db.P_WMS_ProcessProductEntry(oper, productBillNum, returnValue);
                            if (returnValue.Value == DBNull.Value)
                            {
                                tran.Commit();
                            }
                            else
                            {
                                tran.Rollback();
                                errors.Add((string)returnValue.Value);
                            }

                            //tran.Commit();  //必须调用Commit(),不然数据不会保存
                        }
                        else
                        {
                            tran.Rollback();    //出错就回滚
                        }
                    }
                }
                wb.Save();
            }

            return(rtn);
        }
コード例 #54
0
ファイル: WMS_InvInfoBLL.cs プロジェクト: zqs99/XDWMS-Ymnets
        public bool ImportExcelData(string filePath, ref ValidationErrors errors)
        {
            bool rtn = true;

            var targetFile = new FileInfo(filePath);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(filePath);

            using (XLWorkbook wb = new XLWorkbook(filePath))
            {
                //第一个Sheet
                using (IXLWorksheet wws = wb.Worksheets.First())
                {
                    //对应列头
                    excelFile.AddMapping <WMS_InvInfoModel>(x => x.InvCode, "库房编码");
                    excelFile.AddMapping <WMS_InvInfoModel>(x => x.InvName, "库房名称");
                    excelFile.AddMapping <WMS_InvInfoModel>(x => x.Remark, "说明");
                    excelFile.AddMapping <WMS_InvInfoModel>(x => x.Status, "状态");
                    excelFile.AddMapping <WMS_InvInfoModel>(x => x.CreatePerson, "创建人");
                    excelFile.AddMapping <WMS_InvInfoModel>(x => x.CreateTime, "创建时间");
                    excelFile.AddMapping <WMS_InvInfoModel>(x => x.ModifyPerson, "修改人");
                    excelFile.AddMapping <WMS_InvInfoModel>(x => x.ModifyTime, "修改时间");

                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_InvInfoModel>(0);

                    //开启事务
                    using (DBContainer db = new DBContainer())
                    {
                        var tran     = db.Database.BeginTransaction();                      //开启事务
                        int rowIndex = 0;

                        //检查数据正确性
                        foreach (var row in excelContent)
                        {
                            rowIndex += 1;
                            string errorMessage = String.Empty;
                            var    model        = new WMS_InvInfoModel();
                            model.Id           = row.Id;
                            model.InvCode      = row.InvCode;
                            model.InvName      = row.InvName;
                            model.Remark       = row.Remark;
                            model.Status       = row.Status;
                            model.CreatePerson = row.CreatePerson;
                            model.CreateTime   = row.CreateTime;
                            model.ModifyPerson = row.ModifyPerson;
                            model.ModifyTime   = row.ModifyTime;

                            if (!String.IsNullOrEmpty(errorMessage))
                            {
                                rtn = false;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, 10).Value = errorMessage;
                                continue;
                            }

                            //执行额外的数据校验
                            try
                            {
                                AdditionalCheckExcelData(model);
                            }
                            catch (Exception ex)
                            {
                                rtn          = false;
                                errorMessage = ex.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, 10).Value = errorMessage;
                                continue;
                            }

                            //写入数据库
                            WMS_InvInfo entity = new WMS_InvInfo();
                            entity.Id           = model.Id;
                            entity.InvCode      = model.InvCode;
                            entity.InvName      = model.InvName;
                            entity.Remark       = model.Remark;
                            entity.Status       = model.Status;
                            entity.CreatePerson = model.CreatePerson;
                            entity.CreateTime   = model.CreateTime;
                            entity.ModifyPerson = model.ModifyPerson;
                            entity.ModifyTime   = model.ModifyTime;

                            db.WMS_InvInfo.Add(entity);
                            try
                            {
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                rtn = false;
                                //将当前报错的entity状态改为分离,类似EF的回滚(忽略之前的Add操作)
                                db.Entry(entity).State = System.Data.Entity.EntityState.Detached;
                                errorMessage           = ex.InnerException.InnerException.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, 10).Value = errorMessage;
                            }
                        }

                        if (rtn)
                        {
                            tran.Commit();                                      //必须调用Commit(),不然数据不会保存
                        }
                        else
                        {
                            tran.Rollback();                                        //出错就回滚
                        }
                    }
                }
                wb.Save();
            }

            return(rtn);
        }
コード例 #55
0
        public virtual void Create(ref ValidationErrors errors, Apps.Models.SCV.DOWNLOAD.DOWNLOAD_SHIPMENT_HEADER_FAILED_MODEL model)
        {
            Apps.Models.DOWNLOAD_SHIPMENT_HEADER_FAILED entity = m_Rep.GetById(model.INTERFACE_RECORD_ID);
            if (entity != null)
            {
                errors.Add(Resource.PrimaryRepeat);
                return;
            }
            entity = new Apps.Models.DOWNLOAD_SHIPMENT_HEADER_FAILED();
            entity.INTERFACE_RECORD_ID   = model.INTERFACE_RECORD_ID;
            entity.INTERFACE_ACTION_CODE = model.INTERFACE_ACTION_CODE;
            entity.INTERFACE_CONDITION   = model.INTERFACE_CONDITION;
            entity.PROCESS_STAMP         = model.PROCESS_STAMP;
            entity.WAREHOUSE             = model.WAREHOUSE;
            entity.COMPANY                   = model.COMPANY;
            entity.INTERNAL_LOAD_NUM         = model.INTERNAL_LOAD_NUM;
            entity.SHIPMENT_ID               = model.SHIPMENT_ID;
            entity.ERP_ORDER                 = model.ERP_ORDER;
            entity.LEADING_STS               = model.LEADING_STS;
            entity.TRAILING_STS              = model.TRAILING_STS;
            entity.PROCESS_TYPE              = model.PROCESS_TYPE;
            entity.SHIPMENT_TYPE             = model.SHIPMENT_TYPE;
            entity.ROUTE                     = model.ROUTE;
            entity.SHIP_TO                   = model.SHIP_TO;
            entity.SHIP_TO_NAME              = model.SHIP_TO_NAME;
            entity.SHIP_TO_ADDRESS1          = model.SHIP_TO_ADDRESS1;
            entity.SHIP_TO_ADDRESS2          = model.SHIP_TO_ADDRESS2;
            entity.SHIP_TO_DISTRICT          = model.SHIP_TO_DISTRICT;
            entity.SHIP_TO_CITY              = model.SHIP_TO_CITY;
            entity.SHIP_TO_STATE             = model.SHIP_TO_STATE;
            entity.SHIP_TO_COUNTRY           = model.SHIP_TO_COUNTRY;
            entity.SHIP_TO_POSTAL_CODE       = model.SHIP_TO_POSTAL_CODE;
            entity.SHIP_TO_ATTENTION_TO      = model.SHIP_TO_ATTENTION_TO;
            entity.SHIP_TO_PHONE_NUM         = model.SHIP_TO_PHONE_NUM;
            entity.SHIP_TO_FAX_NUM           = model.SHIP_TO_FAX_NUM;
            entity.SHIP_TO_EMAIL_ADDRESS     = model.SHIP_TO_EMAIL_ADDRESS;
            entity.PRIORITY                  = model.PRIORITY;
            entity.USER_STAMP                = model.USER_STAMP;
            entity.DATE_TIME_STAMP           = model.DATE_TIME_STAMP;
            entity.REQUESTED_DELIVERY_DATE   = model.REQUESTED_DELIVERY_DATE;
            entity.REQUESTED_DELIVERY_TYPE   = model.REQUESTED_DELIVERY_TYPE;
            entity.SCHEDULED_SHIP_DATE       = model.SCHEDULED_SHIP_DATE;
            entity.ACTUAL_SHIP_DATE_TIME     = model.ACTUAL_SHIP_DATE_TIME;
            entity.ACTUAL_DELIVERY_DATE_TIME = model.ACTUAL_DELIVERY_DATE_TIME;
            entity.DELIVERY_NOTE             = model.DELIVERY_NOTE;
            entity.REJECTION_NOTE            = model.REJECTION_NOTE;
            entity.INTERNAL_WAVE_NUM         = model.INTERNAL_WAVE_NUM;
            entity.SHIP_DOCK                 = model.SHIP_DOCK;
            entity.ALLOCATE_COMPLETE         = model.ALLOCATE_COMPLETE;
            entity.TOTAL_QTY                 = model.TOTAL_QTY;
            entity.TOTAL_WEIGHT              = model.TOTAL_WEIGHT;
            entity.WEIGHT_UM                 = model.WEIGHT_UM;
            entity.TOTAL_VOLUME              = model.TOTAL_VOLUME;
            entity.VOLUME_UM                 = model.VOLUME_UM;
            entity.TOTAL_LINES               = model.TOTAL_LINES;
            entity.TOTAL_CONTAINERS          = model.TOTAL_CONTAINERS;
            entity.CARRIER                   = model.CARRIER;
            entity.CARRIER_SERVICE           = model.CARRIER_SERVICE;
            entity.USER_DEF1                 = model.USER_DEF1;
            entity.USER_DEF2                 = model.USER_DEF2;
            entity.USER_DEF3                 = model.USER_DEF3;
            entity.USER_DEF4                 = model.USER_DEF4;
            entity.USER_DEF5                 = model.USER_DEF5;
            entity.USER_DEF6                 = model.USER_DEF6;
            entity.USER_DEF7                 = model.USER_DEF7;
            entity.USER_DEF8                 = model.USER_DEF8;
            entity.BACK_ORDER_NUM            = model.BACK_ORDER_NUM;
            entity.LAST_WAVE_NUM             = model.LAST_WAVE_NUM;
            entity.GROUP_NUM                 = model.GROUP_NUM;
            entity.GROUP_INDEX               = model.GROUP_INDEX;
            entity.SIGN_VALUE                = model.SIGN_VALUE;
            entity.SHIPMENT_SUB_TYPE         = model.SHIPMENT_SUB_TYPE;
            entity.SHIPMENT_CATEGORY1        = model.SHIPMENT_CATEGORY1;
            entity.SHIPMENT_CATEGORY2        = model.SHIPMENT_CATEGORY2;
            entity.SHIPMENT_CATEGORY3        = model.SHIPMENT_CATEGORY3;
            entity.SHIPMENT_CATEGORY4        = model.SHIPMENT_CATEGORY4;
            entity.SHIPMENT_CATEGORY5        = model.SHIPMENT_CATEGORY5;
            entity.SHIPMENT_CATEGORY6        = model.SHIPMENT_CATEGORY6;
            entity.SHIPMENT_CATEGORY7        = model.SHIPMENT_CATEGORY7;
            entity.SHIPMENT_CATEGORY8        = model.SHIPMENT_CATEGORY8;
            entity.SHIP_TO_MOBILE            = model.SHIP_TO_MOBILE;

            m_Rep.Create(entity);
        }
コード例 #56
0
 public void AddGroupError(string error)
 {
     ValidationErrors.Add("groupFailedToImport", new List <string> {
         error
     });
 }
コード例 #57
0
        public bool ImportExcelData(string oper, string filePath, ref ValidationErrors errors)
        {
            bool rtn = true;

            var targetFile = new FileInfo(filePath);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(filePath);

            using (XLWorkbook wb = new XLWorkbook(filePath))
            {
                //第一个Sheet
                using (IXLWorksheet wws = wb.Worksheets.First())
                {
                    //对应列头
                    excelFile.AddMapping <WMS_Feed_ListModel>(x => x.FeedBillNum, "投料单号(业务)");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.ReleaseBillNum, "投料单号(系统)");
                    excelFile.AddMapping <WMS_Feed_ListModel>(x => x.Department, "投料部门");
                    excelFile.AddMapping <WMS_Feed_ListModel>(x => x.AssemblyPartCode, "总成物料");
                    excelFile.AddMapping <WMS_Feed_ListModel>(x => x.SubAssemblyPartCode, "投料物料");
                    excelFile.AddMapping <WMS_Feed_ListModel>(x => x.Lot, "批次号");
                    excelFile.AddMapping <WMS_Feed_ListModel>(x => x.FeedQty, "投料数量");
                    excelFile.AddMapping <WMS_Feed_ListModel>(x => x.BoxQty, "箱数");
                    excelFile.AddMapping <WMS_Feed_ListModel>(x => x.Capacity, "体积");
                    excelFile.AddMapping <WMS_Feed_ListModel>(x => x.InvName, "库房");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.SubInvId, "子库存");
                    excelFile.AddMapping <WMS_Feed_ListModel>(x => x.Remark, "备注");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.PrintStaus, "打印状态");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.PrintDate, "打印时间");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.PrintMan, "打印人");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.ConfirmStatus, "确认状态");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.ConfirmMan, "确认人");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.ConfirmDate, "确认时间");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.Attr1, "");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.Attr2, "");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.Attr3, "");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.Attr4, "");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.Attr5, "");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.CreatePerson, "创建人");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.CreateTime, "创建时间");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.ModifyPerson, "修改人");
                    //excelFile.AddMapping<WMS_Feed_ListModel>(x => x.ModifyTime, "修改时间");

                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_Feed_ListModel>(0);

                    //开启事务
                    using (DBContainer db = new DBContainer())
                    {
                        var tran     = db.Database.BeginTransaction();                      //开启事务
                        int rowIndex = 0;

                        //检查数据正确性
                        foreach (var row in excelContent)
                        {
                            rowIndex += 1;
                            string errorMessage = String.Empty;
                            var    model        = new WMS_Feed_ListModel();
                            model.Id          = row.Id;
                            model.FeedBillNum = row.FeedBillNum;
                            //model.ReleaseBillNum = row.ReleaseBillNum;
                            model.Department          = row.Department;
                            model.AssemblyPartCode    = row.AssemblyPartCode;
                            model.SubAssemblyPartCode = row.SubAssemblyPartCode;
                            model.FeedQty             = row.FeedQty;
                            model.BoxQty   = row.BoxQty;
                            model.Capacity = row.Capacity;
                            model.InvName  = row.InvName;
                            model.Lot      = row.Lot;
                            //model.SubInvId = row.SubInvId;
                            model.Remark = row.Remark;
                            //model.PrintStaus = row.PrintStaus;
                            //model.PrintDate = row.PrintDate;
                            //model.PrintMan = row.PrintMan;
                            //model.ConfirmStatus = row.ConfirmStatus;
                            //model.ConfirmMan = row.ConfirmMan;
                            //model.ConfirmDate = row.ConfirmDate;
                            //model.Attr1 = row.Attr1;
                            //model.Attr2 = row.Attr2;
                            //model.Attr3 = row.Attr3;
                            //model.Attr4 = row.Attr4;
                            //model.Attr5 = row.Attr5;
                            //model.CreatePerson = row.CreatePerson;
                            //model.CreateTime = row.CreateTime;
                            //model.ModifyPerson = row.ModifyPerson;
                            //model.ModifyTime = row.ModifyTime;

                            if (!String.IsNullOrEmpty(errorMessage))
                            {
                                rtn = false;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                            }

                            //执行额外的数据校验
                            try
                            {
                                AdditionalCheckExcelData(db, ref model);
                            }
                            catch (Exception ex)
                            {
                                rtn          = false;
                                errorMessage = ex.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                            }

                            //写入数据库
                            WMS_Feed_List entity = new WMS_Feed_List();
                            entity.Id          = model.Id;
                            entity.FeedBillNum = model.FeedBillNum;
                            //entity.ReleaseBillNum = model.ReleaseBillNum;
                            //entity.ReleaseBillNum = "TL" + DateTime.Now.ToString("yyyyMMddHHmmssff");打印时生成
                            entity.Department        = model.Department;
                            entity.AssemblyPartId    = model.AssemblyPartId;
                            entity.SubAssemblyPartId = model.SubAssemblyPartId;
                            entity.FeedQty           = model.FeedQty;
                            entity.BoxQty            = model.BoxQty;
                            entity.Capacity          = model.Capacity;
                            entity.InvId             = model.InvId;
                            entity.Lot = model.Lot;
                            //entity.SubInvId = model.SubInvId;
                            entity.Remark     = model.Remark;
                            entity.PrintStaus = "未打印";
                            //entity.PrintDate = model.PrintDate;
                            //entity.PrintMan = model.PrintMan;
                            entity.ConfirmStatus = "未确认";
                            //entity.ConfirmMan = model.ConfirmMan;
                            //entity.ConfirmDate = model.ConfirmDate;
                            //entity.Attr1 = model.Attr1;
                            //entity.Attr2 = model.Attr2;
                            //entity.Attr3 = model.Attr3;
                            //entity.Attr4 = model.Attr4;
                            //entity.Attr5 = model.Attr5;
                            //entity.CreatePerson = model.CreatePerson;
                            //entity.CreateTime = model.CreateTime;
                            //entity.ModifyPerson = model.ModifyPerson;
                            //entity.ModifyTime = model.ModifyTime;
                            entity.CreatePerson = oper;
                            entity.CreateTime   = DateTime.Now;
                            entity.ModifyPerson = oper;
                            entity.ModifyTime   = DateTime.Now;

                            db.WMS_Feed_List.Add(entity);
                            try
                            {
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                rtn = false;
                                //将当前报错的entity状态改为分离,类似EF的回滚(忽略之前的Add操作)
                                db.Entry(entity).State = System.Data.Entity.EntityState.Detached;
                                errorMessage           = ex.InnerException.InnerException.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                            }
                        }

                        if (rtn)
                        {
                            tran.Commit();                                      //必须调用Commit(),不然数据不会保存
                        }
                        else
                        {
                            tran.Rollback();                                        //出错就回滚
                        }
                    }
                }
                wb.Save();
            }

            return(rtn);
        }
コード例 #58
0
ファイル: SysPersonBLL.cs プロジェクト: Bryanlhx/permisson
        /// <summary>
        /// 编辑一个人员
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个人员</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysPerson entity)
        {
            /*
                           * 不操作 原有 现有
                           * 增加   原没 现有
                           * 删除   原有 现没
                           */
            if (entity == null)
            {
                return false;
            }
            if (CheckName(entity))
            {
                validationErrors.Add("用户名已被占用,请换一个新的用户名");
                return false;
            }

            int count = 1;
            SysPerson editEntity = repository.Edit(db, entity);

            List<string> addSysRoleId = new List<string>();
            List<string> deleteSysRoleId = new List<string>();
            DataOfDiffrent.GetDiffrent(entity.SysRoleId.GetIdSort(), entity.SysRoleIdOld.GetIdSort(), ref addSysRoleId, ref deleteSysRoleId);
            if (addSysRoleId != null && addSysRoleId.Count() > 0)
            {
                foreach (var item in addSysRoleId)
                {
                    SysRole sys = new SysRole { Id = item };
                    db.SysRole.Attach(sys);
                    editEntity.SysRole.Add(sys);
                    count++;
                }
            }
            if (deleteSysRoleId != null && deleteSysRoleId.Count() > 0)
            {
                List<SysRole> listEntity = new List<SysRole>();
                foreach (var item in deleteSysRoleId)
                {
                    SysRole sys = new SysRole { Id = item };
                    listEntity.Add(sys);
                    db.SysRole.Attach(sys);
                }
                foreach (SysRole item in listEntity)
                {
                    editEntity.SysRole.Remove(item);//查询数据库
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("编辑人员出错了");
            }
            return false;
        }
コード例 #59
0
 public void AddValidNotification(string legacyId)
 {
     ValidationErrors.Add(legacyId, new List <string>());
 }
コード例 #60
0
ファイル: SysPersonBLL.cs プロジェクト: Bryanlhx/permisson
 /// <summary>
 ///  创建人员集合
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entitys">人员集合</param>
 /// <returns></returns>
 public bool EditCollection(ref ValidationErrors validationErrors, IQueryable<SysPerson> entitys)
 {
     if (entitys != null)
     {
         try
         {
             int flag = 0, count = entitys.Count();
             if (count > 0)
             {
                 using (TransactionScope transactionScope = new TransactionScope())
                 {
                     foreach (var entity in entitys)
                     {
                         if (Edit(ref validationErrors, db, entity))
                         {
                             flag++;
                         }
                         else
                         {
                             Transaction.Current.Rollback();
                             return false;
                         }
                     }
                     if (count == flag)
                     {
                         transactionScope.Complete();
                         return true;
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             validationErrors.Add(ex.Message);
             ExceptionsHander.WriteExceptions(ex);
         }
     }
     return false;
 }