Ejemplo n.º 1
0
        private void ChangeViolationsJournal_Click(object sender, RoutedEventArgs e)
        {
            ChangeJournalEntry changeJournalEntry = new ChangeJournalEntry();

            changeJournalEntry.Show();
            this.Close();
        }
Ejemplo n.º 2
0
        private void BackToWindow(object sender, RoutedEventArgs e)
        {
            ChangeJournalEntry changeJournalEntry = new ChangeJournalEntry();

            changeJournalEntry.Show();
            this.Close();
        }
Ejemplo n.º 3
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();
            }
        }