private void register_Click(object sender, RoutedEventArgs e) { if (usernamecontainer.Text != String.Empty && passwdcontainer.Password != String.Empty) { try { username = usernamecontainer.Text.ToString(); password = passwdcontainer.Password.ToString(); using (painDB_Entities db = new painDB_Entities()) { user u1 = new user { username = username, passw = password, role = "users" }; // добавление var us = db.users; if (us.Find(u1.username) == null) { db.users.Add(u1); db.SaveChanges();// сохранение изменений Message exept = new Message("Вы зарегистрированы. Попробуйте войти"); exept.ShowDialog(); } else { Message exept = new Message("Такой пользователь уже есть"); exept.ShowDialog(); } } } catch (Exception ex) { Message exept = new Message(ex.Message); exept.ShowDialog(); } } }
private void Button_Click_1(object sender, RoutedEventArgs e) //del { try { using (painDB_Entities db = new painDB_Entities()) { var a = db.pictures; foreach (picture pic in a) { if (logged.username == pic.username) { db.pictures.Remove(pic); } } db.SaveChanges(); } using (painDB_Entities db = new painDB_Entities()) { var pics = db.users; foreach (user p in pics) { if (logged.username == p.username) { db.users.Remove(p); } } db.SaveChanges(); } delet.IsEnabled = false; delet.Content = "✓"; edit.IsEnabled = false; } catch (Exception ex) { Message a = new Message(ex.Message); a.ShowDialog(); } }
public Gallery(user ab) { InitializeComponent(); logged = ab; counter = 3; try { using (painDB_Entities db = new painDB_Entities()) { var pics = db.pictures; foreach (picture p in pics) { if (p.username == logged.username) { show(p, true); } } foreach (picture p in pics) { if (p.username != logged.username) { show(p, false); } } } } catch (Exception ex) { Message exept = new Message(ex.Message); exept.ShowDialog(); } }
private void sortDate(object sender, RoutedEventArgs e) { this.stack_to_add2.Children.Clear(); this.stack_to_add1.Children.Clear(); this.stack_to_add.Children.Clear(); counter = 3; using (painDB_Entities db = new painDB_Entities()) { var pics = db.pictures.OrderByDescending(s => s.date_created); foreach (picture p in pics) { if (p.username == logged.username) { show(p, true); } } foreach (picture p in pics) { if (p.username != logged.username) { show(p, false); } } } }
private void SaveintoGallery(object sender, RoutedEventArgs e) { Infopicker inf = new Infopicker("Название или описание вашего эскиза:"); if (inf.ShowDialog() == true) { try { Save(temppic); StrokeCollection t = new StrokeCollection(ic.Strokes); ic.Strokes.Clear(); Save(tempbackg); ic.Strokes = t; var fs1 = new FileStream(tempstrokes, FileMode.Create, FileAccess.ReadWrite); ic.Strokes.Save(fs1); fs1.Close(); string str = "null"; using (painDB_Entities db = new painDB_Entities()) { str = inf.write.Text; string path = Environment.CurrentDirectory.ToString() + $@"\Resources\Data\stroke_copies\{str}.bmp"; byte[] buffer = File.ReadAllBytes(temppic); string base64String = Convert.ToBase64String(buffer, 0, buffer.Length); byte[] bufferdata = Convert.FromBase64String(base64String); byte[] bufferbg = File.ReadAllBytes(tempbackg); string base64Stringbg = Convert.ToBase64String(bufferbg, 0, bufferbg.Length); byte[] bufferdatabg = Convert.FromBase64String(base64Stringbg); picture p1 = new picture { username = logged.username, painting = bufferdata, date_created = DateTime.Now, descript = str, path = path, bg = bufferdatabg }; db.pictures.Add(p1); db.SaveChanges(); //сохраняю штрихи в хранилище var fs = new FileStream(path, FileMode.Create); ic.Strokes.Save(fs); } } catch (Exception ex) { Message exept = new Message(ex.Message); exept.ShowDialog(); } } }
private void Button_Click(object sender, RoutedEventArgs e) //edit { try { using (painDB_Entities db = new painDB_Entities()) { var pics = db.users; foreach (user p in pics) { if (logged.username == p.username) { p.passw = passw.Text; } } db.SaveChanges(); } edit.IsEnabled = false; edit.Content = "✓"; } catch (Exception ex) { Message a = new Message(ex.Message); a.ShowDialog(); } }
public Gallery(user ab, bool a) { InitializeComponent(); logged = ab; counter = 3; b1.Visibility = Visibility.Hidden; b2.Visibility = Visibility.Hidden; try { using (painDB_Entities db = new painDB_Entities()) { var users = db.users; foreach (user u in users) { UserControl1 b = new UserControl1(u); if (counter % 3 == 0) { this.stack_to_add.Children.Add(b); } else if (counter % 2 == 0) { this.stack_to_add1.Children.Add(b); } else if (counter % 1 == 0) { this.stack_to_add2.Children.Add(b); } counter -= 1; if (counter == 0) { counter = 3; } } } } catch (Exception ex) { Message exept = new Message(ex.Message); exept.ShowDialog(); } }
private void edit_Click(object sender, RoutedEventArgs e) { try { using (painDB_Entities db = new painDB_Entities()) { var pics = db.pictures; foreach (picture p in pics) { if (Convert.ToInt32(iddd.Text) == p.painting_id) { p.descript = description.Text; p.username = owner.Text; } } db.SaveChanges(); del.IsEnabled = false; del.Content = "✓"; continue_.IsEnabled = false; edit.IsEnabled = false; } } catch (Exception ex) { Message a = new Message(ex.Message); a.ShowDialog(); } }
private void del_Click(object sender, RoutedEventArgs e) { try{ using (painDB_Entities db = new painDB_Entities()) { var pics = db.pictures; foreach (picture p in pics) { if (Convert.ToInt32(iddd.Text) == p.painting_id) { db.pictures.Remove(p); } string file = Environment.CurrentDirectory.ToString() + $"\\Resources\\Data\\stroke_copies\\{p.descript}.bmp"; File.Delete(file); } db.SaveChanges(); del.IsEnabled = false; del.Content = "✓"; continue_.IsEnabled = false; edit.IsEnabled = false; } } catch (Exception ex) { Message a = new Message(ex.Message); a.ShowDialog(); } }
private void login_Click(object sender, RoutedEventArgs e) { //реализация того же, но на ado.net /* if (usernamecontainer.Text != String.Empty && passwdcontainer.Password != String.Empty) * { * username = usernamecontainer.Text.ToString(); * password = passwdcontainer.Password.ToString(); * string cmdlogin = $"select * from users where username='******' "; * using (SqlConnection connection = new SqlConnection(connectionString)) * { * listofusers.Clear(); * SqlCommand command = new SqlCommand(cmdlogin, connection); * connection.Open(); * using (SqlDataReader oReader = command.ExecuteReader()) * { * while (oReader.Read()) * { * listofusers.Add(new user(oReader["username"].ToString(), oReader["passw"].ToString())); * } * } * connection.Close(); * } * if (listofsers.Count() == 1) * { * foreach (user u in listofusers) * { * if (u.Password == password) * { * * MainWindow a = new MainWindow(); * a.Show(); * this.Close(); * } else { Message a = new Message("Неверный пароль"); a.ShowDialog(); } * } * } * else * { Message a = new Message("Такого пользователя нет. Зарегистрируйтесь"); a.ShowDialog(); } * } * else { Message a = new Message("Логин и пароль должны быть заполнены!"); a.ShowDialog(); } */ if (usernamecontainer.Text != String.Empty && passwdcontainer.Password != String.Empty) { try { username = usernamecontainer.Text.ToString(); password = passwdcontainer.Password.ToString(); using (painDB_Entities db = new painDB_Entities()) { var us = db.users; foreach (user u in us) { if (u.username == username) { listofusers.Add(u); if (u.passw == password) { new MainWindow(u).Show(); this.Close(); } else { Message a = new Message("Неверный пароль"); a.ShowDialog(); } } } if (listofusers.Count == 0) { Message a = new Message("Такого пользователя нет. Зарегистрируйтесь"); a.ShowDialog(); } } } catch (Exception ex) { Message exept = new Message(ex.Message); exept.ShowDialog(); } } else { Message a = new Message("Логин и пароль должны быть заполнены!"); a.ShowDialog(); } }