예제 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (criterion.Text == "Дата нарушения")
            {
                if (searchCriterion.Text != CheckJournalEntry.CheckEnrtyDate(searchCriterion.Text))
                {
                    System.Windows.MessageBox.Show(CheckJournalEntry.CheckEnrtyDate(searchCriterion.Text));
                    return;
                }
            }
            else if (criterion.Text == "Время нарушения")
            {
                if (searchCriterion.Text != CheckJournalEntry.CheckEntryTime(searchCriterion.Text))
                {
                    System.Windows.MessageBox.Show(CheckJournalEntry.CheckEntryTime(searchCriterion.Text));
                    return;
                }
            }
            else if (criterion.Text == "Тип нарушения")
            {
                if (searchCriterion.Text != CheckViolation.CheckViolationName(searchCriterion.Text))
                {
                    System.Windows.MessageBox.Show(CheckViolation.CheckViolationName(searchCriterion.Text));
                    return;
                }
            }
            else if (criterion.Text == "Номер автомобиля")
            {
                if (searchCriterion.Text != CheckCar.CheckCarStateNumber(searchCriterion.Text))
                {
                    System.Windows.MessageBox.Show(CheckCar.CheckCarStateNumber(searchCriterion.Text));
                    return;
                }
            }
            else if (criterion.Text == "Марка автомобиля")
            {
                if (searchCriterion.Text != CheckCar.CheckCarModel(searchCriterion.Text))
                {
                    System.Windows.MessageBox.Show(CheckCar.CheckCarModel(searchCriterion.Text));
                    return;
                }
            }
            else if (criterion.Text == "Фамилия нарушителя")
            {
                if (searchCriterion.Text != CheckViolator.CheckViolatorSurname(searchCriterion.Text))
                {
                    System.Windows.MessageBox.Show(CheckViolator.CheckViolatorSurname(searchCriterion.Text));
                    return;
                }
            }
            else if (criterion.Text == "Имя нарушителя")
            {
                if (searchCriterion.Text != CheckViolator.CheckViolatorName(searchCriterion.Text))
                {
                    System.Windows.MessageBox.Show(CheckViolator.CheckViolatorName(searchCriterion.Text));
                    return;
                }
            }
            else if (criterion.Text == "Отчество нарушителя")
            {
                if (searchCriterion.Text != CheckViolator.CheckViolatorPatronymic(searchCriterion.Text))
                {
                    System.Windows.MessageBox.Show(CheckViolator.CheckViolatorPatronymic(searchCriterion.Text));
                    return;
                }
            }
            else if (criterion.Text == "Сумма штрафа (руб.)")
            {
                if (searchCriterion.Text != CheckViolation.CheckViolationCost(searchCriterion.Text))
                {
                    System.Windows.MessageBox.Show(CheckViolation.CheckViolationCost(searchCriterion.Text));
                    return;
                }
            }
            else if (criterion.Text == "Статус оплаты")
            {
                if (searchCriterion.Text != CheckJournalEntry.CheckPaymentStatus(searchCriterion.Text))
                {
                    System.Windows.MessageBox.Show(CheckJournalEntry.CheckPaymentStatus(searchCriterion.Text));
                    return;
                }
            }
            else
            {
                System.Windows.MessageBox.Show("Вы не выбрали критерий поиска.");
                return;
            }
            StreamWriter writeCriterion = new StreamWriter("Criterion.txt");

            writeCriterion.Write(criterion.Text);
            writeCriterion.Close();
            StreamWriter writeSearchCriterion = new StreamWriter("SearchCriterion.txt");

            writeSearchCriterion.Write(searchCriterion.Text);
            writeSearchCriterion.Close();
            JournalEntriesResult journalEntriesResult = new JournalEntriesResult();

            journalEntriesResult.Show();
            this.Close();
        }
예제 #2
0
        private void SaveChanges(object sender, RoutedEventArgs e)
        {
            if (criterion.Text != string.Empty && searchCriterion.Text != string.Empty)
            {
                if (criterion.Text == "Дата нарушения")
                {
                    if (changingCriterion.Text != CheckJournalEntry.CheckEnrtyDate(changingCriterion.Text))
                    {
                        MessageBox.Show(CheckJournalEntry.CheckEnrtyDate(changingCriterion.Text));
                        return;
                    }
                    using (SqlConnection updateDate = new SqlConnection(connectionString))
                        using (SqlCommand lastCommnd = updateDate.CreateCommand())
                        {
                            lastCommnd.CommandText = "UPDATE ViolationsJournal SET EntryNumberDate = @date WHERE EntryNumber = @code";

                            lastCommnd.Parameters.AddWithValue("@date", Convert.ToDateTime(changingCriterion.Text));
                            lastCommnd.Parameters.AddWithValue("@code", Convert.ToInt32(searchCriterion.Text));

                            updateDate.Open();
                            lastCommnd.ExecuteNonQuery();
                            updateDate.Close();
                        }
                }
                else if (criterion.Text == "Время нарушения")
                {
                    if (changingCriterion.Text != CheckJournalEntry.CheckEntryTime(changingCriterion.Text))
                    {
                        MessageBox.Show(CheckJournalEntry.CheckEntryTime(changingCriterion.Text));
                        return;
                    }
                    using (SqlConnection updateTime = new SqlConnection(connectionString))
                        using (SqlCommand lastCommnd = updateTime.CreateCommand())
                        {
                            lastCommnd.CommandText = "UPDATE ViolationsJournal SET EntryNumberTime = @time WHERE EntryNumber = @code";

                            lastCommnd.Parameters.AddWithValue("@time", TimeSpan.Parse(changingCriterion.Text));
                            lastCommnd.Parameters.AddWithValue("@code", Convert.ToInt32(searchCriterion.Text));

                            updateTime.Open();
                            lastCommnd.ExecuteNonQuery();
                            updateTime.Close();
                        }
                }
                else if (criterion.Text == "Тип нарушения")
                {
                    if (changingCriterion.Text == string.Empty)
                    {
                        MessageBox.Show("Вы не ввели код нарушения.");
                        return;
                    }
                    else
                    {
                        char[] codeArray = changingCriterion.Text.ToCharArray();
                        for (int i = 0; i < codeArray.Length; i++)
                        {
                            if (!char.IsDigit(codeArray[i]))
                            {
                                MessageBox.Show("Вы указали в коде нарушения недопустимые символы.");
                                return;
                            }
                        }
                    }
                    string        query         = @"SELECT ViolationCode FROM Violation WHERE ViolationCode = '" + changingCriterion.Text + "'";
                    int           violationCode = 0;
                    SqlConnection sqlConnection = new SqlConnection(connectionString);
                    sqlConnection.Open();
                    SqlCommand    sqlCommand    = new SqlCommand(query, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            violationCode = Convert.ToInt32(sqlDataReader[0].ToString());
                        }
                    }
                    else
                    {
                        MessageBox.Show("Такого нарушения нет в базе.");
                        return;
                    }
                    sqlDataReader.Close();
                    sqlConnection.Close();
                    using (SqlConnection updateViolationType = new SqlConnection(connectionString))
                        using (SqlCommand lastCommnd = updateViolationType.CreateCommand())
                        {
                            lastCommnd.CommandText = "UPDATE ViolationsJournal SET ViolationCode = @viol WHERE EntryNumber = @code";

                            lastCommnd.Parameters.AddWithValue("@viol", Convert.ToInt32(changingCriterion.Text));
                            lastCommnd.Parameters.AddWithValue("@code", Convert.ToInt32(searchCriterion.Text));

                            updateViolationType.Open();
                            lastCommnd.ExecuteNonQuery();
                            updateViolationType.Close();
                        }
                }
                else if (criterion.Text == "Автомобиль и владелец")
                {
                    if (changingCriterion.Text == string.Empty)
                    {
                        MessageBox.Show("Вы не ввели код автомобиля.");
                        return;
                    }
                    else
                    {
                        char[] codeArray = changingCriterion.Text.ToCharArray();
                        for (int i = 0; i < codeArray.Length; i++)
                        {
                            if (!char.IsDigit(codeArray[i]))
                            {
                                MessageBox.Show("Вы указали в коде автомобиля недопустимые символы.");
                                return;
                            }
                        }
                    }
                    string        query         = @"SELECT CarCode FROM ViolatorCar WHERE CarCode = '" + changingCriterion.Text + "'";
                    int           violationCode = 0;
                    SqlConnection sqlConnection = new SqlConnection(connectionString);
                    sqlConnection.Open();
                    SqlCommand    sqlCommand    = new SqlCommand(query, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            violationCode = Convert.ToInt32(sqlDataReader[0].ToString());
                        }
                    }
                    else
                    {
                        MessageBox.Show("Такого автомобиля нет в базе.");
                        return;
                    }
                    sqlDataReader.Close();
                    sqlConnection.Close();
                    using (SqlConnection updateCarAndViolator = new SqlConnection(connectionString))
                        using (SqlCommand lastCommnd = updateCarAndViolator.CreateCommand())
                        {
                            lastCommnd.CommandText = "UPDATE ViolationsJournal SET CarCode = @cc WHERE EntryNumber = @code";

                            lastCommnd.Parameters.AddWithValue("@cc", Convert.ToInt32(changingCriterion.Text));
                            lastCommnd.Parameters.AddWithValue("@code", Convert.ToInt32(searchCriterion.Text));

                            updateCarAndViolator.Open();
                            lastCommnd.ExecuteNonQuery();
                            updateCarAndViolator.Close();
                        }
                }
                else if (criterion.Text == "Статус оплаты")
                {
                    if (changingCriterion.Text != CheckJournalEntry.CheckPaymentStatus(changingCriterion.Text))
                    {
                        MessageBox.Show(CheckJournalEntry.CheckPaymentStatus(changingCriterion.Text));
                        return;
                    }
                    string        query         = @"SELECT ViolationStatusCode FROM ViolationStatus WHERE ViolationStatusName = '" + changingCriterion.Text + "'";
                    int           statusCode    = 0;
                    SqlConnection sqlConnection = new SqlConnection(connectionString);
                    sqlConnection.Open();
                    SqlCommand    sqlCommand    = new SqlCommand(query, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            statusCode = Convert.ToInt32(sqlDataReader[0].ToString());
                        }
                    }
                    sqlDataReader.Close();
                    sqlConnection.Close();
                    using (SqlConnection updateCarAndViolator = new SqlConnection(connectionString))
                        using (SqlCommand lastCommnd = updateCarAndViolator.CreateCommand())
                        {
                            lastCommnd.CommandText = "UPDATE ViolationsJournal SET ViolationStatusCode = @status WHERE EntryNumber = @code";

                            lastCommnd.Parameters.AddWithValue("@status", statusCode);
                            lastCommnd.Parameters.AddWithValue("@code", Convert.ToInt32(searchCriterion.Text));

                            updateCarAndViolator.Open();
                            lastCommnd.ExecuteNonQuery();
                            updateCarAndViolator.Close();
                        }
                }
            }
            else
            {
                MessageBox.Show("Вы не выбрали данные для изменения.");
                return;
            }
            MessageBoxResult mboxResult = MessageBox.Show("Данные обновлены. Желаете изменить что-нибудь еще?", "Предупреждение", MessageBoxButton.YesNo);

            if (mboxResult == MessageBoxResult.No)
            {
                ChangeJournalEntry changeJournalEntry = new ChangeJournalEntry();
                changeJournalEntry.Show();
                this.Close();
            }
        }
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            connection.Open();
            if (violationCode.Text == string.Empty)
            {
                System.Windows.MessageBox.Show("Вы не выбрали код нарушения");
                return;
            }
            if (entryDate.Text != CheckJournalEntry.CheckEnrtyDate(entryDate.Text))
            {
                System.Windows.MessageBox.Show(CheckJournalEntry.CheckEnrtyDate(entryDate.Text));
                return;
            }
            if (entryTime.Text != CheckJournalEntry.CheckEntryTime(entryTime.Text))
            {
                System.Windows.MessageBox.Show(CheckJournalEntry.CheckEntryTime(entryTime.Text));
                return;
            }
            if (carStateNumber.Text != CheckCar.CheckCarStateNumber(carStateNumber.Text))
            {
                System.Windows.MessageBox.Show(CheckCar.CheckCarStateNumber(carStateNumber.Text));
                return;
            }
            int           carCode       = 0;
            string        query         = @"SELECT CarCode FROM ViolatorCar WHERE CarStatetNumber = '" + carStateNumber.Text + "'";
            SqlConnection sqlConnection = new SqlConnection(connectionString);

            sqlConnection.Open();
            SqlCommand    sqlCommand = new SqlCommand(query, sqlConnection);
            SqlDataReader dataReader = sqlCommand.ExecuteReader();

            if (dataReader.HasRows)
            {
                while (dataReader.Read())
                {
                    carCode = Convert.ToInt32(dataReader[0].ToString());
                }
            }
            else
            {
                MessageBoxResult meboxResult = System.Windows.MessageBox.Show("Машины с таким номером нет в базе. Можете добавить добавить её.", "Предупреждение", MessageBoxButton.YesNo);
                if (meboxResult == MessageBoxResult.Yes)
                {
                    AddViolatorCar addViolatorCar = new AddViolatorCar();
                    addViolatorCar.Show();
                    this.Close();
                }
                return;
            }
            dataReader.Close();
            sqlConnection.Close();
            int          inspectorCode = 0;
            string       login         = string.Empty;
            StreamReader streamReader  = new StreamReader("UserLogin.txt");

            login = streamReader.ReadLine();
            streamReader.Close();
            string        query1         = @"SELECT UserCode FROM Users WHERE UserLogin = '******'";
            SqlConnection sqlConnection1 = new SqlConnection(connectionString);

            sqlConnection1.Open();
            SqlCommand    sqlCommand1 = new SqlCommand(query1, sqlConnection1);
            SqlDataReader dataReader1 = sqlCommand1.ExecuteReader();

            if (dataReader1.HasRows)
            {
                while (dataReader1.Read())
                {
                    inspectorCode = Convert.ToInt32(dataReader1[0].ToString());
                }
            }
            dataReader1.Close();
            sqlConnection1.Close();

            int           statusCode     = 0;
            string        query2         = @"SELECT ViolationStatusCode FROM ViolationStatus WHERE ViolationStatusName = 'Не оплачено'";
            SqlConnection sqlConnection2 = new SqlConnection(connectionString);

            sqlConnection2.Open();
            SqlCommand    sqlCommand2 = new SqlCommand(query2, sqlConnection2);
            SqlDataReader dataReader2 = sqlCommand2.ExecuteReader();

            if (dataReader2.HasRows)
            {
                while (dataReader2.Read())
                {
                    statusCode = Convert.ToInt32(dataReader2[0].ToString());
                }
            }
            dataReader2.Close();
            sqlConnection2.Close();
            string        findReplays   = "SELECT EntryNumber FROM ViolationsJournal WHERE EntryNumberDate = '" + Convert.ToDateTime(entryDate.Text) + "' AND EntryNumberTime = '" + TimeSpan.Parse(entryTime.Text) + "' AND UserCode = " + inspectorCode + " AND ViolationCode = " + Convert.ToInt32(violationCode.Text) + " AND CarCode = " + carCode + " AND ViolationStatusCode = " + statusCode + "";
            SqlCommand    sqlCommand3   = new SqlCommand(findReplays, connection);
            SqlDataReader sqlDataReader = sqlCommand3.ExecuteReader();

            if (sqlDataReader.HasRows)
            {
                System.Windows.MessageBox.Show("Такая запись уже есть в журнале.");
                return;
            }
            else
            {
                using (SqlConnection journalEntry = new SqlConnection(connectionString))
                    using (SqlCommand lastCommnd = journalEntry.CreateCommand())
                    {
                        lastCommnd.CommandText = "INSERT INTO ViolationsJournal (EntryNumberDate, EntryNumberTime, UserCode, ViolationCode, CarCode, ViolationStatusCode) VALUES (@date, @time, @uc, @vc, @cc, @status)";

                        lastCommnd.Parameters.AddWithValue("@date", Convert.ToDateTime(entryDate.Text));
                        lastCommnd.Parameters.AddWithValue("@time", TimeSpan.Parse(entryTime.Text));
                        lastCommnd.Parameters.AddWithValue("@uc", inspectorCode);
                        lastCommnd.Parameters.AddWithValue("@vc", Convert.ToInt32(violationCode.Text));
                        lastCommnd.Parameters.AddWithValue("@cc", carCode);
                        lastCommnd.Parameters.AddWithValue("@status", statusCode);

                        journalEntry.Open();
                        lastCommnd.ExecuteNonQuery();
                        journalEntry.Close();
                    }
                System.Windows.MessageBox.Show("Запись добавлена в журнал.");
            }
            sqlDataReader.Close();
            connection.Close();
        }