Advertisement
annstasi

9

May 9th, 2021
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11.  
  12. namespace bd
  13. {
  14. public partial class Form4 : Form
  15. {
  16. private SqlConnection sqlConnection = null;
  17. public Form4(string str, string id2, string str2)
  18. {
  19. InitializeComponent();
  20. textBox1.Text = str;
  21. textBox2.Text = id2;
  22. textBox3.Text = str2;
  23. string ConnectionString = @"Data Source=192.168.112.103;Initial Catalog=db22204;User ID=User032;Password=PASSWORD;Integrated Security=False";
  24. sqlConnection = new SqlConnection(ConnectionString);
  25. sqlConnection.Open();
  26.  
  27. SqlCommand command2 = new SqlCommand("SELECT txtOperationTypeName From tblOperationType", sqlConnection);
  28. SqlDataReader reader2 = command2.ExecuteReader();
  29. var sp2 = new List<string>();
  30. while (reader2.Read())
  31. {
  32. sp2.Add(reader2[0].ToString());
  33. }
  34.  
  35. reader2.Close();
  36. comboBox1.DataSource = sp2;
  37.  
  38.  
  39. }
  40.  
  41. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  42. {
  43.  
  44. }
  45.  
  46. private void Form4_Load(object sender, EventArgs e)
  47. {
  48.  
  49. }
  50.  
  51. private void button2_Click(object sender, EventArgs e)
  52. {
  53. this.Close();
  54. }
  55.  
  56. private void button1_Click(object sender, EventArgs e)
  57. {
  58. SqlCommand getIdOperation = new SqlCommand("Select intOperationTypeId FROM tblOperationType WHERE (txtOperationTypeName = '" + comboBox1.Text +"')", sqlConnection);
  59. var operation = getIdOperation.ExecuteReader();
  60. var idOperation = 0;
  61.  
  62. while (operation.Read())
  63. {
  64. idOperation = operation.GetInt32(0);
  65. }
  66. operation.Close();
  67.  
  68. SqlCommand getIdAccount = new SqlCommand("Select tblAccount.intAccountId FROM tblAccountType, tblAccount WHERE (tblAccount.intAccountTypeId = tblAccountType.intAccountTypeId) and (txtAccountNumber = '" + textBox2.Text + "')", sqlConnection);
  69. var Account = getIdAccount.ExecuteReader();
  70. var idAccount = 0;
  71.  
  72. while (Account.Read())
  73. {
  74. idAccount = Account.GetInt32(0);
  75. }
  76. Account.Close();
  77.  
  78. SqlCommand command = new SqlCommand("INSERT INTO tblOperation (intOperationTypeId, intAccountId, fltValue, datOperation)" +
  79. " VALUES (@intOperationTypeId, @intAccountId, @fltValue, @datOperation )", sqlConnection);
  80. command.Parameters.AddWithValue("intOperationTypeId", idOperation);
  81. command.Parameters.AddWithValue("intAccountId", idAccount);
  82. command.Parameters.AddWithValue("fltValue", maskedTextBox1.Text);
  83. DateTime date = DateTime.Parse(dateTimePicker1.Text);
  84. command.Parameters.AddWithValue("datOperation", $"{date.Month}/{date.Day}/{date.Year}");
  85.  
  86. int UspeshnoeIzmenenie = command.ExecuteNonQuery();
  87.  
  88. if (UspeshnoeIzmenenie != 0)
  89. MessageBox.Show("Изменения внесены", "Изменение записи");
  90. else MessageBox.Show("Не удалось внести изменения", "Изменение записи");
  91. this.Close();
  92. }
  93.  
  94. private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
  95. {
  96.  
  97. }
  98.  
  99. private void textBox1_TextChanged(object sender, EventArgs e)
  100. {
  101.  
  102. }
  103. }
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement