using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SMS_Archiv
{
public partial class f_Auslesen : Form
{
#region Deklarationen
OleDbConnection database = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + f_Hauptmenue._DatenbankPfad);
OleDbCommand SQLQuery = new OleDbCommand();
private DataTable data = new DataTable();
private OleDbDataAdapter dataAdapter = null;
private DataSet ds = new DataSet();
private BindingSource bs = new BindingSource();
private string _queryString;
#endregion
public f_Auslesen()
{
InitializeComponent();
}
private void f_Auslesen_Load(object sender, EventArgs e)
{
_queryString = "SELECT * FROM SMS ORDER BY SMS_Datum, SMS_Zeit ASC";
loadDataGrid(_queryString);
}
private void b_Close_Click(object sender, EventArgs e)
{
DialogResult result;
result = MessageBox.Show(this, "Sollen alle Änderungen gespeichert werden?", "Schließen/Speichern", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (result == DialogResult.Yes)
{
bs.EndEdit();
dataAdapter.Update(data);
this.Close();
}
else if (result == DialogResult.No)
{
bs.EndEdit();
this.Close();
}
}
private void f_Auslesen_FormClosing(object sender, FormClosingEventArgs e)
{
database.Close();
f_Hauptmenue.Auslesen_Offen = false;
}
#region DataGridView Laden
public void loadDataGrid(string sqlQueryString)
{
DataTable data = null;
dataGridView1.DataSource = null;
SQLQuery.Connection = null;
dataGridView1.Columns.Clear(); // <-- clear columns
//---------------------------------
SQLQuery.CommandText = sqlQueryString;
SQLQuery.Connection = database;
data = new DataTable();
dataAdapter = new OleDbDataAdapter(SQLQuery);
dataAdapter.Fill(data);
OleDbCommandBuilder cb = new OleDbCommandBuilder(dataAdapter);
bs.DataSource = data;
this.dataGridView1.DataSource = bs;
dataGridView1.DataSource = data;
dataGridView1.AllowUserToAddRows = false; // remove the null line
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.ReadOnly = false;
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
dataGridView1.Columns["ID"].Visible = false;
dataGridView1.Columns["SMS_Text"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView1.Columns["SMS_Text"].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.Columns["SMS_Zeit"].DefaultCellStyle.Format = "HH:mm";
dataGridView1.Columns["SMS_Zeit"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;
dataGridView1.Columns["SMS_Datum"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;
dataGridView1.RowHeadersVisible = false;
}
#endregion
}
}