private void login_Click(object sender, RoutedEventArgs e) { App.WorkMode = (WorkMode)((ComboBoxItem)WorkModeBox.SelectedItem).Tag; using (MainModel modelContainer = new MainModel(App.WorkMode)) { string username = UserName_Box.Text; string passwordHash = Utilities.Sha256(Password_Box.Password); User user = modelContainer.UserSet.SingleOrDefault(u => u.Username == username && u.PasswordHash == passwordHash); if (user != null) { App.UserAccessLevel = user.AccessLevel; SecondaryPage sp = new SecondaryPage(); Content = sp; } else { MessageBox.Show("שגיאה בכניסה למערכת -בדוק את שם המשתמש ו\\או הסיסמא.", "שגיאה בכניסה למערכת", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void cancel_Button_Click(object sender, RoutedEventArgs e) { SecondaryPage sp = new SecondaryPage(); Content = new Frame { Content = sp }; }
private void synchronizeDataBase_Click(object sender, RoutedEventArgs e) { if (App.WorkMode == WorkMode.Local) { MessageBox.Show("לא ניתן לבצע סינכרון במצב מקומי.", "לא ניתן לבצע סינכרון", MessageBoxButton.OK, MessageBoxImage.Error); return; } MessageBox.Show("סנכרון מתחיל. נא לא לסגור את התוכנה עד לקבל הודעת סיום", "סנכרון מתחיל", MessageBoxButton.OK, MessageBoxImage.Exclamation); using (MainModel remoteModel = new MainModel(WorkMode.Main)) using (MainModel localModel = new MainModel(WorkMode.Local)) { // delete all local data localModel.PbxConnectionSet.RemoveRange(localModel.PbxConnectionSet); localModel.KolanConnectionSet.RemoveRange(localModel.KolanConnectionSet); localModel.TelnetConnectionSet.RemoveRange(localModel.TelnetConnectionSet); localModel.CheckPointVpnConnectionSet.RemoveRange(localModel.CheckPointVpnConnectionSet); localModel.FileSet.RemoveRange(localModel.FileSet); localModel.SwitchSet.RemoveRange(localModel.SwitchSet); localModel.UserSet.RemoveRange(localModel.UserSet); localModel.SaveChanges(); // add new data localModel.SwitchSet.AddRange(remoteModel.SwitchSet.AsNoTracking()); localModel.PbxConnectionSet.AddRange(remoteModel.PbxConnectionSet.AsNoTracking()); localModel.KolanConnectionSet.AddRange(remoteModel.KolanConnectionSet.AsNoTracking()); localModel.TelnetConnectionSet.AddRange(remoteModel.TelnetConnectionSet.AsNoTracking()); localModel.CheckPointVpnConnectionSet.AddRange(remoteModel.CheckPointVpnConnectionSet.AsNoTracking()); localModel.FileSet.AddRange(remoteModel.FileSet.AsNoTracking()); localModel.UserSet.AddRange(remoteModel.UserSet.AsNoTracking()); localModel.SaveChanges(); MessageBox.Show("סנכרון הסתיים", "סנכרון הסתיים", MessageBoxButton.OK, MessageBoxImage.Information); } SecondaryPage sp = new SecondaryPage(); Content = new Frame { Content = sp }; }
private void Ok_Click(object sender, RoutedEventArgs e) { if (App.UserAccessLevel > AccessLevel.Manager) { MessageBox.Show("אינך מורשה לבצע שינויים בדף זה יש לפנות למנהל המערכת", "בעיה בהרשאות", MessageBoxButton.OK, MessageBoxImage.Error); return; } int parsedSwitchId; if (string.IsNullOrWhiteSpace(ManufacturingNumber_Box.Text) || !int.TryParse(ManufacturingNumber_Box.Text, out parsedSwitchId)) { MessageBox.Show("חובה להכניס מספר בתעשיה תקין", "מספר בתעשיה לא תקין", MessageBoxButton.OK, MessageBoxImage.Error); return; } using (MainModel modelContainer = new MainModel(App.WorkMode)) { try { Switch switchToEdit = null; if (IsNewSwitch) { switchToEdit = new Switch(); modelContainer.SwitchSet.Add(switchToEdit); } else { switchToEdit = modelContainer.SwitchSet.Single(x => x.Id == _switchIdToEdit); } switchToEdit.Name = CustomerName_Box.Text; switchToEdit.CrmNum = CustomerNum_Box.Text; switchToEdit.Id = parsedSwitchId; switchToEdit.MachineType = MachineType_ComboBox.Text; switchToEdit.SwRelease = Release_ComboBox.Text; switchToEdit.Comments = Comments_Box.Text; // add the switch if necessary, because all the connections depend on it modelContainer.SaveChanges(); if (!string.IsNullOrWhiteSpace(PbxPhoneNumber_Box.Text) || !string.IsNullOrWhiteSpace(PbxUserName_Box.Text) || !string.IsNullOrWhiteSpace(PbxPass_Box.Text) || !string.IsNullOrWhiteSpace(PbxDebugPass_Box.Text) || !string.IsNullOrWhiteSpace(PbxParDataStop_ComboBox.Text)) { PbxConnection pbxEditData = switchToEdit.PbxConnection; bool newPbxConnection = false; if (pbxEditData == null) { pbxEditData = new PbxConnection(); pbxEditData.SwitchId = switchToEdit.Id; modelContainer.PbxConnectionSet.Add(pbxEditData); } pbxEditData.DialNum = PbxPhoneNumber_Box.Text; int parsedBaudRate = 0; if (int.TryParse(PbxBoudrate_ComboBox.Text, out parsedBaudRate)) { pbxEditData.BaudRate = parsedBaudRate; } pbxEditData.LoginName = PbxUserName_Box.Text; pbxEditData.LoginPassword = PbxPass_Box.Text; pbxEditData.DebugPassword = PbxDebugPass_Box.Text; pbxEditData.ParDataStop = PbxParDataStop_ComboBox.Text; } if (!string.IsNullOrWhiteSpace(KolanPhoneNumber_Box.Text)) { KolanConnection kolanEditData = switchToEdit.KolanConnection; if (kolanEditData == null) { kolanEditData = new KolanConnection(); kolanEditData.SwitchId = switchToEdit.Id; modelContainer.KolanConnectionSet.Add(kolanEditData); } kolanEditData.DialNum = KolanPhoneNumber_Box.Text; int parsedKolanBaudRate = 0; if (int.TryParse(KolanBoudrate_ComboBox.Text, out parsedKolanBaudRate)) { kolanEditData.BaudRate = parsedKolanBaudRate; } kolanEditData.ParDataStop = KolanParDataStop_ComboBox.Text; } if (!string.IsNullOrWhiteSpace(TelnetAddress_Box.Text) || !string.IsNullOrWhiteSpace(TelnetUserNameCS_Box.Text) || !string.IsNullOrWhiteSpace(TelnetPassCS_Box.Text) || !string.IsNullOrWhiteSpace(TelnetUserNameSS_Box.Text) || !string.IsNullOrWhiteSpace(TelnetPasswordSS_Box.Text)) { TelnetConnection telnetEditData = switchToEdit.TelnetConnection; if (telnetEditData == null) { telnetEditData = new TelnetConnection(); telnetEditData.SwitchId = switchToEdit.Id; modelContainer.TelnetConnectionSet.Add(telnetEditData); } telnetEditData.IpAddress = TelnetAddress_Box.Text; telnetEditData.UsernameCs = TelnetUserNameCS_Box.Text; telnetEditData.PasswordCs = TelnetPassCS_Box.Text; telnetEditData.UsernameSs = TelnetUserNameSS_Box.Text; telnetEditData.PasswordSs = TelnetPasswordSS_Box.Text; } if (!string.IsNullOrWhiteSpace(ClientAddress_Box.Text) || !string.IsNullOrWhiteSpace(SiteName_Box.Text) || !string.IsNullOrWhiteSpace(NetworkUserName_Box.Text) || !string.IsNullOrWhiteSpace(NetworkPass_Box.Text) || !string.IsNullOrWhiteSpace(NetworkPort_Box.Text)) { CheckPointVpnConnection checkPointVpnConnectionEditData = switchToEdit.CheckPointVpnConnection; if (checkPointVpnConnectionEditData == null) { checkPointVpnConnectionEditData = new CheckPointVpnConnection(); checkPointVpnConnectionEditData.SwitchId = switchToEdit.Id; modelContainer.CheckPointVpnConnectionSet.Add(checkPointVpnConnectionEditData); } checkPointVpnConnectionEditData.IpAddress = ClientAddress_Box.Text; checkPointVpnConnectionEditData.Site = SiteName_Box.Text; checkPointVpnConnectionEditData.Username = NetworkUserName_Box.Text; checkPointVpnConnectionEditData.Password = NetworkPass_Box.Text; checkPointVpnConnectionEditData.Port = string.IsNullOrWhiteSpace(NetworkPort_Box.Text) ? (short?)null : short.Parse(NetworkPort_Box.Text); } modelContainer.SaveChanges(); MessageBox.Show("השינויים נשמרו בהצלחה"); SecondaryPage sp = new SecondaryPage(); Content = new Frame { Content = sp }; } catch (DbEntityValidationException ex) { string errors = string.Empty; foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors) { foreach (DbValidationError dbValidationError in validationError.ValidationErrors) { errors += dbValidationError + "\n"; } } MessageBox.Show("בעיה בשמירת המתג:\n" + errors); } catch (Exception ex) { MessageBox.Show("בעיה בשמירת המתג." + ex); } } }