Advertisement
annstasi

report2

May 28th, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. private void button3_Click(object sender, EventArgs e)
  2. {
  3. string ConnectionString = @"Data Source=192.168.112.103;Initial Catalog=db22204;User ID=User032;Password=User032%$27;Integrated Security=False;MultipleActiveResultSets=True;";
  4. sqlConnection = new SqlConnection(ConnectionString);
  5.  
  6. sqlConnection.Open();
  7. StreamWriter file = new StreamWriter("report2.html");
  8. file.WriteLine("<h1 style='text-align: center;'> Закрытые счета </h1>");
  9. file.WriteLine("<hr></hr>");
  10.  
  11. SqlCommand command1 = new SqlCommand("SELECT txtAccountTypeName, txtAccountNumber, " +
  12. "datAccountBegin, datAccountEnd, " +
  13. "concat(txtClientSurname, ' ', txtClientName, ' ', txtClientSecondName), txtClientAddress " +
  14. "FROM tblClient, tblAccount, tblAccountType " +
  15. "WHERE (tblAccount.intAccountTypeId = tblAccountType.intAccountTypeId) " +
  16. "AND (tblAccount.intClientId = tblClient.intClientId) " +
  17. "AND (tblAccount.datAccountEnd < CURRENT_TIMESTAMP) ORDER BY txtAccountTypeName", sqlConnection);
  18. var reader1 = command1.ExecuteReader();
  19.  
  20. var count = 0;
  21. var totalCount = 0;
  22. int c1 = 0; int c2 = 0; int c3 = 0; int c4 = 0; int c5 = 0;
  23.  
  24. while (reader1.Read())
  25. {
  26. var type = reader1[0].ToString();
  27. if (type == "Дебетовый") c1++;
  28. if (type == "Кредитный") c2++;
  29. if (type == "Депозитный") c3++;
  30. if (type == "Лицевой") c4++;
  31. if (type == "Расчётный") c5++;
  32. totalCount++;
  33. var name1 = reader1[4].ToString();
  34. var client = name1.Split(' ');
  35.  
  36. string open = reader1[2].ToString();
  37. string[] openDate = open.Split(' ');
  38. var date = openDate[0];
  39.  
  40. string close = reader1[3].ToString();
  41. string[] closeDate = close.Split(' ');
  42. var date1 = closeDate[0];
  43. var number = reader1[1].ToString();
  44.  
  45. file.WriteLine("<p><strong>Наименование типа счета:</strong> " + type + "</p>");
  46. file.WriteLine("<p><strong>Номер счета:</strong> " + number + " </p>");
  47. file.WriteLine("<p><strong>Дата открытия счета: </strong>" + date + "</p>");
  48. file.WriteLine("<p><strong>Дата закрытия счета: </strong>" + date1 + "</p>");
  49. file.WriteLine("<p><strong>ФИО клиента:</strong> " + name1 + "</p>");
  50. file.WriteLine("<p><strong>Адрес: </strong>" + reader1[5].ToString() + " </p>");
  51.  
  52. file.WriteLine("<p style='text-align: center;'>Список операций </p>");
  53.  
  54. file.WriteLine("<table align='center' border='1'> " +
  55. " <tr>" +
  56. " <th>Дата проведения</th> " +
  57. " <th>Тип операции</th> " +
  58. " <th>Сумма операции</th>" +
  59. " </tr>");
  60.  
  61. SqlCommand command = new SqlCommand(
  62. "SELECT datOperation, txtOperationTypeName, fltValue FROM tblOperation, tblOperationType, tblAccount " +
  63. "WHERE (tblOperationType.intOperationTypeId = tblOperation.intOperationTypeId)" +
  64. " AND (tblOperation.intAccountId = tblAccount.intAccountId)" +
  65. " AND (txtAccountNumber = @number1) ORDER BY datOperation DESC", sqlConnection);
  66. command.Parameters.AddWithValue("number1", number);
  67. SqlDataReader reader = command.ExecuteReader();
  68.  
  69. while (reader.Read())
  70. {
  71. count++;
  72. string str1 = reader.GetDateTime(0).ToString("dd.MM.yyyy");
  73. string str2 = reader.GetString(1);
  74. var str3 = reader.GetDecimal(2);
  75.  
  76. file.WriteLine("<tr><td> " + str1 + "</td>" +
  77. "<td> " + str2 + "</td>" +
  78. "<td> " + str3 + "</td> " +
  79. "</tr>");
  80. }
  81. reader.Close();
  82.  
  83. file.WriteLine("</table>");
  84. file.WriteLine("<p><strong>Количество операций:</strong> " + count + " </p>");
  85. file.WriteLine("<hr></hr>");
  86. count = 0;
  87. }
  88. reader1.Close();
  89. file.WriteLine("<p><strong>Количество закрытых дебетовых счетов:</strong> " + c1 + " </p>");
  90. file.WriteLine("<p><strong>Количество закрытых кредитных счетов:</strong> " + c2 + " </p>");
  91. file.WriteLine("<p><strong>Количество закрытых депозитных счетов:</strong> " + c3 + " </p>");
  92. file.WriteLine("<p><strong>Количество закрытых лицевых счетов:</strong> " + c4 + " </p>");
  93. file.WriteLine("<p><strong>Количество закрытых расчётных счетов:</strong> " + c5 + " </p>");
  94. file.WriteLine("<p><strong>ОБЩЕЕ КОЛИЧЕСТВО ЗАКРЫТЫХ СЧЕТОВ:</strong> " + totalCount + " </p>");
  95.  
  96. file.Close();
  97. Process.Start(@"report2.html");
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement