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

namespace eFrameWork.AppMobile
{
    public partial class Model : System.Web.UI.Page
    {
        public string AppItem = eParameters.Request("AppItem");
        public string ModelID = eParameters.Request("ModelID");
        public eModel model;
        private eUser user;
        DataRow appRow;

        protected void Page_Load(object sender, EventArgs e)
        {
            user = new eUser("AppMobile");
            user.Check();
            if (AppItem.Length > 0)
            {
                DataRow[] appRows = eBase.a_eke_sysApplicationItems.Select("ApplicationItemID='" + AppItem + "'");
                if (appRows.Length == 0) Response.End();
                appRow = appRows[0];
                if (ModelID.Length == 0) ModelID = appRow["ModelID"].ToString();
                model = new eModel(AppItem, ModelID, user);
            }
            else
            {
                model = new eModel(ModelID, user);
            }
            model.Mode = "mobile";

            switch (model.Action.Value)
            {
                case "building":
                    LitBody.Text = "<div style=\"text-align:center;margin-top:20px;\"><img src=\"../images/Building.jpg\" style=\"width:280px;\" /></div>";
                    break;
                case "":
                    if (model.ModelInfo["type"].ToString() == "4")//报表
                    {
                        LitBody.Text = model.getReportList();
                    }
                    else
                    {
                        LitBody.Text = model.getListHTML();
                    }
                    break;
                case "add":
                    LitBody.Text = model.getAddHTML();
                    break;
                case "edit":
                    LitBody.Text = model.getEditHTML();                 
                    break;
                case "copy":
                    LitBody.Text = model.getEditHTML();
                    break;
                case "view":
                    LitBody.Text = model.getViewHTML();
                    break;
                case "save":
                    model.Save();
                    break;
                case "del":
                    model.Delete();
                    break;
                case "addsub":
                    eBase.Write(model.getAddHTML());
                    eBase.End();
                    break;
                case "viewsub":
                    eBase.Write(model.getViewHTML());
                    eBase.End();
                    break;
            }
            
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            Literal lit = (Literal)Master.FindControl("LitTitle");
            if (lit != null)
            {
                lit.Text = model.ModelInfo["mc"].ToString() + " - " + eConfig.systemName();
            }
            lit = (Literal)Master.FindControl("LitJavascript");
            if (lit != null && model.Javasctipt.Length > 0)
            {
                lit.Text = model.Javasctipt;
            }
        }
    }
}