I was published this problem over 10 forums and no one know what the solution for that. i try to make some application that deal with billboards and advertising. When i want to make order for some billboard i need to fillup the billboard number (wich his number is string and not integer) and i need to choose between 2 dates when the billboard is up (for example 01.08.2009 dd;mm;yyyy) for 14 days (until 14.08.2009). This is the first section! If i want to make new order and i choose the same billboard number and the same dates the application need NOT to let me doing the order by messageBox "The billboard is not availble". i was wrote some code and the problem is: i was ordered sign number 23 (for example) between the dates 1.8.2009 - 14.8.2009, then i was try to order the same sign number between 28.7.2009 - 12.8.2009, the application DONT ACCEPT THE ORDER cause the dates was blocked. but then i make order with the same sign number between 5.8.2009 - 13.8.2209 then the application Accept the order.....????????? the code is:
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.Data.Odbc;
namespace
forumArt
{
public partial class addNewCampaign : Form
{
public addNewCampaign()
{
InitializeComponent();
}
private void addNewCampaign_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dataSet1.agents' table. You can move, or remove it, as needed.
this.agentsTableAdapter.Fill(this.dataSet1.agents);
// TODO: This line of code loads data into the 'dataSet1.customers' table. You can move, or remove it, as needed.
this.customersTableAdapter.Fill(this.dataSet1.customers);
// TODO: This line of code loads data into the 'dataSet1.signsDetails' table. You can move, or remove it, as needed.
this.signsDetailsTableAdapter.Fill(this.dataSet1.signsDetails);
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (signNumber.Text == "")
{
MessageBox.Show(" ");
}
if (companyName.Text == "")
{
MessageBox.Show(" ");
}
else
{
try
{
OdbcConnection conn = new OdbcConnection("dsn=forumArtDataBase");
var cmdCheck = new OdbcCommand("SELECT Count(*) FROM Orders WHERE signNumber = ? AND (fromDate BETWEEN ? and ? OR toDate BETWEEN ? AND ?)", conn);
cmdCheck.Parameters.Add(
new OdbcParameter("@p1", OdbcType.Int)).Value = signNumber.Text;
cmdCheck.Parameters.Add(
new OdbcParameter("@p2", OdbcType.DateTime)).Value = fromDate.Value;
cmdCheck.Parameters.Add(
new OdbcParameter("@p3", OdbcType.DateTime)).Value = toDate.Value;
cmdCheck.Parameters.Add(
new OdbcParameter("@p4", OdbcType.DateTime)).Value = fromDate.Value;
cmdCheck.Parameters.Add(
new OdbcParameter("@p5", OdbcType.DateTime)).Value = toDate.Value;
conn.Open();
int result = Convert.ToInt32(cmdCheck.ExecuteScalar());
conn.Close();
if (result > 0)
{
MessageBox.Show(" ");
return;
}
else
{
OdbcCommand indata = new OdbcCommand("insert into orders (signNumber,fromDate,toDate,companyName,comments) values ('"+signNumber.Text+"','"+fromDate.Text+"','"+toDate.Text+"','"+companyName.Text+"','"+comments.Text+"')", conn);
conn.Open();
indata.ExecuteNonQuery();
conn.Close();
MessageBox.Show(" ");
Close();
}
}
catch (OdbcException ex)
{
MessageBox.Show(" " + ex);
}
}
}
}
}