Summary object-oriented design

xiaoxiao2021-03-06  39

Start contact. Net people will know. Net is an object-oriented programming, even from ASP to ASP. The NET transformation people will also find that although the code page is still familiar with the HTML page, the post page is also a class inherited in system.web.ui.page. Three methods are implemented in the class: Page_Load (Object Sender, System.EventArgs E) Initialization () Code post page mainly implements the function of the business layer, implementing data validity, business logic, etc. Features. And shouldering the database bridge is your own data entity class, usually we all define a class that only contains an object of an object, as follows: Entity class: DatFaultInfo, which encapsulates related properties.

using System; namespace oilManage {public class DatfaultInfo {public DatfaultInfo () {} public DatfaultInfo (string descrption, string dispose, decimal fault_id, DateTime operatedate, string operateuser, decimal trialinfo_id) {this.Descrption = descrption; this.Dispose = dispose; this.Fault_id = fault_id; this.Operatedate = operatedate; this.Operateuser = operateuser; this.Trialinfo_id = trialinfo_id;} private string mDescrption; public string Descrption {get {return mDescrption;} set {mDescrption = value;}} private string mDispose ; public string Dispose {get {return mDispose;} set {mDispose = value;}} private decimal mFault_id; public decimal fault_id {get {return mFault_id;} set {mFault_id = value;}} private DateTime mOperateda te; public DateTime Operatedate {get {return mOperatedate;} set {mOperatedate = value;}} private string mOperateuser; public string Operateuser {get {return mOperateuser;} set {mOperateuser = value;}} private decimal mTrialinfo_id; public decimal Trialinfo_id { Get {Return mtrialInfo_id;} set {mtrialInfo_id = value;}}}} For custom classes, consider the function to provide a collection, such as: IList, Icollection, IEnumerable access collection, then The collection class for this data class is implemented using ArrayList.

As follows: DatfaultInfoCollectionusing System; using System.Collections; namespace oilManage {public class DatfaultInfoCollection: IList, ICollection, IEnumerable {System.Collections.ArrayList elements; public DatfaultInfoCollection () {elements = new System.Collections.ArrayList ();} public DatfaultInfo this [int index] {get {return (datfaultinfo) this.elements [index];} set {this.efficient [index] = value;}}

INT IList.Indexof (Object Value) {Return (DatfaultInfocollection) .indexof ((DatFaultInfo) value);}

Public int indexof (datfaultinfo value) {return this.ersion.ements.indexof (value);

Public Bool IsReadonly {Get {Return this.efficient.IsreadOle;}}

Object ilist.this [int index] {get {return ((DATFAULTINFOCOLLECTION) THIS [INDEX]; (DATFAULTINFOCOLLECTION) [index] = (datfaultInfo) value;}}

Public Bool isfixedsize {get {returnid;}}

Public Bool Issynchronized {Get {Return True;}}

Public int count {get {return this.efficient.count;}}

Public void copyspace, int index) {this.Elements.copyto (array, index);

Public Object syncroot {get {return this.elements.syncroot;}} public system.collections.ienumerator getenumerator () {return this.ersion.GeteNumerator ();

Public Int Add (DatfaultInfo Value) {Return this.ements.add (value);}

INT IList.Add (Object Value) {Return ((DatfaultInfocollection) .Add ((DatFaultInfo) value);}

Void IList.insert (int index, object value) {((DatfaultInfocollection) .insert (Index, (DatfaultInfo) value);}

Public void insert (int index, datfaultinfo value) {this.ements.insert (Index, Value);

Public void removeat (int index) {this.ersion.removeat (index);}

Void IList.Remove (Object Value) {(DATFAULTINFOCOLLECTION). Remove ((DatFaultInfo) value);}

Public Void Remove (DatfaultInfo Value) {this.Elements.Remove (Value);

Bool ilist.contains (Object value) {Return ((DatfaultInfocollection) this) .Contains ((DatFaultInfo) value);}

Public Bool Contains (Datfaultinfo Value) {Return this.ements.contains (value);}

Public void clear () {this.ements} We use a CRUD method that communicates with the database for a given data.

So we define the data for which access classes: DatfaultDB using System; using System.Data; using System.Data.OracleClient; using Fjeptri.DataAccess.DataHelper; namespace oilManage {public class DatfaultDB {public static bool Create (DatfaultInfo datfaultInfo) {string CREATE = "insert into DATFAULT (DESCRPTION, DISPOSE, fAULT_ID, OPERATEDATE, OPERATEUSER, TRIALINFO_ID) values ​​(: DESCRPTION,: DISPOSE,: fAULT_ID,: OPERATEDATE,: OPERATEUSER,: TRIALINFO_ID)"; OracleParameter [] param = OracleHelper.GetCacheParameter ( Create); if (param == null) {param = new OracleParater [6]; param [0] = New OracleParameter ("Descrption", Oracletype.varchar, 4000); param [1] = New OracleParameter ("Dispose", Oracletype.varchar, 4000; param [2] = new OracleParameter ("fault_id", oracletype.Number; param [3] = New OracleParameter ("Operatedate", ORACletype.datetime); param [4] = new OracleParameter (" Operateuser ", Oracletype.varchar, 20) ; Param [5] = new OracleParameter ( "TRIALINFO_ID", OracleType.Number); OracleHelper.CacheParameter (CREATE, param);} param [0] .Value = datfaultInfo.Descrption == null string.Empty: datfaultInfo.Descrption;? PARAM [1] .Value = DATFAULTINFO.Dispose == NULL? String.empty: Datfaultinfo.dispose; param [2] .value = datfaultinfo.fault_id; param [3] .value = datfaultinfo.operatedate; param [4] .value = DATFAULTINFO.OPERATEUSER == NULL? STRING.EMPTY: DATFAULTINFO.OPERATEUSER; param [5] .value = datfaultinfo.trialInfo_id;

? Return OracleHelper.ExecuteNonQuery (ConfigInfo.GetConnectionString (), CommandType.Text, CREATE, param)> 0 true: false;} public static int Delete (DatfaultPK datfaultPK) {string DELETE = "delete DATFAULT where FAULT_ID =: FAULT_ID"; OracleParameter [] param = OracleHelper.GetCacheParameter (DELETE); if (param == null) {param = new OracleParameter [1]; param [0] = new OracleParameter ( "fAULT_ID", OracleType.Number); OracleHelper.CacheParameter (DELETE, param);} param [0] .Value = datfaultPK.Fault_id; return OracleHelper.ExecuteNonQuery (ConfigInfo.GetConnectionString (), CommandType.Text, DELETE, param);} public static DatfaultInfo Read (datfaultPK datfaultPK) {string READ = "select Descrption, Dispose, Fault_ID, OperateDate, Operateuser, TriaLinfo_id from Datfault Where Fault_ID =: Fault_ID "; OracleParameter [] param = ORACleHELPER.GETCAAPARAME Ter (read); if (param == null) {param = new OracleParameter [1]; param [0] = New OracleParameter ("fault_id", oracletype.Number; OracleHelper.cacheParameter (Read, Param);} param 0] .Value = datfaultPK.Fault_id; using (OracleDataReader dr = OracleHelper.ExecuteReader (ConfigInfo.GetConnectionString (), CommandType.Text, READ, param)) {if (dr.Read () == false) return null; DatfaultInfo obj = new datfaultinfo (); if (! Dr.isdbnull (0)) Obj.descrption =

Dr.getstring (0); if (! Dr.isdbnull (1)) Obj.dispose = Dr.getstring (1); if (! Dr.Isdbnull (2)) Obj.fault_id = Dr.GetDecimal (2); if (! Dr.Indbnull (3)) Obj.operatedate = Dr.GetdateTime (3); if (! Dr.Indbnull (4)) Obj.operateuser = Dr.getstring (4); if (! Dr.Isdbnull (5) ) obj.Trialinfo_id = dr.GetDecimal (5); return obj;}} public static DataTable SelectAllDatfaultInfo () {string SELECTALLDATFAULTINFO = "select DESCRPTION, DISPOSE, fAULT_ID, OPERATEDATE, OPERATEUSER, TRIALINFO_ID from DATFAULT"; return OracleHelper.ExecuteDataTable (ConfigInfo .GetConnectionString (), CommandType.Text, SELECTALLDATFAULTINFO);} public static bool Update (datfaultInfo datfaultInfo) {string UPDATE = "update DATFAULT set DESCRPTION =: DESCRPTION, DISPOSE =: DISPOSE, fAULT_ID =: fAULT_ID, OPE RATEDATE =: OPERATEDATE, OPERATEUSER =: OPERATEUSER, TRIALINFO_ID =: TRIALINFO_ID where FAULT_ID =: FAULT_ID "; OracleParameter [] param = OracleHelper.GetCacheParameter (UPDATE); if (param == null) {param = new OracleParameter [7]; param [0] = New OracleParameter ("Descrption", ORACletype.varchar, 4000); param [1] = New OracleParameter ("Dispose", Oracletype.varchar, 4000); param [2] = New OracleParameter ("fault_id", ORACletype .Number); param [3] = New OracleParameter ("OperateDate", Oracletype.Datetime); param [4] =

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

New Post(0)