asp.net (C #) +sql Server three-tier architecture data access Scheme (iv)

Source: Internet
Author: User
Tags count tostring trim
asp.net|server| Architecture | Data #region Public methods

<summary>

Get points set according to different conditions

</summary>

<param name= "FunctionID" > Function id</param>

<param name= "OperationID" > Operation id</param>

<param name= "Roletypeid" > Role id</param>

<param name= "Bbstypeid" > Type di</param>

<param name= "Score" > Points </param>

<param name= "BB" > Currency </param>

<param name= "Buytype" > Purchase type </param>

<param name= "Functionstate" > Functional status </param>

<returns></returns>

public bool Getspecialinfo (int functionid,int operationid,int roletypeid,int bbstypeid,int score,int bB,int buyType,int Functionstate)

{

SqlDataAdapter dataAdapter = null;

Database data = new Database ("Town");

#region Create parameters

ArrayList sqlparameterlist=new ArrayList ();

if (functionid!=-1)

Sqlparameterlist.add (data. Makeinparam ("@FunctionID", SqlDbType.Int, 4, FunctionID));

if (operationid!=-1)

Sqlparameterlist.add (data. Makeinparam ("@OperationID", SqlDbType.Int, 4, OperationID));

if (roletypeid!=-1)

Sqlparameterlist.add (data. Makeinparam ("@RoleTypeID", SqlDbType.Int, 4, Roletypeid));

if (bbstypeid!=-1)

Sqlparameterlist.add (data. Makeinparam ("@BBSTypeID", SqlDbType.Int, 4, Bbstypeid));

if (score!=-1)

Sqlparameterlist.add (data. Makeinparam ("@Score", SqlDbType.Int, 4, Score));

if (bb!=-1)

Sqlparameterlist.add (data. Makeinparam ("@BB", SqlDbType.Int, 4, BB));

if (buytype!=-1)

Sqlparameterlist.add (data. Makeinparam ("@BuyType", SqlDbType.Int, 4, buytype));

if (functionstate!=-1)

Sqlparameterlist.add (data. Makeinparam ("@FunctionState", SqlDbType.Int, 4, functionstate));



Sqlparameter[] prams= new Sqlparameter[sqlparameterlist.count];

for (int i=0;i<sqlparameterlist.count;i++)

{

prams[i]= (SqlParameter) sqlparameterlist[i];

}

#endregion

Try

{

Data. Runproc ("getscoresetting", prams, out dataAdapter);

DataSet DataSet = new DataSet ();

DataAdapter.Fill (DataSet, "table");

Dataadapter.dispose ();

if (dataset.tables["table"). Rows.Count = 0)

{

DataSet.Clear ();

Dataset.dispose ();

return false;

}

Else

{



foreach (DataRow dr in dataset.tables["table"). Rows)

{

scoresetting SS = new scoresetting ();

Ss.id= Int32.Parse (dr["Scoresettingid"). ToString (). Trim ());

Ss. Functionid= Int32.Parse (dr["FunctionID"). ToString (). Trim ());

Ss. Operationid= Int32.Parse (dr["OperationID"). ToString (). Trim ());

Ss. Roletypeid= Int32.Parse (dr["Roletypeid"). ToString (). Trim ());

Ss. Bbstypeid= Int32.Parse (dr["Bbstypeid"). ToString (). Trim ());

Ss. Score= Int32.Parse (dr["Score"). ToString (). Trim ());

Ss. bb= Int32.Parse (dr["BB"). ToString (). Trim ());

Ss. Buytype= Int32.Parse (dr["Buytype"). ToString (). Trim ());

Ss. Functionstate= Int32.Parse (dr["Functionstate"). ToString (). Trim ());

ADD (SS);

}



DataSet.Clear ();

Dataset.dispose ();



return true;

}

}

catch (Exception ex)

{

Error.Log ("Town", ex. ToString ());

Dataadapter.dispose ();

return false;

}

Finally

{

Data. Close ();

Data. Dispose ();/release Database

}

}

#endregion



}

}



A little note:

The code for classifying data-tier classes is divided into six blocks: private members, constructors, public properties, indexes, private methods, and public methods. This establishes the index for the class, which is the necessary element of the collection class. Then there is a private method, the role is to add objects to the collection, the public method is a query method, the above example is passed through the parameter, in fact, can also be used to pass the attribute. There is a convention that if the value of 1 is passed, the variable does not work, basically the same as the idea in the stored procedure. The Scoresetting object in this example is another separate class, as follows:



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.