private void Button_FindUser(object sender, RoutedEventArgs e) { Singelton.EmailSetting.SmtpClient = TB_SmtpClient.Text; Singelton.EmailSetting.MailFrom = TB_MailFrom.Text; Singelton.EmailSetting.Password = StringCipher.Encrypt(TB_Password.Password, "f6v?jkfk+8#62&D=w7UW8pkfRLdxzEaKE=LH6N?q"); Singelton.EmailSetting.Subject = TB_Subject.Text; Singelton.EmailSetting.Body = TB_Body.Text; using (var db = new RfidContext()) { var remove = db.C_EmailSetting.FirstOrDefault(); db.C_EmailSetting.Remove(remove); db.SaveChanges(); db.C_Setting.SingleOrDefault().ExportInBdSetting(); db.SaveChanges(); } if (Singelton.Frame.CanGoBack) { Singelton.Frame.GoBack(); } }
public void Ticker_Tick(object sender, EventArgs e) { _context = new RfidContext(); foreach (var user in _context.C_Users) { if (user.isInside) { if (user.P_UserTime.Count != 0) { user.P_UserTime.Last().TimeOut = DateTime.Now; TimeSpan?lengthOfInside = user.P_UserTime.Last().TimeOut - user.P_UserTime.Last().TimeIn; if (lengthOfInside > Singelton.WatcherSetting.MaxTimeInside) { lengthOfInside = Singelton.WatcherSetting.MaxTimeInside; user.P_UserTime.Last().TimeOut = user.P_UserTime.Last().TimeIn + MaxTimeInside; DateTime?dtInsige = DateTime.Today.Add(lengthOfInside.Value); user.P_UserTime.Last().LengthOfInside = dtInsige; user.isInside = false; _context.SaveChanges(); } else { } } } } _context.Dispose(); }
private void Btn_AddInterval_Click(object sender, RoutedEventArgs e) { if (DP_StarDate.SelectedDate > DP_EndDate.SelectedDate) { MessageBox.Show((string)Application.Current.Resources["msb_startIsBeggerEnd"], "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } var date = new M_Calendar(); try { date.Start = (DateTime)DP_StarDate.SelectedDate; date.End = (DateTime)DP_EndDate.SelectedDate; date.TypeDate = _calendarTypeSetting; } catch (FormatException) { MessageBox.Show((string)Application.Current.Resources["msb_slectDate"], "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); } using (var db = new RfidContext()) { if (_selectedId != null) { var user = from d in db.C_Users where d.ID == _selectedId select d; user.Single().P_Calendar.Add(date);; db.SaveChanges(); } else if (_calendarTypeSetting == CalendarType.Holideys) { db.C_Calendar.Add(date); db.SaveChanges(); return; } else { MessageBox.Show((string)Application.Current.Resources["msb_startIsBeggerEnd"]); return; } ShowDate(); } }
private void ChangeStatus_Click(object sender, RoutedEventArgs e) { if ( MessageBox.Show(((TextBlock)((StackPanel)ChangeStatus.Content).Children[0]).Text + " ?", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { _aboutHelper.ChangeStatus(CurrentUser); _db.SaveChanges(); IsInside = CurrentUser.isInside; } }
private void ClickUlinkRFID(object sender, RoutedEventArgs e) { RfidContext db = new RfidContext(); var temp = db.C_Rfids.Where(z => z.P_Users.ID == ID).Where(x => x.IsArhive == false); db.C_Rfids.Where(z => z.P_Users.ID == ID).Where(x => x.IsArhive == false).Single().IsArhive = true; db.C_Rfids.Where(z => z.P_Users.ID == ID).Where(x => x.IsArhive == false).Single().Comment = "louse"; RFIDCodeTags.Content = ""; db.SaveChanges(); }
public void Snap(int id, string rfidNum) { try { var db = new RfidContext(); var temp = db.C_Rfids.Where(z => z.P_Users.ID == id).Where(x => x.IsArhive == false); M_Users user; if (temp.Count() != 0) { foreach (var rfid in db.C_Rfids.Where(z => z.P_Users.ID == id).Where(x => x.IsArhive == false)) { rfid.IsArhive = true; } var addRfid = new M_Rfids { RfidID = Convert.ToInt64(rfidNum), IsArhive = false, Date = DateTime.Now }; user = db.C_Users.Single(z => z.ID == id); addRfid.P_Users = user; user.P_Rfids.Add(addRfid); } else { foreach (var rfid in db.C_Rfids.Where(z => z.P_Users.ID == id).Where(x => x.IsArhive == false)) { rfid.IsArhive = true; } var addRfid = new M_Rfids { RfidID = Convert.ToInt64(rfidNum), IsArhive = false, Date = DateTime.Now }; user = db.C_Users.Single(z => z.ID == id); addRfid.P_Users = user; user.P_Rfids.Add(addRfid); } db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void SaveButton_Click(object sender, RoutedEventArgs e) { Singelton.LanguageSetting.SelectedLanguage = CB_ChangeLanguage.SelectedIndex; using (var db = new RfidContext()) { db.C_Setting.SingleOrDefault().ExportInBdSetting(); db.SaveChanges(); } if (Singelton.Frame.CanGoBack) { Singelton.Frame.GoBack(); } }
private void SnapRFIDTag(object sender, RoutedEventArgs e) { try { RfidContext db = new RfidContext(); var temp = db.C_Rfids.Where(z => z.P_Users.ID == ID).Where(x => x.IsArhive == false); WindowSnapRFID snapRfid = new WindowSnapRFID(); snapRfid.ShowDialog(); if (temp.Count() != 0) { foreach (var rfid in db.C_Rfids.Where(z => z.P_Users.ID == ID).Where(x => x.IsArhive == false)) { rfid.IsArhive = true; } M_Rfids addRfid = new M_Rfids(); addRfid.RfidID = Convert.ToInt64(snapRfid.TSnapRFID.Text); addRfid.IsArhive = false; db.C_Users.Where(z => z.ID == ID).Single().P_Rfids.Add(addRfid); } else { foreach (var rfid in db.C_Rfids.Where(z => z.P_Users.ID == ID).Where(x => x.IsArhive == false)) { rfid.IsArhive = true; } M_Rfids addRfid = new M_Rfids(); addRfid.RfidID = Convert.ToInt64(snapRfid.TSnapRFID.Text); addRfid.IsArhive = false; addRfid.Date = DateTime.Now; db.C_Users.Where(z => z.ID == ID).Single().P_Rfids.Add(addRfid); } RFIDCodeTags.Content = snapRfid.TSnapRFID.Text; db.SaveChanges(); } catch { // throw; } }
private void Button_Click(object sender, RoutedEventArgs e) { Singelton.WatcherSetting.MaxTimeInside = (TimeSpan)LimitPicker.SelectedTime; Singelton.WatcherSetting.Interval = (TimeSpan)IntervalPicker.SelectedTime; using (var db = new RfidContext()) { db.C_Setting.SingleOrDefault().ExportInBdSetting(); db.SaveChanges(); } if (Singelton.Frame.CanGoBack) { Singelton.Frame.GoBack(); } }
private void SaveButton_Click(object sender, RoutedEventArgs e) { if (PathToExcelFile != string.Empty) { Singelton.ExcelSetting.Path = PathToExcelFile; using (var db = new RfidContext()) { db.C_Setting.SingleOrDefault().ExportInBdSetting(); db.SaveChanges(); } if (Singelton.Frame.CanGoBack) { Singelton.Frame.GoBack(); } } else { MessageBox.Show((string)Application.Current.Resources["msb_floderNotSelected"], "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void ClickUlinkRFID(object sender, RoutedEventArgs e) { var db = new RfidContext(); var usedRfid = db.C_Rfids.Where(z => z.P_Users.ID == ID).SingleOrDefault(x => x.IsArhive == false); if (usedRfid != null) { usedRfid.IsArhive = true; usedRfid.Comment = Application.Current.Resources[StringsMapper.Lost].ToString(); db.SaveChanges(); } else { MessageBox.Show(Application.Current.Resources[StringsMapper.AllRfidArchive].ToString(), Application.Current.Resources[StringsMapper.ErrorHeader].ToString(), MessageBoxButton.OK, MessageBoxImage.Error); } RFIDCodeTags.Text = ""; }
private void BOK_Click(object sender, RoutedEventArgs e) { try { RfidNumber = TBGetRfidId.Text; var db = new RfidContext(); var s = Convert.ToInt64(RfidNumber); var user = db.Database.SqlQuery <M_Users>(new SqlSearchUserForRfid().SQl_SearchUserForRfid, s).SingleOrDefault(); var dsd = db.C_Users.Single(z => z.ID == user.ID); AuthorithationUser = dsd; _rfidHelper.WriteById(dsd); db.SaveChanges(); var p = new AboutUserPage(AuthorithationUser.ID); Singelton.Frame.NavigationService.Navigate(p); } catch { MessageBox.Show((string)Application.Current.Resources[StringsMapper.ErrorEnterRfid], (string)Application.Current.Resources[StringsMapper.ErrorHeader], MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
private void WriteById() { try { RfidContext db = new RfidContext(); #region User information M_Users user = new M_Users(); // HelperPortDataReceived portDataReceived = new HelperPortDataReceived(); // long s = portDataReceived.ParseInData; GetRFIDIdWindow getId = new GetRFIDIdWindow(); getId.ShowDialog(); long s = Convert.ToInt64(getId.TBGetRfidId.Text); var dsd = db.C_Rfids.Where(x => x.RfidID == s).Single(); //user = db.C_Users.Where(z => z.P_Rfids.Contains(db.C_Rfids.Where(x => x.RfidID == s).Single()) ).Single(); #endregion if (dsd.P_Users.isInside == false) { TimeSpan?lengthOfInside = new TimeSpan(); if (dsd.P_Users.P_UserTime.Count != 0) { lengthOfInside = DateTime.Now - dsd.P_Users.P_UserTime.Last().TimeOut; DateTime date = DateTime.Today.Add(lengthOfInside.Value); DateTime?dtOutsige = DateTime.Today.Add(lengthOfInside.Value); dsd.P_Users.P_UserTime.Last().LengthOfOutside = dtOutsige; } dsd.P_Users.P_UserTime.Add(new M_UserTime { SingleDate = DateTime.Now.Date }); dsd.P_Users.P_UserTime.Last().Day = DateTime.Now.DayOfWeek.ToString(); dsd.P_Users.P_UserTime.Last().TimeIn = DateTime.Now; dsd.P_Users.isInside = true; } else { dsd.P_Users.P_UserTime.Last().TimeOut = DateTime.Now; TimeSpan?lengthOfInside = dsd.P_Users.P_UserTime.Last().TimeOut - dsd.P_Users.P_UserTime.Last().TimeIn; DateTime?dtInsige = DateTime.Today.Add(lengthOfInside.Value); dsd.P_Users.P_UserTime.Last().LengthOfInside = dtInsige; dsd.P_Users.isInside = false; } db.SaveChanges(); } catch { throw; } }
public void SaveSetting() { db.C_Setting.SingleOrDefault().ExportInBdSetting(); db.SaveChanges(); }
private void Button_Save_Click(object sender, RoutedEventArgs e) { try { List <Label> listLableContact = new List <Label>(); listLableContact.Add(HelperUser.FindChild <Label>(Application.Current.MainWindow, "L_ContactPhone3")); listLableContact.Add(HelperUser.FindChild <Label>(Application.Current.MainWindow, "L_ContactPhone3")); // Contact men M_Names contactManNames = new M_Names { NameFirst = TB_FN.Text, NameLast = TB_SN.Text, NameThird = TB_TN.Text }; M_Phones contacPhones = new M_Phones { PhoneNumber = TB_ContacnManPhone.Text + "," + listLableContact[0].Content.ToString() + "," + listLableContact[1].Content.ToString() }; List <M_Names> contactManNamesList = new List <M_Names>(); contactManNamesList.Add(contactManNames); List <M_Phones> phonesContactMan = new List <M_Phones>(); phonesContactMan.Add(contacPhones); List <M_Users> listUser = new List <M_Users>(); M_Users contactUserTextBox = new M_Users { P_Names = contactManNamesList, Address = TB_UsesrAddr.Text, P_Phones = phonesContactMan }; listUser.Add(contactUserTextBox); List <Label> listLable = new List <Label>(); listLable.Add(HelperUser.FindChild <Label>(Application.Current.MainWindow, "L_Contact1")); listLable.Add(HelperUser.FindChild <Label>(Application.Current.MainWindow, "L_Contact2")); foreach (Label tempLab in listLable) { if (tempLab != null) { List <M_Names> contactManNamesListLabel = new List <M_Names>(); List <M_Phones> phonesContactManLabel = new List <M_Phones>(); string contentSecond = tempLab.Content.ToString(); string[] split; split = contentSecond.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries); M_Names contactManNamesAdd = new M_Names { NameFirst = split[0], NameLast = split[1], NameThird = split[2] }; contactManNamesListLabel.Add(contactManNamesAdd); for (int i = 3; i < split.Length; i++) { M_Phones phone = new M_Phones() { PhoneNumber = split[i] }; phonesContactManLabel.Add(phone); } M_Users contactUser = new M_Users { P_Names = contactManNamesListLabel, Address = TB_UsesrAddr.Text, P_Phones = phonesContactManLabel }; listUser.Add(contactUser); } } // Address string address = TB_UsesrAddr.Text; // Birthday DateTime?birth = DP_UserBithday.SelectedDate; // Phones List <M_Phones> userPhones = new List <M_Phones>(); foreach (string item in pnoneNumbersUser) { userPhones.Add(new M_Phones { PhoneNumber = item }); } // Department M_Names departmentName = new M_Names { NameFirst = TB_DepFN.Text, NameLast = TB_DepSN.Text, NameThird = TB_DepTN.Text }; List <M_Names> departmentNames = new List <M_Names>(); departmentNames.Add(departmentName); List <M_Phones> directorPhones = new List <M_Phones>(); foreach (string item in pnoneNumbersDirector) { directorPhones.Add(new M_Phones { PhoneNumber = item }); } M_Departments department = new M_Departments { CodeFull = TB_DepCode.Text, Name = TB_DepName.Text, DepartmentDirectorName = departmentNames, DepartmentDirectorPhone = directorPhones }; // User M_Names contactManNamess = new M_Names { NameFirst = TB_UserFN.Text, NameLast = TB_UserSN.Text, NameThird = TB_UserTN.Text }; List <M_Names> pName = new List <M_Names>(); pName.Add(contactManNamess); List <M_Users> contactMan = new List <M_Users>(); // contactMan.Add(); M_Users user = new M_Users(); user.P_Names = pName; user.Address = address; user.D_Birth = birth; user.P_ManForContact = listUser; user.P_Phones = userPhones; bool isNoFind = true; foreach (var dep in db.C_Departments) { if (dep.Name == department.Name && dep.CodeFull == department.CodeFull) { dep.P_Users.Add(user); isNoFind = false; break; } } if (isNoFind) { user.P_Departments = department; } user.IsUser = true; M_Rfids rFids = new M_Rfids(); rFids.RfidID = Convert.ToInt64(ShowRfid.Text); rFids.Date = DateTime.Now; user.P_Rfids = new List <M_Rfids>(); user.P_Rfids.Add(rFids); // Image string imagepath = ((BitmapImage)imgPhoto.Source).UriSource.AbsolutePath; var imageFile = new FileInfo(imagepath); string imageName = string.Empty; if (imageFile.Exists)// check image file exist { imageName = string.Format("{0}_{1}_{2}.{3}", user.ID.ToString(), TB_UserFN.Text.Replace(" ", string.Empty), TB_UserSN.Text.Replace(" ", string.Empty), imageFile.ToString().Split('.').Last() ); // get your application folder var applicationPath = Directory.GetCurrentDirectory(); // get your 'Uploaded' folder var dir = new DirectoryInfo(System.IO.Path.Combine(applicationPath, "Photos")); if (!dir.Exists) { dir.Create(); } // Copy file to your folder imageFile.CopyTo(System.IO.Path.Combine(dir.FullName, imageName)); } user.Photo = imageName; DateTime start = new DateTime(2000, 01, 01); DateTime and = new DateTime(2000, 01, 01); DateTime valid = new DateTime(2000, 01, 01); TimeSpan start1 = TimeSpan.Parse(TB_Start.Text); TimeSpan and1 = TimeSpan.Parse(TB_And.Text); TimeSpan valid1 = TimeSpan.Parse(TB_Valid.Text); start += (start1); and += (and1); valid += (valid1); M_InOutValidTimes time = new M_InOutValidTimes { Start = start, And = and, Valid = valid }; user.P_InOutValidTimes = time; db.C_Users.Add(user); db.SaveChanges(); } catch (Exception ex) { throw; } UserInfo_Main p = new UserInfo_Main(); this.NavigationService.Navigate(p); }
public static void SaveInfo(int?iD, RfidContext db, bool isImageExist, string imagePath, Grid userInfoGrid, Grid workTimeInfoGrid, Grid contactManInfoGrid, Grid rfidGrid, Grid departmentInfoGrid) { //add or update user info if (iD != null) { var user = db.C_Users.Find(iD); UpdateUserInfo(userInfoGrid, workTimeInfoGrid, user); UpdateContactsInfo(contactManInfoGrid, user); UpdateInOutTimes(workTimeInfoGrid, user); user.Photo = GetPhotoPath(user, isImageExist, imagePath); //rfid checks and update var newRfid = Convert.ToInt64(((TextBox)userInfoGrid.FindName("ShowRfid")).Text); if (!(user.P_Rfids.FirstOrDefault().RfidID == newRfid)) { foreach (var item in db.C_Rfids) { if (item.RfidID == newRfid && item.IsArhive) { item.IsArhive = false; user.P_Rfids = new List <M_Rfids> { item }; } else if (item.RfidID == newRfid && !item.IsArhive) { MessageBox.Show((string)Application.Current.Resources[StringsMapper.ErrorBindingRfid], (string)Application.Current.Resources[StringsMapper.ErrorHeader], MessageBoxButton.OK, MessageBoxImage.Error); return; } else { user.P_Rfids = new List <M_Rfids> { GetRfidInfo(rfidGrid) }; } } } //departments checks and update var newDepName = ((TextBox)departmentInfoGrid.FindName("TB_DepName")).Text; var newDepCode = ((TextBox)departmentInfoGrid.FindName("TB_DepCode")).Text; var isNoFind = true; foreach (var dep in db.C_Departments) { if (dep.Name == newDepName && dep.CodeFull == newDepCode) { var userDepartmentDirector = user.P_Departments.DepartmentDirectorName.FirstOrDefault(); var userDepartmentPhone = user.P_Departments.DepartmentDirectorPhone.FirstOrDefault(); var departmentDirector = dep.DepartmentDirectorName.FirstOrDefault(); var departmentPhone = dep.DepartmentDirectorPhone.FirstOrDefault(); user.P_Departments.CodeFull = dep.CodeFull; user.P_Departments.Name = dep.Name; userDepartmentDirector.NameFirst = departmentDirector?.NameFirst; userDepartmentDirector.NameLast = departmentDirector?.NameLast; userDepartmentDirector.NameThird = departmentDirector?.NameThird; userDepartmentPhone.PhoneNumber = departmentPhone?.PhoneNumber; isNoFind = false; break; } } if (isNoFind) { user.P_Departments = GetDepartmentInfo(departmentInfoGrid, user); } } else { //create new user with input info var newUser = GetNewUserInfo(userInfoGrid, workTimeInfoGrid); newUser.P_ManForContact = GetAllContactsInfo(contactManInfoGrid, newUser); newUser.P_InOutValidTimes = GetInOutValidTimes(workTimeInfoGrid); newUser.Photo = GetPhotoPath(newUser, isImageExist, imagePath); //department adding & checking for existing departments var isNoFind = true; foreach (var dep in db.C_Departments) { if (dep.Name == ((TextBox)departmentInfoGrid.FindName("TB_DepName")).Text && dep.CodeFull == ((TextBox)departmentInfoGrid.FindName("TB_DepCode")).Text) { dep.P_Users.Add(newUser); isNoFind = false; break; } } if (isNoFind) { newUser.P_Departments = GetDepartmentInfo(departmentInfoGrid, newUser); } //rfid checks and adding var changeRfid = true; foreach (var itemRfid in db.C_Rfids) { if (itemRfid.RfidID == Convert.ToInt64(((TextBox)userInfoGrid.FindName("ShowRfid")).Text) && itemRfid.IsArhive) { itemRfid.IsArhive = false; itemRfid.P_Users = newUser; changeRfid = false; break; } if (itemRfid.RfidID == Convert.ToInt64(((TextBox)userInfoGrid.FindName("ShowRfid")).Text) && !itemRfid.IsArhive) { MessageBox.Show((string)Application.Current.Resources[StringsMapper.ErrorBindingRfid], (string)Application.Current.Resources[StringsMapper.ErrorHeader], MessageBoxButton.OK, MessageBoxImage.Error); return; } } if (changeRfid) { newUser.P_Rfids = new List <M_Rfids> { GetRfidInfo(rfidGrid) }; } db.C_Users.Add(newUser); } db.SaveChanges(); var p = new StartUpPage(); Singelton.Frame.NavigationService.Navigate(p); }