/// <summary> /// Will add the three boxes needed for each assignemnt to the form. /// </summary> /// <param name="assignmentsToAdd"></param> private void AddTextBoxes(int assignmentsToAdd) { assignmentsTotal += assignmentsToAdd; Point ongoing; if (false == hasGenerated) { ongoing = assignmentNameLabel.Location; } else { ongoing = assignments[assignments.Count - 1].Location; } yOffset = DEFAULT_Y_OFFSET; for (int i = linesGenerated; i < assignmentsTotal; i++) { AssignmentInput inp = new AssignmentInput(); this.Controls.Add(inp); // inp.Location = ongoing; ongoing.Y += Math.Abs(yOffset); assignments.Add(inp); inp.Location = ongoing; linesGenerated += 1; } hasGenerated = true; }
/// <summary> /// Prompts the user to find and select a file, then opens that file /// and reads the data into a list, which it then assigns to the refferenced list. /// </summary> /// <returns></returns> public void ReadFromFile(ref List <AssignmentInput> list) { OpenFileDialog fileDialogue = new OpenFileDialog(); DialogResult result = fileDialogue.ShowDialog(); if (DialogResult.OK == result) { list = new List <AssignmentInput>(); string file = fileDialogue.FileName; XmlReader reader = XmlReader.Create(file); XmlDocument doc = new XmlDocument(); doc.Load(file); XmlElement root = doc.DocumentElement; XmlNodeList nodes = root.ChildNodes; List <XmlNode> nodeAttrib = new List <XmlNode>(); XmlAttributeCollection xmlAttr; foreach (XmlNode node in nodes) { xmlAttr = node.Attributes; AssignmentInput input = new AssignmentInput(); input.AssignmentName = xmlAttr[0].Value; input.AssignemntGrade = Int32.Parse(xmlAttr[1].Value); input.AssignmentWeight = float.Parse(xmlAttr[2].Value); list.Add(input); } MainProgram.mainFormRef.EditingFileName = file; } }