SummaSaleDay.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. namespace proba
  12. {
  13. public partial class SummaSaleDay : Form
  14. {
  15. DataBase dataBase = new DataBase();
  16. public SummaSaleDay()
  17. {
  18. InitializeComponent();
  19. }
  20. private void button_back_Click(object sender, EventArgs e)
  21. {
  22. this.Hide();
  23. Form2 form2 = new Form2();
  24. form2.ShowDialog();
  25. }
  26. private void button1_Click(object sender, EventArgs e)
  27. {
  28. dataBase.openConnection();
  29. double[] summa = new double[0];
  30. SqlCommand command = new SqlCommand($"SELECT summa From Sales WHERE date_sale = '{text_day.Text}'", dataBase.GetConnection());
  31. SqlDataReader reader = command.ExecuteReader();
  32. int i = 0;
  33. while (reader.Read())
  34. {
  35. Array.Resize(ref summa, summa.Length + 1);
  36. summa[i] = Convert.ToDouble(reader[0]);
  37. i++;
  38. }
  39. text_summa.Text = Convert.ToString(GetSumma(summa));
  40. text_summa.ForeColor = Color.Black;
  41. dataBase.closeConnection();
  42. }
  43. public static double GetSumma(double[] massive)
  44. {
  45. double summa = 0;
  46. for(int i = 0; i < massive.Length; i++)
  47. {
  48. summa += massive[i];
  49. }
  50. return summa;
  51. }
  52. private void text_day_Enter(object sender, EventArgs e)
  53. {
  54. if (text_day.ForeColor == Color.Gray)
  55. {
  56. text_day.Text = null;
  57. text_day.ForeColor = Color.Black;
  58. }
  59. }
  60. private void text_day_Leave(object sender, EventArgs e)
  61. {
  62. if(text_day.Text == "")
  63. {
  64. text_day.Text = "1 мая 2022";
  65. text_day.ForeColor = Color.Gray;
  66. }
  67. }
  68. private void SummaSaleDay_Load(object sender, EventArgs e)
  69. {
  70. text_day.Text = "1 мая 2022";
  71. text_day.ForeColor = Color.Gray;
  72. text_summa.Text = "Не редактируется";
  73. text_summa.ForeColor = Color.Gray;
  74. }
  75. public void global_FormClosed(object sender, EventArgs e)
  76. {
  77. Application.Exit();
  78. }
  79. }
  80. }