13 Replies - 754 Views - Last Post: 21 March 2012 - 08:52 PM Rate Topic: -----

#1 Zigon  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 20-January 12

Followup for "Reading other application output"

Posted 19 March 2012 - 09:22 PM

I've been missunderstood...

Quote

Otherwise we're not going to help you eavesdrop on commercial software so you can gather credit card details.

It is nothing like that!
All payements are made by cash only, so there is no need for credit card details. All we want is to pull a draw (something like bingo or something - I do not know how it is called in English) and all I need is the "bill number" (that is the number of the transaction on the bill, the customer recieves when the payement is made) and the amount on that bill.
I can do that by entering those numbers by hand, but that wound be time consuming when ringing bills and all I wanted is to automate the whole thing. As for today, we're doing it "by hand", so we print the copy of the bill, the customer signs it and the at the end of the period, we calculate the sums and worked out which one was the best customer, so we could give-out the gift...
I am sorry as English is not my native language and it's been a while since I wrote or try to explain soething in English...

Now I do hope you understand what I mean and what I am trying to acchieve. There are absolutely no bad intentions there as there is no need to collect ANY of the vital customer info (we really do not need it anyway). We're just tryin to track how the bussiness is going and reward the best buyers (I hope I wrote that right).

Regards and best wishes!

This post has been edited by tlhIn`toq: 21 March 2012 - 05:27 AM
Reason for edit:: tag fix


Is This A Good Question/Topic? 0
  • +

Replies To: Followup for "Reading other application output"

#2 Robin19  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 272
  • Posts: 552
  • Joined: 07-July 10

Re: Followup for "Reading other application output"

Posted 20 March 2012 - 04:44 AM

Quote

All we want is to pull a draw (something like bingo or something - I do not know how it is called in English)

Raffle or lottery would probably be the American English word you are looking for.

It still stands that you are eavesdropping on commercial software. If there is a SQL database already being used by the software, I would find a way to query that data than try to replicate parts of that data in another space. Or find out if the software you are using can somehow give you a report that you can use. At work, we have one piece of software that records the data in a proprietary format. We want to run a report off of it, which would be easy with SQL Reporting Services. Instead, we "export" the data into a CSV and use Crystal Reports to read the data. It wouldn't be that hard to use C# to read the CSV and do what you want to do.
Was This Post Helpful? 0
  • +
  • -

#3 Zigon  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 20-January 12

Re: Followup for "Reading other application output"

Posted 20 March 2012 - 05:53 AM

Thanks for the reply!

Actually I was thinking about (also tried it) redirecting the printer to the text file and then red the lines, but there's a problem printing into the file and to the printer at the same time.

About querying the database, I had a problem opening it, because the system wouldn't allow me to do so (err.: the file is allready in use). My guess would be it's being used (locked) by SQL server. That's because even if I close down the application, I still cannot access the database.

Therefore I was thinking about reading the printer output directly, catching the escape sequences for the new line, so I could count the lines.

All I am interested in is the bill number (I hope it called that) and the amount on that bill. I would then save that data along with the customer ID (or name) to my database. At the end of the period, I would pull that data out and pay out the present.

The easiest way for me would be to connect to the DB (I have established the connection) but I can't open it, to read the data.

Now, I hoe you understand, what I mean...

Regards and best wishes!
Was This Post Helpful? 0
  • +
  • -

#4 Zigon  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 20-January 12

Re: Followup for "Reading other application output"

Posted 20 March 2012 - 06:01 AM

Can't find the "Edit" button, so...

Another problem is, that I need to do this "on the fly" - for every transaction being made by the clerk.
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5520
  • View blog
  • Posts: 11,827
  • Joined: 02-June 10

Re: Followup for "Reading other application output"

Posted 20 March 2012 - 10:54 AM

I think Robin had the better answer: Just ask the database what receipt (docket) numbers have been issued.

IF you aren't notifying people they are winners in real time at the checkout stand you could also (programmatically) query the database for the start and end receipt numbers for that day and select one at random. Then post a sign saying "Tuesday's winner: Docket 123465" It brings people back if only to check their numbers, and returning customers mean more sales.
Was This Post Helpful? 0
  • +
  • -

#6 Zigon  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 20-January 12

Re: Followup for "Reading other application output"

Posted 20 March 2012 - 10:26 PM

Quote

you could also (programmatically) query the database

well, this is the problem! It just won't let me!
When I try to open the database, I get the error saying that the file is allready in use.

I've tried closing the main application, but to no avail. The error was still there... hence my question about reading the printer output.

Maybe I'm doing it all wrong. I don't know. But this seemed to be the easiest solution at the time.

If only I could open the database (just for reading) that would solve the problem.

I was thinking also about enumerating the main window of the application with some native API calls (FindWindow, FindWindowEx) catching the text with SendMessage with WM_GETTEXT. But I believe this would be too much hassle and also it would resolve only part of my problem as the "docket" number is not displayed.

Any suggestions?

Regards and best wishes!
Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Followup for "Reading other application output"

Posted 21 March 2012 - 05:27 AM

View PostZigon, on 21 March 2012 - 01:26 AM, said:

When I try to open the database, I get the error saying that the file is allready in use.


How are you trying to opening it?
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5520
  • View blog
  • Posts: 11,827
  • Joined: 02-June 10

Re: Followup for "Reading other application output"

Posted 21 March 2012 - 05:30 AM

What "file"? What is the type of database being used for this?

Database tutorials:

See FAQ # 21. (Click the SHOW button below)


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Mar 2012
Spoiler



Was This Post Helpful? 0
  • +
  • -

#9 Zigon  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 20-January 12

Re: Followup for "Reading other application output"

Posted 21 March 2012 - 06:08 AM

Actually it happens when I point to it with the OpenFile dialog
		private void btnOpenFile_Click(object sender, EventArgs e)
			{
			OpenFileDialog ofd = new OpenFileDialog();
			ofd.ShowDialog();
			//if ofd.FileOk
			filePath = ofd.FileName;

			}



I then include the filePath string into my Connectionstring. Like this:
            con = new System.Data.SqlClient.SqlConnection();
            ds1 = new DataSet();
            string sql = "SELECT * FROM POSRacuni";
			FindFile();
            con.ConnectionString="Data Source=.\\SQLEXPRESS;AttachDbFilename=" + filePath + ";Integrated Security=True;Connect Timeout=30;User Instance=True";



but it never gets there. It stops right on clicking the OPEN button on the OpenFileDialog.


The database is "XXXXXX.mdf" so I guess it's an SQL database. I know it contains several tabels (I can see them in backup of the database itself) and I know field names, but the backup is done every seven days or so that data is not relevant.

Regards and best wishes!
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5520
  • View blog
  • Posts: 11,827
  • Joined: 02-June 10

Re: Followup for "Reading other application output"

Posted 21 March 2012 - 06:13 AM

Quote

It stops right on clicking the OPEN button on the OpenFileDialog.


Do you know how to place breakpoints and understand about debugging?
You shouldn't be guessing which line of code its stopping on.

I'm suspicious of the FindFile() method call in the second code block. What is the purpose of having that wedged in the middle of your database communication stuff?

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute. Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


See FAQ # 2. (Click the SHOW button below)


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Mar 2012
Spoiler



Was This Post Helpful? 1
  • +
  • -

#11 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Followup for "Reading other application output"

Posted 21 March 2012 - 06:15 AM

Check the Services on the PC to see if the SQLEXPRESS service is running. If so, don't try to open the database file. It's already in-use by the database service. Simply connect to the SQLEXPRESS instance WITHOUT attaching the file.
Was This Post Helpful? 2
  • +
  • -

#12 Zigon  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 20-January 12

Re: Followup for "Reading other application output"

Posted 21 March 2012 - 08:14 AM

Thanks guys! I finally got it!
The catch was in thins sentence:

Quote

Simply connect to the SQLEXPRESS instance WITHOUT attaching the file.


I just cannot get used to deal with SQL databases (all I ever worked with was Access DB behind ADO with VB6)

Now it works like a charm!

Now I just have to figure out how to check if there was a record added to the database to trigger my application... I guess I could do it on some interval with a timer and check if the ROWCOUNT has changed...

Again, Thanks a lot!

Regards and best wishes!
Was This Post Helpful? 0
  • +
  • -

#13 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Followup for "Reading other application output"

Posted 21 March 2012 - 11:52 AM

You should look into using the SqlDependency class to do this. I wrote a tutorial on how to use it.

http://www.dreaminco...tabase-changes/

It allows you to effectively monitor the database and the database will let you know when the records change. You give it a specific query, and if anything in that query changes, the database notifies the application and you handle it.
Was This Post Helpful? 2
  • +
  • -

#14 Zigon  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 20-January 12

Re: Followup for "Reading other application output"

Posted 21 March 2012 - 08:52 PM

Brilliat! Thanks again!

I'll give it a go.

Thanks and best wishes!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1