C# and Crystal Report 9

V

vickie

I have a sql server7 database using C#. The system runs fine until the
user try to run a report. I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:



[NullReferenceException: Object reference not set to an instance of an
object.]
LostToolReporting.LostTool.loadDetails(Int32 rec_id) in
\\rsila1-web\C$\Inetpub\wwwroot\LostToolReporting\LostTool.aspx.cs:204
LostToolReporting.LostTool.Page_Load(Object sender, EventArgs e) in
\\rsila1-web\C$\Inetpub\wwwroot\LostToolReporting\LostTool.aspx.cs:142
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +742

Version Information: Microsoft .NET Framework Version:1.1.4322.573;
ASP.NET Version:1.1.4322.1085

Thanks for the help in advance,
 
B

Bruce Wood

OK... so what is LostTool? Is it something you wrote? Something you
bought? Do you have the source code for it?
 
V

Vickie Wheaton

Lost Tooling is a system that keep track of all Tools that was lost or
found at the company. It was developed by the a programmer who is no
longer with the company. Therefore, I had to take over since I the only
programmer left. I don't know c sharpe, I'm learning as I go. However,
I have taken a training class on Crystal.
Thanks,
 
B

Bruce Wood

OK, so then according to the message you have to find

\\rsila1-web\C$\Inetpub\wwwroot\LostToolReporting\LostTool.a­spx.cs

and post the C# code for the method that encompasses line 204, so we
can see the code that failed, and maybe give you some ideas as to what
might have gone wrong.
 
V

Vickie Wheaton

Rsila1 is our web server. Here is the code for lost_tool.aspx.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
using NGIT_Utility_Classes;
using Microsoft.Web.UI.WebControls;

namespace LostToolReporting
{
/// <summary>
/// Summary description for Inventory.
/// </summary>
public class LostTool : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.TextBox txtQuantity;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Button btnSave;
protected System.Web.UI.WebControls.Button Home;
protected System.Web.UI.WebControls.Button btnPrint;
protected System.Web.UI.WebControls.CheckBox chkDelete;
protected System.Web.UI.WebControls.CheckBox chkMultiple;
protected System.Web.UI.WebControls.TextBox txtDrawer;
protected System.Web.UI.WebControls.TextBox txtCategory;
protected System.Web.UI.WebControls.TextBox txtDescription;
protected System.Web.UI.WebControls.CheckBox chkRecovered;
protected System.Web.UI.WebControls.DropDownList ddlShift;
protected System.Web.UI.WebControls.TextBox txtExtension;
protected System.Web.UI.WebControls.TextBox txtDate;
protected System.Web.UI.WebControls.DropDownList ddlAircraft;
protected System.Web.UI.WebControls.DropDownList ddlBuilding;
protected System.Web.UI.WebControls.DropDownList ddlTypeOfTool;
protected System.Web.UI.WebControls.TextBox txtDateTimeLost;
protected System.Web.UI.WebControls.CheckBox chkTalkedWithCoworkers;
protected System.Web.UI.WebControls.CheckBox chkNotifiedSupervisor;
protected System.Web.UI.WebControls.TextBox txtLostToolReportNo;
protected System.Web.UI.WebControls.TextBox txtDateToolWasFound;
protected System.Web.UI.WebControls.TextBox txtWhoFoundTool;
protected System.Web.UI.WebControls.TextBox txtIdentifyingMarks;
protected System.Web.UI.WebControls.DropDownList ddlColorOfTool;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.TextBox txtEmployeeNumber;
protected System.Web.UI.WebControls.TextBox txtEmployeeName;
protected System.Web.UI.WebControls.TextBox txtDepartment;
protected System.Web.UI.WebControls.ListBox lbAreaLost;
protected System.Web.UI.WebControls.ListBox lbAreaSearched;
protected System.Web.UI.WebControls.DropDownList ddlDescriptionOfTool;
protected System.Web.UI.WebControls.ListBox lbEmployeeAction;
protected System.Web.UI.WebControls.TextBox txtFOEResults;
protected System.Web.UI.WebControls.ListBox lbSupervisorAction;
protected System.Web.UI.WebControls.ListBox lbQualityAction;
protected System.Web.UI.WebControls.ListBox lbLocationFound;
protected System.Web.UI.WebControls.TextBox txtSupervisorResults;
protected System.Web.UI.WebControls.ListBox lbFOEAction;
protected System.Web.UI.WebControls.TextBox txtFOEComments;
protected System.Web.UI.WebControls.TextBox txtQualityResults;
protected System.Web.UI.WebControls.Panel pnlSupervisor;
protected System.Web.UI.WebControls.Panel pnlQuality;
protected System.Web.UI.WebControls.Panel pnlFOE;
protected System.Web.UI.WebControls.CheckBox chkNeedsCalibration;
protected System.Web.UI.WebControls.DropDownList ddlSupervisor;
protected System.Web.UI.WebControls.DropDownList ddlQuality;
protected System.Web.UI.WebControls.DropDownList ddlFOECoordinator;
protected System.Web.UI.WebControls.CheckBox chkNotifiedFOE;
protected System.Web.UI.WebControls.CheckBox chkNotifiedQuality;
protected System.Web.UI.WebControls.TextBox txtAdditionalComments;
protected System.Web.UI.WebControls.DropDownList
ddlSecondFOECoordinator;
protected System.Web.UI.WebControls.DropDownList ddlSecondQuality;
protected System.Web.UI.WebControls.Panel pnlEmployee;
protected System.Web.UI.WebControls.Panel pnlTracks;
protected System.Web.UI.WebControls.Repeater rptrList;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator2;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator3;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator4;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator5;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator6;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator7;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator8;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator9;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator10;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator11;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator12;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator13;
protected System.Web.UI.WebControls.TextBox txtSnitch;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator16;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator20;
protected System.Web.UI.WebControls.RequiredFieldValidator
RequiredFieldValidator24;
protected System.Web.UI.WebControls.DropDownList ddl2ndSupervisor;

public WebStatic globalWebStatic;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

int intRecordNumber;

globalWebStatic = new WebStatic(this);

btnSave.Attributes.Add("onClick", "javascript:donttattle();");

if (Page.IsPostBack == true)
{
txtSnitch.Text = "modified";

lblMessage.Visible = false;

if (isValidEmployee(txtEmployeeNumber.Text) == false)
{
lblMessage.Text = "Employee number not found. Please enter a valid
employee number.";
lblMessage.Visible = true;
}
return;
}

loadDropdowns();
loadDefaults();

if (Request.QueryString.GetValues(0).GetValue(0).ToString() == "Add")
{
pnlSupervisor.Visible = false;
pnlQuality.Visible = false;
pnlFOE.Visible = false;
pnlTracks.Visible = false;
return;
}

intRecordNumber =
System.Int32.Parse(Request.QueryString.GetValues(1).GetValue(0).ToString
());

loadDetails(intRecordNumber);

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

rptrList.DataSource = dbio.getDataSet("LIST","MTO_LTR","Select* from
DocumentTracks where ID = " + intRecordNumber.ToString() + " ORDER BY
DateTimeLogged DESC");

rptrList.DataBind();

dbio.Dispose();

if (Request.QueryString.GetValues(0).GetValue(0).ToString() != "Add")
{
lockDown(pnlEmployee);
}
if (isMember("Supervisors") == false)
{
lockDown(pnlSupervisor);
}
if (isMember("Quality") == false)
{
lockDown(pnlQuality);
}
if (isMember("FOE") == false)
{
lockDown(pnlFOE);
}
}
private void lockDown(System.Web.UI.WebControls.Panel pnl)
{
if (isMember("Superuser") == true)
return;

foreach (System.Web.UI.Control control in pnl.Controls)
{
if (control.GetType().FullName ==
"System.Web.UI.WebControls.TextBox")
((System.Web.UI.WebControls.TextBox)control).Enabled = false;
else
if (control.GetType().FullName ==
"System.Web.UI.WebControls.ListBox")
((System.Web.UI.WebControls.ListBox)control).Enabled = false;
else
if (control.GetType().FullName ==
"System.Web.UI.WebControls.CheckBox")
((System.Web.UI.WebControls.CheckBox)control).Enabled = false;
else
if (control.GetType().FullName ==
"System.Web.UI.WebControls.DropDownList")
((System.Web.UI.WebControls.DropDownList)control).Enabled = false;
}
txtSnitch.Enabled = true;
}
private void loadDetails(int rec_id)
{
PrimitiveDatabaseIO pdio = new PrimitiveDatabaseIO();

pdio.createSqlDataReader("MTO_LTR", "Select * from LTR WHERE
LostToolReportNumber = " + rec_id.ToString());

if (pdio.Read())
{
txtEmployeeName.Text =
pdio.getFieldValue("EmployeeName").ToString();
txtDepartment.Text = pdio.getFieldValue("Department").ToString();
ddlShift.Items.FindByValue(pdio.getFieldValue("Shift").ToString()).S
elected = true;
txtExtension.Text = pdio.getFieldValue("Extension").ToString();
txtEmployeeNumber.Text =
pdio.getFieldValue("EmployeeNumber").ToString();
txtDate.Text =
((System.DateTime)pdio.getFieldValue("DateTimeCreated")).ToString("MM/dd
/yy HH:mm");
ddlAircraft.Items.FindByValue(pdio.getFieldValue("Aircraft").ToStrin
g()).Selected = true;
ddlBuilding.Items.FindByValue(pdio.getFieldValue("Building").ToStrin
g()).Selected = true;
ddlTypeOfTool.Items.FindByValue(pdio.getFieldValue("TypeOfTool").ToS
tring()).Selected = true;
if (pdio.getFieldValue("DateTimeLost").ToString().Length > 0)
if (pdio.getFieldValue("DateTimeLost").ToString() != "1/1/1900
12:00:00 AM")
txtDateTimeLost.Text =
((System.DateTime)pdio.getFieldValue("DateTimeLost")).ToString("MM/dd/yy
HH:mm");
txtIdentifyingMarks.Text =
pdio.getFieldValue("IdentifyingMarks").ToString();
ddlDescriptionOfTool.Items.FindByValue(pdio.getFieldValue("Descripti
onOfTool").ToString()).Selected = true;
ddlColorOfTool.Items.FindByValue(pdio.getFieldValue("ColorOfTool").T
oString()).Selected = true;
flagSelected(lbAreaLost,
pdio.getFieldValue("AreaToolWasLost").ToString());
flagSelected(lbAreaSearched,
pdio.getFieldValue("AreaSearched").ToString());
chkTalkedWithCoworkers.Checked =
(pdio.getFieldValue("TalkedWithCoWorkers").ToString() == "True");
chkNotifiedSupervisor.Checked =
(pdio.getFieldValue("NotifiedSupervisor").ToString() == "True");
chkNotifiedQuality.Checked =
(pdio.getFieldValue("NotifiedQuality").ToString() == "True");
chkNotifiedFOE.Checked =
(pdio.getFieldValue("NotifiedFOE").ToString() == "True");
flagSelected(lbEmployeeAction,
pdio.getFieldValue("ActionEmployeeTook").ToString());
txtAdditionalComments.Text =
pdio.getFieldValue("AdditionalComments").ToString();
if
(ddlSupervisor.Items.FindByValue(pdio.getFieldValue("Supervisor").ToStri
ng()) != null)
ddlSupervisor.Items.FindByValue(pdio.getFieldValue("Supervisor").To
String()).Selected = true;
if (pdio.getFieldValue("Supervisor").ToString().Length > 0 &&
pdio.getFieldValue("SecondSupervisor").ToString().Length > 0)
{
lockDown(pnlSupervisor);
if (isMember("Supervisors") == true)
btnSave.Visible = false;
}
if
(ddl2ndSupervisor.Items.FindByValue(pdio.getFieldValue("SecondSupervisor
").ToString()) != null)
ddl2ndSupervisor.Items.FindByValue(pdio.getFieldValue("SecondSuperv
isor").ToString()).Selected = true;
flagSelected(lbSupervisorAction,
pdio.getFieldValue("SupervisorActionTook").ToString());
txtSupervisorResults.Text =
pdio.getFieldValue("SupervisorInvestigationResults").ToString();
if
(ddlQuality.Items.FindByValue(pdio.getFieldValue("QualityInvestigator").
ToString()) != null)
ddlQuality.Items.FindByValue(pdio.getFieldValue("QualityInvestigato
r").ToString()).Selected = true;
if (pdio.getFieldValue("QualityInvestigator").ToString().Length > 0
&& pdio.getFieldValue("SecondQualityPerson").ToString().Length > 0)
{
lockDown(pnlQuality);
if (isMember("Quality") == true)
btnSave.Visible = false;
}
if
(ddlSecondQuality.Items.FindByValue(pdio.getFieldValue("SecondQualityPer
son").ToString()) != null)
ddlSecondQuality.Items.FindByValue(pdio.getFieldValue("SecondQualit
yPerson").ToString()).Selected = true;
flagSelected(lbQualityAction,
pdio.getFieldValue("QualityActionTook").ToString());
txtQualityResults.Text =
pdio.getFieldValue("QualityInvestigationResults").ToString();
if
(ddlFOECoordinator.Items.FindByValue(pdio.getFieldValue("FOECoordinator"
).ToString()) != null)
ddlFOECoordinator.Items.FindByValue(pdio.getFieldValue("FOECoordina
tor").ToString()).Selected = true;
if
(ddlSecondFOECoordinator.Items.FindByValue(pdio.getFieldValue("SecondFOE
").ToString()) != null)
ddlSecondFOECoordinator.Items.FindByValue(pdio.getFieldValue("Secon
dFOE").ToString()).Selected = true;
txtLostToolReportNo.Text =
pdio.getFieldValue("LostToolReportNumber").ToString();
flagSelected(lbFOEAction,
pdio.getFieldValue("FOEActionTook").ToString());
txtFOEResults.Text =
pdio.getFieldValue("FOEInvestigationResults").ToString();
if (pdio.getFieldValue("DateToolFound").ToString().Length > 0)
if (pdio.getFieldValue("DateToolFound").ToString() != "1/1/1900
12:00:00 AM")
txtDateToolWasFound.Text =
((System.DateTime)pdio.getFieldValue("DateToolFound")).ToString("MM/dd/y
y HH:mm");
txtWhoFoundTool.Text =
pdio.getFieldValue("WhoFoundTool").ToString();
flagSelected(lbLocationFound,
pdio.getFieldValue("WhereToolWasFound").ToString());
txtFOEComments.Text = pdio.getFieldValue("FOEComments").ToString();
chkRecovered.Checked =
(pdio.getFieldValue("ToolWasFound").ToString() == "True");
chkNeedsCalibration.Checked =
(pdio.getFieldValue("NeedsCalibration").ToString() == "True");

}

pdio.Dispose();
}
private string getSelected(System.Web.UI.WebControls.ListBox lb)
{
string result = "";
string result2 = "";

foreach (System.Web.UI.WebControls.ListItem item in lb.Items)
{
if (item.Selected == true)
{
result2 = result + item.Value.ToString() + "\r\n";
if (result2.Length < 1025)
result = result2;
}
}
return result;
}
private void flagSelected(System.Web.UI.WebControls.ListBox lb, string
items)
{
if (items == null)
return;
if (items.Length < 1)
return;

string delimStr = "\r\n";
char [] delimiter = delimStr.ToCharArray();
string [] split = null;

try
{

split = items.Split(delimiter, 256);

foreach (string item in split)
{
if (item.Length > 0)
lb.Items.FindByValue(item).Selected = true;
}
}
catch{};
}
private void loadDefaults()
{
txtDate.Text = System.DateTime.Now.ToString("MM/dd/yy HH:mm");
}
private void loadDropdowns()
{
PrimitiveDatabaseIO pdio = new PrimitiveDatabaseIO();

pdio = new PrimitiveDatabaseIO();

ddlShift.DataSource = pdio.getDataSet("Items", "MTO_LTR", "select
null as Shift union Select DISTINCT Shift from Shifts where shift <>
'zzz' ORDER BY Shift");
ddlShift.DataTextField = "Shift";
ddlShift.DataValueField = "Shift";

ddlShift.DataBind();

pdio.Dispose();

pdio = new PrimitiveDatabaseIO();

ddlAircraft.DataSource = pdio.getDataSet("Items", "MTO_LTR", "Select
null as Aircraft union Select DISTINCT Aircraft from Aircraft where
aircraft <> 'zzz' ORDER BY Aircraft");
ddlAircraft.DataTextField = "Aircraft";
ddlAircraft.DataValueField = "Aircraft";

ddlAircraft.DataBind();

pdio.Dispose();

pdio = new PrimitiveDatabaseIO();

ddlBuilding.DataSource = pdio.getDataSet("Items", "MTO_LTR", "select
null as Building union Select DISTINCT Building from Buildings where
building <> 'zzz' ORDER BY Building");
ddlBuilding.DataTextField = "Building";
ddlBuilding.DataValueField = "Building";

ddlBuilding.DataBind();

pdio.Dispose();

pdio = new PrimitiveDatabaseIO();

ddlTypeOfTool.DataSource = pdio.getDataSet("Items", "MTO_LTR",
"select null as Type union Select DISTINCT Type from ToolTypes where
type <> 'zzz' ORDER BY Type");
ddlTypeOfTool.DataTextField = "Type";
ddlTypeOfTool.DataValueField = "Type";

ddlTypeOfTool.DataBind();

pdio.Dispose();

pdio = new PrimitiveDatabaseIO();

ddlDescriptionOfTool.DataSource = pdio.getDataSet("Items", "MTO_LTR",
"select null as Description union Select DISTINCT Description from
ToolDescriptions where description <> 'zzz' ORDER BY Description");
ddlDescriptionOfTool.DataTextField = "Description";
ddlDescriptionOfTool.DataValueField = "Description";

ddlDescriptionOfTool.DataBind();

pdio.Dispose();

pdio = new PrimitiveDatabaseIO();

ddlColorOfTool.DataSource = pdio.getDataSet("Items", "MTO_LTR",
"select null as Color union Select DISTINCT Color from ToolColors where
color <> 'zzz' ORDER BY Color");
ddlColorOfTool.DataTextField = "Color";
ddlColorOfTool.DataValueField = "Color";

ddlColorOfTool.DataBind();

pdio.Dispose();

pdio = new PrimitiveDatabaseIO();

lbAreaLost.DataSource = pdio.getDataSet("Items", "MTO_LTR", "Select
DISTINCT Area from Areas where area <> 'zzz' ORDER BY Area");
lbAreaLost.DataTextField = "Area";
lbAreaLost.DataValueField = "Area";

lbAreaLost.DataBind();

pdio.Dispose();

pdio = new PrimitiveDatabaseIO();

lbAreaSearched.DataSource = pdio.getDataSet("Items", "MTO_LTR",
"Select DISTINCT Area from Areas where area <> 'zzz' ORDER BY Area");
lbAreaSearched.DataTextField = "Area";
lbAreaSearched.DataValueField = "Area";

lbAreaSearched.DataBind();

pdio.Dispose();

pdio = new PrimitiveDatabaseIO();

lbEmployeeAction.DataSource = pdio.getDataSet("Items", "MTO_LTR",
"Select DISTINCT Action from Actions where action <> 'zzz' and who in
('All','Mechanic') ORDER BY Action");
lbEmployeeAction.DataTextField = "Action";
lbEmployeeAction.DataValueField = "Action";

lbEmployeeAction.DataBind();

pdio.Dispose();

ddlSupervisor.DataSource = getPeople("Supervisors");
ddlSupervisor.DataTextField = "Individual";
ddlSupervisor.DataValueField = "Individual";

ddlSupervisor.DataBind();

pdio.Dispose();

ddl2ndSupervisor.DataSource = getPeople("Supervisors");
ddl2ndSupervisor.DataTextField = "Individual";
ddl2ndSupervisor.DataValueField = "Individual";

ddl2ndSupervisor.DataBind();

pdio.Dispose();

pdio = new PrimitiveDatabaseIO();

lbSupervisorAction.DataSource = pdio.getDataSet("Items", "MTO_LTR",
"Select DISTINCT Action from Actions where action <> 'zzz' and who in
('All','Supervisor') ORDER BY Action");
lbSupervisorAction.DataTextField = "Action";
lbSupervisorAction.DataValueField = "Action";

lbSupervisorAction.DataBind();

pdio.Dispose();

ddlQuality.DataSource = getPeople("Quality");
ddlQuality.DataTextField = "Individual";
ddlQuality.DataValueField = "Individual";

ddlQuality.DataBind();

ddlSecondQuality.DataSource = getPeople("Quality");
ddlSecondQuality.DataTextField = "Individual";
ddlSecondQuality.DataValueField = "Individual";

ddlSecondQuality.DataBind();

lbQualityAction.DataSource = pdio.getDataSet("Items", "MTO_LTR",
"Select DISTINCT Action from Actions where action <> 'zzz' and who in
('All','Quality') ORDER BY Action");
lbQualityAction.DataTextField = "Action";
lbQualityAction.DataValueField = "Action";

lbQualityAction.DataBind();

pdio.Dispose();

ddlFOECoordinator.DataSource = getPeople("FOE");
ddlFOECoordinator.DataTextField = "Individual";
ddlFOECoordinator.DataValueField = "Individual";

ddlFOECoordinator.DataBind();

ddlSecondFOECoordinator.DataSource = getPeople("FOE");
ddlSecondFOECoordinator.DataTextField = "Individual";
ddlSecondFOECoordinator.DataValueField = "Individual";

ddlSecondFOECoordinator.DataBind();

pdio = new PrimitiveDatabaseIO();

lbFOEAction.DataSource = pdio.getDataSet("Items", "MTO_LTR", "Select
DISTINCT Action from Actions where action <> 'zzz' and who in
('All','FOE') ORDER BY Action");
lbFOEAction.DataTextField = "Action";
lbFOEAction.DataValueField = "Action";

lbFOEAction.DataBind();

pdio.Dispose();

pdio = new PrimitiveDatabaseIO();

lbLocationFound.DataSource = pdio.getDataSet("Items", "MTO_LTR",
"Select DISTINCT Area from Areas where area <> 'zzz' ORDER BY Area");
lbLocationFound.DataTextField = "Area";
lbLocationFound.DataValueField = "Area";

lbLocationFound.DataBind();

pdio.Dispose();

}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txtEmployeeNumber.TextChanged += new
System.EventHandler(this.txtEmployeeNumber_Changed);
this.Home.Click += new System.EventHandler(this.Home_Click);
this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public bool isValidEmployee(string perm)
{
if (perm == null)
return false;
if (perm.Length < 1)
return false;

bool result = false;

while (perm.Length > 0 && perm.StartsWith("0") == true)
perm = perm.Substring(1,perm.Length-1);

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlDataReader("MTO_LTR", "Select EmployeeNumber,
EmployeeName, Department from Employees where EmployeeNumber = '" + perm
+ "'");

if (dbio.Read())
{
result = true;
txtEmployeeNumber.Text = perm;
txtEmployeeName.Text =
dbio.getFieldValue("EmployeeName").ToString();
txtDepartment.Text = dbio.getFieldValue("Department").ToString();
}

dbio.Dispose();

return result;
}
private bool validateDateTime(string victim)
{
bool result = true;
System.DateTime dt;

if (victim == null || victim.Length < 1)
return true;

System.IFormatProvider format = new
System.Globalization.CultureInfo("en-US", true);

try
{
dt = System.DateTime.Parse(victim, format);
}
catch {result = false;}
return result;
}
private bool isInvalidEmployee()
{
if (Request.QueryString.GetValues(0).GetValue(0).ToString() != "Add")
return false;

foreach (System.Web.UI.Control control in pnlEmployee.Controls)
{
if (control.ID != null)
if (control.ID.StartsWith("RequiredFieldValidator"))
((System.Web.UI.WebControls.RequiredFieldValidator)control).Valida
te();
}
foreach (System.Web.UI.Control control in pnlEmployee.Controls)
{
if (control.ID != null)
if (control.ID.StartsWith("RequiredFieldValidator"))
if
(((System.Web.UI.WebControls.RequiredFieldValidator)control).IsValid ==
false)
{
lblMessage.Text = "*Required employee data was not entered.
Please enter all the required data then click save.";
lblMessage.Visible = true;
return true;
}
}
if (ddlTypeOfTool.SelectedValue.ToUpper().Trim() == "OTHER")
if (txtAdditionalComments.Text.Length < 1)
{
lblMessage.Text = "*Please enter the type of tool in the additional
comments text box.";
lblMessage.Visible = true;
return true;
}

if (chkNotifiedSupervisor.Checked != true)
{
lblMessage.Text = "Please notify your supervisor then click the
'Notified Supervisor' checkbox.";
lblMessage.Visible = true;
return true;
}
if (chkNotifiedFOE.Checked != true)
{
lblMessage.Text = "Please notify the FOE team then click the
'Notified FOE' checkbox.";
lblMessage.Visible = true;
return true;
}

if (isTooLong(pnlEmployee).Length > 0)
{
lblMessage.Text = isTooLong(pnlEmployee);
lblMessage.Visible = true;
return true;
}

return false;
}
private bool isInvalidSupervisor()
{
if (Request.QueryString.GetValues(0).GetValue(0).ToString() == "Add")
return false;

if (isMember("Superuser") == false && isMember("Supervisors") ==
false)
return false;

if (chkRecovered.Checked == true)
return false;

if (ddlSupervisor.SelectedValue.Length > 0 &&
ddlSupervisor.SelectedValue.Substring(0,4) == "PASI")
{
if (txtSupervisorResults.Text.Length < 1)
{
lblMessage.Text = "You must enter your name in the Additional
Investigation Results edit box.";
lblMessage.Visible = true;
return true;
}
}

foreach (System.Web.UI.Control control in pnlSupervisor.Controls)
{
if (control.ID != null)
if (control.ID.StartsWith("RequiredFieldValidator"))
((System.Web.UI.WebControls.RequiredFieldValidator)control).Valida
te();
}
foreach (System.Web.UI.Control control in pnlSupervisor.Controls)
{
if (control.ID != null)
if (control.ID.StartsWith("RequiredFieldValidator"))
if
(((System.Web.UI.WebControls.RequiredFieldValidator)control).IsValid ==
false)
{
lblMessage.Text = "*Required supervisor data was not entered.
Please enter all the required data then click save.";
lblMessage.Visible = true;
return true;
}
}
if (ddlSupervisor.SelectedValue.Length < 1 &&
ddl2ndSupervisor.SelectedValue.Length < 1)
{
lblMessage.Text = "You must select either a first shift or second
shift supervisor.";
lblMessage.Visible = true;
return true;
}
if (isTooLong(pnlSupervisor).Length > 0)
{
lblMessage.Text = isTooLong(pnlSupervisor);
lblMessage.Visible = true;
return true;
}

return false;
}
private bool isInvalidQuality()
{
if (Request.QueryString.GetValues(0).GetValue(0).ToString() == "Add")
return false;

if (isMember("Superuser") == false && isMember("Quality") == false)
return false;

if (chkRecovered.Checked == true)
return false;

if (ddlQuality.SelectedValue.Length > 0 &&
ddlQuality.SelectedValue.Substring(0,4) == "PASI")
{
if (txtQualityResults.Text.Length < 1)
{
lblMessage.Text = "You must enter your name in the Investigation
Results By Quality Person edit box.";
lblMessage.Visible = true;
return true;
}
}
if (ddlSecondQuality.SelectedValue.Length > 0 &&
ddlSecondQuality.SelectedValue.Substring(0,4) == "PASI")
{
if (txtQualityResults.Text.Length < 1)
{
lblMessage.Text = "You must enter your name in the Investigation
Results By Quality Person edit box.";
lblMessage.Visible = true;
return true;
}
}
foreach (System.Web.UI.Control control in pnlQuality.Controls)
{
if (control.ID != null)
if (control.ID.StartsWith("RequiredFieldValidator"))
((System.Web.UI.WebControls.RequiredFieldValidator)control).Valida
te();
}
foreach (System.Web.UI.Control control in pnlQuality.Controls)
{
if (control.ID != null)
if (control.ID.StartsWith("RequiredFieldValidator"))
if
(((System.Web.UI.WebControls.RequiredFieldValidator)control).IsValid ==
false)
{
lblMessage.Text = "*Required quality data was not entered. Please
enter all the required data then click save.";
lblMessage.Visible = true;
return true;
}
}

if (ddlQuality.SelectedValue.Length < 1 &&
ddlSecondQuality.SelectedValue.Length < 1)
{
lblMessage.Text = "You must select either a first shift or second
shift quality person.";
lblMessage.Visible = true;
return true;
}

if (isTooLong(pnlQuality).Length > 0)
{
lblMessage.Text = isTooLong(pnlQuality);
lblMessage.Visible = true;
return true;
}

return false;
}
private bool isInvalidFOE()
{
if (Request.QueryString.GetValues(0).GetValue(0).ToString() == "Add")
return false;

if (isMember("Superuser") == false && isMember("FOE") == false)
return false;

foreach (System.Web.UI.Control control in pnlFOE.Controls)
{
if (control.ID != null)
if (control.ID.StartsWith("RequiredFieldValidator"))
((System.Web.UI.WebControls.RequiredFieldValidator)control).Valida
te();
}
foreach (System.Web.UI.Control control in pnlFOE.Controls)
{
if (control.ID != null)
if (control.ID.StartsWith("RequiredFieldValidator"))
if
(((System.Web.UI.WebControls.RequiredFieldValidator)control).IsValid ==
false)
{
lblMessage.Text = "*Required FOE data was not entered. Please
enter all the required data then click save.";
lblMessage.Visible = true;
return true;
}
}
if (ddlFOECoordinator.SelectedValue.Length < 1 &&
ddlSecondFOECoordinator.SelectedValue.Length < 1)
{
lblMessage.Text = "You must select either a first shift or second
shift FOE coordinator.";
lblMessage.Visible = true;
return true;
}

if (isTooLong(pnlFOE).Length > 0)
{
lblMessage.Text = isTooLong(pnlFOE);
lblMessage.Visible = true;
return true;
}

return false;
}
private void disableSave()
{
Session.Add("Save","Disabled");
}
private void enableSave()
{
Session.Remove("Save");
}
private void btnSave_Click(object sender, System.EventArgs e)
{
globalWebStatic = new WebStatic(this);

try
{
if (Session["Save"].ToString() == "Disabled")
{
lblMessage.Text = "Please wait...";
lblMessage.Visible = true;
return;
}
}
catch{};

disableSave();

txtSnitch.Text = "modified";

lblMessage.Visible = false;

if (isInvalidEmployee() == true)
{
enableSave();
return;
}
if (isInvalidSupervisor() == true)
{
enableSave();
return;
}
if (isInvalidQuality() == true)
{
enableSave();
return;
}
if (isInvalidFOE() == true)
{
enableSave();
return;
}

if (validateDateTime(txtDateTimeLost.Text) == false)
{
lblMessage.Text = "The Date/Time the tool was lost must be a date in
MM/DD/YY HH:MM format. Please correct the error and click Save again.";
lblMessage.Visible = true;
enableSave();
return;
}
if (validateDateTime(txtDateToolWasFound.Text) == false)
{
lblMessage.Text = "The Date/Time the tool was found must be a date
in MM/DD/YY HH:MM format. Please correct the error and click Save
again.";
lblMessage.Visible = true;
enableSave();
return;
}

if (isValidEmployee(txtEmployeeNumber.Text) == false)
{
lblMessage.Text = "Employee number not found. Please enter a valid
employee number.";
lblMessage.Visible = true;
enableSave();
return;
}
if (chkRecovered.Checked == true)
{
if (txtDateToolWasFound.Text.Length < 1)
{
lblMessage.Text = "The Date/Time the tool was found must be entered
for recovered tools.";
lblMessage.Visible = true;
enableSave();
return;
}
}
if (chkRecovered.Checked == true)
{
if (txtWhoFoundTool.Text.Length < 1)
{
lblMessage.Text = "You must enter who found the tool for recovered
tools.";
lblMessage.Visible = true;
enableSave();
return;
}
}
if (chkRecovered.Checked == true)
{
if (lbLocationFound.SelectedValue.Length < 1)
{
lblMessage.Text = "You must enter the location a tool was
recovered.";
lblMessage.Visible = true;
enableSave();
return;
}
}

if (Request.QueryString.GetValues(0).GetValue(0).ToString() == "Add")
{
addRecord();
promoteDocument(retrieveReportNumber());
makeTracks(retrieveReportNumber());
enableSave();
Response.Redirect("LTR_ACK.aspx");
}
else
if (Request.QueryString.GetValues(0).GetValue(0).ToString() ==
"Update")
{
updateRecord(System.Int32.Parse(Request.QueryString.GetValues(1).Get
Value(0).ToString()));
promoteDocument(System.Int32.Parse(Request.QueryString.GetValues(1).
GetValue(0).ToString()));
makeTracks(System.Int32.Parse(Request.QueryString.GetValues(1).GetVa
lue(0).ToString()));
enableSave();
Response.Redirect("LTR_ACK.aspx");
}
enableSave();
}
private void addRecord()
{
string strSQL;

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlCommand("MTO_LTR");
dbio.addSqlParameter("@Type", "M4-F051");
dbio.addSqlParameter("@Subtype", "N/A");
dbio.addSqlParameter("@EmployeeName", txtEmployeeName.Text);
dbio.addSqlParameter("@Department", txtDepartment.Text);
dbio.addSqlParameter("@Shift", ddlShift.SelectedValue);
dbio.addSqlParameter("@Extension", txtExtension.Text);
dbio.addSqlParameter("@EmployeeNumber", txtEmployeeNumber.Text);
dbio.addSqlParameter("@DateTimeCreated", txtDate.Text);
dbio.addSqlParameter("@Aircraft", ddlAircraft.SelectedValue);
dbio.addSqlParameter("@Building", ddlBuilding.SelectedValue);
dbio.addSqlParameter("@TypeOfTool", ddlTypeOfTool.SelectedValue);
dbio.addSqlParameter("@DateTimeLost", txtDateTimeLost.Text);
dbio.addSqlParameter("@IdentifyingMarks", txtIdentifyingMarks.Text);
dbio.addSqlParameter("@DescriptionOfTool",
ddlDescriptionOfTool.SelectedValue);
dbio.addSqlParameter("@ColorOfTool", ddlColorOfTool.SelectedValue);
dbio.addSqlParameter("@AreaToolWasLost", getSelected(lbAreaLost));
dbio.addSqlParameter("@AreaSearched", getSelected(lbAreaSearched));
dbio.addSqlParameter("@TalkedWithCoWorkers",
chkTalkedWithCoworkers.Checked);
dbio.addSqlParameter("@NotifiedSupervisor",
chkNotifiedSupervisor.Checked);
dbio.addSqlParameter("@NotifiedQuality", chkNotifiedQuality.Checked);
dbio.addSqlParameter("@NotifiedFOE", chkNotifiedFOE.Checked);
dbio.addSqlParameter("@ActionEmployeeTook",
getSelected(lbEmployeeAction));
dbio.addSqlParameter("@AdditionalComments",
txtAdditionalComments.Text);
dbio.addSqlParameter("@Supervisor", ddlSupervisor.SelectedValue);
dbio.addSqlParameter("@SecondSupervisor",
ddl2ndSupervisor.SelectedValue);
dbio.addSqlParameter("@ActionSupervisorTook",
getSelected(lbSupervisorAction));
dbio.addSqlParameter("@SupervisorInvestigationResults",
txtSupervisorResults.Text);
dbio.addSqlParameter("@QualityInvestigator",
ddlQuality.SelectedValue);
dbio.addSqlParameter("@QualityActionTook",
getSelected(lbQualityAction));
dbio.addSqlParameter("@QualityInvestigationResults",
txtQualityResults.Text);
dbio.addSqlParameter("@FOECoordinator",
ddlFOECoordinator.SelectedValue);
dbio.addSqlParameter("@FOEActionTook", getSelected(lbFOEAction));
dbio.addSqlParameter("@FOEInvestigationResults", txtFOEResults.Text);
dbio.addSqlParameter("@DateToolFound", System.DBNull.Value);
dbio.addSqlParameter("@WhoFoundTool", txtWhoFoundTool.Text);
dbio.addSqlParameter("@WhereToolWasFound",
lbLocationFound.SelectedValue);
dbio.addSqlParameter("@FOEComments", txtFOEComments.Text);
dbio.addSqlParameter("@ToolWasFound", chkRecovered.Checked);
dbio.addSqlParameter("@NeedsCalibration",
chkNeedsCalibration.Checked);
dbio.addSqlParameter("@SecondQualityPerson",
ddlSecondQuality.SelectedValue);
dbio.addSqlParameter("@SecondFOE",
ddlSecondFOECoordinator.SelectedValue);

strSQL = "INSERT INTO LTR
(Type,Subtype,EmployeeName,Department,Shift,Extension,EmployeeNumber,Dat
eTimeCreated,Aircraft,Building,TypeOfTool,DateTimeLost,IdentifyingMarks,
DescriptionOfTool,ColorOfTool,AreaToolWasLost,AreaSearched,TalkedWithCoW
orkers,NotifiedSupervisor,NotifiedQuality,NotifiedFOE,ActionEmployeeTook
,AdditionalComments,Supervisor,SecondSupervisor,SupervisorActionTook,Sup
ervisorInvestigationResults,QualityInvestigator,QualityActionTook,Qualit
yInvestigationResults,FOECoordinator,FOEActionTook,FOEInvestigationResul
ts,DateToolFound,WhoFoundTool,WhereToolWasFound,FOEComments,ToolWasFound
,NeedsCalibration,SecondQualityPerson,SecondFOE) ";
strSQL = strSQL +
"VALUES(@Type,@Subtype,@EmployeeName,@Department,@Shift,@Extension,@Empl
oyeeNumber,@DateTimeCreated,@Aircraft,@Building,@TypeOfTool,@DateTimeLos
t,@IdentifyingMarks,@DescriptionOfTool,@ColorOfTool,@AreaToolWasLost,@Ar
eaSearched,@TalkedWithCoWorkers,@NotifiedSupervisor,@NotifiedQuality,@No
tifiedFOE,@ActionEmployeeTook,@AdditionalComments,@Supervisor,@SecondSup
ervisor,@ActionSupervisorTook,@SupervisorInvestigationResults,@QualityIn
vestigator,@QualityActionTook,@QualityInvestigationResults,@FOECoordinat
or,@FOEActionTook,@FOEInvestigationResults,@DateToolFound,@WhoFoundTool,
@WhereToolWasFound,@FOEComments,@ToolWasFound,@NeedsCalibration,@SecondQ
ualityPerson,@SecondFOE)";

dbio.executeNonQuery(strSQL);

dbio.Dispose();
}
private int retrieveReportNumber()
{
int result = -1;

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlDataReader("MTO_LTR", "SELECT LostToolReportNumber from
LTR where EmployeeNumber = '" + txtEmployeeNumber.Text + "' and
DateTimeCreated = '" + txtDate.Text + "'");

if (dbio.Read())
{
result = (int)dbio.getFieldValue("LostToolReportNumber");
}
dbio.Dispose();

return result;
}
private void promoteDocumentsv(int intLostToolReportNumber)
{
int intQueue = -1;
string strAircraft = "";

SendMail smtp = new SendMail();

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlDataReader("MTO_LTR", "Select CurrentQueue,
ToolWasFound, Aircraft from LTR where LostToolReportNumber = " +
intLostToolReportNumber.ToString());

if (dbio.Read())
{
intQueue = (int)dbio.getFieldValue("CurrentQueue");
strAircraft = dbio.getFieldValue("Aircraft").ToString();
if (dbio.getFieldValue("ToolWasFound").ToString() == "True")
intQueue = 5;
}

dbio.Dispose();

if (intQueue == -1)
return;
if (intQueue == 4)
return;

dbio = new PrimitiveDatabaseIO();

dbio.createSqlCommand("MTO_LTR");
dbio.addSqlParameter("@LostToolReportNumber",
intLostToolReportNumber);

if (intQueue == 5)
{
intQueue = 4;
dbio.executeNonQuery("UPDATE LTR set CurrentQueue = 5 WHERE
LostToolReportNumber = @LostToolReportNumber");
}
else
dbio.executeNonQuery("UPDATE LTR set CurrentQueue = CurrentQueue + 1
WHERE LostToolReportNumber = @LostToolReportNumber");

dbio.Dispose();

dbio = new PrimitiveDatabaseIO();

dbio.createSqlDataReader("MTO_LTR", "Select * from QueueNotification
where NotificationType = 'Approved' and QueueNumber = " + (intQueue +
1).ToString());

while (dbio.Read())
{
smtp.from = "LostToolReporting";
smtp.to = getTo(dbio.getFieldValue("SendTo").ToString());
smtp.subject =
dbio.getFieldValue("Subject").ToString().Replace("[AIRCRAFT]",strAircraf
t);
smtp.body =
dbio.getFieldValue("Body").ToString().Replace("[DocumentNumber]",intLost
ToolReportNumber.ToString());
smtp.body =
smtp.body.ToString().Replace("[HostName]",Dns.GetHostName().ToString());
smtp.send();
}

dbio.Dispose();

}
private void promoteDocument(int intLostToolReportNumber)
{
string strAircraft = "";

int intQueue = getNextQueue(intLostToolReportNumber);

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlDataReader("MTO_LTR", "Select Aircraft from LTR where
LostToolReportNumber = " + intLostToolReportNumber.ToString());

if (!dbio.Read())
{
dbio.Dispose();
return;
}

strAircraft = dbio.getFieldValue("Aircraft").ToString();

dbio.Dispose();

dbio = new PrimitiveDatabaseIO();

dbio.createSqlCommand("MTO_LTR");
if (intQueue == -1)
dbio.addSqlParameter("@CurrentQueue", 1);
else
dbio.addSqlParameter("@CurrentQueue", intQueue);
dbio.addSqlParameter("@LostToolReportNumber",
intLostToolReportNumber);

dbio.executeNonQuery("UPDATE LTR set CurrentQueue = @CurrentQueue
WHERE LostToolReportNumber = @LostToolReportNumber");

dbio.Dispose();

dbio = new PrimitiveDatabaseIO();

dbio.createSqlDataReader("MTO_LTR", "Select * from QueueNotification
where NotificationType = 'Approved' and QueueNumber = " +
intQueue.ToString());

SendMail smtp = new SendMail();

while (dbio.Read())
{
smtp.from = "(e-mail address removed)";//"LostToolReporting";
smtp.to = getTo(dbio.getFieldValue("SendTo").ToString());
smtp.subject =
dbio.getFieldValue("Subject").ToString().Replace("[AIRCRAFT]",strAircraf
t);
smtp.body =
dbio.getFieldValue("Body").ToString().Replace("[DocumentNumber]",intLost
ToolReportNumber.ToString());
smtp.body =
smtp.body.ToString().Replace("[HostName]",Dns.GetHostName().ToString());
smtp.send();
}

smtp = null;

dbio.Dispose();

}
private int getNextQueue(int intLostToolReportNumber)
{
int currentQueue = -1;

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlDataReader("MTO_LTR", "select ToolWasFound,
len(Supervisor) + len(SecondSupervisor) as SupervisorUpdated,
len(QualityInvestigator) + len(SecondQualityPerson) as QualityUpdated,
len(FOECoordinator) + len(SecondFOE) as FOEUpdated from LTR where
LostToolReportNumber = " + intLostToolReportNumber.ToString());

if (!dbio.Read())
{
dbio.Dispose();
return 1;
}

if (dbio.getFieldValue("ToolWasFound").ToString() == "True")
currentQueue = 5;
else
if ((int)dbio.getFieldValue("SupervisorUpdated") == 0
&& ((int)dbio.getFieldValue("QualityUpdated") != 0
|| (int)dbio.getFieldValue("FOEUpdated") != 0))
currentQueue = -1;
else
if ((int)dbio.getFieldValue("SupervisorUpdated") == 0)
currentQueue = 1;
else
if ((int)dbio.getFieldValue("QualityUpdated") == 0)
currentQueue = 2;
else
if ((int)dbio.getFieldValue("FOEUpdated") == 0)
currentQueue = 3;
else
currentQueue = 4;

dbio.Dispose();

return currentQueue;

}
private string getTo(string sendto)
{
string result = "";
string strTo = sendto;

if (strTo.Length < 1)
return "";

strTo = strTo.Replace("[","'");
strTo = strTo.Replace("]","'");
strTo = strTo.Replace(";",",");
strTo = " where [group] in (" + strTo + ")";

PrimitiveDatabaseIO faucet = new PrimitiveDatabaseIO();

faucet.createSqlDataReader("MTO_LTR", "SELECT * FROM users" + strTo);

ExchangeInfoADO xcng = new ExchangeInfoADO();

while (faucet.Read())
{
if (faucet.getFieldValue("Group").ToString() == "Calibration")
{
if (chkNeedsCalibration.Checked == true)
{
if (faucet.getFieldValue("ExternalEmail").ToString().Length > 0)
result = result + ";" +
faucet.getFieldValue("ExternalEmail").ToString();
xcng.getUserInfo(faucet.getFieldValue("UserName").ToString());
result = result + ";" + xcng.mail;
}
}
else
if (faucet.getFieldValue("Group").ToString() == "DCMA")
{
result = result + ";" +
faucet.getFieldValue("ExternalEmail").ToString();
}
else
{
if (faucet.getFieldValue("ExternalEmail").ToString().Length > 0)
result = result + ";" +
faucet.getFieldValue("ExternalEmail").ToString();
xcng.getUserInfo(faucet.getFieldValue("UserName").ToString());
result = result + ";" + xcng.mail;
}
}

xcng = null;
faucet.Dispose();

return result;
}
private void updateRecord(int rec_id)
{
if (Request.QueryString.GetValues(0).GetValue(0).ToString() ==
"Add")
updateRecord_Employee(rec_id);
else
if (isMember("Superuser") == true)
updateRecord_Superuser(rec_id);
else
if (isMember("Supervisors") == true)
updateRecord_Supervisor(rec_id);
else
if (isMember("Quality") == true)
updateRecord_Quality(rec_id);
else
if (isMember("FOE") == true)
updateRecord_FOE(rec_id);
}
private void updateRecord_Employee(int rec_id)
{
string strSQL;

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlCommand("MTO_LTR");
dbio.addSqlParameter("@EmployeeName", txtEmployeeName.Text);
dbio.addSqlParameter("@Department", txtDepartment.Text);
dbio.addSqlParameter("@Shift", ddlShift.SelectedValue);
dbio.addSqlParameter("@Extension", txtExtension.Text);
dbio.addSqlParameter("@EmployeeNumber", txtEmployeeNumber.Text);
dbio.addSqlParameter("@DateTimeCreated", txtDate.Text);
dbio.addSqlParameter("@Aircraft", ddlAircraft.SelectedValue);
dbio.addSqlParameter("@Building", ddlBuilding.SelectedValue);
dbio.addSqlParameter("@TypeOfTool", ddlTypeOfTool.SelectedValue);
dbio.addSqlParameter("@DateTimeLost", txtDateTimeLost.Text);
dbio.addSqlParameter("@IdentifyingMarks", txtIdentifyingMarks.Text);
dbio.addSqlParameter("@DescriptionOfTool",
ddlDescriptionOfTool.SelectedValue);
dbio.addSqlParameter("@ColorOfTool", ddlColorOfTool.SelectedValue);
dbio.addSqlParameter("@AreaToolWasLost", getSelected(lbAreaLost));
dbio.addSqlParameter("@AreaSearched", getSelected(lbAreaSearched));
dbio.addSqlParameter("@TalkedWithCoWorkers",
chkTalkedWithCoworkers.Checked);
dbio.addSqlParameter("@NotifiedSupervisor",
chkNotifiedSupervisor.Checked);
dbio.addSqlParameter("@NotifiedQuality", chkNotifiedQuality.Checked);
dbio.addSqlParameter("@NotifiedFOE", chkNotifiedFOE.Checked);
dbio.addSqlParameter("@ActionEmployeeTook",
getSelected(lbEmployeeAction));
dbio.addSqlParameter("@AdditionalComments",
txtAdditionalComments.Text);

strSQL = "UPDATE LTR SET
EmployeeName=@EmployeeName,Department=@Department,Shift=@Shift,Extension
=@Extension,EmployeeNumber=@EmployeeNumber,DateTimeCreated=@DateTimeCrea
ted,Aircraft=@Aircraft,Building=@Building,TypeOfTool=@TypeOfTool,DateTim
eLost=@DateTimeLost,IdentifyingMarks=@IdentifyingMarks,DescriptionOfTool
=@DescriptionOfTool,ColorOfTool=@ColorOfTool,AreaToolWasLost=@AreaToolWa
sLost,AreaSearched=@AreaSearched,TalkedWithCoWorkers=@TalkedWithCoWorker
s,NotifiedSupervisor=@NotifiedSupervisor,NotifiedQuality=@NotifiedQualit
y,NotifiedFOE=@NotifiedFOE,ActionEmployeeTook=@ActionEmployeeTook,Additi
onalComments=@AdditionalComments where losttoolreportnumber = " +
rec_id.ToString();

dbio.executeNonQuery(strSQL);

dbio.Dispose();
}
private void updateRecord_Supervisor(int rec_id)
{
string strSQL;

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlCommand("MTO_LTR");
dbio.addSqlParameter("@Supervisor", ddlSupervisor.SelectedValue);
dbio.addSqlParameter("@SecondSupervisor",
ddl2ndSupervisor.SelectedValue);
dbio.addSqlParameter("@ActionSupervisorTook",
getSelected(lbSupervisorAction));
dbio.addSqlParameter("@SupervisorInvestigationResults",
txtSupervisorResults.Text);

strSQL = "UPDATE LTR SET
Supervisor=@Supervisor,SecondSupervisor=@SecondSupervisor,SupervisorActi
onTook=@ActionSupervisorTook,SupervisorInvestigationResults=@SupervisorI
nvestigationResults where losttoolreportnumber = " + rec_id.ToString();

dbio.executeNonQuery(strSQL);

dbio.Dispose();
}
private void updateRecord_Quality(int rec_id)
{
string strSQL;

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlCommand("MTO_LTR");
dbio.addSqlParameter("@QualityInvestigator",
ddlQuality.SelectedValue);
dbio.addSqlParameter("@QualityActionTook",
getSelected(lbQualityAction));
dbio.addSqlParameter("@QualityInvestigationResults",
txtQualityResults.Text);
dbio.addSqlParameter("@NeedsCalibration",
chkNeedsCalibration.Checked);
dbio.addSqlParameter("@SecondQualityPerson",
ddlSecondQuality.SelectedValue);

strSQL = "UPDATE LTR SET
QualityInvestigator=@QualityInvestigator,QualityActionTook=@QualityActio
nTook,QualityInvestigationResults=@QualityInvestigationResults,NeedsCali
bration=@NeedsCalibration,SecondQualityPerson=@SecondQualityPerson where
losttoolreportnumber = " + rec_id.ToString();

dbio.executeNonQuery(strSQL);

dbio.Dispose();
}
private void updateRecord_FOE(int rec_id)
{
string strSQL;

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlCommand("MTO_LTR");
dbio.addSqlParameter("@FOECoordinator",
ddlFOECoordinator.SelectedValue);
dbio.addSqlParameter("@FOEActionTook", getSelected(lbFOEAction));
dbio.addSqlParameter("@FOEInvestigationResults", txtFOEResults.Text);
if (txtDateToolWasFound.Text.Length > 0)
dbio.addSqlParameter("@DateToolFound",
txtDateToolWasFound.Text);
else
dbio.addSqlParameter("@DateToolFound", System.DBNull.Value);
dbio.addSqlParameter("@WhoFoundTool", txtWhoFoundTool.Text);
dbio.addSqlParameter("@WhereToolWasFound",
getSelected(lbLocationFound));
dbio.addSqlParameter("@FOEComments", txtFOEComments.Text);
dbio.addSqlParameter("@ToolWasFound", chkRecovered.Checked);
dbio.addSqlParameter("@SecondFOE",
ddlSecondFOECoordinator.SelectedValue);

strSQL = "UPDATE LTR SET
FOECoordinator=@FOECoordinator,FOEActionTook=@FOEActionTook,FOEInvestiga
tionResults=@FOEInvestigationResults,DateToolFound=@DateToolFound,WhoFou
ndTool=@WhoFoundTool,WhereToolWasFound=@WhereToolWasFound,FOEComments=@F
OEComments,ToolWasFound=@ToolWasFound,SecondFOE=@SecondFOE where
losttoolreportnumber = " + rec_id.ToString();

dbio.executeNonQuery(strSQL);

dbio.Dispose();
}
private void updateRecord_Superuser(int rec_id)
{
string strSQL;

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlCommand("MTO_LTR");
dbio.addSqlParameter("@Type", "M4-F051");
dbio.addSqlParameter("@Subtype", "N/A");
dbio.addSqlParameter("@EmployeeName", txtEmployeeName.Text);
dbio.addSqlParameter("@Department", txtDepartment.Text);
dbio.addSqlParameter("@Shift", ddlShift.SelectedValue);
dbio.addSqlParameter("@Extension", txtExtension.Text);
dbio.addSqlParameter("@EmployeeNumber", txtEmployeeNumber.Text);
dbio.addSqlParameter("@DateTimeCreated", txtDate.Text);
dbio.addSqlParameter("@Aircraft", ddlAircraft.SelectedValue);
dbio.addSqlParameter("@Building", ddlBuilding.SelectedValue);
dbio.addSqlParameter("@TypeOfTool", ddlTypeOfTool.SelectedValue);
dbio.addSqlParameter("@DateTimeLost", txtDateTimeLost.Text);
dbio.addSqlParameter("@IdentifyingMarks", txtIdentifyingMarks.Text);
dbio.addSqlParameter("@DescriptionOfTool",
ddlDescriptionOfTool.SelectedValue);
dbio.addSqlParameter("@ColorOfTool", ddlColorOfTool.SelectedValue);
dbio.addSqlParameter("@AreaToolWasLost", getSelected(lbAreaLost));
dbio.addSqlParameter("@AreaSearched", getSelected(lbAreaSearched));
dbio.addSqlParameter("@TalkedWithCoWorkers",
chkTalkedWithCoworkers.Checked);
dbio.addSqlParameter("@NotifiedSupervisor",
chkNotifiedSupervisor.Checked);
dbio.addSqlParameter("@NotifiedQuality", chkNotifiedQuality.Checked);
dbio.addSqlParameter("@NotifiedFOE", chkNotifiedFOE.Checked);
dbio.addSqlParameter("@ActionEmployeeTook",
getSelected(lbEmployeeAction));
dbio.addSqlParameter("@AdditionalComments",
txtAdditionalComments.Text);
dbio.addSqlParameter("@Supervisor", ddlSupervisor.SelectedValue);
dbio.addSqlParameter("@SecondSupervisor",
ddl2ndSupervisor.SelectedValue);
dbio.addSqlParameter("@ActionSupervisorTook",
getSelected(lbSupervisorAction));
dbio.addSqlParameter("@SupervisorInvestigationResults",
txtSupervisorResults.Text);
dbio.addSqlParameter("@QualityInvestigator",
ddlQuality.SelectedValue);
dbio.addSqlParameter("@QualityActionTook",
getSelected(lbQualityAction));
dbio.addSqlParameter("@QualityInvestigationResults",
txtQualityResults.Text);
dbio.addSqlParameter("@FOECoordinator",
ddlFOECoordinator.SelectedValue);
dbio.addSqlParameter("@FOEActionTook", getSelected(lbFOEAction));
dbio.addSqlParameter("@FOEInvestigationResults", txtFOEResults.Text);
if (txtDateToolWasFound.Text.Length > 0)
dbio.addSqlParameter("@DateToolFound", txtDateToolWasFound.Text);
else
dbio.addSqlParameter("@DateToolFound", System.DBNull.Value);
dbio.addSqlParameter("@WhoFoundTool", txtWhoFoundTool.Text);
dbio.addSqlParameter("@WhereToolWasFound",
getSelected(lbLocationFound));
dbio.addSqlParameter("@FOEComments", txtFOEComments.Text);
dbio.addSqlParameter("@ToolWasFound", chkRecovered.Checked);
dbio.addSqlParameter("@NeedsCalibration",
chkNeedsCalibration.Checked);
dbio.addSqlParameter("@SecondQualityPerson",
ddlSecondQuality.SelectedValue);
dbio.addSqlParameter("@SecondFOE",
ddlSecondFOECoordinator.SelectedValue);

strSQL = "UPDATE LTR SET
Type=@Type,Subtype=@Subtype,EmployeeName=@EmployeeName,Department=@Depar
tment,Shift=@Shift,Extension=@Extension,EmployeeNumber=@EmployeeNumber,D
ateTimeCreated=@DateTimeCreated,Aircraft=@Aircraft,Building=@Building,Ty
peOfTool=@TypeOfTool,DateTimeLost=@DateTimeLost,IdentifyingMarks=@Identi
fyingMarks,DescriptionOfTool=@DescriptionOfTool,ColorOfTool=@ColorOfTool
,AreaToolWasLost=@AreaToolWasLost,AreaSearched=@AreaSearched,TalkedWithC
oWorkers=@TalkedWithCoWorkers,NotifiedSupervisor=@NotifiedSupervisor,Not
ifiedQuality=@NotifiedQuality,NotifiedFOE=@NotifiedFOE,ActionEmployeeToo
k=@ActionEmployeeTook,AdditionalComments=@AdditionalComments,Supervisor=
@Supervisor,SecondSupervisor=@SecondSupervisor,SupervisorActionTook=@Act
ionSupervisorTook,SupervisorInvestigationResults=@SupervisorInvestigatio
nResults,QualityInvestigator=@QualityInvestigator,QualityActionTook=@Qua
lityActionTook,QualityInvestigationResults=@QualityInvestigationResults,
FOECoordinator=@FOECoordinator,FOEActionTook=@FOEActionTook,FOEInvestiga
tionResults=@FOEInvestigationResults,DateToolFound=@DateToolFound,WhoFou
ndTool=@WhoFoundTool,WhereToolWasFound=@WhereToolWasFound,FOEComments=@F
OEComments,ToolWasFound=@ToolWasFound,NeedsCalibration=@NeedsCalibration
,SecondQualityPerson=@SecondQualityPerson,SecondFOE=@SecondFOE where
losttoolreportnumber = " + rec_id.ToString();

dbio.executeNonQuery(strSQL);

dbio.Dispose();
}
private int getInteger(string id,
System.Web.UI.WebControls.RepeaterItem row)
{
System.Web.UI.WebControls.TextBox txtBox =
(System.Web.UI.WebControls.TextBox)getControl(id, row);

if (txtBox == null)
return 0;
if (txtBox.Text.Length < 1)
return 0;
return System.Int32.Parse(txtBox.Text);
}
private bool getBool(string id, System.Web.UI.WebControls.RepeaterItem
row)
{
System.Web.UI.WebControls.CheckBox chkBox =
(System.Web.UI.WebControls.CheckBox)getControl(id, row);

if (chkBox == null)
return false;

return chkBox.Checked;
}
private string getString(string id,
System.Web.UI.WebControls.RepeaterItem row)
{
System.Web.UI.WebControls.TextBox txtBox =
(System.Web.UI.WebControls.TextBox)getControl(id, row);

if (txtBox == null)
return null;
if (txtBox.Text.Length < 1)
return "";

return txtBox.Text;
}
private System.Web.UI.Control getControl(string id,
System.Web.UI.WebControls.RepeaterItem row)
{
foreach (System.Web.UI.Control control in row.Controls)
{
if (control.ID == id)
return control;
}

return null;
}
private void Home_Click(object sender, System.EventArgs e)
{
string strRedirect;

strRedirect = "<script language='Javascript'>";
strRedirect += "parent.main.location.href='welcome.aspx';";
strRedirect += "</script>";

Response.Write(strRedirect);
}
private bool isMember(string strGroup)
{
bool result = false;

PrimitiveDatabaseIO faucet = new PrimitiveDatabaseIO();

faucet.createSqlDataReader("MTO_LTR", "SELECT username FROM users
WHERE [group] = '" + strGroup + "' and username = '" +
User.Identity.Name.Substring(10, User.Identity.Name.Length - 10) + "'");

if (faucet.Read())
{
result = true;
}

faucet.Dispose();

return result;
}
private bool isAuthorized(int intQueue)
{
string strGroup = "";

if (intQueue == 0)
return true;
if (intQueue == 4)
return false;
if (intQueue == 5)
return false;

switch (intQueue)
{
case 1:
strGroup = "Supervisors";
break;
case 2:
strGroup = "Quality";
break;
case 3:
strGroup = "FOE";
break;
default:
return false;
}

return isMember(strGroup);
}
private DataSet getPeople(string group)
{
DataSet result = new DataSet("people");
DataRow row;
DataColumn col;

result.Tables.Add();

col = new DataColumn();
col.DataType = System.Type.GetType("System.String");
col.ColumnName= "Individual";
result.Tables[0].Columns.Add(col);

row = result.Tables[0].NewRow();
row["Individual"] = null;
result.Tables[0].Rows.Add(row);

PrimitiveDatabaseIO faucet = new PrimitiveDatabaseIO();

faucet.createSqlDataReader("MTO_LTR", "SELECT username FROM users
where [group] = '" + group + "' order by username");

ExchangeInfoADO xcng = new ExchangeInfoADO();

while(faucet.Read())
{
if (faucet.getFieldValue("username").ToString().Substring(0,4) ==
"PASI")
{
row = result.Tables[0].NewRow();
row["Individual"] = faucet.getFieldValue("username").ToString();
result.Tables[0].Rows.Add(row);
}
else
{
xcng.name = "";
xcng.getUserInfo(faucet.getFieldValue("username").ToString());

if (xcng.name != null && xcng.name.Length > 2)
{
row = result.Tables[0].NewRow();
row["Individual"] = xcng.name;
result.Tables[0].Rows.Add(row);
}
}
}

xcng = null;

faucet.Dispose();

return result;
}

private void txtEmployeeNumber_Changed(object sender, System.EventArgs
e)
{
isValidEmployee(txtEmployeeNumber.Text);
}
private void makeTracks(int id)
{
string strSQL;
string strMemberships = "";

if (isMember("Superuser") == true)
strMemberships = strMemberships + "Superuser|";
if (isMember("Supervisors") == true)
strMemberships = strMemberships + "Supervisors|";
if (isMember("Quality") == true)
strMemberships = strMemberships + "Quality|";
if (isMember("FOE") == true)
strMemberships = strMemberships + "FOE|";
if (isMember("DCMA") == true)
strMemberships = strMemberships + "DCMA|";

if (strMemberships.Length < 1)
strMemberships = "Employee|";

strMemberships = strMemberships.Substring(0,strMemberships.Length
-1);

PrimitiveDatabaseIO dbio = new PrimitiveDatabaseIO();

dbio.createSqlCommand("MTO_LTR");
dbio.addSqlParameter("@ID", id);
dbio.addSqlParameter("@DateTimeLogged", System.DateTime.Now);
dbio.addSqlParameter("@DocumentType", "M4-F051");
dbio.addSqlParameter("@DocumentSubtype", "N/A");
dbio.addSqlParameter("@QueueName", strMemberships);
dbio.addSqlParameter("@PlacedHereBy", User.Identity.Name);

strSQL = "INSERT INTO DocumentTracks
(ID,DateTimeLogged,DocumentType,DocumentSubtype,QueueName,PlacedHereBy)
";
strSQL = strSQL +
"VALUES(@ID,@DateTimeLogged,@DocumentType,@DocumentSubtype,@QueueName,@P
lacedHereBy)";

dbio.executeNonQuery(strSQL);

dbio.Dispose();
}
private void btnPrint_Click(object sender, System.EventArgs e)
{
string strReport =
"LTR_ReportView.aspx?Report=LostToolReport&SelectionFormula={LTR.LostToo
lReportNumber}=" + txtLostToolReportNo.Text + "";

Response.Redirect(strReport);
}
private string isTooLong(System.Web.UI.WebControls.Panel pnl)
{
foreach (System.Web.UI.Control control in pnl.Controls)
{
if (control.GetType().FullName ==
"System.Web.UI.WebControls.TextBox")
{
if (((System.Web.UI.WebControls.TextBox)control).Text.Length >
((System.Web.UI.WebControls.TextBox)control).MaxLength)
{
((System.Web.UI.WebControls.TextBox)control).Font.Bold = true;
((System.Web.UI.WebControls.TextBox)control).ForeColor =
System.Drawing.Color.Red;
return "The text you typed is too long to be stored in the Lost
Tool Reporting database. Please adjust the text length.";
}
else
{
((System.Web.UI.WebControls.TextBox)control).Font.Bold = false;
((System.Web.UI.WebControls.TextBox)control).ForeColor =
System.Drawing.Color.Black;
}
}
}

return "";
}

}
}
 
V

Vickie Wheaton

Sorry that is the wrong code. Below is the code where I'm getting the
exception.


ddlAircraft.Items.FindByValue(pdio.getFieldValue("Aircraft").ToString())
.Selected = true;
 
B

Bruce Wood

Well, there's a lot going on in that line. Try breaking it down into
separate statements as follows. This won't fix the problem, but at
least it will allow you to pinpoint exactly what is happening:

object aircraftFieldValue = pdio.getFieldValue("Aircraft");

string aircraftValueString = aircraftFieldValue.ToString(); // Will die
here if pdio.getFieldValue() failed above

ListItem aircraftItem =
ddlAircraft.Items.FindByValue(aircraftValueString);

aircraftItem.Selected = true; // Will die here if no item in drop down
list corresponds to aircraftValueString.

Try that and see what it tells you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top