private void Button_Click(object sender, RoutedEventArgs e) { using (CarServiceDBEntities1 context = new CarServiceDBEntities1()) { foreach (var brand in context.Brands) { if (brand.Name.Equals(txtRead.Text, StringComparison.InvariantCultureIgnoreCase)) { MessageBox.Show("Brand with this name already exists"); return; } } Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog(); fileDialog.Filter = "Image File (*.jpg, *.jpeg, *.png)|*.jpg; *.jpeg; *.jpe; *.jfif; *.png"; fileDialog.ShowDialog(); if (fileDialog.FileName == null || fileDialog.FileName == "") { return; } byte[] binaryImage; using (Stream stream = File.OpenRead(fileDialog.FileName)) { binaryImage = new byte[stream.Length]; stream.Read(binaryImage, 0, (int)stream.Length); } br = new Brand(); br.Name = txtRead.Text.ToString(); br.imageUrl = binaryImage; btnAdd.IsEnabled = true; } }
public Homepage() { InitializeComponent(); using (var context = new CarServiceDBEntities1()) { var CarList = context.Models.Where(i => i.Name == "/").ToList(); } ShowsNavigationUI = false; }
public RepairInfo(int repairID) { CarServiceDBEntities1 context = new CarServiceDBEntities1(); this.repairID = repairID; repair = context.Repairs.Where(i => i.Id == this.repairID).First(); DataContext = this; InitializeComponent(); }
public void delete() { using (var contex = new CarServiceDBEntities1()) { foreach (Car c in contex.Cars) { contex.Cars.Remove(c); } contex.SaveChanges(); } }
private void Button_Click(object sender, RoutedEventArgs e) { using (var context = new CarServiceDBEntities1()) { var item = datagr.SelectedItem; var selectedEmail = (datagr.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text; int selectedUserID = context.Users.Where(i => i.Email == selectedEmail).First().Id; UserInfo usInfo = new UserInfo(selectedUserID); this.NavigationService.Navigate(usInfo); } }
public Users() { ShowsNavigationUI = true; using (var context = new CarServiceDBEntities1()) { UserLIst = context.Users.OrderBy(x => x.Name).ToList(); } DataContext = this; InitializeComponent(); }
static AddUserCar() { using (CarServiceDBEntities1 context = new CarServiceDBEntities1()) { BrandsList = context.Brands.Select(i => i.Name).ToList(); } foreach (System.Reflection.PropertyInfo prop in typeof(Colors).GetProperties()) { Colours.Add(prop.Name); } }
private void AddButton_Click(object sender, RoutedEventArgs e) { AddUser adduser = new AddUser(); adduser.ShowDialog(); using (var context = new CarServiceDBEntities1()) { UserLIst = context.Users.OrderBy(x => x.Name).ToList(); User u = new User(); } OnPropertyChanged("_User"); }
/*public void Fill() * { * List<Hyperlink> hplCar = new List<Hyperlink>(); * List<TextBlock> txtCar = new List<TextBlock>(); * CarServiceDBEntities1 context = new CarServiceDBEntities1(); * Brand br; * * * txtCar.Add(new TextBlock()); * hplCar.Add(new Hyperlink()); * br = context.Brands.FirstOrDefault(); * * hplCar[0].Inlines.Add(br.Name); * hplCar[0].Foreground = Brushes.Black; * hplCar[0].FontWeight = FontWeights.Bold; * hplCar[0].TextDecorations = null; * txtCar[0].Inlines.Add(hplCar[0]); * * Border border = new Border(); * border.Width = 100; * border.Height = 100; * Grid grid = new Grid(); * border.Child = grid; * Image im = new Image(); * RenderOptions.SetBitmapScalingMode(im, BitmapScalingMode.Fant); * BorderContent(grid, im, br.imageUrl, txtCar[0]); * gr.Children.Add(border); * * * DataGridRow dhr = new DataGridRow(); * var item = datagr.SelectedItem; * int row = 0; * int col = 0; * DataGridRow r = (DataGridRow)datagr.ItemContainerGenerator.ContainerFromIndex(row); * DataGridCell RowColumn = datagr.Columns[col].GetCellContent(r).Parent as DataGridCell; * RowColumn.Content = border; * } */ public void OrderPage() { List <Brand> CarList = null; using (var context = new CarServiceDBEntities1()) { CarList = context.Brands.ToList(); } gr.Height = 450; int i = 1; List <Hyperlink> hplCar = new List <Hyperlink>(); List <TextBlock> txtCar = new List <TextBlock>(); foreach (Brand br in CarList) { txtCar.Add(new TextBlock()); hplCar.Add(new Hyperlink()); hplCar[i - 1].Inlines.Add(br.Name); hplCar[i - 1].Foreground = Brushes.Black; hplCar[i - 1].FontWeight = FontWeights.Bold; hplCar[i - 1].TextDecorations = null; txtCar[i - 1].Inlines.Add(hplCar[i - 1]); Border border = new Border(); BorderMargin(border, i); Grid grid = new Grid(); border.Child = grid; Image im = new Image(); RenderOptions.SetBitmapScalingMode(im, BitmapScalingMode.Fant); BorderContent(grid, im, br.imageUrl, txtCar[i - 1]); gr.Children.Add(border); hplCar[i - 1].Click += new RoutedEventHandler((sender, e) => hlclick(sender, e, br.Id)); im.IsMouseDirectlyOverChanged += new DependencyPropertyChangedEventHandler((sender, e) => MousePosition(sender, e, im)); im.MouseDown += new MouseButtonEventHandler(MousePressed); im.MouseUp += new MouseButtonEventHandler((sender, e) => MouseReleased(sender, e, br.Id)); i++; } }
private void BtnAdd_Click(object sender, RoutedEventArgs e) { int result = 0; txtVinNumber.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtRegNumber.GetBindingExpression(TextBox.TextProperty).UpdateSource(); foreach (TextBox txt in gr.Children.OfType <TextBox>()) { result += System.Windows.Controls.Validation.GetErrors(txt).Count; } if (result == 0) { using (CarServiceDBEntities1 context = new CarServiceDBEntities1()) { foreach (Car car in context.Cars) { if (car.WINnumber == this.VINNumber) { MessageBox.Show("Car with this VIN number already exists"); return; } if (car.RegNumber == this.RegNumber) { MessageBox.Show("Car with this registration number already exists"); return; } } Car c = new Car(); c.BrandID = br.Id; c.ModelID = context.Models.Where(i => i.Name == SelectedModel).Select(i => i.Id).First(); c.WINnumber = VINNumber; c.RegNumber = RegNumber; c.Colour = SelectedColour; c.UserID = this.id; context.Cars.Add(c); context.SaveChanges(); MessageBox.Show("Done"); this.Close(); } } }
private void BtnAdd_Click(object sender, RoutedEventArgs e) { if (!Regex.Match(txtRead.Text, @"^[A-Z]{1}[a-z]*$").Success) { MessageBox.Show("Brand name can contain only letters and must start with upper case!"); return; } else { using (CarServiceDBEntities1 context = new CarServiceDBEntities1()) { br.Name = txtRead.Text.ToString(); context.Brands.Add(br); context.SaveChanges(); MessageBox.Show("Done!"); this.Close(); } } }
private void BtnAdd_Click(object sender, RoutedEventArgs e) { txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtSurename.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtIdNumber.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtEGN.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtCountry.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtCity.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtStreet.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtPhone.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtEmail.GetBindingExpression(TextBox.TextProperty).UpdateSource(); int result = 0; foreach (TextBox txt in gr.Children.OfType <TextBox>()) { result += System.Windows.Controls.Validation.GetErrors(txt).Count; } if (result == 0) { using (var context = new CarServiceDBEntities1()) { foreach (User user in context.Users) { if (user.EGN == long.Parse(txtEGN.Text)) { MessageBox.Show("User with this EGN already exists!"); return; } if (user.IdCardNumber == long.Parse(txtIdNumber.Text)) { MessageBox.Show("User with this ID card already exists!"); return; } } User u = new User(); u.Name = txtName.Text; u.Surename = txtSurename.Text; u.IdCardNumber = long.Parse(txtIdNumber.Text); u.EGN = long.Parse(txtEGN.Text); u.Address = txtCountry.Text + ", " + txtCity.Text + ", " + txtStreet.Text; if (btnMale.IsChecked == true) { u.Gender = btnMale.Content.ToString(); } if (btnFemale.IsChecked == true) { u.Gender = btnMale.Content.ToString(); } u.PhoneNumber = txtPhone.Text; u.Email = txtEmail.Text; context.Users.Add(u); try { context.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var errors in ex.EntityValidationErrors) { foreach (var validationError in errors.ValidationErrors) { string errorMessage = validationError.ErrorMessage; MessageBox.Show(errorMessage); } } } } MessageBox.Show("Done"); this.Close(); } }