日渲染在本地数据库中不起作用 [英] Day render not working in local database
问题描述
大家好,我的问题是代码正确无误,因为它在我使用在线数据库时有效,但是当我使用本地数据库时,我的Dayrender不能为日历的单元格上色,我尝试了一切,但似乎没有任何办法解决它....请帮帮我....这是针对一群学生的最后一个项目....
这是前端....
Hello everyone my issue is that the code is proper and everything because its working when i use online database but my dayrender wont work in coloring the cells of the calendar when i am using local database i tried everything but nothing seems to solve it....please help me out....its a final year project for a bunch of students....
this is the front end....
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="newcalendar.aspx.cs" Inherits="newcalendar" Title="Calendar Page" EnableEventValidation="false" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>
<table width="550px" align="left">
<tr>
<td>
<table border="0px" cellpadding="0px" cellspacing="0px" style="width:690px; height:auto" align="left">
<tr style="width:550px;">
<td style="font-size:13px;text-align:center;text-decoration:underline;font-weight:bold; width:690px;">Party Hall Booking Status</td>
</tr>
<tr style="width:690px;">
<td style="font-size:13px;text-align:left;font-weight:bold">
Select Party Hall Name:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataTextField="partyhallname"
DataValueField="partyhallname" Height="22px" Width="200px"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
CssClass="WaterMarkedTextBox" >
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:chaturvedabcon %>"
SelectCommand="SELECT [partyhallname] FROM [PartyHallDetails]">
<br />
<asp:Label ID="Label1" runat="server" Visible="false">
<br />
</td>
</tr>
<%--calendar control--%>
<tr style="width:690px;">
<td style="width:690px;">
<asp:Calendar ID="Calendar1" runat="server" BackColor="White"
DayStyle-Height="80px" DayStyle-Width="690px"
BorderColor="Black" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black"
Height="475px" Width="690px"
OnDayRender="Calendar1_DayRender"
onselectionchanged="Calendar1_SelectionChanged"
SelectMonthText="" BorderStyle="Solid"
NextPrevFormat="FullMonth" ShowGridLines="True" CellPadding="0">
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<weekenddaystyle width="690px" />
<todaydaystyle backcolor="#999999" borderstyle="None" forecolor="White" />
<othermonthdaystyle forecolor="#999999" />
<daystyle backcolor="White" />
<nextprevstyle font-size="8pt" forecolor="White" borderstyle="None">
Font-Bold="True" />
<dayheaderstyle font-bold="True" height="8pt" font-size="8pt">
ForeColor="White" BackColor="#009999" />
<TitleStyle BackColor="#3399FF" Font-Bold="True"
Font-Size="12pt" ForeColor="White" BorderStyle="Solid" Height="12pt" />
</dayheaderstyle></nextprevstyle></td>
</tr>
<tr>
<%-- <td align="right">
<asp:DropDownList ID="DropDownList3" runat="server">
<asp:ListItem Value="Word">Word
<asp:ListItem Value="Excel">Excel
<asp:ImageButton ID="ImageButton2" runat="server"
ImageUrl="~/images/buttons/blue_export_button.jpg" Height="21px" onclick="ImageButton1_Click"
Width="60px" />
</td>--%>
<td><br /></td>
</tr>
<tr style="width:auto;">
<td>
<div style="background-color:#2F4F4F ;color:White;font-family:Tahoma;font-size:12px;text-align:left;font-weight:bold;">DarkSlateGray color for booked hall.</div>
<div style="color:Black;font-family:Tahoma;font-size:12px;text-align:left;font-weight:bold;background-color:White;">White color for Available hall.</div>
<div style="background-color:#C0C0C0;color:Black;font-family:Tahoma;font-size:12px;text-align:left;font-weight:bold;">LightGray color for Temperory booked hall.</div>
</td>
</tr>
</table>
<br />
</td>
</tr>
</table>
</div>
这是代码的后端.....
and this is the back end of the code.....
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Drawing;
public partial class newcalendar : System.Web.UI.Page
{
SqlConnection myCon = new SqlConnection();
DataTable dt = new DataTable();
public static ArrayList MyColllection;
public struct My_Date
{
public DateTime Cal_Date;
public string Cal_Status;
}
protected void Page_Load(object sender, EventArgs e)
{
String connectionString = ConfigurationManager.ConnectionStrings["chaturvedabcon"].ToString();
myCon.ConnectionString = connectionString;
if (!Page.IsPostBack)
{
Getdata();
MyColllection = Get_Event();
//maintaining masterpage controls
if (Session["uname"] != null)
{
if (Session["area"] != null)
{
TextBox tb = (TextBox)Master.FindControl("txtccl");
DropDownList ddl = (DropDownList)Master.FindControl("ddlarea");
ddl.SelectedValue = Session["area"].ToString();
tb.Text = Session["selecteddate"].ToString();
}
if (Session["puname"] != null)
{
if (Session["area"] != null)
{
TextBox tb = (TextBox)Master.FindControl("txtccl");
DropDownList ddl = (DropDownList)Master.FindControl("ddlarea");
ddl.SelectedValue = Session["area"].ToString();
tb.Text = Session["selecteddate"].ToString();
}
}
}
}
}
//maintaining the patyhalls which are in active status
private void Getdata()
{
try
{
string qury = "select distinct partyhallname from PartyHallDetails where mstr_id in (select mstr_id from master_admin where status='active' and role='partyadmin')";
SqlCommand cmd = new SqlCommand(qury, myCon);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
}
catch (Exception)
{
Response.Redirect("index.aspx");
}
}
//selecting the partyhall with respect of displaying list
public ArrayList Get_Event()
{
string str = "SELECT * FROM Booking where partyhallname='" + DropDownList1.SelectedValue + "'";
SqlCommand myComd = new SqlCommand(str, myCon);
SqlDataReader myDataReader;
try
{
myCon.Open();
myDataReader = myComd.ExecuteReader();
MyColllection = new ArrayList();
My_Date temp;
while (myDataReader.Read())
{
String yy = myDataReader["chkin_year"].ToString();
String mm = myDataReader["chkin_month"].ToString();
String dd = myDataReader["chkin_day"].ToString();
String bdate = mm + "/" + dd + "/" + yy;
temp.Cal_Status = myDataReader.GetValue(13).ToString();
temp.Cal_Date = Convert.ToDateTime(bdate);
MyColllection.Add(temp);
}
}
catch
{
}
finally
{
myCon.Close();
}
return MyColllection;
}
//displaying the calendar with current status(like with available and booking dates)
public void Calendar1_DayRender(object o, DayRenderEventArgs e)
{
DateTime today = Convert.ToDateTime(DateTime.Now.ToShortDateString());
DateTime bfor = Convert.ToDateTime(e.Day.Date.ToShortDateString());
if (bfor < today)
{
e.Cell.BackColor = ColorTranslator.FromHtml("#F7F6F3");//#a9a9a9 #0090cc
e.Day.IsSelectable = false;
//e.Cell.Text = "x";
}
try
{
string compDate = DateTime.Now.ToString();// "2011/07/01"; // Date to compare initially
DateTime DayVal = Convert.ToDateTime(compDate);
bool mItemDay = false;
bool dayTextChanged = false;
StringBuilder strTemp = new StringBuilder();
foreach (My_Date temp_dt in MyColllection)
{
if (compDate != temp_dt.Cal_Date.ToShortDateString())
{
if (dayTextChanged == true)
{
break;
}
mItemDay = false;
DayVal = temp_dt.Cal_Date;
}
else
{
mItemDay = true;
}
if (e.Day.Date == Convert.ToDateTime(temp_dt.Cal_Date.ToString("d")))
{
if (mItemDay == false)
{
strTemp = new StringBuilder();
}
else
{
strTemp.Append("<br>");
}
strTemp.Append("<span style="font-family:verdana;font-size:10px;font-weight:bold;color" hold=" /> strTemp.Append("></span></br>
Code tags added - LOSMAC[/EDIT]
Code tags added - LOSMAC[/EDIT]
推荐答案
ConnectionStrings:chaturvedabcon %>" SelectCommand="SELECT [partyhallname] FROM [PartyHallDetails]"> < br > <asp:Label ID="Label1" runat="server" Visible="false"> < br > < /td > < /tr > <%--calendar control--%> <tr style="width:690px;"> <td style="width:690px;"> <asp:Calendar ID="Calendar1" runat="server" BackColor="White" DayStyle-Height="80px" DayStyle-Width="690px" BorderColor="Black" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="475px" Width="690px" OnDayRender="Calendar1_DayRender" onselectionchanged="Calendar1_SelectionChanged" SelectMonthText="" BorderStyle="Solid" NextPrevFormat="FullMonth" ShowGridLines="True" CellPadding="0"> <SelectedDayStyle BackColor="#333399" ForeColor="White" /> <weekenddaystyle width="690px" /> <todaydaystyle backcolor="#999999" borderstyle="None" forecolor="White" /> < 其他月份 样式 forecolor =" #999999" / > <daystyle backcolor="White" /> <nextprevstyle font-size="8pt" forecolor="White" borderstyle="None"> Font-Bold="True"/> <dayheaderstyle font-bold="True" height="8pt" font-size="8pt"> ForeColor="White" BackColor="#009999"/> <TitleStyle BackColor="#3399FF" Font-Bold="True" span> 字体大小 =" 12pt" ForeColor="White" BorderStyle="Solid" Height="12pt" /> </dayheaderstyle></nextprevstyle></td> < /tr > < tr > <%-- <td align="right"> <asp:DropDownList ID="DropDownList3" runat="server"> <asp:ListItem Value="Word">Word <asp:ListItem Value="Excel">Excel <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/buttons/blue_export_button.jpg" Height="21px" onclick="ImageButton1_Click" Width="60px"/> </td> -%> <td><br /></td> < /tr > <tr style="width:auto;"> < td > <div style="background-color:#2F4F4F ;color:White;font-family:Tahoma;font-size:12px;text-align:left;font-weight:bold;">DarkSlateGray color for booked hall.</div> <div style="color:Black;font-family:Tahoma;font-size:12px;text-align:left;font-weight:bold;background-color:White;">White color for Available hall.</div> <div style="background-color:#C0C0C0;color:Black;font-family:Tahoma;font-size:12px;text-align:left;font-weight:bold;">LightGray color for Temperory booked hall.</div> < /td > < /tr > < /table > < br > < /td > < /tr > < /table > </div>
ConnectionStrings:chaturvedabcon %>" SelectCommand="SELECT [partyhallname] FROM [PartyHallDetails]"> <br /> <asp:Label ID="Label1" runat="server" Visible="false"> <br /> </td> </tr> <%--calendar control--%> <tr style="width:690px;"> <td style="width:690px;"> <asp:Calendar ID="Calendar1" runat="server" BackColor="White" DayStyle-Height="80px" DayStyle-Width="690px" BorderColor="Black" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="475px" Width="690px" OnDayRender="Calendar1_DayRender" onselectionchanged="Calendar1_SelectionChanged" SelectMonthText="" BorderStyle="Solid" NextPrevFormat="FullMonth" ShowGridLines="True" CellPadding="0"> <SelectedDayStyle BackColor="#333399" ForeColor="White" /> <weekenddaystyle width="690px" /> <todaydaystyle backcolor="#999999" borderstyle="None" forecolor="White" /> <othermonthdaystyle forecolor="#999999" /> <daystyle backcolor="White" /> <nextprevstyle font-size="8pt" forecolor="White" borderstyle="None"> Font-Bold="True" /> <dayheaderstyle font-bold="True" height="8pt" font-size="8pt"> ForeColor="White" BackColor="#009999" /> <TitleStyle BackColor="#3399FF" Font-Bold="True" Font-Size="12pt" ForeColor="White" BorderStyle="Solid" Height="12pt" /> </dayheaderstyle></nextprevstyle></td> </tr> <tr> <%-- <td align="right"> <asp:DropDownList ID="DropDownList3" runat="server"> <asp:ListItem Value="Word">Word <asp:ListItem Value="Excel">Excel <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/buttons/blue_export_button.jpg" Height="21px" onclick="ImageButton1_Click" Width="60px" /> </td>--%> <td><br /></td> </tr> <tr style="width:auto;"> <td> <div style="background-color:#2F4F4F ;color:White;font-family:Tahoma;font-size:12px;text-align:left;font-weight:bold;">DarkSlateGray color for booked hall.</div> <div style="color:Black;font-family:Tahoma;font-size:12px;text-align:left;font-weight:bold;background-color:White;">White color for Available hall.</div> <div style="background-color:#C0C0C0;color:Black;font-family:Tahoma;font-size:12px;text-align:left;font-weight:bold;">LightGray color for Temperory booked hall.</div> </td> </tr> </table> <br /> </td> </tr> </table> </div>
and this is the back end of the code.....
and this is the back end of the code.....
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Drawing;
public partial class newcalendar : System.Web.UI.Page
{
SqlConnection myCon = new SqlConnection();
DataTable dt = new DataTable();
public static ArrayList MyColllection;
public struct My_Date
{
public DateTime Cal_Date;
public string Cal_Status;
}
protected void Page_Load(object sender, EventArgs e)
{
String connectionString = ConfigurationManager.ConnectionStrings["chaturvedabcon"].ToString();
myCon.ConnectionString = connectionString;
if (!Page.IsPostBack)
{
Getdata();
MyColllection = Get_Event();
//maintaining masterpage controls
if (Session["uname"] != null)
{
if (Session["area"] != null)
{
TextBox tb = (TextBox)Master.FindControl("txtccl");
DropDownList ddl = (DropDownList)Master.FindControl("ddlarea");
ddl.SelectedValue = Session["area"].ToString();
tb.Text = Session["selecteddate"].ToString();
}
if (Session["puname"] != null)
{
if (Session["area"] != null)
{
TextBox tb = (TextBox)Master.FindControl("txtccl");
DropDownList ddl = (DropDownList)Master.FindControl("ddlarea");
ddl.SelectedValue = Session["area"].ToString();
tb.Text = Session["selecteddate"].ToString();
}
}
}
}
}
//maintaining the patyhalls which are in active status
private void Getdata()
{
try
{
string qury = "select distinct partyhallname from PartyHallDetails where mstr_id in (select mstr_id from master_admin where status='active' and role='partyadmin')";
SqlCommand cmd = new SqlCommand(qury, myCon);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
}
catch (Exception)
{
Response.Redirect("index.aspx");
}
}
//selecting the partyhall with respect of displaying list
public ArrayList Get_Event()
{
string str = "SELECT * FROM Booking where partyhallname='" + DropDownList1.SelectedValue + "'";
SqlCommand myComd = new SqlCommand(str, myCon);
SqlDataReader myDataReader;
try
{
myCon.Open();
myDataReader = myComd.ExecuteReader();
MyColllection = new ArrayList();
My_Date temp;
while (myDataReader.Read())
{
String yy = myDataReader["chkin_year"].ToString();
String mm = myDataReader["chkin_month"].ToString();
String dd = myDataReader["chkin_day"].ToString();
String bdate = mm + "/" + dd + "/" + yy;
temp.Cal_Status = myDataReader.GetValue(13).ToString();
temp.Cal_Date = Convert.ToDateTime(bdate);
MyColllection.Add(temp);
}
}
catch
{
}
finally
{
myCon.Close();
}
return MyColllection;
}
//displaying the calendar with current status(like with available and booking dates)
public void Calendar1_DayRender(object o, DayRenderEventArgs e)
{
DateTime today = Convert.ToDateTime(DateTime.Now.ToShortDateString());
DateTime bfor = Convert.ToDateTime(e.Day.Date.ToShortDateString());
if (bfor < today)
{
e.Cell.BackColor = ColorTranslator.FromHtml("#F7F6F3");//#a9a9a9 #0090cc
e.Day.IsSelectable = false;
//e.Cell.Text = "x";
}
try
{
string compDate = DateTime.Now.ToString();// "2011/07/01"; // Date to compare initially
DateTime DayVal = Convert.ToDateTime(compDate);
bool mItemDay = false;
bool dayTextChanged = false;
StringBuilder strTemp = new StringBuilder();
foreach (My_Date temp_dt in MyColllection)
{
if (compDate != temp_dt.Cal_Date.ToShortDateString())
{
if (dayTextChanged == true)
{
break;
}
mItemDay = false;
DayVal = temp_dt.Cal_Date;
}
else
{
mItemDay = true;
}
if (e.Day.Date == Convert.ToDateTime(temp_dt.Cal_Date.ToString("d")))
{
if (mItemDay == false)
{
strTemp = new StringBuilder();
}
else
{
strTemp.Append("<br>");
}
strTemp.Append("<span style="font-family:verdana;font-size:10px;font-weight:bold;color" hold=" /> strTemp.Append("></span></br>
Code tags added - LOSMAC[/EDIT]
Code tags added - LOSMAC[/EDIT]
这篇关于日渲染在本地数据库中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!