Ejemplo n.º 1
0
        public static RegNameList <ListTabSheet> CreateTabSheets(this CodeTable codeTable,
                                                                 TkDbContext context, IFieldInfo field)
        {
            DataSet ds = new DataSet()
            {
                Locale = ObjectUtil.SysCulture
            };

            using (ds)
            {
                codeTable.Fill(ds, context);
                if (ds.Tables.Count == 0)
                {
                    return(null);
                }
                DataTable table = ds.Tables[0];
                if (table.Rows.Count == 0)
                {
                    return(null);
                }

                RegNameList <ListTabSheet> result = new RegNameList <ListTabSheet>();
                foreach (DataRow row in table.Rows)
                {
                    object        value   = row[DecoderConst.CODE_NICK_NAME];
                    IParamBuilder builder = SqlParamBuilder.CreateEqualSql(context, field,
                                                                           value);
                    ListTabSheet tab = new ListTabSheet(value.ToString(),
                                                        row[DecoderConst.NAME_NICK_NAME].ToString(), builder);
                    result.Add(tab);
                }

                return(result);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 public DataRightEventArgs(TkDbContext context, IUserInfo user,
                           IFieldInfoIndexer fieldIndexer, IPageStyle style, DataRow row)
     : base(context, user, fieldIndexer)
 {
     Style = style;
     Row   = row;
 }
Ejemplo n.º 4
0
        public static void ExcelImport(TkDbContext context, string strFileName,
                                       Tk5ListMetaData metaData, ImportResultData result)
        {
            string sheetName = metaData.Table.TableDesc;
            ISheet sheet     = null;

            string fileExt = Path.GetExtension(strFileName).ToLower(ObjectUtil.SysCulture);

            using (FileStream file = new FileStream(strFileName, FileMode.Open, FileAccess.Read))
            {
                if (fileExt == ".xls")
                {
                    HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);
                    sheet = hssfworkbook.GetSheet(sheetName);
                }
                else if (fileExt == ".xlsx")
                {
                    XSSFWorkbook xssfworkbook = new XSSFWorkbook(file);
                    sheet = xssfworkbook.GetSheet(sheetName);
                }
                else
                {
                    throw new WebPostException("上传的文件不是Excel文件,请确认上传文件的格式");
                }
            }
            if (sheet != null)
            {
                SheetImport(context, metaData, sheet, result);
            }
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        protected override IParamBuilder CreateActiveFilter(TkDbContext context)
        {
            string sql = string.Format(ObjectUtil.SysCulture, "{0} IS NULL OR {0} <> 1",
                                       context.EscapeName(DecoderConst.DEL_FIELD_NAME));

            return(SqlParamBuilder.CreateSql(sql));
        }
Ejemplo n.º 8
0
        protected override DataTable FetchRows(TkDbContext context, DataSet dataSet,
                                               IParamBuilder builder, int topCount)
        {
            SqlSelector selector = new SqlSelector(context, dataSet);

            using (selector)
            {
                IParamBuilder addBuilder = CreateAdditionCondition(context, fScheme);
                builder = ParamBuilder.CreateParamBuilder(builder, addBuilder);
                string whereSql;
                if (builder == null)
                {
                    whereSql = string.Empty;
                }
                else
                {
                    whereSql = "WHERE " + builder.Sql;
                }

                TableSchemeData schemeData = TableSchemeData.Create(context, fScheme);
                var             result     = context.ContextConfig.GetListSql(schemeData.SelectFields,
                                                                              GetTableName(context), schemeData.KeyFieldArray,
                                                                              whereSql, OrderBy, 0, topCount);
                ISimpleAdapter adapter = selector;
                adapter.SetSql(result.ListSql, builder);
                context.ContextConfig.SetListData(result, adapter, dataSet, 0, TopCount, EASYSEARCH_TABLE_NAME);

                return(dataSet.Tables[EASYSEARCH_TABLE_NAME]);
            }
        }
Ejemplo n.º 9
0
        protected virtual IParamBuilder CreateAdditionCondition(TkDbContext context, IFieldInfoIndexer indexer)
        {
            TkDebug.AssertArgumentNull(context, "context", this);
            TkDebug.AssertArgumentNull(indexer, "indexer", this);

            ParamBuilderContainer result = new ParamBuilderContainer();

            if (FilterSql != null)
            {
                string sql = Expression.Execute(FilterSql, context, indexer);
                result.Add(sql);
            }
            if (DataRight != null)
            {
                TkDebug.ThrowIfNoGlobalVariable();
                IUserInfo     userInfo = BaseGlobalVariable.Current.UserInfo;
                IParamBuilder builder  = DataRight.GetListSql(new ListDataRightEventArgs(context, userInfo, indexer));
                result.Add(builder);
            }
            if (ActiveData != null)
            {
                IParamBuilder builder = ActiveData.CreateParamBuilder(context, indexer);
                result.Add(builder);
            }
            if (result.IsEmpty)
            {
                return(null);
            }
            return(result);
        }
Ejemplo n.º 10
0
        public static IParamBuilder CreateLikeSql(TkDbContext context, IFieldInfo fieldName,
                                                  string likeValue, string exceptValue)
        {
            CodeLikeParamBuilder builder = new CodeLikeParamBuilder();

            return(builder.InternalCreateLikeSql(context, fieldName, likeValue, exceptValue));
        }
Ejemplo n.º 11
0
        protected override FieldErrorInfo CheckError(IInputData inputData, string value,
                                                     int position, params object[] args)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }
            string original = null;

            try
            {
                DataRow row = HostDataSet.Tables[TableName].Rows[position];
                original = row[Field.NickName, DataRowVersion.Original].ToString();
            }
            catch
            {
            }
            if (!string.IsNullOrEmpty(original) && original == value)
            {
                return(null);
            }
            else
            {
                TkDbContext context = ObjectUtil.ConfirmQueryObject <TkDbContext>(this, args);

                IParamBuilder builder = SqlParamBuilder.CreateEqualSql(context, Field, value);
                int           count   = DbUtil.ExecuteScalar("SELECT COUNT(*) FROM " + TableName,
                                                             context, builder).Value <int>();
                if (count > 0)
                {
                    return(CreateErrorObject(Message));
                }
                return(null);
            }
        }
Ejemplo n.º 12
0
        protected override DataTable FillDbData(TkDbContext context, DataSet dataSet)
        {
            using (SqlSelector selector = new SqlSelector(context, dataSet))
            {
                TableSchemeData       data      = new TableSchemeData(context, Scheme);
                ParamBuilderContainer container = new ParamBuilderContainer();
                if (FilterSql != null)
                {
                    string filter = Expression.Execute(FilterSql, selector);
                    container.Add(filter);
                }
                container.Add(CreateActiveFilter(context));

                string tableName = Scheme.TableName;
                string sql       = string.Format(ObjectUtil.SysCulture, "SELECT {0} FROM {1}",
                                                 data.SelectFields, context.EscapeName(tableName));
                string regName = RegName;
                selector.Select(regName, sql, container, OrderBy);
                DataTable dataTable = dataSet.Tables[regName];

                DataColumn idColumn = dataTable.Columns[fDisplay.Id.NickName];
                idColumn.ColumnName = DecoderConst.CODE_NICK_NAME;
                dataTable.Columns[fDisplay.Name.NickName].ColumnName = DecoderConst.NAME_NICK_NAME;

                if (NameExpression != "{Name}")
                {
                    foreach (DataRow row in dataTable.Rows)
                    {
                        row[DecoderConst.NAME_NICK_NAME] = InternalExpression.Execute(row);
                    }
                }
                return(dataTable);
            }
        }
Ejemplo n.º 13
0
 protected override string ConvertValue(TkDbContext context, string value)
 {
     if (fCodeTable.ContainsKey(value))
     {
         return(fCodeTable[value].Value);
     }
     throw new ToolkitException(string.Format(ObjectUtil.SysCulture,
                                              "{0}不是一个有效的代码,请从模板的下拉框选择", value), this);
 }
Ejemplo n.º 14
0
        private IParamBuilder CreateRefBuilder(TkDbContext context, EasySearchRefField field)
        {
            IFieldInfo fieldInfo = SourceScheme[field.NickName];

            if (fieldInfo != null)
            {
                return(SqlParamBuilder.CreateEqualSql(context, fieldInfo, field.Value));
            }
            return(null);
        }
Ejemplo n.º 15
0
        protected override DataRow FetchRow(string code, TkDbContext context, DataSet dataSet)
        {
            TempSource    source   = new TempSource(dataSet, context);
            TableSelector selector = new TableSelector(fScheme, source);

            using (selector)
            {
                return(selector.TrySelectRowWithKeys(code));
            }
        }
Ejemplo n.º 16
0
        private void SetDataSet(object userId)
        {
            fDataSet = new DataSet {
                Locale = CultureInfo.CurrentCulture
            };
            TkDbContext context = DbContextUtil.CreateDefault();

            using (context)
            {
                IParamBuilder builder = SqlParamBuilder.CreateEqualSql(context, "USER_ID", TkDataType.String, userId);
                fAdmin = DbUtil.ExecuteScalar("SELECT USER_ADMIN FROM UR_USERS", context, builder).ToString() == "1";
                SqlSelector selector = new SqlSelector(context, fDataSet);
                using (selector)
                {
                    string userIdName = context.GetSqlParamName("USER_ID");
                    string sql        = string.Format(ObjectUtil.SysCulture, FUNC_SQL, userIdName,
                                                      context.ContextConfig.GetFunction("LENGTH", "FN_TREE_LAYER"));
                    selector.Select("SYS_FUNCTION", sql, builder.Parameters);

                    Dictionary <int, FunctionItem> idFunctions = new Dictionary <int, FunctionItem>();

                    DataTable table = fDataSet.Tables["SYS_FUNCTION"];
                    foreach (DataRow row in table.Rows)
                    {
                        FunctionItem item = new FunctionItem(row);
                        if (item.IsLeaf)
                        {
                            try
                            {
                                idFunctions.Add(item.Id, item);
                                fFunctions.Add(item.Key, item);
                            }
                            catch
                            {
                            }
                        }
                    }

                    sql = string.Format(ObjectUtil.SysCulture, SUB_FUNC_SQL, userIdName);
                    selector.Select("SYS_SUB_FUNC", sql, builder.Parameters);
                    table = fDataSet.Tables["SYS_SUB_FUNC"];
                    var group = from item in table.AsEnumerable()
                                group item by item.Field <int>("FnId");

                    foreach (var groupItem in group)
                    {
                        FunctionItem item;
                        if (idFunctions.TryGetValue(groupItem.Key, out item))
                        {
                            item.AddSubFunctions(groupItem);
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
        protected internal BaseSqlEasySearch(string sql, string idField, string nameField,
                                             TkDbContext context)
            : base(new SqlProxyScheme(DbUtil.CreateSqlTableScheme(sql, TABLE_NAME,
                                                                  idField, context), idField, nameField),
                   StringUtil.GetNickName(idField), StringUtil.GetNickName(nameField), false)
        {
            fSql = sql;
            TableSchemeData schemeData = TableSchemeData.Create(context, ProxyScheme);

            fSelectFields = schemeData.SelectFields;
        }
Ejemplo n.º 18
0
 public void ReadColumn(DataRow row, IRow cellRow, TkDbContext context)
 {
     try
     {
         row[FieldInfo.NickName] = ReadColumn(cellRow, context);
     }
     catch (Exception ex)
     {
         throw new ImportConvertException(FieldInfo.NickName, cellRow.RowNum, ex.Message, ex);
     }
 }
Ejemplo n.º 19
0
        protected override DataRow FetchRow(string code, TkDbContext context, DataSet dataSet)
        {
            SqlSelector selector = new SqlSelector(context, dataSet);

            using (selector)
            {
                IParamBuilder builder = SqlParamBuilder.CreateEqualSql(context, ValueField, code);
                String        sql     = string.Format("SELECT {0} FROM ({1}) {2}", fSelectFields, fSql, TABLE_NAME);
                return(selector.TrySelectRow(TABLE_NAME, sql, builder));
            }
        }
Ejemplo n.º 20
0
        protected override IParamBuilder GetRefParamBuilder(TkDbContext context, List <EasySearchRefField> refFields)
        {
            if (refFields == null || refFields.Count == 0)
            {
                return(null);
            }

            var builders = from item in refFields
                           select CreateRefBuilder(context, item);

            return(ParamBuilder.CreateParamBuilder(builders));
        }
Ejemplo n.º 21
0
 private void GetContext(object[] args, out TkDbContext context, out bool createContext)
 {
     context       = ObjectUtil.QueryObject <TkDbContext>(args);
     createContext = false;
     if (!string.IsNullOrEmpty(ContextName))
     {
         if (context.ContextConfig.Name != ContextName)
         {
             createContext = true;
             context       = DbContextUtil.CreateDbContext(ContextName);
         }
     }
 }
Ejemplo n.º 22
0
        protected override string ConvertValue(TkDbContext context, string value)
        {
            if (value == "√")
            {
                return(fCheckValue);
            }
            else if (value == "X" || string.IsNullOrEmpty(value))
            {
                return(fUncheckValue);
            }

            throw new ToolkitException(string.Format(ObjectUtil.SysCulture,
                                                     "{0}不是合法的,选择√或者X", value), this);
        }
Ejemplo n.º 23
0
        protected override DataTable FillDbData(TkDbContext context, DataSet dataSet)
        {
            using (SqlSelector selector = new SqlSelector(context, dataSet))
            {
                BasePlugInAttribute attr = Attribute;
                TkDebug.AssertNotNull(attr, "需要设置CodeAttribute", this);
                string regName = attr.GetRegName(GetType());
                string sql     = Expression.Execute(Sql, selector);
                selector.Select(regName, sql);
                DataTable dataTable = dataSet.Tables[regName];

                return(dataTable);
            }
        }
Ejemplo n.º 24
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 + "%"));
            }
        }
Ejemplo n.º 25
0
        public override OutputData DoAction(IInputData input)
        {
            DateTime      current    = DateTime.Today;
            DateTime      firstMonth = new DateTime(current.Year, current.Month, 1);
            DateTime      endMonth   = firstMonth.AddMonths(1);
            TkDbContext   context    = Context;
            FieldItem     field      = new FieldItem("WM_SEND_DATE", TkDataType.DateTime);
            IParamBuilder builder    = ParamBuilder.CreateParamBuilder(
                SqlParamBuilder.CreateSingleSql(context, field, ">=", firstMonth),
                SqlParamBuilder.CreateSingleSql(context, field, "<", "WM_SEND_DATE1", endMonth));
            int count = DbUtil.ExecuteScalar("SELECT COUNT(*) FROM CS_WEIXIN_MASS", context, builder)
                        .Value <int>();

            return(OutputData.Create(count.ToString()));
        }
Ejemplo n.º 26
0
        private IParamBuilder InternalCreateLikeSql(TkDbContext context, IFieldInfo fieldName,
                                                    string likeValue, string exceptValue)
        {
            string fieldName1 = fieldName.FieldName + "1";
            string fieldName2 = fieldName.FieldName + "2";

            fSql = string.Format(ObjectUtil.SysCulture, "{0} LIKE {1} AND {0} <> {2}",
                                 context.EscapeName(fieldName.FieldName), context.GetSqlParamName(fieldName1),
                                 context.GetSqlParamName(fieldName2));

            fParams.Add(fieldName1, fieldName.DataType, likeValue);
            fParams.Add(fieldName2, fieldName.DataType, exceptValue);

            return(this);
        }
Ejemplo n.º 27
0
        public override IEnumerable <IDecoderItem> Search(SearchField field,
                                                          string text, List <EasySearchRefField> refFields)
        {
            IFieldInfo fieldName = null;

            switch (field)
            {
            case SearchField.Value:
            case SearchField.DefaultValue:
                fieldName = ValueField;
                break;

            case SearchField.Name:
                fieldName = NameField;
                break;

            case SearchField.Pinyin:
                fieldName = PinyinField ?? NameField;
                break;
            }
            TkDbContext context = string.IsNullOrEmpty(ContextName) ? DbContextUtil.CreateDefault()
                : DbContextUtil.CreateDbContext(ContextName);

            using (context)
            {
                IParamBuilder builder = SearchMethod.Search(this, field, context, fieldName, text);
                if (refFields != null && refFields.Count > 0)
                {
                    IParamBuilder refBuilder = GetRefParamBuilder(context, refFields);
                    builder = ParamBuilder.CreateParamBuilder(builder, refBuilder);
                }
                DataTable table = FetchRows(context, fDataSet, builder, TopCount);
                if (table == null || table.Rows.Count == 0)
                {
                    return(null);
                }

                List <IDecoderItem>  result  = new List <IDecoderItem>(table.Rows.Count);
                DataColumnCollection columns = table.Columns;
                foreach (DataRow row in table.Rows)
                {
                    result.Add(new DataRowDecoderItem(columns, row,
                                                      DecoderConst.CODE_NICK_NAME, fExpression, fDisplayExpression));
                }
                return(result);
            }
        }
Ejemplo n.º 28
0
        protected override string ConvertValue(TkDbContext context, string value)
        {
            IDecoderItem[] items = fEasySearch.SearchByName(value, context);
            switch (items.Length)
            {
            case 0:
                throw new ToolkitException(string.Format(ObjectUtil.SysCulture,
                                                         "{0}不存在,请确认", value), this);

            case 1:
                return(items[0].Value);

            default:
                throw new ToolkitException(string.Format(ObjectUtil.SysCulture,
                                                         "{0}存在{1}条记录,有二义性,请处理", value, items.Length), this);
            }
        }
Ejemplo n.º 29
0
        public CodeTableColumnReader(Tk5FieldInfoEx fieldInfo, TkDbContext context, int cellIndex)
            : base(fieldInfo, cellIndex)
        {
            CodeTableContainer ctContainer = new CodeTableContainer();
            string             regName     = fieldInfo.Decoder.RegName;
            CodeTable          codeTable   = PlugInFactoryManager.CreateInstance <CodeTable>(
                CodeTablePlugInFactory.REG_NAME, regName);

            codeTable.Fill(ctContainer, context);
            IEnumerable <IDecoderItem> data = ctContainer[regName];

            fCodeTable = new Dictionary <string, IDecoderItem>();
            foreach (var item in data)
            {
                fCodeTable[item.Name] = item;
            }
        }
Ejemplo n.º 30
0
        public void CheckPostDataSet(TkDbContext context, IInputData inputData,
                                     string tableName, FieldErrorInfoCollection errorObjects)
        {
            DataSet   ds    = inputData.PostObject.Convert <DataSet>();
            DataTable table = ds.Tables[tableName];

            if (table == null)
            {
                return;
            }

            foreach (BaseConstraint constraint in fList)
            {
                string fieldName = constraint.Field.NickName;
                if (!table.Columns.Contains(fieldName))
                {
                    if (constraint.CoerceCheck)
                    {
                        constraint.InternalCheckError(inputData, null, -1, context);
                    }
                    continue;
                }

                int i = 0;
                foreach (DataRow row in table.Rows)
                {
                    if (row.RowState == DataRowState.Deleted)
                    {
                        ++i;
                        continue;
                    }
                    string value = row[fieldName].ToString();
                    if (!errorObjects.Contains(constraint, i))
                    {
                        FieldErrorInfo error = constraint.InternalCheckError(inputData, value, i,
                                                                             context, row, table, ds);
                        if (error != null)
                        {
                            errorObjects.Add(constraint, error, i);
                        }
                    }
                    ++i;
                }
            }
        }