Advertisement
driftboatdave

TryOutSteps.aspx.cs

Jan 16th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. using System.Data;
  9. using PCS2.Classes;
  10.  
  11. namespace PCS2.Forms
  12. {
  13.     public partial class TryOutSteps : System.Web.UI.Page
  14.     {
  15.         DBBuilds myDBBuilds = new DBBuilds();
  16.         UtilFunctions myUtilFunctions = new UtilFunctions();
  17.         protected void Page_Load(object sender, EventArgs e)
  18.         {
  19.  
  20.             if (!IsPostBack)
  21.             {
  22.                  //string LocationDesc = (string)Session["LocationDesc"];
  23.                 LoadDropDowns(false);
  24.                 //if (Request.QueryString["TryOutID"] != null)
  25.  
  26.                 try
  27.                 {
  28.                     int TryOutID = 1; // Convert.ToInt32(Request.QueryString["TryOutID"]);
  29.                     //and display any rows
  30.                     bool b = BindList();
  31.                 }
  32.                 catch(Exception)
  33.                 {
  34.                     //fill in later
  35.                 }
  36.             }
  37.             else
  38.             {
  39.                 //later we will have the Process dropdown selections change when the Location is reset. \
  40.                 //that's major surgery really. we'll have to reset each process and step value.
  41.                 //at this point we're not going to reset the PRocess dropdown without running an update on the entire table TryOutStep.ProcessID values.
  42.                 //LoadDropDowns(true);
  43.             }
  44.  
  45.         }
  46.  
  47.  
  48.         private void LoadDropDowns(bool IsPostBack)
  49.         {
  50.             if (IsPostBack == false)
  51.             {
  52.                 PopulateProductTypeDropdown();
  53.                 PopulateLocation();
  54.                 //PopulateProcessDrop(); //default selection
  55.                 //PopulateStepType();
  56.             }
  57.             else
  58.             {
  59.                 //need to reset processes based on product type
  60.                 PopulateProcessListviewDrops();
  61.             }
  62.         }
  63.  
  64.         //this is called with every postback
  65.         protected void PopulateProcessListviewDrops()
  66.         {
  67.             DropDownList DropDownToFill = (DropDownList)TryOutStepList.InsertItem.FindControl("ProcessDropIns");
  68.             PopulateProcessDrop(DropDownToFill);
  69.              //then our edit item template
  70.         }
  71.  
  72.         //step type stays static
  73.  
  74.         protected void PopulateStepTypeListviewDrops()
  75.         {
  76.             DropDownList DropDownToFill = (DropDownList)TryOutStepList.InsertItem.FindControl("StepTypeDropIns");
  77.             PopulateStepType(DropDownToFill);
  78.         }
  79.  
  80.         protected void PopulateProcessDrop(DropDownList DropDownToFill)
  81.         {
  82.             int index = myUtilFunctions.DropdownFirstOrValidValue(ProductTypesDrop);
  83.             int ProductTypeID = Convert.ToInt32(ProductTypesDrop.Items[index].Value);
  84.             index = myUtilFunctions.DropdownFirstOrValidValue(LocationDrop);
  85.             int LocationID = Convert.ToInt32(LocationDrop.Items[index].Value);
  86.             //DropDownList DropDownToFill = (DropDownList)TryOutStepList.InsertItem.FindControl("ProcessDrop");
  87.             myUtilFunctions.PopulateProcessDropdown(ProductTypeID, LocationID, DropDownToFill);
  88.         }
  89.  
  90.         protected void PopulateProductTypeDropdown()
  91.         {
  92.             myUtilFunctions.PopulateProductTypeDropdown(ProductTypesDrop);
  93.         }
  94.  
  95.  
  96.         protected void PopulateStepType(DropDownList DropDownToFill)
  97.         {
  98.             myUtilFunctions.PopulateStepTypeDropdown(DropDownToFill);
  99.         }
  100.  
  101.         protected void PopulateLocation()
  102.         {
  103.             myUtilFunctions.PopulateLocationDropdown(LocationDrop);
  104.         }
  105.  
  106.  
  107.         protected bool BindList()
  108.         {
  109.             bool result = false;
  110.             int TryOutID = Convert.ToInt32(TryOutText.Text);
  111.             DataTable dt = myDBBuilds.GetTryOutStep(TryOutID, 0);
  112.             //if (dt.Rows.Count > 0) - there will be many times where there's no steps yet associated with a tryout
  113.                 try
  114.                 {
  115.                     TryOutStepList.DataSource = dt; //cmd.ExecuteReader(CommandBehavior.Default);
  116.                     TryOutStepList.DataBind();
  117.                     //and fill the StepType and Process dropdowns
  118.                     PopulateStepTypeListviewDrops();
  119.                     PopulateProcessListviewDrops();
  120.                     result = true;
  121.                 }
  122.                 catch (Exception)
  123.                 {
  124.                 }
  125.             return result;
  126.         }
  127.  
  128.         protected void TryOutStepList_ItemInserting(object sender, ListViewInsertEventArgs e)
  129.         {
  130.             try
  131.             {
  132.                 int ProcessID = 0;
  133.                 int StepTypeID = 0;
  134.                 int TryOutID = Convert.ToInt32(TryOutText.Text);
  135.                 DropDownList DropDownSource = (DropDownList)e.Item.FindControl("ProcessDropIns");  //(TryOutStepList.Items[e.ItemIndex].FindControl("ProcessDropEdit")) as DropDownList;
  136.                 if (DropDownSource != null)
  137.                 {
  138.                     ProcessID = Convert.ToInt32(DropDownSource.SelectedItem.Value);
  139.                 }
  140.                 DropDownSource = (DropDownList)e.Item.FindControl("StepTypeDropIns");  //(TryOutStepList.Items[e.ItemIndex].FindControl("ProcessDropEdit")) as DropDownList;
  141.                 if (DropDownSource != null)
  142.                 {
  143.                     StepTypeID = Convert.ToInt32(DropDownSource.SelectedItem.Value);
  144.                 }
  145.                 string Description = ((TextBox)e.Item.FindControl("DescriptionTextIns")).Text;
  146.                 int StepOrder = Convert.ToInt32(((TextBox)e.Item.FindControl("StepOrderTextIns")).Text);
  147.                 string CreatedBy = Context.User.Identity.Name.ToString();
  148.                 int TryOutStepID = myDBBuilds.InsertTryOutStep(TryOutID, StepOrder, CreatedBy, CreatedBy, Description, ProcessID, StepTypeID);
  149.                 TryOutStepList.EditIndex = -1;    
  150.                 BindList();
  151.  
  152.  
  153.  
  154.                 ////BELOW does not work
  155.                 //ListViewItem item = TryOutStepList.Items[e.Item.DataItemIndex];
  156.                 //int ProcessID = Convert.ToInt32(((DropDownList)e.Item.FindControl("ProcessDropIns")).SelectedItem.Value);
  157.                 //string Description = ((TextBox)e.Item.FindControl("DescriptionTextIns")).Text;
  158.                 //int StepOrder = Convert.ToInt32(((TextBox)e.Item.FindControl("StepOrderTextIns")).Text);
  159.                 //int StepTypeID = Convert.ToInt32(((DropDownList)e.Item.FindControl("StepTypeDropIns")).SelectedItem.Value);
  160.                 //string CreatedBy = Context.User.Identity.Name.ToString();
  161.                 //int TryOutStepID = myDBBuilds.InsertTryOutStep(TryOutID, StepOrder, CreatedBy, CreatedBy, Description, ProcessID, StepTypeID);
  162.  
  163.  
  164.  
  165.  
  166.  
  167.              }
  168.             catch
  169.             {
  170.                 //add handling here on bad values i.e. in StepOrder fields
  171.             }
  172.  
  173.         }
  174.  
  175.         //this is very wasteful and needs to be fixed. We're calling the same database multiple times for the same set.
  176.         //TODO: Will refactor when there's time.
  177.  
  178.  
  179.         protected void TryOutStepList_ItemDeleting(object sender, ListViewDeleteEventArgs e)
  180.         {
  181.  
  182.                 int TryOutStepID = Convert.ToInt32(TryOutStepList.DataKeys[e.ItemIndex].Value.ToString());
  183.                 myDBBuilds.DeleteTryOutStep(TryOutStepID);
  184.                 TryOutStepList.EditIndex = -1;
  185.                 BindList();
  186.         }
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.         protected void TryOutStepList_ItemEditing(object sender, ListViewEditEventArgs e)
  194.         {
  195.             TryOutStepList.EditIndex = e.NewEditIndex;
  196.             //databind here?
  197.             BindList();
  198.  
  199.         }
  200.  
  201.         protected void TryOutStepList_ItemCanceling(object sender, ListViewCancelEventArgs e)
  202.         {
  203.             //Message.Text = "error message here";
  204.             e.Cancel = true;
  205.             TryOutStepList.SelectedIndex = -1;
  206.             //redatabind here?
  207.             BindList();
  208.         }
  209.  
  210.         protected void TryOutStepList_DataBound(object sender, EventArgs e)
  211.         {
  212.             //fill out edit dropdowns
  213.             if (TryOutStepList.EditItem != null)
  214.             {
  215.                 DropDownList DropDownToFill = (DropDownList)TryOutStepList.EditItem.FindControl("ProcessDropEdit");
  216.                 if (DropDownToFill != null)
  217.                 {
  218.                     PopulateProcessDrop(DropDownToFill);
  219.                 }
  220.                 DropDownToFill = (DropDownList)TryOutStepList.EditItem.FindControl("StepTypeDropEdit");
  221.                 if (DropDownToFill != null)
  222.                 {
  223.                     PopulateStepType(DropDownToFill);
  224.                 }
  225.             }
  226.             //and now insertion dropdowns
  227.             if (TryOutStepList.InsertItem != null)
  228.             {
  229.                 DropDownList DropDownToFill = (DropDownList)TryOutStepList.InsertItem.FindControl("ProcessDropIns");
  230.                 if (DropDownToFill != null)
  231.                 {
  232.                     PopulateProcessDrop(DropDownToFill);
  233.                 }
  234.                 DropDownToFill = (DropDownList)TryOutStepList.InsertItem.FindControl("StepTypeDropIns");
  235.                 if (DropDownToFill != null)
  236.                 {
  237.                     PopulateStepType(DropDownToFill);
  238.                 }
  239.             }            
  240.  
  241.         }
  242.  
  243.         protected void TryOutStepList_ItemUpdating(object sender, ListViewUpdateEventArgs e)
  244.         {
  245.  
  246.             try
  247.             {
  248.                 int ProcessID = 0;
  249.                 int StepTypeID = 0;
  250.                 int TryOutID = Convert.ToInt32(TryOutText.Text);
  251.                 ListViewItem item = TryOutStepList.Items[e.ItemIndex];
  252.                 DropDownList DropDownSource = (DropDownList)item.FindControl("ProcessDropEdit");  //(TryOutStepList.Items[e.ItemIndex].FindControl("ProcessDropEdit")) as DropDownList;
  253.                 if (DropDownSource!=null)
  254.                 {
  255.                     ProcessID = Convert.ToInt32(DropDownSource.SelectedItem.Value);
  256.                 }
  257.                 DropDownSource = (DropDownList)item.FindControl("StepTypeDropEdit");  //(TryOutStepList.Items[e.ItemIndex].FindControl("ProcessDropEdit")) as DropDownList;
  258.                 if (DropDownSource != null)
  259.                 {
  260.                     StepTypeID = Convert.ToInt32(DropDownSource.SelectedItem.Value);
  261.                 }
  262.                 int TryOutStepID = Convert.ToInt32(TryOutStepList.DataKeys[e.ItemIndex].Value.ToString());
  263.  
  264.                 string Description = ((TextBox)item.FindControl("DescriptionTextEdit")).Text;
  265.                 int StepOrder = Convert.ToInt32(((TextBox)item.FindControl("StepOrderTextEdit")).Text);
  266.                 string ModifiedBy = Context.User.Identity.Name.ToString();
  267.                 myDBBuilds.UpdateTryOutStep(TryOutStepID, StepOrder, ModifiedBy, Description, ProcessID, StepTypeID);
  268.                 TryOutStepList.EditIndex = -1;    
  269.                 BindList();
  270.  
  271.                 //DropDownList DropDownToFill = (DropDownList)item.FindControl("ProcessDropEdit");
  272.                
  273.                 //ABOVE - todo - replace with master form
  274.  
  275.                 //does this find it? or do we do the item.x method?
  276.                 //nope, breaks DropDownList DropDownToFillTEMP = (DropDownList)TryOutStepList.EditItem.FindControl("StepTypeDropEdit");
  277.                 //string s = DropDownToFillTEMP.SelectedValue.ToString();
  278.  
  279.  
  280.                 //ListViewItem item = TryOutStepList.Items[e.NewEditIndex];
  281.                 //ProcessID = Convert.ToInt32(((DropDownList)item.FindControl("ProcessDropEdit")).SelectedItem.Value);
  282.                 //string Description = ((TextBox)item.FindControl("DescriptionTextEdit")).Text;
  283.                 //int StepOrder = Convert.ToInt32(((TextBox)item.FindControl("StepOrderTextEdit")).Text);
  284.                 //int StepTypeID = Convert.ToInt32(((DropDownList)item.FindControl("StepTypeDropEdit")).SelectedItem.Value);
  285.                 //string ModifiedBy = Context.User.Identity.Name.ToString();
  286.                 //myDBBuilds.UpdateTryOutStep(TryOutStepID, StepOrder, ModifiedBy, Description, ProcessID, StepTypeID);
  287.  
  288.  
  289.  
  290.             }
  291.             catch
  292.             {
  293.                 //add handling here on bad values i.e. in StepOrder fields
  294.             }
  295.  
  296.  
  297.         }
  298.  
  299.  
  300.  
  301.  
  302.  
  303.     }
  304. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement