1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient;
namespace Pfandleihhaus { public partial class Kunden : MaterialSkin.Controls.MaterialForm {
SqlConnection CON = new SqlConnection("Data Source=.;Initial Catalog=myData;Integrated Security=True;Pooling=False"); public Kunden() { InitializeComponent(); anzeigen(); clear(); visual(); }
DataTable DATA;
private void Kunden_Load(object sender, EventArgs e) { }
private void btZurück_Click(object sender, EventArgs e) { this.Hide(); Hauptmenü ht = new Hauptmenü(); ht.ShowDialog(); }
private void anzeigen() { CON.Open(); SqlDataAdapter SDA = new SqlDataAdapter(" SELECT * FROM Kunde", CON); DATA = new DataTable(); SDA.Fill(DATA); dataGridView1.DataSource = DATA; CON.Close();
}
private void clear() {
textBox3.Clear(); textBox4.Clear(); textBox5.Clear(); textBox6.Clear(); textBox7.Clear(); dateTimePicker1.ResetText();
}
private void visual() { dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Arial", 12F, FontStyle.Bold); dataGridView1.EnableHeadersVisualStyles = false; dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.LightYellow; dataGridView1.DefaultCellStyle.Font = new Font("Arial", 12); DataGridViewColumn plz = dataGridView1.Columns[3]; plz.Width = 80; DataGridViewColumn kd = dataGridView1.Columns[0]; kd.Width = 60; DataGridViewColumn nm = dataGridView1.Columns[1]; nm.Width = 180; DataGridViewColumn st = dataGridView1.Columns[2]; st.Width = 180; DataGridViewColumn tel = dataGridView1.Columns[5]; tel.Width = 100; }
private void button1_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { CON.Open(); SqlDataAdapter SDA = new SqlDataAdapter("INSERT INTO Kunde (Name,Straße,Plz,Wohnort,TelNr,Geburtstag)VALUES('" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + dateTimePicker1.Text + "')", CON); SDA.SelectCommand.ExecuteNonQuery(); CON.Close(); MessageBox.Show("Speichern erfolgreich !"); anzeigen(); clear(); } }
private void button2_Click(object sender, EventArgs e)
{ CON.Open(); SqlDataAdapter SDA = new SqlDataAdapter("UPDATE Kunde SET Name = '" + textBox3.Text + "', Straße = '" + textBox4.Text + "', Plz = '" + textBox5.Text + "', Wohnort = '" + textBox6.Text + "',TelNr = '" + textBox7.Text + "', Geburtstag = '" + dateTimePicker1.Text + "'WHERE KdNr ='" + textBox1.Text + "'", CON); SDA.SelectCommand.ExecuteNonQuery(); CON.Close(); MessageBox.Show("Update erfolgreich !"); anzeigen(); clear(); }
private void dataGridView1_MouseClick(object sender, MouseEventArgs e) {
textBox1.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
textBox3.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(); textBox4.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString(); textBox5.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString(); textBox6.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString(); textBox7.Text = dataGridView1.SelectedRows[0].Cells[5].Value.ToString(); dateTimePicker1.Text = dataGridView1.SelectedRows[0].Cells[6].Value.ToString(); }
private void button3_Click(object sender, EventArgs e) { CON.Open(); SqlDataAdapter SDA = new SqlDataAdapter("DELETE FROM Kunde WHERE KdNr ='" + textBox1.Text + "'", CON); SDA.SelectCommand.ExecuteNonQuery(); CON.Close(); MessageBox.Show("GELÖSCHT !"); anzeigen(); clear(); }
private void textBox3_Validating(object sender, CancelEventArgs e) { if (string.IsNullOrEmpty(textBox3.Text)) { e.Cancel = true; errorProvider1.SetError(textBox3, "Bitte füllen !"); } else { e.Cancel = false; errorProvider1.SetError(textBox3, ""); } }
private void textBox4_Validating(object sender, CancelEventArgs e) { if (string.IsNullOrEmpty(textBox4.Text)) { e.Cancel = true; errorProvider1.SetError(textBox4, "Bitte füllen !"); } else { e.Cancel = false; errorProvider1.SetError(textBox4, ""); } }
private void textBox5_Validating(object sender, CancelEventArgs e) { if (string.IsNullOrEmpty(textBox5.Text)) { e.Cancel = true; errorProvider1.SetError(textBox5, "Bitte füllen !"); } else { e.Cancel = false; errorProvider1.SetError(textBox5, ""); } }
private void textBox7_Validating(object sender, CancelEventArgs e) { if (string.IsNullOrEmpty(textBox7.Text)) { e.Cancel = true; errorProvider1.SetError(textBox7, "Bitte füllen !"); } else { e.Cancel = false; errorProvider1.SetError(textBox7, ""); } }
private void dateTimePicker1_Validating(object sender, CancelEventArgs e) { DateTime today = DateTime.Now; DateTime datum = dateTimePicker1.Value; var age = dateTimePicker1.Value.Year;
if (string.IsNullOrEmpty(dateTimePicker1.Text)) { e.Cancel = true; errorProvider1.SetError(dateTimePicker1, "Bitte füllen !"); } else { e.Cancel = false; errorProvider1.SetError(dateTimePicker1, ""); }
if (datum > today) { e.Cancel = true; errorProvider1.SetError(dateTimePicker1, "Datum größer als Heute !"); } else { e.Cancel = false; errorProvider1.SetError(dateTimePicker1, ""); }
if ((dateTimePicker1.Value > DateTime.Today.AddYears(-18))) {
e.Cancel = true; errorProvider1.SetError(dateTimePicker1, "Kunde nicht Volljährig !"); } else { e.Cancel = false; errorProvider1.SetError(dateTimePicker1, ""); }
}
private void textBox3_KeyPress(object sender, KeyPressEventArgs e) {
if (e.Handled = !(Char.IsLetter(e.KeyChar) || e.KeyChar == 8) && !char.IsPunctuation(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar)) { MessageBox.Show("Bitte keine Zahlen eingeben !"); e.KeyChar = (char)0; } }
private void textBox6_Validating(object sender, CancelEventArgs e) { if (string.IsNullOrEmpty(textBox6.Text)) { e.Cancel = true; errorProvider1.SetError(textBox6, "Bitte füllen !"); } else { e.Cancel = false; errorProvider1.SetError(textBox6, ""); } }
private void textBox2_TextChanged(object sender, EventArgs e) { DataView DV = new DataView(DATA); DV.RowFilter = string.Format("Name LIKE '%{0}%'", textBox2.Text); dataGridView1.DataSource = DV; }
private void textBox5_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar < '0' || e.KeyChar > '9') { if (e.KeyChar != (char)8) { MessageBox.Show("Bitte keine Buchstaben eingeben oder Sonderzeichen eingeben!"); e.KeyChar = (char)0; }
} }
private void textBox6_KeyPress(object sender, KeyPressEventArgs e) { if (e.Handled = !(Char.IsLetter(e.KeyChar) || e.KeyChar == 8) && !char.IsPunctuation(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar)) { MessageBox.Show("Bitte keine Zahlen eingeben !"); e.KeyChar = (char)0; } }
private void textBox7_KeyPress(object sender, KeyPressEventArgs e) { if (e.Handled = (Char.IsLetter(e.KeyChar) && !char.IsPunctuation(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar))) { if (e.KeyChar != (char)8) { MessageBox.Show("Bitte keine Buchstaben !"); e.KeyChar = (char)0; } } }
private void Kunden_FormClosing(object sender, FormClosingEventArgs e) { Rechnung rn = new Rechnung(); rn.Refresh(); }
} } |