示例#1
0
 private void ChangePass_Click(object sender, RoutedEventArgs e)
 {
     if (OldPassword.Password != "" && NewPassword.Password != "" && ConfirmPassword.Password != "")
     {
         if (Crypter.CheckPass(OldPassword.Password) && NewPassword.Password == ConfirmPassword.Password)
         {
             if (OldPassword.Password != NewPassword.Password)
             {
                 Crypter.changePass(NewPassword.Password);
                 MessageBox.Show("Пароль изменен");
                 OldPassword.Password     = "";
                 NewPassword.Password     = "";
                 ConfirmPassword.Password = "";
                 return;
             }
             else
             {
                 MessageBox.Show("Пароли не должны повторяться");
                 return;
             }
         }
     }
     if (!Crypter.CheckPass(OldPassword.Password))
     {
         MessageBox.Show("Неправильно указан текущий пароль");
         return;
     }
     else if (NewPassword.Password != ConfirmPassword.Password && NewPassword.Password != "" && ConfirmPassword.Password != "")
     {
         MessageBox.Show("Новый пароль и подтверждение не совпадают.");
         return;
     }
     else
     {
         MessageBox.Show("Необходимо заполнить все поля");
     }
 }
示例#2
0
        public static async void Add(string pcName, string admPass, string biosPass, string model) //Insert new PC
        {
            SqlCommand command = new SqlCommand("INSERT INTO [Table] (PcName, Date, Responsibility, AdmPass, BiosPass, pcModel)VALUES(UPPER(@PcName), @Date, @Responsible, @AdmPass, @BiosPass, @Model)", connection);

            command.Parameters.AddWithValue("PcName", pcName);
            command.Parameters.AddWithValue("Date", DateTime.Today);
            command.Parameters.AddWithValue("Responsible", Environment.UserName);
            command.Parameters.AddWithValue("AdmPass", Crypter.RSAEncrypt(admPass));
            command.Parameters.AddWithValue("BiosPass", Crypter.RSAEncrypt(biosPass));
            command.Parameters.AddWithValue("Model", model);

            try
            {
                await command.ExecuteNonQueryAsync();

                UpdateLastPC();

                MessageBox.Show("Запись добавлена успешно.");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
示例#3
0
        public static async void LoadDB()
        {
            Comps.compsList.Clear();
            SqlDataReader reader = null;

            if (connection == null)
            {
                try
                {
                    connection = new SqlConnection(Settings2.Default.dataSource);
                    await connection.OpenAsync(); //Open connection with start programm and closing it with main window
                }
                catch
                {
                    MessageBox.Show("Не удалось установить соединение с базой. Возможно местоположение изменилось. Укажите еще раз.");
                    ChangePath();
                    return;
                }
            }

            SqlCommand command = new SqlCommand("SELECT * FROM [Table] ORDER BY PCname", connection);

            try
            {
                reader = await command.ExecuteReaderAsync();

                while (await reader.ReadAsync())
                {
                    new Comps(reader[0].ToString(), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), Crypter.RSADecrypt(reader[4].ToString()), Crypter.RSADecrypt(reader[5].ToString()), reader[6].ToString());
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
            }

            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (models == null)
                {
                    models = new List <string>();
                    GetModels();
                }
            }
        }
示例#4
0
        private static async void UpdateLastPC()
        {
            SqlDataReader reader     = null;
            SqlCommand    sqlCommand = new SqlCommand("SELECT MAX(Id) FROM [Table]");

            while (connection.State == System.Data.ConnectionState.Open)
            {
                await Task.Delay(1000);
            }

            try
            {
                reader = await sqlCommand.ExecuteReaderAsync();

                while (await reader.ReadAsync())
                {
                    Comps comp = new Comps(reader[0].ToString(), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), Crypter.RSADecrypt(reader[4].ToString()), Crypter.RSADecrypt(reader[5].ToString()), reader[6].ToString());
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }