Exemple #1
0
        public UserDetail(int user)
        {
            InitializeComponent();

            userclass = new Userclass();
            advancedDataGridView1.DataSource = userclass.penaltylist;
            string sqlExpression = $"SELECT [ID],[Full_Name],[Balance],[Debt],[Drive_License],[Password],[Login],[Pasport],[Admin] FROM [dbo].[User] WHERE [ID]='{user}' ";

            using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.City_ParkingConnectionString))
            {
                connection.Open();
                SqlCommand    command = new SqlCommand(sqlExpression, connection);
                SqlDataReader reader  = command.ExecuteReader();

                if (reader.HasRows)       // если есть данные
                {
                    while (reader.Read()) // построчно считываем данные
                    {
                        for (int i = 0; i < userclass.GetType().GetProperties().Length - 2; i++)
                        {
                            if (reader.GetValue(i) is DBNull)
                            {
                            }
                            else
                            {
                                userclass.GetType().GetProperties()[i].SetValue(userclass, reader.GetValue(i));
                            }
                        }
                    }
                }
            }
            textBox5.Text       = userclass.Full_Name;
            textBox4.Text       = userclass.Pasport;
            textBox3.Text       = userclass.Drive_License;
            textBox1.Text       = Convert.ToString(userclass.Balance);
            textBox2.Text       = Convert.ToString(userclass.Login);
            listBox1.DataSource = userclass.carsList;
        }
Exemple #2
0
        public User(object id)
        {
            user = new Userclass();
            InitializeComponent();
            string sqlExpression = $"SELECT [ID],[Full_Name],[Balance],[Debt],[Drive_License],[Password],[Login],[Pasport],[Admin] FROM [dbo].[User] WHERE [ID]='{id}' ";

            using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.City_ParkingConnectionString))
            {
                connection.Open();
                SqlCommand    command = new SqlCommand(sqlExpression, connection);
                SqlDataReader reader  = command.ExecuteReader();

                if (reader.HasRows)       // если есть данные
                {
                    while (reader.Read()) // построчно считываем данные
                    {
                        for (int i = 0; i < user.GetType().GetProperties().Length - 2; i++)
                        {
                            if (reader.GetValue(i) is DBNull)
                            {
                            }
                            else
                            {
                                user.GetType().GetProperties()[i].SetValue(user, reader.GetValue(i));
                            }
                        }
                    }
                }
            }
            textBox5.Text = user.Full_Name;
            textBox4.Text = user.Pasport;
            textBox3.Text = user.Drive_License;
            textBox6.Text = Convert.ToString(user.Balance);
            textBox2.Text = Convert.ToString(user.Debt);
            advancedDataGridView1.DataSource = user.carsList;
            string sql = "SELECT SUM([Sum]) FROM [dbo].[Penalty] WHERE FK_User = "******"")
                {
                    sum += Convert.ToInt32(count);
                }
            }
            string sql3 = "SELECT [Balance] FROM [dbo].[User] WHERE ID= " + id;

            using (SqlConnection con = new SqlConnection(Properties.Settings.Default.City_ParkingConnectionString))
            {
                con.Open();
                SqlCommand command = new SqlCommand(sql3, con);
                object     count   = command.ExecuteScalar();
                if (Convert.ToString(count) != "")
                {
                    bal += Convert.ToInt32(count);
                }
            }

            string sql1 = "SELECT [Debt] FROM [dbo].[User] WHERE ID= " + id;

            using (SqlConnection con = new SqlConnection(Properties.Settings.Default.City_ParkingConnectionString))
            {
                con.Open();
                SqlCommand command = new SqlCommand(sql1, con);
                object     count   = command.ExecuteScalar();
                if (Convert.ToString(count) != "")
                {
                    sum += Convert.ToInt32(count);
                }
            }
            textBox2.Text = Convert.ToString(sum);
            try
            {
                using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.City_ParkingConnectionString))
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand();
                    command.CommandText = "UPDATE [User] SET [Debt]=" + sum + "WHERE ID= " + id;
                    command.Connection  = connection;
                    command.ExecuteNonQuery();
                    MessageBox.Show("Данные о задолженности обновлены");
                }
            }
            catch (Exception exc)
            {
                Debug.WriteLine(exc);
                MessageBox.Show("Не удалось обновить данные о задолженности");
            }
            try
            {
                using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.City_ParkingConnectionString))
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand();
                    command.CommandText = "DELETE FROM [Penalty] WHERE FK_User= "******"Данные о назначенных вам штрафах внесены в задолженность и удалены");
                }
            }
            catch (Exception exc)
            {
                Debug.WriteLine(exc);
                MessageBox.Show("Не удалось удалить ваши штрафы");
            }
        }