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

public partial class Plugins_Procedure : System.Web.UI.Page
{
    public string UserArea = "Application";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.UrlReferrer == null) return;
        if (Request.Url.Host.ToLower() != Request.UrlReferrer.Host.ToLower()) return;
        if (!eConfig.portMapping && Request.Url.Port != Request.UrlReferrer.Port) return;

        eUser user = new eUser(eBase.getUserArea(UserArea));
        if (!user.Logined) eResult.Error("登录后操作!");
        user.Check();

        string datasource = eParameters.Form("datasource");
        string name = eParameters.Form("name");
        string param = eParameters.Form("params");
        string sql = "exec " + name + (param.Length > 0 ? " " + param : "");
        eDataBase db = eBase.DataBase;
        if (datasource.Length > 0) db = new eDataBase(datasource);
        DataTable dt = db.getDataTable(sql);
        if (dt.Rows.Count > 0)
        {
            eBase.WriteJson(dt.Rows[0].toJSONData().ToJson());
        }
        else
        {
            eBase.WriteJson("{}");
        }
        eBase.End();

    }
}