verification if record posts to multiple tables - asp.net

i hope i have another simple question for someone out there.
im currently working on a website where i am having a user post information to the server and upon posting they are taken to a verification page that tells them if it successfully was stored on the .mbd table or not. I have had no problems with doing this for a single table but i seem to be running into a issue when wanting to verifing the information stored on multiple tables.
HERE is the code that im using THAT IS WORKING for posting to a SINGLE table
protected void Page_Load(object sender, EventArgs e)
{
txtVerifiedInfo.Text = Session["txtUserFirstName"].ToString() +
"\n" + Session["txtUserLastName"].ToString() +
"\n" + Session["txtUserName"].ToString() +
"\n" + Session["txtUserPassword"].ToString() +
;
// Check if the record is successfully saved in the tblUserLogin Table and prints the appropriate message in the text box txtVerifiedInfo
if (clsDataLayer.SavePersonnel(Server.MapPath("App_Data\\WSC_DB.mdb"),
Session["txtUserFirstName"].ToString(),
Session["txtUserLastName"].ToString(),
Session["txtUserName"].ToString(),
Session["txtUserPassword"].ToString(),
))
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\nThe information was successfully saved!";
}
else
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\nThe information was NOT saved.";
}
}
}
Here is what i have attempted with not much luck at all
if (clsDataLayer.Saveneworder(Server.MapPath("App_Data\\WSC_DB.mdb"),
Session["txtfirstName"].ToString(),
Session["txtlastName"].ToString(),
Session["txtstreetAddress"].ToString(),
Session["txtcity"].ToString(),
Session["txtzipCode"].ToString()))
&& if (clsDataLayer.Savenewitem(Server.MapPath("App_Data\\WSC_DB.mdb"),
Session["jobType"].ToString() +
Session["txtmediaContent"].ToString()))
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\nThe Order successfully submitted!";
}
else
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\n The order did not save, please return to the previous screen and verify all of yourr data is correct, thank you.";
}
}
}
I Imagine im not that close to doing this correctly but hopefully in the ball park.
any help with this would be great.
Thank you for your time

To simplify, this is roughly what you have now:
var path = Server.MapPath("App_Data\\WSC_DB.mdb");
if (clsDataLayer.Saveorder(path, [order parameters]
&& clsDataLayer.Saveitem(path, [item parameters])
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\nThe Order successfully submitted!";
}
else
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\n The order did not save, please return to the previous screen and verify all of yourr data is correct, thank you.";
}
The code you've presented is not well structured, in that there is an unnecessary call to Server.MapPath and the call may be better placed as part of an argument to the constructor of your datalayer class.
What you may not be aware of is the && is a shortcut operator - the second part of the argument will not be called if the first part fails. Is this the behaviour you want?
I suspect you want Saveorder AND Saveitem to succeed or fail together, as part of one transaction. That being the case, you might be better off writing a new method in your datalayer class that does exactly that.
I'm assuming the .mdb in your filename indicates you're using MS Access? I'm not sure if it deals with transactions as well as SQL server (for instance), so you might need to write your own code to remove the order if its item cannot be saved (or whatever on-failure behaviour you need).

Related

nextPage() method - not functioning

I have a datasource that contains > 1000 records. The current Query page size is at 100.
I have a need to loop through each item, and try to find a record that matches input given by the user. Fairly simple use-case, however, I can't seem to get the script to loop through the pages so it just finishes its loop at the query page size of 100 and therefore only searching the first 100 records.
I've tried putting in
app.datasources.Vehicles.nextPage();
at the end of the for loop and then call regoExists again with the new page but it doesn't work. How is nextPage() meant to be used in client scripts?
function regoExists(rego){
var regoUp = rego.toUpperCase();
regoUp = regoUp.trim();
ds = app.datasources.Vehicles.items;
for (var i in ds){
if (ds[i].registration === regoUp){
console.log(ds[i].registration + " equals " + regoUp);
app.datasources.Vehicles.query.filters.registration._equals = regoUp;
return true;
} else {
console.log(ds[i].registration + " does not equals " + regoUp);
continue;
}
}
}
Rather than looping through each record and performing the query on each individual record I would suggest introducing a textbox widget in the same datasource and setting the binding to:
#datasource.query.filters.registration._equals
Then load the datasource via a button click or via the onValueEdit event of the textbox widget. If the registration value exists, it will be returned in a table presumably, and if it doesn't exist no records would be returned.

In JavaFX, How to load database value into textfield?

I try to load database value into textfield. this code is not showing any error. But it also not giving result. It showing blank textfield.
try
{
connection = database_controller.dbconnect();
String query = "Select * from newlead2 where SERIAL_NO ='lead_id'";
resultset = database_controller.dbExecuteQuery(query);
/*preparedstatement =connection.prepareStatement(query);
resultset =preparedstatement.executeQuery();*/
while(resultset.next())
{
String FN = resultset.getString("CUSTOMER_NAME");
Customer_Name.setText(FN);
}
}
catch(SQLException ex)
{
System.err.println("Error:" + ex);
}
I’m going off what you posted in the comments. You aren’t connected to the database, so your resultset is empty. Put in some code to test if these variables are empty. But like others have said it is too hard to answer this question without a more concise example.

Offline routing is not working

I'd like to use the offline routing feature so I downloaded the MapPackage of my region. I know the download went well because I can zoom on towns in the region offline and all details are shown).
But when I try to compute a route on this region, it does not work, and I get no error message. The onCalculateRouteFinished callback is just never called.
I'm using RouteManager#calculateRoute method (as for online calculation). Should I be using something else to make it work ?
I'm using an evaluation license, is it related ?
Thank you
edit to answer marco's comment:
I'm using "bretagne" region in france/europe.
RouteOptions ro = new RouteOptions();
ro.setTransportMode(RouteOptions.TransportMode.TRUCK);
ro.setRouteType(RouteOptions.Type.FASTEST);
RoutePlan routePlan = new RoutePlan();
routePlan.setRouteOptions(ro);
-- addWaypoint (coord) called several times. all coords are in the bretagne region --
RouteManager routeManager = new RouteManager();
routeManager.calculateRoute(routePlan, new RouteManager.Listener(){
#Override
public void onProgress(int i) {
//Log.d(TAG, "progress " + index + ": " + i);
}
#Override
public void onCalculateRouteFinished(RouteManager.Error error, List<RouteResult> list) {
if (error != RouteManager.Error.NONE) {
Log.e(TAG, "Could not calculate route: " + error.name());
return;
}
if (list != null && list.size() > 0) {
-- do something with result --
}
}
Using TransportMode.CAR instead of TRUCK fixed the problem. As stated by marco in the comments, offline routing is only available for cars.

Blackberry not creating a valid sqlite database

I have a very unusual problem.
I'm trying to create a simple database (6 tables, 4 of which only have 2 columns).
I'm using an in-house database library which I've used in a previous project, and it does work.
However with my current project there are occasional bugs. Basically the database isn't created correctly. It is added to the sdcard but when I access it I get a DatabaseException.
When I access the device from the desktop manager and try to open the database (with SQLite Database Browser v2.0b1) I get "File is not a SQLite 3 database".
UPDATE
I found that this happens when I delete the database manually off the sdcard.
Since there's no way to stop a user doing that, is there anything I can do to handle it?
CODE
public static boolean initialize()
{
boolean memory_card_available = ApplicationInterface.isSDCardIn();
String application_name = ApplicationInterface.getApplicationName();
if (memory_card_available == true)
{
file_path = "file:///SDCard/" + application_name + ".db";
}
else
{
file_path = "file:///store/" + application_name + ".db";
}
try
{
uri = URI.create(file_path);
FileClass.hideFile(file_path);
} catch (MalformedURIException mue)
{
}
return create(uri);
}
private static boolean create(URI db_file)
{
boolean response = false;
try
{
db = DatabaseFactory.create(db_file);
db.close();
response = true;
} catch (Exception e)
{
}
return response;
}
My only suggestion is keep a default database in your assets - if there is a problem with the one on the SD Card, attempt to recreate it by copying the default one.
Not a very good answer I expect.
Since it looks like your problem is that the user is deleting your database, just make sure to catch exceptions when you open it (or access it ... wherever you're getting the exception):
try {
URI uri = URI.create("file:///SDCard/Databases/database1.db");
sqliteDB = DatabaseFactory.open(myURI);
Statement st = sqliteDB.createStatement( "CREATE TABLE 'Employee' ( " +
"'Name' TEXT, " +
"'Age' INTEGER )" );
st.prepare();
st.execute();
} catch ( DatabaseException e ) {
System.out.println( e.getMessage() );
// TODO: decide if you want to create a new database here, or
// alert the user if the SDCard is not available
}
Note that even though it's probably unusual for a user to delete a private file that your app creates, it's perfectly normal for the SDCard to be unavailable because the device is connected to a PC via USB. So, you really should always be testing for this condition (file open error).
See this answer regarding checking for SDCard availability.
Also, read this about SQLite db storage locations, and make sure to review this answer by Michael Donohue about eMMC storage.
Update: SQLite Corruption
See this link describing the many ways SQLite databases can be corrupted. It definitely sounded to me like maybe the .db file was deleted, but not the journal / wal file. If that was it, you could try deleting database1* programmatically before you create database1.db. But, your comments seem to suggest that it was something else. Perhaps you could look into the file locking failure modes, too.
If you are desperate, you might try changing your code to use a different name (e.g. database2, database3) each time you create a new db, to make sure you're not getting artifacts from the previous db.

Adobe Flex Salesforce problem converting account ids to account name

I am using Adobe Air to get data from SalesForce, and present it in a datagrid.
I am using a query to get the data, and then put it into an arraycollection that is bound to the datagrid, this works correctly and the data is displayed.
The problem is that I want to convert the Account Id in the Event to show the account Name. To do this I am using the following code:-
_serviceWrapper.query( "Select * From Event order by StartDateTime asc", new mx.rpc.Responder( eventQueryHandler, faultHandler ))}
protected function eventQueryHandler(qr:ArrayCollection):void {
var acctIdss:String = "";
for each(var contact:DynamicEntity in qr) {
if (contact.AccountId != null && acctIdss.indexOf(contact.AccountId) == -1) {
acctIdss += "'" + contact.AccountId + "',";
}
//contact.AccountName = ""; // Add field to contact for account name
TempGridProvider.addItem(contact); // Add contact to temp grid data data provider
//TempGridProvider.contact.AccountName = "";
}
acctIdss = acctIdss.substr(0, acctIdss.length - 1);
// Query for the accounts based on the account ids found in the contact list
_serviceWrapper.query("Select Id, Name, BillingCity From Account Where Id in (" + acctIdss + ")",
new SfdcAsyncResponder(Event2QueryHandler, faultHandler));
}
protected function Event2QueryHandler(accounts:ArrayCollection):void {
for each (var account:DynamicEntity in accounts) {
for each(var contact:DynamicEntity in TempGridProvider) {
if (contact.AccountId == account.Id) {
contact.AccountName = account.Name + " - " + account.BillingCity;
}
}
}
onQueryResult(TempGridProvider);
private function onQueryResult( rows : ArrayCollection ) : void {
// release previous query results
_serviceWrapper.releaseQueryResults( _gridDataProvider );
// populate datagrid
_gridDataProvider = rows;
// show message in status bar
var status : F3Message = new F3Message( F3Message.STATUS_INFO, "Query came back with " + ( _gridDataProvider == null ? 0 : _gridDataProvider.length ) + " " + _selectedEntity + "s" );
showStatus( status );
TempGridProvider = new ArrayCollection();;
}
This works and displays the Account Name, the problem is that when I use this script and then Sync Changes to SalesForce all the records that have been displayed are identified as needing to be syncronised even if they have only been displayed.
If I skip the function eventQueryHandler, and link my query to the OnQueryResult function then there is no problem, but only the Account Id can be displayed.
How can I stop Air marking these records as having changed, or is there a better way to achieve this??
Thanks in advance, any help is greatly appreciated.
Roy
I think you need to not manipulate the underlying object. There are two options for getting the data to render in a DataGrid.
Option 1 - Create another non-managed ValueObject that holds the values you need to display in the DataGrid. Copy the values when you receive them into the new ValueObject.
Option 2 - Use a labelFunction on the DataGridColumn to fetch the data externally when each cell in a given column is rendered.

Resources