Sun Qiang's query base class and application.

Source: Internet
Author: User
Tags mailmessage

Using system;
Using system. Data. sqlclient;
Using system. Data;

Namespace webshop
{
/// <Summary>
/// Summary of common.
/// </Summary>
Public class common: idisposable
{
String sqlconn = system. configuration. configurationsettings. appsettings ["sqlconn"]. tostring ();
Sqldataadapter adapter;
Public dataset full (string sqltext, commandtype comtype, string tablename, Params sqlparameter [] para)
{
Adapter = new sqldataadapter ();
Adapter. selectcommand = new sqlcommand ();
Adapter. selectcommand. Connection = new sqlconnection (sqlconn );
Adapter. selectcommand. commandtext = sqltext;
Adapter. selectcommand. commandtype = comtype;

Foreach (sqlparameter P in para)
{
Adapter. selectcommand. Parameters. Add (P );
}

Dataset DS = new dataset ();

Try
{
Adapter. selectcommand. Connection. open ();
Adapter. Fill (DS, tablename );
Return Ds;
}
Catch (system. Exception ex)
{
Throw new exception (ex. Message );

}
Finally
{
Adapter. selectcommand. Connection. Close ();

}

}


Public bool exec (string sqltext, commandtype comtype, Params sqlparameter [] para)
{
Adapter = new sqldataadapter ();
Adapter. selectcommand = new sqlcommand ();
Adapter. selectcommand. Connection = new sqlconnection (sqlconn );
Adapter. selectcommand. commandtext = sqltext;
Adapter. selectcommand. commandtype = comtype;

Foreach (sqlparameter P in para)
{
Adapter. selectcommand. Parameters. Add (P );
}

Bool number = false;
Try
{
Adapter. selectcommand. Connection. open ();
If (adapter. selectcommand. executenonquery ()> 0)
Number = true;
Return number;

}
Catch (system. Exception ex)
{
Throw new exception (ex. Message );

}
Finally
{
Adapter. selectcommand. Connection. Close ();

}

}
# Region idisposable Member

Public void dispose ()
{
// Todo: Add common. Dispose implementation
}
Protected void dispose (bool displsing)
{
If (displsing)
{
If (adapter! = NULL)
{
If (adapter. selectcommand! = NULL)
{
If (adapter. selectcommand. connection! = NULL)
Adapter. selectcommand. Connection. Dispose ();
Adapter. selectcommand. Dispose ();
}
Adapter. Dispose ();
Adapter = NULL;

}
}
}

# Endregion
}
}

 

 

Application

 

Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using system. Data. sqlclient;

Namespace bargaining. ascx
{
/// <Summary>
/// Summary of gerenfabu.
/// </Summary>
Public class gerenfabu: system. Web. UI. Page
{
Protected system. Web. UI. webcontrols. Label label1;
Protected system. Web. UI. webcontrols. Button button1;
Protected system. Web. UI. webcontrols. datalist youxibi;
 
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
If (! Page. ispostback)
{
Webshop. Common common = new webshop. Common ();
String strsql = "select wupinxinxi. shangpinid, wupinxinxi. serverid, DBO. game. gamename, DBO. subarea. gamesubarea, wupinxinxi. xinxibiaoti, DBO. server. gameserver, Prop. propname, Prop. propid, DBO. wupinxinxi. shuliang as Shu from DBO. wupinxinxi inner join DBO. game On DBO. wupinxinxi. gameid = DBO. game. gameid inner join DBO. server on DBO. wupinxinxi. serverid = DBO. server. serverid inner join DBO. subarea on DBO. wupinxinxi. subareaid = DBO. subarea. subareaid inner join prop on wupinxinxi. propid = prop. propid group by DBO. game. gamename, DBO. subarea. gamesubarea, DBO. server. gameserver, DBO. prop. propname, wupinxinxi. xinxibiaoti, Prop. propid, wupinxinxi. propid, wupinxinxi. serverid, wupinxinxi. userid, wupinxinxi. shangpinid, DBO. wupinxinxi. shuliang, shengyushuliang having (DBO. wupinxinxi. userid = '"+ session [" userid "]. tostring () + "') and shengyushuliang> 0 ";
Dataset DS = Common. Full (strsql, commandtype. Text, "bixiangxi ");
If (Ds. Tables [0]. Rows. Count> 0)
{
// This. labelrecord. Text = Ds. Tables [0]. Rows. Count. tostring ();
// Int recordcount = int. parse (this. labelrecord. Text );
// Int intpageno, intpagesize, intpagecount;
// Intpagesize = 5;
// Intpagecount = recordcount % intpagesize = 0? Recordcount/intpagesize: recordcount/intpagesize + 1;
// Labelpage. Text = intpagecount. tostring ();
//
// Pageddatasource objpage = new pageddatasource ();
// Objpage. datasource = Ds. Tables [0]. defaultview;
// Objpage. allowpaging = true;
// Objpage. pagesize = intpagesize;
// If (this. request ["currentpage"] = NULL)
//{
// Intpageno = 1;
//}
// Else
//{
// Intpageno = int. parse (this. request ["currentpage"]);
//}
//
// If (! This. ispostback)
//{
// For (INT I = 1; I <= intpagecount; I ++)
//{
// This. dropdownlist2.items. Add (I. tostring ());
//}
// This. dropdownlist2.selectedvalue = intpageno. tostring ();
//}
// Intpageno = int. parse (this. dropdownlist2.selecteditem. Text );
// This. labelrow. Text = intpageno. tostring ();
// Objpage. currentpageindex = intPageNo-1;
// If (intpageno> 1)
//{
// This. hlfistpage. navigateurl = "gerenshangdian. aspx? Currentpage = 1 ";
// This. hlprevpage. navigateurl = string. Concat ("gerenshangdian. aspx? Currentpage = "," ", intPageNo-1 );
//}
// Else
//{
// Hlfistpage. navigateurl = "";
// Hlprevpage. navigateurl = "";
//}
// If (intpageno! = Intpagecount)
//{
// This. hlnextpage. navigateurl = string. Concat ("gerenshangdian. aspx? Currentpage = "," ", intpageno + 1 );
// This. hlendpage. navigateurl = string. Concat ("gerenshangdian. aspx? Currentpage = "," ", intpagecount );
//}
// Else
//{
// This. hlnextpage. navigateurl = "";
// This. hlendpage. navigateurl = "";
//}
This. youxibi. datasource = Ds. Tables [0];
This. youxibi. databind ();
}
}
}

# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}

/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. button1.click + = new system. eventhandler (this. button#click );
This. Load + = new system. eventhandler (this. page_load );

}
# Endregion

Public void button#click (Object sender, system. eventargs E)
{
Linkbutton d = (linkbutton) sender;
String id = D. commandargument. tostring ();
Webshop. common1 comm = new webshop. common1 ();
String strsql = "delete wupinxinxi where shangpinid = '" + ID + "'";
Comm.exe C (strsql, commandtype. Text, "wupinxinxi ");

}
}
}

 

 

Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using system. Web. mail;
Using system. Data. sqlclient;

Namespace bargaining
{
/// <Summary>
/// Summary of dingdan.
/// </Summary>
Public class dingdan: system. Web. UI. Page
{
Protected system. Web. UI. htmlcontrols. htmlform form1;
Protected system. Web. UI. htmlcontrols. htmlform form2;
Protected system. Web. UI. webcontrols. Label label10;
Protected system. Web. UI. webcontrols. Label label8;
Protected system. Web. UI. webcontrols. Label label9;
Protected system. Web. UI. webcontrols. Label label7;
Protected system. Web. UI. webcontrols. linkbutton linkbutton1;
Protected system. Web. UI. webcontrols. Label label1;
Protected system. Web. UI. webcontrols. Label label6;
Protected system. Web. UI. webcontrols. Label label5;
Protected system. Web. UI. webcontrols. Label label3;
Protected system. Web. UI. webcontrols. Label label2;
Protected system. Web. UI. webcontrols. Label label4;
Protected system. Web. UI. webcontrols. Image image1;
Protected system. Web. UI. htmlcontrols. htmltable table7;
Protected system. Web. UI. webcontrols. linkbutton linkbutton2;
Protected system. Web. UI. htmlcontrols. htmlform form3;
 
Private void page_load (Object sender, system. eventargs E)
{
String H = "";
If (! This. ispostback)
{
Try
{
H = session ["userid"]. tostring ();
}
Catch
{
H = "";
}
If (H! = "")
{
This. table7.visible = false;
String diankaname = This. Request. querystring ["dingdanname"]. tostring ();;
Response. Write (diankaname );
Dataset Ds;
String strsql = "select DBO. diankaxinxi. diankaid, DBO. diankaxinxi. diankaname, DBO. diankaxinxi. accountname, DBO. diankaxinxi. password, DBO. diankaxinxi. newjia, DBO. diankaxinxi. jiage, DBO. dianka. jieshengshu, DBO. dianka. dianshu, DBO. dianka. IMG, dianka. beizhu, DBO. diankaxinxi. xiangxiid from DBO. dianka inner join DBO. diankaxinxi on DBO. dianka. diankaid = DBO. diankaxinxi. diankaid where dianka. diankaname = '"+ diankaname + "'";
Using (webshop. Common common = new webshop. Common ())
{
DS = Common. Full (strsql, commandtype. Text, "dianka ");
}
If (Ds. Tables [0]. Rows. Count> 0)
{
This. image1.imageurl = "dianka/" + Ds. Tables [0]. Rows [0] [8]. tostring ();
This. label4.text = Ds. Tables [0]. Rows [0] [1]. tostring ();
This. label2.text = Ds. Tables [0]. Rows [0] [5]. tostring ();
This. label3.text = Ds. Tables [0]. Rows [0] [4]. tostring ();
String jiesheng = Ds. Tables [0]. Rows [0] [6]. tostring ();
Double Jie = double. parse (jiesheng. tostring ());
If (Jie <0)
{
This. label5.text = "the current price is higher than the original price ";
}
Else
{
This. label5.text = Ds. Tables [0]. Rows [0] [6]. tostring () = ""? & Quot; 0.00 & quot;: Ds. Tables [0]. Rows [0] [6]. tostring ();
}
This. label6.text = Ds. Tables [0]. Rows [0] [7]. tostring ();
This. label1.text = Ds. Tables [0]. Rows [0] [9]. tostring ();
This. viewstate. Add ("accountname", DS. Tables [0]. Rows [0] [2]. tostring ());
This. viewstate. Add ("password", DS. Tables [0]. Rows [0] [3]. tostring ());
This. viewstate. Add ("diankaid", DS. Tables [0]. Rows [0] [10]. tostring ());
}
Else
{

Response. Write ("<script language = 'javascript '> ");
Response. Write ("alert ('Do not have this cart ');");
Response. Write ("parent. Opener = NULL ;");
Response. Write ("window. Close ();");
Response. Write ("</SCRIPT> ");

}
}
Else
{
Response. Write ("<script language = 'javascript '> ");
Response. Write ("alert ('Log On First ');");
Response. Write ("parent. Opener = NULL ;");
Response. Write ("window. Close ();");
Response. Write ("</SCRIPT> ");

}

}

This. linkbutton1.attributes. Add ("onclick", "Return confirm ('Are you sure you want to buy? ')");
}
Private void sendemail (string Kano, string PWD)
{

Mailmessage mymail = new mailmessage ();
Mymail. To = This. session ["email"]. tostring ();
Mymail. From = "lfjdc001@163.com ";
Mymail. Subject = ": Hello! Please check the card counting account and password you purchased on Tiancheng game network! ";
Mymail. Body = "Point card account:" + Kano + "Point card password:" + PWD;
Mymail. bodyformat = mailformat. html;
Mymail. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1 ");
Mymail. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", "lfjdc001 ");
Mymail. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", "2881056 ");
Smtpmail. smtpserver = "smtp.163.com ";
Try
{
Smtpmail. Send (mymail );

This. response. Write ("<SCRIPT> alert ('your card account and password have been sent to your mailbox. Please check it! ') </SCRIPT> ");
}
Catch (system. Exception ex)
{
Throw new exception (ex. Message );
}
}
# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}

/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. linkbutton1.click + = new system. eventhandler (this. linkbutton#click );
This. linkbutton2.click + = new system. eventhandler (this. linkbutton2_click );
This. Load + = new system. eventhandler (this. page_load );

}
# Endregion

Private void linkbutton#click (Object sender, system. eventargs E)
{

Dataset account = (Dataset) This. session ["Account"];
If (account. Tables [0]. Rows. Count> 0)
{
If (double. parse (account. Tables [0]. Rows [0] [2]. tostring ()> = double. parse (this. label3.text ))
{
Int userid = int. parse (this. session ["userid"]. tostring ());
Using (webshop. Common common = new webshop. Common ())
{
Common.exe C ("pro_diankatran", commandtype. storedprocedure, new sqlparameter ("@ userid", userid), new sqlparameter ("@ wupinname", this. label4.text), new sqlparameter ("@ jiage", decimal. parse (this. label3.text), new sqlparameter ("@ dingdantime", system. datetime. now. tostring (), new sqlparameter ("@ mymoney", decimal. parse (this. label3.text), new sqlparameter ("@ diankaid", Int. parse (this. viewstate ["diankaid"]. tostring ())));
}
This. table7.visible = true;
This. label9.visible = true;
This. label10.visible = true;
This. label9.text = This. viewstate ["accountname"]. tostring ();
This. label10.text = This. viewstate ["password"]. tostring ();
This. linkbutton1.enabled = false;

This. sendemail (this. viewstate ["accountname"]. tostring (), this. viewstate ["password"]. tostring ());
// This. response. Redirect ("default. aspx", false );

}
Else
{
This. response. Write ("<SCRIPT> alert ('your available amount is insufficient. Please recharge your account! ') </SCRIPT> ");
}
}
Else
{
This. response. Write ("<SCRIPT> alert ('your account has not been recharged. Please recharge first! ') </SCRIPT> ");
}
}

Private void linkbutton2_click (Object sender, system. eventargs E)
{
// This. response. Redirect ("default. aspx", true );
Dataset account = (Dataset) This. session ["Account"];
If (account. Tables [0]. Rows. Count> 0)
{
If (double. parse (account. Tables [0]. Rows [0] [2]. tostring ()> = double. parse (this. label3.text ))
{
Int userid = int. parse (this. session ["userid"]. tostring ());
Using (webshop. Common common = new webshop. Common ())
{
Common.exe C ("pro_diankatran", commandtype. storedprocedure, new sqlparameter ("@ userid", userid), new sqlparameter ("@ wupinname", this. label4.text), new sqlparameter ("@ jiage", decimal. parse (this. label3.text), new sqlparameter ("@ dingdantime", system. datetime. now. tostring (), new sqlparameter ("@ mymoney", decimal. parse (this. label3.text), new sqlparameter ("@ diankaid", Int. parse (this. viewstate ["diankaid"]. tostring ())));
}
This. table7.visible = true;
This. label9.visible = true;
This. label10.visible = true;
This. label9.text = This. viewstate ["accountname"]. tostring ();
This. label10.text = This. viewstate ["password"]. tostring ();
This. linkbutton1.enabled = false;

This. sendemail (this. viewstate ["accountname"]. tostring (), this. viewstate ["password"]. tostring ());
// This. response. Redirect ("default. aspx", false );

}
Else
{
This. response. Write ("<SCRIPT> alert ('your available amount is insufficient. Please recharge your account! ') </SCRIPT> ");
}
}
Else
{
This. response. Write ("<SCRIPT> alert ('your account has not been recharged. Please recharge first! ') </SCRIPT> ");
}
}

}
}

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.