You think you have got it bad?
Posted: Tue Oct 18, 2005 3:20 pm
Here is some code I was just looking at. Why do people feel a need to nest if statments when they dont have to? What's wrong with using 'return' at the end of if block? Why the hell am I still in Arkansas?
Code: Select all
//Description Field
if ((t1.Text.Trim () == ""))
{
t1.BorderColor = Color.Red;
t1.Text = null;
xMenu.SetError("Please Enter Description.");
}
else
{
t1.BorderColor = Color.White;
// Account Number
if((t7.Text.Trim () == "" || ! validateAccountNumber(t7.Text)))
{
t7.BorderColor = Color.Red;
t7.Text = null;
xMenu.SetError("Please Enter a Vaild Account Number.");
}
else
{
t7.BorderColor = Color.White;
//Agent Field
if ((t7.Text == "1200" || t7.Text == "1201") && ((t3.Text.Trim () == "") || IsNumeric(t3.Text) == false))
{
t3.BorderColor = Color.Red;
t3.Text = null;
xMenu.SetError("Please Enter Agent Name.");
}
else
{
t3.BorderColor = Color.White;
//Agent Account Field
if (t3.Text.Trim ()!="" && ((t4.Text.Trim () == "") || t4.Text.Length != 2 || IsNumeric(t4.Text) == false))
{
t4.BorderColor = Color.Red;
t4.Text = null;
xMenu.SetError("Both Agent and Valid Agent Account is required.");
}
else
{
t4.BorderColor = Color.White;
//Misc Codes Field
if((t5.Text.Trim () == "" || !validateAgentAccountMiscTypeCodes(t5.Text)))
{
t5.BorderColor = Color.Red;
t5.Text = null;
xMenu.SetError("Please Enter a Vaild MISC Type.");
}
else
{
t5.BorderColor = Color.White;
// Amount
if((t8.Text.Trim () == "") || IsNumeric(t8.Text) == false || !(Double.Parse(t8.Text) > 0.0))
{
t8.BorderColor = Color.Red;
t8.Text = null;
GiveMsg ("Please Enter a Valid Amount (> 0.00).",0); }
else
{
t8.BorderColor = Color.White;
// Policy
if((t5.Text == "01" || t5.Text == "02") && (t6.Text.Trim () == ""))
{
t6.BorderColor = Color.Red;
t6.Text = null;
GiveMsg ("Policy Number Cannot be Null when Pay Type Code is 01 or 02.",0); }
else
{
t6.BorderColor = Color.White;
ArrayList upvalues = new ArrayList ();
upvalues.Add (e.Item.Cells [0].Text); //Voucher
upvalues.Add (e.Item.Cells [1].Text); //Item No
upvalues.Add (e.Item.Cells [2].Text); //Entry
upvalues.Add (t1.Text); //Description
upvalues.Add (t2.Text); //Center
upvalues.Add (t3.Text); //Agent
upvalues.Add (t4.Text); //Agt
upvalues.Add (t5.Text); //MType
upvalues.Add (t6.Text); //Policy
upvalues.Add (dd1.SelectedValue); //D/C
upvalues.Add (t7.Text); //Account
upvalues.Add (Double.Parse (t8.Text).ToString("0.00")); //Amount
upvalues.Add (e.Item.Cells [15].Text); //Type
upvalues.Add (e.Item.Cells [16].Text); // Com
upvalues.Add (e.Item.Cells [17].Text); // Dept
upvalues.Add (e.Item.Cells [14].Text); // Name
SessionVaribles.AppGlobal.DGEditMode = "F";
DataGrid1.EditItemIndex = -1;
System.Web.UI.WebControls.LinkButton lblStat = (System.Web.UI.WebControls.LinkButton)e.Item.Cells[18].Controls[0];
if(lblStat.Text=="Insert")
{ act = "add"; }
else
{ act = "updt"; }
if (e.Item.Cells [15].Text == "99" || e.Item.Cells[15].Text == "99" || SessionVaribles.VoucherSystem.status == "3")
{
GiveMsg ("History Vouchers Cannot be Updated.",0);
DataGrid1.CurrentPageIndex = 0;
DataGrid1.DataSource = SessionVaribles.VoucherSystem.VoucherEntries;
DataGrid1.DataBind ();
}
else
{
try
{
TWM.Common.DataServices.VOUCHER.RECORDHEADER upvrec = changeVDesc ( act,"ORMVOUVF","99", upvalues);
if (Convert.ToInt32 (upvrec.ReturnCode) == 0)
{
GiveMsg ("Record Successfully Added.",1);
SessionVaribles.VoucherSystem.VoucherEntries = VoucherTable (bfwdVDesc ("bfwd","ORMVOUVF","99", e.Item.Cells [16].Text, "-1") , "-1");
DataGrid1.CurrentPageIndex = 0;
DataGrid1.DataSource = SessionVaribles.VoucherSystem.VoucherEntries;
DataGrid1.DataBind ();
ddlStatus.SelectedValue = "1";
}
else
{
GiveMsg(upvrec.Message,0);
}
}
catch (Exception ee)
{
GiveMsg (ee.Message,0);
}
}
} } } } } }
}