Esempio n. 1
0
        public OutputData DoAction(IInputData input)
        {
            if (input.IsPost)
            {
                EasySearchInput esIn       = input.PostObject.Convert <EasySearchInput>();
                EasySearch      easySearch = PlugInFactoryManager.CreateInstance <EasySearch>(
                    EasySearchPlugInFactory.REG_NAME, esIn.RegName);
                using (easySearch as IDisposable)
                {
                    IEnumerable <IDecoderItem> result = easySearch.Search(esIn.Text, esIn.RefFields);

                    //EasySearchOutput output = new EasySearchOutput(result);
                    IDecoderItem[] resultArr;
                    if (result != null)
                    {
                        resultArr = result.ToArray();
                    }
                    else
                    {
                        resultArr = new CodeItem[0];
                    }
                    return(OutputData.CreateToolkitObject(resultArr));
                }
            }

            TkDebug.ThrowImpossibleCode(this);
            return(null);
        }
Esempio n. 2
0
        IParamBuilder ISearch.Search(EasySearch easySearch, SearchField searchType,
                                     TkDbContext context, IFieldInfo fieldName, string fieldValue)
        {
            TkDebug.AssertArgumentNull(easySearch, "easySearch", this);
            TkDebug.AssertArgumentNull(context, "context", this);
            TkDebug.AssertArgumentNull(fieldName, "fieldName", this);

            switch (searchType)
            {
            case SearchField.Value:
            case SearchField.DefaultValue:
                return(LikeSearch.Instance.Search(easySearch, searchType, context,
                                                  easySearch.ValueField, fieldValue));

            case SearchField.Name:
                return(SimpleSearch.Instance.Search(easySearch, searchType, context,
                                                    easySearch.NameField, fieldValue));

            case SearchField.Pinyin:
                return(LikeSearch.Instance.Search(easySearch, searchType, context,
                                                  easySearch.PinyinField, fieldValue.ToUpper(ObjectUtil.SysCulture)));
            }
            TkDebug.ThrowImpossibleCode(this);
            return(null);
        }
Esempio n. 3
0
        public IParamBuilder Search(EasySearch easySearch, SearchField searchType,
                                    TkDbContext context, IFieldInfo fieldName, string fieldValue)
        {
            TkDebug.AssertArgumentNull(easySearch, "easySearch", this);
            TkDebug.AssertArgumentNull(context, "context", this);
            TkDebug.AssertArgumentNull(fieldName, "fieldName", this);
            TkDebug.AssertArgumentNull(fieldValue, "fieldValue", this);

            switch (searchType)
            {
            case SearchField.Value:
            case SearchField.DefaultValue:
                return(GetQueryParamBuilder(context, easySearch.ValueField, fieldValue));

            case SearchField.Name:
                return(SimpleSearch.Instance.Search(easySearch, searchType,
                                                    context, easySearch.NameField, fieldValue));

            case SearchField.Pinyin:
                if (easySearch.PinyinField == null)
                {
                    return(ClassicPYSearch.Instance.Search(easySearch, searchType,
                                                           context, easySearch.NameField, fieldValue));
                }
                else
                {
                    return(LikeSearch.Instance.Search(easySearch, searchType,
                                                      context, easySearch.PinyinField, fieldValue));
                }
            }
            TkDebug.ThrowImpossibleCode(this);
            return(null);
        }
Esempio n. 4
0
        IParamBuilder ISearch.Search(EasySearch easySearch, SearchField searchType,
                                     TkDbContext context, IFieldInfo fieldName, string fieldValue)
        {
            TkDebug.AssertArgumentNull(context, "context", this);
            TkDebug.AssertArgumentNull(fieldName, "fieldName", this);

            if (string.IsNullOrEmpty(fieldValue))
            {
                return(null);
            }

            fieldValue = StringUtil.EscapeAposString(fieldValue);
            string sql;

            if (fieldValue.IndexOfAny(WideChars) != -1)
            {
                fieldValue = StringUtil.EscapeSqlString(fieldValue);
                sql        = string.Format(ObjectUtil.SysCulture,
                                           "(({0} LIKE '{1}%' ESCAPE '\\') OR ({0} LIKE '{2}%' ESCAPE '\\') OR ({3}))",
                                           context.EscapeName(fieldName.FieldName), fieldValue.ToUpper(ObjectUtil.SysCulture),
                                           fieldValue.ToLower(ObjectUtil.SysCulture),
                                           PinYinUtil.GetCharFullCondition(context, fieldName.FieldName, fieldValue));
            }
            else
            {
                sql = string.Format(ObjectUtil.SysCulture,
                                    "(({0} LIKE '{1}%') OR ({0} LIKE '{2}%') OR ({3}))",
                                    context.EscapeName(fieldName.FieldName), fieldValue.ToUpper(ObjectUtil.SysCulture),
                                    fieldValue.ToLower(ObjectUtil.SysCulture),
                                    PinYinUtil.GetCharFullCondition(context, fieldName.FieldName, fieldValue));
            }
            return(SqlParamBuilder.CreateSql(sql));
        }
Esempio n. 5
0
        protected override FieldErrorInfo CheckError(IInputData inputData,
                                                     string value, int position, params object[] args)
        {
            DataRow row = GetPostRow(inputData, position);

            string hdFieldValue = row[HdFieldName].ToString();

            if (string.IsNullOrEmpty(value) && string.IsNullOrEmpty(hdFieldValue))
            {
                return(null);
            }

            EasySearch easySearch = PlugInFactoryManager.CreateInstance <EasySearch>(
                EasySearchPlugInFactory.REG_NAME, fRegName);
            string newValue           = value;
            EasySearchErrorType error = easySearch.CheckName(hdFieldValue, ref newValue, args);

            if (error == EasySearchErrorType.None)
            {
                if (newValue != value)
                {
                    if (string.IsNullOrEmpty(newValue))
                    {
                        row[Field.NickName] = DBNull.Value;
                    }
                    else
                    {
                        row[Field.NickName] = newValue;
                    }
                }
                return(null);
            }
            return(CreateErrorObject(error));
        }
Esempio n. 6
0
        IParamBuilder ISearch.Search(EasySearch easySearch, SearchField searchType,
                                     TkDbContext context, IFieldInfo fieldName, string fieldValue)
        {
            TkDebug.AssertArgumentNull(context, "context", this);
            TkDebug.AssertArgumentNull(fieldName, "fieldName", this);

            if (string.IsNullOrEmpty(fieldValue))
            {
                return(null);
            }
            else
            {
                return(SqlParamBuilder.CreateSingleSql(context, fieldName, "LIKE", fieldValue + "%"));
            }
        }
Esempio n. 7
0
        public override OutputData DoAction(IInputData input)
        {
            string     regName    = input.QueryString["RegName"];
            EasySearch easySearch = PlugInFactoryManager.CreateInstance <EasySearch>(
                EasySearchPlugInFactory.REG_NAME, regName);
            BaseDbEasySearch dbSearch = easySearch as BaseDbEasySearch;

            if (dbSearch != null)
            {
                if (!string.IsNullOrEmpty(dbSearch.ContextName))
                {
                    Context = DbContextUtil.CreateDbContext(dbSearch.ContextName);
                }
            }
            IConfigCreator <ITree> creator = easySearch as IConfigCreator <ITree>;

            TkDebug.AssertNotNull(creator, string.Format(ObjectUtil.SysCulture,
                                                         "类型为{0},注册名为{1}的EasySearch需要实现创建ITree的接口",
                                                         easySearch.GetType(), regName), easySearch);
            Tree = creator.CreateObject(this);

            return(base.DoAction(input));
        }
        public OutputData DoAction(IInputData input)
        {
            string     regName    = input.QueryString["RegName"];
            EasySearch easySearch = PlugInFactoryManager.CreateInstance <EasySearch>(
                EasySearchPlugInFactory.REG_NAME, regName);
            IConfigCreator <ITree> creator = easySearch as IConfigCreator <ITree>;
            string url;

            if (creator != null)
            {
                url = string.Format(ObjectUtil.SysCulture,
                                    "~/c/source/C/EasySearchTreeDialog?RegName={0}&InitValue={1}",
                                    regName, input.QueryString["InitValue"]);
            }
            else
            {
                url = string.Format(ObjectUtil.SysCulture,
                                    "~/c/source/C/EasySearchDialog?RegName={0}&RefValue={1}&Addition={2}",
                                    regName, input.QueryString["RefValue"], input.QueryString["Addition"]);
            }

            return(OutputData.Create(url));
        }
Esempio n. 9
0
        public bool Search(EasySearch easySearch, SearchField searchType,
                           string dataValue, string searchValue)
        {
            if (string.IsNullOrEmpty(searchValue))
            {
                return(true);
            }

            switch (searchType)
            {
            case SearchField.DefaultValue:
                return(true);

            case SearchField.Value:
                return(dataValue.StartsWith(searchValue));

            case SearchField.Name:
                return(dataValue.IndexOf(searchValue) >= 0);

            case SearchField.Pinyin:
                return(dataValue.StartsWith(searchValue.ToUpper(ObjectUtil.SysCulture)));
            }
            return(false);
        }
Esempio n. 10
0
        public MultipleEasySearch(EasySearch easySearch)
        {
            TkDebug.AssertArgumentNull(easySearch, "easySearch", null);

            fEasySearch = easySearch;
        }