利用WSS做后台存储--设计一个统一的信息发布平台

方案设计:
功能包括:信息发布,保存,浏览,修改,查询
问题提出:信息发布内容和格式不能确定,应该允许客户定制信息(名称、类型、显示方式和布局)
每条目信息可以包含一个或多个附件。可以全文检索信息。
采用WSS做后台信息存储,针对于用户定义的信息内容包含数据字典为用户建立一个WSS中的“列表”和一个“文档库”,每条发布的信息存储在“列表”的一个item中,根据列表中每个Item的ID在文档库中建立一个以ID为名称的folder,在folder下存储该item的附件。
利用SPS的search webseivce进行检索

附部分类库源代码:
IPList类

namespace SPSInformationPublish
{
    
/// <summary>
    
///操作信息发布"列表"的类
    
/// </summary>

    public class IPList
    
{
        

        
属性
        
构造器
        
私有方法 
        
公共方法 
    }

}


类IPListAttach
namespace SPSInformationPublish
{
    
/// <summary>
    
/// 操作信息发布附件的类
    
/// </summary>

    public class IPListAttach
    
{
        
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
        
{
            
get
            
{
                
if (m_ProxyDL != null)
                
{
                    
return m_ProxyDL;
                }

                
return new DocumentLibrary(this.m_SiteUrl,this.m_Guid,true);
            }

        }

        
public IPListAttach(string guid,string siteUrl)
        
{
            m_Guid 
= guid;
            m_SiteUrl 
= siteUrl;
            m_CurrentSite 
= GetSPSite();
            m_CurrentWeb 
= m_CurrentSite.OpenWeb();
            m_DL 
= (SPDocumentLibrary)GetSPListByGUID(guid);
        }

        
public SPList GetSPListByGUID(string guid)
        
{
            
try
            
{
                
return m_CurrentWeb.Lists.GetList(new Guid(guid),true);
            }

            
catch
            
{
                
return null;
            }

        }

        
public SPSite GetSPSite()
        
{
            
return new SPSite(m_SiteUrl);
        }

        
public void Create(string title,string description ,ArrayList objExtendFields)
        
{
            
string id = Create(title,description);
            CreateView(id);
            CreateExtendFields(objExtendFields,id);
        }

        
public void CreateExtendFields(ArrayList objExtendFields,string guid)
        
{
            IEnumerator objenum 
= objExtendFields.GetEnumerator();
            
while (objenum.MoveNext())
            
{
                ExtendFieldsInfo fieldInfo 
= objenum.Current as ExtendFieldsInfo;
                
if (fieldInfo != null)
                
{
                    CreateExtendField(fieldInfo.ExtendFieldCode,
                        fieldInfo.ExtendFieldName,
                        IPExtendFieldDataType.GetType(fieldInfo.ExtendFieldDataType),
                        guid );
                }

            }

        }

        
private void CreateExtendField(string fieldName,string fieldTitle, SPFieldType type,string guid)
        
{
            
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)
        
{
            
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();

            
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, 
300truetrue);
        }

        
public string Create(string title,
            
string description
            )
        
{
            
try
            
{
                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)
            
{
                
throw new Exception("创建文档库出错!" + e.ToString());
            }

        }

        
public string CreateDocumentLibrary(string SiteURL,
            
string docTitle,
            
string docDescription,
            
bool VersionControl)
        
{
            
return null;
        }

        
public void Delete(int id)
        
{
            
this.ProxyDL.DeleteFolder(id.ToString());
        }

        
public void CreateFolder(int id)
        
{
        }

        
public bool HasAttach(int id)
        
{
            
try
            
{
                
if(ProxyDL.GetFolder(id.ToString()).Files.Count > 0)
                    
return true;
                
else
                    
return false;
            }

            
catch
            
{
                
return false;
            }

        }

        
public void AddAttach(int id)
        
{
        }

        
public void Delete(string guid)
        
{
            
try
            
{
                
this.m_CurrentSite.AllowUnsafeUpdates = true;
                
this.m_CurrentWeb.AllowUnsafeUpdates = true;
                
this.m_CurrentWeb.Lists.Delete(new Guid(guid));
            }

            
catch(Exception e)
            
{
                
throw new Exception("删除文档库(GUID:" + guid + ")出错!" + e.ToString());
            }

        }

        
/// <summary>
        
/// 把附件添加到SPS文档库中
        
/// </summary>

        public int  AddToDocLib(int id,byte[] fileConent,string fileName,Hashtable inputFields)
        
{
            
try
            
{
                
//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)
            
{
                
throw e;
            }

        }

        
public void DeleteFromDocLibByItemID(int itemID)
        
{
            ProxyDL.web.AllowUnsafeUpdates 
= true;
            ProxyDL.DocLibrary.Items.DeleteItemById(itemID);
            
        }

        
/// <summary>
        
/// 更新扩展字段
        
/// </summary>
        
/// <param name="itemID"></param>
        
/// <param name="inputFields"></param>

        private void UpdateItem(int itemID,Hashtable inputFields)
        
{
            SPListItem item 
= ProxyDL.DocLibrary.Items.GetItemById(itemID);

            IDictionaryEnumerator myEnumerator 
= inputFields.GetEnumerator();
            
while (myEnumerator.MoveNext())
            
{
                item[myEnumerator.Key.ToString()] 
= myEnumerator.Value.ToString();
            }

            item.Update();
        }

        
/// <summary>
        
/// 得到一个列表条目下的附件列表
        
/// </summary>
        
/// <param name="id">列表ID</param>
        
/// <returns></returns>

        public DataView GetDataViewFromFolder(int id)
        
{
            
try
            
{
                
//创建记录集对象
                DataSet Ds = ProxyDL.GetItem(ProxyDL.DocLibrary.Title + "/" + id.ToString());
                DataView DV 
= new DataView() ;
                
if(Ds.Tables.Count > 0)
                
{
                    
//过滤掉目录
                    DV = new DataView(Ds.Tables[0],"DocIcon <> ''","",DataViewRowState.CurrentRows);
                    DV.Sort 
= "Last_x0020_Modified Desc";
                }

                
return DV;
            }

            
catch(Exception Err)
            
{
                
throw Err;
                
return null;
            }

        }

    }

}


IListItem

namespace SPSInformationPublish
{
    
/// <summary>
    
/// 操作信息发布item类
    
/// </summary>

    public class IPListItem
    
{
        
private IPList m_IPList;
        
private IPListAttach m_IPListAttach;
        
public IPList List
        
{
            
get
            
{
                
return this.m_IPList;
            }

        }

        
public IPListAttach ListAttach
        
{
            
get
            
{
                
return this.m_IPListAttach;
            }

        }

        
public IPListItem(IPList objList,IPListAttach objAttach)
        
{
            m_IPList 
= objList;
            m_IPListAttach 
= objAttach;
        }

        
public void TransferHasAttachStatus(int id ,string hasAttachFieldName )
        
{
            
if (ListAttach.HasAttach(id))
            
{
                SetHasAttach(id,hasAttachFieldName);
            }

            
else
            
{
                SetNoneAttach(id,hasAttachFieldName);
            }

        }

        
/// <summary>
        
/// 添加一条记录
        
/// </summary>
        
/// <param name="inputFields"></param>
        
/// <returns></returns>

        public int Add(Hashtable inputFields)
        
{
            SPListItem item 
= List.ObjSPList.Items.Add();
            IDictionaryEnumerator myEnumerator 
= inputFields.GetEnumerator();
            
while (myEnumerator.MoveNext())
            
{
                item[myEnumerator.Key.ToString()] 
= myEnumerator.Value.ToString();
            }

            item.Update();
            ProxyCreateFolder(item.ID);
            ProxyAddAttach(item.ID);
            
return item.ID;
        }

        
/// <summary>
        
/// 修改一条记录
        
/// </summary>
        
/// <param name="id"></param>
        
/// <param name="inputFields"></param>

        public void Update(int id,Hashtable inputFields)
        
{
            SPListItem item 
= List.ObjSPList.Items.GetItemById(id);
            IDictionaryEnumerator myEnumerator 
= inputFields.GetEnumerator();
            
while (myEnumerator.MoveNext())
            
{
                item[myEnumerator.Key.ToString()] 
= myEnumerator.Value.ToString();
            }

            item.Update();
        }

        
/// <summary>
        
/// 删除一个记录
        
/// </summary>
        
/// <param name="id"></param>

        public void Delete(int id)
        
{
            List.ObjSPList.Items.DeleteItemById(id);
            
//删除附件
            ListAttach.Delete(id);
        }

        
private void ProxyCreateFolder(int id)
        
{
            ListAttach.CreateFolder(id);
        }

        
private void ProxyAddAttach(int id)
        
{
            ListAttach.AddAttach(id);
        }

        
private void SetHasAttach(int id,string hasAttachFieldName)
        
{
            Hashtable ht 
= new Hashtable();
            ht.Add(hasAttachFieldName,
true);
            Update(id,ht);
        }

        
private void SetNoneAttach(int id,string hasAttachFieldName)
        
{
            Hashtable ht 
= new Hashtable();
            ht.Add(hasAttachFieldName,
false);
            Update(id,ht);
        }

    }

}


IPFacadeFactory
namespace SPSInformationPublish
{
    
/// <summary>
    
/// 外部调用程序通过本类统一访问此类库功能
    
/// </summary>

    public class IPFacadeFactory
    
{
        
private IPFacadeFactory()
        
{
            
//
            
// TODO: 在此处添加构造函数逻辑
            
//
        }

        
/// <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
            )
        
{
            
return new IPListItem(CreateIPList(listGuid,siteUrl),
                CreateAttachList(attachGuid,siteUrl));
        }

        
/// <summary>
        
/// 返回IPList对象
        
/// </summary>
        
/// <param name="guid"></param>
        
/// <param name="siteUrl"></param>
        
/// <returns></returns>

        public static IPList CreateIPList(string guid,string siteUrl)
        
{
            
return new IPList(guid,siteUrl);
        }

        
/// <summary>
        
/// 返回IPList对象(没有实力化列表对象,Add时候使用)
        
/// </summary>
        
/// <param name="siteUrl"></param>
        
/// <returns></returns>

        public static IPList CreateIPList(string siteUrl)
        
{
            
return CreateIPList("",siteUrl);
        }

        
/// <summary>
        
/// 返回AttachList对象
        
/// </summary>
        
/// <param name="guid"></param>
        
/// <param name="siteUrl"></param>
        
/// <returns></returns>

        public static IPListAttach CreateAttachList(string guid,string siteUrl)
        
{
            
return new IPListAttach(guid,siteUrl);
        }

    }

}


直接从sps数据库中检索数据
using System;
using System.Data;
using System.Collections;
using System.Text;
using UltraPower.SPS.DB;

namespace SPSInformationPublish
{
    
/// <summary>
    
/// FilterDB 的摘要说明。
    
/// </summary>

    public class FilterDB : IFilterDB
    
{
        
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
        
{
            
get
            
{
                
if (m_SpsExpendFields != null)
                
{
                    
return m_SpsExpendFields;
                }

                
return new SpsExpendFields(m_ConnStr,m_ListGuid);
            }

        }

        
构造器
        
私有方法
        
IFilterDB 成员
    }

}


类图:
posted @ 2004-08-11 15:13  umlchina  阅读(2481)  评论(4编辑  收藏  举报