Ejemplo n.º 1
0
        public static void RedirectPage(IMetaData metaData, ISource source, IWebHandler handler,
                                        OutputData outputData, IRedirector redirector)
        {
            MetaDataUtil.SetMetaData(redirector, handler.Style, metaData);
            string url = redirector.Redirect(source, handler, outputData);

            TkDebug.AssertNotNullOrEmpty(url,
                                         "Redirector.Redirect函数返回的Url为空,不能重定向该地址", redirector);
            url = AppUtil.ResolveUrl(url);

            handler.Response.Redirect(url, false);
        }
Ejemplo n.º 2
0
        private string GetFieldDbType(IFieldInfoEx field)
        {
            var index = (int)field.DataType;

            TkDebug.Assert(index >= 0 && index < CONVET_ARR.Length
                           , string.Format(ObjectUtil.SysCulture, "给定枚举值{0}越界了", field.DataType), this);
            var result = string.Format(ObjectUtil.SysCulture, CONVET_ARR[index]
                                       , field.Length, field.Precision);

            TkDebug.AssertNotNullOrEmpty(result
                                         , string.Format(ObjectUtil.SysCulture, "字段:{0}找不到相匹配的数据库的数据类型", field.FieldName), this);
            return(result);
        }
Ejemplo n.º 3
0
        protected internal IContent WritePage(IPageData pageData, OutputData outputData)
        {
            PageMakerUtil.AssertType(this, outputData, SourceOutputType.XmlReader, SourceOutputType.String,
                                     SourceOutputType.DataSet, SourceOutputType.ToolkitObject);

            string xsltFile = GetRealXsltFile(pageData); // Path.Combine(AppSetting.Current.XmlPath, XsltFile);

            TkDebug.AssertNotNullOrEmpty(xsltFile, "没有设置XsltFile属性,该值为空", this);
            TkDebug.Assert(File.Exists(xsltFile), string.Format(ObjectUtil.SysCulture,
                                                                "系统中并不存在文件名为{0}的文件,请检查路径!", xsltFile), this);

            XsltArgumentList args = null;

            if (UseXsltArgs)
            {
                args = new XsltArgumentList();
                AddXsltParam(args, pageData);
            }
            string    content = string.Empty;
            XmlReader reader  = null;

            switch (outputData.OutputType)
            {
            case SourceOutputType.XmlReader:
                reader = outputData.Data.Convert <XmlReader>();
                break;

            case SourceOutputType.String:
                reader = XmlTransformUtil.GetXmlReader(outputData.Data.Convert <string>());
                break;

            case SourceOutputType.ToolkitObject:
                XDocument doc = outputData.Data.CreateXDocument(null, ObjectUtil.WriteSettings, QName.ToolkitNoNS);
                reader = doc.CreateReader();
                break;

            case SourceOutputType.DataSet:
                reader = new XmlDataSetReader(outputData.Data.Convert <DataSet>());
                break;

            default:
                TkDebug.ThrowImpossibleCode(this);
                break;
            }
            content = XmlTransformUtil.Transform(reader, xsltFile, args, TransformSetting.All);
            Encoding encoding = Encoding ?? (pageData.IsPost ? Encoding.UTF8 : null);

            return(CreateContent(pageData, content, encoding));
        }
Ejemplo n.º 4
0
        internal static int FillDataSet(object sender, IDbDataAdapter adapter, DataSet dataSet, string tableName)
        {
            TkDebug.AssertNotNull(adapter.SelectCommand, "adapter参数的SelectCommand为空,无法从数据库取数据", sender);
            TkDebug.AssertNotNullOrEmpty(adapter.SelectCommand.CommandText,
                                         "adapter参数的SelectCommand的CommandText属性为空,无法从数据库取数据", sender);

            TkTrace.LogInfo(adapter.SelectCommand.CommandText);
            try
            {
                return((adapter as DbDataAdapter).Fill(dataSet, tableName));
            }
            catch (Exception ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "执行SQL:{0}时出错", adapter.SelectCommand.CommandText), ex, sender);
                return(-1);
            }
        }
Ejemplo n.º 5
0
        public void Add(IParamBuilder builder)
        {
            if (builder == null)
            {
                return;
            }
            string sql = builder.Sql;

            TkDebug.AssertNotNullOrEmpty(sql,
                                         "传入参数builder生成的Sql为空,这是不允许的", builder);

            AddSql(sql);
            DbParameterList parameters = builder.Parameters;

            TkDebug.AssertNotNull(parameters,
                                  "传入参数builder调用GetParameters返回为空,这是不允许的", builder);

            fParams.Add(parameters);
        }
Ejemplo n.º 6
0
        private static IParamBuilder LinkParamBuilder(IEnumerable <IParamBuilder> builders,
                                                      string linkOperator)
        {
            int j = 0;
            InternalParamBuilder result  = new InternalParamBuilder();
            StringBuilder        builder = new StringBuilder();

            foreach (IParamBuilder item in builders)
            {
                string sql = item.Sql;
                TkDebug.AssertNotNullOrEmpty(sql, string.Format(ObjectUtil.SysCulture,
                                                                "builders参数第{0}个IParamBuilder生成的Sql是空,这是不允许的", j), item);
                if (j > 0)
                {
                    builder.Append(linkOperator);
                }
                builder.Append("(").Append(sql).Append(")");
                //StringUtil.JoinStringItem(builder, i++, "(" + sql + ")", linkOperator);
                DbParameterList itemParams = item.Parameters;
                TkDebug.AssertNotNull(itemParams, string.Format(ObjectUtil.SysCulture,
                                                                "builders参数第{0}个IParamBuilder调用的Parameters返回是空,这是不允许的",
                                                                j), item);
                result.Parameters.Add(itemParams);
                ++j;
            }
            //result.Sql = builder.ToString();
            if (j == 0)
            {
                return(null);
            }
            else if (j == 1)
            {
                return(builders.First());
            }
            else
            {
                result.Sql = builder.ToString();
                return(result);
            }
        }
Ejemplo n.º 7
0
        public TableResolver CreateObject(params object[] args)
        {
            IDbDataSource source = ObjectUtil.ConfirmQueryObject <IDbDataSource>(this, args);

            TkDebug.AssertNotNullOrEmpty(TableName, "没有配置TableName属性", this);
            TableResolver resolver;

            if (string.IsNullOrEmpty(KeyFields))
            {
                resolver = new TableResolver(TableName, source);
            }
            else if (string.IsNullOrEmpty(Fields))
            {
                resolver = new TableResolver(TableName, KeyFields, source);
            }
            else
            {
                resolver = new TableResolver(TableName, KeyFields, Fields, source);
            }
            resolver.AutoTrackField = AutoTrackField;
            resolver.AutoUpdateKey  = AutoUpdateKey;

            return(resolver);
        }