/// <summary> /// Creates a new SongForm /// </summary> /// <param name="pc">The project controller</param> /// <param name="user">The user that was logged in</param> public SongForm(IController pc, User user) { // Initialize the class this.currentUser = user; this.projectController = pc; InitializeComponent(); // Set up event handlers for sorting the table and pressing enter in the search text box dataGridView1.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(this.columnHeaders_Click); searchBox.KeyPress += new KeyPressEventHandler(onKeyPress); this.MinimumSize = this.Size; this.MaximumSize = this.Size; // If not logged in as an owner, disable some functionality if (!user.IsOwner) { // Disable the ability to add/delete songs and save/backup the database for a regular user databaseToolStripMenuItem.Visible = false; songLibraryToolStripMenuItem.Visible = false; deleteButton.Visible = false; deleteButton.Enabled = false; // Don't allow regular user to edit fields foreach (DataGridViewColumn d in dataGridView1.Columns) { d.ReadOnly = true; } } else { // Set up event handlers for editing fields dataGridView1.CellBeginEdit += new DataGridViewCellCancelEventHandler(dataGridView1_CellBeginEdit); dataGridView1.CellEndEdit += new DataGridViewCellEventHandler(dataGridView1_CellEndEdit); // Register delete key press while focus is on the table dataGridView1.KeyDown += new KeyEventHandler(dataGridView1_KeyDown); } // Set the default sorting for the table currentSortField = SongFields.Artist; currentSortType = SortType.Ascending; currentSearchString = null; currentSearchField = SongFields.Artist; // Set the search field drop down box to Artist fieldSelectBox.SelectedIndex = 0; // Load the database loadDatabase(); }
/// <summary> /// Loads the users information into the database /// </summary> private void LoadUsersFromFile() { try { using (XmlTextReader xtr = new XmlTextReader(Assembly.GetExecutingAssembly().Location + @"\..\Resources\Users.xml")) { User u = null; string nodeType = "none"; while (xtr.Read()) { switch (xtr.NodeType) { case XmlNodeType.Element: if (xtr.Name == "User") { u = new User(); } nodeType = xtr.Name; break; case XmlNodeType.Text: if (nodeType == "Name") { u.Name = xtr.Value; } else if (nodeType == "Username") { u.Username = xtr.Value; } else if (nodeType == "Password") { u.Password = xtr.Value; } else if (nodeType == "UserType") { u.Type = (UserType)Enum.Parse(typeof(UserType), xtr.Value); } break; case XmlNodeType.EndElement: if (xtr.Name == "User") { this.Users.Add(u); } break; } } } } catch (FileNotFoundException) { throw new FileNotFoundException("The user database could not be found"); } }