Advertisement
annstasi

8

May 9th, 2021
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 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 Form3 : Form
  15. {
  16. private SqlDataAdapter adapter = null;
  17.  
  18. private DataTable table;
  19. public Form3(SqlConnection sqlConnection, int id)
  20. {
  21. // MessageBox.Show(id.ToString());
  22.  
  23.  
  24. InitializeComponent();
  25. sqlConnection.Open();
  26.  
  27. SqlCommand command = new SqlCommand(
  28. "SELECT txtAccountTypeName, concat(txtClientSurname, ' ', txtClientName, ' ', txtClientSecondName), datAccountBegin, datAccountEnd, txtAccountNumber, fltAccountSum" +
  29. " FROM tblClient, tblAccountType, tblAccount WHERE (tblAccountType.intAccountTypeId = tblAccount.intAccountTypeId) AND ( tblClient.intClientId = tblAccount.intClientId) and (tblAccount.intAccountId= " + id + ")", sqlConnection);
  30.  
  31. SqlDataReader rd;
  32. rd = command.ExecuteReader();
  33.  
  34. while (rd.Read())
  35. {
  36. textBox1.Text = rd[0].ToString();
  37. textBox2.Text = rd[1].ToString();
  38. textBox3.Text = DateTime.Parse(rd[2].ToString()).ToShortDateString();
  39. textBox4.Text = DateTime.Parse(rd[3].ToString()).ToShortDateString();
  40. textBox5.Text = rd[4].ToString();
  41. textBox6.Text = rd[5].ToString();
  42. }
  43. rd.Close();
  44.  
  45.  
  46. table = new DataTable();
  47.  
  48. adapter = new SqlDataAdapter("SELECT tblOperation.datOperation as 'Дата проведения операции', tblOperationType.txtOperationTypeName as 'Наименование типа операции', tblOperation.fltValue as 'Сумма' FROM tblOperation, tblOperationType, tblAccount WHERE (tblAccount.intAccountId = tblOperation.intAccountId) and (tblOperation.intOperationTypeId = tblOperationType.intOperationTypeId) and (tblAccount.intAccountId = '" + id + "')", sqlConnection);
  49. adapter.Fill(table);
  50. dataGridView1.DataSource = table;
  51. dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
  52.  
  53. dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  54. dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
  55.  
  56. sqlConnection.Close();
  57.  
  58. }
  59.  
  60. private void Form3_Load(object sender, EventArgs e)
  61. {
  62. }
  63. private void Cancel_Click_1(object sender, EventArgs e)
  64. {
  65. this.Hide();
  66.  
  67. var form = new Form1();
  68. form.ShowDialog();
  69. }
  70.  
  71. private void Add_Click(object sender, EventArgs e)
  72. {
  73. var form = new Form4(textBox2.Text.ToString(), textBox5.Text.ToString(), textBox1.Text.ToString());
  74. form.Show();
  75. }
  76.  
  77. private void button_Click(object sender, EventArgs e)
  78. {
  79.  
  80. table.Clear();
  81.  
  82. adapter.Fill(table);
  83. dataGridView1.DataSource = table;
  84.  
  85.  
  86. }
  87. }
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement