I have a form, in that I have user control(for displaying member name with datetime) and two comboboxes(one is cbstatus values like (refused , accepts , logout) and another combobox cbperiod and values like (today, 7 days, 30 days..)
I am showing the member name along with visit datetime and logout datetime like this..)
by using the following query
sql = @"SELECT member_Firstname, member_Lastname, member_Postcode,
visit_DateTime, visit_Status, visit_Logout_DateTime, visits.member_Id, visit_AlertMsg
FROM members,visits
WHERE members.member_Id = visits.member_Id
AND members.member_Active LIKE 'y%'";
this is working fine …..
I am getting the values depends on the combobox values like this ..
if (cbStatus.Text == "Accepts")
{
sql += " AND visits.visit_Status = 'accepted' ";
}
i have got the two more conditions like this…
if (cbStatus.Text == "refusals")
{
sql += blahh blahh blahhhh
}
i am getting values for selecting cbperiod combobox like this…
if (cbPeriod.Text == "Today")
{
string dtStartString = DateTime.Today.ToString(DataHelper.dateFormat);
sql += string.Format(" AND visits.visit_Date = '{0}'", dtStartString);
}
//here i am comparing the cbstatus value logout and cbperiod text with today to get the member details whose logout datetime is today
if (cbStatus.Text == "Logout" && cbPeriod.Text == "Today")
{
string dtStartString = DateTime.Today.ToString("yyyy-MM-dd");
sql += string.Format(" AND DATE(visits.visit_Logout_DateTime) = '{0}'", dtStartString);
}
and i have got two more conditions like this…. for values in cbstatus and cbperiod
here i binding my values with usercontrol….
datatable dt1 = Helper.GetData(sql);
if (dt1 != null)
{
if (dt1.Rows.Count > 0)
{
foreach (DataRow row in dt1.Rows)
{
newItem = new EntryItem();// this is my usercontrol
if (cbStatus.Text != "Logout")
{
DateTime dtTemp = DateTime.Parse(row["visit_DateTime"].ToString()); // here I am showing the data when user not selected the cbstatus text as logout I mean (refusal,..)
but the below function overrides this data ....
if (cbPeriod.Text == "Today") newItem.lblTime.Text = dtTemp.ToString("HH':'mm':'ss");
else newItem.lblTime.Text = dtTemp.ToString("yyyy'-'MM'-'dd' - 'HH':'mm':'ss");
}
if (row["visit_Logout_DateTime"] != DBNull.Value)
{
DateTime dtlogout = DateTime.Parse(row["visit_Logout_DateTime"].ToString());
if (dtlogout != null)
{
if (cbStatus.Text == "Logout" && cbPeriod.Text == "Today")
{
newItem.lblTime.Text = dtlogout.ToString("HH':'mm':'ss");
newItem.lblName.Text = row["member_Firstname"].ToString() + " " + row["member_Lastname"].ToString();
newItem.lblAlertMessage.Text = row["visit_AlertMsg"].ToString();
}
else
newItem.lblTime.Text = dtlogout.ToString("yyyy'-'MM'-'dd' - 'HH':'mm':'ss");
newItem.lblName.Text = row["member_Firstname"].ToString() + " " + row["member_Lastname"].ToString();
newItem.lblAlertMessage.Text = row["visit_AlertMsg"].ToString();
}
}
newItem.lblName.Text = row["member_Firstname"].ToString() + " " + row["member_Lastname"].ToString();
newItem.lblAlertMessage.Text = row["visit_AlertMsg"].ToString();
when i select cbstatus.text == logout it will showing the correct data with members with logout datetime…
but when i select cbstatus.text == refusals .. it was showing logout data (members with logoutdaatetime) ..this is wrong actual it has to show the refusal members with visit_Datetime
how can i show both data with members has logoutdatetime and visit datetime
Note:one member have both logoutdatetime and visitdatetime….
and my data is like this…
firstname lastname postcode status visit_Logout_DateTime visit_datetime
------------- -------- --------- ------- --------------------- ----------------
rob peter hhd344h refused 2011-05-06 12:09:07 2011-05-06 08:09:34
peter chan hy78kjk refused 2011-09-08 12:09:08 2011-05-03 06:09:34
rock sam yudufg3746h refused 2011-08-08 09:08:45
rob peter hhd344h refused 2011-05-10 12:09:07 2011-05-10 08:09:34
I have solved my problem… like this….