コード例 #1
0
        /// <summary>
        /// 规则名称不能重复
        /// </summary>
        /// <param name="fullName">名称</param>
        /// <param name="keyValue">主键</param>
        /// <returns></returns>
        public bool ExistFullName(string fullName, string keyValue)
        {
            try
            {
                var strSql = new StringBuilder();
                strSql.Append(" SELECT t.F_RuleId FROM LR_Base_CodeRule t WHERE t.F_DeleteMark = 0 AND t.F_FullName = @fullName ");
                if (!string.IsNullOrEmpty(keyValue))
                {
                    strSql.Append(" AND t.F_RuleId != @keyValue  ");
                }
                CodeRuleEntity entity = this.BaseRepository().FindEntity <CodeRuleEntity>(strSql.ToString(), new { fullName = fullName, keyValue = keyValue });

                return(entity == null ? true : false);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
コード例 #2
0
ファイル: CodeRuleBLL.cs プロジェクト: IvanMeng/LearunTC
 /// <summary>
 /// 占用单据号
 /// </summary>
 /// <param name="enCode">单据编码</param>
 /// <param name="userId">用户ID</param>
 /// <returns>true/false</returns>
 public void UseRuleSeed(string enCode, string userId = "")
 {
     try
     {
         CodeRuleEntity codeRuleSeedEntity = GetEntityByCode(enCode);
         if (codeRuleSeedEntity != null)
         {
             if (string.IsNullOrEmpty(userId))
             {
                 UserInfo userInfo = LoginUserInfo.Get();
                 //删除用户已经用掉的种子
                 codeRuleService.DeleteSeed(userInfo.userId, codeRuleSeedEntity.F_RuleId);
             }
             else
             {
                 codeRuleService.DeleteSeed(userId, codeRuleSeedEntity.F_RuleId);
             }
             cache.Remove(cacheKeySeed + codeRuleSeedEntity.F_RuleId, CacheId.codeRule);
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// 保存规则表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="codeRuleEntity">规则实体</param>
 /// <returns></returns>
 public void SaveEntity(string keyValue, CodeRuleEntity codeRuleEntity, UserInfo userInfo = null)
 {
     try
     {
         if (!string.IsNullOrEmpty(keyValue))
         {
             codeRuleEntity.Modify(keyValue, userInfo);
             this.BaseRepository().Update(codeRuleEntity);
         }
         else
         {
             codeRuleEntity.Create(userInfo);
             this.BaseRepository().Insert(codeRuleEntity);
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowServiceException(ex);
         }
     }
 }
コード例 #4
0
ファイル: CodeRuleService.cs プロジェクト: IvanMeng/LearunTC
        /// <summary>
        /// 保存规则表单(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="codeRuleEntity">规则实体</param>
        /// <param name="userInfo">当前登录用户</param>
        /// <returns></returns>
        public void SaveEntity2(string keyValue, CodeRuleEntity codeRuleEntity, UserInfo userInfo = null)
        {
            var db = this.BaseRepository().BeginTrans();

            try
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    codeRuleEntity.Modify(keyValue, userInfo);
                    db.Update(codeRuleEntity);
                }
                else
                {
                    codeRuleEntity.Create(userInfo);
                    db.Insert(codeRuleEntity);
                }
                db.Delete <CodeRuleSeedEntity>(t => t.F_RuleId == codeRuleEntity.F_RuleId);
                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
コード例 #5
0
ファイル: CodeRuleBLL.cs プロジェクト: IvanMeng/LearunTC
 /// <summary>
 /// 删除规则
 /// </summary>
 /// <param name="keyValue">主键</param>
 public void VirtualDelete(string keyValue)
 {
     try
     {
         CodeRuleEntity entity = codeRuleService.GetEntity(keyValue);
         cache.Remove(cacheKey + entity.F_EnCode, CacheId.codeRule);
         codeRuleService.VirtualDelete(keyValue);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
コード例 #6
0
ファイル: CodeRuleBLL.cs プロジェクト: IvanMeng/LearunTC
 /// <summary>
 /// 保存规则表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="codeRuleEntity">规则实体</param>
 /// <returns></returns>
 public void SaveEntity(string keyValue, CodeRuleEntity codeRuleEntity)
 {
     try
     {
         if (!string.IsNullOrEmpty(keyValue))
         {
             CodeRuleEntity entity = codeRuleService.GetEntity(keyValue);
             cache.Remove(cacheKey + entity.F_EnCode, CacheId.codeRule);
         }
         codeRuleService.SaveEntity(keyValue, codeRuleEntity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
コード例 #7
0
 /// <summary>
 /// 删除规则
 /// </summary>
 /// <param name="keyValue">主键</param>
 public void VirtualDelete(string keyValue)
 {
     try
     {
         CodeRuleEntity entity = new CodeRuleEntity()
         {
             F_RuleId     = keyValue,
             F_DeleteMark = 1
         };
         this.BaseRepository().Update(entity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowServiceException(ex);
         }
     }
 }
コード例 #8
0
ファイル: CodeRuleBLL.cs プロジェクト: IvanMeng/LearunTC
 /// <summary>
 /// 规则实体
 /// </summary>
 /// <param name="enCode">规则编码</param>
 /// <returns></returns>
 public CodeRuleEntity GetEntityByCode(string enCode)
 {
     try
     {
         CodeRuleEntity codeRuleEntity = cache.Read <CodeRuleEntity>(cacheKey + enCode, CacheId.codeRule);
         if (codeRuleEntity == null)
         {
             codeRuleEntity = codeRuleService.GetEntityByCode(enCode);
             cache.Write <CodeRuleEntity>(cacheKey + enCode, codeRuleEntity, CacheId.codeRule);
         }
         return(codeRuleEntity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
コード例 #9
0
ファイル: CodeRuleBLL.cs プロジェクト: IvanMeng/LearunTC
        /// <summary>
        /// 获得指定模块或者编号的单据号
        /// </summary>
        /// <param name="enCode">编码</param>
        /// <param name="userId">用户ID</param>
        /// <returns>单据号</returns>
        public string GetBillCode(string enCode, string userId = "")
        {
            try
            {
                string billCode     = "";    //单据号
                string nextBillCode = "";    //单据号
                bool   isOutTime    = false; //是否已过期


                CodeRuleEntity coderuleentity = GetEntityByCode(enCode);
                if (coderuleentity != null)
                {
                    UserInfo userInfo = null;
                    if (string.IsNullOrEmpty(userId))
                    {
                        userInfo = LoginUserInfo.Get();
                    }
                    else
                    {
                        UserEntity userEntity = userIBLL.GetEntityByUserId(userId);
                        userInfo = new UserInfo
                        {
                            userId       = userEntity.F_UserId,
                            enCode       = userEntity.F_EnCode,
                            password     = userEntity.F_Password,
                            secretkey    = userEntity.F_Secretkey,
                            realName     = userEntity.F_RealName,
                            nickName     = userEntity.F_NickName,
                            headIcon     = userEntity.F_HeadIcon,
                            gender       = userEntity.F_Gender,
                            mobile       = userEntity.F_Mobile,
                            telephone    = userEntity.F_Telephone,
                            email        = userEntity.F_Email,
                            oICQ         = userEntity.F_OICQ,
                            weChat       = userEntity.F_WeChat,
                            companyId    = userEntity.F_CompanyId,
                            departmentId = userEntity.F_DepartmentId,
                            openId       = userEntity.F_OpenId,
                            isSystem     = userEntity.F_SecurityLevel == 1 ? true : false
                        };
                    }

                    int nowSerious = 0;
                    List <CodeRuleFormatModel> codeRuleFormatList = coderuleentity.F_RuleFormatJson.ToList <CodeRuleFormatModel>();
                    string dateFormatStr = "";
                    foreach (CodeRuleFormatModel codeRuleFormatEntity in codeRuleFormatList)
                    {
                        switch (codeRuleFormatEntity.itemType.ToString())
                        {
                        //自定义项
                        case "0":
                            billCode     = billCode + codeRuleFormatEntity.formatStr;
                            nextBillCode = nextBillCode + codeRuleFormatEntity.formatStr;
                            break;

                        //日期
                        case "1":
                            //日期字符串类型
                            dateFormatStr = codeRuleFormatEntity.formatStr;
                            billCode      = billCode + DateTime.Now.ToString(codeRuleFormatEntity.formatStr.Replace("m", "M"));
                            nextBillCode  = nextBillCode + DateTime.Now.ToString(codeRuleFormatEntity.formatStr.Replace("m", "M"));
                            break;

                        //流水号
                        case "2":
                            CodeRuleSeedEntity maxSeed            = null;
                            CodeRuleSeedEntity codeRuleSeedEntity = null;


                            List <CodeRuleSeedEntity> seedList = GetSeedList(coderuleentity.F_RuleId, userInfo);
                            maxSeed = seedList.Find(t => t.F_UserId.IsEmpty());


                            int seedStep  = codeRuleFormatEntity.stepValue == null ? 1 : int.Parse(codeRuleFormatEntity.stepValue.ToString());   //如果步长为空默认1
                            int initValue = codeRuleFormatEntity.initValue == null ? 1 : int.Parse(codeRuleFormatEntity.initValue.ToString());   //如果初始值为空默认1

                            if (maxSeed.IsInit)
                            {
                                maxSeed.F_SeedValue = initValue;
                            }

                            #region 处理流水号归0
                            // 首先确定最大种子是否未归0的
                            if (dateFormatStr.Contains("dd"))
                            {
                                if ((maxSeed.F_ModifyDate).ToDateString() != DateTime.Now.ToString("yyyy-MM-dd"))
                                {
                                    isOutTime            = true;
                                    nowSerious           = initValue;
                                    maxSeed.F_SeedValue  = initValue + seedStep;
                                    maxSeed.F_ModifyDate = DateTime.Now;
                                }
                            }
                            else if (dateFormatStr.Contains("mm"))
                            {
                                if (((DateTime)maxSeed.F_ModifyDate).ToString("yyyy-MM") != DateTime.Now.ToString("yyyy-MM"))
                                {
                                    isOutTime            = true;
                                    nowSerious           = initValue;
                                    maxSeed.F_SeedValue  = initValue + seedStep;
                                    maxSeed.F_ModifyDate = DateTime.Now;
                                }
                            }
                            else if (dateFormatStr.Contains("yy"))
                            {
                                if (((DateTime)maxSeed.F_ModifyDate).ToString("yyyy") != DateTime.Now.ToString("yyyy"))
                                {
                                    isOutTime            = true;
                                    nowSerious           = initValue;
                                    maxSeed.F_SeedValue  = initValue + seedStep;
                                    maxSeed.F_ModifyDate = DateTime.Now;
                                }
                            }
                            #endregion
                            // 查找当前用户是否已有之前未用掉的种子做更新
                            codeRuleSeedEntity = seedList.Find(t => t.F_UserId == userInfo.userId && t.F_RuleId == coderuleentity.F_RuleId && (t.F_CreateDate).ToDateString() == DateTime.Now.ToString("yyyy-MM-dd"));
                            string keyvalue = codeRuleSeedEntity == null ? "" : codeRuleSeedEntity.F_RuleSeedId;
                            if (isOutTime)
                            {
                                SaveSeed(maxSeed.F_RuleSeedId, maxSeed, userInfo);
                            }
                            else if (codeRuleSeedEntity == null)
                            {
                                nowSerious           = (int)maxSeed.F_SeedValue;
                                maxSeed.F_SeedValue += seedStep;    //种子加步长
                                maxSeed.Modify(maxSeed.F_RuleSeedId, userInfo);
                                SaveSeed(maxSeed.F_RuleSeedId, maxSeed, userInfo);
                            }
                            else
                            {
                                nowSerious = (int)codeRuleSeedEntity.F_SeedValue;
                            }

                            codeRuleSeedEntity = new CodeRuleSeedEntity();
                            codeRuleSeedEntity.Create(userInfo);
                            codeRuleSeedEntity.F_SeedValue = nowSerious;
                            codeRuleSeedEntity.F_UserId    = userInfo.userId;
                            codeRuleSeedEntity.F_RuleId    = coderuleentity.F_RuleId;
                            SaveSeed(keyvalue, codeRuleSeedEntity, userInfo);
                            // 最大种子已经过期
                            string seriousStr     = new string('0', (int)(codeRuleFormatEntity.formatStr.Length - nowSerious.ToString().Length)) + nowSerious.ToString();
                            string NextSeriousStr = new string('0', (int)(codeRuleFormatEntity.formatStr.Length - nowSerious.ToString().Length)) + maxSeed.F_SeedValue.ToString();
                            billCode     = billCode + seriousStr;
                            nextBillCode = nextBillCode + NextSeriousStr;
                            break;

                        //部门
                        case "3":
                            DepartmentEntity departmentEntity = departmentIBLL.GetEntity(userInfo.companyId, userInfo.departmentId);
                            if (codeRuleFormatEntity.formatStr == "code")
                            {
                                billCode     = billCode + departmentEntity.F_EnCode;
                                nextBillCode = nextBillCode + departmentEntity.F_EnCode;
                            }
                            else
                            {
                                billCode     = billCode + departmentEntity.F_FullName;
                                nextBillCode = nextBillCode + departmentEntity.F_FullName;
                            }
                            break;

                        //公司
                        case "4":
                            CompanyEntity companyEntity = companyIBLL.GetEntity(userInfo.companyId);
                            if (codeRuleFormatEntity.formatStr == "code")
                            {
                                billCode     = billCode + companyEntity.F_EnCode;
                                nextBillCode = nextBillCode + companyEntity.F_EnCode;
                            }
                            else
                            {
                                billCode     = billCode + companyEntity.F_FullName;
                                nextBillCode = nextBillCode + companyEntity.F_FullName;
                            }
                            break;

                        //用户
                        case "5":
                            if (codeRuleFormatEntity.formatStr == "code")
                            {
                                billCode     = billCode + userInfo.enCode;
                                nextBillCode = nextBillCode + userInfo.enCode;
                            }
                            else
                            {
                                billCode     = billCode + userInfo.account;
                                nextBillCode = nextBillCode + userInfo.account;
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    coderuleentity.F_CurrentNumber = nextBillCode;
                    SaveEntity(coderuleentity.F_RuleId, coderuleentity, userInfo);
                }
                return(billCode);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }