4月21日 15更新 加了注释, 只留下导入的代码了(解析ICS)
因项目需要,这几天写了个日历导入导出代码 (ICS文件)
与大家探讨探讨;
转载 请注明出处 liveTea http://www.cnblogs.com/zhegebucuo
Code
Test and please not to delete.#region Test and please not to delete.
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}
private ArrayList calendarResult = new ArrayList();// 结果
private ScheduleEntity seResult = new ScheduleEntity();//日历实体,包括提醒实体,提醒是多重的 所以是个list
//解析日历格式 时间
private DateTime getDateTime(string tmp)
{
//20090406T235959000Z
string value = "";
value = tmp.Substring(0, 4) + "-" + tmp.Substring(4, 2) + "-" + tmp.Substring(6, 2) + " " +
tmp.Substring(9, 2) + ":" + tmp.Substring(11, 2);
return Convert.ToDateTime(value);
}
private List<RemindParamEntity> awokeList =new List<RemindParamEntity>();
private RemindParamEntity RemindParam = new RemindParamEntity();
private void caseCalendar(string tmp,string value )
{
if (tmp == "BEGIN")
{
alarmBegin = true;
RemindParam = new RemindParamEntity();
return;
}
else if (tmp == "END")
{
awokeList.Add(RemindParam);
alarmBegin = false;
return;
}
if (alarmBegin)
{
switch (tmp)
{
case "ACTION":
RemindParam.NeedRemind = 1;
break;
case "TRIGGER":
RemindParam.TimeValue = 1;
break;
default:
break;
}
}
else
{
switch (tmp)
{
case "DTSTART":
seResult.BeginTime = getDateTime(value);
break;
case "DTEND":
seResult.EndTime = getDateTime(value);
break;
case "DTSTAMP":
// seResult.CreateTime = getDateTime(value);
;
break;
case "UID":
//seResult.ScheduleID = 1;
;
break;
case "CLASS":
seResult.ScheduleTypeSet = value;
break;
case "CREATED":
seResult.CreateTime = getDateTime(value);
break;
case "DESCRIPTION":
seResult.Brief = value;
break;
case "LAST-MODIFIED":
//seResult.CreateTime = getDateTime(value);
;
break;
case "LOCATION":
seResult.Place = value;
break;
case "SEQUENCE":
//
;
break;
case "STATUS":
//;
;
break;
case "SUMMARY":
seResult.Summary = value;
break;
case "TRANSP":
//;
;
break;
default:
;
break;
}
}
// return "";
}
private void caseAlart(string tmp, string value)
{
}
private ArrayList calendarArray = new ArrayList();
protected void Button2_Click(object sender, EventArgs e)
{
//拆分成独立 日历
string[] s = GetStopWords();
int sLenth = s.Length;
List<string> singleCalendarList= new List<string>();
bool calendarBegin = false;
for (int i = 0; i < sLenth; i++)
{
if (s[i] == "BEGIN:VEVENT")
{
calendarBegin = true;
singleCalendarList=new List<string>();
//singleCalendarList.Clear();
}
else if (s[i] == "END:VEVENT")
{
calendarArray.Add(singleCalendarList);
calendarBegin = false;
}
else if(calendarBegin)
{
singleCalendarList.Add(s[i]);
}
}
doWork(calendarArray);
}
private void doWork(ArrayList a)
{
//separate calendar
List<string> calendar = new List<string>();
int len = a.Count;
for (int i = 0; i < len; i++)
{
calendar = (List<string>)a[i];
doBusiness(calendar);
}
//to do ddataBase
}
private void doBusiness(List<string> L)
{
//seResult init;
//seResult.BeginTime = "";
//List RList = new List();
//RemindParamEntity RParam = new RemindParamEntity();
//RParam.Place = "Test";
// RList.Add(RParam);
seResult = new ScheduleEntity();
// seResult.RemindParamList = RList;
// ;
//singel calendar business
//wokeList = true;
foreach(string calendar in L)
{
string[] subChild = calendar.Split(':');
//if (subChild[0] == "BEGIN:VALARM")
// {
// }
//else
// {
caseCalendar(subChild[0], subChild[1]);
// }
}
seResult.RemindParamList = awokeList;
calendarResult.Add(seResult);
//clear
awokeList = new List<RemindParamEntity>();
//wokeList = false;
}
#endregion
Test and please not to delete.#region Test and please not to delete.
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}
private ArrayList calendarResult = new ArrayList();// 结果
private ScheduleEntity seResult = new ScheduleEntity();//日历实体,包括提醒实体,提醒是多重的 所以是个list
//解析日历格式 时间
private DateTime getDateTime(string tmp)
{
//20090406T235959000Z
string value = "";
value = tmp.Substring(0, 4) + "-" + tmp.Substring(4, 2) + "-" + tmp.Substring(6, 2) + " " +
tmp.Substring(9, 2) + ":" + tmp.Substring(11, 2);
return Convert.ToDateTime(value);
}
private List<RemindParamEntity> awokeList =new List<RemindParamEntity>();
private RemindParamEntity RemindParam = new RemindParamEntity();
private void caseCalendar(string tmp,string value )
{
if (tmp == "BEGIN")
{
alarmBegin = true;
RemindParam = new RemindParamEntity();
return;
}
else if (tmp == "END")
{
awokeList.Add(RemindParam);
alarmBegin = false;
return;
}
if (alarmBegin)
{
switch (tmp)
{
case "ACTION":
RemindParam.NeedRemind = 1;
break;
case "TRIGGER":
RemindParam.TimeValue = 1;
break;
default:
break;
}
}
else
{
switch (tmp)
{
case "DTSTART":
seResult.BeginTime = getDateTime(value);
break;
case "DTEND":
seResult.EndTime = getDateTime(value);
break;
case "DTSTAMP":
// seResult.CreateTime = getDateTime(value);
;
break;
case "UID":
//seResult.ScheduleID = 1;
;
break;
case "CLASS":
seResult.ScheduleTypeSet = value;
break;
case "CREATED":
seResult.CreateTime = getDateTime(value);
break;
case "DESCRIPTION":
seResult.Brief = value;
break;
case "LAST-MODIFIED":
//seResult.CreateTime = getDateTime(value);
;
break;
case "LOCATION":
seResult.Place = value;
break;
case "SEQUENCE":
//
;
break;
case "STATUS":
//;
;
break;
case "SUMMARY":
seResult.Summary = value;
break;
case "TRANSP":
//;
;
break;
default:
;
break;
}
}
// return "";
}
private void caseAlart(string tmp, string value)
{
}
private ArrayList calendarArray = new ArrayList();
protected void Button2_Click(object sender, EventArgs e)
{
//拆分成独立 日历
string[] s = GetStopWords();
int sLenth = s.Length;
List<string> singleCalendarList= new List<string>();
bool calendarBegin = false;
for (int i = 0; i < sLenth; i++)
{
if (s[i] == "BEGIN:VEVENT")
{
calendarBegin = true;
singleCalendarList=new List<string>();
//singleCalendarList.Clear();
}
else if (s[i] == "END:VEVENT")
{
calendarArray.Add(singleCalendarList);
calendarBegin = false;
}
else if(calendarBegin)
{
singleCalendarList.Add(s[i]);
}
}
doWork(calendarArray);
}
private void doWork(ArrayList a)
{
//separate calendar
List<string> calendar = new List<string>();
int len = a.Count;
for (int i = 0; i < len; i++)
{
calendar = (List<string>)a[i];
doBusiness(calendar);
}
//to do ddataBase
}
private void doBusiness(List<string> L)
{
//seResult init;
//seResult.BeginTime = "";
//List
//RParam.Place = "Test";
// RList.Add(RParam);
seResult = new ScheduleEntity();
// seResult.RemindParamList = RList;
// ;
//singel calendar business
//wokeList = true;
foreach(string calendar in L)
{
string[] subChild = calendar.Split(':');
//if (subChild[0] == "BEGIN:VALARM")
// {
// }
//else
// {
caseCalendar(subChild[0], subChild[1]);
// }
}
seResult.RemindParamList = awokeList;
calendarResult.Add(seResult);
//clear
awokeList = new List<RemindParamEntity>();
//wokeList = false;
}
#endregion