Use SQL artisan to Write Business Code (1)

Source: Internet
Author: User

00004 namespace gentleidc. sysbase. Company

00005

{

00006

/// <Summary>

00007

/// Function: Company object operation class

00008

/// By fan jianhan

00009

/// Prepared on:

00010

/// Modifier:

00011

/// Date of Modification

00012

/// </Summary>

00013

Public class companyobj: Gentle. Business. businessadapter

00014

{

00015

Public const string error_exist = "company information with the same name already exists! ";

00016

Public const string error_itemisnull = "the company information object is missing! ";

00017

/// <Summary>

00018

/// Construct and add Company Information Objects

00019

/// </Summary>

00020

PublicCompanyobj ()

00021

{

00022

}

00023

/// <Summary>

00024

/// Construct the company information object

00025

/// And specify the operation type (add | modify)

00026

/// </Summary>

00027

/// <Param name = "isnew"> bool </param>

00028

PublicCompanyobj ( BoolIsnew )

00029

{

00030

Isnew = isnew;

00031

}

00032

/// <Summary>

00033

/// Whether to add information

00034

/// New by default

00035

/// </Summary>

00036

Public boolIsnew

00037

{

00038

Get

00039

{

00040

Return misnew;

00041

}

00042

Set

00043

{

00044

Misnew = value;

00045

}

00046

}

00047

/// <Summary>

00048

/// Company information list

00049

/// </Summary>

00050

PublicGentleidc . Entitys . Tcompany item

00051

{

00052

Get

00053

{

00054

Return mitem;

00055

}

00056

Set

00057

{

00058

Mitem = value;

00059

}

00060

}

00061

Private bool misnew = true;

00062

Private gentleidc. entitys. tcompany mitem;

00063

Protected override voidOnexecute ()

00064

{

00065

If (item = NULL)

00066

Throw (new gentle. Business. businessexception (error_itemisnull

, Null ));

00067

If (isnew)

00068

{

00069

System. Collections. ilist lst = dataunit. List (typeof (tcompany)

, Tcompany. _ companyName = item. companyName );

00070

If (lst. Count> 0)

00071

{

00072

Throw (new gentle. Business. businessexception (error_exist,

Null ));

00073

}

00074

Item. companyindex = getrecordindex (tcompany. TBL. Name );

00075

Dataunit. Save (item );

00076

00077

}

00078

Else

00079

{

00080

Dataunit. Update (item );

00081

}

00082

Base. onexecute ();

00083

}

00084

00085

00086

00087

/// <Summary>

00088

/// Company object for obtaining the corresponding index

00089

/// </Summary>

00090

/// <Param name = "companyid"> company record index </param>

00091

/// <Returns> tcompany </returns>

00092

Public staticTcompany getbyindex ( IntCompanyid )

00093

{

00094

Using (idatasession sessaion = mappingcontainer. configcontainer.

Opensession ())

00095

{

00096

Sessaion. open ();

00097

Return getbyindex (companyid, sessaion );

00098

}

00099

}

00100

00101

/// <Summary>

00102

/// Obtain the company information of the corresponding index in the specified data container

00103

/// </Summary>

00104

/// <Param name = "companyid"> company index value </param>

00105

/// <Param name = "session"> data container </param>

00106

/// <Returns> company object </returns>

00107

Public staticTcompany getbyindex ( IntCompanyid , Idatasession session  

)

00108

{

00109

Return (tcompany) Session. Load (typeof (tcompany), companyid );

00110

}

00111

/// <Summary>

00112

/// Delete company records of the corresponding index

00113

/// </Summary>

00114

/// <Param name = "companyid"> company index </param>

00115

Public static voidDeletebyindex ( IntCompanyid )

00116

{

00117

Using (idatasession session = mappingcontainer. configcontainer.

Opensession ())

00118

{

00119

Session. open ();

00120

Deletebyindex (companyid, session );

00121

}

00122

}

00123

/// <Summary>

00124

/// Delete the company record of the corresponding index in the specified data container

00125

/// </Summary>

00126

/// <Param name = "companyid"> company index </param>

00127

/// <Param name = "session"> data container </param>

00128

Public static voidDeletebyindex ( IntCompanyid , Idatasession session )

00129

{

00130

Idelete delte = session. createdelete (tcompany. TBL );

00131

Delte. expreesion = tcompany. _ companyindex = companyid;

00132

Delte. Execute ();

00133

}

00134

00135

}

00136

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.