Parse() public method

public Parse ( Func func ) : Delegate
func Func
return System.Delegate
Exemplo n.º 1
0
 //利用索引属性的字符串特性,找对象,path可以是一个表达式
 public object this[string path]
 {
     get
     {
         //采用程序解析方式对表达式进行解析,产生判断对象满足条件的代理,
         //利用linq查找对象,对象需要满足的条件由代理判断
         Program prog = new Program(path, null, false);
         Delegate d = prog.Parse(prog.Exp);
         object result = (from p in Objects where IsTrue(d, prog.exp, p) select p).FirstOrDefault();
         return result;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 根据主体数据生成界面
 /// </summary>
 private void UpdateBody()
 {
     if (TableHeadItems.Value.Count == 0 
         && TableLeftItems.Value.Count == 0 
         && TableBodyItems.Count == 0) return;
     //绘制有表头变化,有左侧的主体
     if (HasHead && HasLeft)
     {
         //获得表头变化模板包含几列
         Dictionary<string, int> dic = getColumnNumber(headChangeCellTemplate);
         for (int i = 0; i < TableHeadItems.Value.Count; i++)
         {
             CurrentHead = TableHeadItems.Value[i];
             for (int j = 0; j < TableLeftItems.Value.Count; j++)
             {
                 CurrentLeft = TableLeftItems.Value[j];
                 //画主体
                 foreach (Cell cell in bodyCellTemplate)
                 {
                     Cell copy = cell.copyCell();
                     Program prog = new Program(copy.Content, this, false);
                     Delegate d = prog.Parse(prog.Exp);
                     copy.Delegate = d;
                     object value = copy.Delegate.DynamicInvoke();
                     copy.Content = value + "";
                     copy.Row = cell.Row + j;
                     //单元格在变化部分右侧
                     if (copy.Column > dic["max"]) 
                     { 
                         copy.Column = copy.Column + (TableHeadItems.Value.Count - 1) * dic["count"]; 
                     }
                     else{ copy.Column = cell.Column + i * dic["count"];}
                     this.cells.Add(copy);
                 }
                 
             }
         }
         //根据左侧数据添加行
         foreach (var item in TableLeftItems.Value)
         {
             //根据模板加一行
             Row row = new Row() { Height = bodyCellTemplate[0].Height };
             this.rows.Add(row);
         }
     }
     else if (HasLeft)
     {
         //根据左侧复制主体
         for (int i = 0; i < TableLeftItems.Value.Count; i++)
         {
             CurrentLeft = TableLeftItems.Value[i];
             foreach (Cell cell in bodyCellTemplate)
             {
                 Cell copy = cell.copyCell();
                 Program prog = new Program(copy.Content, this, false);
                 Delegate d = prog.Parse(prog.Exp);
                 copy.Delegate = d;
                 object value = copy.Delegate.DynamicInvoke();
                 copy.Content = value + "";
                 copy.Row = cell.Row + i;
                 copy.Column = cell.Column;
                 this.cells.Add(copy);
             }
             //根据模板加一行
             Row row = new Row() { Height = bodyCellTemplate[0].Height };
             this.rows.Add(row);
         }
     }
     //只有主体部分,没有左侧,没有表头变化部分
     else
     {
         for (int i = 0; i < TableBodyItems[0].Value.Count; i++)
         {
             CurrentMain = TableBodyItems[0].Value[i];
             foreach (Cell cell in bodyCellTemplate)
             {
                 Cell copy = cell.copyCell();
                 Program prog = new Program(copy.Content, this, false);
                 Delegate d = prog.Parse(prog.Exp);
                 copy.Delegate = d;
                 object value = copy.Delegate.DynamicInvoke();
                 copy.Content = value + "";
                 copy.Row = cell.Row + i;
                 this.cells.Add(copy);
             }
             if (bodyCellTemplate.Count != 0)
             {
                 //根据模板加一行
                 Row row = new Row() { Height = bodyCellTemplate[0].Height };
                 this.rows.Add(row);
             }
         }
     }
 }
Exemplo n.º 3
0
 private void UpdateBottom()
 {
     if (TableBodyItems[0].Value.Count == 0) return;
     //绘制有表头变化的情况
     if (HasHead)
     {
         //获得表头变化模板包含几列
         Dictionary<string, int> dic = getColumnNumber(headChangeCellTemplate);
         //根据表头sql数据进行复制
         for (int i = 0; i < TableHeadItems.Value.Count; i++)
         {
             //设置档案表头使用的对象,供表达式获取
             CurrentHead = TableHeadItems.Value[i];
             foreach (Cell cell in bottomCellTemplate)
             {
                 Cell copy = cell.copyCell();
                 Program prog = new Program(copy.Content, this, false);
                 Delegate d = prog.Parse(prog.Exp);
                 copy.Delegate = d;
                 copy.Row = this.rows.Count - this.headRowTemplate.Count + copy.Row - 1;
                 //单元格列号在表头变化部分内
                 if (cell.Column >= dic["min"] && cell.Column <= dic["max"])
                 {
                     object value = copy.Delegate.DynamicInvoke();
                     if (value == null) { value = copy.Content.Replace("$", ""); }
                     copy.Content = value + ""; 
                     //根据表头变化部分模板复制单元格,横向复制
                     copy.Column = cell.Column + i * dic["count"];
                     this.cells.Add(copy);
                 }
                 //在变化部分左侧的,直接设置单元格,执行表达式
                 else if (cell.Column < dic["min"])
                 {
                     object value = copy.Delegate.DynamicInvoke();
                     copy.Content = value+"";  this.cells.Add(copy);
                 }
                 //在变化部分的右侧单元格,
                 else if (cell.Column > dic["max"])
                 {
                     object value = copy.Delegate.DynamicInvoke();
                     copy.Content = value + ""; 
                     //根据表头变化部分模板复制单元格,横向复制
                     copy.Column = cell.Column + (TableHeadItems.Value.Count - 1) * dic["count"];
                     this.cells.Add(copy);
                 }
             }
         }
     }
     //普通绘制
     else
     {
         foreach (Cell cell in bottomCellTemplate)
         {
             Cell copy = cell.copyCell();
             Program prog = new Program(copy.Content, this, false);
             Delegate d = prog.Parse(prog.Exp);
             copy.Delegate = d;
             object value = copy.Delegate.DynamicInvoke();
             copy.Content = value + "";
             copy.Row = this.rows.Count - this.headRowTemplate.Count + copy.Row - 1;
             this.cells.Add(copy);
         }
     }
     //复制表行
     this.rows.AddRange(bottomRowTemplate);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 根据表头,重新绘制,如果有表达式则执行表达式
        /// </summary>
        private void UpdateHead()
        {
            if (TableHeadItems.Value.Count == 0 && TableBodyItems.Count == 0) return;
            //绘制有表头变化部分的表头
            if (HasHead)
            {
                //更新表头前,保存初始化列数据
                List<Column> temp_columns = this.columns_init;
                this.columns.Clear();
                //获得表头变化模板包含几列
                Dictionary<string, int> dic = getColumnNumber(headChangeCellTemplate);
                //根据表头sql数据进行复制
                foreach (Cell cell in headCellTemplate)
                {
                    
                    if (cell.Column < dic["min"])
                    {
                        Cell copy = cell.copyCell();
                        Program prog = new Program(copy.Content, this, false);
                        Delegate d = prog.Parse(prog.Exp);
                        copy.Delegate = d;
                        object value = copy.Delegate.DynamicInvoke();
                        if (value == null) { value = copy.Content.Replace("$", ""); }
                        copy.Content = value+"";
                        copy.Row = cell.Row; this.cells.Add(copy);
                        Column column = new Column() { Width = temp_columns[cell.Column].Width };
                        this.columns.Add(column);
                    }
                    //在变化部分的右侧单元格,
                    else if (cell.Column > dic["max"])
                    {
                        Cell copy = cell.copyCell();
                        Program prog = new Program(copy.Content, this, false);
                        Delegate d = prog.Parse(prog.Exp);
                        copy.Delegate = d;
                        object value = copy.Delegate.DynamicInvoke();
                        if (value == null) { value = copy.Content.Replace("$", ""); }
                        copy.Content = value + "";
                        copy.Row = cell.Row;
                        //根据表头变化部分模板复制单元格,横向复制
                        copy.Column = cell.Column + (TableHeadItems.Value.Count - 1) * dic["count"];
                        this.cells.Add(copy);
                        Column column = new Column() { Width = temp_columns[cell.Column].Width };
                        this.columns.Add(column);
                    }
                    else
                    {

                        for (int i = 0; i < TableHeadItems.Value.Count; i++)
                        {
                            Cell copy = cell.copyCell();
                            Program prog = new Program("data." + copy.Content, this, false);
                            Delegate d = prog.Parse(prog.Exp);
                            copy.Delegate = d;
                            object value = copy.Delegate.DynamicInvoke(new object[] { TableHeadItems.Value[i] });
                            if (value == null) { value = copy.Content.Replace("$", ""); }
                            copy.Content = value + "";
                            copy.Row = cell.Row;
                            //根据表头变化部分模板复制单元格,横向复制
                            copy.Column = cell.Column + i * dic["count"];
                            this.cells.Add(copy);
                            //复制列
                            Column column = new Column() { Width = temp_columns[cell.Column].Width };
                            this.columns.Add(column);
                        }
                    }
                }
            }
            //绘制普通表头,执行表达式
            else
            {
                foreach (Cell cell in headCellTemplate)
                {
                    Cell copy = cell.copyCell();
                    Program prog = new Program(copy.Content, this, false);
                    Delegate d = prog.Parse(prog.Exp);
                    copy.Delegate = d;
                    object value = copy.Delegate.DynamicInvoke();
                    copy.Content = value + "";
                    copy.Row = cell.Row;
                    this.cells.Add(copy);
                }
            }
            //复制表头行
            this.rows.AddRange(headRowTemplate);
        }
Exemplo n.º 5
0
 /// <summary>
 /// 获得模板
 /// </summary>
 /// <param name="item"></param>
 private void InitTemplate(JsonObject item)
 {
     //取出表头行定义
     JsonArray rows = item["rows"] as JsonArray;
     foreach (JsonObject obj in rows)
     {
         int height = obj["height"];
         string type = obj["type"];
         if (type == "head")
         {
             Row row = new Row() { Height = height };
             this.headRowTemplate.Add(row);
         }
         if (type == "bottom")
         {
             Row row = new Row() { Height = height };
             this.bottomRowTemplate.Add(row);
         }
     }
     //获得模板
     JsonArray cells = item["cells"] as JsonArray;
     foreach (JsonObject obj in cells)
     {
         int row = obj["row"];
         int column = obj["column"];
         string content = obj["content"];
         int rowspan = obj["rowspan"];
         int columnspan = obj["columnspan"];
         string location = obj["location"];
         int height = obj["height"];
         Cell cell = new Cell() { Row = row, Column = column, Content = content, RowSpan = rowspan, ColumnSpan = columnspan, Location = location, Height = height };
         string type = obj["type"];
         //表头
         if (type == "head" || type == "headchange")
         {
             this.headCellTemplate.Add(cell);
         }
         //表头变化部分
         if (type == "headchange")
         {
             this.headChangeCellTemplate.Add(cell);
         }
         //左侧
         if (type == "left")
         {
             Program prog = new Program("data."+cell.Content, this, false);
             Delegate d = prog.Parse(prog.Exp);
             cell.Delegate = d;
             this.leftCellTemplate.Add(cell);
         }
         //主体
         if (type == "main")
         {
             this.bodyCellTemplate.Add(cell);
         }
         //表底
         if (type == "bottom")
         {
             this.bottomCellTemplate.Add(cell);
         }
     }
     //如果表头有变化部分,表头模板根据列号排序
     if (HasHead)
     {
         List<Cell> headCellTemplate_temp = new List<Cell>();
         //表头模板根据列号排序
         for (int i = 0; i < this.headCellTemplate.Count; i++)
         {
             foreach (Cell cell in this.headCellTemplate)
             {
                 if (cell.Column == i)
                 {
                     headCellTemplate_temp.Add(cell);
                     break;
                 }
             }
         }
         this.headCellTemplate.Clear();
         this.headCellTemplate.AddRange(headCellTemplate_temp);
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// 获得所有sql的json格式,包括左侧sql
 /// </summary>
 /// <returns></returns>
 private string getJsonSql()
 {
     string sql = "";
     string result="";
     if (HasLeft)
     {
         if (TableLeftItems.NewSql != null)
         {
             sql = TableLeftItems.NewSql;
         }
         else
         {
             sql = TableLeftItems.Sql;
         }
         sql = sql.Replace("$", "'");
         //sql执行表达式
         Program prog = new Program("$" + sql + "$", this, false);
         sql = prog.Parse(prog.Exp).DynamicInvoke() + "";
         result = "{name:'" + TableLeftItems.Name + "',sql:'" + sql.Replace("'", "$") + "'},";
     }
     if (HasHead)
     {
         if (TableHeadItems.NewSql != null)
         {
             sql = TableHeadItems.NewSql;
         }
         else
         {
             sql = TableHeadItems.Sql;
         }
         sql = sql.Replace("$", "'");
         //sql执行表达式
         Program prog = new Program("$" + sql + "$", this, false);
         sql = prog.Parse(prog.Exp).DynamicInvoke() + "";
         result = result + "{name:'" + TableHeadItems.Name + "',sql:'" + sql.Replace("'", "$") + "'},";
     }
     for (int i = 0; i < TableBodyItems.Count; i++)
     {
         BodyDatas bd = TableBodyItems[i];
         sql = "";
         if (bd.NewSql != null)
         {
             sql = bd.NewSql;
         }
         else
         {
             sql = bd.Sql;
         }
         sql = sql.Replace("$", "'");
         //sql执行表达式
         Program prog = new Program("$" + sql + "$", this, false);
         sql = prog.Parse(prog.Exp).DynamicInvoke() + "";
         result = result + "{name:'" + bd.Name + "',sql:'" + sql.Replace("'", "$") + "'},";
     }
     result = "[" + result.Substring(0, result.Length - 1) + "]";
     //如果有条件,替换条件
     if (Condition != null && Condition != "")
     {
         //条件中的单引号替换成$,供后台解析
         string condition = Condition.Replace("'", "$");
         result = result.Replace("#condition#", condition);  
     }
     return result;
 }
Exemplo n.º 7
0
 public void OnLoaded(object o, RoutedEventArgs e)
 {
     //避免重复工作
     _targetObject.GetType().GetEvent("Loaded").RemoveEventHandler(_targetObject, handler);
     handler = null;
     //对表达式进行解析,在绑定发生变化时,调用表达式执行
     //可以对一组表达式工作,表达式之间用'|or|'分割
     string[] strs = Str.Split(new String[] { "|or|" }, StringSplitOptions.RemoveEmptyEntries);
     foreach (string str in strs)
     {
         Program  prog   = new Program(str, _targetObject, true);
         Delegate result = prog.Parse(prog.Exp);
         Result     = result;
         Expression = prog.exp;
         //如果目标是一个代理,直接把编译结果给目标
         if (_targetProperty != null && _targetProperty.PropertyType == typeof(Delegate))
         {
             _targetProperty.SetValue(_targetObject, result, null);
             return;
         }
         //如果有事件,则只是在事件发生时才执行表达式。第一次默认及属性变化都不执行。
         if (prog.Events.Count == 0)
         {
             //先执行一次默认赋值过程,然后当属性值改变时,再调用每个赋值过程
             Assign(result);
             foreach (BindingSlave bs in prog.Bindings)
             {
                 //把BS保存起来,以免丢失
                 bs.Result = result;
                 _bindings.Add(bs);
                 bs.PropertyChanged += (o1, e1) =>
                 {
                     if (e1.PropertyName == "Value")
                     {
                         BindingSlave _bs = (BindingSlave)o1;
                         Assign(bs.Result);
                         //如果是集合本身变了,要监听集合内容的变化过程
                         if (_bs.Value is INotifyCollectionChanged)
                         {
                             MonityCollection(_bs);
                         }
                     }
                 };
                 //如果绑定到了集合,要监听集合变化过程
                 if (bs.Value is INotifyCollectionChanged)
                 {
                     MonityCollection(bs);
                 }
             }
         }
         //执行事件触发时的表达式计算过程
         foreach (ObjectEvent ei in prog.Events)
         {
             if (ei.Event.EventHandlerType == typeof(SelectionChangedEventHandler))
             {
                 ei.Event.AddEventHandler(ei.Object, new SelectionChangedEventHandler((o1, e1) => { Assign(result); }));
             }
             else if (ei.Event.EventHandlerType == typeof(RoutedEventHandler))
             {
                 ei.Event.AddEventHandler(ei.Object, new RoutedEventHandler((o1, e1) => { Assign(result); }));
             }
             else if (ei.Event.EventHandlerType == typeof(AsyncCompletedEventHandler))
             {
                 ei.Event.AddEventHandler(ei.Object, new AsyncCompletedEventHandler((o1, e1) => { Assign(result); }));
             }
             else if (ei.Event.EventHandlerType == typeof(MouseButtonEventHandler))
             {
                 ei.Event.AddEventHandler(ei.Object, new MouseButtonEventHandler((o1, e1) => { Assign(result); }));
             }
             else if (ei.Event.EventHandlerType == typeof(RoutedPropertyChangedEventHandler <object>))
             {
                 ei.Event.AddEventHandler(ei.Object, new RoutedPropertyChangedEventHandler <object>((o1, e1) => { Assign(result); }));
             }
             else if (ei.Event.EventHandlerType == typeof(PopulatingEventHandler))
             {
                 ei.Event.AddEventHandler(ei.Object, new PopulatingEventHandler((o1, e1) => { Assign(result); }));
             }
             else if (ei.Event.EventHandlerType == typeof(RoutedPropertyChangedEventHandler <Boolean>))
             {
                 ei.Event.AddEventHandler(ei.Object, new RoutedPropertyChangedEventHandler <Boolean>((o1, e1) => { Assign(result); }));
             }
             else if (ei.Event.EventHandlerType == typeof(NotifyCollectionChangedEventHandler))
             {
                 ei.Event.AddEventHandler(ei.Object, new NotifyCollectionChangedEventHandler((o1, e1) => { Assign(result); }));
             }
             else if (ei.Event.EventHandlerType == typeof(EventHandler))
             {
                 ei.Event.AddEventHandler(ei.Object, new EventHandler((ol, el) => { Assign(result); }));
             }
             else
             {
                 throw new Exception("不支持这种事件类型:" + ei.Event.EventHandlerType);
             }
         }
     }
 }