using System;
using System.Text;
using Microsoft.SharePoint;
using System.Data.SqlClient;
namespace EventHandle
{
public class listEventHandle : IListEventSink
{
public void OnEvent(SPListEvent listEvent)
{
try
{
if (listEvent.Type == SPListEventType.Insert)
{
SPWeb web = listEvent.Site.OpenWeb();
SPFile SharePointEventItem = web.GetFile(listEvent.UrlAfter);
SPListItem item = SharePointEventItem.Item;
string itemid = item.ID.ToString();
string name = item["姓名"].ToString();
string destAdd = item["目的"].ToString();
string appDate = item["申请日期"].ToString();
string memo = item["备注"].ToString();
string email = item["Email"].ToString();
string cfd = item["出发地"].ToString();
string mdd = item["目的地"].ToString();
SqlConnection conn = new SqlConnection("Data Source=moss;Initial Catalog=test;integrated security=SSPI");
conn.Open();
SqlCommand cmd = new SqlCommand("insert into t_cs(listitem_id,Name,destAdd,appDate,memo,email,cfd,mdd) values('" + itemid + "','" + name + "','" + destAdd + "','" + appDate + "','" + memo + "','" + email + "','" + cfd + "','" + mdd + "')", conn);
cmd.ExecuteNonQuery();
conn.Close();
}
}
catch (Exception e)
{
System.IO.StreamWriter log = new System.IO.StreamWriter(@"d:\log.txt", true);
log.Write("StackTrace:" + e.StackTrace);
log.Write("Message:" + e.Message);
log.Flush();
log.Close();
}
}
}
}