Beispiel #1
0
 /// <summary>
 /// 根据name,设置新的sql,如果原来没有这个name,添加新的sql对象
 /// </summary>
 /// <param name="name"></param>
 /// <param name="sql"></param>
 public void PutSql(string name, string sql)
 {
     if (name == "head")
     {
         TableHeadItems.NewSql = sql; return;
     }
     if (name == "left")
     {
         TableLeftItems.NewSql = sql;
         return;
     }
     for (int i = 0; i < TableBodyItems.Count; i++)
     {
         BodyDatas bd = TableBodyItems[i];
         if (name == bd.Name)
         {
             bd.NewSql = sql;
             return;
         }
         else
         {
             //如果没有找到name,添加新的sql对象
             BodyDatas newbd = new BodyDatas();
             newbd.Name   = name;
             newbd.NewSql = sql;
             TableBodyItems.Add(newbd);
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 加载文件,获得所有需要执行的sql
        /// </summary>
        private void Init()
        {
            string uri = WebClientInfo.BaseAddress + "/" + FileName;
            //根据uri,去后台获取数据
            WebClient client = new WebClient();

            client.DownloadStringCompleted += (o, a) =>
            {
                IsBusy = false;
                if (a.Error != null)
                {
                    MessageBox.Show("加载报表文件失败!");
                }
                else
                {
                    JsonObject item = JsonValue.Parse(a.Result) as JsonObject;
                    //清除原来的数据
                    this.Clear();
                    //取出所有列定义
                    JsonArray columns = item["columns"] as JsonArray;
                    foreach (JsonObject obj in columns)
                    {
                        int    width  = obj["width"];
                        Column column = new Column()
                        {
                            Width = width
                        };
                        this.columns.Add(column);
                    }
                    //主体sql
                    JsonArray sqls = item["sqls"] as JsonArray;
                    for (int i = 0; i < sqls.Count; i++)
                    {
                        JsonObject obj  = sqls[i] as JsonObject;
                        string     name = obj["name"];
                        BodyDatas  bd   = new BodyDatas(name, obj["sql"], new ObjectList());
                        TableBodyItems.Add(bd);
                    }
                    //表头sql
                    string headsql = "";
                    if (item.ContainsKey("headsql"))
                    {
                        headsql = item["headsql"];
                    }
                    if (headsql != "")
                    {
                        HasHead              = true;
                        TableHeadItems.Name  = "head";
                        TableHeadItems.Sql   = headsql;
                        TableHeadItems.Value = new ObjectList();
                    }
                    //左侧sql
                    string leftsql = "";
                    if (item.ContainsKey("leftsql"))
                    {
                        leftsql = item["leftsql"];
                    }
                    if (leftsql != "")
                    {
                        HasLeft              = true;
                        TableLeftItems.Name  = "left";
                        TableLeftItems.Sql   = leftsql;
                        TableLeftItems.Value = new ObjectList();
                    }
                    //加载所有单元格模板
                    InitTemplate(item);
                }
            };
            IsBusy = true;
            client.DownloadStringAsync(new Uri(uri));
        }