using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using SysCore;

public partial class System_GrfPrinter_MakeXmlData : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["test"] = "feel";
        make_xml();
    }
    string make_xml()
    {
        SqlUtil su = new SqlUtil();

        string sql_main = "";
        string sql_detail = "";
        if (Session[Request.QueryString["sql_print_main_session_id"]] != null)
        {
            sql_main = Session[Request.QueryString["sql_print_main_session_id"]].ToString();
        }
        if (Session[Request.QueryString["sql_print_detail_session_id"]] != null)
        {
            sql_detail = Session[Request.QueryString["sql_print_detail_session_id"]].ToString();
        }
        if (sql_main.Equals(""))
        {
            sql_main = "select 1 as temp_main_sql";
        }
        if (sql_detail.Equals(""))
        {
            sql_detail = "select 1 as temp_detail_sql";
        }
        Session["print_sql_main"] = sql_main;
        Session["print_sql_detail"] = sql_detail;
        DataTable dt = su.GetDataTable(sql_main, null);
        int col_count = dt.Columns.Count;
        string main_xml = "";
        foreach(DataRow dr in dt.Rows)
        {
            for (int i = 0; i < col_count; i++)
            {
                string col_name = dt.Columns[i].ColumnName;
                main_xml = main_xml + "<" + col_name + ">" + dr[i].ToString() + "</" + col_name + ">";
            }
        }
        main_xml = "<_grparam>" + main_xml + "</_grparam>";
        
        sql_detail = "select isnull((" + sql_detail + " for xml raw),'') as body_xml";
        
        string body_xml = su.ExecuteScalar(sql_detail, null).ToString();
        body_xml = "<xml>" + body_xml + "</xml>";
        body_xml = "<report>" + body_xml + main_xml  + "</report>";
        Response.Write(body_xml);

        return "";
    }
}