Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statement, scanner input and conditional validation!

Status
Not open for further replies.

proximity

Technical User
Sep 19, 2002
132
0
0
GB
Hi,

I am using Asp.Net 4, C# and MySQL for a task scanning project. Everything works, except I cannot figure out what to do with the else bit!

I have a text box that takes input from a barcode scanner. When the data is received, a TextChanged event calls the code below:

Code:
protected void CheckTaskStatus()
    {
        {
            conn.Open();
            string sqlA = "SELECT COUNT(task_id) FROM tasks WHERE emp_no = '" + this.txtEmployee.Text + "' AND task_end IS NULL AND DATE(task_start) >= CURDATE()-INTERVAL 320 MINUTE";

            MySqlCommand cmd = new MySqlCommand(sqlA, conn);
            Int64 mCount = (Int64)cmd.ExecuteScalar();
            conn.Close();

            if (mCount == 0) //if there is no task assigned to the user, create a new one
            {
                lblMessage.Text = "<h1>User " + txtEmployeeNumber.Text + " is inactive, let's create a New Task</h1>";
               CreateNewJob(); //this works, no problems
            }

            else
            {
               [b] //is user has a task, we need to close it here[/b]
            }
        }

In the else bit (because the result is 1), we need to evaluate two things using the scanned value:

string sqlB = "SELECT task REGEXP '[0-9]' FROM tasks WHERE task_end IS NULL AND employee_no = '" + this.txtEmployeeNumber.Text + "' AND DATE(task_start) >= CURDATE()-INTERVAL 320 MINUTE;";

If sqlB = 1 then call come code


string sqlC = "SELECT task NOT REGEXP '[0-9]' FROM tasks WHERE task_end IS NULL AND employee_no = '" + this.txtEmployeeNumber.Text + "' AND DATE(task_start) >= CURDATE()-INTERVAL 320 MINUTE;";

If sqlC = 1 then call some code

Any help greatly appreciated!

Thank you.
 

Shouldn't the REGEXP be in the WHERE clause?

Code:
SELECT taskCount= COUNT(*) 
FROM tasks 
WHERE   task_end IS NULL AND 
        employee_no = '" + this.txtEmployeeNumber.Text + "' AND 
        DATE(task_start) >= CURDATE()-INTERVAL 320 MINUTE
        and task REGEXP '[0-9]'

SELECT taskCount= COUNT(*) 
FROM tasks 
WHERE   task_end IS NULL AND 
        employee_no = '" + this.txtEmployeeNumber.Text + "' AND 
        DATE(task_start) >= CURDATE()-INTERVAL 320 MINUTE
        and task NOT REGEXP '[0-9]'


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top