All pastes #541798 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-06-05 16:43 UTC
rendered paste body
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using X.API;
using System.IO;
using Humano2.Components.WebTools;
using System.Threading;
using System.Globalization;

public partial class displayQuery : Humano2.Components.WebTools.BasePage
{
    public static int totalRecords;
    public static int totalPages;
    public static int rowsPerPage;
    public static int currentPage;
    public static int rowsInit;
    public static int rowsEnd;
    static DataTable layoutsList;
    static DataTable updateFormsList;
    static string titleColumnHTML;
    static string classId;
    static string queryId;

    protected void Page_Load(object sender, EventArgs e)
    {
       
        Trace.Warn("Page_Load", "Entering");
        try
        {
            string page = Request.QueryString["page"];
            if (page != null)
            {
                this.pageNumber.Value = page;
                
            }
            
            int domainId = APIBuilder.GetCurrentDomainId();
            int userId = APIBuilder.GetCurrentUserId();
            if ((userId != 0) && (domainId != 0))
            {
                string instanceIdToDelete = Request.QueryString["deleteId"];
                if (Request.Form.Count != 0 || instanceIdToDelete != null)
                {
                    ArrayList instancesToDelete = new ArrayList();
                    // for all the checked boxes, delete the instances
                    foreach (string key in Request.Form.AllKeys)
                    {
                        if (key.Contains("checkbox"))
                        {
                            string instanceId = (string)Request.Form[key];
                            instancesToDelete.Add(instanceId);
                        }
                    }
                    if (instanceIdToDelete != null)
                    {
                        // delete this instance                    
                        instancesToDelete.Add(instanceIdToDelete);
                    }
                    QueryHelper queryHelper = new QueryHelper();
                    queryHelper.deleteInstances(instancesToDelete);

                }

                queryId = Request.QueryString["queryId"];
                if ((queryId != null) && (queryId != ""))
                {
                    
                    APIClass api = new APIClass();
                    DataTable dt = api.Query(10751, "10753,10752,32468,10832", "0", queryId);
                    DataTable ddlist = new DataTable();
                    if (dt.Rows.Count > 0)
                    {
                        string query = dt.Rows[0][0].ToString();
                        int rowsPerPage = int.Parse(dt.Rows[0][2].ToString());
                        #region Clean Query
                        query = query.Substring(1, query.Length - 1);
                        query = query.Replace("\"\"", "@");
                        query = query.Replace("\"", "");
                        query = query.Replace("@", "\"");
                        #endregion

                        DataTable dt2 = executeQuery(query, rowsPerPage);
                        string templateHTML = "";

                        DataRow[] datos = dt2.Select();
                        int colsQty = dt2.Columns.Count;
                        int ItemsQty = dt2.Rows.Count;
                        string finalHtml = "";
                        string pagerHTML = "";
                        this.ClassName.InnerHtml = "<h1>" + dt.Rows[0][1].ToString() + "</h1>";
                 
                        classId = dt.Rows[0][3].ToString();
                        // this.editTheView.InnerHtml = "<a href=\"contentFrame.aspx?mode=4&classId=" + classId + "&type=query&bar=administration/cTree.aspx&showviewFr=administration/querytoolalpha.aspx?queryId=" + queryId + "&mode=update\" target=\"toolbox\">edit view</a>";

                        if (this.IsPostBack == false)
                        {
                            titleColumnHTML = "";
                            Trace.Warn("Foreach", "Entering");
                            foreach (DataColumn column in dt2.Columns)
                            {
                                if ((column.ColumnName != "id_entity") && (column.ColumnName != "class"))
                                    titleColumnHTML += "<td id=\"td-" + column.ColumnName + "\" class=\"relatedInfoSubheader2\" border=\"0\"  >" + AttributeHelper.getAttNameForAttSysName(column.ColumnName) + "&nbsp;</td>";
                                //titleColumnHTML += "<td id=\"td-" + column.ColumnName + "\" class=\"relatedInfoSubheader2\" border=\"0\"  >" + column.ColumnName + "&nbsp;</td>";
                                if (column.ColumnName == "id_entity1")
                                {
                                    titleColumnHTML += "<td class=\"relatedInfoSubheader2\" border=\"0\" style=\"width:45px\">&nbsp;</td>";
                                }

                            }
                            Trace.Warn("Foreach", "Exiting");
                            titleColumnHTML = "<tr>" + titleColumnHTML + "</tr>";


                            // retrieve the name and the id of the layouts linked to this id_entity
                            LayoutHelper layoutHelper = new LayoutHelper();
                            Trace.Warn("getLayoutsByClassId", "Entering");
                            layoutsList = layoutHelper.getLayoutsByClassId(int.Parse(classId));
                            Trace.Warn("getLayoutsByClassId", "Exiting");
                            // get the list of Update forms available for this class
                            FormHelper formHelper = new FormHelper();
                            Trace.Warn("getAllUpdateFormsByClassId", "Entering");
                            updateFormsList = formHelper.getAllUpdateFormsByClassId(int.Parse(classId));
                            Trace.Warn("getAllUpdateFormsByClassId", "Exiting");
                        }

                        if (ItemsQty > 0)
                        {

                            Trace.Warn("For", "Entering");
                            for (int i = 0; i < ItemsQty; i++)
                            {
                                string id_identity = datos[i].ItemArray[1].ToString();
                                string classId_ = datos[i].ItemArray[2].ToString();
                                templateHTML = "\n<tr class=\"basicToolBarRow\" onmouseover=\"toggleClassName(this, 'alternateRowColumn');\" onmouseout=\"toggleClassName(this, 'alternateRowColumn');\"> \n" +
                                "<td class=\"regularRowColumn\"  style=\"width:25px;border-bottom:solid 1px #E0EEEE;\">" +
                                "<label><input type=\"checkbox\" name=\"checkbox" + id_identity + "\" value=\"" + id_identity + "\" id=\"" + id_identity + "\" /></label></td>" +
                                "<td class=\"regularRowColumn\" style=\"width:45px;border-bottom:solid 1px #E0EEEE;\">" +
                                javascriptMenu(layoutsList, updateFormsList, classId, id_identity, queryId) + "</td>";

                                for (int j = 3; j < colsQty-1; j++) //start from 2 in order to hide idEntity and classId
                                {
                                    // templateHTML += "<td border=\"1\" class=\"regularRowColumn\"><a href=\"DetailFrameSet.aspx?page=layout.aspx&instanceId=" + id_identity + "&classId=" + classId_ + "\"  target=\"itemsFR\" onclick=\"top.displayItemsFrame();\">" + datos[i].ItemArray[j].ToString() + "</a>&nbsp;</td>";
                                    // the links are now in the menu in the left
                                    templateHTML += "<td border=\"0\" class=\"regularRowColumn\" style=\"border-bottom:solid 1px #E0EEEE;\">" + datos[i].ItemArray[j].ToString() + "&nbsp;</td>";
                                }

                                templateHTML += "</tr>";

                                finalHtml += templateHTML;
                            }
                            Trace.Warn("For", "Exiting");
                            totalPages = (int)Math.Ceiling((double)totalRecords / (double)rowsPerPage);
                            //pagerHTML = "<tr><td colspan=\"7\" class=\"relatedInfoSubheader2\"> " +
                            //    "<span class=\"tableFooterJumpTo\">Go to page number<input type=\"text\" name=\"txtPageNumber\" id=\"txtPageNumber\" runat=\"server\"  size=\"5\" />" +
                            //    "<input type=\"submit\" name=\"goToPageButton\" value=\"OK\" onclick=\"changePage(" + queryId + ")\" /></span>" +
                            //    "<span class=\"tablePager\"> Page " + currentPage + " of " + totalPages.ToString() + " </span></td></tr>";

                        }
                        else
                        {
                            totalPages = 1;
                            finalHtml = "\n<tr class=\"basicToolBarRow\" onmouseover=\"toggleClassName(this, 'alternateRowColumn');\" onmouseout=\"toggleClassName(this, 'alternateRowColumn');\"> \n" +
                                "<td class=\"regularRowColumn\"  style=\" border-bottom:solid 1px #E0EEEE;\" colspan=\"" + colsQty + "\">" +
                                " This view contains no data. </td></tr>";

                        }
                        this.RangeValidator1.MaximumValue = totalPages.ToString();
                        finalHtml = titleColumnHTML + finalHtml;

                        this.portalContent.InnerHtml = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + finalHtml + "</table>";
                        //this.pagerContent.InnerHtml += "<div id='pagerDiv' style='position:absolute;bottom:6px'><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"></table></div>";
                        portalContent.Visible = true;

                    }
                    switch (totalPages)
                    {
                        case 2:
                            {
                                this.lastPage.Visible = false;
                                this.firstPage.Visible = false;
                                break;
                            }
                        default:
                            {
                                if (currentPage == totalPages)
                                {
                                    this.lastPage.Visible = false;
                                    this.nextPage.Visible = false;
                                }
                                if (currentPage == totalPages-1)
                                {
                                    this.lastPage.Visible = false;
                                  
                                }
                                if (currentPage == 1)
                                {
                                    this.firstPage.Visible = false;
                                    this.previousPage.Visible = false;
                                }
                                if (currentPage == 2)
                                {
                                    this.firstPage.Visible = false;
                                    
                                }
                                break;
                            }
                    }
                }

            }
            else
                Response.Redirect(Humano2.Components.WebTools.WebConst.LoginPage);
        }
        catch (Exception exc)
        {
            UserHelper loggedCheck = new UserHelper();
            if (loggedCheck.checkUserLogged())
                Response.Redirect(WebConst.ErrorPage, false);
            else
                Response.Redirect(WebConst.LoginPage, false);
        }
    }
    protected DataTable executeQuery(string query, int rowsPerPage)
    {
        Trace.Warn("executeQuery", "Entering");
        string[] querySections = new string[7];
        string[] stringSeparators = new string[] { ",\"", ", \"", ",'", ", '" };

        string[] queryAux = query.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);

        queryAux[1] = queryAux[1].Insert(0, "0,"); //always request id_entity in all queries.

        int paramNum = querySections.Length;

        for (int i = 0; i < 7; i++) //fill the rest of sections with ""
        {
            if (i < queryAux.Length)
                querySections[i] = queryAux[i];
            else
                querySections[i] = "";

            int varlength = querySections[i].Length;
            if ((varlength > 0) && ((querySections[i][varlength - 1] == '\"') || (querySections[i][varlength - 1].ToString() == "'")))
                querySections[i] = querySections[i].Substring(0, varlength - 1);
        }

        APIClass api = new APIClass();
        int classId = int.Parse(querySections[0]);
        string[] lolo = new string[6];
        for (int j = 1; j < 7; j++)
        {
            lolo[j - 1] = querySections[j];
        }

        if (this.pageNumber.Value != "")
            api.CurrentPage = int.Parse(this.pageNumber.Value);
        else
            currentPage = 1;

        api.RowsPerPage = rowsPerPage;
        if (Request.QueryString["IdEntityFrom"] != null)
        {
            #region addFilter
            string filter = lolo[1];
            // compare the id_entity from the previous request to the pertinence field
            string pertinenceId = Request.QueryString["pertinenceId"] + "";
            if (pertinenceId != "")
            {
                if (filter != null && filter != "")
                {
                    filter = filter.Replace("|0|0", "|1|0;" + pertinenceId + "|4|'" + Request.QueryString["IdEntityFrom"] + "'|0|0");
                }
                else
                {
                    filter = "" + pertinenceId + "|4|'" + Request.QueryString["IdEntityFrom"] + "'|0|0";
                    //filter = "34|8|{(''[DomainId]'',''10'')}|0|0";
                }
                lolo[1] = filter;
            }
            #endregion
        }
        DataTable dt = api.Query(classId, lolo);
        totalRecords = api.TotalRowsRecord;
        rowsPerPage = api.RowsPerPage;
        currentPage = api.CurrentPage;
        if (dt.Rows.Count > 0)
        {
            rowsInit = int.Parse(dt.Rows[0]["row"].ToString());
            rowsEnd = int.Parse(dt.Rows[dt.Rows.Count-1]["row"].ToString());
        }
        //dt.Columns.Remove("row");
        Trace.Warn("executeQuery", "Exiting");
        return dt;
    }
    protected string getEditFormLink()
    {

        //return "<a href=\"contentFrame.aspx?mode=4&classId=" + classId + "&type=query&bar=administration/cTree.aspx&showviewFr=administration/querytoolalpha.aspx?queryId=" + queryId + "&mode=update\" target=\"toolbox\">edit view</a>"; 
        return "/administration/querytoolalpha.aspx?queryId=" + queryId + "&mode=updatefromquery\" target=\"showViewFR\"";
    }
    protected string javascriptMenu(DataTable layoutsList, DataTable updateFormsList, string classId, string id_entity, string queryId)
    {


        string menu = "";
        if (layoutsList != null)
        {
            foreach (DataRow row in layoutsList.Rows)
            {
                string layoutName = "<nobr>" + row["c10748NombreLayout"].ToString() + "</nobr>";
                string href = "DetailFrameSet.aspx?page=layout.aspx&instanceId=" + id_entity + "&classId=" + classId + "&layoutId=" + row["id_entity"].ToString() + "&queryId=" + queryId;
                menu += " myMenu" + classId + ".add(new WebFXMenuItem(\"" + layoutName + "\", \"javascript:loadLayout('" + href + "');\")); ";
            }
        }
        if (updateFormsList != null)
        {
            // add a line to separate the 2 lists
            menu += " myMenu" + classId + ".add(new WebFXMenuSeparator()); ";
            foreach (DataRow row in updateFormsList.Rows)
            {
                string formName = "<nobr>" + row["c10754NombreFormulario"].ToString() + "</nobr>";
                string href = "DetailFrameSet.aspx?page=formDisplay.aspx&instanceId=" + id_entity + "&classId=" + classId + "&formId=" + row["id_entity"].ToString() + "&action=update" + "&queryId=" + queryId;
                menu += " myMenu" + classId + ".add(new WebFXMenuItem(\"" + formName + "\", \"javascript:loadLayout('" + href + "');\")); ";
            }
        }

        string javascriptMenu = "<script type=\"text/javascript\">" +
            "var myMenu" + classId + " = new WebFXMenu(); " +
            menu +
            " var myBar" + classId + " = new WebFXMenuBar(); " +
            " myBar" + classId + ".add(new WebFXMenuButton(\" \", null, null, myMenu" + classId + ")); " +
            " document.write(myBar" + classId + "); " +
            "</script>";

        return javascriptMenu;
    }
    protected void nextPage_Click(object sender, EventArgs e)
    {
        if (currentPage < totalPages)
        {
            int page = currentPage + 1;
            this.pageNumber.Value = page.ToString();
            Response.Redirect("displayQuery.aspx?queryId="+queryId+"&page="+page);
            //this.msgSpan.InnerHtml = "<script>changePage(" + queryId + ");</script>";
        }
    }
    protected void prevPage_Click(object sender, EventArgs e)
    {
        if (currentPage > 1)
        {
            int page = currentPage - 1;
            this.pageNumber.Value = page.ToString();
            Response.Redirect("displayQuery.aspx?queryId=" + queryId + "&page=" + page);
            //this.msgSpan.InnerHtml = "<script>changePage(" + queryId + ");</script>";
        }
    }
    protected void lastPage_Click(object sender, EventArgs e)
    {

        this.pageNumber.Value = totalPages.ToString();
        Response.Redirect("displayQuery.aspx?queryId=" + queryId + "&page=" + totalPages.ToString());
       // this.msgSpan.InnerHtml = "<script>changePage(" + queryId + ");</script>";
      
    }
    protected void firstPage_Click(object sender, EventArgs e)
    {

        this.pageNumber.Value = "1";
        Response.Redirect("displayQuery.aspx?queryId=" + queryId + "&page=1");

        //this.msgSpan.InnerHtml = "<script>changePage(" + queryId + ");</script>";

    }
    protected override void InitializeCulture()
    {
        string lang = (string)Session["Language"];

        if ((lang != null))
        {
            if (lang != "")
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
            }
        }
    }
    protected void delete(object sender, EventArgs e)
    {
        this.msgSpan.InnerHtml= "<script>document.forms.form1.submit()</script>";
   
    }


    protected void editLink_Click(object sender, EventArgs e)
    {
       
    }
}