Ejemplo n.º 1
0
 private void Form9_Load(object sender, EventArgs e)
 {
     try
     {
         string v = cm.GetCurrentMethod();
         logger.Info(v);
         if (Program.fotoUser == false)
         {
             con = new SqlConnection(connectionString);
             con.Open();
             string     vyUserSelect = "SELECT FotoOfDriverLicense FROM Photos Where idUser ='******'";
             SqlCommand vyUser       = new SqlCommand(vyUserSelect, con);
             String     vyUserString = (String)(vyUser).ExecuteScalar();
             pictureBox1.Image = Image.FromFile(vyUserString);
             con.Close();
         }
         if (Program.fotoUser == true)
         {
             con = new SqlConnection(connectionString);
             con.Open();
             string     vyUserSelect = "SELECT FotoOfPassport FROM Photos Where idUser ='******'";
             SqlCommand vyUser       = new SqlCommand(vyUserSelect, con);
             String     vyUserString = (String)(vyUser).ExecuteScalar();
             pictureBox1.Image = Image.FromFile(vyUserString);
             con.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         string method = cm.GetCurrentMethod();
         logger.Error(ex.ToString() + method);
     }
 }
Ejemplo n.º 2
0
        private void GetData(string selectCommand)
        {
            try
            {
                string v = cm.GetCurrentMethod();
                logger.Info(v);
                dataGridView1.AutoGenerateColumns = true;
                dataAdapter = new SqlDataAdapter(selectCommand, connectionString);

                // Create a command builder to generate SQL update, insert, and
                // delete commands based on selectCommand.
                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

                // Populate a new data table and bind it to the BindingSource.
                DataTable table = new DataTable
                {
                    Locale = CultureInfo.InvariantCulture
                };
                dataAdapter.Fill(table);
                bindingSource1.DataSource = table;

                // Resize the DataGridView columns to fit the newly loaded content.
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                string method = cm.GetCurrentMethod();
                logger.Error(ex.ToString() + method);
            }
        }
Ejemplo n.º 3
0
        private void Form2_Load(object sender, EventArgs e)
        {
            bool isRole = IsRunAsAdmin();

            if (isRole is false)
            {
                MessageBox.Show("В процессе работы данного приложения происходит чтение и запись файлов.\r Для корректной работы, пожалуйста запустите программу от имени администратора.\r Приложение будет закрыто.", "Не обнаружены права администратора", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Application.Exit();
            }
            string v = cm.GetCurrentMethod();

            logger.Info(v);
            textBox1.Text = System.Net.Dns.GetHostName() + "\\SQLEXPRESS;";

            textBox2.Text = "Diplom";
        }
Ejemplo n.º 4
0
        private void label4_Click(object sender, EventArgs e)
        {
            string v = cm.GetCurrentMethod();

            logger.Info(v);
            this.Size = new Size(0, 0);
            this.CenterToScreen();
            f4 = new Form4();
            f4.ShowDialog();
            this.Size = new Size(770, 415);
            this.CenterToScreen();
        }
Ejemplo n.º 5
0
        private void Form19_Load(object sender, EventArgs e)
        {
            try
            {
                string v = cm.GetCurrentMethod();
                logger.Info(v);
                con = new SqlConnection(connectionString);
                con.Open();
                string     idUserSelect = "SELECT idUser FROM Poezdka Where idPoezdki = '" + Program.getIdTrip + " '";
                SqlCommand idUser       = new SqlCommand(idUserSelect, con);
                Int32      idUserInt    = (Int32)(idUser).ExecuteScalar();

                string     fioUserSelect = "SELECT Fio  FROM Polzovatel Where IdUser = '******'";
                SqlCommand fioUser       = new SqlCommand(fioUserSelect, con);
                String     fioUserString = (String)(fioUser).ExecuteScalar();
                label3.Text = fioUserString;

                string     timeOfStartSelect = "SELECT TimeOfStart  FROM Poezdka Where idPoezdki = '" + Program.getIdTrip + " '";
                SqlCommand timeOfStart       = new SqlCommand(timeOfStartSelect, con);
                DateTime   timeOfStartString = (DateTime)(timeOfStart).ExecuteScalar();
                label4.Text = timeOfStartString.ToString();

                string     timeOfEndSelect = "SELECT TimeOfEnd  FROM Poezdka Where idPoezdki = '" + Program.getIdTrip + " '";
                SqlCommand timeOfEnd       = new SqlCommand(timeOfEndSelect, con);
                DateTime   timeOfEndString = (DateTime)(timeOfEnd).ExecuteScalar();
                label6.Text = timeOfEndString.ToString();

                string     timeOfTripSelect = "SELECT Dlitelnost  FROM Poezdka Where idPoezdki = '" + Program.getIdTrip + " '";
                SqlCommand timeOfTrip       = new SqlCommand(timeOfTripSelect, con);
                Int32      timeOfTripInt    = (Int32)(timeOfTrip).ExecuteScalar();
                var        ts = TimeSpan.FromMinutes(Convert.ToDouble(timeOfTripInt));
                label8.Text = String.Format("{0} д. {1} ч. {2} м. ", ts.Days, ts.Hours, ts.Minutes);

                string     costOfTripSelect = "SELECT Stoim  FROM Poezdka Where idPoezdki = '" + Program.getIdTrip + " '";
                SqlCommand costOfTrip       = new SqlCommand(costOfTripSelect, con);
                Int32      costOfTripInt    = (Int32)(costOfTrip).ExecuteScalar();
                label10.Text = Convert.ToString(costOfTripInt) + " р.";

                string     idAvtoSelect = "SELECT idAvto FROM Poezdka Where idPoezdki = '" + Program.getIdTrip + " '";
                SqlCommand idAvto       = new SqlCommand(idAvtoSelect, con);
                Int32      idAvtoInt    = (Int32)(idAvto).ExecuteScalar();

                string     markaAvtoSelect = "SELECT Marka  FROM Avto Where idAvto = '" + idAvtoInt + " '";
                SqlCommand markaAvto       = new SqlCommand(markaAvtoSelect, con);
                String     markaAvtoString = (String)(markaAvto).ExecuteScalar();

                string     nameAvtoSelect = "SELECT Nazvanie  FROM Avto Where idAvto = '" + idAvtoInt + " '";
                SqlCommand nameAvto       = new SqlCommand(nameAvtoSelect, con);
                String     nameAvtoString = (String)(nameAvto).ExecuteScalar();
                label12.Text = markaAvtoString + " " + nameAvtoString;

                string     idTarifSelect = "SELECT idTarifa FROM Poezdka Where idPoezdki = '" + Program.getIdTrip + " '";
                SqlCommand idTarif       = new SqlCommand(idTarifSelect, con);
                Int32      idTarifInt    = (Int32)(idTarif).ExecuteScalar();

                string     nameOfTarifSelect = "SELECT Nazvanie  FROM Tarif Where idTarifa = '" + idTarifInt + " '";
                SqlCommand nameOfTarif       = new SqlCommand(nameOfTarifSelect, con);
                String     nameOfTarifString = (String)(nameOfTarif).ExecuteScalar();

                string     typeOfTarifSelect = "SELECT TipTarifa  FROM Tarif Where idTarifa = '" + idTarifInt + " '";
                SqlCommand typeOfTarif       = new SqlCommand(typeOfTarifSelect, con);
                String     typeOfTarifString = (String)(typeOfTarif).ExecuteScalar();
                label14.Text = nameOfTarifString + ", " + typeOfTarifString;
                try
                {
                    string     idProizSelect = "SELECT idProischestviya FROM Poezdka Where idPoezdki = '" + Program.getIdTrip + " '";
                    SqlCommand idProiz       = new SqlCommand(idProizSelect, con);
                    Int32      idProizInt    = (Int32)(idProiz).ExecuteScalar();

                    string     opicanieProizSelect = "SELECT Opicanie  FROM Proishestviya Where idProischestviya = '" + idProizInt + " '";
                    SqlCommand opicanieProiz       = new SqlCommand(opicanieProizSelect, con);
                    String     opicanieProizString = (String)(opicanieProiz).ExecuteScalar();
                    label16.Text      = opicanieProizString;
                    label16.ForeColor = Color.Red;
                }
                catch (Exception)
                {
                    label16.Text      = "Отсутствуют";
                    label16.ForeColor = Color.Green;
                }
                try
                {
                    string     otzyvSelect = "SELECT Otzyv  FROM Poezdka Where idPoezdki = '" + Program.getIdTrip + " '";
                    SqlCommand otzyv       = new SqlCommand(otzyvSelect, con);
                    String     otzyvString = (String)(otzyv).ExecuteScalar();
                    richTextBox1.Text = otzyvString;
                }
                catch (Exception)
                {
                    richTextBox1.Text = "Пользователь не оставил отзыв на эту поездку";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                string method = cm.GetCurrentMethod();
                logger.Error(ex.ToString() + method);
            }
        }
Ejemplo n.º 6
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         string v = cm.GetCurrentMethod();
         logger.Info(v);
         con = new SqlConnection(connectionString);
         con.Open();
         comboBox2.Enabled = true;
         string query;
         query = String.Format("SELECT  Tip FROM KlassAvto Where Klass = '" + comboBox1.Text + " '", con);
         SqlCommand     cmd1 = new SqlCommand(query, con);
         DataTable      tbl1 = new DataTable();
         SqlDataAdapter da   = new SqlDataAdapter(cmd1);
         da.Fill(tbl1);
         this.comboBox2.DataSource    = tbl1;
         this.comboBox2.DisplayMember = "Tip"; // столбец для отображения
                                               //this.comboBox2.ValueMember = idKlassa";//столбец с id
                                               // this.comboBox2.SelectedIndex = 1;
         con.Close();
     }
     catch (Exception ex)
     {
         //MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         string method = cm.GetCurrentMethod();
         logger.Error(ex.ToString() + method);
     }
 }
Ejemplo n.º 7
0
        private void Form8_Load(object sender, EventArgs e)
        {
            try
            {
                string v = cm.GetCurrentMethod();
                logger.Info(v);
                con = new SqlConnection(connectionString);
                con.Open();

                string     vyUserSelect = "SELECT FotoOfFace FROM Photos Where idUser ='******'";
                SqlCommand vyUser       = new SqlCommand(vyUserSelect, con);
                String     vyUserString = (String)(vyUser).ExecuteScalar();
                pictureBox1.Image = Image.FromFile(vyUserString);

                string     fioUserSelect = "SELECT Fio FROM Polzovatel Where IdUser = '******'";
                SqlCommand fioUser       = new SqlCommand(fioUserSelect, con);
                String     fioUserString = (String)(fioUser).ExecuteScalar();
                label3.Text = fioUserString;

                string     numberOfPassportUserSelect = "SELECT NomerPassporta FROM Polzovatel Where IdUser = '******'";
                SqlCommand numberOfPassportUser       = new SqlCommand(numberOfPassportUserSelect, con);
                String     numberOfPassportUserString = (String)(numberOfPassportUser).ExecuteScalar();
                label4.Text = numberOfPassportUserString;

                string     propiskaUserSelect = "SELECT Propiska FROM Polzovatel Where IdUser = '******'";
                SqlCommand propiskaUser       = new SqlCommand(propiskaUserSelect, con);
                String     propiskaUserString = (String)(propiskaUser).ExecuteScalar();
                label6.Text = propiskaUserString;

                string     dayOfBirthdayUserSelect = "SELECT DataRozdeniya FROM Polzovatel Where IdUser = '******'";
                SqlCommand dayOfBirthdayUser       = new SqlCommand(dayOfBirthdayUserSelect, con);
                DateTime   dayOfBirthdayUserString = (DateTime)(dayOfBirthdayUser).ExecuteScalar();
                var        date = dayOfBirthdayUserString.ToShortDateString();
                label8.Text = Convert.ToString(date);

                string     numberOfDriverLicenseUserSelect = "SELECT NomerVY FROM Polzovatel Where IdUser = '******'";
                SqlCommand numberOfDriverLicenseUser       = new SqlCommand(numberOfDriverLicenseUserSelect, con);
                String     numberOfDriverLicenseUserString = (String)(numberOfDriverLicenseUser).ExecuteScalar();
                label10.Text = numberOfDriverLicenseUserString;

                string     statusUserSelect = "SELECT StatusPodtverzdeniya FROM Polzovatel Where IdUser = '******'";
                SqlCommand statusUser       = new SqlCommand(statusUserSelect, con);
                Boolean    statusUserString = (Boolean)(statusUser).ExecuteScalar();
                var        status           = statusUserString.ToString();
                label12.Text = status;

                if (label12.Text == "False")
                {
                    label12.Text = "Не подтвержден";
                    label18.Text = "-";
                }
                else if (label12.Text == "True")
                {
                    label12.Text = "Подтвержден";
                }

                string     emailUserSelect = "SELECT Email FROM Polzovatel Where IdUser = '******'";
                SqlCommand emailUser       = new SqlCommand(emailUserSelect, con);
                String     emailUserString = (String)(emailUser).ExecuteScalar();
                label14.Text = emailUserString;

                string     mobilePhoneUserSelect = "SELECT MobilePhone FROM Polzovatel Where IdUser = '******'";
                SqlCommand mobilePhoneUser       = new SqlCommand(mobilePhoneUserSelect, con);
                String     mobilePhoneUserString = (String)(mobilePhoneUser).ExecuteScalar();
                label16.Text = mobilePhoneUserString;

                string     countTripsUserSelect = "Select Count (*) From Poezdka WHERE idUser = '******'";
                SqlCommand countTripsUser       = new SqlCommand(countTripsUserSelect, con);
                Int32      countTripsUserString = (Int32)(countTripsUser).ExecuteScalar();
                label18.Text = countTripsUserString.ToString();
                if (label12.Text == "Не подтвержден")
                {
                    label18.Text = "-";
                }
                try
                {
                    string     sumOfTripsUserSelect = "Select SUM(Stoim) From Poezdka WHERE idUser = '******'";
                    SqlCommand sumOfTripsUser       = new SqlCommand(sumOfTripsUserSelect, con);
                    Int32      sumOfTripsUserString = (Int32)(sumOfTripsUser).ExecuteScalar();
                    label20.Text = sumOfTripsUserString.ToString() + "р.";
                }
                catch (Exception)
                {
                    if (label12.Text == "Не подтвержден")
                    {
                        label20.Text = "-";
                    }
                    else if (label12.Text == "Подтвержден")
                    {
                        label20.Text = "0";
                    }
                }

                string     countProisUserSelect = "Select Count (idProischestviya) From Poezdka WHERE idUser = '******'";
                SqlCommand countProisTripsUser  = new SqlCommand(countProisUserSelect, con);
                Int32      countProisUserString = (Int32)(countProisTripsUser).ExecuteScalar();
                label22.Text = countProisUserString.ToString();
                if (label22.Text != "0")
                {
                    label22.ForeColor = Color.Red;
                }
                if (label12.Text == "Не подтвержден")
                {
                    label22.Text = "-";
                }

                try
                {
                    string     sumOfTimeUserSelect = "Select SUM(Dlitelnost) From Poezdka WHERE idUser = '******'";
                    SqlCommand sumOfTimeUser       = new SqlCommand(sumOfTimeUserSelect, con);
                    Int32      sumOfTimeUserString = (Int32)(sumOfTimeUser).ExecuteScalar();
                    var        ts = TimeSpan.FromMinutes(sumOfTimeUserString);
                    label24.Text = String.Format("{0} д. {1} ч. {2} м. ", ts.Days, ts.Hours, ts.Minutes);
                }
                catch (Exception)
                {
                    if (label12.Text == "Не подтвержден")
                    {
                        label24.Text = "-";
                    }
                    else if (label12.Text == "Подтвержден")
                    {
                        label24.Text = "0";
                    }
                }

                if (label12.Text == "Не подтвержден")
                {
                    button2.Visible = true;
                }
                else if (label12.Text == "Подтвержден")
                {
                    button2.Visible = true;
                }

                SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Messages Where IdUser = '******' ", con);
                DataTable      dt  = new DataTable();
                sda.Fill(dt);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if ((bool)dt.Rows[i]["StatusPolzv"] == true)
                    {
                        string who;
                        who = "Пользователь: ";
                        string name = dt.Rows[i]["Text"].ToString();

                        richTextBox1.Text = who + name + "\r\n" + richTextBox1.Text;
                    }
                    else
                    {
                        string who;
                        who = "Вы: ";
                        string name = dt.Rows[i]["Text"].ToString();

                        richTextBox1.Text = who + name + "\r\n" + richTextBox1.Text;
                    }
                }


                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                string method = cm.GetCurrentMethod();
                logger.Error(ex.ToString() + method);
            }
        }
Ejemplo n.º 8
0
        private void Form16_Load(object sender, EventArgs e)
        {
            try
            {
                string v = cm.GetCurrentMethod();
                logger.Info(v);
                con = new SqlConnection(connectionString);
                con.Open();

                string     fioUserSelect = "SELECT Fio FROM Polzovatel Where IdUser = '******'";
                SqlCommand fioUser       = new SqlCommand(fioUserSelect, con);
                String     fioUserString = (String)(fioUser).ExecuteScalar();
                label1.Text = "Спасибо за поездку " + fioUserString + "!";
            }
            catch (Exception ex)
            {
                string method = cm.GetCurrentMethod();
                logger.Error(ex.ToString() + method);
            }
        }
Ejemplo n.º 9
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                String connectionString1 = @"Data Source=" + Program.serverName + "Initial Catalog=" + Program.bdName + ";" +
                                           "Integrated Security=True";

                con1 = new SqlConnection(connectionString1);
                con1.Open();
                CarSharing.Properties.Settings.Default.DiplomConnectionString = connectionString1;
                string     firstNewSelect = "SELECT TOP (1)  KratkoeOpicanie  FROM News ORDER BY idNews DESC";
                SqlCommand firstNew       = new SqlCommand(firstNewSelect, con);
                String     firstNewString = (String)(firstNew).ExecuteScalar();
                label3.Text = firstNewString;

                string     firstNewFullSelect = "SELECT TOP (1)  PolnoeOpicanie  FROM News ORDER BY idNews DESC";
                SqlCommand firstNewFull       = new SqlCommand(firstNewFullSelect, con);
                String     firstNewFullString = (String)(firstNewFull).ExecuteScalar();
                label2.Text = firstNewFullString;

                string     newPicture    = "SELECT TOP (1) Izobrazenie FROM News ORDER BY idNews DESC";
                SqlCommand sqlnewPicture = new SqlCommand(newPicture, con);
                String     pictureString = (String)(sqlnewPicture).ExecuteScalar();
                pictureBox1.Image = Image.FromFile(pictureString);


                SqlDataAdapter sda1 = new SqlDataAdapter("select top(2) * from News order by idNews desc", con);
                DataTable      dt1  = new DataTable();
                sda1.Fill(dt1);
                label4.Text       = dt1.Rows[1][1].ToString();
                label5.Text       = dt1.Rows[1][2].ToString();
                pictureBox2.Image = Image.FromFile(dt1.Rows[1][3].ToString());
                con1.Close();
                string v = cm.GetCurrentMethod();
                logger.Info(v);
            }
            catch (Exception ex)
            {
                string method = cm.GetCurrentMethod();
                logger.Error(ex.ToString() + method);
            }
        }
Ejemplo n.º 10
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string v = cm.GetCurrentMethod();
                logger.Info(v);
                String insertValueName                  = textBox1.Text;
                String insertValueSurname               = textBox2.Text;
                String insertValueSecondName            = textBox3.Text;
                String insertValueFio                   = insertValueSurname + " " + insertValueName + " " + insertValueSecondName;
                String insertValueNumberOfPassport      = maskedTextBox2.Text;
                String insertValuePlaceOfRegistration   = richTextBox1.Text;
                String insertValueDateOfBirthday        = dateTimePicker1.Value.ToString();
                String insertValueNumberOfDriverLicense = maskedTextBox1.Text;
                String insertValueEmail                 = textBox6.Text;
                String insertValueMobilePhone           = maskedTextBox3.Text;
                String insertValueStatus                = "0";
                if (maskedTextBox2.Text.Length != 10)
                {
                    MessageBox.Show("Пожалуйста, заполните до конца номер паспорта", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    maskedTextBox2.Focus();
                    return;
                }
                if (maskedTextBox1.Text.Length != 10)
                {
                    MessageBox.Show("Пожалуйста, заполните до конца номер водительского удостоверения", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    maskedTextBox1.Focus();
                    return;
                }
                if (maskedTextBox3.Text.Length != 18)
                {
                    MessageBox.Show("Пожалуйста, заполните до конца номер телефона", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    maskedTextBox3.Focus();
                    return;
                }


                con = new SqlConnection(connectionString);
                con.Open();
                SqlDataAdapter sda = new SqlDataAdapter("Select Count (*) From Polzovatel WHERE Email = '" + insertValueEmail + " '", con);
                DataTable      dt  = new DataTable();
                sda.Fill(dt);
                SqlDataAdapter sd1 = new SqlDataAdapter("Select Count (*) From Polzovatel WHERE NomerPassporta = '" + insertValueNumberOfPassport + " '", con);
                DataTable      dt1 = new DataTable();
                sd1.Fill(dt1);
                SqlDataAdapter sd2 = new SqlDataAdapter("Select Count (*) From Polzovatel WHERE NomerVY = '" + insertValueNumberOfDriverLicense + " '", con);
                DataTable      dt2 = new DataTable();
                sd2.Fill(dt2);
                SqlDataAdapter sd3 = new SqlDataAdapter("Select Count (*) From Polzovatel WHERE MobilePhone = '" + insertValueMobilePhone + " '", con);
                DataTable      dt3 = new DataTable();
                sd3.Fill(dt3);
                if (dt1.Rows[0][0].ToString() != "0")
                {
                    MessageBox.Show("Данный номер паспорта уже существует", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (dt2.Rows[0][0].ToString() != "0")
                {
                    MessageBox.Show("Данный номер Водительского Удостоверения уже существует", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (dt.Rows[0][0].ToString() != "0")
                {
                    MessageBox.Show("Такой адрес электронной почты уже существует", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (dt3.Rows[0][0].ToString() != "0")
                {
                    MessageBox.Show("Такой номер телефона уже существует", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                else
                {
                    string sqlInsertNewUser = string.Format("INSERT INTO Polzovatel (Fio, NomerPassporta, Propiska, DataRozdeniya, NomerVY, StatusPodtverzdeniya, Email, MobilePhone)  VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', {5}, '{6}', '{7}')", insertValueFio,
                                                            insertValueNumberOfPassport, insertValuePlaceOfRegistration,
                                                            insertValueDateOfBirthday, insertValueNumberOfDriverLicense, insertValueStatus, insertValueEmail,
                                                            insertValueMobilePhone);
                    SqlCommand insNewUser = new SqlCommand(sqlInsertNewUser, con);
                    insNewUser.ExecuteNonQuery();

                    textBox1.Enabled        = false;
                    textBox2.Enabled        = false;
                    textBox3.Enabled        = false;
                    maskedTextBox2.Enabled  = false;
                    maskedTextBox1.Enabled  = false;
                    richTextBox1.Enabled    = false;
                    dateTimePicker1.Enabled = false;
                    textBox5.Enabled        = false;
                    textBox6.Enabled        = false;
                    maskedTextBox3.Enabled  = false;
                    button2.Enabled         = false;
                    textBox9.Enabled        = true;
                    textBox8.Enabled        = true;
                    button4.Enabled         = true;
                    textBox5.Enabled        = true;
                    checkInsert             = false;
                    closing           = false;
                    checkBox2.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                string method = cm.GetCurrentMethod();
                logger.Error(ex.ToString() + method);
            }
        }
Ejemplo n.º 11
0
        private void Form5_Load(object sender, EventArgs e)
        {
            try
            {
                string v = cm.GetCurrentMethod();
                logger.Info(v);
                this.Name = "Администрирование";
                con       = new SqlConnection(connectionString);
                con.Open();

                string     countTripsSelect = "Select Count (idPoezdki) From Poezdka ";
                SqlCommand countTrips       = new SqlCommand(countTripsSelect, con);
                Int32      countTripsString = (Int32)(countTrips).ExecuteScalar();
                label3.Text = countTripsString.ToString();

                try
                {
                    string     sumTripsSelect = "Select SUM (Stoim) From Poezdka ";
                    SqlCommand sumTrips       = new SqlCommand(sumTripsSelect, con);
                    Int32      sumTripsString = (Int32)(sumTrips).ExecuteScalar();
                    label4.Text = sumTripsString.ToString() + " р.";
                }
                catch (Exception)
                {
                    label4.Text = "0";
                }

                string     countProisSelect = "Select Count (idProischestviya) From Poezdka ";
                SqlCommand countProis       = new SqlCommand(countProisSelect, con);
                Int32      countProisString = (Int32)(countProis).ExecuteScalar();
                label6.Text = countProisString.ToString();

                string     countAvtoSelect = "Select Count (idAvto) From Avto ";
                SqlCommand countAvto       = new SqlCommand(countAvtoSelect, con);
                Int32      countAvtoString = (Int32)(countAvto).ExecuteScalar();
                label8.Text = countAvtoString.ToString();

                string     countAvtoRepairSelect = "Select Count (idAvto) From Avto WHERE StatusDostypa = 1 ";
                SqlCommand countAvtoRepair       = new SqlCommand(countAvtoRepairSelect, con);
                Int32      countAvtoRepairString = (Int32)(countAvtoRepair).ExecuteScalar();
                label11.Text = countAvtoRepairString.ToString();

                string     countUsersSelect = "Select Count (idUser) From AutDate ";
                SqlCommand countUsers       = new SqlCommand(countUsersSelect, con);
                Int32      countUsersString = (Int32)(countUsers).ExecuteScalar();
                label14.Text = countUsersString.ToString();

                string     countUsersPotrSelect = "Select Count (IdUser) From Polzovatel WHERE StatusPodtverzdeniya = 1 ";
                SqlCommand countUsersPotr       = new SqlCommand(countUsersPotrSelect, con);
                Int32      countUsersPotrString = (Int32)(countUsersPotr).ExecuteScalar();
                label12.Text = countUsersPotrString.ToString();

                string     timeOfTripSelect = "SELECT SUM(Dlitelnost) FROM Poezdka";
                SqlCommand timeOfTrip       = new SqlCommand(timeOfTripSelect, con);
                Int32      timeOfTripInt    = (Int32)(timeOfTrip).ExecuteScalar();
                Int32      medianTimeOfTrip = timeOfTripInt / countTripsString;
                var        ts = TimeSpan.FromMinutes(Convert.ToDouble(timeOfTripInt));
                label16.Text = String.Format("{0} д. {1} ч. {2} м. ", ts.Days, ts.Hours, ts.Minutes);
                var ts2 = TimeSpan.FromMinutes(Convert.ToDouble(medianTimeOfTrip));
                label18.Text = String.Format("{0} д. {1} ч. {2} м. ", ts2.Days, ts2.Hours, ts2.Minutes);

                SqlDataAdapter sda = new SqlDataAdapter("select idAvto, count(*) as num from Poezdka group by idAvto order by count(*) desc", con);
                DataTable      dt  = new DataTable();
                sda.Fill(dt);

                String idAvtoString = dt.Rows[0][0].ToString();
                Int32  idAvto       = Convert.ToInt32(idAvtoString);

                string     markaAvtoSelect = "Select Marka From Avto WHERE idAvto = '" + idAvto + " ' ";
                SqlCommand markaAvto       = new SqlCommand(markaAvtoSelect, con);
                string     markaAvtoString = (string)(markaAvto).ExecuteScalar();

                string     nazvanieAvtoSelect = "Select Nazvanie From Avto WHERE idAvto = '" + idAvto + " ' ";
                SqlCommand nazvanieAvto       = new SqlCommand(nazvanieAvtoSelect, con);
                string     nazvanieAvtoString = (string)(nazvanieAvto).ExecuteScalar();

                string     gosNomerAvtoSelect = "Select GosNomer From Avto WHERE idAvto = '" + idAvto + " ' ";
                SqlCommand gosNomerAvto       = new SqlCommand(gosNomerAvtoSelect, con);
                string     gosNomerAvtoString = (string)(gosNomerAvto).ExecuteScalar();
                label20.Text = markaAvtoString + ", " + nazvanieAvtoString + ", " + gosNomerAvtoString;

                String countOfTripsString = dt.Rows[0][1].ToString();
                label22.Text = countOfTripsString;


                SqlDataAdapter sda1 = new SqlDataAdapter("select idTarifa, count(*) as num from Poezdka group by idTarifa order by count(*) desc", con);
                DataTable      dt1  = new DataTable();
                sda1.Fill(dt1);

                String idTarifaString = dt1.Rows[0][0].ToString();
                Int32  idTarifa       = Convert.ToInt32(idTarifaString);

                string     nameOfTarifSelect = "Select Nazvanie From Tarif WHERE idTarifa = '" + idTarifa + " ' ";
                SqlCommand nameOfTarif       = new SqlCommand(nameOfTarifSelect, con);
                string     nameOfTarifString = (string)(nameOfTarif).ExecuteScalar();

                string     typeOfTarifSelect = "Select TipTarifa From Tarif WHERE idTarifa = '" + idTarifa + " ' ";
                SqlCommand typeOfTarif       = new SqlCommand(typeOfTarifSelect, con);
                string     typeOfTarifString = (string)(typeOfTarif).ExecuteScalar();

                string     timeOfTarifSelect = "Select VremyaTarifa From Tarif WHERE idTarifa = '" + idTarifa + " ' ";
                SqlCommand timeOfTarif       = new SqlCommand(timeOfTarifSelect, con);
                string     timeOfTarifString = (string)(timeOfTarif).ExecuteScalar();
                label24.Text = typeOfTarifString + ", " + timeOfTarifString + ", " + nameOfTarifString;

                String countOfTripsTarifString = dt1.Rows[0][1].ToString();
                label26.Text = countOfTripsTarifString;

                string     countPovrSelect = "Select Count (idPovrezdeniya) From Povrezdeniya ";
                SqlCommand countPovr       = new SqlCommand(countPovrSelect, con);
                Int32      countPovrString = (Int32)(countPovr).ExecuteScalar();
                label28.Text = countPovrString.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                string method = cm.GetCurrentMethod();
                logger.Error(ex.ToString() + method);
            }
        }