search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

refresh call to SQL does not work as expected

Asked by John
15 years ago.

I am using the refresh even to reset the datasource for the calendar. I have some custom query fields that are brought in from the Request.Form that are passed to the SQL. It works fine in the initial page load. I store the custom fields in a global variable called addstuff. However when I call the SQL again in the refresh event the addstuff does not appear to work as the calendar returns all the events --not just the ones selected via the addstuff filter variables. I have tried to write out the SQL (via response.write and setting an asp label text), but this does not seem to work within the refresh method. Any help or sample code would be appreciated.

I may be missing something very basic as I normally program in VB

potected void DayPilotCalendar1_Refresh(object sender, RefreshEventArgs e)
{
DayPilotCalendar1.StartDate = DayPilot.Utils.Week.FirstDayOfWeek(e.StartDate);

addstuff = addstuff;


mx= (e.StartDate.Month);
yx= (e.StartDate.Year);
dx= (e.StartDate.Day);

dex = dx + 7;


dbstring = mx +"/" + dx + "/" + yx;

destring = mx +"/" + dex + "/" + yx;

Convert.ToDateTime(mx +"/" + dx + "/" + yx);
// Response.Write("addstuff" + m);


DataTable dt;
dt= new DataTable();



using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["daypilot"].ConnectionString))
{
con.Open();

// SqlDataAdapter ad = new SqlDataAdapter("SELECT [id], [ctype], [A1begin], [A1date], [allday] FROM [citystat] WHERE (([A1date] <= '" + destring + "' ) AND ([A1begin] >= '" + dbstring + "' ))", con);


SqlDataAdapter ad = new SqlDataAdapter("SELECT citystat.id, [ctype], [A1begin], [A1date], [allday] FROM [citystat] INNER JOIN csusers ON citystat.a1actor = CSusers.id INNER JOIN CSdepartments ON csusers.department = CSdepartments.id WHERE [A1date] <= '" + destring + "' AND [A1begin] >= '" + dbstring + "' " + addstuff + " ", con);



DataSet ds = new DataSet();

ad.Fill(ds,"Categories");

DayPilotCalendar1.StartDate = Convert.ToDateTime(e.StartDate);


DayPilotCalendar1.DataSource = ds;
}



DayPilotCalendar1.DataBind();
DayPilotCalendar1.Update();
}

Comment posted by John
15 years ago.

I think I solve it...I really did work on it a long time before posting. I commented out theDayPilotCalendar1.DataBind(); in the refresh method.

Comment posted by John
15 years ago.

My solution was not perfect. I still cannot seem to refresh the data that is being used in the calendar. I tried to call a custom method that calls the SQL from the refresh method, but it never works. Is there a good way to pass the new data that comes from the javascript.dc1.refreshcallback method into a place where I can then run my custom SQL to bring back the new data for the new dates.

protected void datab(String ndate){



Response.Write(ndate);

m= Request.Form["month"];
y= Request.Form["year"];
RadioGroup1a = Request.Form["RadioGroup1a"];
typ= Request.Form["type"];
department = Request.Form["department"];
ctype = Request.Form["ctype"];


if(m != null){

if( RadioGroup1a == "resolved") {
addstuff = addstuff + " AND ( resolved = 1 )";
}

if( RadioGroup1a == "unresolved") {
addstuff = addstuff + " AND ( resolved = 0 )";
}

if(typ != null){
typ = Regex.Replace(typ, "'","*");
}

if( typ == "4" ) {
addstuff = addstuff;
}else{
addstuff = addstuff +" And a1actor = " + typ + " ";
}


if( department == "18" ) {
}else{
addstuff = addstuff + " And csusers.department = " + department + " ";
}


if( ctype == "All" ) {
}else{
addstuff = addstuff + " And citystat.ctype = '" + ctype + "' ";
}

}







// Response.Write("XXXXXXXXXXXXX" + m);

if(m == null){

m = "current";
y = "current";

}
DateTime dtVariable = DateTime.Now;


if(m == "current"){ mx= (dtVariable.Month); }
if(y == "current"){ yx= (dtVariable.Year); }
dx= (dtVariable.Day);

dex = dx + 7;

//



dbstring = mx +"/" + 1 + "/" + yx;


if(mx == 12){ mx = 1; yx = yx +1;}else{ mx = mx + 1;}

destring = mx +"/" + 1 + "/" + yx;

// Convert.ToDateTime(mx +"/" + dx + "/" + yx);
// Response.Write("XXXXXXXXXXXXX" + m);
//

DataTable dt;
dt= new DataTable();



Response.Write( "SELECT citystat.id, [ctype], [A1begin], [A1date], [allday] FROM [citystat] INNER JOIN csusers ON citystat.a1actor = CSusers.id INNER JOIN CSdepartments ON csusers.department = CSdepartments.id WHERE [A1date] <= '" + destring + "' AND [A1begin] >= '" + dbstring + "' " + addstuff + " ");

// Response.End();



using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["daypilot"].ConnectionString))
{
con.Open();




SqlDataAdapter ad = new SqlDataAdapter("SELECT citystat.id, [ctype], [A1begin], [A1date], [allday] FROM [citystat] INNER JOIN csusers ON citystat.a1actor = CSusers.id INNER JOIN CSdepartments ON csusers.department = CSdepartments.id WHERE [A1date] <= '" + destring + "' AND [A1begin] >= '" + dbstring + "' " + addstuff + " ", con);





DataSet ds = new DataSet();

ad.Fill(ds,"Categories");

DayPilotCalendar1.StartDate = Convert.ToDateTime(dtVariable);


DayPilotCalendar1.DataSource = ds;
}

}


This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.