mardi 6 septembre 2016

Why my code can't locate the data table?

I have this code below to generate a report. My problem is why one of the content of my data table can't locate by my code?. The ds.dt_ProposedSeminars is the table.

public JsonResult ReportProposal(int year)
     {
         string Userkey = "gHeOai6bFzWskyUxX2ivq4+pJ7ALwbzwF55dZvy/23BrHAfvDVj7mg  ";
         string PassKey = "lLAHwegN8zdS7mIZyZZj+EmzlkUXkvEYxLvgAYjuBVtU8sw6wKXy2g  ";

         JsonResult result = new JsonResult();
         MemoryStream oStream;

         PCSO_ProposedSeminars rpt = new PCSO_ProposedSeminars();
         dsPCSO_TrainingProgram ds = new dsPCSO_TrainingProgram();

         //-----------------------------------------------------
         var seminars = db.Certificates
            .Where(x => x.Year.Value.Year == year && !x.IsApproved.HasValue)
            .Select(z => z).Distinct();

         foreach (var train in seminars)
         {
             string trainingProgram = train.CertificateName;
             string resourcePerson = train.ResourceSpeaker;
             string target = "";

             var classifications = db.CertificateTrainingClassifications.Where(a => a.CertificateId == train.CertificateId).Select(b=>b.TrainingClassification.Classification);

             int x = 1;
             foreach (var classification in classifications)
             {
                 if (classifications.Count() > 1)
                 {
                     if (x == 1) target += classification;
                     else target +=  ", " + classification;
                 }
                 else target += classification;

                 x++;
             }

             if (train.TargetParticipants.HasValue)
             {
                 target += "/" + train.TargetParticipants.Value + ((train.TargetParticipants != null) ? " pax" : "");
             }

             if (train.IsPerBatch.Value)
             {
                 target += "/batch";
             }
             string duration = train.Duration.Value + " days";
             decimal estimatedExpenses = new decimal();
             estimatedExpenses = train.EstimatedExpenses.Value;
             ds.dt_ProposedSeminars.Adddt_ProposedSeminarsRow(
                     trainingProgram,
                     resourcePerson,
                     target,
                     duration,
                     estimatedExpenses);
         }

         DataTable dtable = new DataTable();
         dtable = ds.dt_ProposedSeminars;
         rpt.SetDataSource(dtable);
         rpt.Refresh();
         rpt.SetParameterValue(0, year);
         rpt.SetParameterValue(1, "");
         rpt.SetParameterValue(2, "Head, Training Unit, Admin Department");
         oStream = (MemoryStream)rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
         string filename = Convert.ToString((DateTime.Now.Month) + Convert.ToString(DateTime.Now.Day) + Convert.ToString(DateTime.Now.Year) + Convert.ToString(DateTime.Now.Hour) + Convert.ToString(DateTime.Now.Minute) + Convert.ToString(DateTime.Now.Second) + Convert.ToString(DateTime.Now.Millisecond)) + "RequestApplication";
         var len = oStream.Length;

         FileTransferServiceClient client2 = new FileTransferServiceClient();
         RemoteFileInfo rmi = new RemoteFileInfo();
         DateTime dt = DateTime.Now;
        DownloadRequest dr = new DownloadRequest();
         string fId = client2.UploadFileGetId("", filename, len, PassKey, Userkey, oStream);
         result.Data = new
         {
             fileId = fId,
             filename = filename
         };
         rpt.Close();
         rpt.Dispose();
         oStream.Close();
         oStream.Dispose();
         result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
         return result;
     }

Here is the picture.

Here is the error.

Aucun commentaire:

Enregistrer un commentaire