/// <summary> /// Retrieves table from database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LoadTableFromDatabase(object sender, EventArgs e) { using (GetUserServiceClient client = new GetUserServiceClient("NetTcpBinding_IGetUserService")) { DataSet set = client.GetTable(); if (set.DataSetName == "Error") { MessageBox.Show("Client could not connect to database. Server is either unavailable or you are not connected to the internet.", "Connection error"); return; } DataTable table = set.Tables[0]; RefreshDataGridView(MainGridView); MainGridView.DataSource = table; foreach (DataGridViewColumn column in MainGridView.Columns) { column.HeaderText = table.Columns[MainGridView.Columns.IndexOf(column)].Caption; } } ChangedCells.Clear(); BadCells.Clear(); SetButtons(true, true, true); LoadSettings(); Output("Loaded data from database."); }
/// <summary> /// Loads table from XML file. /// </summary> private void LoadFromXML() { if (!File.Exists(XmlPath)) { MainGridView.Rows.Clear(); return; } RefreshDataGridView(MainGridView); using (DataSet set = new DataSet()) { set.ReadXml(XmlPath, XmlReadMode.ReadSchema); MainGridView.DataSource = set.Tables[0]; foreach (DataGridViewColumn column in MainGridView.Columns) { column.HeaderText = set.Tables[0].Columns[MainGridView.Columns.IndexOf(column)].Caption; } } ChangedCells.Clear(); BadCells.Clear(); SetButtons(false, false, true); LoadSettings(); }
/// <summary> /// Sets changed cell's colors to white and clears the list. /// </summary> private void ClearChangedCells() { foreach (DataGridViewCell cell in ChangedCells) { cell.Style.BackColor = Color.Empty; } ChangedCells.Clear(); }
/// <summary> /// Deletes content of given DataGridView. /// </summary> /// <param name="gridView"></param> private void RefreshDataGridView(DataGridView gridView) { gridView.Columns.Clear(); DataTable DT = (DataTable)gridView.DataSource; DT?.Clear(); BadCells.Clear(); ChangedCells.Clear(); gridView.Refresh(); }