导入日历 ICS文件 完整版(原创)---解析icS文件

   

4月21日 15更新   加了注释, 只留下导入的代码了(解析ICS) 

 

因项目需要,这几天写了个日历导入导出代码 (ICS文件)

 

与大家探讨探讨;

 

转载 请注明出处  liveTea http://www.cnblogs.com/zhegebucuo

 

 

 

ContractedBlock.gif ExpandedBlockStart.gif Code
ContractedBlock.gifExpandedBlockStart.gifTest and please not to delete.#region Test and please not to delete. 
        
public override void VerifyRenderingInServerForm(Control control)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//base.VerifyRenderingInServerForm(control);
        }

        
private ArrayList calendarResult = new ArrayList();// 结果
        private ScheduleEntity seResult = new ScheduleEntity();//日历实体,包括提醒实体,提醒是多重的  所以是个list
 
      
//解析日历格式 时间
        private DateTime getDateTime(string tmp)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//20090406T235959000Z
            string value = "";
            value 
= tmp.Substring(04+ "-" + tmp.Substring(42+ "-" + tmp.Substring(62+ " " +
                tmp.Substring(
92+ ":" + tmp.Substring(112);
            
return Convert.ToDateTime(value);
        }


        
private List<RemindParamEntity> awokeList =new List<RemindParamEntity>();
        
private RemindParamEntity RemindParam = new RemindParamEntity();
        
private void caseCalendar(string tmp,string value )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
if (tmp == "BEGIN")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                alarmBegin 
= true;
                RemindParam 
= new RemindParamEntity();
                
return;
            }

            
else if (tmp == "END")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                awokeList.Add(RemindParam);
                alarmBegin 
= false;
                
return;
            }

            
if (alarmBegin)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
switch (tmp)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
case "ACTION":

                        RemindParam.NeedRemind 
= 1;

                        
break;
                    
case "TRIGGER":

                        RemindParam.TimeValue 
= 1;

                        
break;
                    
default:
                        
                        
break;
                }


            }

            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
switch (tmp)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
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)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{

        }

        
private ArrayList calendarArray = new ArrayList();
        
protected void Button2_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
//拆分成独立 日历
            string[] s = GetStopWords();
            
int sLenth = s.Length;
            List
<string> singleCalendarList= new List<string>();
            
bool calendarBegin = false;
            
for (int i = 0; i < sLenth; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
if (s[i] == "BEGIN:VEVENT")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    calendarBegin 
= true;
                    singleCalendarList
=new List<string>();
                    
//singleCalendarList.Clear();
                }

                
else if (s[i] == "END:VEVENT")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    calendarArray.Add(singleCalendarList);
                    calendarBegin 
= false;
                }

                
else if(calendarBegin)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    singleCalendarList.Add(s[i]);
                }

                
            }

            doWork(calendarArray);
            
        }

        
private void doWork(ArrayList a)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//separate calendar
             List<string> calendar = new List<string>();
            
int len = a.Count;
            
for (int i = 0; i < len; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                calendar 
= (List<string>)a[i];
                doBusiness(calendar);
            }

            
//to do ddataBase
        }

        
private void doBusiness(List<string> L)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//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)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
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

 

 

 

转载于:https://www.cnblogs.com/zhegebucuo/archive/2009/04/20/1439810.html

你可能感兴趣的:(导入日历 ICS文件 完整版(原创)---解析icS文件)