2007-11-20 20:12:45 +00:00

109 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using Csla;
using Csla.Data;
using System.Xml;
using System.Data.SqlClient;
using System.Data;
namespace VEPROMS.CSLA.Library
{
public partial class Content
{
public override string ToString()
{
return string.Format("{0} {1}", Number, Text);
}
}
public partial class ContentInfo
{
public override string ToString()
{
return string.Format("{0} {1}", Number, Text);
}
//public XmlNode ToXml(XmlNode xn)
//{
// XmlNode nd = xn.OwnerDocument.CreateElement("Content");
// xn.AppendChild(nd);
// AddAttribute(nd, "Number", _Number);
// AddAttribute(nd, "Text", _Text);
// AddAttribute(nd, "FormatID", _FormatID);
// AddAttribute(nd, "Config", _Config);
// return nd;
//}
//public void AddAttribute(XmlNode xn, string name, object o)
//{
// if (o != null && o.ToString() != "")
// {
// XmlAttribute xa = xn.OwnerDocument.CreateAttribute(name);
// xa.Value = o.ToString();
// xn.Attributes.Append(xa);
// }
//}
}
public partial class ContentInfoList
{
public static ContentInfoList GetList(int? itemID)
{
try
{
ContentInfoList tmp = DataPortal.Fetch<ContentInfoList>(new ContentListCriteria(itemID));
ContentInfo.AddList(tmp);
tmp.AddEvents();
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
}
}
[Serializable()]
private class ContentListCriteria
{
public ContentListCriteria(int? itemID)
{
_ItemID = itemID;
}
private int? _ItemID;
public int? ItemID
{
get { return _ItemID; }
set { _ItemID = value; }
}
}
private void DataPortal_Fetch(ContentListCriteria criteria)
{
this.RaiseListChangedEvents = false;
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "vesp_ListContentsByItemID";
cm.Parameters.AddWithValue("@ItemID", criteria.ItemID);
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read())
{
ContentInfo contentInfo = new ContentInfo(dr);
this.Add(contentInfo);
}
IsReadOnly = true;
}
}
}
}
catch (Exception ex)
{
Database.LogException("ContentInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("ContentInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
}
}
}