[code=csharp public void SysEventList(string org_id)
{
try
{
//string timeStamp = sysDataRecordService.getTimeStampByTableName(uid,”Event”, new Guid());
Paging<EventUrl> eUrlPage = UrlFunc.EventList();
if (eUrlPage == null || eUrlPage.List == null || eUrlPage.List.Count <= 0) return;
BeginTransaction();
eventList = eventService.GetList().List.ToList();
if (eUrlPage.List != null && eUrlPage.List.Count > 0)
{
UIdRelateEventService ueService = new UIdRelateEventService();
foreach (EventUrl item in eUrlPage.List)
{
Event tempEvent = eventList.FirstOrDefault(d => d.Event_Id == item.event_id);
Guid tempId = new Guid();
if (tempEvent != null)
{
tempId = tempEvent.Id;
Event eObj = tempEvent;
eObj.SponsorName = “”;
eObj.Title = item.title;
eObj.SubTitle = “”;//SysDataRecordService.subStringByLength(item.sub_title, 500);
eObj.ActivityIntroduce = SysDataRecordService.subStringByLength(item.introduce, 5000);
eObj.Site = SysDataRecordService.subStringByLength(item.place_name, 200);
eObj.Province = item.province;
eObj.City = item.city;
eObj.StartDate = item.sdate;
eObj.EndDate = item.edate;
eObj.Status = item.status;
eObj.Address = SysDataRecordService.subStringByLength(item.address, 500);
eObj.Code = item.event_id.ToString();
eObj.Event_Class = item.class_name;
eventService.Update(eObj);
}
else {
Event eObj = new Event();
eObj.Id = Guid.NewGuid();
tempId = eObj.Id;
eObj.Event_Id = item.event_id;
eObj.SponsorName = “”;
eObj.Title = item.title;
eObj.SubTitle = SysDataRecordService.subStringByLength(item.sub_title, 500);
eObj.ActivityIntroduce = SysDataRecordService.subStringByLength(item.introduce, 5000);
eObj.Site = SysDataRecordService.subStringByLength(item.place_name, 200);
eObj.Province = item.province;
eObj.City = item.city;
eObj.StartDate = item.sdate;
eObj.EndDate = item.edate;
eObj.Status = item.status;
eObj.Address = SysDataRecordService.subStringByLength(item.address, 500);
eObj.Code = item.event_id.ToString();
eObj.Event_Class = item.class_name;
eventService.Insert(eObj);
}
//添加主办方与活动关联
DataTable dt = ueService.GetListByOwnEvent(org_id, tempId);
if (dt == null || dt.Rows.Count <= 0)
{
UIdRelateEvent ueObj = new UIdRelateEvent();
ueObj.Id = Guid.NewGuid();
ueObj.User_Id = int.Parse(org_id);
ueObj.OwnEvent = tempId;
ueObj.Event_Id = item.event_id;
ueObj.Status = true;
ueService.Insert(ueObj);
}
}
//tempTimeStamp = eUrlPage.TimeStamp;
//sysDataRecordService.chkAndActionSysDataRecord(uid, “Event”, new Guid(), tempTimeStamp.ToString());
}
Commit();
}
catch (Exception ex)
{
Rollback();
WriteLog.writeErrorLog(“SysServerData:SysEventList()”, “org_id:” + org_id, ex.ToString());
throw ex;
}
}][/code]
数据库是使用SQLine,想问一下在UIdRelateEventService类里GetListByOwnEvent(org_id, tempId)及Insert函数该怎么样书写,请求指导答,实在没想法,下不下去。
{
try
{
//string timeStamp = sysDataRecordService.getTimeStampByTableName(uid,”Event”, new Guid());
Paging<EventUrl> eUrlPage = UrlFunc.EventList();
if (eUrlPage == null || eUrlPage.List == null || eUrlPage.List.Count <= 0) return;
BeginTransaction();
eventList = eventService.GetList().List.ToList();
if (eUrlPage.List != null && eUrlPage.List.Count > 0)
{
UIdRelateEventService ueService = new UIdRelateEventService();
foreach (EventUrl item in eUrlPage.List)
{
Event tempEvent = eventList.FirstOrDefault(d => d.Event_Id == item.event_id);
Guid tempId = new Guid();
if (tempEvent != null)
{
tempId = tempEvent.Id;
Event eObj = tempEvent;
eObj.SponsorName = “”;
eObj.Title = item.title;
eObj.SubTitle = “”;//SysDataRecordService.subStringByLength(item.sub_title, 500);
eObj.ActivityIntroduce = SysDataRecordService.subStringByLength(item.introduce, 5000);
eObj.Site = SysDataRecordService.subStringByLength(item.place_name, 200);
eObj.Province = item.province;
eObj.City = item.city;
eObj.StartDate = item.sdate;
eObj.EndDate = item.edate;
eObj.Status = item.status;
eObj.Address = SysDataRecordService.subStringByLength(item.address, 500);
eObj.Code = item.event_id.ToString();
eObj.Event_Class = item.class_name;
eventService.Update(eObj);
}
else {
Event eObj = new Event();
eObj.Id = Guid.NewGuid();
tempId = eObj.Id;
eObj.Event_Id = item.event_id;
eObj.SponsorName = “”;
eObj.Title = item.title;
eObj.SubTitle = SysDataRecordService.subStringByLength(item.sub_title, 500);
eObj.ActivityIntroduce = SysDataRecordService.subStringByLength(item.introduce, 5000);
eObj.Site = SysDataRecordService.subStringByLength(item.place_name, 200);
eObj.Province = item.province;
eObj.City = item.city;
eObj.StartDate = item.sdate;
eObj.EndDate = item.edate;
eObj.Status = item.status;
eObj.Address = SysDataRecordService.subStringByLength(item.address, 500);
eObj.Code = item.event_id.ToString();
eObj.Event_Class = item.class_name;
eventService.Insert(eObj);
}
//添加主办方与活动关联
DataTable dt = ueService.GetListByOwnEvent(org_id, tempId);
if (dt == null || dt.Rows.Count <= 0)
{
UIdRelateEvent ueObj = new UIdRelateEvent();
ueObj.Id = Guid.NewGuid();
ueObj.User_Id = int.Parse(org_id);
ueObj.OwnEvent = tempId;
ueObj.Event_Id = item.event_id;
ueObj.Status = true;
ueService.Insert(ueObj);
}
}
//tempTimeStamp = eUrlPage.TimeStamp;
//sysDataRecordService.chkAndActionSysDataRecord(uid, “Event”, new Guid(), tempTimeStamp.ToString());
}
Commit();
}
catch (Exception ex)
{
Rollback();
WriteLog.writeErrorLog(“SysServerData:SysEventList()”, “org_id:” + org_id, ex.ToString());
throw ex;
}
}][/code]
数据库是使用SQLine,想问一下在UIdRelateEventService类里GetListByOwnEvent(org_id, tempId)及Insert函数该怎么样书写,请求指导答,实在没想法,下不下去。
public DataTable GetListByOwnEvent(string org_id, Guid tempId) { string sqlstr = "select * from UIdRelateEvent where User_Id = "{0}" and OwnEvent = "{1}""; sqlstr = String.Format(org_id, tempId.ToString()); DataTable dt = SQLite.GetResultTable(sqlstr); List<UIdRelateEvent> elist = new List<UIdRelateEvent>(); if(dt != null && dt.Rows.Count > 0) } public void Insert(UIdRelateEvent ueObj) { string sqlstr = "Insert into UIdRelateEvent(Id,User_Id,OwnEvent,Event_Id,Status) Values("{0}","{1}","{2}","{3}","{4}")"; sqlstr = string.Format(Guid.NewGuid().ToString(),); try { var res = SQLite.ExecuteSql(sqlstr, trans); Commit(); } catch (Exception ex) { Rollback(); throw ex; } finally { DisposeTran(); } }
解决方案
20
你这种查找和插入的方法那就只能是将table里的列一行行取出来赋值给一个Item,然后用集合的ADD方法来了。插入的话一样,你要把集合的属性和数据库的列一一对应。很麻烦的。
建议你可以采用一个 ORM框架来做。Entity Framework 或是Nhibernate,都提供LINQ查询和操作语句,可以大大减少你的工作量,不然以后维护和修改的时候头痛死你
建议你可以采用一个 ORM框架来做。Entity Framework 或是Nhibernate,都提供LINQ查询和操作语句,可以大大减少你的工作量,不然以后维护和修改的时候头痛死你
10
for(int i =0;i<dt.Rows.Count;i++)
{
UIdRelateEvent uidevent = = new UIdRelateEvent();
uidevent.User_ID = dt.Rows[i].cloumn[0] ;
uidevent.OwnEvent = dt.Rows[i].cloumn[1] ;
elist.Add(uidevent);
}
插入的你本人写吧,意思差不多,都是需要列对应的,要用AddParameter添加参数,你去查查。错误本人调
{
UIdRelateEvent uidevent = = new UIdRelateEvent();
uidevent.User_ID = dt.Rows[i].cloumn[0] ;
uidevent.OwnEvent = dt.Rows[i].cloumn[1] ;
elist.Add(uidevent);
}
插入的你本人写吧,意思差不多,都是需要列对应的,要用AddParameter添加参数,你去查查。错误本人调
5
你把函数的返回数据类型改成List别用table,table的数据是没法直接用的
5
public List<UIdRelateEvent> GetListByOwnEvent(string org_id, Guid tempId)
{
{
return elist ;
}