private void Button_UploadImage(object sender, RoutedEventArgs e) { var op = new OpenFileDialog { Title = "Select a photo", Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" + "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + "Portable Network Graphic (*.png)|*.png" }; if (op.ShowDialog() == true) { imgPhoto.Source = ImageLoaderHelper.GetImageFromFolder(op.FileName); _imagePath = op.FileName; IsImageExist = true; } }
public M_Users GetUserInfo(int selectedId, TextBlock nameUser, ImageBrush imageReport) { var db = new RfidContext(); var selectedUser = (from d in db.C_Users where d.ID == selectedId select d).Single(); var dir = new DirectoryInfo(Singelton.PathToPhoto); var queryPhoto = from cust in db.C_Users where cust.ID == selectedId select new { cust.Photo }; var names = db.Database.SqlQuery <M_Names>(new SqlGetUserName() .SQl_GetUserFirstName, selectedId).SingleOrDefault(); var firstName = names.NameFirst; var lastName = names.NameLast; var z = queryPhoto.ToList(); nameUser.Text = firstName + " " + lastName; var str = dir.FullName + Path.AltDirectorySeparatorChar + z[0].Photo; try { var nameImage = z[0].Photo; var words = nameImage.Split('_'); var indexdot = words[2].IndexOf('.'); nameUser.Text = words[1] + " " + words[2].Remove(indexdot); imageReport.ImageSource = ImageLoaderHelper.GetImageFromFolder(str); } catch (Exception ex) { MessageBox.Show((string)Application.Current.Resources[StringsMapper.ErrorUserPhoto] + ex); } db.Dispose(); return(selectedUser); }
public M_Users GetCurrentUser(int?selectedId, DataGrid monthlyReportGrid, DataGrid basicInformationGrid) { var db = new RfidContext(); var selectedUser = (from d in db.C_Users where d.ID == selectedId select d).Single(); var culture = App.Language; if (selectedUser.P_UserTime.ToList().Count != 0) { var queryAllCustomers = (from cust in db.C_UserTime where cust.P_Users.ID == selectedId select cust) .AsEnumerable() .Select(cust => new { cust.ID, cust.SingleDate, Day = culture.DateTimeFormat.GetDayName(((DayOfWeek)Enum.Parse(typeof(DayOfWeek), cust.Day))), cust.TimeIn, cust.TimeOut, cust.LengthOfInside, cust.LengthOfOutside }); monthlyReportGrid.ItemsSource = queryAllCustomers.ToList(); monthlyReportGrid.Items.Refresh(); } else { MessageBox.Show((string)Application.Current.Resources[StringsMapper.ErrorUserTimeNFound], (string)Application.Current.Resources[StringsMapper.ErrorHeader], MessageBoxButton.OK, MessageBoxImage.Error); monthlyReportGrid.ItemsSource = null; } // get your 'Uploaded' folder var dir = new DirectoryInfo(Singelton.PathToPhoto); var queryPhoto = from cust in db.C_Users where cust.ID == selectedId select new { cust.Photo }; var names = db.Database .SqlQuery <M_Names>(new SqlGetUserName().SQl_GetUserFirstName, (object)selectedId) .SingleOrDefault(); var firstName = names.NameFirst; var lastName = names.NameLast; var z = queryPhoto.ToList(); ((TextBlock)basicInformationGrid.FindName("NameUser")).Text = firstName + " " + lastName; var str = dir.FullName + Path.AltDirectorySeparatorChar + z[0].Photo; try { var NameImage = z[0].Photo; var words = NameImage.Split('_'); var indexdot = words[2].IndexOf('.'); ((TextBlock)basicInformationGrid.FindName("NameUser")).Text = words[1] + " " + words[2].Remove(indexdot); ((ImageBrush)basicInformationGrid.FindName("imageReport")).ImageSource = ImageLoaderHelper.GetImageFromFolder(str); } catch (Exception) { ((ImageBrush)basicInformationGrid.FindName("imageReport")).ImageSource = new BitmapImage(new Uri("pack://application:,,,/Image/ProfileIcon.png")); var message = (string)Application.Current.Resources[StringsMapper.ErrorUserPhoto]; MessageBox.Show(message, (string)Application.Current.Resources[StringsMapper.ErrorHeader], MessageBoxButton.OK, MessageBoxImage.Error); } db.Dispose(); return(selectedUser); }
public AddOrUpdateUserPage(int id) { InitializeComponent(); _iD = id; Singelton.MainWindow.ChangeStringAddres(Title + " > " + Application.Current.Resources[StringsMapper.UpdateImage]); CurrentUser = (from x in _db.C_Users where x.ID == id select x).Single(); var dir = new DirectoryInfo(Singelton.PathToPhoto); var str = dir.FullName + Path.AltDirectorySeparatorChar + CurrentUser.Photo; try { imgPhoto.Source = ImageLoaderHelper.GetImageFromFolder(str); IsImageExist = false; } catch (Exception) { MessageBox.Show((string)Application.Current.Resources[StringsMapper.ErrorUserPhoto], (string)Application.Current.Resources[StringsMapper.ErrorHeader], MessageBoxButton.OK, MessageBoxImage.Exclamation); } //UserInformationSelection var nameCurrentUser = CurrentUser.P_Names.Single(); TB_UserFN.Text = nameCurrentUser.NameFirst; TB_UserSN.Text = nameCurrentUser.NameLast; TB_UserTN.Text = nameCurrentUser.NameThird; TB_UsesrAddr.Text = CurrentUser.Address; DP_UserBithday.SelectedDate = CurrentUser.D_Birth; var phoneCurrentUser = CurrentUser.P_Phones.ToList(); AddUserHelper.SetPhones(PhoneNumber1, PhoneNumber2, PhoneNumber3, phoneCurrentUser); var cmUsers = CurrentUser.P_ManForContact.ToList(); if (cmUsers.Count > 0) { CMFirstShow.Visibility = Visibility.Visible; AddUserHelper.SetContactMan(CMFirstName1, CMSecondName1, CMThirdName1, CMPhone11, CMPhone12, CMPhone13, cmUsers[0]); } if (cmUsers.Count > 1) { CMSecondShow.Visibility = Visibility.Visible; AddUserHelper.SetContactMan(CMFirstName2, CMSecondName2, CMThirdName2, CMPhone21, CMPhone22, CMPhone23, cmUsers[1]); } if (cmUsers.Count > 2) { CMThirdShow.Visibility = Visibility.Visible; AddUserHelper.SetContactMan(CMFirstName3, CMSecondName3, CMThirdName3, CMPhone31, CMPhone32, CMPhone33, cmUsers[2]); } var depCurrentUser = CurrentUser.P_Departments; TB_DepName.Text = depCurrentUser.Name; TB_DepCode.Text = depCurrentUser.CodeFull; var derName = depCurrentUser.DepartmentDirectorName.Single(); TB_DepFN.Text = derName.NameFirst; TB_DepSN.Text = derName.NameLast; TB_DepTN.Text = derName.NameThird; AddUserHelper.SetPhones(DepartmentPhoneNumber1, DepartmentPhoneNumber2, DepartmentPhoneNumber3, depCurrentUser.DepartmentDirectorPhone.ToList()); //Rfid ShowRfid.Text = CurrentUser.P_Rfids.Last().RfidID.ToString(); // WorkTime var timeCurrentUser = CurrentUser.P_InOutValidTimes; TB_Start.SelectedTime = timeCurrentUser.Start.TimeOfDay; TB_End.SelectedTime = timeCurrentUser.End.TimeOfDay; TB_Valid.SelectedTime = timeCurrentUser.Valid.TimeOfDay; TB_HourRate.Text = CurrentUser.HourRate.ToString(); TB_OverTimerate.Text = CurrentUser.OvertimeRate.ToString(); if (timeCurrentUser.Dinner == null) { TB_Dinner.SelectedTime = DateTime.Now.TimeOfDay; } TB_Dinner.SelectedTime = ((DateTime)timeCurrentUser.Dinner).TimeOfDay; CB_IsAdmin.IsChecked = CurrentUser.IsAdmin; CB_IsDirecor.IsChecked = CurrentUser.IsDirector; }