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.FrameWork;
using EKETEAM.Data;

namespace eFrameWork.Manage
{
    public partial class ModelItems_CheckUp : System.Web.UI.Page
    {
        public string modelid = eParameters.QueryString("modelid");
        public string getJsonText(string jsonstr, string name)
        {
            StringBuilder sb = new StringBuilder();
            if (jsonstr.Length > 0)
            {
                eJson json = new eJson(jsonstr);
                foreach (eJson m in json.GetCollection())
                {
                    sb.Append("<span style=\"display:inline-block;margin-right:6px;border:1px solid #ccc;padding:3px 12px 3px 12px;\">" + HttpUtility.HtmlDecode(m.GetValue(name)) + "</span>");
                }
            }
            return sb.ToString();
        }
        private DataRow _modelinfo;
        public DataRow ModelInfo
        {
            get
            {
                if (_modelinfo == null)
                {
                    DataTable dt = eOleDB.getDataTable("select * from a_eke_sysModels where ModelID='" + modelid + "'");
                    if (dt.Rows.Count > 0) _modelinfo = dt.Rows[0];
                }
                return _modelinfo;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            if (eConfig.showHelp())
            {
                Response.Write("<div class=\"tips\" style=\"margin-bottom:6px;\">");
                Response.Write("<b>审批</b><br>");
                Response.Write("设置本模块的审批流程。<br>需要做审批的模块，数据结构必须包含CheckupCode(当前审批状态编码)和CheckupText(当前审批状态名称)两个列且设置数据库默认值为未审批状态。<br>");
                Response.Write("</div> ");
            }
            if (ModelInfo["code"].ToString().Length == 0) return;
            string AllCols = eOleDB.getTableColumnNames(ModelInfo["code"].ToString(), "").ToLower();
           


            DataRow dr = eOleDB.getDataTable("select * from a_eke_sysModels where ModelID='" + modelid + "'").Select()[0];
            //Response.Write("&nbsp;动作权限：<input type=\"text\" value=\"" + System.Web.HttpUtility.HtmlEncode(dr["actionPower"].ToString()) + "\" oldvalue=\"" + System.Web.HttpUtility.HtmlEncode(dr["actionPower"].ToString()) + "\"  class=\"edit\" style=\"width:650px;\" onBlur=\"setModel(this,'actionPower');\" />");
            //Response.Write("&nbsp;权限控制：<br>");
            //Response.Write("<textarea reload=\"true\" id=\"actionpower\" jsonformat=\"[{&quot;text&quot;:&quot;动作编码&quot;,&quot;value&quot;:&quot;action&quot;},{&quot;text&quot;:&quot;字段编码&quot;,&quot;value&quot;:&quot;field&quot;},{&quot;text&quot;:&quot;值&quot;,&quot;value&quot;:&quot;value&quot;}]\" name=\"textarea\" style=\"width:90%;display:none;\" rows=\"2\"  onBlur=\"setModel(this,'actionpower');\" oldvalue=\"" + System.Web.HttpUtility.HtmlEncode(dr["actionPower"].ToString()) + "\">" + System.Web.HttpUtility.HtmlEncode(dr["actionPower"].ToString()) + "</textarea>");
            //Response.Write("<img src=\"images/jsonedit.jpg\" style=\"cursor:pointer;margin-right:5px;\" align=\"absmiddle\" onclick=\"Json_Edit('actionpower');\">");
            //Response.Write(getJsonText(dr["actionPower"].ToString(), "action"));
            //if (eConfig.showHelp()) Response.Write(" <img src=\"images/help.gif\" align=\"absmiddle\" border=\"0\" onclick=\"showHelp(165);\" title=\"查看帮助\" alt=\"查看帮助\" style=\"cursor:pointer;margin-bottom:4px;\">");


            if (AllCols.ToLower().IndexOf("checkupcode") == -1 || AllCols.ToLower().IndexOf("checkuptext") == -1) return;
            //Response.Write("<br>\r\n");
            //Response.Write("<br>\r\n");            
            eList elist = new eList("a_eke_sysCheckUps");
            elist.Where.Add("ModelID='" + modelid + "' ");
            elist.Where.Add("delTag=0");
            elist.OrderBy.Add("px,addTime");
            elist.Bind(Rep);



            System.IO.StringWriter sw = new System.IO.StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            Rep.RenderControl(htw);
            Rep.Visible = false;//不输出，要在获取后设，不然取不到内容。
            Response.Write(sw.ToString());
            sw.Close();
            Response.End();

        }
    }
}