Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Main : MetroForm
- {
- public Main()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- // TODO: данная строка кода позволяет загрузить данные в таблицу "comp1DataSet.Sales". При необходимости она может быть перемещена или удалена.
- this.salesTableAdapter.Fill(this.comp1DataSet.Sales);
- // TODO: данная строка кода позволяет загрузить данные в таблицу "comp1DataSet.Categories". При необходимости она может быть перемещена или удалена.
- this.categoriesTableAdapter.Fill(this.comp1DataSet.Categories);
- // TODO: данная строка кода позволяет загрузить данные в таблицу "comp1DataSet.Computers". При необходимости она может быть перемещена или удалена.
- this.computersTableAdapter.Fill(this.comp1DataSet.Computers);
- fillProducts();
- countRow("Computers");
- }
- private void fillProducts()
- {
- string query = @"SELECT Computers.*, Categories.Name AS Name
- FROM Categories INNER JOIN Computers ON Categories.[Id] = Computers.[Id_category]";
- fillDataGridViewFromQuery(query);
- }
- private void countRow(string nameTable)
- {
- try
- {
- string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=comp1.mdb";
- OleDbConnection con = new OleDbConnection(connectionString);
- OleDbCommand com = con.CreateCommand();
- com.CommandText = "SELECT count(*) FROM " + nameTable;
- con.Open();
- int n = Convert.ToInt32(com.ExecuteScalar());
- tsslCountRows.Text = "Количество записей в таблице: " + Convert.ToString(n);
- con.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- }
- private void toolStripMenuItem1_Click(object sender, EventArgs e)
- {
- }
- private void toolStripTextBox1_Click(object sender, EventArgs e)
- {
- }
- private void Form1_FormClosed(object sender, FormClosedEventArgs e)
- {
- Application.Exit();
- }
- private void metroTabControl1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (metroTabControl1.SelectedIndex == 0)
- {
- countRow("Computers");
- }
- else if (metroTabControl1.SelectedIndex == 1)
- {
- countRow("categories");
- }
- else
- {
- countRow("Sales");
- }
- }
- private void metroButton1_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < dataGridView1.RowCount; i++)
- {
- dataGridView1.Rows[i].Selected = false;
- for (int j = 0; j < dataGridView1.ColumnCount; j++)
- if (dataGridView1.Rows[i].Cells[j].Value != null)
- {
- if (metrotextBox1.Text != " " || metrotextBox1.Text != String.Empty)
- {
- if (dataGridView1.Rows[i].Cells[j].Value.ToString().ToLower().Contains(metrotextBox1.Text.ToLower()))
- {
- if (!dataGridView1.Rows[i].Visible)
- {
- dataGridView1.Rows[i].Visible = true;
- }
- dataGridView1.Rows[i].Selected = true;
- break;
- }
- }
- }
- }
- for (int i = 0; i < dataGridView1.RowCount; i++)
- {
- if (dataGridView1.Rows[i].Selected != true)
- {
- dataGridView1.CurrentCell = null;
- if (dataGridView1.Rows[i].Cells[0].Value != null)
- {
- dataGridView1.Rows[i].Visible = false;
- }
- }
- }
- }
- private void metroButton4_Click(object sender, EventArgs e)
- {
- fillProducts();
- }
- private void toolStripButton1_Click(object sender, EventArgs e)
- {
- addcomp ac = new addcomp("Add");
- ac.ShowDialog();
- fillProducts();
- }
- private void metrotextBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void metrotextBox1_KeyPress(object sender, KeyPressEventArgs e)
- {
- }
- private void fillDataGridViewFromQuery(string query)
- {
- try
- {
- OleDbConnection sqlconn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=comp1.mdb");
- sqlconn.Open();
- OleDbDataAdapter oda = new OleDbDataAdapter(query, sqlconn);
- DataTable dt = new DataTable();
- oda.Fill(dt);
- dataGridView1.DataSource = dt;
- sqlconn.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void toolStripButton2_Click(object sender, EventArgs e)
- {
- try
- {
- OleDbConnection sqlconn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=comp1.mdb");
- sqlconn.Open();
- string query = "DELETE FROM Computers WHERE Id = " + dataGridView1.CurrentRow.Cells[0].Value.ToString() + ";";
- OleDbDataAdapter oda = new OleDbDataAdapter(query, sqlconn);
- DataTable dt = new DataTable();
- oda.Fill(dt);
- sqlconn.Close();
- fillProducts();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void metroButton2_Click(object sender, EventArgs e)
- {
- fillProducts();
- }
- private void toolStripButton4_Click(object sender, EventArgs e)
- {
- addcomp ap = new addcomp(dataGridView1.CurrentRow.Cells[0].Value.ToString(),
- dataGridView1.CurrentRow.Cells[1].Value.ToString(),
- dataGridView1.CurrentRow.Cells[2].Value.ToString(),
- dataGridView1.CurrentRow.Cells[3].Value.ToString(),
- dataGridView1.CurrentRow.Cells[4].Value.ToString(),
- dataGridView1.CurrentRow.Cells[5].Value.ToString(),
- dataGridView1.CurrentRow.Cells[6].Value.ToString(),
- dataGridView1.CurrentRow.Cells[7].Value.ToString(),
- dataGridView1.CurrentRow.Cells[8].Value.ToString(),
- dataGridView1.CurrentRow.Cells[9].Value.ToString(),
- "Edit");
- ap.ShowDialog();
- fillProducts();
- }
- private void выходToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- }
- private void отчетыToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Report rp = new Report();
- rp.ShowDialog();
- }
- private void toolStripButton3_Click(object sender, EventArgs e)
- {
- Basket b = new Basket(dataGridView1.CurrentRow.Cells[0].Value.ToString(),
- dataGridView1.CurrentRow.Cells[1].Value.ToString(),
- dataGridView1.CurrentRow.Cells[2].Value.ToString(),
- dataGridView1.CurrentRow.Cells[3].Value.ToString());
- b.ShowDialog();
- }
- private void Main_FormClosing(object sender, FormClosingEventArgs e)
- {
- this.categoriesTableAdapter.Update(this.comp1DataSet.Categories);
- }
- }
- public partial class addcomp : MetroForm
- {
- string idComputer, model, processor, videocard, hdd, memory, price, description, quantity, category, operation;
- private void bindingSource1_CurrentChanged(object sender, EventArgs e)
- {
- }
- public addcomp(string operation)
- {
- InitializeComponent();
- this.operation = operation;
- }
- public addcomp(string idComputer, string model, string processor, string videocard, string hdd, string memory, string price, string description, string quantity, string category, string operation)
- {
- InitializeComponent();
- this.category = category;
- this.model = model;
- this.processor = processor;
- this.videocard = videocard;
- this.hdd = hdd;
- this.memory = memory;
- this.price = price;
- this.description = description;
- this.quantity = quantity;
- this.operation = operation;
- }
- private void metroTextBox7_Click(object sender, EventArgs e)
- {
- }
- private void metroLabel7_Click(object sender, EventArgs e)
- {
- }
- private void metroButton3_Click(object sender, EventArgs e)
- {
- metroTextBox1.Text = " ";
- metroTextBox2.Text = " ";
- metroTextBox3.Text = " ";
- metroTextBox4.Text = " ";
- metroTextBox5.Text = " ";
- metroTextBox6.Text = " ";
- metroTextBox7.Text = " ";
- metroTextBox8.Text = " ";
- metroTextBox1.Focus();
- }
- private void addcomp_Load(object sender, EventArgs e)
- {
- // TODO: данная строка кода позволяет загрузить данные в таблицу "comp1DataSet1.Categories". При необходимости она может быть перемещена или удалена.
- this.computersTableAdapter2.Fill(this.comp1DataSet1.Computers);
- this.categoriesTableAdapter.Fill(this.comp1DataSet1.Categories);
- metroTextBox1.Text = model;
- metroTextBox2.Text = processor;
- metroTextBox3.Text = videocard;
- metroTextBox4.Text = hdd;
- metroTextBox5.Text = memory;
- metroTextBox6.Text = price;
- metroTextBox7.Text = description;
- metroTextBox8.Text = quantity;
- metroComboBox1.Text = category;
- if (operation == "Add")
- {
- metroButton1.Text = "Добавить";
- }
- else if (operation == "Edit")
- {
- this.Text = "Изменение товара";
- metroButton1.Text = "Изменить";
- }
- }
- private void metroButton1_Click(object sender, EventArgs e)
- {
- int idCategory;
- if (!Int32.TryParse(metroComboBox1.Text, out idCategory))
- {
- idCategory = Convert.ToInt32(metroComboBox1.SelectedValue);
- }
- else
- {
- MessageBox.Show("Недопустимая категория продукта!");
- return;
- }
- string model;
- if (metroTextBox1.Text != "" && metroTextBox1.Text != null)
- {
- model = metroTextBox1.Text;
- }
- else
- {
- MessageBox.Show("Заполните название продукта!");
- return;
- }
- string processor;
- if (metroTextBox2.Text != "" && metroTextBox2.Text != null)
- {
- processor = metroTextBox2.Text;
- }
- else
- {
- MessageBox.Show("Заполните название продукта!");
- return;
- }
- string videocard;
- if (metroTextBox3.Text != "" && metroTextBox3.Text != null)
- {
- videocard = metroTextBox3.Text;
- }
- else
- {
- MessageBox.Show("Заполните название продукта!");
- return;
- }
- string hdd;
- if (metroTextBox4.Text != "" && metroTextBox4.Text != null)
- {
- hdd = metroTextBox4.Text;
- }
- else
- {
- MessageBox.Show("Заполните название продукта!");
- return;
- }
- string memory;
- if (metroTextBox5.Text != "" && metroTextBox5.Text != null)
- {
- memory = metroTextBox5.Text;
- }
- else
- {
- MessageBox.Show("Заполните название продукта!");
- return;
- }
- int price;
- if (Int32.TryParse(metroTextBox6.Text, out price))
- {
- price = Convert.ToInt32(metroTextBox6.Text);
- }
- else
- {
- MessageBox.Show("Некоректная цена продукта!");
- return;
- }
- int quantity;
- if (Int32.TryParse(metroTextBox8.Text, out price))
- {
- quantity = Convert.ToInt32(metroTextBox8.Text);
- }
- else
- {
- MessageBox.Show("Некоректная цена продукта!");
- return;
- }
- string description;
- if (metroTextBox7.Text != "" && metroTextBox7.Text != null)
- {
- description = metroTextBox5.Text;
- }
- else
- {
- MessageBox.Show("Заполните название продукта!");
- return;
- }
- try
- {
- if (operation == "Add")
- {
- computersTableAdapter2.Insert(Convert.ToInt32(idComputer), model, processor, videocard, hdd, memory, price, description, quantity, idCategory);
- }
- else if (operation == "Edit")
- {
- computersTableAdapter2.Edit(model, processor, videocard, hdd, memory, price, description, quantity, idCategory, Convert.ToInt32(idComputer));
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- this.Close();
- }
- private void metroButton2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- }
Add Comment
Please, Sign In to add comment