Пример #1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                var password = Password.Password;
                if (string.IsNullOrEmpty(Login.Text) || string.IsNullOrEmpty(password))
                {
                    throw new Exception("Введите логин и пароль");
                }

                var user = new EF.User();

                using (var db = new EF.Context())
                {
                    if (!db.Users.Any(u => u.Login.Equals(Login.Text) && u.Password.Equals(password)))
                    {
                        throw new Exception("Такого пользователя не существует");
                    }
                    else
                    {
                        user = db.Users.FirstOrDefault(u => u.Login.Equals(Login.Text) && u.Password.Equals(password));
                    }
                }

                Shelf shelf = new Shelf(user);
                shelf.Show();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK);
                return;
            }
        }
Пример #2
0
 public Shelf(EF.User u)
 {
     CurrentUser = u;
     InitializeComponent();
     BooksList    = new List <EF.Book>();
     SelectedBook = new EF.Book();
     LoadComboboxItems();
 }
Пример #3
0
 public Bookmark(EF.User user, EF.Book book)
 {
     CurrentUser = user;
     CurrentBook = book;
     DataContext = this;
     db          = new EF.Context();
     InitializeComponent();
     BookmarksList = new List <EF.Bookmark>();
     LoadBookmarks();
 }
Пример #4
0
        public Read(EF.User u, EF.Book book, string text)
        {
            InitializeComponent();
            CurrentUser = u;
            CurrentBook = book;
            FlowDocument doc = new FlowDocument(new Paragraph(new Run(text)));

            AddRead();
            Rtb.Document = doc;
        }
Пример #5
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var password    = Password.Password;
                var repPassword = RepeatPassword.Password;

                if (string.IsNullOrEmpty(Login.Text) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(repPassword))
                {
                    throw new Exception("Заполните все поля");
                }
                if (Login.Text.Length > 50 || password.Length > 50)
                {
                    throw new Exception("Слишком длинный логин/пароль");
                }
                if (!password.Equals(repPassword))
                {
                    throw new Exception("Пароли должны совпадать");
                }

                using (var db = new EF.Context())
                {
                    if (db.Users.Any(u => u.Login.Equals(Login.Text)))
                    {
                        throw new Exception("Пользователь с таким именем уже существует");
                    }

                    var user = new EF.User()
                    {
                        Login    = Login.Text,
                        Password = password
                    };
                    db.Users.Add(user);
                    db.SaveChanges();
                }

                var str = "Пользователь " + Login.Text + " успешно добавлен";
                MessageBox.Show(str);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK);
                return;
            }
        }