using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
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 LitJson;

public partial class recordView : System.Web.UI.Page
{
    public string RecordID = eParameters.QueryString("RecordID");
    private DataRow _record;
    public DataRow Record
    {
        get
        {
            if (_record == null)
            {
                DataTable dt = eBase.DataBase.getDataTable("select * from a_eke_sysDataRecords where RecordID='" + RecordID + "'");
                if (dt.Rows.Count > 0) _record = dt.Rows[0];
            }
            return _record;
        }
    }
    public dynamic record = new eViewObject();

    private eDataBase _database;
    public eDataBase DataBase
    {
        get
        {
            if (_database == null)
            {
                if (Record["DataSourceID"].ToString().Length > 0)
                {
                    _database = new eDataBase(Record);
                }
                else
                {
                    _database = eConfig.DefaultDataBase;
                }
            }
            return _database;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        eUser user = new eUser("Manage");
        user.Check();


        if (RecordID.Length == 0)
        {
            RecordID = eBase.DataBase.getValue("select top 1 RecordID from a_eke_sysDataRecords where deltag=0 order by addTime desc");
        }
        record = eBase.DataBase.getValues("select * from a_eke_sysDataRecords where RecordID='" + RecordID + "'");


        //string tempsql = eBase.getRecordDesignSql(record.relationJson, DataBase.StartNameSplitChar, DataBase.EndNameSplitChar);
        //eBase.Writeln("tempsql=" + tempsql);
        //return;

       // eBase.Writeln(record.relationJson);
        //return;

        string sql = record.resultSql.Length > 0 ? record.resultSql : record.tempSql;
        //eBase.Writeln(sql);
        sql = eParameters.Replace(sql, null, null);
        //eBase.Writeln(sql);

        sql=sql.Replace("select ","select top 10 ");
        DataTable dt = DataBase.getDataTable(sql);
        //eBase.PrintDataTable(dt);
        litBody.Text = eBase.getTableHTML(dt,0,0,0,30);


    }
}