Пример #1
0
        private void save_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(programmAdd.Text))
            {
                return;
            }
            if (string.IsNullOrEmpty(loginAdd.Text))
            {
                return;
            }
            if (string.IsNullOrEmpty(passAdd.Text))
            {
                return;
            }

            var value = new PAStruct();

            value.program  = EncryptString(programmAdd.Text);
            value.login    = EncryptString(loginAdd.Text);
            value.password = EncryptString(passAdd.Text);
            try
            {
                using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Append)))
                {
                    writer.Write(value.program);
                    writer.Write(value.login);
                    writer.Write(value.password);
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
            AddValues.IsOpen = false;
            listBox.Items.Clear();
            Read();
        }
Пример #2
0
 private void Read()
 {
     data = new List <PAStruct>();
     try
     {
         using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.OpenOrCreate)))
         {
             while (reader.PeekChar() > -1)
             {
                 var entry = new PAStruct
                 {
                     program  = DecryptString(reader.ReadString()),
                     login    = DecryptString(reader.ReadString()),
                     password = DecryptString(reader.ReadString()),
                 };
                 data.Add(entry);
             }
         }
     }
     catch (Exception ex) { MessageBox.Show(ex.Message); }
     foreach (var item in data)
     {
         var textblock = new TextBlock();
         var run       = new Run();
         run.Text     = item.program;
         run.FontSize = 16;
         textblock.Inlines.Add(run);
         textblock.Cursor               = Cursors.Hand;
         textblock.Padding              = new Thickness(10, 10, 10, 10);
         textblock.MouseLeftButtonDown += listBox_MouseLeftButtonDown;
         listBox.Items.Add(textblock);
     }
 }
Пример #3
0
        private void edit_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(login.Text))
            {
                return;
            }
            if (string.IsNullOrEmpty(pass.Password))
            {
                return;
            }

            if (!string.IsNullOrEmpty(passVisible.Text))
            {
                if (passVisible.Text != pass.Password)
                {
                    pass.Password = passVisible.Text;
                }
            }

            var del = data.Where(u => u.program == programm.Content.ToString()).SingleOrDefault();

            data.Remove(del);
            var newProgramm = new PAStruct();

            newProgramm.program  = programm.Content.ToString();
            newProgramm.login    = login.Text;
            newProgramm.password = pass.Password;
            data.Add(newProgramm);
            try
            {
                using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Truncate)))
                {
                    foreach (var item in data)
                    {
                        writer.Write(EncryptString(item.program));
                        writer.Write(EncryptString(item.login));
                        writer.Write(EncryptString(item.password));
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
            add.Focus();
            ShowValues.IsOpen = false;
            listBox.Items.Clear();
            Read();
        }