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;


namespace eFrameWork.Manage
{
    public partial class Records : System.Web.UI.Page
    {
        public eList elist;
        public eForm edt;
        public eUser user;
        string sql = "";
        public string act = eParameters.Request("act");
        protected void Page_Load(object sender, EventArgs e)
        {
            user = new eUser("Manage");           
            edt = new eForm("a_eke_sysDataRecords", user);
            if (act.Length == 0)
            {
                List();
                return;
            }
            if (act == "copy")
            {
                sql = "Insert into a_eke_sysDataRecords (RecordID,ServiceID,Name,DataSourceID,relationJson,tempSql,resultSql,remark,outType)";
                sql += " SELECT '" + Guid.NewGuid().ToString() + "',ServiceID,Name + ' 复件',DataSourceID,relationJson,tempSql,resultSql,remark,outType FROM a_eke_sysDataRecords where RecordID='" + eParameters.QueryString("id") + "'";

                eBase.DataBase.Execute(sql);
                if (Request.ServerVariables["HTTP_REFERER"] == null)
                {
                    Response.Redirect("Records.aspx", true);
                }
                else
                {
                    Response.Redirect(Request.ServerVariables["HTTP_REFERER"].ToString(), true);
                }
                Response.End();

            }

            //edt.AutoRedirect = false;
            edt.AddControl(f1);//名称
            edt.AddControl(f2);//数据源
            edt.AddControl(f3);//说明
            edt.AddControl(f4);//输出类型
            edt.onChange += new eFormTableEventHandler(edt_onChange);
            edt.Handle();
        }
        public void edt_onChange(object sender, eFormTableEventArgs e)
        {
            //eBase.End();
            if (e.eventType == eFormTableEventType.Inserting)
            {
                if (user["ServiceID"].Length > 0) edt.Fields.Add("ServiceID", user["ServiceID"]);
            }
        }
        private void List()
        {
            elist = new eList("a_eke_sysDataRecords");
            //elist.Fields.Add("*");
            elist.Where.Add("delTag=0");
            elist.Where.Add("ServiceID" + (user["ServiceID"].Length == 0 ? " is null" : "='" + user["ServiceID"] + "'"));

            elist.Where.Add(eSearchControlGroup);
            elist.OrderBy.Add("addTime desc");

            elist.Bind(Rep, ePageControl1);
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (Master == null) return;
            Literal lit = (Literal)Master.FindControl("LitTitle");
            if (lit != null)
            {
                lit.Text = "数据集管理 - " + eConfig.manageName(); 
            }
        }
    }
}