Exemple #1
0
        private async void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (DeleteOrUpdateIdErrorLabel.Visible)
                {
                    DeleteOrUpdateIdErrorLabel.Visible = false;
                }


                if (String.IsNullOrEmpty(DeleteOrUpdateIdTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateIdTextBox.Text))
                {
                    DeleteOrUpdateIdErrorLabel.Visible = true;
                }
                else
                {
                    SqlCommand command = new SqlCommand("DELETE FROM [AccountsData] WHERE [Id]=@Id", sqlCon);
                    command.Parameters.AddWithValue("Id", DeleteOrUpdateIdTextBox.Text);
                    await command.ExecuteNonQueryAsync();

                    DeleteOrUpdateIdTextBox.Clear();
                    DeleteOrUdpateDescriptionOfAccountTextBox.Clear();
                    DeleteOrUpdateLoginTextBox.Clear();
                    DeleteOrUpdatePasswordTextBox.Clear();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Идентификатор представляет собой число!");
            }
        }
Exemple #2
0
        private async void UpdateFieldButton_Click(object sender, EventArgs e)
        {
            if (DeleteOrUdpateOneFieldErrorLabel.Visible)
            {
                DeleteOrUdpateOneFieldErrorLabel.Visible = false;
            }
            if (DeleteOrUpdateIdErrorLabel.Visible)
            {
                DeleteOrUpdateIdErrorLabel.Visible = false;
            }
            try
            {
                if ((String.IsNullOrEmpty(DeleteOrUpdateIdTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateIdTextBox.Text)) && (String.IsNullOrEmpty(DeleteOrUdpateDescriptionOfAccountTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUdpateDescriptionOfAccountTextBox.Text)) && (String.IsNullOrEmpty(DeleteOrUpdateLoginTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateLoginTextBox.Text)) && (String.IsNullOrEmpty(DeleteOrUpdatePasswordTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdatePasswordTextBox.Text)))
                {
                    DeleteOrUdpateOneFieldErrorLabel.Visible = true;
                    DeleteOrUpdateIdErrorLabel.Visible       = true;
                }
                if (!(String.IsNullOrEmpty(DeleteOrUpdateIdTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateIdTextBox.Text)) && (String.IsNullOrEmpty(DeleteOrUdpateDescriptionOfAccountTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUdpateDescriptionOfAccountTextBox.Text)) && (String.IsNullOrEmpty(DeleteOrUpdateLoginTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateLoginTextBox.Text)) && (String.IsNullOrEmpty(DeleteOrUpdatePasswordTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdatePasswordTextBox.Text)))
                {
                    DeleteOrUdpateOneFieldErrorLabel.Visible = true;
                }
                if ((String.IsNullOrEmpty(DeleteOrUpdateIdTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateIdTextBox.Text)) && !((String.IsNullOrEmpty(DeleteOrUdpateDescriptionOfAccountTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUdpateDescriptionOfAccountTextBox.Text)) && (String.IsNullOrEmpty(DeleteOrUpdateLoginTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateLoginTextBox.Text)) && (String.IsNullOrEmpty(DeleteOrUpdatePasswordTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdatePasswordTextBox.Text))))
                {
                    DeleteOrUpdateIdErrorLabel.Visible = true;
                }
                if (!(String.IsNullOrEmpty(DeleteOrUdpateDescriptionOfAccountTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUdpateDescriptionOfAccountTextBox.Text)) && ((String.IsNullOrEmpty(DeleteOrUpdateLoginTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateLoginTextBox.Text)) && (String.IsNullOrEmpty(DeleteOrUpdatePasswordTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdatePasswordTextBox.Text))))
                {
                    if (String.IsNullOrEmpty(DeleteOrUpdateIdTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateIdTextBox.Text))
                    {
                        DeleteOrUpdateIdErrorLabel.Visible = true;
                    }
                    else
                    {
                        SqlCommand command = new SqlCommand("UPDATE [AccountsData] SET  [Description_of_account]=@Description_of_account WHERE [Id]=@Id", sqlCon);
                        command.Parameters.AddWithValue("Id", DeleteOrUpdateIdTextBox.Text);
                        command.Parameters.AddWithValue("Description_of_account", DeleteOrUdpateDescriptionOfAccountTextBox.Text);
                        await command.ExecuteNonQueryAsync();

                        DeleteOrUpdateIdTextBox.Clear();
                        DeleteOrUdpateDescriptionOfAccountTextBox.Clear();
                        MessageBox.Show("Изменения сохранены!");
                    }
                }
                else if (!(String.IsNullOrEmpty(DeleteOrUpdateLoginTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateLoginTextBox.Text)) && ((String.IsNullOrEmpty(DeleteOrUdpateDescriptionOfAccountTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUdpateDescriptionOfAccountTextBox.Text)) && (String.IsNullOrEmpty(DeleteOrUpdatePasswordTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdatePasswordTextBox.Text))))
                {
                    if (String.IsNullOrEmpty(DeleteOrUpdateIdTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateIdTextBox.Text))
                    {
                        DeleteOrUpdateIdErrorLabel.Visible = true;
                    }
                    else
                    {
                        SqlCommand command = new SqlCommand("UPDATE [AccountsData] SET [Login_of_account]=@Login_of_account WHERE [Id]=@Id", sqlCon);
                        command.Parameters.AddWithValue("Id", DeleteOrUpdateIdTextBox.Text);
                        command.Parameters.AddWithValue("Login_of_account", DeleteOrUpdateLoginTextBox.Text);
                        await command.ExecuteNonQueryAsync();

                        DeleteOrUpdateIdTextBox.Clear();
                        DeleteOrUpdateLoginTextBox.Clear();
                        MessageBox.Show("Изменения сохранены!");
                    }
                }
                else if (!(String.IsNullOrEmpty(DeleteOrUpdatePasswordTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdatePasswordTextBox.Text)) && ((String.IsNullOrEmpty(DeleteOrUdpateDescriptionOfAccountTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUdpateDescriptionOfAccountTextBox.Text)) && (String.IsNullOrEmpty(DeleteOrUpdateLoginTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateLoginTextBox.Text))))
                {
                    if (String.IsNullOrEmpty(DeleteOrUpdateIdTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateIdTextBox.Text))
                    {
                        DeleteOrUpdateIdErrorLabel.Visible = true;
                    }
                    else
                    {
                        SqlCommand command = new SqlCommand("UPDATE [AccountsData] SET [Pass_of_account]=@Pass_of_account WHERE [Id]=@Id", sqlCon);
                        command.Parameters.AddWithValue("Id", DeleteOrUpdateIdTextBox.Text);
                        command.Parameters.AddWithValue("Pass_of_account", DeleteOrUpdatePasswordTextBox.Text);
                        await command.ExecuteNonQueryAsync();

                        DeleteOrUpdateIdTextBox.Clear();
                        DeleteOrUpdatePasswordTextBox.Clear();
                        MessageBox.Show("Изменения сохранены!");
                    }
                }
                else if ((!(String.IsNullOrEmpty(DeleteOrUdpateDescriptionOfAccountTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUdpateDescriptionOfAccountTextBox.Text)) && !((String.IsNullOrEmpty(DeleteOrUpdateLoginTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateLoginTextBox.Text)))) && (String.IsNullOrEmpty(DeleteOrUpdatePasswordTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdatePasswordTextBox.Text)))
                {
                    if (String.IsNullOrEmpty(DeleteOrUpdateIdTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateIdTextBox.Text))
                    {
                        DeleteOrUpdateIdErrorLabel.Visible = true;
                    }
                    else
                    {
                        SqlCommand command = new SqlCommand("UPDATE [AccountsData] SET  [Description_of_account]=@Description_of_account, [Login_of_account]=@Login_of_account  WHERE [Id]=@Id", sqlCon);
                        command.Parameters.AddWithValue("Id", DeleteOrUpdateIdTextBox.Text);
                        command.Parameters.AddWithValue("Description_of_account", DeleteOrUdpateDescriptionOfAccountTextBox.Text);
                        command.Parameters.AddWithValue("Login_of_account", DeleteOrUpdateLoginTextBox.Text);
                        await command.ExecuteNonQueryAsync();

                        DeleteOrUpdateIdTextBox.Clear();
                        DeleteOrUdpateDescriptionOfAccountTextBox.Clear();
                        DeleteOrUpdateLoginTextBox.Clear();
                        MessageBox.Show("Изменения сохранены!");
                    }
                }
                else if ((!(String.IsNullOrEmpty(DeleteOrUdpateDescriptionOfAccountTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUdpateDescriptionOfAccountTextBox.Text)) && !((String.IsNullOrEmpty(DeleteOrUpdatePasswordTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdatePasswordTextBox.Text)))) && (String.IsNullOrEmpty(DeleteOrUpdateLoginTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateLoginTextBox.Text)))
                {
                    if (String.IsNullOrEmpty(DeleteOrUpdateIdTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateIdTextBox.Text))
                    {
                        DeleteOrUpdateIdErrorLabel.Visible = true;
                    }
                    else
                    {
                        SqlCommand command = new SqlCommand("UPDATE [AccountsData] SET  [Description_of_account]=@Description_of_account, [Pass_of_account]=@Pass_of_account  WHERE [Id]=@Id", sqlCon);
                        command.Parameters.AddWithValue("Id", DeleteOrUpdateIdTextBox.Text);
                        command.Parameters.AddWithValue("Description_of_account", DeleteOrUdpateDescriptionOfAccountTextBox.Text);
                        command.Parameters.AddWithValue("Pass_of_account", DeleteOrUpdatePasswordTextBox.Text);
                        await command.ExecuteNonQueryAsync();

                        DeleteOrUpdateIdTextBox.Clear();
                        DeleteOrUdpateDescriptionOfAccountTextBox.Clear();
                        DeleteOrUpdatePasswordTextBox.Clear();
                        MessageBox.Show("Изменения сохранены!");
                    }
                }
                else if ((!(String.IsNullOrEmpty(DeleteOrUpdateLoginTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateLoginTextBox.Text)) && !((String.IsNullOrEmpty(DeleteOrUpdatePasswordTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdatePasswordTextBox.Text)))) && (String.IsNullOrEmpty(DeleteOrUdpateDescriptionOfAccountTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUdpateDescriptionOfAccountTextBox.Text)))
                {
                    if (String.IsNullOrEmpty(DeleteOrUpdateIdTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateIdTextBox.Text))
                    {
                        DeleteOrUpdateIdErrorLabel.Visible = true;
                    }
                    else
                    {
                        SqlCommand command = new SqlCommand("UPDATE [AccountsData] SET   [Login_of_account]=@Login_of_account, [Pass_of_account]=@Pass_of_account  WHERE [Id]=@Id", sqlCon);
                        command.Parameters.AddWithValue("Id", DeleteOrUpdateIdTextBox.Text);
                        command.Parameters.AddWithValue("Login_of_account", DeleteOrUpdateLoginTextBox.Text);
                        command.Parameters.AddWithValue("Pass_of_account", DeleteOrUpdatePasswordTextBox.Text);
                        await command.ExecuteNonQueryAsync();

                        DeleteOrUpdateIdTextBox.Clear();
                        DeleteOrUpdateLoginTextBox.Clear();
                        DeleteOrUpdatePasswordTextBox.Clear();
                        MessageBox.Show("Изменения сохранены!");
                    }
                }
                else
                {
                    if (String.IsNullOrEmpty(DeleteOrUpdateIdTextBox.Text) && String.IsNullOrWhiteSpace(DeleteOrUpdateIdTextBox.Text))
                    {
                        DeleteOrUpdateIdErrorLabel.Visible = true;
                    }
                    else
                    {
                        SqlCommand command = new SqlCommand("UPDATE [AccountsData] SET  [Description_of_account]=@Description_of_account, [Login_of_account]=@Login_of_account, [Pass_of_account]=@Pass_of_account WHERE [Id]=@Id", sqlCon);
                        command.Parameters.AddWithValue("Id", DeleteOrUpdateIdTextBox.Text);
                        command.Parameters.AddWithValue("Description_of_account", DeleteOrUdpateDescriptionOfAccountTextBox.Text);
                        command.Parameters.AddWithValue("Login_of_account", DeleteOrUpdateLoginTextBox.Text);
                        command.Parameters.AddWithValue("Pass_of_account", DeleteOrUpdatePasswordTextBox.Text);
                        await command.ExecuteNonQueryAsync();

                        DeleteOrUpdateIdTextBox.Clear();
                        DeleteOrUdpateDescriptionOfAccountTextBox.Clear();
                        DeleteOrUpdateLoginTextBox.Clear();
                        DeleteOrUpdatePasswordTextBox.Clear();
                        MessageBox.Show("Изменения сохранены!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Идентификатор представляет собой число!");
            }
        }