Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void button3_Click(object sender, EventArgs e)
- {
- if (TabelkaGUI.pobierzLiczbeStanow(dataGridView1) == 0)
- {
- MessageBox.Show("Najpierw dodaj stany");
- return;
- }
- string input = String.Empty;
- while (String.IsNullOrEmpty(input))
- {
- try
- {
- input = Interaction.InputBox("Dozwolone symbole a-z0-9 oraz $ (znak pusty)", "Podaj znak", String.Empty, (Int32.Parse(screenWidth) / 2) - 150, (Int32.Parse(screenHeight) / 2) - 100);
- if (input == String.Empty) break;
- char c = Char.Parse(input);
- if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '$')
- {
- if (!TabelkaGUI.czyIstniejeRzad(dataGridView1, input)) TabelkaGUI.dodajRzad(dataGridView1, input);
- else MessageBox.Show("Taki znak już istnieje!");
- }
- else
- {
- MessageBox.Show("Niedozwolony symbol!");
- }
- }
- catch (FormatException)
- {
- MessageBox.Show("Możesz podać pojedyńczy symbol!");
- }
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- TabelkaGUI.dodajKolumne(dataGridView1, "q" + (TabelkaGUI.pobierzLiczbeStanow(dataGridView1)).ToString());
- }
- private void button5_Click(object sender, EventArgs e)
- {
- try
- {
- TabelkaGUI.usunOstatniRzad(dataGridView1);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void button6_Click(object sender, EventArgs e)
- {
- try
- {
- TabelkaGUI.usunOstatniaKolumne(dataGridView1);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- =============================================================================
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Diagnostics;
- namespace AutomatZeStosem
- {
- static class TabelkaGUI
- {
- public static void dodajRzad(DataGridView tabelka, string nazwaRzedu)
- {
- if (tabelka.ColumnCount == 0) throw new Exception("Najpierw dodaj kolumny!");
- DataGridViewRow rzad = new DataGridViewRow();
- rzad.HeaderCell.Value = nazwaRzedu;
- tabelka.Rows.Add(rzad);
- }
- public static void dodajKolumne(DataGridView tabelka, string nazwaKolumny)
- {
- tabelka.Columns.Add(nazwaKolumny, nazwaKolumny);
- }
- public static void usunOstatniRzad(DataGridView tabelka)
- {
- int liczbaRzedow = tabelka.Rows.Count;
- liczbaRzedow -= 2;
- if (liczbaRzedow < 0) throw new Exception("Brak rzędów!");
- tabelka.Rows.RemoveAt(tabelka.Rows[liczbaRzedow].Index);
- }
- public static void usunOstatniaKolumne(DataGridView tabelka)
- {
- int liczbaKolumn = tabelka.Columns.Count;
- liczbaKolumn -= 1;
- if (liczbaKolumn < 0) throw new Exception("Brak kolumn!");
- tabelka.Columns.RemoveAt(tabelka.Columns[liczbaKolumn].Index);
- }
- public static void zaznaczKomorke(DataGridView tabelka, int x, int y)
- {
- try
- {
- tabelka.CurrentCell = tabelka[x, y];
- }
- catch (ArgumentOutOfRangeException e)
- {
- throw new ArgumentOutOfRangeException("x = " + x.ToString() + ", y = " + y.ToString(), e);
- }
- }
- public static void wpiszTekst(DataGridView tabelka, int x, int y, string tekst)
- {
- try
- {
- tabelka[x, y].Value = tekst;
- }
- catch (ArgumentOutOfRangeException e)
- {
- throw new ArgumentOutOfRangeException("x = " + x.ToString() + ", y = " + y.ToString(), e);
- }
- }
- public static bool czyIstniejeRzad(DataGridView tabelka, string nazwaRzedu)
- {
- foreach (DataGridViewRow rzad in tabelka.Rows)
- {
- if (rzad.HeaderCell.Value == null) continue;
- if (rzad.HeaderCell.Value.ToString() == nazwaRzedu) return true;
- }
- return false;
- }
- public static bool czyIstniejeKolumna(DataGridView tabelka, string nazwaKolumny)
- {
- foreach (DataGridViewRow rzad in tabelka.Rows)
- {
- if (rzad.HeaderCell.Value.ToString() == nazwaKolumny) return true;
- }
- return false;
- }
- public static int pobierzLiczbeStanow(DataGridView tabelka)
- {
- return tabelka.Columns.Count;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement