Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using PCS2.Classes;
- namespace PCS2.Forms
- {
- public partial class TryOutSteps : System.Web.UI.Page
- {
- DBBuilds myDBBuilds = new DBBuilds();
- UtilFunctions myUtilFunctions = new UtilFunctions();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- //string LocationDesc = (string)Session["LocationDesc"];
- LoadDropDowns(false);
- //if (Request.QueryString["TryOutID"] != null)
- try
- {
- int TryOutID = 1; // Convert.ToInt32(Request.QueryString["TryOutID"]);
- //and display any rows
- bool b = BindList();
- }
- catch(Exception)
- {
- //fill in later
- }
- }
- else
- {
- //later we will have the Process dropdown selections change when the Location is reset. \
- //that's major surgery really. we'll have to reset each process and step value.
- //at this point we're not going to reset the PRocess dropdown without running an update on the entire table TryOutStep.ProcessID values.
- //LoadDropDowns(true);
- }
- }
- private void LoadDropDowns(bool IsPostBack)
- {
- if (IsPostBack == false)
- {
- PopulateProductTypeDropdown();
- PopulateLocation();
- //PopulateProcessDrop(); //default selection
- //PopulateStepType();
- }
- else
- {
- //need to reset processes based on product type
- PopulateProcessListviewDrops();
- }
- }
- //this is called with every postback
- protected void PopulateProcessListviewDrops()
- {
- DropDownList DropDownToFill = (DropDownList)TryOutStepList.InsertItem.FindControl("ProcessDropIns");
- PopulateProcessDrop(DropDownToFill);
- //then our edit item template
- }
- //step type stays static
- protected void PopulateStepTypeListviewDrops()
- {
- DropDownList DropDownToFill = (DropDownList)TryOutStepList.InsertItem.FindControl("StepTypeDropIns");
- PopulateStepType(DropDownToFill);
- }
- protected void PopulateProcessDrop(DropDownList DropDownToFill)
- {
- int index = myUtilFunctions.DropdownFirstOrValidValue(ProductTypesDrop);
- int ProductTypeID = Convert.ToInt32(ProductTypesDrop.Items[index].Value);
- index = myUtilFunctions.DropdownFirstOrValidValue(LocationDrop);
- int LocationID = Convert.ToInt32(LocationDrop.Items[index].Value);
- //DropDownList DropDownToFill = (DropDownList)TryOutStepList.InsertItem.FindControl("ProcessDrop");
- myUtilFunctions.PopulateProcessDropdown(ProductTypeID, LocationID, DropDownToFill);
- }
- protected void PopulateProductTypeDropdown()
- {
- myUtilFunctions.PopulateProductTypeDropdown(ProductTypesDrop);
- }
- protected void PopulateStepType(DropDownList DropDownToFill)
- {
- myUtilFunctions.PopulateStepTypeDropdown(DropDownToFill);
- }
- protected void PopulateLocation()
- {
- myUtilFunctions.PopulateLocationDropdown(LocationDrop);
- }
- protected bool BindList()
- {
- bool result = false;
- int TryOutID = Convert.ToInt32(TryOutText.Text);
- DataTable dt = myDBBuilds.GetTryOutStep(TryOutID, 0);
- //if (dt.Rows.Count > 0) - there will be many times where there's no steps yet associated with a tryout
- try
- {
- TryOutStepList.DataSource = dt; //cmd.ExecuteReader(CommandBehavior.Default);
- TryOutStepList.DataBind();
- //and fill the StepType and Process dropdowns
- PopulateStepTypeListviewDrops();
- PopulateProcessListviewDrops();
- result = true;
- }
- catch (Exception)
- {
- }
- return result;
- }
- protected void TryOutStepList_ItemInserting(object sender, ListViewInsertEventArgs e)
- {
- try
- {
- int ProcessID = 0;
- int StepTypeID = 0;
- int TryOutID = Convert.ToInt32(TryOutText.Text);
- DropDownList DropDownSource = (DropDownList)e.Item.FindControl("ProcessDropIns"); //(TryOutStepList.Items[e.ItemIndex].FindControl("ProcessDropEdit")) as DropDownList;
- if (DropDownSource != null)
- {
- ProcessID = Convert.ToInt32(DropDownSource.SelectedItem.Value);
- }
- DropDownSource = (DropDownList)e.Item.FindControl("StepTypeDropIns"); //(TryOutStepList.Items[e.ItemIndex].FindControl("ProcessDropEdit")) as DropDownList;
- if (DropDownSource != null)
- {
- StepTypeID = Convert.ToInt32(DropDownSource.SelectedItem.Value);
- }
- string Description = ((TextBox)e.Item.FindControl("DescriptionTextIns")).Text;
- int StepOrder = Convert.ToInt32(((TextBox)e.Item.FindControl("StepOrderTextIns")).Text);
- string CreatedBy = Context.User.Identity.Name.ToString();
- int TryOutStepID = myDBBuilds.InsertTryOutStep(TryOutID, StepOrder, CreatedBy, CreatedBy, Description, ProcessID, StepTypeID);
- TryOutStepList.EditIndex = -1;
- BindList();
- ////BELOW does not work
- //ListViewItem item = TryOutStepList.Items[e.Item.DataItemIndex];
- //int ProcessID = Convert.ToInt32(((DropDownList)e.Item.FindControl("ProcessDropIns")).SelectedItem.Value);
- //string Description = ((TextBox)e.Item.FindControl("DescriptionTextIns")).Text;
- //int StepOrder = Convert.ToInt32(((TextBox)e.Item.FindControl("StepOrderTextIns")).Text);
- //int StepTypeID = Convert.ToInt32(((DropDownList)e.Item.FindControl("StepTypeDropIns")).SelectedItem.Value);
- //string CreatedBy = Context.User.Identity.Name.ToString();
- //int TryOutStepID = myDBBuilds.InsertTryOutStep(TryOutID, StepOrder, CreatedBy, CreatedBy, Description, ProcessID, StepTypeID);
- }
- catch
- {
- //add handling here on bad values i.e. in StepOrder fields
- }
- }
- //this is very wasteful and needs to be fixed. We're calling the same database multiple times for the same set.
- //TODO: Will refactor when there's time.
- protected void TryOutStepList_ItemDeleting(object sender, ListViewDeleteEventArgs e)
- {
- int TryOutStepID = Convert.ToInt32(TryOutStepList.DataKeys[e.ItemIndex].Value.ToString());
- myDBBuilds.DeleteTryOutStep(TryOutStepID);
- TryOutStepList.EditIndex = -1;
- BindList();
- }
- protected void TryOutStepList_ItemEditing(object sender, ListViewEditEventArgs e)
- {
- TryOutStepList.EditIndex = e.NewEditIndex;
- //databind here?
- BindList();
- }
- protected void TryOutStepList_ItemCanceling(object sender, ListViewCancelEventArgs e)
- {
- //Message.Text = "error message here";
- e.Cancel = true;
- TryOutStepList.SelectedIndex = -1;
- //redatabind here?
- BindList();
- }
- protected void TryOutStepList_DataBound(object sender, EventArgs e)
- {
- //fill out edit dropdowns
- if (TryOutStepList.EditItem != null)
- {
- DropDownList DropDownToFill = (DropDownList)TryOutStepList.EditItem.FindControl("ProcessDropEdit");
- if (DropDownToFill != null)
- {
- PopulateProcessDrop(DropDownToFill);
- }
- DropDownToFill = (DropDownList)TryOutStepList.EditItem.FindControl("StepTypeDropEdit");
- if (DropDownToFill != null)
- {
- PopulateStepType(DropDownToFill);
- }
- }
- //and now insertion dropdowns
- if (TryOutStepList.InsertItem != null)
- {
- DropDownList DropDownToFill = (DropDownList)TryOutStepList.InsertItem.FindControl("ProcessDropIns");
- if (DropDownToFill != null)
- {
- PopulateProcessDrop(DropDownToFill);
- }
- DropDownToFill = (DropDownList)TryOutStepList.InsertItem.FindControl("StepTypeDropIns");
- if (DropDownToFill != null)
- {
- PopulateStepType(DropDownToFill);
- }
- }
- }
- protected void TryOutStepList_ItemUpdating(object sender, ListViewUpdateEventArgs e)
- {
- try
- {
- int ProcessID = 0;
- int StepTypeID = 0;
- int TryOutID = Convert.ToInt32(TryOutText.Text);
- ListViewItem item = TryOutStepList.Items[e.ItemIndex];
- DropDownList DropDownSource = (DropDownList)item.FindControl("ProcessDropEdit"); //(TryOutStepList.Items[e.ItemIndex].FindControl("ProcessDropEdit")) as DropDownList;
- if (DropDownSource!=null)
- {
- ProcessID = Convert.ToInt32(DropDownSource.SelectedItem.Value);
- }
- DropDownSource = (DropDownList)item.FindControl("StepTypeDropEdit"); //(TryOutStepList.Items[e.ItemIndex].FindControl("ProcessDropEdit")) as DropDownList;
- if (DropDownSource != null)
- {
- StepTypeID = Convert.ToInt32(DropDownSource.SelectedItem.Value);
- }
- int TryOutStepID = Convert.ToInt32(TryOutStepList.DataKeys[e.ItemIndex].Value.ToString());
- string Description = ((TextBox)item.FindControl("DescriptionTextEdit")).Text;
- int StepOrder = Convert.ToInt32(((TextBox)item.FindControl("StepOrderTextEdit")).Text);
- string ModifiedBy = Context.User.Identity.Name.ToString();
- myDBBuilds.UpdateTryOutStep(TryOutStepID, StepOrder, ModifiedBy, Description, ProcessID, StepTypeID);
- TryOutStepList.EditIndex = -1;
- BindList();
- //DropDownList DropDownToFill = (DropDownList)item.FindControl("ProcessDropEdit");
- //ABOVE - todo - replace with master form
- //does this find it? or do we do the item.x method?
- //nope, breaks DropDownList DropDownToFillTEMP = (DropDownList)TryOutStepList.EditItem.FindControl("StepTypeDropEdit");
- //string s = DropDownToFillTEMP.SelectedValue.ToString();
- //ListViewItem item = TryOutStepList.Items[e.NewEditIndex];
- //ProcessID = Convert.ToInt32(((DropDownList)item.FindControl("ProcessDropEdit")).SelectedItem.Value);
- //string Description = ((TextBox)item.FindControl("DescriptionTextEdit")).Text;
- //int StepOrder = Convert.ToInt32(((TextBox)item.FindControl("StepOrderTextEdit")).Text);
- //int StepTypeID = Convert.ToInt32(((DropDownList)item.FindControl("StepTypeDropEdit")).SelectedItem.Value);
- //string ModifiedBy = Context.User.Identity.Name.ToString();
- //myDBBuilds.UpdateTryOutStep(TryOutStepID, StepOrder, ModifiedBy, Description, ProcessID, StepTypeID);
- }
- catch
- {
- //add handling here on bad values i.e. in StepOrder fields
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement