Passing Fields From a Form To The Fields On a Website - winforms

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);
}

Related

How to access files in FileSystemStorage in Browser component

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);
}
}
}

Close Incident in CRM 2011 with Silverlight

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.

Compiler error while writing to a file

I'm getting the error:-
error: cannot find symbol
tofile.println("Dancing" + " " + danceminutes + " " + bpm);
^
symbol: variable tofile
location: class CreateFile
I'm not sure why.
// writing to a file
PrintWriter toFile = new PrintWriter(new FileWriter("exLog.txt"));
Random randy = new Random();
int count = randy.nextInt(12) + 19;
for (int i = count; i > 0; i--) {
int exercise = randy.nextInt(3);
if (exercise == 0) {
int minutesOne = randy.nextInt(47) + 14;
int minutesTwo = randy.nextInt(62) + 59;
int minutesThree = randy.nextInt(122) + 119;
int roulette = randy.nextInt(100);
if (roulette <= 74) {
int runoneminutes = minutesOne;
double speed = 4.9 + (16.1 - 4.9) * randy.nextDouble();
double distance = speed * runoneminutes/60;
tofile.println("Running" + " " + runoneminutes + " " + distance);
}
else if (roulette > 74 && roulette < 96) {
int runtwominutes = minutesTwo;
double twospeed = 4.9 + (16.1 - 4.9) * randy.nextDouble();
double twodistance = twospeed * runtwominutes/60;
tofile.println("Running" + " " + runtwominutes + " " + twodistance);
}
else if (roulette >= 96) {
int runthreeminutes = minutesThree;
double threespeed = 4.9 + (16.1 - 4.9) * randy.nextDouble();
double threedistance = threespeed * runthreeminutes/60;
tofile.println("Running" + " " + runthreeminutes + " " + threedistance);
}
}
if (exercise == 1) {
int bikeminutesOne = randy.nextInt(62) + 29;
int bikeminutesTwo = randy.nextInt(212) + 89;
int bikeroulette = randy.nextInt(100);
if (bikeroulette <= 49) {
int bikeoneminutes = bikeminutesOne;
double bikeonespeed = 7.9 + (25.1 - 7.9) * randy.nextDouble();
double bikeonedistance = bikeonespeed * bikeoneminutes/60;
tofile.println("Biking" + " " + bikeoneminutes + " " + bikeonedistance);
}
else if (bikeroulette > 49) {
int biketwominutes = bikeminutesTwo;
double biketwospeed = 7.9 + (25.1 - 7.9) * randy.nextDouble();
double biketwodistance = biketwospeed * biketwominutes/60;
tofile.println("Biking" + " " + biketwominutes + " " + biketwodistance);
}
}
if (exercise == 2) {
int exercises = randy.nextInt(15) + 1;
int reps = randy.nextInt(37) + 9;
double liftminutes;
int liftminutes = 5*reps*exercises/60 + 2*(exercises-1);
tofile.println("Lifting" + " " + liftminutes + " " + reps);
}
if (exercise == 3) {
int danceminutes = randy.nextInt(90) + 29;
double bpm = 79.9 + (220 - 79.9) * randy.nextDouble();
tofile.println("Dancing" + " " + danceminutes + " " + bpm);
}
}
toFile.close(); //saving output file
} // end main
} // end CreateFile class
The variable name is toFile. The compiler is complaining about the use of 'tofile'.

how to draw multiple arrow lines in extjs grid panel

i am tryting to draw multiple arrow lines between two grid panels, but i am able to draw only one arrow, when i start to draw the second arrow the first arrow is not showing.below is the code which i have tried.
This is where i am creating a arrow
Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
// alert("raphael");
var angle = Math.atan2(x1-x2,y2-y1);
angle = (angle / (2 * Math.PI)) * 360;
var arrowPath = this.path("M" + x2 + " " + y2 + " L" + (x2 - size) + " " + (y2 - size) + " L" + (x2 - size) + " " + (y2 + size) + " L" + x2 + " " + y2 ).attr("fill","black").rotate((90+angle),x2,y2);
var linePath = this.path("M" + x1 + " " + y1 + " L" + x2 + " " + y2);
return [linePath,arrowPath];
};
drag initialization
onInitDrag : function(x,y){
var data = this.dragData;
this.ddel.innerHTML = this.grid.getDragDropText();
//alert("this.ddel :"+this.ddel.innerHTML);
this.proxy.update(this.ddel);
// fire start drag?
//i would say yes ;-)
this.onStartDrag(x,y);
},
/*
* onStartDrag is called when you initiate the drag action
* it stores the mouse coordinates and create the SVG canvas
*/
onStartDrag : function(x, y){
alert(Ext.getCmp('leftGridId'));
this.arrowStart = {x:x, y:y};
alert("on Start Drag :"+x+","+y);
this.raphaelCanvas = new Raphael(0,0,2000,2000); //could be better...
//apply body.no-cursor (cursor : none) to hide the cursor
//cursor:pointer is nice too
//alert("after StartDrag :"+x+","+y);
},
/*
* onDrag is called on mousemove
* it clears the canvas and draw the arrow again
*/
onDrag : function(e){
//alert("on drag");
//alert("raphael arrow");
this.raphaelCanvas.clear();
var arrow = this.raphaelCanvas.arrow(this.arrowStart.x, this.arrowStart.y, e.xy[0], e.xy[1],8);
// alert("after mapping");
},
/*
* onEndDrag is called when you drop whatever you were dragging
* it removes the SVG canvas from the document
*/
onEndDrag : function(){
alert("on end drag");
//this.raphaelCanvas.remove();
//delete this.raphaelCanvas;
this.raphaelCanvas.renderfix();
if(!onStartDrag){
/this.raphaelCanvas.remove();
//delete this.raphaelCanvas;
}
else{
onStartDrag();
}
}
There can be serious improvements to your code but try these quick changes if at;east your two arrows start appearing ....
Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
// alert("raphael");
var angle = Math.atan2(x1-x2,y2-y1);
angle = (angle / (2 * Math.PI)) * 360;
var arrowPath = this.path("M" + x2 + " " + y2 + " L" + (x2 - size) + " " + (y2 - size) + " L" + (x2 - size) + " " + (y2 + size) + " L" + x2 + " " + y2 ).attr("fill","black").rotate((90+angle),x2,y2);
var linePath = this.path("M" + x1 + " " + y1 + " L" + x2 + " " + y2);
return [linePath,arrowPath];
};
this.raphaelCanvas = new Raphael(0,0,2000,2000);
this.raphaelCanvas.renderfix();
drag initialization
onInitDrag : function(x,y){
var data = this.dragData;
this.ddel.innerHTML = this.grid.getDragDropText();
//alert("this.ddel :"+this.ddel.innerHTML);
this.proxy.update(this.ddel);
// fire start drag?
//i would say yes ;-)
this.onStartDrag(x,y);
},
/*
* onStartDrag is called when you initiate the drag action
* it stores the mouse coordinates and create the SVG canvas
*/
onStartDrag : function(x, y){
alert(Ext.getCmp('leftGridId'));
this.arrowStart = {x:x, y:y};
alert("on Start Drag :"+x+","+y);
//this.raphaelCanvas = new Raphael(0,0,2000,2000); //could be better...
//apply body.no-cursor (cursor : none) to hide the cursor
//cursor:pointer is nice too
//alert("after StartDrag :"+x+","+y);
},
/*
* onDrag is called on mousemove
* it clears the canvas and draw the arrow again
*/
onDrag : function(e){
//alert("on drag");
//alert("raphael arrow");
//this.raphaelCanvas.clear();
var arrow = this.raphaelCanvas.arrow(this.arrowStart.x, this.arrowStart.y, e.xy[0], e.xy[1],8);
// alert("after mapping");
},
/*
* onEndDrag is called when you drop whatever you were dragging
* it removes the SVG canvas from the document
*/
onEndDrag : function(){
alert("on end drag");
//this.raphaelCanvas.remove();
//delete this.raphaelCanvas;
//this.raphaelCanvas.renderfix();
if(!onStartDrag){
//this.raphaelCanvas.remove();
//delete this.raphaelCanvas;
}
else{
onStartDrag();
}
}

SQLServerException Invalid column name

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

Resources