Esempio n. 1
0
    private void Page_Load(System.Object sender, System.EventArgs e)
    {
        //Make sure the user is logged in. If not forward user to login page.
        if ((m_refContentApi.EkContentRef).IsAllowed(0, 0, "users", "IsLoggedIn", m_refContentApi.UserId) == false)
        {
            string strUrl;
            Session["RedirectLnk"] = Request.Url.AbsoluteUri;
            strUrl = "login.aspx?fromLnkPg=1";
            this.Response.ContentType = "";
            this.Response.Redirect(strUrl, true);
        }

        //Put user code to initialize the page here
        int ContentLanguage = m_refContentApi.ContentLanguage;
        if (!(Request.QueryString["LangType"] == null))
        {
            if (Request.QueryString["LangType"] != "")
            {
                ContentLanguage = Convert.ToInt32(Request.QueryString["LangType"]);
                m_refContentApi.SetCookieValue("LastValidLanguageID", ContentLanguage.ToString());
            }
            else
            {
                if (m_refContentApi.GetCookieValue("LastValidLanguageID") != "")
                {
                    ContentLanguage = Convert.ToInt32(m_refContentApi.GetCookieValue("LastValidLanguageID"));
                }
            }
        }
        else
        {
            if (m_refContentApi.GetCookieValue("LastValidLanguageID") != "")
            {
                ContentLanguage = Convert.ToInt32(m_refContentApi.GetCookieValue("LastValidLanguageID"));
            }
        }
        if (ContentLanguage == (int)Ektron.Cms.Common.EkConstants.CONTENT_LANGUAGES_UNDEFINED)
        {
            m_refContentApi.ContentLanguage = Ektron.Cms.Common.EkConstants.ALL_CONTENT_LANGUAGES;
        }
        else
        {
            m_refContentApi.ContentLanguage = ContentLanguage;
        }
        if (!(Request.QueryString["fieldname"] == null))
        {
            FieldName = Request.QueryString["fieldname"];
        }
        QueryLang = ContentLanguage.ToString();
        if (!(Request.QueryString["qlang"] == null))
        {
            QueryLang = Request.QueryString["qlang"];
        }
        if (!String.IsNullOrEmpty(Request["form_id"]))
        {
            FormId = Convert.ToInt64(Request["form_id"]);
        }
        StartDate = Request["start_date"];
        EndDate = Request["end_date"];
        Flag = Request["flag"];
        DataType = Request["data_type"];
        ResultType = Request["result_type"];
        CurrentUserId = m_refContentApi.UserId;
        DisplayType = Request["display_type"];
        FormTitle = Request["form_title"];
        m_refMsg = m_refContentApi.EkMsgRef;
        Security_info = m_refContentApi.LoadPermissions(FormId, "content", 0);
        Response.AddHeader("content-disposition", "attachment; filename=Form_Data_Export.xls");
        objForm = m_refContentApi.EkModuleRef;
        gtForms = objForm.GetAllFormInfo();

        Collection objFormData = new Collection();
        Collection cDatas;
        objFormData.Add(FormId, "FORM_ID", null, null);
        objFormData.Add(CurrentUserId, "USER_ID", null, null);
        objFormData.Add(StartDate, "START_DATE", null, null);
        objFormData.Add(EndDate, "END_DATE", null, null);
        objFormData.Add(QueryLang, "Query_Language", null, null);
        objFormData.Add(FieldName, "Field_Name", null, null);
        cDatas = objForm.GetAllFormData(objFormData);
        if (cDatas.Count == 0)
        {
            FormResult.Text = "<table><tr><td>" + m_refMsg.GetMessage("msg no data report") + "</td></tr></table>";
            return;
        }

        if (Information.IsNumeric(DisplayType))
        {
            //The following lines of code are extracted from dotnetjohn.com on "Export DataSets to Excel"
            //http://www.dotnetjohn.com/articles.aspx?articleid=36
            //first let's clean up the response.object
            Response.Clear();
            Response.Charset = "";
            //set the response mime type for excel
            Response.ContentType = "application/vnd.ms-excel";
            //create a string writer
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            //create an htmltextwriter which uses the stringwriter
            System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
            //instantiate a datagrid
            DataGrid dg = new DataGrid();
            //set the datagrid datasource to the dataset passed in
            dg.DataSource = objForm.GetAllFormRawData(objFormData).Tables[0];
            //bind the datagrid
            dg.DataBind();
            //tell the datagrid to render itself to our htmltextwriter
            dg.RenderControl(htmlWrite);
            //all that's left is to output the html
            Response.Write(stringWrite.ToString());
            Response.End();
        }
        else
        {
            FormResult.Text = LoadResult(objFormData, cDatas);
        }
    }