我试图通过在代码中输入事件来使日历正常工作。我对ASP.NET还不熟悉,所以我不知道如何解决这个问题。我一直得到的错误是:“事件”不包含一个带7个参数的构造函数。事件错误:参考事件构造函数
protected void Page_Load(object sender, EventArgs e)
{
DateTime d1;
anEvent[0] = new Event("Event1", "Event one", "08/01/2014", "20.00", "Connie", "222-222-2222", "[email protected]");
anEvent[1] = new Event("Event2", "Event two", "08/15/2014", "80.00", "Cathryn", "555-555-5555", "[email protected]");
anEvent[2] = new Event("Event3", "Event three", "09/05/2014", "50.00", "Charles", "888-888-8888", "[email protected]");
foreach (Event myEvent in anEvent)
{
String anEventDate;
anEventDate = myEvent.EventDate;
d1 = Convert.ToDateTime(anEventDate);
Calendar2.SelectedDates.Add(d1);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
public partial class CurrentEvents : System.Web.UI.Page
{
Event[] anEvent = new Event[3];
protected void Page_Load(object sender, EventArgs e)
{
DateTime d1;
anEvent[0] = new Event("Event1", "Event one", "08/01/2014", "20.00", "Connie", "222-222-2222", "[email protected]");
anEvent[1] = new Event("Event2", "Event two", "08/15/2014", "80.00", "Cathryn", "555-555-5555", "[email protected]");
anEvent[2] = new Event("Event3", "Event three", "09/05/2014", "50.00", "Charles", "888-888-8888", "[email protected]");
foreach (Event myEvent in anEvent)
{
String anEventDate;
anEventDate = myEvent.EventDate;
d1 = Convert.ToDateTime(anEventDate);
Calendar2.SelectedDates.Add(d1);
}
}
protected void Calendar2_DayRender(object sender, DayRenderEventArgs e)
{
String todayDate = DateTime.Today.ToString("MM/dd/yyyy"); ;
String calendarDate;
for (int i = 0; i < Calendar2.SelectedDates.Count; i++)
{
calendarDate = Calendar2.SelectedDates[i].ToString("MM/dd/yyyy");
if (e.Day.Date.CompareTo(Calendar2.SelectedDates[i]) == 0)
{
if (calendarDate.CompareTo(todayDate) < 0)
{
e.Cell.BackColor = System.Drawing.Color.Red;
}
else
if (calendarDate.CompareTo(todayDate) > 0)
{
e.Cell.BackColor = System.Drawing.Color.Blue;
}
else
if (calendarDate.CompareTo(todayDate) == 0)
{
e.Cell.BackColor = System.Drawing.Color.Green;
}
else
{
e.Cell.BackColor = System.Drawing.Color.LightGray;
}
}
}
}
protected void Calendar2_SelectionChanged(object sender, EventArgs e)
{
String selectedDate;
int foundDate = 0;
selectedDate = Calendar2.SelectedDate.ToString("MM/dd/yyyy");
foreach (Event myEvent in anEvent)
{
if (selectedDate.Equals(myEvent.EventDate))
{
this.ControlNewEventControl.updateControl(sender, e, myEvent.EventName, myEvent.EventDescription, myEvent.EventDate, myEvent.EventFee, myEvent.ECordNm, myEvent.ECordNum, myEvent.ECordEml);
ErrorLabel.Text = "";
foundDate = 1;
}
}
if (foundDate == 0)
{
this.ControlNewEventControl.updateControl(sender, e, "", "", "", "", "", "", "");
ErrorLabel.Text = "* There is no Event Scheduled for that Date.<br /> Please Choose Another Date.";
}
Page_Load(sender, e);
}
/* SqlConnection dbConnection = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\Database2.mdf;Integrated Security=True");
DateTime Date;
try
{
dbConnection.Open();
string SQLselectQuery = "SELECT EventDate FROM Event";
using (SqlCommand selectCommand = new SqlCommand(SQLselectQuery, dbConnection))
{
SqlDataReader reader = selectCommand.ExecuteReader();
while (reader.Read())
{
Date = reader.GetDateTime(0);
Calendar2.SelectedDates.Add(Date);
}
}
}
catch (SqlException exception)
{
Response.Write("<p>Error code " + exception.Number + ": " + exception.Message + "</p>");
}
finally
{
dbConnection.Close();
}
}
protected void Calendar2_DayRender(object sender, DayRenderEventArgs e)
{
String todayDate = DateTime.Today.ToString("MM/dd/yyyy"); ;
String calendarDate;
for (int i = 0; i < Calendar2.SelectedDates.Count; i++)
{
calendarDate = Calendar2.SelectedDates[i].ToString("MM/dd/yyyy");
if (e.Day.Date.CompareTo(Calendar2.SelectedDates[i]) == 0)
{
if (calendarDate.CompareTo(todayDate) < 0)
{
e.Cell.BackColor = System.Drawing.Color.Red;
}
else if (calendarDate.CompareTo(todayDate) > 0)
{
e.Cell.BackColor = System.Drawing.Color.Blue;
}
else if (calendarDate.CompareTo(todayDate) == 0)
{
e.Cell.BackColor = System.Drawing.Color.Green;
}
else
{
e.Cell.BackColor = System.Drawing.Color.Fuchsia;
}
}
}
}
protected void Calendar2_SelectionChanged(object sender, EventArgs e)
{
SqlConnection dbConnection = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\Database2.mdf;Integrated Security=True");
try
{
int count = 0;
dbConnection.Open();
string SQLselectQuery = "SELECT * FROM Event WHERE EventDate = @EventDate";
SqlCommand selectCommand = new SqlCommand(SQLselectQuery, dbConnection);
selectCommand.Parameters.AddWithValue("@EventDate", Calendar2.SelectedDate.ToString());
using (selectCommand)
{
SqlDataReader reader = selectCommand.ExecuteReader();
while (reader.Read())
{
count++;
Ename.Text = reader.GetString(1).ToString();
Escript.Text = reader.GetString(2).ToString();
EDate.Text = reader.GetDateTime(3).ToString();
EvFee.Text = reader.GetDecimal(4).ToString();
ECordNm.Text = reader.GetString(5).ToString();
ECordNum.Text = reader.GetString(6).ToString();
ECordEml.Text = reader.GetString(7).ToString();
}
}
if (count == 0)
{
Ename.Text = "";
Escript.Text = "There is no Event for this Date";
EDate.Text = Calendar2.SelectedDate.ToString();
EvFee.Text = "";
ECordNm.Text = "";
ECordNum.Text = "";
ECordEml.Text = "";
}
}
catch (SqlException exception)
{
Response.Write("<p>Error code " + exception.Number + ": " + exception.Message + "</p>");
}
finally
{
dbConnection.Close();
Page_Load(sender, e);
}
} */
protected void Ename_TextChanged(object sender, EventArgs e)
{
}
}
错误很明显 - “Event”类没有一个构造函数需要7个参数。发布'Event'的代码(如果它是你自己的课程),我们可以告诉你更多。 – Tim 2014-09-28 20:03:05
显示您的班级 – meda 2014-09-28 20:11:17
我不太确定要发布哪些代码。我是否发布主aspx页面? – 2014-09-28 20:12:53