private void DisplayShopsOnMap(double radius) { GMapOverlay shop_overlay = new GMapOverlay("Shops"); using (SearchProductsEntities db = new SearchProductsEntities()) { var results = db.Shops.Join(db.ShopsAdress, // второй набор p => p.Id, // свойство-селектор объекта из первого набора c => c.Shop_id, // свойство-селектор объекта из второго набора (p, c) => new { shop_name = p.ShopName, shop_adress = c.ShopAdress, shop_lat = c.ShopLatitude, shop_lon = c.ShopLongitude }); try { foreach (var shop in results) { var distance = ComputeDistance((double)shop.shop_lat, (double)shop.shop_lon); if (distance <= radius) { PointLatLng point = new PointLatLng((double)shop.shop_lat, (double)shop.shop_lon); GMarkerGoogle marker = new GMarkerGoogle(point, GMarkerGoogleType.blue); shop_overlay.Markers.Add(marker); } } } catch { } } gMapControl1.Overlays.Add(shop_overlay); gMapControl1.Zoom = 14; }
private void bunifuThinButton21_Click(object sender, EventArgs e) { oldEmailTextbox.LineIdleColor = Color.Gray; newEmailTextBox.LineIdleColor = Color.Gray; if (String.IsNullOrEmpty(oldEmailTextbox.Text)) { oldEmailTextbox.LineIdleColor = Color.Red; return; } if (String.IsNullOrEmpty(newEmailTextBox.Text)) { newEmailTextBox.LineIdleColor = Color.Red; return; } #region Изменить емейл using (SearchProductsEntities db = new SearchProductsEntities()) { Users user = db.Users.Where(x => x.UserLogin == CUser.CurrentUser).FirstOrDefault(); if (user.UserEmail == oldEmailTextbox.Text) { oldEmailTextbox.LineIdleColor = Color.Red; return; } else { user.UserEmail = newEmailTextBox.Text; db.SaveChanges(); label3.Visible = true; } } #endregion }
public ShopsUserControl() { InitializeComponent(); gMapControl1.ShowCenter = false; gMapControl1.RoutesEnabled = true; gMapControl1.CanDragMap = true; gMapControl1.MarkersEnabled = true; gMapControl1.DragButton = MouseButtons.Left; GoogleMapProvider.Language = LanguageType.Russian; GMapProviders.GoogleMap.ApiKey = @"AIzaSyCyUssDzzAFVD5sqSoy-X_L5fEvC-JyMhU"; gMapControl1.MapProvider = GMapProviders.GoogleMap; using (SearchProductsEntities db = new SearchProductsEntities()) { var results = db.Shops.Join(db.ShopsAdress, // второй набор p => p.Id, // свойство-селектор объекта из первого набора c => c.Shop_id, // свойство-селектор объекта из второго набора (p, c) => new { shop_name = p.ShopName, shop_adress = c.ShopAdress, shop_lat = c.ShopLatitude, shop_lon = c.ShopLongitude }); foreach (var shop in results) { SearchDataGrid.Rows.Add(shop.shop_name, shop.shop_adress); } } }
private bool LoginExists(string user_login) { using (SearchProductsEntities db = new SearchProductsEntities()) { var vc = db.Users.Where(x => x.UserLogin == user_login).FirstOrDefault(); return(vc != null ? false : true); } }
private void searchButton_Click(object sender, EventArgs e) { SearchDataGrid.Rows.Clear(); errorLabel.Visible = false; successLabel.Visible = true; string product_to_search = bunifuMetroTextbox1.Text; #region Обработка ввода пустых строк if (String.IsNullOrEmpty(product_to_search)) //Проверка на ввод пустых значений { errorLabel.Text = "Введите название товара"; errorLabel.Visible = true; return; } #endregion #region Запрос к БД на поиск using (SearchProductsEntities db = new SearchProductsEntities()) { var results = db.Products.Join(db.Prices, // второй набор p => p.Product_id, // свойство-селектор объекта из первого набора c => c.Product_id, // свойство-селектор объекта из второго набора (p, c) => new { volume = p.ProductVolume, name = p.ProductName, shop = c.Shop_id, price = c.ProductPrice }).Where(x => x.name.Contains(product_to_search)); #region Запрос не найден if (results.Count() == 0) { errorLabel.Text = "По данному запросу ничего не найдено"; errorLabel.Visible = true; } #endregion #region Добавление в таблицу int row_number = 1; foreach (var res in results) { var shop = db.Shops.Where(x => x.Id == res.shop).Select(x => x.ShopName); foreach (var f in shop) { SearchDataGrid.Rows.Add(row_number, res.name, res.volume, f.ToString(), res.price.ToString()); } row_number++; } #endregion } #endregion }
private void authButtom_Click(object sender, EventArgs e) { using (SearchProductsEntities db = new SearchProductsEntities()) { var pass = db.Users.Where(x => x.UserLogin == LoginTextBox.Text).FirstOrDefault(); if (pass != null) { if (String.Compare(pass.UserPassword, Crypto.Hash(PasswordTextBox.Text)) == 0) { CUser.CurrentUser = LoginTextBox.Text; CUser.UserPhoto = ImageConvertion.RetriveImage(pass.UserPhoto); CUser.City = pass.UserCity; CUser.UserName = pass.UserName; CUser.UserSName = pass.UserSecondName; CUser.RegDate = pass.UserRegistrationDate; if (isAdmin.Checked) { if (pass.UserAdminRights) { CUser.CurrentUser = LoginTextBox.Text; AdminForm1 af = new AdminForm1(); this.Hide(); af.Show(); } else { rightsErrorLabel.Visible = true; //Сообщение об ошибке } } else { CUser.CurrentUser = LoginTextBox.Text; MainForm mf = new MainForm(); this.Hide(); mf.Show(); } } else { wrongPassLabel.Visible = true; //Сообщение об ошибке } } else { wrongLoginLabel.Visible = true; //Сообщение об ошибке } } }
private void ChangePasswordButton_Click(object sender, EventArgs e) { oldPsswordTextBox.BorderColorIdle = Color.Gray; newPasswordTextBox.BorderColorIdle = Color.Gray; confirmNewPasswordTextBox.BorderColorIdle = Color.Gray; if (String.IsNullOrEmpty(oldPsswordTextBox.Text)) { oldPsswordTextBox.BorderColorIdle = Color.Red; return; } if (String.IsNullOrEmpty(newPasswordTextBox.Text)) { newPasswordTextBox.BorderColorIdle = Color.Red; return; } #region Изменить пароль using (SearchProductsEntities db = new SearchProductsEntities()) { Users user = db.Users.Where(x => x.UserLogin == CUser.CurrentUser).FirstOrDefault(); if (String.Compare(user.UserPassword, Crypto.Hash(oldPsswordTextBox.Text)) == 0) { if (newPasswordTextBox.Text.Length < 6) { newPasswordTextBox.BorderColorIdle = Color.Red; return; } if (confirmNewPasswordTextBox.Text != newPasswordTextBox.Text) { confirmNewPasswordTextBox.BorderColorIdle = Color.Red; return; } else { user.UserPassword = Crypto.Hash(newPasswordTextBox.Text); db.SaveChanges(); label2.Visible = true; } } else { oldPsswordTextBox.BorderColorIdle = Color.Red; } } #endregion }
private void AddPhoto(object ofds) { OpenFileDialog ofd = (OpenFileDialog)ofds; try { #region Добавить в базу фото using (SearchProductsEntities db = new SearchProductsEntities()) { Users user = db.Users.Where(x => x.UserLogin == CUser.CurrentUser).FirstOrDefault(); user.UserPhoto = ImageConvertion.ConvertToByteArray(Image.FromFile(ofd.FileName)); db.SaveChanges(); // circularPictureBox1.Image = ImageConvertion.RetriveImage(user.UserPhoto); } #endregion } catch (OutOfMemoryException ex) { MessageBox.Show(ex.Message); } }
private void saveChangesButton_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(changedNameTextbox.Text)) { changedNameTextbox.LineIdleColor = Color.Red; return; } #region Изменить информацию using (SearchProductsEntities db = new SearchProductsEntities()) { Users user = db.Users.Where(x => x.UserLogin == CUser.CurrentUser).FirstOrDefault(); user.UserName = changedNameTextbox.Text; user.UserSecondName = changedSNameTextbox.Text; user.UserCity = ChangedCityTextBox.Text; db.SaveChanges(); label1.Visible = true; nameTextBox.Text = user.UserName; SecondNameTextBox.Text = user.UserSecondName; CityTextBox.Text = user.UserCity; } #endregion }
private void bunifuThinButton21_Click(object sender, EventArgs e) { ClearErrors(); #region Проверка полей if (Password2TextBox.Text != PasswordTextBox.Text) { passwordMatchErrorLabel.Text = "Пароли должны совпадать"; passwordErrorLabel.Visible = true; return; } if (String.IsNullOrEmpty(NameTextBox.Text)) { nameErrorLabel.Text = "Необходимо указать имя"; nameErrorLabel.Visible = true; return; } if (String.IsNullOrEmpty(LoginTextBox.Text)) { loginErrorLabel.Text = "Необходимо указать логин"; loginErrorLabel.Visible = true; return; } if (String.IsNullOrEmpty(EmailTextBox.Text)) { emailErrorLabel.Text = "Необходимо указать почту"; emailErrorLabel.Visible = true; return; } if (String.IsNullOrEmpty(PasswordTextBox.Text)) { passwordErrorLabel.Text = "Необходимо указать пароль"; passwordErrorLabel.Visible = true; return; } if (String.IsNullOrEmpty(Password2TextBox.Text)) { passwordMatchErrorLabel.Text = "Необходимо указать пароль"; passwordMatchErrorLabel.Visible = true; return; } if (!EmailExists(EmailTextBox.Text)) //Почта совпадает { emailErrorLabel.Text = "Указанный адресс уже используется"; emailErrorLabel.Visible = true; return; } if (!LoginExists(LoginTextBox.Text)) //Логин совпадает { loginErrorLabel.Text = "Указанный логин уже используется"; loginErrorLabel.Visible = true; return; } if (PasswordTextBox.Text.Length < 6) { passwordErrorLabel.Text = "Минимальная длина пароля 6 символов"; passwordErrorLabel.Visible = true; return; } #endregion Users user = new Users(); user.UserName = NameTextBox.Text; user.UserLogin = LoginTextBox.Text; user.UserEmail = EmailTextBox.Text; user.UserEmailConfirmed = false; user.UserAdminRights = false; user.UserCity = "Пермь"; user.UserRegistrationDate = DateTime.Now.ToString(); #region Хэширование пароля user.UserPassword = Crypto.Hash(PasswordTextBox.Text); #endregion #region Добавление в базу using (SearchProductsEntities db = new SearchProductsEntities()) { db.Users.Add(user); db.SaveChanges(); } #endregion panel1.Visible = true; }