Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 MySql.Data.MySqlClient;
- namespace CodGenerate
- {
- public partial class Form1 : Form
- {
- public void removeTable() {
- tableLayoutPanel1.Controls.Clear();
- strs.Clear();
- }
- private void showTable() {
- string query = "SELECT * FROM `cod` WHERE 1";
- MySqlCommand comand = new MySqlCommand(query, connection);
- comand.ExecuteNonQuery();
- MySqlDataAdapter data = new MySqlDataAdapter(comand);
- DataTable dt = new DataTable();
- data.Fill(dt);
- var myData = dt.Select();
- tableLayoutPanel1.RowCount = myData.Length;
- tableLayoutPanel1.ColumnCount = 4;
- for (int i = 0; i < myData.Length; i++)
- {
- string[] component = new string[myData[i].ItemArray.Length];
- for (int j = 0; j < myData[i].ItemArray.Length; j++)
- {
- Label lb = new Label();
- lb.Text = myData[i].ItemArray[j].ToString();
- component[j] = myData[i].ItemArray[j].ToString();
- tableLayoutPanel1.Controls.Add(lb);
- // lb.SizeChanged
- lb.Dock = DockStyle.Fill;
- lb.BackColor = Color.White;
- }
- Button bt = new Button();
- bt.Click += click;
- strs.Add(component);
- bt.Text = "Сгенерировать карточку";
- bt.Dock = DockStyle.Fill;
- bt.TabIndex = i;
- tableLayoutPanel1.Controls.Add(bt);
- }
- }
- List<string[]> strs = new List<string[]>();
- private MySqlConnection connection = new MySqlConnection("server= localhost;user= root; database=CodGenerate;password=;");
- public Form1()
- {
- InitializeComponent();
- connection.Open();
- removeTable();
- showTable();
- }
- private void click(object sender, EventArgs e)
- {
- Button bt = sender as Button;
- this.Text = bt.TabIndex.ToString();
- Form2 form2 = new Form2(strs.ToArray()[bt.TabIndex]);
- form2.Show();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Form3 form = new Form3(connection, strs.ToArray());
- form.Show();
- form.FormClosing += close;
- }
- private void close(object sender, FormClosingEventArgs e)
- {
- removeTable();
- showTable();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement