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 proba { public partial class SummaSaleDay : Form { DataBase dataBase = new DataBase(); public SummaSaleDay() { InitializeComponent(); } private void button_back_Click(object sender, EventArgs e) { this.Hide(); Form2 form2 = new Form2(); form2.ShowDialog(); } private void button1_Click(object sender, EventArgs e) { dataBase.openConnection(); double[] summa = new double[0]; SqlCommand command = new SqlCommand($"SELECT summa From Sales WHERE date_sale = '{text_day.Text}'", dataBase.GetConnection()); SqlDataReader reader = command.ExecuteReader(); int i = 0; while (reader.Read()) { Array.Resize(ref summa, summa.Length + 1); summa[i] = Convert.ToDouble(reader[0]); i++; } text_summa.Text = Convert.ToString(GetSumma(summa)); text_summa.ForeColor = Color.Black; dataBase.closeConnection(); } public static double GetSumma(double[] massive) { double summa = 0; for(int i = 0; i < massive.Length; i++) { summa += massive[i]; } return summa; } private void text_day_Enter(object sender, EventArgs e) { if (text_day.ForeColor == Color.Gray) { text_day.Text = null; text_day.ForeColor = Color.Black; } } private void text_day_Leave(object sender, EventArgs e) { if(text_day.Text == "") { text_day.Text = "1 мая 2022"; text_day.ForeColor = Color.Gray; } } private void SummaSaleDay_Load(object sender, EventArgs e) { text_day.Text = "1 мая 2022"; text_day.ForeColor = Color.Gray; text_summa.Text = "Не редактируется"; text_summa.ForeColor = Color.Gray; } public void global_FormClosed(object sender, EventArgs e) { Application.Exit(); } } }