using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml; using XmlHelpers; public partial class goalsheet_goalsheetExplorer : System.Web.UI.Page { private void populateXmlForm(int numberOfExtraFields) { XmlDocument doc = new XmlDocument(); string loadXmlDirectory = Server.MapPath("xmlGoalsheets/83_1.xml"); try { doc.Load(loadXmlDirectory); } catch (Exception ex) { throw ex; } // init nodelists for iterations doc.Load(loadXmlDirectory); XmlNodeList nodeListHeader = doc.SelectNodes("goalsheet/header"); XmlNodeList nodeListGoalInfo = doc.SelectNodes("goalsheet/goals/goal"); XmlNodeList nodeListGoalCount = doc.SelectNodes("goalsheet/goals"); //counters used in iterations int TitlesCounter = 0; //label index for new goalsheets int goalTitleIndex = -1; int GoalDescriptionCounter = 0; //counter to name goaldescription textboxes //array used to store goal titles string[] goalTitles; goalTitles = new string[nodeListGoalInfo.Count]; //string used to store the current goal title so it only displays once string currentGoalTitle; //initial setup of header node (no loops -easy) foreach (XmlNode node in nodeListHeader) { txtCourseTitle.Text += node.SelectSingleNode("title").InnerText; txtDescription.Text += node.SelectSingleNode("description").InnerText; txtPrerequisites.Text += node.SelectSingleNode("prerequisites").InnerText; txtLevelId.Text += node.SelectSingleNode("levelid").InnerText; } //add the blank textboxe for new goal input //I left this programmatic in case multiple boxes ever need to be added. TextBox txtTitleNew = new TextBox(); PlaceHolderAddNewGoal.Controls.Add(new LiteralControl("
")); PlaceHolderAddNewGoal.Controls.Add(new LiteralControl("TITLE:
")); txtTitleNew.ID = "txtTitleNew"; txtTitleNew.Width = 400; PlaceHolderAddNewGoal.Controls.Add(txtTitleNew); PlaceHolderAddNewGoal.Controls.Add(new LiteralControl("
")); //TitlesCounter++; PlaceHolderAddNewGoal.Controls.Add(new LiteralControl("GOAL DESCRIPTION:
")); TextBox txtGoalDescriptionNew = new TextBox(); txtGoalDescriptionNew.ID = "txtGoalDescriptionNew"; txtGoalDescriptionNew.Height = 50; txtGoalDescriptionNew.Width = 400; PlaceHolderAddNewGoal.Controls.Add(txtGoalDescriptionNew); PlaceHolderAddNewGoal.Controls.Add(new LiteralControl("
")); //GoalDescriptionCounter++; PlaceHolderAddNewGoal.Controls.Add(new LiteralControl("
")); //populate array of goaltitles for (int i = 0; i < nodeListGoalInfo.Count; i++) { goalTitles[i] = nodeListGoalInfo[i].SelectSingleNode("goaltitle").InnerText; } foreach (XmlNode node2 in nodeListGoalInfo) { //increment the title counter goalTitleIndex++; string boxText = ""; TextBox txtTitles = new TextBox(); TitlesCounter++; txtTitles.Text = goalTitles[goalTitleIndex]; //use the goaltitle array to display the goal title txtTitles.ID = "txtTitles" + Convert.ToString(TitlesCounter); txtTitles.CssClass = "goalsheetEditTitle"; txtTitles.Width = 400; PlaceHolderListGoals.Controls.Add(new LiteralControl("TITLE:
")); PlaceHolderListGoals.Controls.Add(txtTitles); PlaceHolderListGoals.Controls.Add(new LiteralControl("
")); PlaceHolderListGoals.Controls.Add(new LiteralControl("GOAL DESCRIPTION:
")); //iterate through all the nodes using the length of the unique amount of goal titles in the goalTitle array //starts at "1" to skip the title (which is "0") for (int x = 1; x < nodeListGoalInfo[goalTitleIndex].ChildNodes.Count; x++) { currentGoalTitle = nodeListGoalInfo[goalTitleIndex].SelectSingleNode("goaltitle").InnerText; //comparison to make sure only one goal is displayed if (currentGoalTitle == goalTitles[goalTitleIndex]) { //returns the child of "/goal" using index "x" boxText = boxText + "\n" + node2.ChildNodes[x].InnerText; } } //ALLAIN: GoalDescriptionCounter++; TextBox txtGoalDescription = new TextBox(); txtGoalDescription.Text = boxText; txtGoalDescription.ID = "txtGoalDescription" + Convert.ToString(GoalDescriptionCounter); txtGoalDescription.CssClass = "goalsheetEditDescription"; txtGoalDescription.TextMode = TextBoxMode.MultiLine; txtGoalDescription.AutoPostBack = false; txtGoalDescription.Height = 150; txtGoalDescription.Width = 600; PlaceHolderListGoals.Controls.Add(txtGoalDescription); PlaceHolderListGoals.Controls.Add(new LiteralControl("
")); } } private void saveXmlForm() { xmlHelper xmlHelper = new xmlHelper(); ContentPlaceHolder C = (ContentPlaceHolder)this.Page.Master.FindControl("ContentPlaceHolder1"); ContentPlaceHolder c = (ContentPlaceHolder)C; PlaceHolder PlaceHolderAddNewGoal = (PlaceHolder)C.FindControl("PlaceHolderAddNewGoal"); // Control txtTitlesFound = c.FindControl("txtTitles" + Convert.ToString(i)); XmlDocument doc = new XmlDocument(); string loadXmlDirectory = Server.MapPath("xmlGoalsheets/83_1.xml"); try { doc.Load(loadXmlDirectory); } catch (Exception ex) { throw ex; } XmlNodeList nodeListGoalInfo = doc.SelectNodes("goalsheet/goals/goal"); string[] goalTitlesAndDescription; //"+2" to make room for the extra add goal fields and the unused "0" array element goalTitlesAndDescription = new string[nodeListGoalInfo.Count+2]; int goalCounter =0; for (int i = 1; i <= nodeListGoalInfo.Count; i++) { TextBox txtTitleFound = (TextBox)c.FindControl("txtTitles" + Convert.ToString(i)); TextBox txtDescriptionFound = (TextBox)c.FindControl("txtGoalDescription" + Convert.ToString(i)); string fixedDescription = txtDescriptionFound.Text.Replace("\n", ","); goalTitlesAndDescription[i] = txtTitleFound.Text + "=>" + fixedDescription; goalCounter++; Response.Write(goalTitlesAndDescription[i] + "

"); //txtTitlesFound = c.FindControl("txtTitles" + Convert.ToString(i)); } goalCounter++; TextBox txtTitleNewFound = (TextBox)c.FindControl("txtTitleNew"); TextBox txtGoalDescriptionNewFound = (TextBox)c.FindControl("txtGoalDescriptionNew"); string fixedNewDescription = txtGoalDescriptionNewFound.Text.Replace("\n", ","); goalTitlesAndDescription[goalCounter] = txtTitleNewFound.Text + "=>" + fixedNewDescription; Response.Write(goalTitlesAndDescription[goalCounter]); for (int i = 0; i < nodeListGoalInfo.Count + 1; i++) { //Response.Write(goalTitles[i]); } } protected void Page_Load(object sender, EventArgs e) { populateXmlForm(0); } protected void cmdAddGoal_Click(object sender, EventArgs e) { } protected void cmdEditGoalsheetSave_Click(object sender, EventArgs e) { saveXmlForm(); } }