Custom sorting and display of custom data set objects

xiaoxiao2021-03-06  37

Part of code: Data entity object: using system; using vuser.ecommerce.dataproxy;

Namespace vuser.ecommerce.core {

[Serializable] public class BaseObject: IComparable {#region domain member private int m_ID; private string m_Title; private string m_Remark; private IDataProxy m_DataProxy; private bool m_IsModify = false; private bool m_IsDirty = false; private string m_SortFieldName;

#ndregion

#REGION attribute public virtual int id {set {m_id = value;} Get {return m_id;}} ///

/// Name /// public virtual string title {set {m_title = value; } Get {return m_title;}} /// /// Note /// public string remark {set {m_remark = value;} get {return m_remark;}} public virtual string sortfieldname {get {Get { IF (m_sortfieldname == null) {m_sortfieldname = "id";} return m_sortfieldname;} set {m_sortfieldname = value;}}

///

/// database proxy object (operation on the database) /// public virtual iDataProxy DataProxy {get {returnim_dataProxy;} set {this.m_dataproxy = value;}} public bool ISMODIFY {get {returnim {this.m_ismodify;} set {get}}}} set {this.m_isdirty = value;}} #endregion;}} #ENDREGION

#REGION constructor

///

/// Structure /// public baseObject () {// // Todo: Add constructor logic //} /// /// belt data Agent object constructor /// ///

#ndregion

#Region Reserved Method ///

/// Compare two objects are equal /// /// /// Public Overide Bool Equals (Object Obj) {IF (Obj == Null || gettype ()! = obj.gettype ()) {Return False;} Return ID.Equals ((BaseObject) Obj) .id); } Public override int getHashcode () {returnid.gethashcode ();

#ndregion

#Region operator

Public Static Bool Operator == (BaseObject X, BaseObject Y) {Return X.ID == Y.Id;} public static bool operator! = (BaseObject X, baseObject Y) {return! (x == y);} # EndRegion public override string toString () {return this.title;}}} Data entity object NEWS Using system; use system.data; using vuser.ecommerce.dataProxy;

Namespace vuser.ecommerce.core {///

/// news Abstract Description.

/// public class News: BaseObject {private DateTime m_AddTime = DateTime.Now; private int m_ClassID; private string m_ClassName; private NewClass m_NewClassObj; private bool m_IsPublish; public DateTime AddTime {get {return m_AddTime;} set {m_AddTime = Value;}} public int classid {get {return m_classid;} set {// if (! new newscollection (). ISEXIST (Value)) // {// throw new exception ("The classid isn't exist") ; //} m_ClassID = value;}} public string ClassName {get {return this.m_ClassName;} set {this.m_ClassName = value;}} public NewClass NewClassObj {get {if (m_NewClassObj == null) {if (this. ! m_ClassID = 0) {m_NewClassObj = (NewClass) (new NewClass () Load (ClassID));.}} return m_NewClassObj;}} public bool IsPublish {get {return m_IsPublish;} set {m_IsPublish = value;}} public News () {// // Todo: Add a structure here Public override int compareto (object obj) {if (this.SortfieldName.toupper (). Equals ("addtime")) {return addtime.compareto ((news) obj) .addtime);} (this.SortfieldName.toupper (). Equals ("classid")) {Return classid.compareto ((news) obj) .classid;} if (this.sortfieldname.toupper (). Equals ("classname")) {RETURN ClassName.Compareto ((NEWS) OBJ) .ClassName);} if (this.SortfieldName.toupper (). Equals ("ispublish")) {Return ISPublish.comPareto ((news) obj) .Ispublish; } Return Base.compareto (OBJ);}}} Data Collection Object Using System; Using System.collections; Using System.Data; Using Vuser.ECommerce.DataProxy;

Namespace vuser.ecommerce.core {[serializable] public class basecollection: ienumerator, iCollection {#Region domain

#REGON data synchronization identification bit

///

/// Items data changed, yet not submitted to Database /// private bool m_ismodify = false; /// // 是 是 Database Already changed, Items data has been "dirty" /// private bool m_isdioty = false;

#ndregion

///

/// Browse data Cursor pointer /// private int m_index = -1; /// /// Operating database agent ////// private IdataProxy M_DataProxy; /// /// Store data object /// private arraylist m_items;

#ndregion

#REGON attribute ///

/// set sort field name /// public string setsortfieldname {set {for (int i = 0; i /// Items (memory) data has been changed, yet not submitted to Database /// public bool ismodify {get {return m_ismodify } Set {m_ismodify = value;}} /// /// The data in the database has changed, Items (memory) data has been "dirty" /// public bool isdirty {set { M_Indirty = value;} get {return m_isdirty;}} /// /// Record collection /// public arraylist items {get {f (this.m_items == null) {m_items = new ArrayList ();} Return this.m_items;}} /// /// public int count {get {return items.count;}} /// /// Operating database agent //// public virtual iDataProxy DataProxy {Get {Return M_DataProxy;} set {m_dataproxy = value;}} /// /// Indexer /// public baseObject this [int index] {get {if (items! = null) {= ((index> = 0) || (Index = 0) || INDEX

Public Basecollection () {} private basecollection (arraylist items) {m_items = items;

# endregion # region Use the Database Agent Object (DataProxy)

#Region loading data from the database

Public Virtual Basecollection Load () {Return DataProxy.Load ();

#ndregion

Public void deletebyid (int id) {dataproxy.deletebyid (id);

public virtual int Add (BaseObject objData) {return DataProxy.Add (objData);} public virtual bool IsExist (int id) {return this.DataProxy.IsExist (id);} public virtual BaseCollection GetItems () {return this.DataProxy. PUBLIC Virtual DataSet Todataset () {return this.dataProxy.todataset ();

#ndregion

#Region Icollection member

Public Bool Issynchronized {Get {// Todo: Add eocollection.issynchronized getter Implement Return False;}}

Public void CopyTo (Array Array, Int Index) {// Todo: Add Eocollection.copy Tool}

Public Object syncroot {get {// Todo: Add eocollection.syncroot getter Implement Return null;}}

#ndregion

#Region Ienumerable member

public virtual IEnumerator GetEnumerator () {// TODO: Add EOCollection.GetEnumerator implemented // return (IEnumerator) new EOCollection (this.Items); return this.Items.GetEnumerator ();} public object Current {get {return Items [m_Index ];}} Public Bool MoveNext () {m_index ; return m_index

#Region Memory Data Operation ///

// / Add Items Collection Data (to memory, temporarily not commit to database) /// /// Public void addtomemo (baseObject obj) {items.add (obj);} /// /// Remove a line record in Items collection /// /// Delete public void deleteFromMemo (BaseObject obj) {items.remove (obj);} /// /// Delete a line record in Items collection /// / // Delete public void deleteFromMemo (int id) {baseObject obj = baseObject.new (); obj.id = id; deleteFromMemo (OBJ);} // / // / / /// To sort the field name public virtual void sort (string fieldname) {SORT (String FieldName) { Items.Sort (New BaseSort (FieldName));} public virtual void sort () {items.sort ();} public virtual void sort (bool isdesc) {items.sort (); if (isdesc) {items.reverse );}} /// /// Sort by the field specified by Items collection /// /// The field name to be sorted ////// Whether to order public virtual void sort (string fieldname, bool isdesc) {sort (limited "; if (isdesc) {items.reverse ();}} #endregion #Region retrieve memory Object

public int IndexOf (object obj) {return Items.IndexOf (obj);} #endregion #region memory database interaction public virtual void Refresh () {} public virtual void Submit () {if (IsModify) {foreach (BaseObject obj in THISTEMS) {if (obj.ismodify) {this.dataProxy.Update (obj);}}}} #endregion}}} #endregion}}}}}}}}}}}}}}}}}}}}}}} Core {///

/// BaseSort's summary description. /// public class BaseSort: IComparer {private string m_SortFieldName; public BaseSort (string fieldName) {m_SortFieldName = fieldName;} public virtual int CompareField (object x, object y) {try {Type typex = x.GetType ( ); Type typey = y.GetType (); // Get each property by name PropertyInfo pix = typex.GetProperty (m_SortFieldName); PropertyInfo piy = typey.GetProperty (m_SortFieldName); // Get the value of the property for each object IComparable PVALX = (iComparable) Pix.getValue (x, null); object pvaly = piy.getValue (y, null); // compare value, using iComparable interface of the property's type return pvalx.compareto (pvaly);} catch // IF x or y is null value dam}} #REGION ICOMPARER member

Public Virtual Int Compare (Object X, Object Y) {// Todo: Add BaseSort.Compare Realization Return Comparefield (x, y);

转载请注明原文地址:https://www.9cbs.com/read-66064.html

New Post(0)