如何创建在ASP.net节日历 [英] How to create festival calendar in ASP.net
问题描述
我想从我用了两个阿贾克斯日历让使用asp.net的节日日历和一个TextBox它是一个节日的文本框,我们分别为这寄件者和TODATE进入节日。我想这样做如下点
-
如果我在圣诞节的文本输入和选择寄件者= 25/12/2011年和TODATE = 31 /二千〇十一分之一十二那么这将是有效的
-
如果我选择寄件者= 25/12/2011年和TODATE = 24 /二千〇十一分之一十二那么它将无效
-
如果我选择寄件者= 25/12/2011年和TODATE = 28 /二千〇十一分之一十二那么也实在是无效的,因为它25/12/2011 31/12/2011和未来之间在
-
如果我选择寄件者= 1/1/2011年和TODATE = 1 /二千零十一分之一那么它是有效的
-
如果我选择寄件者= 21/12/2011年和25/12/2011那是因为已经在圣诞节做无效2011/1/1
和所有的日期应该在GridView中显示像25 - 12月2011格式
下面是我的code:
的DateTime DT1 = Convert.ToDateTime(txt_fromdate.Text);
日期时间DT2 = Convert.ToDateTime(txt_todate.Text);
如果(DT1> DT2)
{
con.Open();
COM =新的SqlCommand(BTNN_MovieDB_Festival_Details_InsertCON);
com.Parameters.Add(@寄件者,SqlDbType.VarChar).value的= dateformat_mmdd(txt_fromdate.Text.ToString()修剪());
com.Parameters.Add(@ TODATE,SqlDbType.VarChar).value的= dateformat_mmdd(txt_todate.Text.ToString()修剪());
com.Parameters.Add(@回归,SqlDbType.VarChar).Direction = ParameterDirection.ReturnValue;
com.ExecuteNonQuery();
con.Close();
showdata();
}
否则,如果(DT1< DT2)
{
lblerror.Text =TODATE应该比寄件者更大;}
这code的作用应
静态无效的主要(字串[] args)
{
// allFestivals保存所有的节日列表
// allFestivals值可能来自如数据库其它数据源
清单<节暨GT; allFestivals =新的List<节暨GT;(); //通过插入模拟圣诞节
节日chirstmas =新节()
{
NAME =圣诞节,
的startDate =新日期时间(2011,12,25)
结束日期=新的日期时间(2011,12,31)
};
AddFestival(allFestivals,chirstmas); // NEWYEAR不会插入因为31-12-2011已经
//圣诞节标记为节日
AddFestival(allFestivals,新节()
{
NAME =NEWYEAR
的startDate =新日期时间(2011,12,31)
结束日期=新的日期时间(2012年,1,01)
});
到Console.ReadLine();
} ///<总结>
///新节添加到节日列表
///< /总结>
///< PARAM NAME =allFestivals>< /参数>
///< PARAM NAME =newFestival>< /参数>
静态无效AddFestival(列表<节暨GT; allFestivals,节日newFestival)
{
//如果newFestival符合所有标准才添加到列表
如果(ValidDates(newFestival)及&放大器;
!NameExists(allFestivals,newFestival)及&放大器;
!NonHoliday(allFestivals,newFestival))
{
// allFestivals值可以strored到数据库
allFestivals.Add(newFestival);
}
} ///<总结>
///检查newFestival的startDate或结束日期落入范围内的任何的已
///现有节开始和结束日期
///< /总结>
///< PARAM NAME =日期>< /参数>
///< PARAM NAME =newFestival>< /参数>
///<&回报GT;< /回报>
私人静态布尔NonHoliday(列表<节暨GT;红枣,节日newFestival)
{
返回dates.Exists((日期)=>
newFestival.startDate> = date.startDate和放大器;&安培; newFestival.startDate< = || date.endDate
newFestival.endDate> = date.startDate和放大器;&安培; newFestival.endDate< = date.endDate);
} ///<总结>
///如果节日名称已经存在,返回true,否则返回false
///< /总结>
///< PARAM NAME =日期>< /参数>
///< PARAM NAME =newFestival>< /参数>
///<&回报GT;< /回报>
私人静态布尔NameExists(列表<节暨GT;红枣,节日newFestival)
{
返回日期=空&安培;!&安培;
dates.Count()> 0安培;&安培;
dates.FirstOrDefault((DT)= GT; dt.Name == newFestival.Name)!= NULL;
} ///<总结>
///验证如果结束日期大于或等于开始日期
///< /总结>
///< PARAM NAME =newFestival>< /参数>
///<&回报GT;< /回报>
私人静态布尔ValidDates(节newFestival)
{
返回newFestival.endDate> = newFestival.startDate;
} //数据结构重新presenging节的详细信息
类节
{
公众的DateTime的startDate {搞定;组; }
公共DateTime的结束日期{搞定;组; }
公共字符串名称{;组; }
}
I want to make a festival calendar using asp.net from that I used two ajax calendar and one textbox it is a festival textbox where we enter festival which FromDate and ToDate respectively. I want to do this as following point
If I enter in textbox Christmas and Choose Fromdate=25/12/2011 and ToDate=31/12/2011 then it will be valid
If I choose fromDate=25/12/2011 and ToDate=24/12/2011 then it will invalid
If I choose Fromdate=25/12/2011 and Todate=28/12/2011 then also it is invalid because it coming in between 25/12/2011 and 31/12/2011
If I Choose fromdate=1/1/2011 and ToDate=1/1/2011 then it is valid
If I choose fromdate=21/12/2011 and 25/12/2011 then it is invalid because of already Christmas done in 1/1/2011
And all date should show in gridview like 25-dec-2011 format
Here is my code:
DateTime dt1 = Convert.ToDateTime(txt_fromdate.Text);
DateTime dt2 = Convert.ToDateTime(txt_todate.Text);
if (dt1 > dt2)
{
con.Open();
com = new SqlCommand("BTNN_MovieDB_Festival_Details_Insert", con);
com.Parameters.Add("@fromdate", SqlDbType.VarChar).Value = dateformat_mmdd(txt_fromdate.Text.ToString().Trim());
com.Parameters.Add("@todate", SqlDbType.VarChar).Value = dateformat_mmdd(txt_todate.Text.ToString().Trim());
com.Parameters.Add("@return", SqlDbType.VarChar).Direction = ParameterDirection.ReturnValue;
com.ExecuteNonQuery();
con.Close();
showdata();
}
else if (dt1 < dt2)
{
lblerror.Text = "ToDate should be greater than FromDate";
}
This code should function
static void Main(string[] args)
{
// allFestivals holds all the festival list
// allFestivals values may come from some other data source like database
List<Festival> allFestivals =new List<Festival>();
// Simulate by inserting Christmas
Festival chirstmas = new Festival()
{
Name = "Christmas",
startDate = new DateTime(2011, 12, 25),
endDate = new DateTime(2011, 12, 31)
};
AddFestival(allFestivals, chirstmas);
// NewYear will not be inserted since 31-12-2011 is already
// marked as holiday by Christmas
AddFestival(allFestivals, new Festival()
{
Name = "NewYear",
startDate = new DateTime(2011, 12, 31),
endDate = new DateTime(2012, 1, 01)
});
Console.ReadLine();
}
/// <summary>
/// Add new festival to the list of festivals
/// </summary>
/// <param name="allFestivals"></param>
/// <param name="newFestival"></param>
static void AddFestival(List<Festival> allFestivals, Festival newFestival)
{
// If newFestival meets all the criteria only then add to the list
if (ValidDates(newFestival) &&
!NameExists(allFestivals, newFestival) &&
!NonHoliday(allFestivals, newFestival) )
{
// allFestivals values may be strored into database
allFestivals.Add(newFestival);
}
}
/// <summary>
/// Check if the newFestival startDate or endDate falls within any of the already
/// existing festival start and end date
/// </summary>
/// <param name="dates"></param>
/// <param name="newFestival"></param>
/// <returns></returns>
private static bool NonHoliday(List<Festival> dates, Festival newFestival)
{
return dates.Exists((date) =>
newFestival.startDate >= date.startDate && newFestival.startDate <= date.endDate ||
newFestival.endDate >= date.startDate && newFestival.endDate <= date.endDate);
}
/// <summary>
/// If the festival name already exists, returns true else false
/// </summary>
/// <param name="dates"></param>
/// <param name="newFestival"></param>
/// <returns></returns>
private static bool NameExists(List<Festival> dates, Festival newFestival)
{
return dates != null &&
dates.Count() > 0 &&
dates.FirstOrDefault((dt) => dt.Name == newFestival.Name) != null;
}
/// <summary>
/// Validate if end date is greater than or equal to start date
/// </summary>
/// <param name="newFestival"></param>
/// <returns></returns>
private static bool ValidDates(Festival newFestival)
{
return newFestival.endDate >= newFestival.startDate;
}
// Data structure represenging festival details
class Festival
{
public DateTime startDate { get; set; }
public DateTime endDate { get; set; }
public string Name { get; set; }
}
这篇关于如何创建在ASP.net节日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!