Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am showing the payslip using wpf mvvm.First time its showing payslip.

i selected another payslip but wpfpdfviewer shows the previous payslip.

The code is
C#
public PdfView(PdfViewModel viewModel)
{
  InitializeComponent();
  this.DataContext = viewModel;
  string Exepath = System.Reflection.Assembly.GetExecutingAssembly().Location;
  string Directory = System.IO.Path.GetDirectoryName(Exepath);
  string Path =  Directory + "\\Employee.pdf" ;
  pdfViewer.LoadFile(Path);
  if(System.IO.File.Exists(Path))
  {
    System.IO.File.Delete(Path);
  }  
}


But in the save path, its showing corret month payslip.

In the Ui,its showing whatever is showing for the firstime ,every time its showing the first time payslip.

C#
private void ExecuteGetPayslip()
      {
          if (AnnualData == null || AnnualContextItem.Id == -1)
          {
              //RaiseNotifyValidation(Resources.Failure, Resources.ErrorMessage);
              MessageBox.Show("Please Select Payslip.");
          }
          else
          {
              AppController.UserInstance.InitializeLoader(Resources.DefaultLoadingMessage);
              UserMetadata userMetaData = AppMonitor.GetSession();
              string pdfPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
              if (userMetaData != null)
              {
                  var absenceTypeWithReasonParams =
                         new Dictionary<string, string>();
                  var absenceTypeWithReasonBodyParams =
                       new Dictionary<string, string>();
                  absenceTypeWithReasonParams.Add(Resources.UserId, userMetaData.userId);
                  absenceTypeWithReasonParams.Add(Resources.SessionToken, userMetaData.sessionToken);
                  absenceTypeWithReasonParams.Add(Resources.DeviceType, Resources.DeviceName);
                  absenceTypeWithReasonParams.Add("personId", personId);
                  absenceTypeWithReasonParams.Add("actionContextId", Convert.ToString(AnnualContextItem.Id));
                  var apiServiceHelper = new CommonServiceHelper();
                  var response = apiServiceHelper.SendMessage(ServiceUrlConstants.GetPaySlipRequestId(), absenceTypeWithReasonParams);
                  if (string.IsNullOrEmpty(response))
                      RaiseNotifyValidation(Resources.Failure, Resources.ErrorMessage);
                  var obj = JsonHelper.ConvertJsonStringToObject<LoginResponse>(response);
                  if (obj.Status == Resources.Success)
                  {
                      RequestId = Convert.ToString(obj.Data.RequestId);
                      //var parameters = new NavigationParameters();
                      //parameters.Add("RequestId", RequestId);
                  }
                  else
                  {
                      AppController.UserInstance.UnInitilizeLoader();
                      RaiseNotifyValidation(obj.Status, obj.Message);

                  }
                  var pdfResponse = apiServiceHelper.PostRequest(ServiceUrlConstants.getPaySlipStatus(), absenceTypeWithReasonParams, absenceTypeWithReasonBodyParams, "" + "?reqId=" + Convert.ToString(RequestId));
                  if (!string.IsNullOrEmpty(pdfResponse))
                  {
                       var pdfobj = JsonHelper.ConvertJsonStringToObject<PayslipResponse>(pdfResponse);
                       if (pdfobj.Data.PaySlipStatus == "Failure")
                      {
                          RaiseNotifyValidation(obj.Status, "Payslip is not generated for this user.");
                          AppController.UserInstance.UnInitilizeLoader();
                      }
                       else if (pdfobj.Data.PaySlipStatus == "Completed")
                      {
                          absenceTypeWithReasonBodyParams.Add("reqId", Convert.ToString(RequestId));
                          var pdfresponse = apiServiceHelper.PostRequestForByteArray(ServiceUrlConstants.GetPaySlip(), absenceTypeWithReasonParams, absenceTypeWithReasonBodyParams);
                          System.IO.File.WriteAllBytes(pdfPath + "\\Employee.pdf", pdfresponse);
                          var regionManager = (RegionManager)ServiceLocator.Current.GetInstance<IRegionManager>();
                          var AbsenceModuleView = new Uri(Resources.PdfView, UriKind.Relative);
                          regionManager.RequestNavigate(RegionNames.MainContentRegion, AbsenceModuleView);
                          AppController.UserInstance.UnInitilizeLoader();
                      }
                      else
                      {
                          int x = 0;
                          do
                          {
                              AppController.UserInstance.InitializeLoader(Resources.DefaultLoadingMessage);
                              pdfResponse = apiServiceHelper.PostRequest(ServiceUrlConstants.getPaySlipStatus(), absenceTypeWithReasonParams, absenceTypeWithReasonBodyParams, "" + "?reqId=" + Convert.ToString(RequestId));
                              pdfobj = JsonHelper.ConvertJsonStringToObject<PayslipResponse>(pdfResponse);
                              x++;
                          } while (pdfobj.Data.PaySlipStatus != "Completed");
                          absenceTypeWithReasonBodyParams.Add("reqId", Convert.ToString(RequestId));
                          var pdfresponse = apiServiceHelper.PostRequestForByteArray(ServiceUrlConstants.GetPaySlip(), absenceTypeWithReasonParams, absenceTypeWithReasonBodyParams);
                          System.IO.File.WriteAllBytes(pdfPath + "\\Employee.pdf", pdfresponse);
                          var regionManager = (RegionManager)ServiceLocator.Current.GetInstance<IRegionManager>();
                          var AbsenceModuleView = new Uri(Resources.PdfView, UriKind.Relative);
                          regionManager.RequestNavigate(RegionNames.MainContentRegion, AbsenceModuleView);
                          AppController.UserInstance.UnInitilizeLoader();

                      }

                  }
                  else
                  {
                      RaiseNotifyValidation(Resources.Failure, Resources.ErrorMessage);
                  }
                  AppController.UserInstance.UnInitilizeLoader();
              }
          }

      }




Can you please help me?
Posted
Updated 26-Nov-14 21:22pm
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900