Esempio n. 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);
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 清除所有数据
 /// </summary>
 public void Clear()
 {
     HasLeft = false;
     HasHead = false;
     this.cells.Clear();
     this.columns.Clear();
     this.rows.Clear();
     TableBodyItems.Clear();
     TableLeftItems = new BodyDatas();
     TableHeadItems = new BodyDatas();
     bodyCellTemplate.Clear();
     leftCellTemplate.Clear();
     headCellTemplate.Clear();
     headChangeCellTemplate.Clear();
 }
Esempio n. 3
0
        /// <summary>
        /// 加载每页数据
        /// </summary>
        private void LoadDetail()
        {
            //如果有左侧不加载总数
            string    uri    = WebClientInfo.BaseAddress + "/sql/" + PageIndex + "/" + PageSize;
            string    sqls   = getJsonSql();
            WebClient client = new WebClient();

            client.UploadStringCompleted += (o, a) =>
            {
                IsBusy = false;
                if (a.Error != null || a.Result == null)
                {
                    MessageBox.Show("加载报表数据失败!");
                    return;
                }
                JsonObject item = JsonValue.Parse(a.Result) as JsonObject;
                if (HasLeft)
                {
                    JsonArray array = item["left"] as JsonArray;
                    TableLeftItems.Value.FromJson(array);
                }
                if (HasHead)
                {
                    JsonArray array = item["head"] as JsonArray;
                    TableHeadItems.Value.FromJson(array);
                }
                for (int i = 0; i < TableBodyItems.Count; i++)
                {
                    BodyDatas bd    = TableBodyItems[i];
                    JsonArray array = item[bd.Name] as JsonArray;
                    bd.Value.FromJson(array);
                }
                //画界面
                UpdateElement();
            };
            IsBusy = true;
            client.UploadStringAsync(new Uri(uri), sqls);
        }
Esempio n. 4
0
 /// <summary>
 /// 根据名称获得sql,左侧数据name为left
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public string GetSql(string name)
 {
     //表头数据
     if (name == "head")
     {
         return(TableHeadItems.Sql);
     }
     //左侧数据
     if (name == "left")
     {
         return(TableLeftItems.Sql);
     }
     for (int i = 0; i < TableBodyItems.Count; i++)
     {
         BodyDatas bd = TableBodyItems[i];
         if (name == bd.Name)
         {
             return(bd.Sql);
         }
     }
     MessageBox.Show("没有找到name为" + name + "的sql!");
     return(null);
 }
Esempio n. 5
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);
        }
Esempio n. 6
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));
        }
Esempio n. 7
0
 /// <summary>
 /// 清除所有数据
 /// </summary>
 public void Clear()
 {
     HasLeft = false;
     HasHead = false;
     this.cells.Clear();
     this.columns.Clear();
     this.rows.Clear();
     TableBodyItems.Clear();
     TableLeftItems = new BodyDatas();
     TableHeadItems = new BodyDatas();
     bodyCellTemplate.Clear();
     leftCellTemplate.Clear();
     headCellTemplate.Clear();
     headChangeCellTemplate.Clear();
 }
Esempio n. 8
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);
         }
     }
 }
Esempio n. 9
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);
                 //保存列初始化数据
                 this.columns_init.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));
 }