1
I’ve done some updates with Ingles no problem. but the way my code is, I’m having trouble. What’s the rule:
1) I have a screen where I do some reporting requests. Soon I may have n requests in progress.
2) These requests, I fill in some fields except two fields: DT_GERACAO
and BL_RELATORIO
. BL_RELATORIO must contain a binary file (LOB-Oracle field), which is the report itself(An array of bytes generated in my application).
3) So when I call the report, it should pick up the first record they find and popular these two fields null
, where the DT_GERACAO
receives DateTime.Now()
and the BL_RELATORIO
receives the generated binary file, but only one at a time, that is, each time I run the report, it searches the table in question and sees if the two fields cited are null
and then populate. The application that generates the report, is a console application and I have no context in it, only dataset. See the code below the report generator.
public static void Emitir()
{
//Relatório com DataSource = ORACLE
dsPlanoMedico.PLANO_MEDICODataTable dtPlanoMedico = new dsPlanoMedico.PLANO_MEDICODataTable();
dsPlanoMedico.POC_SOLIC_RELATORIODataTable dtSolicRel = new dsPlanoMedico.POC_SOLIC_RELATORIODataTable();
dsPlanoMedicoTableAdapters.PLANO_MEDICOTableAdapter adapt = new dsPlanoMedicoTableAdapters.PLANO_MEDICOTableAdapter();
dsPlanoMedicoTableAdapters.POC_SOLIC_RELATORIOTableAdapter solic_adapt = new dsPlanoMedicoTableAdapters.POC_SOLIC_RELATORIOTableAdapter();
adapt.Fill(dtPlanoMedico);
solic_adapt.Fill(dtSolicRel);
dtSolicRel.Where(p => p.DT_GERACAO == null && p.BL_RELATORIO == null).First();
//dtPlanoMedico.Where(i => i.IND_REGULAMENTADO == "S");
var dv = new System.Data.DataView(dtPlanoMedico);
dv.RowFilter = "IND_REGULAMENTADO LIKE 'N' and TIPO_REGISTRO_ANS LIKE 'D'";
//dv.RowFilter = "TIPO_REGISTRO_ANS LIKE 'D'";
ReportDataSource rds = new ReportDataSource("dsDados", dv);
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = "ReportBD.rdlc";
//viewer.LocalReport.SetParameters(new ReportParameter("Regulamentado", "S"));
viewer.LocalReport.DataSources.Add(rds);
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
byte[] bytesPDF = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
FileStream fsPDF = new FileStream("c:\\Relatemp\\report.pdf", FileMode.Create);
fsPDF.Write(bytesPDF, 0, bytesPDF.Length);
fsPDF.Close();
fsPDF.Dispose();
byte[] bytesExcel = viewer.LocalReport.Render("Excel", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
FileStream fsExcel = new FileStream("c:\\Relatemp\\report.xls", FileMode.Create);
fsExcel.Write(bytesExcel, 0, bytesExcel.Length);
fsExcel.Close();
fsExcel.Dispose();
byte[] bytesWord = viewer.LocalReport.Render("Word", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
FileStream fsWord = new FileStream("c:\\Relatemp\\report.doc", FileMode.Create);
fsWord.Write(bytesWord, 0, bytesWord.Length);
fsWord.Close();
fsWord.Dispose();
if(dtSolicRel.Count > 0)
{
var query = (from qr in dtSolicRel
select qr).ToList();
}
}
I tried to do my update on these lines, but it’s not working. I can’t bring the fields in var query to update:
if(dtSolicRel.Count > 0)
{
var query = (from qr in dtSolicRel
select qr).ToList();
}
bytesPDF is the binary that should be saved in the table. The table is called: POC_SOLIC_RELATORIO
. The dataset is called: dsPlanoMedico
and it already contains all the necessary tables(4). We use Reportviewer.
This is the condition for the update:
dtSolicRel.Where(p => p.DT_GERACAO == null && p.BL_RELATORIO == null).First();
I haven’t tried it yet. I did it, but I’m having doubts about how to write in the comic book, because I don’t have context and I’m a big doubt on how to do with Dataset.
dtSolicRel.Where(p => p.DT_GERACAO == null && p.BL_RELATORIO == null).First();
if (dtSolicRel.Count > 0 && bytesPDF.Length > 0)
{
var query = dtSolicRel.AsEnumerable().Where(x => x.DT_GERACAO == null && x.BL_RELATORIO == null).First();
query.BL_RELATORIO = bytesPDF;
query.DT_GERACAO = DateTime.Now;
}
EDITED BELOW
I’m doing this and I’m going to test it. What I found strange is that it didn’t accept Datetime.Now(), but like this: Datetime.Now.
var query = dtSolicRel.AsEnumerable()
.Where(x => x.DT_GERACAO == null && x.BL_RELATORIO == null).First();
query.BL_RELATORIO = bytesPDF;
query.DT_GERACAO = DateTime.Now;
solic_adapt.Update(query);
I tried to do this but is giving error due to test null, but I see no other way.
var query = (from i in dtSolicRel
//where i.DT_GERACAO == null && i.BL_RELATORIO == null
select i).ToList().First();
if(query.BL_RELATORIO == null && query.DT_GERACAO == null)
{
query.BL_RELATORIO = bytesPDF;
query.DT_GERACAO = DateTime.Now;
solic_adapt.Update(query);
}
I can’t get the datasets. For me Datasets, but you don’t have the Table property. I can’t assign anything.
– pnet
Unable to create this: Datatable dtSolicRel= dataset.Tables["Tablename"]; dtSolicRel is already a datatable and pointing to the corresponding table. see the code posted and see what I should do. I will edit the post and show what I did and my difficulties.
– pnet
your example is ok. I think this is the way, I will only now make it record only one record and exit, because that is the rule, not all null, only the first record I find, popula e só.
– pnet
Sorry for the delay, I’m happy to help... in case you are already a datatable, you don’t need the Datatable line dtSolicRel= dataset.Tables["Datatable"].
– Danilo Breda