示例#1
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);
            }
        }
示例#2
0
        public override IDecoderItem[] SearchByName(string name, params object[] args)
        {
            TkDbContext context;
            bool        createContext;

            GetContext(args, out context, out createContext);

            try
            {
                IParamBuilder builder = SqlParamBuilder.CreateEqualSql(context, NameField, name);
                DataTable     table   = FetchRows(context, fDataSet, builder, 2);
                if (table == null || table.Rows.Count == 0)
                {
                    return(null);
                }
                IDecoderItem[]       result  = new IDecoderItem[table.Rows.Count];
                int                  index   = 0;
                DataColumnCollection columns = table.Columns;
                foreach (DataRow row in table.Rows)
                {
                    result[index++] = new DataRowDecoderItem(columns, row,
                                                             DecoderConst.CODE_NICK_NAME, fExpression, fDisplayExpression);
                }

                return(result);
            }
            finally
            {
                if (createContext)
                {
                    context.Dispose();
                }
            }
        }
示例#3
0
        internal static string GetLayer(ListDataRightEventArgs e)
        {
            IParamBuilder builder = SqlParamBuilder.CreateEqualSql(e.Context, "ORG_ID", TkDataType.Int, e.User.MainOrgId);
            string        layer   = DbUtil.ExecuteScalar(SQL, e.Context, builder).ToString();

            return(layer);
        }
示例#4
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);
            }
        }
示例#5
0
        protected override OutputData DoGet(IInputData input)
        {
            Tk5TableResolver getResovler = new Tk5TableResolver(@"Weixin\CorpTagDept.xml", this);

            using (getResovler)
            {
                DataTable     table   = getResovler.CreateVirtualTable();
                IParamBuilder builder = SqlParamBuilder.CreateEqualSql(Context, "CU_USER_ID",
                                                                       TkDataType.Int, input.QueryString["UserId"]);
                string          dept = DbUtil.ExecuteScalar(SQL, Context, builder).ToString();
                QuoteStringList list = dept.Value <QuoteStringList>();
                if (list != null)
                {
                    List <int> deptList = list.ConvertToList <int>();
                    if (deptList != null)
                    {
                        foreach (var item in deptList)
                        {
                            DataRow userRow = table.NewRow();
                            userRow["DeparmentId"] = item;
                            table.Rows.Add(userRow);
                        }
                        getResovler.Decode(input.Style);
                    }
                }

                input.CallerInfo.AddInfo(DataSet);
            }
            return(OutputData.Create(DataSet));
        }
示例#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);
            }

            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));
        }
示例#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));
        }
示例#8
0
        public IParamBuilder GetListSql(ListDataRightEventArgs e)
        {
            if (e.User.MainOrgId == null)
            {
                return(SqlParamBuilder.NoResult);
            }

            return(SqlParamBuilder.CreateEqualSql(e.Context, fField, e.User.MainOrgId));
        }
示例#9
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);
        }
示例#10
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);
                        }
                    }
                }
            }
        }
示例#11
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));
            }
        }
示例#12
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 + "%"));
            }
        }
示例#13
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()));
        }
示例#14
0
        public static string GetSXCode(TkDbContext context, double latitude, double longitude)
        {
            TkDebug.AssertArgumentNull(context, "context", null);

            var result = MapUtil.GetAddress(latitude, longitude);

            if (result.Status == 0 && !string.IsNullOrEmpty(result.Result.CityCode))
            {
                IParamBuilder builder = SqlParamBuilder.CreateEqualSql(context, "CODE_VALUE",
                                                                       TkDataType.Int, result.Result.CityCode);
                object value = DbUtil.ExecuteScalar("SELECT CODE_GB FROM CD_BAIDU_CITY", context, builder);
                if (value == DBNull.Value)
                {
                    return("000000");
                }
                return(value.ToString());
            }
            return("000000");
        }
示例#15
0
        public static string GetSXCode(TkDbContext context, string province, string city,
                                       string defaultCode)
        {
            TkDebug.AssertArgumentNull(context, "context", null);

            if (string.IsNullOrEmpty(province) || string.IsNullOrEmpty(city))
            {
                return(defaultCode);
            }

            const string  sql     = "SELECT MIN(CODE_VALUE) FROM CD_SX";
            IParamBuilder builder = SqlParamBuilder.CreateParamBuilder(
                SqlParamBuilder.CreateEqualSql(context, "CODE_WX_PROVINCE", TkDataType.String, province),
                SqlParamBuilder.CreateEqualSql(context, "CODE_WX_CITY", TkDataType.String, city));
            object value = DbUtil.ExecuteScalar(sql, context, builder);

            if (value == DBNull.Value)
            {
                return(defaultCode);
            }
            return(value.ToString());
        }
示例#16
0
        private IParamBuilder GetQueryParamBuilder(TkDbContext context, IFieldInfo fieldName,
                                                   string fieldValue)
        {
            int len = Math.Min(fieldValue.Length, fTreeDef.TotalCount);

            if (len == fTreeDef.TotalCount)
            {
                return(SqlParamBuilder.CreateEqualSql(context, fieldName, fieldValue));
            }
            if (len == 0)
            {
                return(SqlParamBuilder.CreateSingleSql(context, fieldName,
                                                       "LIKE", fLevelProvider.GetSqlLikeValue(fTreeDef, 0, fieldValue)));
            }
            else
            {
                int    level       = fTreeDef.GetLevel(fieldValue);
                string likeValue   = fLevelProvider.GetSqlLikeValue(fTreeDef, level + 1, fieldValue);
                string exceptValue = fLevelProvider.GetSqlExceptValue(fTreeDef, level + 1, fieldValue);
                return(CodeLikeParamBuilder.CreateLikeSql(context, fieldName, likeValue, exceptValue));
            }
        }
示例#17
0
 public IParamBuilder CreateParamBuilder(TkDbContext context, IFieldInfoIndexer indexer)
 {
     return(SqlParamBuilder.CreateSql("CODE_DEL IS NULL OR CODE_DEL <> 1"));
 }