I have an big issue to close an incident with the Dynamics CRM 2011 Organization Service. There is no CloseIncidentRequest class avaiable and also with fetch xml I've no chance:
public void CloseCase(Guid pCaseId)
{
FetchExpression fetch = new FetchExpression();
String requestMain = "";
requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
requestMain += " <s:Body>";
requestMain += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request i:type=\"b:CloseIncidentRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>IncidentResolution</c:key>";
requestMain += " <c:value i:type=\"a:Entity\">";
requestMain += " <a:Attributes>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>incidentid</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>{0}</a:Id>";
requestMain += " <a:LogicalName>incident</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>subject</c:key>";
requestMain += " <c:value i:type=\"d:string\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">Parent Case has been resolved</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Attributes>";
requestMain += " <a:EntityState i:nil=\"true\" />";
requestMain += " <a:FormattedValues />";
requestMain += " <a:Id>{1}</a:Id>";
requestMain += " <a:LogicalName>incidentresolution</a:LogicalName>";
requestMain += " <a:RelatedEntities />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>Status</c:key>";
requestMain += " <c:value i:type=\"a:OptionSetValue\">";
requestMain += " <a:Value>5</a:Value>";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>CloseIncident</a:RequestName>";
requestMain += " </request>";
requestMain += " </Execute>";
requestMain += " </s:Body>";
requestMain += "</s:Envelope>";
fetch.Query = String.Format(requestMain, pCaseId.ToString(), pCaseId.ToString());
_orgService.BeginRetrieveMultiple(fetch, CloseCaseResult, null);
Any idea to solve this problem?
Best Regards
Recheck following article about calling of IOrganizationService in silverlight - http://mileyja.blogspot.com/2011/06/retrieve-entity-in-microsoft-dynamics.html
First part of code (creation of request) should be replaced with following code:
Entity incidentresolution = new Entity()
{
LogicalName = "incidentresolution"
};
incidentresolution["subject"] = "Incident was closed";
incidentresolution["incidentid"] = new EntityReference()
{
Id = Guid.Empty,
LogicalName = "incident"
};
OrganizationRequest request = new OrganizationRequest()
{
RequestName = "CloseIncident"
};
request["incidentresolution"] = incidentresolution;
request["status"] = new OptionSetValue()
{
Value = -1
};
Of course you should replace Guid.Empty with id of incident you want to close.
Related
I am trying to display a pdf saved in FileSystemStorage inside the browsercomponent, but it keeping giving me this error on the console: [0813/072549.347989:INFO:CONSOLE(37)] "Not allowed to load local resource: file://home//Chapter_11.pdf#toolbar=0&navpanes=0&scrollbar=0&statusbar=0&messages=0&scrollbar=0&view=FitH", source: https://cn1app/streams/1 (37) [0813/072551.123557:INFO:CONSOLE(0)] "Not allowed to load local resource: file://home//Chapter_11.pdf#toolbar=0&navpanes=0&scrollbar=0&statusbar=0&messages=0&scrollbar=0&view=FitH", source: https://cn1app/streams/1 (0) . Its like there is a restriction that I need to work around. How can I go around this?
Edits... Added information below.
This is the code I am using:
Form hi;
Container loadingMsg;
public void Home(){
Form form = new Form("Display pdf", new BorderLayout());
Button showPdf = new Button("Show Pdf");
showPdf.addActionListener(l->{
show();
});
form.add(BorderLayout.CENTER, showPdf);
form.show();
}
private void show(){
hi = new Form("PDF Viewer", new BorderLayout());
Label loadingLabel = new Label("Loading PDF...");
loadingMsg = FlowLayout.encloseCenter(loadingLabel);
hi.add(BorderLayout.NORTH, loadingMsg);
String pdfUrl = "https://as.vanderbilt.edu/chemistry/Rizzo/chem220a/Chapter_11.pdf";
String fileName = FileSystemStorage.getInstance().getAppHomePath() + "Chapter_11";
if (!FileSystemStorage.getInstance().exists(fileName)) {
Util.downloadUrlToFileSystemInBackground(pdfUrl, fileName);
};
hi.addShowListener(l -> {
run1(fileName);
});
hi.show();
}
private void run1(String fileName) {
BrowserComponent browser = new BrowserComponent();
browser.setPage(getPdfViewerHtml(fileName), null);
hi.add(BorderLayout.CENTER, browser);
loadingMsg.remove();
hi.revalidate();
}
private String getPdfViewerHtml(String fileName) {
String html = "<!DOCTYPE html>\n"
+ "<html>\n"
+ " <head>\n"
+ " <title>PDF Viewer</title>\n"
+ " <style>\n"
+ " html{\n"
+ " height: 100%;\n"
+ " padding: 0;\n"
+ " }\n"
+ " body{\n"
+ " height: 100%;\n"
+ " overflow-y: hidden;\n"
+ " position: fixed;\n"
+ " width: 100%;\n"
+ " padding: 0;\n"
+ " margin: 0;\n"
+ " }\n"
+ " </style>\n"
+ " </head>\n"
+ " <body>\n"
+ "\n"
+ " <div style= \"height: 100%; margin: 0;\">\n"
+ " <iframe\n"
+ " src='"+fileName+"#toolbar=0&navpanes=0&scrollbar=0&statusbar=0&messages=0&scrollbar=0&view=FitH'\n"
+ " width=\"100%\"\n"
+ " height=\"100%\"\n"
+ " >\n"
+ " <p>This browser does not support PDF!</p>\n"
+ " </iframe>\n"
+ "\n"
+ " </div>\n"
+ "\n"
+ " </body>\n"
+ "</html>";
return html;
}
So in the method String getPdfViewerHtml(String fileName),when i replace the fileName with a URL, thing works fine. But I want it to display a file from FileSystemStorage.
The code below should support the local embed tag correctly:
private Container loadingMsg;
public void start() {
if (current != null) {
current.show();
return;
}
home();
}
public void home() {
Form form = new Form("Display pdf", new BorderLayout());
Button showPdf = new Button("Show Pdf");
showPdf.addActionListener(l -> {
showPdf.setText("Dowloading PDF...");
showPdf.setEnabled(false);
form.revalidate();
show();
});
form.add(BorderLayout.CENTER, showPdf);
form.show();
}
private void show() {
String root = getAppHomePath() + "httpdocs/";
mkdir(root);
hi = new Form("PDF Viewer", new BorderLayout());
Label loadingLabel = new Label("Loading PDF...");
loadingMsg = FlowLayout.encloseCenter(loadingLabel);
hi.add(BorderLayout.NORTH, loadingMsg);
String pdfUrl = "https://as.vanderbilt.edu/chemistry/Rizzo/chem220a/Chapter_11.pdf";
String fileName = root + "/Chapter_11.pdf";
if (!FileSystemStorage.getInstance().exists(fileName)) {
Util.downloadUrlToFile(pdfUrl, fileName, false);
try {
run1(docRoot, "Chapter_11.pdf");
} catch (IOException ex) {
Log.e(ex);
}
} else {
try {
run1(docRoot, fileName);
} catch (IOException ex) {
Log.e(ex);
}
}
hi.show();
}
private void run1(String docRoot, String fileName) throws IOException {
BrowserComponent browser = new BrowserComponent();
String localUrl = fileName;
String htmlPage = getPdfViewerHtml(localUrl);
File indexHtml = new File(docRoot, "index.html");
writeStringToFile(indexHtml, htmlPage);
browser.setURL(docRoot + "/index.html");
hi.add(BorderLayout.CENTER, browser);
loadingMsg.remove();
hi.revalidate();
}
private String getPdfViewerHtml(String fileName) {
String html = "<!DOCTYPE html>\n"
+ "<html>\n"
+ " <head>\n"
+ " <title>PDF Viewer</title>\n"
+ " <style>\n"
+ " html{\n"
+ " height: 100%;\n"
+ " padding: 0;\n"
+ " }\n"
+ " body{\n"
+ " height: 100%;\n"
+ " overflow-y: hidden;\n"
+ " position: fixed;\n"
+ " width: 100%;\n"
+ " padding: 0;\n"
+ " margin: 0;\n"
+ " }\n"
+ " </style>\n"
+ " </head>\n"
+ " <body>\n"
+ "\n"
+ " <div style= \"height: 100%; margin: 0;\">\n"
+ " <iframe\n"
+ " src='" + fileName + "#toolbar=0&navpanes=0&scrollbar=0&statusbar=0&messages=0&scrollbar=0&view=FitH'\n"
+ " width=\"100%\"\n"
+ " height=\"100%\"\n"
+ " >\n"
+ " <p>This browser does not support PDF!</p>\n"
+ " </iframe>\n"
+ "\n"
+ " </div>\n"
+ "\n"
+ " </body>\n"
+ "</html>";
return html;
}
private void writeStringToFile(File file, String content) throws IOException {
FileSystemStorage fs = FileSystemStorage.getInstance();
try (OutputStream os = fs.openOutputStream(file.getAbsolutePath())) {
Util.copy(new ByteArrayInputStream(content.getBytes("UTF-8")), os);
}
}
}
When trying to concatenate two strings, they combine but the next three characters overwrite earlier concatenated text before again continuing to concatenate as expected. I suspect this is something to do with the retrieve_mapped_value(cmd.Interaction.Replies[p_index].Variable[r_index], var_swap) function as this phenomena only happens when it is called within the double for of the cmd.Interaction section of build_executable.
Where the error is
func build_executable(cmd shell_command, var_swap string_matrix, is_first bool) string{
sleep_duration := cmd.Sleep
result := ""
if !is_first{
result = "send \""
} else {
result = "spawn "
}
result += cmd.Command
if len(cmd.Options.Dashes) > 0 {
for index := range cmd.Options.Dashes{
if cmd.Options.Dashes[index] != "" || cmd.Options.Flags[index] != ""{
result += " " + cmd.Options.Dashes[index] + cmd.Options.Flags[index]
}
if cmd.Options.Values[index] != ""{
result += " " + cmd.Options.Values[index]
}
}
}
if len(cmd.Targets.Litteral) > 0{
result += " "
for index := range cmd.Targets.Litteral{
result += cmd.Targets.Litteral[index] + retrieve_mapped_value(cmd.Targets.Variable[index], var_swap)
}
}
if !is_first{
result += "\\r\"\n"
} else {
result += "\n"
}
result += "sleep " + sleep_duration + "\n"
if len(cmd.Interaction.Prompts) > 0{
for p_index := range cmd.Interaction.Prompts{
fmt.Println("cmd.Interaction.Prompts[p_index]\t" + cmd.Interaction.Prompts[p_index])
result += "expect \"" + cmd.Interaction.Prompts[p_index] + "\"\nsend \""
for r_index := range cmd.Interaction.Replies[p_index].Litteral{
fmt.Println("cmd.Interaction.Replies[p_index].Litteral[r_index]\t'" + cmd.Interaction.Replies[p_index].Litteral[r_index] + "'")
fmt.Println("cmd.Interaction.Replies[p_index].Variable[r_index]\t'" + cmd.Interaction.Replies[p_index].Variable[r_index] + "'")
fmt.Println("retrieve_mapped_value(cmd.Interaction.Replies[p_index].Variable[r_index], var_swap)\t'" + retrieve_mapped_value(cmd.Interaction.Replies[p_index].Variable[r_index], var_swap) + "'")
result += cmd.Interaction.Replies[p_index].Litteral[r_index]
result += retrieve_mapped_value(cmd.Interaction.Replies[p_index].Variable[r_index], var_swap)
result += "" + "" + ""
}
result += "\\r\"\nsleep " + sleep_duration + "\n"
}
}
if cmd.Expects != "" {
result += "expect \"" + cmd.Expects + "\"\n"
}
return result
}
Suspect function
func retrieve_mapped_value(key string, mapping string_matrix) string{
if key != "" {
for _, layer := range mapping{
if layer[0] == key {
return layer[1]
}
}
} else {
return key
}
return "***No Match Error***"
}
What I should get
expect "Enter password for user root: "
send "e3H-*HGHu__7\r"
sleep 10
What I actually get
expect "Enter password for user root: "
\r"d "e3H-*HGHu__7
sleep 10
It is taking the last 3 characters of one line and overwriting the front with them. I don't understand.
I never found the solution to this but the temp_add section of the below where I arbitrarily slice off the end of the string works. There is some voodoo up in here.
func build_executable(cmd shell_command, var_swap string_matrix, is_first bool) string{
sleep_duration := cmd.Sleep
result := ""
if !is_first{
result = "send \""
} else {
result = "spawn "
}
result += cmd.Command
if len(cmd.Options.Dashes) > 0 {
for index := range cmd.Options.Dashes{
if cmd.Options.Dashes[index] != "" || cmd.Options.Flags[index] != ""{
result += " " + cmd.Options.Dashes[index] + cmd.Options.Flags[index]
}
if cmd.Options.Values[index] != ""{
result += " " + cmd.Options.Values[index]
}
}
}
if len(cmd.Targets.Litteral) > 0{
result += " "
for index := range cmd.Targets.Litteral{
result += cmd.Targets.Litteral[index] + retrieve_mapped_value(cmd.Targets.Variable[index], var_swap)
}
}
if !is_first{
result += "\\r\"\n"
} else {
result += "\n"
}
result += "sleep " + sleep_duration + "\n"
if len(cmd.Interaction.Prompts) > 0{
for p_index := range cmd.Interaction.Prompts{
interaction_result := "expect \"" + cmd.Interaction.Prompts[p_index] + "\"\nsend \""
temp_add := ""
for r_index := range cmd.Interaction.Replies[p_index].Litteral{
interaction_result += cmd.Interaction.Replies[p_index].Litteral[r_index]
temp_add = retrieve_mapped_value(cmd.Interaction.Replies[p_index].Variable[r_index], var_swap)
if temp_add != ""{ //this looks wasteful but it is needed for reasons I don't understand
temp_add += "\n" //the basic explaination is it seems `retrieve_mapped_value` appends a carriage return & this
temp_add = temp_add[:len(temp_add) - 2] //messes up the script, I don't know why it appends it, but removes it
}
interaction_result += temp_add
}
interaction_result += "\\r\"\nsleep " + sleep_duration + "\n"
result += interaction_result
}
}
if cmd.Expects != "" {
result += "expect \"" + cmd.Expects + "\"\n"
}
return result
}
So I am just a hobby programmer that is self taught C# and currently designing my own application to reduce the amount of steps it requires to do stuff for my job and I have a Few things I would Like help with one thing is i would like to create Fields that update a Internets Form I am not sure if this is do able even between 2 different languages.
Website Elements
//When Button is Pressed Create The New Job In The Specified Location and
//then create text files to send file attributes to.
//Future: Add the ability to also use these field attributes to update and
//create the job folder on the website as well.
private void NewJob_Click(object sender, EventArgs e)
{
if (!Directory.Exists(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text))
Directory.CreateDirectory(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text);
if (!Directory.Exists(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\0-Submittals"))
Directory.CreateDirectory(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\0-Submittals");
if (!Directory.Exists(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\1-Pricing"))
Directory.CreateDirectory(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\1-Pricing");
if (!Directory.Exists(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\2-Take Off"))
Directory.CreateDirectory(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\2-Take Off");
if (!Directory.Exists(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\3-Files"))
Directory.CreateDirectory(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\3-Files");
if (!Directory.Exists(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\4-Plans"))
Directory.CreateDirectory(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\4-Plans");
if (!Directory.Exists(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\5-Specs"))
Directory.CreateDirectory(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\5-Specs");
if (!Directory.Exists(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\6-Emails"))
Directory.CreateDirectory(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\6-Emails");
if (!Directory.Exists(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\Properties"))
Directory.CreateDirectory(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + "\\Properties");
File.WriteAllText(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + #"\Properties\Contact.txt", lblContact.Text);
File.WriteAllText(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + #"\Properties\JobName.txt", lblJobName.Text);
File.WriteAllText(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + #"\Properties\BidDate.txt", lblBidDate.Text);
File.WriteAllText(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + #"\Properties\Engineer.txt", lblEngineer.Text);
File.WriteAllText(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + #"\Properties\TakeOff.txt", lblTakeOff.Text);
File.WriteAllText(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + #"\Properties\Received.txt", lblReceived.Text);
File.WriteAllText(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + #"\Properties\Vendor.txt", lblVendor.Text);
File.WriteAllText(#textBox1.Text + "\\" + lblBidDate.Text + " - " + lblJobName.Text + #"\Properties\Notes.txt", lblNotes.Text);
}
Another problem is how do you remove this error when you right click on a web browser that is being used as a file explorer, without removing the fire wall.
Photo of the security Message
Thank you in advance.
I figured it out
private void Generate_Click(object sender, EventArgs e)
{
if (lblContact.Text.Contains("name0"))
lblContact.Text.Replace("name0", "7");
HtmlDocument doc = wbNewProject.Document;
HtmlElement wbJobName = doc.GetElementById("Name"); //lblcontact.text
HtmlElement wbEngineer = doc.GetElementById("engineer-lookup"); //
HtmlElement wbSalesEng = doc.GetElementById("SalesEngineerUserId");
HtmlElement wbLocation = doc.GetElementById("Location");
HtmlElement wbBidDate = doc.GetElementById("BidDate");
HtmlElement wbPriorApproval = doc.GetElementById("PriorApproval"); //True or False
HtmlElement wbTakeOff = doc.GetElementById("TakeOffComplete"); //True or False
HtmlElement wbProject = doc.GetElementById("RoleType"); //Design/Build or Plan/Spec
wbJobName.SetAttribute("value", lblJobName.Text);
if (lblContact.Text.Contains("Name1"))
wbSalesEng.SetAttribute("value", "2");
if (lblContact.Text.Contains("name2"))
wbSalesEng.SetAttribute("value", "3");
if (lblContact.Text.Contains("name3"))
wbSalesEng.SetAttribute("value", "4");
if (lblContact.Text.Contains("name4"))
wbSalesEng.SetAttribute("value", "5");
if (lblContact.Text.Contains("name5"))
wbSalesEng.SetAttribute("value", "6");
if (lblContact.Text.Contains("name6"))
wbSalesEng.SetAttribute("value", "7");
if (lblContact.Text.Contains("name7"))
wbSalesEng.SetAttribute("value", "10");
if (lblContact.Text.Contains("name8"))
wbSalesEng.SetAttribute("value", "11");
if (lblContact.Text.Contains("name9"))
wbSalesEng.SetAttribute("value", "12");
wbLocation.SetAttribute("value", lblLocation.Text);
wbBidDate.SetAttribute("value", lblBidDate.Text);
if (lblPriorApp.Text.Contains("Yes"))
wbPriorApproval.SetAttribute("value", "true");
if (lblPriorApp.Text.Contains("No"))
wbPriorApproval.SetAttribute("value", "false");
if (lblTakeOff.Text.Contains("Done"))
wbTakeOff.SetAttribute("value", "true");
if (lblTakeOff.Text.Contains("Not Done"))
wbTakeOff.SetAttribute("value", "false");
wbEngineer.SetAttribute("value", lblEngineer.Text);
wbProject.SetAttribute("value", lblProject.Text);
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
MyForm2^ myform2 = gcnew MyForm2();
String^ constring = L"datasource=localhost;port=3306;username=root;password=root";
MySqlConnection^ conDataBase = gcnew MySqlConnection(constring);
MySqlCommand^ cmdDataBase = gcnew MySqlCommand(
"Update librarysystem.bookdetails set isbn = '" + this->textBox1->Text +
"', booktitle = '" + this->textBox2->Text +
"', bookauthor = '" + this->textBox3->Text +
"', bookcategory = '" + this->comboBox1->SelectedItem +
"', bookedition = '" + this->textBox5->Text +
"', booknumofcopies = '" + this->textBox4->Text +
"' where isbn = '" + myform2->listView1->FocusedItem->ListView + "' ;",
conDataBase);
MySqlDataReader^ myReader;
MyForm2^ myform2 = gcnew MyForm2();
...
myform2->listView1->FocusedItem->ListView
There's something wrong with your declaration of MyForm2. Most likely is that you didn't #include "MyForm2.h". You are probably also getting errors about 'MyForm2' : undeclared identifier.
I have a problem that doesn't appear always, but it do it most of the times. In my huge java forecast class I have some ResultSets, and when I execute the routine I get:
com.microsoft.sqlserver.jdbc.SQLServerException: El nombre de columna DistanciaMision no es vßlido.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.findColumn(SQLServerResultSet.java:626)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getString(SQLServerResultSet.java:2301)
at es.csic.iiia.udt.itim.iInformation.WebData.Forecast.etaMSR(Forecast.java:1109)
at es.csic.iiia.udt.itim.iInformation.WebData.Forecast.phase2(Forecast.java:662)
at es.csic.iiia.udt.itim.iInformation.WebData.Forecast.setData(Forecast.java:166)
at es.csic.iiia.udt.itim.iInformation.WebData.Forecast.main(Forecast.java:81)
at es.csic.iiia.udt.itim.iInformation.WebData.Forecast.execute(Forecast.java:71)
at org.quartz.core.JobRunShell.run(JobRunShell.java:199)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:546)
The column exists, so I don't know what is the problem...
The code line is this one:
Float distancia_restante = (float) ( Integer.parseInt(rs.getString("DistanciaMision")) - (myodometer - initialodometer));
The same problem appears on other columns but it usually crash here.
Thank you!
Edit: ok, this is the whole method:
private static void etaMSR() throws Exception, SQLException {
/**
*
* Calculem ETAN MSR - Mision - Seguimiento - Restricciones conductor
*
*
**/
System.out
.print("Get data from iTIM forecast&forecastAUX DDBB ....... ");
myStatement = MSSQLServerAccess.connection();
// Distancia mision, ruta, hora mision anterior, hora
rs = getTable("SELECT dbo.WebForecast.IdConductor, dbo.WebForecast.IdMision, dbo.WebForecast.IdMisionAnterior, dbo.WebForecast.DistanciaMision, "
+ " WebForecast_1.HoraIniMis AS himanterior, dbo.WebForecast.HoraFiMis AS hfmactual, WebForecast_1.Ciudad AS CiudadOrigen,"
+ " dbo.WebForecast.Ciudad AS CiudadDestino, dbo.Distancias.Ruta, dbo.WebForecast.HoraDistancia AS HoraDistancia"
+ " FROM dbo.WebForecast AS WebForecast_1 INNER JOIN"
+ " dbo.Distancias ON WebForecast_1.Ciudad = dbo.Distancias.Origen RIGHT OUTER JOIN"
+ " dbo.WebForecast ON WebForecast_1.IdMision = dbo.WebForecast.IdMisionAnterior AND dbo.Distancias.Destino = dbo.WebForecast.Ciudad"
+ " WHERE (dbo.WebForecast.IdConductor <> '') AND (CONVERT(datetime, '"
+ df.format(fechaDia)
+ "') <= dbo.WebForecast.HoraFiMis) "
+ " AND WebForecast_1.HoraIniMis <= CONVERT(datetime, '"
+ df.format(fechaDia) + "') ");
System.out.println("[ok]");
while (rs.next() && (rs.getString("IdConductor") != "") && org.apache.commons.lang.StringUtils.isNumeric(rs.getString("IdConductor"))) {
int initialodometer = 0;
String start = null;
if (rs.getString("HoraDistancia") != null) {
start = rs.getString("HoraDistancia");
}
if (rs.getString("himanterior") != null) {
start = rs.getString("himanterior");
}
if (start != null) {
ResultSet myrs = null;
Timestamp tobjetivo = rs.getTimestamp("himanterior");
long boundtime = 7200000; // 3600000 = 60m = 1h
Timestamp tini = (Timestamp) rs.getTimestamp("himanterior")
.clone();
Timestamp tfin = (Timestamp) rs.getTimestamp("himanterior")
.clone();
tini.setTime(tini.getTime() - boundtime);
tfin.setTime(tfin.getTime() + boundtime);
int contador = 0;
long bestdiff = 0;
myStatement = MSSQLServerAccess.connection();
myrs = getTable("SELECT DISTINCT Odometer, DT "
+ "FROM DriverEvents "
+ "WHERE (DT BETWEEN CONVERT(datetime, '"
+ df.format(tini) + "') " + "AND CONVERT(datetime, '"
+ df.format(tfin) + "')) " + "AND (CardId = '"
+ Integer.parseInt(rs.getString("IdConductor")) + "')");
int j = 0;
while (!myrs.next() && (j < 20)) {
// En caso de no encontrar en las 2h antes y despues nada:
tini.setTime(tini.getTime() - boundtime);
tfin.setTime(tfin.getTime() + boundtime);
myrs.close();
myStatement = MSSQLServerAccess.connection();
myrs = getTable("SELECT DISTINCT Odometer, DT "
+ "FROM DriverEvents "
+ "WHERE (DT BETWEEN CONVERT(datetime, '"
+ df.format(tini) + "') "
+ "AND CONVERT(datetime, '" + df.format(tfin)
+ "')) " + "AND (CardId = '"
+ Integer.parseInt(rs.getString("IdConductor"))
+ "')");
j++;
}
if (myrs.next()) {
initialodometer = myrs.getInt("Odometer");
bestdiff = Math.abs(tobjetivo.getTime()
- myrs.getTimestamp("DT").getTime());
contador++;
while (myrs.next()) {
long pretendiente = Math.abs(tobjetivo.getTime()
- myrs.getTimestamp("DT").getTime());
if (pretendiente <= bestdiff) {
bestdiff = pretendiente;
initialodometer = myrs.getInt("Odometer");
}
contador++;
}
}
myrs.close();
}
// Get Odometer distance at the moment
if (!rs.getString("IdConductor").isEmpty() && !rs.getString("IdConductor").equals("") ) {
ResultSet myrs = null;
int myodometer = 0;
myStatement = MSSQLServerAccess.connection();
myrs = getTable("SELECT MAX(DT) AS DT, MAX(Odometer) AS Odometer"
+ " FROM dbo.DriverEvents"
+ " WHERE (CardId = '"
+ Integer.parseInt(rs.getString("IdConductor"))
+ "') AND (DT > CONVERT(datetime, '"
+ df.format(fechaDatos) + "')) ");
if (myrs.next()) {
myodometer = myrs.getInt("Odometer");
if (initialodometer == 0)
initialodometer = myodometer;
Float distancia_restante = (float) ( Integer.parseInt(rs.getString("DistanciaMision")) - (myodometer - initialodometer));
if (distancia_restante < 0)
distancia_restante = (float) 0;
Timestamp ETAN = null;
Calendar cal = Calendar.getInstance();
if (rs.getTimestamp("himanterior") != null && rs.getTimestamp("himanterior").toString() != "") {
cal.setTimeInMillis(rs.getTimestamp("himanterior")
.getTime());
if (cal.after(Calendar.getInstance())) {
cal.setTimeInMillis(rs.getTimestamp("himanterior")
.getTime());
}
if (cal.before(Calendar.getInstance())) {
cal = Calendar.getInstance();
}
} else {
if (rs.getTimestamp("HoraDistancia") != null)
cal.setTimeInMillis(rs
.getTimestamp("HoraDistancia").getTime());
}
myStatement = MSSQLServerAccess.connection();
rs2 = getTable("SELECT TOP (100) PERCENT CardId, DT"
+ " FROM dbo.DriverEvents"
+ " GROUP BY CardId, DT"
+ " HAVING (CardId = '"
+ Integer.parseInt(rs.getString("IdConductor"))
+ "') AND (DT > CONVERT(datetime, '"
+ df.format(fechaDatos) + "'))");
if (rs2.next()) {
ETAN = getETAN(rs, distancia_restante, cal);
} else {
ETAN = getETA(rs, distancia_restante, cal, 1);
Statement myStatement2 = MSSQLServerAccess.connection();
myStatement2.executeUpdate("UPDATE WebForecast "
+ "SET ETAmsr = '" + df.format(ETAN)
+ "', KmsDiff = '" + distancia_restante.intValue()
+ "' " + "WHERE IdMision = '"
+ rs.getString("IdMision") + "'");
} else {
}
}
}
rs.close();
}
And the statement, maybe i'm doing something wrong?:
private static Statement conStatement(Properties properties){
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // Load the JDBC driver
String dbURL = "jdbc:sqlserver://"
+ properties.getProperty("qualcomm.action.JDBC.MSSQLServerAccess.ddbbserverIP")
+ ";DatabaseName="
+ properties.getProperty("qualcomm.action.JDBC.MSSQLServerAccess.ddbbName")
+ ";SelectMethod=Cursor;"; // Connect to a server and database
String userName = properties.getProperty("qualcomm.action.JDBC.MSSQLServerAccess.userName");
String userPwd = properties.getProperty("qualcomm.action.JDBC.MSSQLServerAccess.userPwd");
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
//log.info("Connection Successful!");
Statement myst = dbConn.createStatement();
return myst;
} catch (Exception e) {
log.error(e);
System.out.println(e);
return null;
}
}
Thanks guys :) Could be something wrong with the statement?
remember that Java is case-sensitive and so can be your table on SQL depending on the way you created them, actually depending on the collation on your DB. If your database is created with a Case Sensitive collation then all object names will be Case Sensitive.
try to check the exact columns name of the column on SQL and access it using [] and the exact case