Exemplo n.º 1
0
        /// <summary>
        /// 输出转化器
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public static IOutputConvert GetOutputConvert(string expr, out string[] fields)
        {
            string fun = GetFun(expr);

            fields = GetArgs(expr);
            IOutputConvert converter = AppCtx.Cache.RetrieveObject <IOutputConvert>(GetOutputConvertKey(fun));

            if (converter == null)
            {
                string typestr = ModelConfig.Converters[fun];
                converter = Utils.CreateInstance <IOutputConvert>(ModelConfig.Converters[fun]);
                if (converter == null)
                {
                    throw new SysException("不存在当前转化器" + fun);
                }
                AppCtx.Cache.AddObjectWithFileChange(GetOutputConvertKey(fun), converter, ModelConfig.ConfigFilePath);
            }
            return(converter);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 扩展数据表格
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="dcc"></param>
        public static void ExtendDataTable(DataTable dt, We7DataColumnCollection dcc)
        {
            foreach (We7DataColumn column in dcc)
            {
                if (!dt.Columns.Contains(column.Name) && (column.Direction == ParameterDirection.ReturnValue || column.Direction == ParameterDirection.Output || column.Direction == ParameterDirection.InputOutput))
                {
                    dt.Columns.Add(column.Name);
                }
            }

            foreach (DataRow row in dt.Rows)
            {
                if (!row.Table.Columns.Contains("Object"))
                {
                    continue;
                }
                foreach (We7DataColumn column in dcc)
                {
                    IOutputConvert convert = null;
                    string[]       fields;

                    if (column.Direction == ParameterDirection.InputOutput || column.Direction == ParameterDirection.Output)
                    {
                        fields  = new string[] { String.IsNullOrEmpty(column.Mapping) ? column.Name : column.Mapping };
                        convert = new GetEntityValue();
                        if (row[column.Name] == DBNull.Value)
                        {
                            row[column.Name] = convert.Convert(column, row, fields, row["Object"]);
                        }
                    }
                    else if (column.Direction == ParameterDirection.ReturnValue)
                    {
                        convert          = ConvertHelper.GetOutputConvert(column.Expression, out fields);
                        row[column.Name] = convert.Convert(column, row, fields, row["Object"]);
                    }
                }
            }
        }