Thank you PrinceG for your response.
How to replace the hard coded values 0.30 and 0.20 with fieldname.
For instance, the values of the DropDownList from the original code is hard coded as constants here:
static byte num20 = 0, num30 = 0;
The if you look at the addWater_Click event, you see something like this:
if (Water1.SelectedItem.Value == "0.30")
num30 += 1;
else num20 += 1;
Our hope is to have this be more dynamic.
protected void addWater_Click(object sender, EventArgs e)
{
// get session information on rebatable waters
string[] waters = new string[3], waters = new string[3];
if ((string)Session["GPFPerWater"] != "")
{
waters = Session["GPFPerWater"].ToString().Split(',');
waters = Session["GPFPerWater"].ToString().Split(',');
}
// set the available fields based on the number of rebatable waters
switch (numWater)
{
case 0:
firstToilet.Visible = Water2.Visible = Water3.Visible = false;
break;
case 1:
firstToilet.Visible = true;
if (Water1.SelectedIndex == 0)
{
if (waters[0] != null) Water1.SelectedValue = waters[0].ToString();
if (waters[0] != null) WaterValue1.Text = waters[0].ToString();
Water2.Visible = Water3.Visible = false;
}
break;
case 2:
firstToilet.Visible = Water2.Visible = true;
if (Water1.SelectedIndex == 0)
{
if (waters[0] != null) Water1.SelectedValue = waters[0].ToString();
if (waters[0] != null) waterValue1.Text = waters[0].ToString();
if (waters[1] != null) Water2.SelectedValue = waters[1].ToString();
if (waters[1] != null) waterValue2.Text = waters[1].ToString();
Water3.Visible = false;
}
break;
case 3:
firstToilet.Visible = Water2.Visible = Water3.Visible = true;
if (Water1.SelectedIndex == 0)
{
if (waters[0] != null) Water1.SelectedValue = waters[0].ToString();
if (waters[0] != null) waterValue1.Text = waters[0].ToString();
if (waters[1] != null) Water2.SelectedValue = waters[1].ToString();
if (waters[1] != null) waterValue2.Text = waters[1].ToString();
if (waters[2] != null) Water2.SelectedValue = waters[2].ToString();
if (waters[2] != null) waterValue2.Text = waters[2].ToString();
}
break;
}
addRebateWater_ModalPopupExtender.Show();
}
protected void addWater_Click(object sender, EventArgs e)
{
string gpf = "", rpt = "", tinfo = "";
double ttl = 0;
bool okToHide = true;
if (Water1.SelectedIndex != 0)
{
if (waterValue1.Text.Contains(".") == false) waterValue1.Text = waterValue1.Text + ".00";
if (CheckToiletValue(Water1.SelectedValue, decimal.Parse(waterValue1.Text)) == true)
{
// gallons per flush
gpf += Water1.SelectedValue;
Session["GPFPerWater"] = Water1.SelectedItem.Value;
// water per water
rpt += waterValue1.Text;
Session["WaterPerToilet"] = waterValue1.Text;
// add to the total
ttl += double.Parse(waterValue1.Text);
// format the water info string
tinfo += Water1.SelectedItem + " @ " + waterValue1.Text;
if (Water1.SelectedItem.Value == "0.30") num30 += 1;
else num20 += 1;
}
else
{
Master.ShowMessage("The first water water value is higher than rules allow, please edit the value and try again");
okToHide = false;
}
}
if (Water2.Visible == true)
{
if (Water2.SelectedIndex != 0)
{
if (waterValue2.Text.Contains(".") == false) waterValue2.Text = waterValue2.Text + ".00";
if (CheckToiletValue(Water2.SelectedValue, decimal.Parse(waterValue2.Text)) == true)
{
// gallons per flush
gpf += "," + Water2.SelectedValue;
Session["GPFPerWater"] += "," + Water2.SelectedItem.Value;
// water per water
rpt += waterValue2.Text;
Session["WaterPerToilet"] += "," + waterValue2.Text;
// add to the total
ttl += double.Parse(waterValue2.Text);
// format the water info string
tinfo += "<br />" + Water2.SelectedItem + " @ " + waterValue2.Text;
if (Water2.SelectedItem.Value == "0.30") num30 += 1;
else num20 += 1;
}
else
{
Master.ShowMessage("The second water water value is higher than rules allow, please edit the value and try again");
okToHide = false;
}
}
}
if (Water3.Visible==true)
{
if (water3.SelectedIndex != 0)
{
if (waterValue3.Text.Contains(".") == false) waterValue3.Text = waterValue3.Text + ".00";
if (CheckToiletValue(water3.SelectedValue, decimal.Parse(waterValue3.Text)) == true)
{
// gallons per flush
gpf += "," + water3.SelectedValue;
Session["GPFPerWater"] += "," + water3.SelectedItem.Value;
// water per water
rpt += waterValue3.Text;
Session["WaterPerToilet"] += "," + waterValue3.Text;
// add to the total
ttl += double.Parse(waterValue3.Text);
// format the water info string
tinfo += "<br />" + water3.SelectedItem + " @ " + waterValue3.Text;
if (water3.SelectedItem.Value == "0.30") num30 += 1;
else num20 += 1;
}
else
{
Master.ShowMessage("The third water water value is higher than rules allow, please edit the value and try again");
okToHide = false;
}
}
}
if (okToHide == true)
{
waterInformation.Text = tinfo;
Session["ToiletInformation"] = tinfo;
totalWater.Text = ttl.ToString("##00.00");
Session["TotalWater"] = ttl.ToString("##00.00");
addRebateWater_ModalPopupExtender.Hide();
}
}
protected bool CheckToiletValue(string gpf, decimal amt)
{
bool valueOK = false;
switch (gpf)
{
case "0.20":
if (amt <= 100)
valueOK = true;
break;
case "0.30":
if (amt <= 50)
valueOK = true;
break;
}
return valueOK;
}