Exemplo n.º 1
0
        /// <summary>
        /// 替换字符串里的%变量%(用entity内变量),用','连接
        /// 内部参数带quoto引号
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="entities"></param>
        /// <param name="quoto"></param>
        /// <returns></returns>
        public static string ReplaceEntities(string expression, object[] entities, char quoto)
        {
            try
            {
                Match m = s_regexEntityParamter.Match(expression);
                while (m.Success)
                {
                    StringBuilder sb = new StringBuilder();

                    sb.Append(quoto);
                    foreach (object entity in entities)
                    {
                        object v = EntityScript.GetPropertyValue(entity, m.Groups[1].Value);

                        string s = ConvertEntityParamToString(v, null);

                        sb.Append(s);
                        sb.Append(",");
                    }
                    if (sb[sb.Length - 1] == ',')
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }
                    sb.Append(quoto);
                    expression = expression.Replace(m.Groups[0].Value, sb.ToString());

                    m = s_regexEntityParamter.Match(expression);
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("expression of " + expression + " format is invalid!", ex);
            }
            return(expression);
        }
Exemplo n.º 2
0
        //private bool m_needSearchExpression = true;
        ///// <summary>
        ///// 是否需要查找条件(如需要,刷新的时候必须要现有条件)
        ///// </summary>
        //protected bool NeedSearchConddition
        //{
        //    get { return m_needSearchExpression; }
        //    set { m_needSearchExpression = value; }
        //}

        /// <summary>
        /// 重新读入当前行
        /// </summary>
        public void ReloadItem(int idx)
        {
            //if (this.DisplayManager.CurrentItem == null)
            //    return;
            if (this.DisplayManager.EntityInfo == null)
            {
                return;
            }
            if (idx < 0 || idx >= this.DisplayManager.Count)
            {
                return;
            }
            object entity = this.DisplayManager.Items[idx];
            object id     = EntityScript.GetPropertyValue(entity, this.DisplayManager.EntityInfo.IdName);

            IList list = this.GetData(SearchExpression.Eq(this.DisplayManager.EntityInfo.IdName, id), null) as IList;

            System.Diagnostics.Debug.Assert(list.Count <= 1);

            if (list.Count == 0)
            {
                return;
            }
            else if (list.Count == 1)
            {
                this.DisplayManager.Items[idx] = list[0];
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 替换字符串里的%变量%(用entity内变量)(只有entity变量)
 /// 注意,返回字符串会的entity变量会带""""(为了表达式计算需要),如果不需要,调用有quoto函数
 /// 如果是Enum,例如收付标志.收,只需要写%收付标志%="收"
 /// </summary>
 /// <param name="expression"></param>
 /// <param name="entity"></param>
 /// <param name="quoto"></param>
 /// <returns></returns>
 public static string ReplaceEntity(string expression, object entity, char?quoto = '\"')
 {
     return(ReplaceEntity(expression, new GetReplaceValue(delegate(string paramName)
     {
         return EntityScript.GetPropertyValue(entity, paramName);
     }),
                          quoto));
 }
Exemplo n.º 4
0
        private void GenerateNewChild(T parent)
        {
            parent.ChildEntity = ReflectionHelper.CreateInstanceFromType(parent.ChildType) as S;
            parent.ChildEntity.ParentEntity = parent;

            EntityScript.SetPropertyValue(parent.ChildEntity, ServiceProvider.GetService <IEntityMetadataGenerator>().GenerateEntityMetadata(typeof(S)).IdName,
                                          EntityScript.GetPropertyValue(parent, ServiceProvider.GetService <IEntityMetadataGenerator>().GenerateEntityMetadata(typeof(T)).IdName));
        }
        ///// <summary>
        ///// 在显示当前位置数据前发生
        ///// </summary>
        //public event EventHandler CurrentDisplaying;

        /// <summary>
        /// 显示当前位置实体类数据
        /// </summary>
        public virtual void DisplayCurrent()
        {
            foreach (IDataControl dc in this.DataControls)
            {
                // if in tab control, the data control may be invisible
                //if (!dc.Visible)
                //    continue;

                switch (dc.ControlType)
                {
                case DataControlType.Unbound:
                    break;

                case DataControlType.Normal:
                {
                    if (string.IsNullOrEmpty(dc.PropertyName))
                    {
                        continue;
                    }

                    if (this.CurrentItem == null)
                    {
                        dc.SelectedDataValue = null;
                    }
                    else
                    {
                        try
                        {
                            dc.SelectedDataValue = EntityScript.GetPropertyValue(this.CurrentItem, dc.Navigator, dc.PropertyName);
                        }
                        catch (Exception ex)
                        {
                            throw new ArgumentException(string.Format("DataControl of {0} is Invalid!", dc.Name), ex);
                        }
                    }
                }
                break;

                case DataControlType.Expression:
                    if (string.IsNullOrEmpty(dc.PropertyName))
                    {
                        continue;
                    }
                    if (dc.PropertyName.Contains("%"))
                    {
                        dc.SelectedDataValue = EntityScript.CalculateExpression(dc.PropertyName, this.CurrentItem);
                    }
                    else
                    {
                    }
                    break;

                default:
                    throw new ArgumentException(string.Format("DataControl of {0} is Invalid!", dc.Name));
                }
            }
        }
Exemplo n.º 6
0
        private void Load()
        {
            m_buffers = new System.Collections.Generic.Dictionary <object, object>();

            using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository(m_persistentClass))
            {
                rep.BeginTransaction();
                IList list = rep.List(m_persistentClass);
                rep.CommitTransaction();

                foreach (object i in list)
                {
                    object id = EntityScript.GetPropertyValue(i, ServiceProvider.GetService <IEntityMetadataGenerator>().GenerateEntityMetadata(m_persistentClass).IdName);
                    m_buffers[id] = i;
                }
            }
        }