private void button1_Click(object sender, EventArgs e) { try { if (textBox1.Text != "" && textBox2.Text != "" && comboBox3.Text != "" && numericUpDown1.Value > 0) { string SqlReqAdd = $"insert into materials (articul, name, count, min_count, organization) values ('{textBox1.Text.Trim()}', '{textBox2.Text.Trim()}', '0', '{numericUpDown1.Value}', (select id from organizations where name = '{comboBox3.Text}'));"; SqlCommand command = new SqlCommand(SqlReqAdd, db.GetConnection()); command.ExecuteNonQuery(); Главная главная = (Главная)this.Owner; главная.Materials(); this.Close(); db.closeConnection(); } else { MessageBox.Show("Не все поля заполнены, пожалуйста заполните все поля"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button1_Click(object sender, EventArgs e) { DB db = new DB(); Главная главная = (Главная)this.Owner; try { if (textBox1.Text != "" && textBox2.Text != "") { db.openConnection(); string MySqlreq = "INSERT INTO organizations (name, phone) VALUES ('" + textBox1.Text + "', '" + textBox2.Text + "');"; SqlCommand command = new SqlCommand(MySqlreq, db.GetConnection()); command.ExecuteNonQuery(); главная.Organizations(); this.Hide(); db.closeConnection(); } else { MessageBox.Show("Не все поля заполнены, пожалуйста заполните все поля"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button1_Click(object sender, EventArgs e) { try { if (comboBox1.Text == "Пришло") { string SqlReqAdd = $"UPDATE records " + $"SET materials = (SELECT id FROM materials where name = '{comboBox2.Text}'), " + $"org_in = (SELECT id FROM organizations where name = '{comboBox3.Text}'), " + $"in_out_count = '{numericUpDown1.Value}' WHERE id = {DataBank.Номер};"; diff = Convert.ToInt32(numericUpDown1.Value); diff -= DataBank.Количество; string SqlReqUpdate = $"UPDATE materials " + $"SET count += {diff} " + $"WHERE name = '{comboBox2.Text}' AND " + $"organization = (SELECT id FROM organizations where name = '{comboBox3.Text}');"; SqlCommand command = new SqlCommand(SqlReqAdd, db.GetConnection()); command.ExecuteNonQuery(); SqlCommand command1 = new SqlCommand(SqlReqUpdate, db.GetConnection()); command1.ExecuteNonQuery(); } if (comboBox1.Text == "Ушло") { string SqlReqAdd = $"UPDATE records " + $"SET materials = (SELECT id FROM materials where name = '{comboBox2.Text}'), " + $"id_users = (SELECT id FROM users where fio = '{comboBox4.Text}'), " + $"dep_to = (SELECT id FROM departments where name = '{comboBox3.Text}'), " + $"in_out_count = '{numericUpDown1.Value}' WHERE id = {DataBank.Номер};"; diff = Convert.ToInt32(numericUpDown1.Value); diff -= DataBank.Количество; string SqlReqUpdate = $"UPDATE materials " + $"SET count -= {diff} " + $"WHERE name = '{comboBox2.Text}';"; SqlCommand command = new SqlCommand(SqlReqAdd, db.GetConnection()); command.ExecuteNonQuery(); SqlCommand command1 = new SqlCommand(SqlReqUpdate, db.GetConnection()); command1.ExecuteNonQuery(); } db.closeConnection(); Главная главная = (Главная)this.Owner; главная.Records(); главная.Materials(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button1_Click(object sender, EventArgs e) { try { if (TextLogin.Text != "" && TextPass.Text != "") { string login = TextLogin.Text.Trim(); string pass = TextPass.Text.Trim(); string Sqlreq = "SELECT id FROM users WHERE fio = '" + login + "' AND password = ('" + pass + "');"; db.openConnection(); SqlCommand command = new SqlCommand(Sqlreq, db.GetConnection()); int id = 0; id = Convert.ToInt32(command.ExecuteScalar()); if (id != 0) { Главная главная = new Главная { Owner = this }; TextLogin.Text = ""; TextPass.Text = ""; db.closeConnection(); главная.Show(); this.Hide(); } else { MessageBox.Show("Логин и/или пароль введены не правильно"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button1_Click(object sender, EventArgs e) { try { if (comboBox1.Text != "" && comboBox2.Text != "" && comboBox3.Text != "" && numericUpDown1.Value > 0) { if (comboBox1.Text == "Пришло") { string SqlReqAdd = "insert into records " + "(materials, org_in, date_time, in_out_count, in_out) " + "values (" + "(SELECT id FROM materials where name = '" + comboBox2.Text + "'), " + "(SELECT id FROM organizations where name = '" + comboBox3.Text + "'), " + "GETDATE(), '" + numericUpDown1.Value + "', 'Пришло');"; diff = Convert.ToInt32(numericUpDown1.Value); string SqlReqUpdate = "UPDATE materials " + $"SET count = count + {diff} " + $"WHERE name = '{comboBox2.Text}' AND " + $"organization = (SELECT id FROM organizations where name = '{comboBox3.Text}');"; SqlCommand command = new SqlCommand(SqlReqAdd, db.GetConnection()); command.ExecuteNonQuery(); SqlCommand command1 = new SqlCommand(SqlReqUpdate, db.GetConnection()); command1.ExecuteNonQuery(); } if (comboBox1.Text == "Ушло") { diff = Convert.ToInt32(numericUpDown1.Value); int tmp = 0; string req = $"select count from materials where name = '{comboBox2.Text}'"; SqlCommand command = new SqlCommand(req, db.GetConnection()); tmp = Convert.ToInt32(command.ExecuteScalar()); if (numericUpDown1.Value <= tmp) { string SqlReqAdd = "insert into records " + "(materials, id_users, dep_to, date_time, in_out_count, in_out) " + "values (" + "(SELECT id FROM materials where name = '" + comboBox2.Text + "'), " + "(SELECT id FROM users WHERE fio = '" + comboBox4.Text + "'), " + "(SELECT id FROM departments where name = '" + comboBox3.Text + "'), " + "GETDATE(), '" + numericUpDown1.Value + "', 'Ушло');"; string SqlReqUpdate = "UPDATE materials " + $"SET count -= {diff} " + $"WHERE name = '{comboBox2.Text}' AND " + $"organization = (SELECT id FROM departments where name = '{comboBox3.Text}');"; SqlCommand command1 = new SqlCommand(SqlReqAdd, db.GetConnection()); command1.ExecuteNonQuery(); SqlCommand command2 = new SqlCommand(SqlReqUpdate, db.GetConnection()); command2.ExecuteNonQuery(); } else { MessageBox.Show("Вы пытаетесь затребовать со склада больше, чем есть на данный момент!"); } } } else { MessageBox.Show("Не все поля заполнены, пожалуйста заполните все поля"); } db.closeConnection(); Главная главная = (Главная)this.Owner; главная.Records(); главная.Materials(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }