方案设计:
功能包括:信息发布,保存,浏览,修改,查询
问题提出:信息发布内容和格式不能确定,应该允许客户定制信息(名称、类型、显示方式和布局)
每条目信息可以包含一个或多个附件。可以全文检索信息。
采用WSS做后台信息存储,针对于用户定义的信息内容包含数据字典为用户建立一个WSS中的“列表”和一个“文档库”,每条发布的信息存储在“列表”的一个item中,根据列表中每个Item的ID在文档库中建立一个以ID为名称的folder,在folder下存储该item的附件。
利用SPS的search webseivce进行检索
附部分类库源代码:
IPList类
namespace SPSInformationPublish
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///操作信息发布"列表"的类
/// </summary>
public class IPList
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
域#region 域
private string m_Guid;
private string m_SiteUrl;
private SPWeb m_CurrentWeb;
private SPList m_SPList;
private SPSite m_CurrentSite;
private string defaultViewName = "DocManageDefaultView";
#endregion
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
属性#region 属性
private SPList GetSPListByGUID(string guid,SPListCollection spLists)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return spLists.GetList(new Guid(guid),true);
}
catch
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return null;
}
}
public string Guid
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return m_Guid;
}
}
public SPWeb CurrentWeb
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (this.m_CurrentWeb == null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return CurrentSite.OpenWeb();
}
return m_CurrentWeb;
}
}
public SPSite CurrentSite
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (this.m_CurrentSite == null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return GetSPSite();
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return m_CurrentSite;
}
}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_CurrentSite = value;
}
}
public SPList ObjSPList
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return GetSPListByGUID(Guid);
}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ObjSPList = value;
}
}
#endregion
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
构造器#region 构造器
public IPList()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public IPList(string guid,string siteUrl)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_Guid = guid;
m_SiteUrl = siteUrl;
m_CurrentSite = GetSPSite();
m_CurrentWeb = m_CurrentSite.OpenWeb();
}
public IPList(SPList objSPList)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ObjSPList = objSPList;
m_Guid = objSPList.ID.ToString();
CurrentSite = objSPList.ParentWeb.Site;
m_CurrentWeb = objSPList.ParentWeb;
}
#endregion
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
私有方法#region 私有方法
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 为文档库新建一个字段
/// </summary>
/// <param name="FieldName">字段名</param>
/// <param name="Type">字段类型,为SPFieldType枚举</param>
/// <returns>bool</returns>
private void CreateExtendField(string fieldName,string fieldTitle, SPFieldType type,string guid)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
CurrentSite.AllowUnsafeUpdates = true;
CurrentWeb.AllowUnsafeUpdates = true;
SPFieldCollection fields = CurrentWeb.Lists[new Guid(guid)].Fields;
fields.Add(fieldName,type,false);
SPField fld=fields.GetField(fieldName);
fld.Title=fieldTitle;
fld.Update();
//将字段加入到视图中
SPList list = CurrentWeb.Lists[new Guid(guid)];
SPView view = list.DefaultView;
SPViewFieldCollection viewFields = view.ViewFields;
viewFields.Add(fieldName);
view.Update();
}
#endregion
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
公共方法#region 公共方法
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
文档库基本操作#region 文档库基本操作
public SPSite GetSPSite()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return new SPSite(this.m_SiteUrl);
}
public SPList GetSPListByGUID(string guid)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return CurrentWeb.Lists.GetList(new Guid(guid),true);
}
catch
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return null;
}
}
public void Create(string title,string description ,ArrayList objExtendFields)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string id = this.Create(title,description);
CreateView(id);
CreateExtendFields(objExtendFields,id);
}
public string Create(string title,
string description
)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
CurrentSite.AllowUnsafeUpdates = true;
CurrentWeb.AllowUnsafeUpdates = true;
SPListCollection lists = CurrentWeb.Lists;
Guid id = lists.Add(title, description, SPListTemplateType.GenericList);
return id.ToString();
}
catch(Exception e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new Exception("创建文档库出错!" + e.ToString());
}
}
public string Create(string title,
string description ,
bool enableVersion )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
CurrentSite.AllowUnsafeUpdates = true;
CurrentWeb.AllowUnsafeUpdates = true;
SPListCollection lists = CurrentWeb.Lists;
Guid id = lists.Add(title, description, SPListTemplateType.GenericList);
SPList list = CurrentWeb.Lists[id];
list.EnableVersioning = enableVersion;
list.Update();
return id.ToString();
}
catch(Exception e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new Exception("创建文档库出错!" + e.ToString());
}
}
public void Delete(string guid)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
CurrentSite.AllowUnsafeUpdates = true;
CurrentWeb.AllowUnsafeUpdates = true;
CurrentWeb.Lists.Delete(new Guid(guid));
}
catch(Exception e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new Exception("删除文档库(GUID:" + guid + ")出错!" + e.ToString());
}
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
扩展字段操作#region 扩展字段操作
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///
/// </summary>
/// <param name="objExtendFields"></param>
public void CreateExtendFields(ArrayList objExtendFields,string guid)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
IEnumerator objenum = objExtendFields.GetEnumerator();
while (objenum.MoveNext())
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ExtendFieldsInfo fieldInfo = objenum.Current as ExtendFieldsInfo;
if (fieldInfo != null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
CreateExtendField(fieldInfo.ExtendFieldCode,
fieldInfo.ExtendFieldName,
IPExtendFieldDataType.GetType(fieldInfo.ExtendFieldDataType),
guid );
}
}
}
public void CreateView(string guid)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
CurrentSite.AllowUnsafeUpdates = true;
CurrentWeb.AllowUnsafeUpdates = true;
SPListCollection lists = CurrentWeb.Lists;
SPList list = lists[new Guid(guid)];
SPViewCollection views = list.Views;
StringCollection viewFields = new StringCollection();
string viewName = defaultViewName;
viewFields.Add("ID");
viewFields.Add("Author");
viewFields.Add("Created");
viewFields.Add("Modified");
viewFields.Add("Title");
string query = "";
views.Add(viewName, viewFields, query, 300, true, true);
}
#endregion
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
获取数据列表操作#region 获取数据列表操作
![](/Images/OutliningIndicators/InBlock.gif)
public DataView GetListItem()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DataView dv = ObjSPList.GetItems(ObjSPList.DefaultView).GetDataTable().DefaultView;
dv.Sort = "Created Desc";
return dv;
}
public DataView GetListItem(IFilter filter)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DataView dv = ObjSPList.GetItems(filter.ToQuery()).GetDataTable().DefaultView;
dv.Sort = "Created Desc";
return dv;
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 按条件直接从SPS数据库UserData表中查找数据
/// </summary>
/// <param name="filter"></param>
/// <param name="dbSPS"></param>
/// <returns></returns>
public DataSet GetListItem(IFilterDB dbFilter,DataBase dbSPS)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return dbSPS.RunProc(dbFilter.ToQuerySqlString(),new DataSet());
}
catch(Exception e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new Exception("构造SQL语句出错:" + dbFilter.ToQuerySqlString() + "错误源:" + e.ToString());
}
}
#endregion
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
统计信息#region 统计信息
public int GetTotal(IFilterDB dbFilter,DataBase dbSPS)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return int.Parse(dbSPS.ReturnValue(dbFilter.ToCountSqlString()));
}
catch(Exception e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new Exception("构造SQL语句出错:" + dbFilter.ToQuerySqlString() + "错误源:" + e.ToString());
}
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
}
}
![](/Images/OutliningIndicators/None.gif)
类IPListAttach
namespace SPSInformationPublish
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 操作信息发布附件的类
/// </summary>
public class IPListAttach
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private SPSite m_CurrentSite;
private SPWeb m_CurrentWeb;
private string m_Guid;
private string m_SiteUrl;
private SPDocumentLibrary m_DL;
private string defaultViewName = "DocManageDefaultView";
private DocumentLibrary m_ProxyDL;
public DocumentLibrary ProxyDL
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (m_ProxyDL != null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return m_ProxyDL;
}
return new DocumentLibrary(this.m_SiteUrl,this.m_Guid,true);
}
}
public IPListAttach(string guid,string siteUrl)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_Guid = guid;
m_SiteUrl = siteUrl;
m_CurrentSite = GetSPSite();
m_CurrentWeb = m_CurrentSite.OpenWeb();
m_DL = (SPDocumentLibrary)GetSPListByGUID(guid);
}
public SPList GetSPListByGUID(string guid)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return m_CurrentWeb.Lists.GetList(new Guid(guid),true);
}
catch
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return null;
}
}
public SPSite GetSPSite()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return new SPSite(m_SiteUrl);
}
public void Create(string title,string description ,ArrayList objExtendFields)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string id = Create(title,description);
CreateView(id);
CreateExtendFields(objExtendFields,id);
}
public void CreateExtendFields(ArrayList objExtendFields,string guid)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
IEnumerator objenum = objExtendFields.GetEnumerator();
while (objenum.MoveNext())
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ExtendFieldsInfo fieldInfo = objenum.Current as ExtendFieldsInfo;
if (fieldInfo != null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
CreateExtendField(fieldInfo.ExtendFieldCode,
fieldInfo.ExtendFieldName,
IPExtendFieldDataType.GetType(fieldInfo.ExtendFieldDataType),
guid );
}
}
}
private void CreateExtendField(string fieldName,string fieldTitle, SPFieldType type,string guid)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.m_CurrentSite.AllowUnsafeUpdates = true;
this.m_CurrentWeb.AllowUnsafeUpdates = true;
SPFieldCollection fields = m_CurrentWeb.Lists[new Guid(guid)].Fields;
fields.Add(fieldName,type,false);
SPField fld=fields.GetField(fieldName);
fld.Title=fieldTitle;
fld.Update();
//将字段加入到视图中
SPList list = m_CurrentWeb.Lists[new Guid(guid)];
SPView view = list.DefaultView;
SPViewFieldCollection viewFields = view.ViewFields;
viewFields.Add(fieldName);
view.Update();
}
public void CreateView(string guid)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.m_CurrentSite.AllowUnsafeUpdates = true;
this.m_CurrentWeb.AllowUnsafeUpdates = true;
SPListCollection lists = m_CurrentWeb.Lists;
SPList list = lists[new Guid(guid)];
SPViewCollection views = list.Views;
StringCollection viewFields = new StringCollection();
![](/Images/OutliningIndicators/InBlock.gif)
string viewName = defaultViewName;
viewFields.Add("DocIcon");
viewFields.Add("LinkFilename");
viewFields.Add("Last_x0020_Modified");
viewFields.Add("Editor");
viewFields.Add("ID");
viewFields.Add("Author");
viewFields.Add("Created_x0020_Date");
viewFields.Add("FileLeafRef");
viewFields.Add("LinkFilenameNoMenu");
viewFields.Add("FileSizeDisplay");
viewFields.Add("Title");
string query = "";
views.Add(viewName, viewFields, query, 300, true, true);
}
public string Create(string title,
string description
)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_CurrentSite.AllowUnsafeUpdates = true;
m_CurrentWeb.AllowUnsafeUpdates = true;
SPListCollection lists = m_CurrentWeb.Lists;
Guid id = lists.Add(title, description, SPListTemplateType.DocumentLibrary);
return id.ToString();
}
catch(Exception e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new Exception("创建文档库出错!" + e.ToString());
}
}
public string CreateDocumentLibrary(string SiteURL,
string docTitle,
string docDescription,
bool VersionControl)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return null;
}
public void Delete(int id)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.ProxyDL.DeleteFolder(id.ToString());
}
public void CreateFolder(int id)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
public bool HasAttach(int id)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(ProxyDL.GetFolder(id.ToString()).Files.Count > 0)
return true;
else
return false;
}
catch
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return false;
}
}
public void AddAttach(int id)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
public void Delete(string guid)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.m_CurrentSite.AllowUnsafeUpdates = true;
this.m_CurrentWeb.AllowUnsafeUpdates = true;
this.m_CurrentWeb.Lists.Delete(new Guid(guid));
}
catch(Exception e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new Exception("删除文档库(GUID:" + guid + ")出错!" + e.ToString());
}
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 把附件添加到SPS文档库中
/// </summary>
public int AddToDocLib(int id,byte[] fileConent,string fileName,Hashtable inputFields)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//CreateFolder(dl,dl.docLibrary.Title,taskID.ToString());
ProxyDL.web.AllowUnsafeUpdates = true;
SPFileCollection files = ProxyDL.GetFolder(ProxyDL.docLibrary.Title + "/" + id.ToString()).Files;
SPFile myFile = files.Add(ProxyDL.SiteURL + "/" + ProxyDL.docLibrary.Title +
"/" + id.ToString() + "/" + fileName ,fileConent,true);
UpdateItem(myFile.Item.ID,inputFields);
return myFile.Item.ID;
}
catch(Exception e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw e;
}
}
public void DeleteFromDocLibByItemID(int itemID)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ProxyDL.web.AllowUnsafeUpdates = true;
ProxyDL.DocLibrary.Items.DeleteItemById(itemID);
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 更新扩展字段
/// </summary>
/// <param name="itemID"></param>
/// <param name="inputFields"></param>
private void UpdateItem(int itemID,Hashtable inputFields)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SPListItem item = ProxyDL.DocLibrary.Items.GetItemById(itemID);
![](/Images/OutliningIndicators/InBlock.gif)
IDictionaryEnumerator myEnumerator = inputFields.GetEnumerator();
while (myEnumerator.MoveNext())
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
item[myEnumerator.Key.ToString()] = myEnumerator.Value.ToString();
}
item.Update();
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 得到一个列表条目下的附件列表
/// </summary>
/// <param name="id">列表ID</param>
/// <returns></returns>
public DataView GetDataViewFromFolder(int id)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//创建记录集对象
DataSet Ds = ProxyDL.GetItem(ProxyDL.DocLibrary.Title + "/" + id.ToString());
DataView DV = new DataView() ;
if(Ds.Tables.Count > 0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//过滤掉目录
DV = new DataView(Ds.Tables[0],"DocIcon <> ''","",DataViewRowState.CurrentRows);
DV.Sort = "Last_x0020_Modified Desc";
}
return DV;
}
catch(Exception Err)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw Err;
return null;
}
}
}
}
![](/Images/OutliningIndicators/None.gif)
IListItem
namespace SPSInformationPublish
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 操作信息发布item类
/// </summary>
public class IPListItem
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private IPList m_IPList;
private IPListAttach m_IPListAttach;
public IPList List
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return this.m_IPList;
}
}
public IPListAttach ListAttach
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return this.m_IPListAttach;
}
}
public IPListItem(IPList objList,IPListAttach objAttach)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_IPList = objList;
m_IPListAttach = objAttach;
}
public void TransferHasAttachStatus(int id ,string hasAttachFieldName )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (ListAttach.HasAttach(id))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SetHasAttach(id,hasAttachFieldName);
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SetNoneAttach(id,hasAttachFieldName);
}
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 添加一条记录
/// </summary>
/// <param name="inputFields"></param>
/// <returns></returns>
public int Add(Hashtable inputFields)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SPListItem item = List.ObjSPList.Items.Add();
IDictionaryEnumerator myEnumerator = inputFields.GetEnumerator();
while (myEnumerator.MoveNext())
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
item[myEnumerator.Key.ToString()] = myEnumerator.Value.ToString();
}
item.Update();
ProxyCreateFolder(item.ID);
ProxyAddAttach(item.ID);
return item.ID;
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 修改一条记录
/// </summary>
/// <param name="id"></param>
/// <param name="inputFields"></param>
public void Update(int id,Hashtable inputFields)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SPListItem item = List.ObjSPList.Items.GetItemById(id);
IDictionaryEnumerator myEnumerator = inputFields.GetEnumerator();
while (myEnumerator.MoveNext())
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
item[myEnumerator.Key.ToString()] = myEnumerator.Value.ToString();
}
item.Update();
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 删除一个记录
/// </summary>
/// <param name="id"></param>
public void Delete(int id)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
List.ObjSPList.Items.DeleteItemById(id);
//删除附件
ListAttach.Delete(id);
}
private void ProxyCreateFolder(int id)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ListAttach.CreateFolder(id);
}
private void ProxyAddAttach(int id)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ListAttach.AddAttach(id);
}
private void SetHasAttach(int id,string hasAttachFieldName)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Hashtable ht = new Hashtable();
ht.Add(hasAttachFieldName,true);
Update(id,ht);
}
private void SetNoneAttach(int id,string hasAttachFieldName)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Hashtable ht = new Hashtable();
ht.Add(hasAttachFieldName,false);
Update(id,ht);
}
}
}
![](/Images/OutliningIndicators/None.gif)
IPFacadeFactory
namespace SPSInformationPublish
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 外部调用程序通过本类统一访问此类库功能
/// </summary>
public class IPFacadeFactory
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private IPFacadeFactory()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//
// TODO: 在此处添加构造函数逻辑
//
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 返回listitem对象
/// </summary>
/// <param name="listGuid">列表对象的GUID</param>
/// <param name="attachGuid">附件文档库的GUID</param>
/// <param name="siteUrl">站点的Url</param>
/// <returns></returns>
public static IPListItem Create(string listGuid,
string attachGuid,
string siteUrl
)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return new IPListItem(CreateIPList(listGuid,siteUrl),
CreateAttachList(attachGuid,siteUrl));
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 返回IPList对象
/// </summary>
/// <param name="guid"></param>
/// <param name="siteUrl"></param>
/// <returns></returns>
public static IPList CreateIPList(string guid,string siteUrl)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return new IPList(guid,siteUrl);
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 返回IPList对象(没有实力化列表对象,Add时候使用)
/// </summary>
/// <param name="siteUrl"></param>
/// <returns></returns>
public static IPList CreateIPList(string siteUrl)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return CreateIPList("",siteUrl);
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 返回AttachList对象
/// </summary>
/// <param name="guid"></param>
/// <param name="siteUrl"></param>
/// <returns></returns>
public static IPListAttach CreateAttachList(string guid,string siteUrl)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return new IPListAttach(guid,siteUrl);
}
}
}
![](/Images/OutliningIndicators/None.gif)
直接从sps数据库中检索数据
using System;
using System.Data;
using System.Collections;
using System.Text;
using UltraPower.SPS.DB;
![](/Images/OutliningIndicators/None.gif)
namespace SPSInformationPublish
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// FilterDB 的摘要说明。
/// </summary>
public class FilterDB : IFilterDB
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private string m_ListGuid;
private string m_ConnStr;
private SpsExpendFields m_SpsExpendFields;
private ArrayList m_SelectFields;
private ArrayList m_WhereFields;
private string m_Where;
private ArrayList m_OrderByFields;
public SpsExpendFields ExpendFields
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (m_SpsExpendFields != null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return m_SpsExpendFields;
}
return new SpsExpendFields(m_ConnStr,m_ListGuid);
}
}
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
构造器#region 构造器
public FilterDB(string guid,
ArrayList select,
ArrayList whereFields,
string where,
ArrayList orderBy,
string connStr)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_ListGuid = guid;
m_ConnStr = connStr;
m_SelectFields = select;
m_WhereFields = whereFields;
this.m_Where = where;
m_OrderByFields = orderBy;
}
public FilterDB(string guid,
ArrayList select,
ArrayList whereFields,
string where,
string connStr)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_ListGuid = guid;
m_ConnStr = connStr;
m_SelectFields = select;
m_WhereFields = whereFields;
this.m_Where = where;
}
public FilterDB(string guid,
ArrayList whereFields,
string where,
string connStr)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_ListGuid = guid;
m_ConnStr = connStr;
m_WhereFields = whereFields;
this.m_Where = where;
}
public FilterDB(string guid,string connStr)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_ListGuid = guid;
m_ConnStr = connStr;
}
#endregion
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
私有方法#region 私有方法
![](/Images/OutliningIndicators/InBlock.gif)
private string GetOrderBy()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
StringBuilder sb = new StringBuilder();
if (this.m_OrderByFields == null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return "";
}
if (this.m_OrderByFields.Count == 0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return "";
}
if (this.m_OrderByFields.Count == 1)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return this.GetDBField(this.m_OrderByFields[0].ToString());
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(int i=0;i<this.m_OrderByFields.Count;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i == 0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sb.Append(" " + GetDBField(this.m_OrderByFields[i].ToString()));
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sb.Append("," + GetDBField(this.m_OrderByFields[i].ToString()));
}
}
return " Order By " + sb.ToString();
}
}
private string GetSelect()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
StringBuilder sb = new StringBuilder();
sb.Append(" Select '0',");
for(int i = 0;i< m_SelectFields.Count;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sb.Append(" " + this.GetDBField(m_SelectFields[i].ToString()) +
" As " + m_SelectFields[i].ToString() + ",");
}
sb.Append(" '1' ");
sb.Append(" From UserData ");
![](/Images/OutliningIndicators/InBlock.gif)
return sb.ToString();
}
private string GetWhere()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (this.m_Where.Trim()=="")
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return "Where tp_ListID = '" + m_ListGuid + "'" ;
}
StringBuilder sb = new StringBuilder();
for(int i=0;i<this.m_WhereFields.Count;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_Where = m_Where.Replace(this.m_WhereFields[i].ToString(),this.GetDBField(m_WhereFields[i].ToString()));
}
sb.Append(" Where (" + this.m_Where + ") ");
sb.Append(" And tp_ListID = '" + m_ListGuid + "'");
return sb.ToString();
}
private bool IsDBField(string field)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return true;
}
private bool IsSPSExpendField(string field)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return true;
}
private string GetDBField(string spsExpendField)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return ExpendFields.GetDBFieldName(spsExpendField);
}
#endregion
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
IFilterDB 成员#region IFilterDB 成员
![](/Images/OutliningIndicators/InBlock.gif)
public string ToQuerySqlString()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// TODO: 添加 FilterDB.ToQuerySqlString 实现
return GetSelect() + " " + GetWhere() + " " + GetOrderBy();
}
public string ToCountSqlString()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return "Select Count(*) as total From UserData " + " " + GetWhere() + " " ;
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
}
}
![](/Images/OutliningIndicators/None.gif)
类图: