示例#1
0
        /// <summary>
        /// 保存表单
        /// </summary>
        /// <param name="keyValue"></param>
        /// <param name="entity">实体</param>
        /// <param name="moduleId">模块</param>
        public void SaveImportForm(string keyValue, CustomerEntity entity, string moduleId)
        {
            if (string.IsNullOrWhiteSpace(keyValue))
            {
                if (entity.FullName.Length <= 3)
                {
                    throw new Exception("客户名称不完整");
                }
                //System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"^([\u4e00-\u9fa5]*[((]?[\u4e00-\u9fa5]+[))]?[\u4e00-\u9fa5]*)$");
                //if (!reg.IsMatch(entity.FullName))
                //{
                //    throw new Exception("客户名称只能包含汉字和括弧");
                //}
                if (!ExistFullName(entity.FullName, keyValue))
                {
                    throw new Exception("客户信息已存在");
                }
            }

            try
            {
                service.SaveForm(keyValue, entity, moduleId);
                //创建搜索索引
                if (string.IsNullOrWhiteSpace(keyValue))
                {
                    CustomerLuceneNet.GetInstance().AddCustomer(entity.CustomerId);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// 定义公有方法提供一个全局访问点,同时你也可以定义公有属性来提供全局访问点
        /// </summary>
        /// <returns></returns>
        public static CustomerLuceneNet GetInstance()
        {
            // 当第一个线程运行到这里时,此时会对locker对象 "加锁",
            // 当第二个线程运行该方法时,首先检测到locker对象为"加锁"状态,该线程就会挂起等待第一个线程解锁
            // lock语句运行完之后(即线程运行完之后)会对该对象"解锁"
            lock (locker)
            {
                // 如果类的实例不存在则创建,否则直接返回
                if (uniqueInstance == null)
                {
                    uniqueInstance = new CustomerLuceneNet();
                }
            }

            return(uniqueInstance);
        }