Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New window action causes original page controls to open new window!

Status
Not open for further replies.

lastdonuk

Programmer
Jan 19, 2005
58
GB
Hi,

I'm building a .NET 2.0 app using C#. Here's my issue:

I have a standard .aspx page with CodeBehind in a separate .cs page.

From this page, I'm opening a new page using target='_blank' from an OnClientClick to view a chart in a full window, notes, photos, etc and to do this I'm using a Response.Redirect with a QueryString:

The onClick does this (edited version):

Code:
protected void Report_Click(object sender, ImageClickEventArgs e)
{        
Response.Redirect("NewPage.aspx?data="+data);
}

This is called from an OnClick in an asp:ImageButton:

Code:
<asp:ImageButton ID="Report" runat="server" ImageUrl="~/images/report.gif" AlternateText="View Full Report (will open in a new window)" OnClick="Report_Click" OnClientClick="Form.target='_blank';" />

This works great, and took a while to get to this stage. HOWEVER, when I return to the original page, ANY control I then click on opens a new window! This applies to dropdowm lists, Help icons, anything on the page!

I'm thinking it could be to do with using a QueryString and therefore a GET action within an ASPX page which will POST
to itself by default, but am lost after that...

The only way to stop this is to Refresh the page, I'm obviously missing something here...any ideas?

Thanks in advance,
Bob




lastdonuk
 
Here you go, first the aspx:

Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="assignments.aspx.cs" Inherits="customers_assigntrack" EnableEventValidation = "false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head runat="server">
    <title>Customer Portal</title>
    <link type="text/css" rel="stylesheet" href="~/blue.css" id="stylesheet" />
    <script type="text/javascript" language="javascript" src="../js/FusionCharts.js"></script>
	<script type="text/javascript" language="javascript" src="../js/func.js"></script>
</head>
<body>
    <form id="AssignForm" runat="server">
        <div id="header">
            <span style="float:left;">Customer Portal</span>
            <asp:TextBox ID="CustomerCode" runat="server" Visible="False"></asp:TextBox><asp:TextBox ID="debug" runat="server" Visible="False"></asp:TextBox>
            <asp:TextBox ID="QuestionNo" runat="server" Visible="False"></asp:TextBox><asp:TextBox ID="AnswerNo" runat="server" Visible="False"></asp:TextBox>
            <asp:TextBox ID="GraphSet" runat="server" Visible="False">1</asp:TextBox>
            <asp:TextBox ID="current_group" runat="server" Visible="False"></asp:TextBox>&nbsp;
            <asp:TextBox ID="FormState" runat="server" Visible="False">1</asp:TextBox>
            <asp:LoginView ID="LoginStatus1" runat="server">
            <LoggedInTemplate>
            <asp:LoginName ID="LoginName1" runat="server" FormatString="Currently signed in as <strong>{0}</strong> " /> | 
            <a href="../Help.htm" title="Click for Help (will open a new window)" target="_blank">Help</a> | 
            <a href="logout.aspx" title="Click to Sign Out">Sign out</a>
            </LoggedInTemplate>
            </asp:LoginView>
            &nbsp; &nbsp;
        </div>
        <div id="wrapper">
            <div id="content">
                <div id="leftcol">        
                    <div class="controlcontainer"> 
                        <div class="shortlabel"> 
                            <asp:Label ID="AssignNoLabel" runat="server" Text="Assign No:"></asp:Label>
                        </div>
                        <div class="content">
                            <p class="ddLMargin"> 
                                <asp:DropDownList ID="ddlAssignments" runat="server" BackColor="#ffffff" DataSourceID="SqlDataSourceAssignment"
                                    DataTextField="assignment" DataValueField="wahv_assignment_code" TabIndex="1" AutoPostBack="True" AppendDataBoundItems="True" OnSelectedIndexChanged="ddlAssignments_SelectedIndexChanged">
                                </asp:DropDownList>
                                <a href="../Help.htm#assign-no" title="Click to view Help (will open in a new window)" target="_blank"><img src="../images/question-mark.gif" alt="Click to view Help (will open in a new window)" style="border:0;" /></a>
                            </p>
                        </div>
                    </div>
                    <div class="controlcontainer"> 
                        <div class="shortlabel"> 
                            <asp:Label ID="WorkDateLabel" runat="server" Text="Work Date:"></asp:Label>
                        </div>
                        <div class="content"> 
                            <p class="ddLMargin"> 
                                <asp:DropDownList ID="ddlDates" runat="server" AutoPostBack="True" BackColor="#ffffff" TabIndex="2"
                                    DataSourceID="SqlDataSourceDates" DataTextField="Column1" DataValueField="Column1" OnSelectedIndexChanged="ddlDates_SelectedIndexChanged">
                                </asp:DropDownList>
                                <a href="../Help.htm#work-date" title="Click to view Help (will open in a new window)" target="_blank"><img src="../images/question-mark.gif" alt="Click to view Help (will open in a new window)" style="border:0;" /></a>                                
                            </p>
                        </div>
                    </div>
                    <div class="controlcontainer"> 
                        <div class="shortlabel"> 
                            <asp:Label ID="LocationLabel" runat="server" Text="Locations:"></asp:Label>
                        </div>
                        <div class="content"> 
                            <p class="ddLMargin"> 
                                <asp:DropDownList ID="ddlLocation" runat="server" BackColor="#ffffff" DataSourceID="SqlDataSourceLocation"
                                    DataTextField="location" DataValueField="cl_unique_id" TabIndex="3" AutoPostBack="True" OnSelectedIndexChanged="ddlLocation_SelectedIndexChanged">
                                </asp:DropDownList>
                                <a href="../Help.htm#locations" title="Click to view Help (will open in a new window)" target="_blank"><img src="../images/question-mark.gif" alt="Click to view Help (will open in a new window)" style="border:0;" /></a>                                
                            </p>
                        </div>
                    </div>
                    <div class="controlcontainer" style="<% Response.Write(_ddlQSetStyle); %>">  
                        <div class="shortlabel"> 
                            <asp:Label ID="ddlQSetsLabel" runat="server" Text="Qu Set:"></asp:Label>
                        </div>
                        <div class="content">
                            <p class="ddLMargin">
                                <asp:DropDownList ID="ddlQSets" runat="server" AutoPostBack="True" BackColor="#ffffff" DataSourceID="SqlDataSourceQSet" 
                                    DataTextField="question_set" DataValueField="ciqh_ivr_number" OnSelectedIndexChanged="ddlQSets_SelectedIndexChanged">
                                </asp:DropDownList>
                                <a href="../Help.htm#qu-sets" title="Click to view Help (will open in a new window)" target="_blank"><img src="../images/question-mark.gif" alt="Click to view Help (will open in a new window)" style="border:0;" /></a>                                
                            </p>
                        </div>
                    </div>
                    <div class="gvcontainer">
                        <asp:Panel ID="ScrollingLayoutPanel" runat="server" Height="450px" Width="475px" ScrollBars="Vertical">
                            <asp:GridView ID="gvLayout" CellPadding="3" GridLines="None" runat="server" DataSourceID="SqlDataSourceLayout" AutoGenerateColumns="False" 
                                Width="457px" OnSelectedIndexChanged="gvLayout_SelectedIndexChanged" BackColor="#ffffff" OnDataBound="gvLayout_DataBound" AllowPaging="False"
                                EmptyDataText="No calls made to date. We are awaiting data, please check back a little later..." Enabled="False" AlternatingRowStyle-BackColor="LightCyan" PageSize="20">
                                <Columns>
                                    <asp:CommandField ShowSelectButton="True" ButtonType="Image" SelectImageUrl="~/images/select.gif">
                                        <ControlStyle BorderStyle="None" CssClass="padding:5px;" />
                                    </asp:CommandField>
                                    <asp:BoundField DataField="ciqm_question_no" HeaderText="Question No" SortExpression="ciqm_question_no" Visible="False" />
                                    <asp:BoundField DataField="ciqm_question_text" HeaderText="Assignment Questions/Answers" SortExpression="ciqm_question_text" ReadOnly="True" >
                                        <ControlStyle BackColor="White" ForeColor="Black" />
                                        <HeaderStyle HorizontalAlign="Left" />
                                        <ItemStyle HorizontalAlign="Left" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="ciqm_next_question_no" HeaderText="ciqm_next_question_no" SortExpression="ciqm_next_question_no" Visible="False" />
                                    <asp:BoundField DataField="ciqm_response_type" HeaderText="ciqm_response_type" SortExpression="ciqm_response_type" Visible="False" />
                                    <asp:BoundField DataField="ciqr_response_no" HeaderText="ciqr_response_no" SortExpression="ciqr_response_no" Visible="False" />
                                    <asp:BoundField DataField="ciqm_tiered" HeaderText="ciqm_tiered" SortExpression="ciqm_tiered" Visible="False" />
                                    <asp:BoundField DataField="ciqm_s_order" HeaderText="ciqm_s_order" SortExpression="ciqm_s_order" Visible="False" />
                                    <asp:BoundField DataField="ciqm_person_type" HeaderText="ciqm_person_type" SortExpression="ciqm_person_type" Visible="False" />
                                    <asp:BoundField DataField="ciqm_dept_code" HeaderText="ciqm_dept_code" SortExpression="ciqm_dept_code" Visible="False" />
                                    <asp:BoundField DataField="ciqm_dept_size" HeaderText="ciqm_dept_size" SortExpression="ciqm_dept_size" Visible="False" />
                                    <asp:BoundField DataField="ciqm_date_from" HeaderText="ciqm_date_from" SortExpression="ciqm_date_from" Visible="False" />
                                    <asp:BoundField DataField="ciqm_date_to" HeaderText="ciqm_date_to" SortExpression="ciqm_date_to" Visible="False" />
                                    <asp:BoundField DataField="l" SortExpression="l" Visible="False">
                                        <ItemStyle ForeColor="OldLace" Width="0px" Wrap="False" />
                                    </asp:BoundField>
                                </Columns>
                                <PagerSettings Mode="NumericFirstLast" />
                                <PagerStyle HorizontalAlign="Center" BackColor="#1C477E" ForeColor="White" />
                                <FooterStyle BackColor="#1C477E" ForeColor="White" />
                                <HeaderStyle BackColor="#1C477E" ForeColor="White" />
                                <AlternatingRowStyle BackColor="LightCyan" />
                            </asp:GridView>  
                        </asp:Panel>
                    </div>
                </div>
                <div id="rightcol">             
                    <table>
                        <tr>
                            <td class="controlcontainer" style="float:left;">                               
                                <asp:GridView ID="GridViewSummary" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSourceSummary" GridLines="None">
                                    <Columns>
                                        <asp:BoundField DataField="stat_type" HeaderText="Collation Overview" HeaderStyle-Wrap="False" SortExpression="stat_type" />
                                        <asp:BoundField DataField="stat_value" SortExpression="stat_value" />
                                    </Columns>
                                    <HeaderStyle BackColor="#1C477E" ForeColor="White" />
                                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />                  
                                    <RowStyle BackColor="#EFF3FB" />
                                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="Black" />
                                    <EditRowStyle BackColor="#2461BF" />
                                    <AlternatingRowStyle BackColor="White" />                                    
                                </asp:GridView>                                                                      
                            </td>
                            <td>
                                <img src="../images/AT-logo.gif" alt="Customer Portal Assignment Tracking" style="padding:10px;" />
                            </td>
                        </tr>
                    </table>
                    <p class="showmore"><a href="../Help.htm#showmore" title="Click to view Help (will open in a new window)" target="_blank"><img src="../images/question-mark.gif" alt="Click to view Help (will open in a new window)" style="border:0; margin-top:2px;" /></a>&nbsp;<% Response.Write(_detail_placeholder_text); %></p>
                    <div>
                        <asp:ImageButton ID="DetailImageButton" BorderStyle="None" runat="server" ImageUrl="~/images/detail.gif" AlternateText="Click to view Detail" OnClick="DetailImageButton_Click" />
                        <asp:ImageButton ID="Previous" BorderStyle="None" runat="server" ImageUrl="~/images/previous.gif" AlternateText="View Previous Page" Visible="True" OnClick="Previous_Click" />
                        <asp:ImageButton ID="Next" BorderStyle="None" runat="server" ImageUrl="~/images/next.gif" AlternateText="View Next Page" Visible="True" OnClick="Next_Click" />
                        <asp:ImageButton ID="FullScreen" BorderStyle="None" runat="server" ImageUrl="~/images/full-screen.gif" AlternateText="View as Full Screen (will open in a new window)" Visible="False" OnClick="FullScreen_Click" OnClientClick="AssignForm.target='_blank';" />
                        <br />
                        <asp:ImageButton ID="Export" BorderStyle="None" runat="server" ImageUrl="~/images/export.gif" AlternateText="Export to spreadsheet (CSV)" OnClick="Export_Click" Visible="False" />
                        <asp:ImageButton ID="Photo" BorderStyle="None" runat="server" ImageUrl="~/images/photo.gif" AlternateText="View the Person's Photo (will open in a new window)" Visible="False" OnClick="Photo_Click" OnClientClick="AssignForm.target='_blank';" />
                        <asp:ImageButton ID="Report" BorderStyle="None" runat="server" ImageUrl="~/images/report.gif" AlternateText="View Full Report (will open in a new window)" Visible="False" OnClick="Report_Click" OnClientClick="AssignForm.target='_blank';" />
                        <asp:ImageButton ID="Notes" BorderStyle="None" runat="server" ImageUrl="~/images/notes.gif" AlternateText="View Notes (will open in a new window)" Visible="False" OnClick="Notes_Click" OnClientClick="AssignForm.target='_blank';" />
                        <br />
                    </div>
                    <div class="mainpane">
                        <% Response.Write(_param); %>
                        <div style="<% Response.Write(_help); %>"><a href="../Help.htm#charts" title="Click to view Help (will open in a new window)" target="_blank"><img src="../images/question-mark.gif" alt="Click to view Help (will open in a new window)" style="border:0; margin-top:2px;" /></a> <span style="font-size:0.8em;">Click to view Help about the Charts</span></div>                       
                    </div>
                    <div class="controlcontainer">                     
                        <asp:Panel ID="ScrollingResultsPanel" runat="server" Height="350px" Width="375px" ScrollBars="Vertical">
                            <asp:GridView ID="gvResults" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="3" EmptyDataText="No data to display"
                                DataSourceID="SqlDataSourceResults" GridLines="None" Font-Overline="False" Width="350px" OnRowCommand="gvResults_RowCommand">                               
                                <SelectedRowStyle BackColor="LightCyan" Font-Bold="True" />
                                <HeaderStyle BackColor="#1C477E" Font-Bold="True" ForeColor="White" Font-Names="Verdana" />
                                <EditRowStyle BackColor="#2461BF" BorderStyle="Outset" />
                                <AlternatingRowStyle BackColor="Snow" Font-Bold="False" />
                                <FooterStyle BackColor="#1C477E" Font-Bold="True" ForeColor="White" />
                                <RowStyle BackColor="#EFF3FB" />
                                <Columns>                                
                                    <asp:BoundField DataField="Question_no" HeaderText="Question No" SortExpression="Question_no" Visible="False" />
                                    <asp:BoundField DataField="Answer_text" HeaderText="Answer Text" SortExpression="Answer_text" Visible="False" />                                        
                                    <asp:BoundField DataField="location_desc" HeaderText="Location" SortExpression="location_desc">
                                        <HeaderStyle HorizontalAlign="Left" Width="200px" Wrap="True" />
                                        <ItemStyle HorizontalAlign="Left" Width="200px" Wrap="True" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="call_date" HeaderText="Call Date" SortExpression="call_date" >
                                        <HeaderStyle HorizontalAlign="Center" />
                                        <ItemStyle HorizontalAlign="Center" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="note" HeaderText="Note" SortExpression="note" Visible="False" />
                                    <asp:BoundField DataField="person_code" HeaderText="Person Code" SortExpression="person_code" Visible="False" />
                                    <asp:BoundField DataField="caller_number" HeaderText="Caller Number" SortExpression="caller_number" Visible="False" >
                                        <HeaderStyle HorizontalAlign="Left" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Answer_no" HeaderText="Answer No" SortExpression="Answer_no" Visible="False">
                                        <ItemStyle HorizontalAlign="Center" Font-Bold="True" Font-Size="0.9em" />
                                    </asp:BoundField>
                                    <asp:CommandField ShowSelectButton="True" ButtonType="Image" SelectImageUrl="~/images/select.gif"
                                        SelectText="Select individual record in order to view more information, notes, photos, etc...">
                                        <ControlStyle BorderStyle="None" CssClass="padding:5px;" />
                                    </asp:CommandField>
                                </Columns>
                            </asp:GridView>
                        </asp:Panel>
                    </div>
                    <div class="controlcontainer">
                        <asp:GridView ID="gvSummary" runat="server" AutoGenerateColumns="False" CellPadding="4"
                            DataSourceID="SqlDataSourceDetail" GridLines="None" ShowHeader="False" Width="375px">
                            <FooterStyle BackColor="#507cd1" Font-Bold="True" ForeColor="#ffffff" />
                            <RowStyle BackColor="#eff3fb" />
                            <Columns>
                                <asp:BoundField DataField="text_type" HeaderText="None" SortExpression="text_type" />
                                <asp:BoundField DataField="text_out" HeaderText="None" ReadOnly="True" SortExpression="text_out" />
                            </Columns>
                            <PagerStyle BackColor="#2461bf" ForeColor="#ffffff" HorizontalAlign="Center" />
                            <SelectedRowStyle BackColor="#d1ddf1" Font-Bold="True" ForeColor="#333333" />
                            <HeaderStyle BackColor="#1c477e" Font-Bold="True" ForeColor="#ffffff" />
                            <EditRowStyle BackColor="#2461bf" />
                            <AlternatingRowStyle BackColor="#ffffff" />
                        </asp:GridView>
                        <asp:GridView ID="collation_groups" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourceCollation" Visible="False">
                            <Columns>
                                <asp:BoundField DataField="ciqm_question_no" HeaderText="ciqm_question_no" SortExpression="ciqm_question_no" />
                                <asp:BoundField DataField="collated" HeaderText="collated" SortExpression="collated" />
                                <asp:BoundField DataField="collation_type" HeaderText="collation_type" SortExpression="collation_type" />
                                <asp:BoundField DataField="question_count" HeaderText="question_count" SortExpression="question_count" />
                            </Columns>
                        </asp:GridView>
                        <asp:SqlDataSource ID="SqlDataSourceCollation" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                            SelectCommand="spname_sp" SelectCommandType="StoredProcedure">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="ddlQSets" Name="question_set" PropertyName="SelectedValue"
                                    Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </div>
                </div>
                <asp:SqlDataSource ID="SqlDataSourceLocation" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="spname_sp" SelectCommandType="StoredProcedure">
                <SelectParameters>
                <asp:ControlParameter ControlID="ddlAssignments" Name="assignment_code" PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSourceDates" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="spname_sp" SelectCommandType="StoredProcedure">
                <SelectParameters>
                <asp:ControlParameter ControlID="ddlAssignments" Name="assignment_code" PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSourceQSet" runat="server" ConnectionString="<%$ ConnectionStrings:webdbConnectionString %>"
                SelectCommand="spname_sp" SelectCommandType="StoredProcedure">
                <SelectParameters>
                <asp:ControlParameter ControlID="ddlAssignments" Name="assignment_code" PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSourceLayout" runat="server" ConnectionString="<%$ ConnectionStrings:webdbConnectionString %>"
                SelectCommand="web_get_ivr_layout_sp" SelectCommandType="StoredProcedure">
                <SelectParameters>
                <asp:ControlParameter ControlID="ddlQSets" Name="layout_no" PropertyName="SelectedValue" Type="Int32" />
                </SelectParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSourceSummary" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="spname_sp" SelectCommandType="StoredProcedure">
                <SelectParameters>
                <asp:ControlParameter ControlID="ddlAssignments" Name="assignment_code" PropertyName="SelectedValue" Type="String" />
                <asp:ControlParameter ControlID="ddlDates" DefaultValue="null" Name="orig_date_str" PropertyName="SelectedValue" Type="String" />
                <asp:ControlParameter ControlID="ddlQSets" DefaultValue="0" Name="question_set" PropertyName="SelectedValue" Type="Int32" />
                </SelectParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSourceAssignment" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="spname_sp" SelectCommandType="StoredProcedure">
                <SelectParameters>
                <asp:ControlParameter ControlID="CustomerCode" Name="customer_code" PropertyName="Text" Type="String" />
                </SelectParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSourceResults" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="spname_sp" SelectCommandType="StoredProcedure">
                <SelectParameters>
                <asp:ControlParameter ControlID="ddlQSets" Name="question_set" PropertyName="SelectedValue" Type="Int32" />
                <asp:ControlParameter ControlID="QuestionNo" Name="question_no" PropertyName="Text" Type="Int32" />
                <asp:ControlParameter ControlID="AnswerNo" Name="answer_no" PropertyName="Text" Type="Int32" />
                <asp:ControlParameter ControlID="ddlDates" Name="orig_date" PropertyName="SelectedValue" Type="String" />
                    <asp:ControlParameter ControlID="ddlLocation" Name="location_id" PropertyName="SelectedValue"
                        Type="String" />
                </SelectParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSourceDetail" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="spname_sp" SelectCommandType="StoredProcedure">
                <SelectParameters>
                <asp:ControlParameter ControlID="ddlAssignments" Name="assignment_code" PropertyName="SelectedValue" Type="String" DefaultValue="0" />
                </SelectParameters>
                </asp:SqlDataSource>
            </div>
        </div>
        <div id="footer">
            <span style="float:left;">Back to: <a href="dashboard.aspx" title="Back to Dashboard">Dashboard</a></span>
            Copyright &copy; 2008
        </div>
    </form>
</body>
</html>

and the Code Behind:

Code:
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 System.Data.SqlClient;
using InfoSoftGlobal;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using DataConnection;
using System.Web.Caching;
using System.Collections.Specialized;

public partial class customers_assigntrack : System.Web.UI.Page
{
    public string _UserName = "";
    private string _CustCode = "";
    public string _AssignCode = "";
    public string _QSet = "";
    public string _QNo = "";
    public string _Date = "";
    public string _Location = "";
    public string _param = "";
    public string _ANo = "";
    public string rowtype = "";
    public string responsetype = "";
    public string sGraphSet;
    public string Qtext = "";
    public string _ImageURL = "";
    public string _ddlQSetStyle = "";
    public string _question_text;
    public string sRtn;
    public string _help = "display:none;";
    public string _url;
    public string query;
    public string sp_name;
    public SqlConnection conn;
    public SqlConnection conn2;
    public SqlCommand comm;
    public string _QSet2 = "";
    public string _QNo2 = "";
    public string _Date2 = "";
    public string _note = "";
    public int c_qno = 0;
    public int c_atext = 1;
    public int c_loc = 2;
    public int c_date = 3;
    public int c_notes = 4;
    public int c_person = 5;
    public int c_callerid = 6;
    public int c_ano = 7;
    public Boolean b_sum_graph_click = false; //set the summary graph flag to "not clicked" initially
    public int i_graph_type; //collation chart type
    public int i_question_count; //The number of questions being collated
    public Boolean b_summary_flag = true; //set flag to "Summary" mode initially
    public string _detail_placeholder_text = "Click 'Show Detail' and select a specific question or answer from the lefthand grid to view further information from the promotion"; //if the gvSummary & gvResults GridViews are empty then show some explanatory text
    public int caller_id;
    public int qset;

    // Status Flags
    public string s_summary = "1";
    public string s_detail = "2";
        
    //PAGE_LOAD EVENT
    protected void Page_Load(object sender, System.EventArgs e)
    {
        //get the logged in user's name
        _UserName = User.Identity.Name;

        //get the customer code for the user
        string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        string dbconn = ConfigurationManager.ConnectionStrings["dbConnectionString"].ConnectionString;
        conn = new SqlConnection(connectionString);
        conn2 = new SqlConnection(webdbconn);
        comm = new SqlCommand("spname", conn);
        comm.CommandType = System.Data.CommandType.StoredProcedure;
        comm.Parameters.Add("@uname", System.Data.SqlDbType.NVarChar, 20);
        comm.Parameters["@uname"].Value = _UserName;
        conn.Open();
        object obj = comm.ExecuteScalar();
        _CustCode = obj.ToString();
        CustomerCode.Text = obj.ToString();
        conn.Close();

        if (!IsPostBack)
        {
            gvSummary.Visible = true;
            ScrollingResultsPanel.Visible = false;
            gvSummary.DataBind();
        }

        if (gvSummary.Visible == false)
        {
            ScrollingResultsPanel.Visible = true;
            _detail_placeholder_text = "Click 'Show Summary' to view Collated Reporting Information and Charts";
        }
    }

    //PAGE_PRERENDERCOMPLETE EVENT
    protected void Page_PreRenderComplete(object sender, System.EventArgs e)
    {
        //if there are any Question Sets then show the dropdown controls
        if (ddlQSets.Items.Count > 1)
        {
            _ddlQSetStyle = "display:block;";
            ddlQSets.Width = 35;
            ddlQSetsLabel.Visible = true;
        }
        //if there aren't any Question Sets then don't show the dropdown controls
        else
        {
            _ddlQSetStyle = "display:none;";
            ddlQSets.Width = 0;
            ddlQSetsLabel.Visible = false;
        }
    }

    //RENDER FUSION CHART FUNCTION
    public string SetGraphParams()
    {   
        //show fullscreen button, make all detail buttons invisible
        FullScreen.Visible = true;
        Export.Visible = false;
        Report.Visible = false;
        Notes.Visible = false;
        Photo.Visible = false;

        //if the summary graph flag has been updated (Previous or Next buttons OnClick has been fired) then...
        if (b_sum_graph_click == true)
        {
            if (i_graph_type == 2)
            {
                if (i_question_count == 1)
                {
                    sp_name = "spname_sp ";
                }
                else
                {
                    sp_name = "spname_sp ";
                }
            }
            else
            {
                if (i_question_count == 1)
                {
                    sp_name = "spname_sp ";
                }
                else
                {
                    sp_name = "spname_sp ";
                }
            }
        }

        //make gvLayout columns visible in order to get the values and databind
        gvLayout.Columns[5].Visible = true;
        gvLayout.Columns[4].Visible = true;
        gvLayout.Columns[1].Visible = true;
        gvLayout.Columns[13].Visible = true;
        gvLayout.DataBind();

        //if a row has been highlighted in gvLayout then...
        if (gvLayout.SelectedIndex >= 0)
        {    
            QuestionNo.Text = gvLayout.Rows[gvLayout.SelectedIndex].Cells[1].Text;
            AnswerNo.Text = gvLayout.Rows[gvLayout.SelectedIndex].Cells[5].Text;

            //if neither of the Prev/Next OnClicks have been fired...
            if (b_sum_graph_click == false)
            {
                _QNo = gvLayout.Rows[gvLayout.SelectedIndex].Cells[1].Text;
                rowtype = gvLayout.Rows[gvLayout.SelectedIndex].Cells[13].Text;
                responsetype = gvLayout.Rows[gvLayout.SelectedIndex].Cells[4].Text;

                if (responsetype == "1")
                {
                    sp_name = "spname_sp ";
                }
                else
                {
                    sp_name = "spname_sp ";
                }
            }
            //if one of the Prev/Next OnClicks HAVE been fired...
            else
            {
                if (i_graph_type == 2)
                {
                    responsetype = "1";
                }
                else
                {
                    responsetype = "0";
                }

                rowtype = "Q";
            }
            _question_text = gvLayout.Rows[gvLayout.SelectedIndex].Cells[2].Text;
        }
        //if a row hasn't been highlighted in gvLayout then...
        else
        {
            rowtype = "Q";

            if (i_graph_type == 2)
            {
                responsetype = "1";
            }
            else
            {
                responsetype = "0";
            }
        }

        //set variables from the dropdown values
        _QSet = ddlQSets.SelectedValue;
        _AssignCode = ddlAssignments.SelectedValue;
        _Date = ddlDates.SelectedValue;
        _Location = ddlLocation.SelectedValue;

        //set the gvLayout fields to be invisible again
        gvLayout.Columns[5].Visible = false;
        gvLayout.Columns[4].Visible = false;
        gvLayout.Columns[1].Visible = false;
        gvLayout.Columns[13].Visible = false;

        //what is GraphSet?
        GraphSet.Visible = true;
        sGraphSet = GraphSet.Text;
        GraphSet.Visible = false;

        //set Location and Date to be null if not used
        if (_Location == "{All Locations}")
        {
            _Location = " null ";
        }
        else
        {
            _Location = "'" + _Location + "'";
        }
        if (_Date == "{All Dates}")
        {
            _Date = " null ";
        }
        else
        {
            _Date = "'" + _Date + "'";
        }

        //if QUESTION rowtype...
        if (rowtype == "Q")
        {            
            //NOTE: It's necessary to encode the dataURL if you've added parameters to it
            String dataURL = Server.UrlEncode("Data.aspx?animate=1&rowtype=" + rowtype + "&responsetype=" + responsetype + "&assign=" + _AssignCode + "&qset=" + _QSet + "&qno=" + _QNo + "&date=" + _Date + "&location=" + _Location + "&graphset=" + sGraphSet + "&sp_name=" + sp_name);

            //hide Summary & Results GridViews, show Help, FullScreen and Refresh
            gvSummary.Visible = false;
            gvResults.Visible = false;
            ScrollingResultsPanel.Visible = false;
            _help = "display:block;";
            FullScreen.Visible = true;
            //Refresh.Visible = true;
         
            if (rowtype == "Q" && responsetype == "0")
            {
                //To debug, change the penultimate var from false to true
                return FusionCharts.RenderChart("../FusionCharts/Pie3D.swf", dataURL, "", "PieSum", "430", "362", false, false);
            }

            if (rowtype == "Q" && responsetype == "1")
            {
                FullScreen.Visible = true;

                if (b_sum_graph_click == true)
                {
                    //To debug, change the penultimate var from false to true
                    return FusionCharts.RenderChart("../FusionCharts/Column3D.swf", dataURL, "", "Col3D", "430", "362", false, false);
                }
                else
                {
                    //To debug, change the penultimate var from false to true
                    return FusionCharts.RenderChart("../FusionCharts/ScrollColumn2D.swf", dataURL, "", "Scroll2D", "430", "362", false, false);
                }
            }
            return "";
        }
        else
        {
            gvResults.Columns[1].Visible = false;
            gvResults.Columns[2].Visible = true;
            gvResults.Columns[3].Visible = true;

            gvSummary.Visible = false;
            gvResults.Visible = true;
            ScrollingResultsPanel.Visible = true;
            gvResults.DataBind();
        }

        return "";
    }

    protected void gvLayout_SelectedIndexChanged(object sender, EventArgs e)
    {
        GraphSet.Text = "1";
        _param = SetGraphParams();
        DetailImageButton.ImageUrl = "~/images/summary.gif";
        DetailImageButton.AlternateText = "Click to view Summary";
        Previous.Visible = false;
        Next.Visible = false;
        //Refresh.Visible = true;
        FullScreen.Visible = true;
    }

    protected void ddlDates_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DetailImageButton.ImageUrl == "~/images/detail.gif")
        {
            b_summary_flag = false;
        }

        if (b_summary_flag == false)
        {
            gvSummary.Visible = true;
            Previous.Visible = false;
            Next.Visible = false;
            //Refresh.Visible = false;
        }
        else
        {
            _param = SetGraphParams();
        }
    }

    protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DetailImageButton.ImageUrl == "~/images/detail.gif")
        {
            b_summary_flag = false;
        }
        
        if (b_summary_flag == false)
        {
            gvSummary.Visible = true;
            Previous.Visible = false;
            Next.Visible = false;
            //Refresh.Visible = false;
        }
        else
        {
            _param = SetGraphParams();
        }
    }

    protected void DetailImageButton_Click(object sender, ImageClickEventArgs e)
    {
        if (FormState.Text == s_summary)
        {
            FormState.Text = s_detail;
            gvSummary.Visible = false;
            gvResults.Visible = true;
            ScrollingResultsPanel.Visible = true;
            DetailImageButton.ImageUrl = "~/images/summary.gif";
            DetailImageButton.AlternateText = "Click to view Summary";
            _detail_placeholder_text = "Click 'Show Summary' to view Collated Reporting Information and Charts";
            Previous.Visible = false;
            Next.Visible = false;
            gvLayout.Enabled = true;
            gvLayout.DataBind();

            if (gvResults.Rows.Count <= 0 & gvLayout.SelectedIndex >= 0)
            {
                _param = SetGraphParams();
            }
        }
        else
        {
            FormState.Text = s_summary;
            gvSummary.Visible = true;
            gvResults.Visible = false;
            ScrollingResultsPanel.Visible = false;
            DetailImageButton.ImageUrl = "~/images/detail.gif";
            DetailImageButton.AlternateText = "Click to view Detail";
            _detail_placeholder_text = "Click 'Show Detail' and select a specific question or answer from the lefthand grid to view further information from the promotion";
            Previous.Visible = true;
            Next.Visible = true;
            Export.Visible = false;
            FullScreen.Visible = false;
            Notes.Visible = false;
            Report.Visible = false;
            Photo.Visible = false;
            gvLayout.Enabled = false;
        }
         
        //gvResults.DataBind();
        gvSummary.DataBind();
    }

    protected void ddlAssignments_SelectedIndexChanged(object sender, EventArgs e)
    {
        GraphSet.Text = "1";     
        FullScreen.Visible = false;
        Export.Visible = false;
        Report.Visible = false;
        Notes.Visible = false;
        Photo.Visible = false;

        if (ddlQSets.Items.Count > 1)
        {
            _ddlQSetStyle = "display:block;";
            ddlQSets.Width = 35;
            ddlQSetsLabel.Visible = true;
        }
        else
        {
            _ddlQSetStyle = "display:none;";
            ddlQSets.Width = 0;
            ddlQSetsLabel.Visible = false;
        }

        ddlQSets.DataBind();
        gvLayout.DataBind();
    } 

    //SET THE COLOR OF THE SELECTED ROW
    public string gvLayout_sortcolors()
    {
        int lLoopVar;
        string sRowType;

        lLoopVar = 0;

        while (lLoopVar < gvLayout.Rows.Count)
        {
            sRowType = gvLayout.Rows[lLoopVar].Cells[13].Text;

            if (sRowType == "A")
            {
                gvLayout.Rows[lLoopVar].BackColor = System.Drawing.Color.Snow;
                gvLayout.Rows[lLoopVar].Cells[13].ForeColor = System.Drawing.Color.Snow;
            }

            lLoopVar = lLoopVar + 1;
        }

        // set the selected row colour
        if (gvLayout.SelectedIndex >= 0)
        {
            
        }

        return "";
    }

    //RETURN THE COLORS TO THE GRIDVIEW
    protected void gvLayout_DataBound(object sender, EventArgs e)
    {
        sRtn = gvLayout_sortcolors();
    }

    //EXPORT THE DATA TO A .CSV FILE
    protected void Export_Click(object sender, ImageClickEventArgs e)
    {
        string attachment = "attachment; filename=output.csv";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/vnd.xls";

        StringWriter sw = new StringWriter();

        // Write the headers
        DataTable csv_export = GetData();

        int iColCount = csv_export.Columns.Count;

        for (int i = 0; i < iColCount; i++)
        {
            sw.Write(csv_export.Columns[i]);
            if (i < iColCount - 1)
            {
                sw.Write(",");
            }
        }

        sw.Write(sw.NewLine);

        // Write the rows
        foreach (DataRow dr in csv_export.Rows)
        {
            for (int i = 0; i < iColCount; i++)
            {
                if (!Convert.IsDBNull(dr[i]))
                {
                    sw.Write(dr[i].ToString());
                }

                if (i < iColCount - 1)
                {
                    sw.Write(",");
                }
            }

            sw.Write(sw.NewLine);
        }

        Response.Write(sw.ToString());
        Response.End();

        sw.Close();
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        // Confused me, but now I understand it, the 'override argument is preventing this 'standard' function/event from running
        // Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.
    }

    public DataTable GetData()
    {
        gvLayout.Columns[5].Visible = true;
        gvLayout.Columns[1].Visible = true;
        gvLayout.DataBind();

        if (gvLayout.SelectedIndex >= 0)
        {
            _ANo = gvLayout.Rows[gvLayout.SelectedIndex].Cells[5].Text;
            _QNo = gvLayout.Rows[gvLayout.SelectedIndex].Cells[1].Text;
        }

        _QSet = ddlQSets.SelectedValue;
        _Date = ddlDates.SelectedValue;
        _Location = ddlLocation.SelectedValue;

        gvLayout.Columns[5].Visible = false;
        gvLayout.Columns[1].Visible = false;

        SqlConnection conn2;

        string dbconn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        conn2 = new SqlConnection(dbconn);

        SqlCommand cmd = new SqlCommand("spname_sp ", conn2);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.Parameters.Add("@question_set", System.Data.SqlDbType.Int);
        cmd.Parameters["@question_set"].Value = Convert.ToInt64(_QSet);
        cmd.Parameters.Add("@question_no", System.Data.SqlDbType.Int);
        cmd.Parameters["@question_no"].Value = Convert.ToInt64(_QNo);
        cmd.Parameters.Add("@answer_no", System.Data.SqlDbType.Int);
        cmd.Parameters["@answer_no"].Value = Convert.ToInt64(_ANo);
        cmd.Parameters.Add("@orig_date", System.Data.SqlDbType.NVarChar, 20);
        cmd.Parameters["@orig_date"].Value = _Date;
        cmd.Parameters.Add("@location_id", System.Data.SqlDbType.NVarChar, 32);
        cmd.Parameters["@location_id"].Value = _Location;
        
        DataTable csv_output = new DataTable();

        try
        {
            using (SqlDataAdapter adapt = new SqlDataAdapter(cmd))
            {
                adapt.SelectCommand = cmd;
                conn2.Open();
                adapt.Fill(csv_output);
                conn2.Close();
            }
            return csv_output;
        }

        catch (SqlException ex) { throw ex; }
    }

    //DISPLAY THE IMAGE - pass in the row count (starting at zero)
    public string ShowEmpImage(int i_row)
    {
        string s_assignment_code;
        long  l_caller_id;
        long l_question_number;

        l_question_number = 0;
        l_caller_id = 0;

        gvLayout.Columns[1].Visible = true;
        gvLayout.DataBind();

        if (gvLayout.SelectedIndex >= 0)
        {
            l_question_number = Convert.ToInt64(gvLayout.Rows[gvLayout.SelectedIndex].Cells[1].Text);
        }
        
        s_assignment_code = ddlAssignments.SelectedValue;
    
        //get the data from the row count
        if (i_row >= 0 )
        {
            //gvResults.Columns[7].Visible = true;
            gvResults.Columns[6].Visible = true;
            gvResults.DataBind();

            l_caller_id = Convert.ToInt64(gvResults.Rows[i_row].Cells[c_callerid].Text);

            gvResults.Columns[6].Visible = false;
            //gvResults.Columns[7].Visible = false;
        }   

        SqlConnection conn2;
        string webdbconn = ConfigurationManager.ConnectionStrings["webdbConnectionString"].ConnectionString;
        conn2 = new SqlConnection(webdbconn);

        string sql = "SELECT statement";

        SqlCommand cmd = new SqlCommand(sql, conn2);
        cmd.CommandType = CommandType.Text;

        cmd.Parameters.Add("@assignment", System.Data.SqlDbType.NVarChar, 30);
        cmd.Parameters["@assignment"].Value = s_assignment_code;
        cmd.Parameters.Add("@caller_id", System.Data.SqlDbType.Int);
        cmd.Parameters["@caller_id"].Value = l_caller_id;
        cmd.Parameters.Add("@question_number", System.Data.SqlDbType.Int);
        cmd.Parameters["@question_number"].Value = l_question_number;
        cmd.CommandTimeout = 500;

        conn2.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        
        dr.Read();
        try
        {
            byte[] bindata = (byte[])dr.GetValue(0);
            Cache["Bindata"] = bindata;
            conn2.Close();
        }
        catch
        {
            conn2.Close();
            return "";
        }
        finally
        {
            conn2.Close();    
        }
               
        return "";     
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    protected void SwitchStylesheets(object sender, EventArgs e)
    {
        if (radioBlue.Checked)
            stylesheet.Href = "~/blue.css";
        if (radioGreen.Checked)
            stylesheet.Href = "~/green.css";         
    }

    //UPDATE THE SUMMARY WHEN A DIFFERENT QUESTION SET IS CHOSEN
    protected void ddlQSets_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewSummary.DataBind();
    }

    //OPEN THE CHART IN A NEW WINDOW
    protected void FullScreen_Click(object sender, ImageClickEventArgs e)
    {        
        int i_group;
        int i_count;
        string s_question;

        _QSet2 = ddlQSets.SelectedValue;      
        _Date2 = ddlDates.SelectedValue;

        if (_Date2 == "{All Dates}")
        {
            _Date2 = " null ";
        }
        else
        {
            _Date2 = "'" + _Date2 + "'";
        }

        gvLayout.Columns[1].Visible = true;
        gvLayout.Columns[5].Visible = true;
        gvLayout.Columns[4].Visible = true;
        gvLayout.Columns[13].Visible = true;
        gvLayout.Enabled = true;
        gvLayout.DataBind();

        if (gvLayout.SelectedIndex >= 0)
        {
            rowtype = gvLayout.Rows[gvLayout.SelectedIndex].Cells[13].Text;
            responsetype = gvLayout.Rows[gvLayout.SelectedIndex].Cells[4].Text;
            AnswerNo.Text = gvLayout.Rows[gvLayout.SelectedIndex].Cells[5].Text;
            _question_text = gvLayout.Rows[gvLayout.SelectedIndex].Cells[2].Text;
            _QNo2 = gvLayout.Rows[gvLayout.SelectedIndex].Cells[1].Text;
        }
        else
        {
            _question_text = "";
        }

        _AssignCode = ddlAssignments.SelectedValue;
        _Location = ddlLocation.SelectedValue;

        GraphSet.Visible = true;
        sGraphSet = GraphSet.Text;
        GraphSet.Visible = false;

        if (_Location == "{All Locations}")
        {
            _Location = " null ";
        }
        else
        {
            _Location = "'" + _Location + "'";
        }

        if (FormState.Text == s_summary)
        {
            collation_groups.Visible = true;
            collation_groups.DataBind();
            
            if (current_group.Text == "")
            {
                i_group = 0;
            }
            else
            {
                i_group = Convert.ToInt32(current_group.Text);
            }

            i_count = 0;

            while (i_count < collation_groups.Rows.Count)
            {
                if (Convert.ToInt32(collation_groups.Rows[i_count].Cells[1].Text) == i_group)
                {
                    i_group = Convert.ToInt32(collation_groups.Rows[i_count].Cells[1].Text);
                    _QNo2 = collation_groups.Rows[i_count].Cells[0].Text;

                    i_graph_type = Convert.ToInt32(collation_groups.Rows[i_count].Cells[2].Text);
                    i_question_count = Convert.ToInt32(collation_groups.Rows[i_count].Cells[3].Text);

                    // in this instance only (e.g when showing the summary graphs, don't show a graph (2) show a pie chart (1) where there is only one question

                    current_group.Text = i_group.ToString();
                    break;
                }
                i_count = i_count + 1;
            }

           collation_groups.Visible = false;
        }

        Cache["Qtext"] = _question_text;

        Response.Redirect("ChartPopUp.aspx?qset="+_QSet2+"&qno="+ _QNo2 +"&dt="+_Date2+"&ro="+rowtype+"&re="+responsetype+"&a="+_AssignCode+"&l="+_Location+"&sG="+sGraphSet+"&f="+FormState.Text+"&g="+i_graph_type+"&qc="+i_question_count);

        gvLayout.Columns[5].Visible = false;
        gvLayout.Columns[4].Visible = false;
        gvLayout.Columns[1].Visible = false;
        gvLayout.Columns[13].Visible = false;
        gvLayout.Enabled = false;
    }

    //OPEN THE NOTES IN A NEW WINDOW
    protected void Notes_Click(object sender, ImageClickEventArgs e)
    {
        string note;
        
        gvResults.Columns[4].Visible = true;
        gvResults.DataBind();
        note = gvResults.Rows[gvResults.SelectedIndex].Cells[c_notes].Text;
        Response.Redirect("NotesPopUp.aspx?note="+note);
        gvResults.Columns[4].Visible = false;      
    }

    //OPEN THE FULL REPORT IN A NEW WINDOW
    protected void Report_Click(object sender, ImageClickEventArgs e)
    {
        //This needs to be working but I'm not sure how to get both working at present
        //if (gvResults.SelectedIndex > 0)
        //{
            gvResults.Columns[6].Visible = true;
            gvResults.DataBind();
            caller_id = Convert.ToInt32(gvResults.Rows[gvResults.SelectedIndex].Cells[c_callerid].Text);          
            gvResults.Columns[6].Visible = false;
        //}

        qset = Convert.ToInt32(ddlQSets.SelectedValue);
        Response.Redirect("ReportPopUp.aspx?caller_id=" + caller_id + "&qset=" + qset);
    }

    //OPEN THE PERSON'S PHOTO IN A NEW WINDOW
    protected void Photo_Click(object sender, ImageClickEventArgs e)
    {
        int i_row;
        i_row = gvResults.SelectedIndex;
        ShowEmpImage(i_row);
    }
    
    //protected void Refresh_Click(object sender, ImageClickEventArgs e)
    //{
    //    b_summary_flag = true;
    //    _param = SetGraphParams();
    //}

    protected void gvResults_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        Export.Visible = true;
        Photo.Visible = true;
        Report.Visible = true;
        Notes.Visible = true;
        string _hidebuttons;
        _hidebuttons = "display:block;";
        _help = "display:none;";
    }

    protected void Next_Click(object sender, ImageClickEventArgs e)
    {
        int     i_group;
        int     i_count;
        string  s_question;

        //set the summary graph click to true
        b_sum_graph_click = true;

        //make the GridView readable and bind the data
        collation_groups.Visible = true;
        collation_groups.DataBind();
        
        if (current_group.Text == "")
        {
            i_group = 0;
        }
        else
        {
            i_group = Convert.ToInt32(current_group.Text);
        }

        i_count = 0;

        while (i_count < collation_groups.Rows.Count)
        {
            
            if (Convert.ToInt32(collation_groups.Rows[i_count].Cells[1].Text) > i_group)
            {
                i_group = Convert.ToInt32(collation_groups.Rows[i_count].Cells[1].Text);
                _QNo = collation_groups.Rows[i_count].Cells[0].Text;
                i_graph_type = Convert.ToInt32(collation_groups.Rows[i_count].Cells[2].Text);
                i_question_count = Convert.ToInt32(collation_groups.Rows[i_count].Cells[3].Text);

                // in this instance only (e.g when showing the summary graphs, don't show a graph (2) show a pie chart (1) where there is only one question
                if (i_graph_type == 2 && i_question_count == 1) 
                {
                    i_graph_type = 1;
                }

                current_group.Text = i_group.ToString();
                break;
            }
            i_count = i_count + 1;
        }
     
        //if the count reaches the number of rows or more then show the Summary otherwise keep showing Charts
        if (i_count >= collation_groups.Rows.Count)
        {
            gvSummary.Visible = true;
        }
        else
        {
            _param = SetGraphParams();
        }

        //hide the GridView
        collation_groups.Visible = false;
        //set the summary graph click to false
        b_sum_graph_click = false;
        //Set the Summary flag so that gvLayout is disabled
        b_summary_flag = true;  
    }

    protected void Previous_Click(object sender, ImageClickEventArgs e)
    {
        int     i_group;
        int     i_count;
        string  s_question;

        //set the summary graph click to true
        b_sum_graph_click = true;
        
        //make the GridView readable and bind the data
        collation_groups.Visible = true;
        collation_groups.DataBind();
  
        if (current_group.Text == "")
        {
            i_group = 0;
            gvSummary.Visible = true;
        }
        else
        {
            i_group = Convert.ToInt32(current_group.Text);
        }

        i_count = collation_groups.Rows.Count - 1;

        while (i_count > 0)
        {

            if (Convert.ToInt32(collation_groups.Rows[i_count].Cells[1].Text) < i_group)
            {
                i_group = Convert.ToInt32(collation_groups.Rows[i_count].Cells[1].Text);
                _QNo = collation_groups.Rows[i_count].Cells[0].Text;
                current_group.Text = i_group.ToString();
                i_graph_type = Convert.ToInt32(collation_groups.Rows[i_count].Cells[2].Text);

                i_question_count = Convert.ToInt32(collation_groups.Rows[i_count].Cells[3].Text);

                if (i_graph_type == 2 && i_question_count == 1) // in this instance only (e.g when showing the summary graphs, don't show a graph (2) show a pie chart (1) 
                // where there is only one question 
                {
                    i_graph_type = 1;
                }

                break;
            }
            i_count = i_count - 1;
        }

        //if the current_group is zero then just show the Summary GridView
        if (i_count == 0 && current_group.Text == "1")
        {
            gvSummary.Visible = true;
        }
        else
        {
            //call the Charts
            _param = SetGraphParams();
        }

        //hide the GridView
        collation_groups.Visible = false;
        //set the summary graph click to false
        b_sum_graph_click = false;
        //Set the Summary flag so that gvLayout is disabled
        b_summary_flag = true;  
    }
}

Thanks in advance for any pointers.
Bob

lastdonuk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top