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 System.Data.SqlClient;
- namespace bd
- {
- public partial class Form4 : Form
- {
- private SqlConnection sqlConnection = null;
- public Form4(string str, string id2, string str2)
- {
- InitializeComponent();
- textBox1.Text = str;
- textBox2.Text = id2;
- textBox3.Text = str2;
- string ConnectionString = @"Data Source=192.168.112.103;Initial Catalog=db22204;User ID=User032;Password=PASSWORD;Integrated Security=False";
- sqlConnection = new SqlConnection(ConnectionString);
- sqlConnection.Open();
- SqlCommand command2 = new SqlCommand("SELECT txtOperationTypeName From tblOperationType", sqlConnection);
- SqlDataReader reader2 = command2.ExecuteReader();
- var sp2 = new List<string>();
- while (reader2.Read())
- {
- sp2.Add(reader2[0].ToString());
- }
- reader2.Close();
- comboBox1.DataSource = sp2;
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void Form4_Load(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- SqlCommand getIdOperation = new SqlCommand("Select intOperationTypeId FROM tblOperationType WHERE (txtOperationTypeName = '" + comboBox1.Text +"')", sqlConnection);
- var operation = getIdOperation.ExecuteReader();
- var idOperation = 0;
- while (operation.Read())
- {
- idOperation = operation.GetInt32(0);
- }
- operation.Close();
- SqlCommand getIdAccount = new SqlCommand("Select tblAccount.intAccountId FROM tblAccountType, tblAccount WHERE (tblAccount.intAccountTypeId = tblAccountType.intAccountTypeId) and (txtAccountNumber = '" + textBox2.Text + "')", sqlConnection);
- var Account = getIdAccount.ExecuteReader();
- var idAccount = 0;
- while (Account.Read())
- {
- idAccount = Account.GetInt32(0);
- }
- Account.Close();
- SqlCommand command = new SqlCommand("INSERT INTO tblOperation (intOperationTypeId, intAccountId, fltValue, datOperation)" +
- " VALUES (@intOperationTypeId, @intAccountId, @fltValue, @datOperation )", sqlConnection);
- command.Parameters.AddWithValue("intOperationTypeId", idOperation);
- command.Parameters.AddWithValue("intAccountId", idAccount);
- command.Parameters.AddWithValue("fltValue", maskedTextBox1.Text);
- DateTime date = DateTime.Parse(dateTimePicker1.Text);
- command.Parameters.AddWithValue("datOperation", $"{date.Month}/{date.Day}/{date.Year}");
- int UspeshnoeIzmenenie = command.ExecuteNonQuery();
- if (UspeshnoeIzmenenie != 0)
- MessageBox.Show("Изменения внесены", "Изменение записи");
- else MessageBox.Show("Не удалось внести изменения", "Изменение записи");
- this.Close();
- }
- private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement