views:

57

answers:

3

Hi guys,

I am wanting to create a VB.Net app that checks a database and then prints out the latest orders, the database is mysql and i need it to periodatically check and only print new orders i.e. not print ones it has already printed out.

Any advice would be greatly appriciated.

Kyle

+2  A: 

I'd recommend breaking the problem down into pieces:

  1. "checks a database" - you'll need to create a connection to a relational database. You'll have to set up either an ADO.NET or ODBC connection to MySQL.
  2. You don't say if the database is running on the same machine as the app. If it's not, you'll have to be able to connect to it on the network.
  3. Make sure that you GRANT the appropriate permissions in MySQL. Don't just use the admin credentials to log in. Set up a separate ID for your app.
  4. "then prints out" - your app will have to find a way to acquire information about a printer. You don't say if it's connected directly to the server on which the job will run or if it's a networked printer. Be sure your app can see the networked printer if it's the latter.
  5. "the latest orders, the database is mysql" - try writing a separate query to test getting only the latest orders.
  6. Does your schema include a way to mark which orders have been printed and when? Your app should INSERT a record noting the timestamp when each order is printed. You can JOIN on this table to figure out what the latest, unprinted orders are.
  7. "and i need it to periodically" - your app needs to be a cron job that's run on a schedule that you specify. Every weekday, hourly? Once a night? You decide when you set up the cron job.
duffymo
+1  A: 

You could try using LINQ and dbLINQ for connecting with MySQL. If you are using .NET Framework 3.5 you may as well take advantage of something like LINQ to speed up development time.

If using WPF for the client application you could use a FlowDocument to layout the order details and then handle printing of the orders. Once they are printed you can update the database or store details locally to mark that order as printed. It depends on your database schema.

Luke
Thank you for your replies.1. Its a Winforms app.2. The printer would be connected to the same machine running the app.3. The db schema is innodb.4. the db is remote5. I have never used LINQ.One final question how would i run a cron within VB.net?Kyle
Kyle Hudson
You could use something like Scheduled Tasks in Windows XP (http://support.microsoft.com/kb/308569) or Task Scheduler in Windows Vista / 7. There should be API access to these Windows tools.
Luke
Thanks Luke, I shall look into that.
Kyle Hudson
+6  A: 

My suggestion is to add a printed flag to your database, i.e. add a printed field in the database which stores 0 by default denoting the entry has not been printed and a 1 that denotes the entry has been printed.

I would then create an application which checks the database table for all entries where flag = 0.

These entries are the ones that need printed.

Print each entry an set its flag to 1 in the database. Setting the flag to 1 ensures that the next time you poll the database the entries will be ignored.

Michael Eakins
@Meakins: this is the solution we came up with thank you. This thread is 6 months old now. Thank you though.
Kyle Hudson