private void btnUpdate_Click(object sender, RoutedEventArgs e) { string password = passwordInfo.Password.ToString(); string rePassword = rePasswordInfo.Password.ToString(); int id = documentManagerVM.CurrentUserVM.Model.Id; string fullName = documentManagerVM.CurrentUserVM.Model.FullName; string username = documentManagerVM.CurrentUserVM.Model.UserName; string image = documentManagerVM.CurrentUserVM.Model.Image; string email = documentManagerVM.CurrentUserVM.Model.Email; if (password == rePassword) { OpUserUpdate ouu = new OpUserUpdate(); ouu.User = new UserDb { User_Id = id, Username = username, Full_Name = fullName, Image = image, Password = password, Email = email }; OperationResult obj = OperationManager.Singleton.executeOperation(ouu); if ((obj == null) || (!obj.Status)) { return; } else { bool isWindowOpen = false; foreach (Window w in Application.Current.Windows) { if (w is UpdateSuccessWindow) { isWindowOpen = true; w.Activate(); } } if (!isWindowOpen) { UpdateSuccessWindow newwindow = new UpdateSuccessWindow(); if (newwindow.ShowDialog() ?? false) { passwordInfo.Password = ""; rePasswordInfo.Password = ""; btnUpdate.IsEnabled = false; Color color = Color.FromRgb(55, 71, 79); Brush background = new SolidColorBrush(color); passwordInfo.BorderBrush = background; rePasswordInfo.BorderBrush = background; } } } } else { Color color = Color.FromRgb(219, 21, 21); Brush background = new SolidColorBrush(color); passwordInfo.BorderBrush = background; rePasswordInfo.BorderBrush = background; } }
private void btnUpdateImage_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Image files (*.png, *.jpg)|*.png;*.jpg|All files (*.*)|*.*"; if (dialog.ShowDialog() ?? false) { FileInfo fileInfo = new FileInfo(dialog.FileName); long numBytes = fileInfo.Length; double dLen = Convert.ToDouble(fileInfo.Length / 1000000); // Because of limited size of 4MB if (dLen < 4) { FileStream fileStream = new FileStream(dialog.FileName, FileMode.Open, FileAccess.Read); BinaryReader binaryReader = new BinaryReader(fileStream); byte[] data = binaryReader.ReadBytes((int)numBytes); binaryReader.Close(); string fileName = this.documentManagerVM.CurrentUserVM.Model.UserName + this.documentManagerVM.CurrentUserVM.Model.Id.ToString() + dialog.SafeFileName; int userId = this.documentManagerVM.CurrentUserVM.Model.Id; //action string status = Server.UploadImage(data, fileName); fileStream.Close(); fileStream.Dispose(); if (status != null) { string password = this.documentManagerVM.CurrentUserVM.Model.Password; int id = documentManagerVM.CurrentUserVM.Model.Id; string fullName = documentManagerVM.CurrentUserVM.Model.FullName; string username = documentManagerVM.CurrentUserVM.Model.UserName; string image = status; string email = documentManagerVM.CurrentUserVM.Model.Email; OpUserUpdate ouu = new OpUserUpdate(); ouu.User = new UserDb { User_Id = id, Username = username, Full_Name = fullName, Image = image, Password = password, Email = email }; OperationResult obj = OperationManager.Singleton.executeOperation(ouu); if ((obj == null) || (!obj.Status)) { return; } else { bool isWindowOpen = false; foreach (Window w in Application.Current.Windows) { if (w is UpdateSuccessWindow) { isWindowOpen = true; w.Activate(); } } if (!isWindowOpen) { UpdateSuccessWindow newwindow = new UpdateSuccessWindow(); if (newwindow.ShowDialog() ?? false) { this.documentManagerVM.CurrentUserVM.Model.Image = status; Server.RemoveOldImage(status); } } } } else { MessageBox.Show("Unable to upload the file", "File Error"); } } else { // Display message if the file was too large to upload MessageBox.Show("The file selected exceeds the size limit for uploads.", "File Size"); } } }