Can someone tell me why my counting wont count correctly?
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Web;<br />
using System.Web.SessionState;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.HtmlControls;<br />
using TCAIMS.Components;<br />
using System.Data.OleDb;<br />
using System.Configuration;<br />
<br />
namespace TCAIMS.NewDag<br />
{<br />
public class WorKiDAGData1 : System.Web.UI.Page<br />
{<br />
protected System.Web.UI.WebControls.Label lblErrorMsg;<br />
protected System.Web.UI.WebControls.DropDownList ddlForm;<br />
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;<br />
protected System.Web.UI.WebControls.Button Button1;<br />
protected System.Web.UI.WebControls.Panel Panel1;<br />
protected System.Web.UI.WebControls.DataGrid DataGrid1;<br />
protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;<br />
protected System.Web.UI.WebControls.Label lblErrMsg;<br />
protected TCAIMS.Server.Navigator MenuNav;<br />
protected System.Web.UI.WebControls.Button TIR_Score;<br />
private string strConnection = ConfigurationSettings.AppSettings["TCAIMSDataCon"];<br />
<br />
<br />
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
<br />
<br />
if(!IsPostBack)<br />
{<br />
string connectionString = strConnection;<br />
OleDbConnection con = new OleDbConnection(connectionString);<br />
CUsers user =new CUsers();<br />
user=(CUsers)Session["SessionUser"];<br />
<br />
<br />
if(user.DAG.ToString() == "False")<br />
{<br />
Panel1.Visible=false;<br />
lblErrorMsg.Visible=true;<br />
}<br />
<br />
CountRecords();<br />
<br />
}<br />
}<br />
<br />
private void CountRecords()<br />
{<br />
<br />
string connectionString = strConnection;<br />
OleDbConnection con = new OleDbConnection(connectionString);<br />
DataSet dsDagFlagCnt = new DataSet("dsDagFlagCnt");<br />
DataTable tblDagFlags = new DataTable("tblDagFlags");<br />
try<br />
{<br />
con.Open();<br />
<br />
string[] list = {"DEMO", "Task_Questionnaire", "Software_Usability_Survey", "Test_Incident_Report", "Workstation_Profile", "t_EOT_IA", "t_EOT_SA", "t_EOT_Security", "t_EOT_SMEpart1", "t_EOT_SMEpart2", "t_EOT_User", "Equipment_Daily_Status"};<br />
<br />
<br />
tblDagFlags.Columns.Add("TableName", typeof(string));<br />
<br />
<br />
<br />
tblDagFlags.Columns.Add("AECVote_NV", typeof(int));<br />
tblDagFlags.Columns.Add("AECVote_P", typeof(int));<br />
tblDagFlags.Columns.Add("AECVote_NA", typeof(int));<br />
tblDagFlags.Columns.Add("AECVote_A", typeof(int));<br />
tblDagFlags.Columns.Add("AECVote_L", typeof(int));<br />
<br />
tblDagFlags.Columns.Add("OTCVote_NV", typeof(int));<br />
tblDagFlags.Columns.Add("OTCVote_P", typeof(int));<br />
tblDagFlags.Columns.Add("OTCVote_NA", typeof(int));<br />
tblDagFlags.Columns.Add("OTCVote_A", typeof(int));<br />
tblDagFlags.Columns.Add("OTCVote_L", typeof(int));<br />
<br />
tblDagFlags.Columns.Add("PMVote_NV", typeof(int));<br />
tblDagFlags.Columns.Add("PMVote_P", typeof(int));<br />
tblDagFlags.Columns.Add("PMVote_NA", typeof(int));<br />
tblDagFlags.Columns.Add("PMVote_A", typeof(int));<br />
tblDagFlags.Columns.Add("PMVote_L", typeof(int));<br />
<br />
tblDagFlags.Columns.Add("HQDAVote_NV", typeof(int));<br />
tblDagFlags.Columns.Add("HQDAVote_P", typeof(int));<br />
tblDagFlags.Columns.Add("HQDAVote_NA", typeof(int));<br />
tblDagFlags.Columns.Add("HQDAVote_A", typeof(int));<br />
tblDagFlags.Columns.Add("HQDAVote_L", typeof(int));<br />
<br />
tblDagFlags.Columns.Add("NAVYVote_NV", typeof(int));<br />
tblDagFlags.Columns.Add("NAVYVote_P", typeof(int));<br />
tblDagFlags.Columns.Add("NAVYVote_NA", typeof(int));<br />
tblDagFlags.Columns.Add("NAVYVote_A", typeof(int));<br />
tblDagFlags.Columns.Add("NAVYVote_L", typeof(int));<br />
<br />
DataRow rw;<br />
<br />
<br />
foreach (string table in list)<br />
{<br />
int countNVaec = CountTableRecordsAEC(table, "Not Viewed", con);<br />
int countPaec = CountTableRecordsAEC(table, "Pending", con);<br />
int countNAaec = CountTableRecordsAEC(table, "Not Authenicated", con);<br />
int countAaec = CountTableRecordsAEC(table, "Authenicated", con);<br />
int countLaec = CountTableRecordsAEC(table, "Limited Use", con);<br />
<br />
int countNVotc = CountTableRecordsOTC(table, "Not Viewed", con);<br />
int countPotc = CountTableRecordsOTC(table, "Pending", con);<br />
int countNAotc = CountTableRecordsOTC(table, "Not Authenicated", con);<br />
int countAotc = CountTableRecordsOTC(table, "Authenicated", con);<br />
int countLotc = CountTableRecordsOTC(table, "Limited Use", con);<br />
<br />
<br />
int countNVpm = CountTableRecordsPM(table, "Not Viewed", con);<br />
int countPpm = CountTableRecordsPM(table, "Pending", con);<br />
int countNApm = CountTableRecordsPM(table, "Not Authenicated", con);<br />
int countApm = CountTableRecordsPM(table, "Authenicated", con);<br />
int countLpm = CountTableRecordsPM(table, "Limited Use", con);<br />
<br />
int countNVhqda = CountTableRecordsHQDA(table, "Not Viewed", con);<br />
int countPhqda = CountTableRecordsHQDA(table, "Pending", con);<br />
int countNAhqda = CountTableRecordsHQDA(table, "Not Authenicated", con);<br />
int countAhqda = CountTableRecordsHQDA(table, "Authenicated", con);<br />
int countLhqda = CountTableRecordsHQDA(table, "Limited Use", con);<br />
<br />
<br />
int countNVnavy = CountTableRecordsNAVY(table, "Not Viewed", con);<br />
int countPnavy = CountTableRecordsNAVY(table, "Pending", con);<br />
int countNAnavy = CountTableRecordsNAVY(table, "Not Authenicated", con);<br />
int countAnavy = CountTableRecordsNAVY(table, "Authenicated", con);<br />
int countLnavy = CountTableRecordsNAVY(table, "Limited Use", con);<br />
<br />
<br />
int totflgs = 0;<br />
totflgs=countNVaec;<br />
<br />
<br />
<br />
rw = tblDagFlags.NewRow();<br />
rw["TableName"] = table;<br />
<br />
rw["AECVote_NV"] = countNVaec;<br />
rw["AECVote_P"] = countPaec;<br />
rw["AECVote_NA"] = countNAaec;<br />
rw["AECVote_A"] = countAaec;<br />
rw["AECVote_L"] = countLaec;<br />
rw["OTCVote_NV"] = countNVotc;<br />
rw["OTCVote_P"] = countPotc;<br />
rw["OTCVote_NA"] = countNAotc;<br />
rw["OTCVote_A"] = countAotc;<br />
rw["OTCVote_L"] = countLotc;<br />
<br />
rw["PMVote_NV"] = countNVpm;<br />
rw["PMVote_P"] = countPpm;<br />
rw["PMVote_NA"] = countNApm;<br />
rw["PMVote_A"] = countApm;<br />
rw["PMVote_L"] = countApm;<br />
<br />
<br />
rw["HQDAVote_NV"] = countNVhqda;<br />
rw["HQDAVote_P"] = countPhqda;<br />
rw["HQDAVote_NA"] = countNAhqda;<br />
rw["HQDAVote_A"] = countAhqda;<br />
rw["HQDAVote_L"] = countLhqda;<br />
<br />
rw["NAVYVote_NV"] = countNVnavy;<br />
rw["NAVYVote_P"] = countPnavy;<br />
rw["NAVYVote_NA"] = countNAnavy;<br />
rw["NAVYVote_A"] = countAnavy;<br />
rw["NAVYVote_L"] = countLnavy;<br />
<br />
tblDagFlags.Rows.Add(rw);<br />
<br />
if(totflgs > 0)<br />
{<br />
ddlForm.Items.Add(table);
}<br />
<br />
}<br />
}<br />
catch (Exception e)<br />
{<br />
HandleErrors(e.Message.ToString());<br />
}<br />
finally<br />
{<br />
if (con.State == ConnectionState.Open)<br />
con.Close();<br />
}<br />
<br />
DataGrid1.DataSource = tblDagFlags;<br />
DataGrid1.DataBind();<br />
}<br />
<br />
private void HandleErrors(string ErrorMessage)<br />
{<br />
lblErrMsg.Text=ErrorMessage;<br />
}<br />
<br />
<br />
private void DeleteFlags(OleDbConnection con)<br />
{<br />
string query = "Delete * from DagFlagCnt";<br />
OleDbCommand command = new OleDbCommand(query, con);<br />
command.ExecuteNonQuery();<br />
command.Dispose();<br />
}<br />
<br />
private int CountTableRecordsAEC(string table, string flag, OleDbConnection con)<br />
{<br />
string query = <br />
string.Format("SELECT Count([AEC Vote]) " + <br />
" FROM {0}" +<br />
" WHERE [AEC Vote] = '{1}'", table, flag);<br />
<br />
OleDbCommand command = new OleDbCommand(query, con);<br />
int count = (int)command.ExecuteScalar();<br />
command.Dispose();<br />
return count;<br />
}<br />
private int CountTableRecordsOTC(string table, string flag, OleDbConnection con)<br />
{<br />
string query = <br />
string.Format("SELECT Count([OTC Vote]) " + <br />
" FROM {0}" +<br />
" WHERE [OTC Vote] = '{1}'", table, flag);<br />
<br />
OleDbCommand command = new OleDbCommand(query, con);<br />
int count = (int)command.ExecuteScalar();<br />
command.Dispose();<br />
return count;<br />
}<br />
<br />
private int CountTableRecordsPM(string table, string flag, OleDbConnection con)<br />
{<br />
string query = <br />
string.Format("SELECT Count([TCA2_PM Vote]) " + <br />
" FROM {0}" +<br />
" WHERE [TCA2_PM Vote] = '{1}'", table, flag);<br />
<br />
OleDbCommand command = new OleDbCommand(query, con);<br />
int count = (int)command.ExecuteScalar();<br />
command.Dispose();<br />
return count;<br />
}<br />
<br />
private int CountTableRecordsHQDA(string table, string flag, OleDbConnection con)<br />
{<br />
string query = <br />
string.Format("SELECT Count([HQDA Vote]) " + <br />
" FROM {0}" +<br />
" WHERE [HQDA Vote] = '{1}'", table, flag);<br />
<br />
OleDbCommand command = new OleDbCommand(query, con);<br />
int count = (int)command.ExecuteScalar();<br />
command.Dispose();<br />
return count;<br />
}<br />
private int CountTableRecordsNAVY(string table, string flag, OleDbConnection con)<br />
{<br />
string query = <br />
string.Format("SELECT Count([Navy Vote]) " + <br />
" FROM {0}" +<br />
" WHERE [Navy Vote] = '{1}'", table, flag);<br />
<br />
OleDbCommand command = new OleDbCommand(query, con);<br />
int count = (int)command.ExecuteScalar();<br />
command.Dispose();<br />
return count;<br />
}<br />
<br />
<br />
<br />
<br />
<br />
private void SetDropdown(DataTable tblDagFlags)<br />
{<br />
<br />
}<br />
<br />
#region Web Form Designer generated code<br />
override protected void OnInit(EventArgs e)<br />
{<br />
InitializeComponent();<br />
base.OnInit(e);<br />
}<br />
<br />
private void InitializeComponent()<br />
{ <br />
this.Button1.Click += new System.EventHandler(this.Button1_Click);<br />
this.TIR_Score.Click += new System.EventHandler(this.TIR_Score_Click);<br />
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);<br />
this.Load += new System.EventHandler(this.Page_Load);<br />
<br />
}<br />
#endregion<br />
<br />
private void Button1_Click(object sender, System.EventArgs e)<br />
{<br />
if(ddlForm.SelectedValue.ToString() == "DEMO")<br />
{<br />
Response.Redirect("../NewDag/Demographics.aspx");<br />
}<br />
else<br />
Response.Redirect("../NewDag/"+ddlForm.SelectedValue+".aspx");<br />
<br />
}<br />
<br />
private void TIR_Score_Click(object sender, System.EventArgs e)<br />
{<br />
Response.Redirect("../NewDag/TIR_Score.aspx");<br />
}<br />
<br />
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)<br />
{<br />
<br />
}<br />
}<br />
}<br />
|