using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using EKETEAM.Data;
using EKETEAM.FrameWork;
using EKETEAM.UserControl;
using System.Xml;
using System.Xml.Serialization;
using LitJson;

namespace eFrameWork.Manage
{
    public partial class setModelField : System.Web.UI.Page
    {
        public eUser user;
        public string modelid = eParameters.QueryString("modelid");
        protected void Page_Load(object sender, EventArgs e)
        {

            user = new eUser("Manage");
            user.Check();


            DataTable dt = eBase.DataBase.getDataTable("select modelid,parentid,mc,code,joinmore from a_eke_sysModels where ModelID='" + modelid + "' order by addtime");
            addModel(dt, modelid);
            //eBase.PrintDataTable(dt);
            StringBuilder sb = new StringBuilder();
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["joinmore"].ToString() == "False") continue;
                sb.Append("<div class=\"tag\">" + dr["mc"].ToString() + ":</div>");
                sb.Append("<a href=\"javascript:;\" onclick=\"parent.setValue('{" + dr["Code"].ToString() + ":number}');\" class=\"tag\">行号</a>");
                sb.Append("<a href=\"javascript:;\" onclick=\"parent.setValue('count(" + dr["Code"].ToString() + ")');\" class=\"tag\">记录数</a>");
                string modelids="'" +  dr["modelid"].ToString() + "'";
                DataRow[] rs = dt.Select("parentid='" + dr["modelid"].ToString() + "' and joinmore=0");
                foreach (DataRow _dr in rs)
                {
                    modelids += ",'" + _dr["modelid"].ToString() + "'";
                }
               
                DataTable items = eBase.DataBase.getDataTable("SELECT modelid,MC,Code FROM a_eke_sysModelItems where ModelID in (" + modelids + ") and Custom=0 and Code not in ('delTime','delUser','delTag') order by num");
                //eBase.PrintDataTable(items);
                foreach (DataRow _dr in items.Rows)
                {
                    if (_dr["modelid"].ToString() != dr["modelid"].ToString() && ",addtime,adduser,edittime,edituser,".Contains(","+ _dr["code"].ToString().ToLower() +",")) continue;
                    sb.Append("<a href=\"javascript:;\" onclick=\"parent.setValue('{" + dr["Code"].ToString() + ":" + _dr["Code"].ToString() + "}');\" class=\"tag\">" + (_dr["mc"].ToString().Length > 0 ? _dr["mc"].ToString() : _dr["code"].ToString()) + "</a>");
                }

                sb.Append("<a href=\"javascript:;\" onclick=\"parent.appendValue('{" + dr["Code"].ToString() + ":循环开始}');\" class=\"tag\">循环开始</a>");
                sb.Append("<a href=\"javascript:;\" onclick=\"parent.appendValue('{" + dr["Code"].ToString() + ":循环结束}');\" class=\"tag\">循环结束</a>");

            }





            sb.Append("<div class=\"tag\">常用功能:</div>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('sum(',')');\" class=\"tag\">汇总</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('max(',')');\" class=\"tag\">最大值</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('min(',')');\" class=\"tag\">最小值</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('avg(',')');\" class=\"tag\">平均值</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('{interface:eBase.MoneyUpper(',')}');\" class=\"tag\">大写</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('barcode(',',13,150,70)');\" class=\"tag\">条码</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('qrcode(',',3,100,100)');\" class=\"tag\">二维码</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('image(',',100,100)');\" class=\"tag\">图片</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setValue('getdate()');\" class=\"tag\">当前时间</a>");

            sb.Append("<div class=\"tag\">格式化:</div>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('format(',',{0:yyyy-MM-dd HH:mm:ss})');\" class=\"tag\">年月日时分秒</a>");
            //sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('format(',',{0:yyyy-MM-dd HH:mm})');\" class=\"tag\">年月日时分</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('format(',',{0:yyyy-MM-dd})');\" class=\"tag\">年月日</a>");
            //sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('format(',',{0:yyyy-MM})');\" class=\"tag\">年月</a>");
            //sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('format(',',{0:yyyy})');\" class=\"tag\">年月</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('format(',',{0:F2})');\" class=\"tag\">2位小数</a>");
            //sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('format(',',{0:F3})');\" class=\"tag\">3位小数</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('format(',',{0:N2})');\" class=\"tag\">千分位2位小数</a>");
            //sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('format(',',{0:N3})');\" class=\"tag\">千分位3位小数</a>");

            sb.Append("<a href=\"javascript:;\" onclick=\"parent.setFunction('format(',',{0:P0})');\" class=\"tag\">百分比</a>");


            sb.Append("<div class=\"tag\">控制项:</div>");
           

            sb.Append("<a href=\"javascript:;\" onclick=\"parent.appendValue('页眉开始');\" class=\"tag\">页眉开始</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.appendValue('页眉结束');\" class=\"tag\">页眉结束</a>");

            sb.Append("<a href=\"javascript:;\" onclick=\"parent.appendValue('页脚开始');\" class=\"tag\">页脚开始</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.appendValue('页脚结束');\" class=\"tag\">页脚结束</a>");
            sb.Append("<a href=\"javascript:;\" onclick=\"parent.appendValue('分页符');\" class=\"tag\">分页符</a>");
            litBody.Text = sb.ToString();
        }
        private void addModel(DataTable dt, string pid)
        {
            DataTable tb = eBase.DataBase.getDataTable("select modelid,parentid,mc,code,joinmore from a_eke_sysModels where ParentID='" + pid + "' and Type in (1,3,6,7,8,12) and delTag=0 order by addtime,JoinMore");
            if (tb.Rows.Count > 0)
            {
                foreach (DataRow dr in tb.Rows)
                {
                    dt.Rows.Add(dr.ItemArray);
                    addModel(dt,dr["ModelID"].ToString());
                }
            }
        }



    }
}