. Net public class design 7

Source: Internet
Author: User

Design of background login module

Verification Code Technology

Public partial class Manage_Login: System. Web. UI. Page
{
// Create a new instance object for the public class CommonClass
CommonClass ccObj = new CommonClass ();
DBClass dbObj = new DBClass ();
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack) // determines whether the page is loaded for the first time.
{
This. labCode. Text = ccObj. RandomNum (4); // generate a verification code
}
}
Protected void btnLogin_Click (object sender, EventArgs e)
{
// Determine whether the user has entered necessary information
If (this.txt AdminName. Text. Trim () = "" | this.txt AdminPwd. Text. Trim () = "")
{
// Call the MessageBox method in the public class CommonClass
Response. Write (ccObj. MessageBox ("the logon name and password cannot be blank! "));
}
Else
{
// Determine whether the verification code entered by the user is correct
If (txtAdminCode. Text. Trim () = labCode. Text. Trim ())
{
// Define a string to obtain user information
String strSql = "select * from tb_Admin where AdminName = '" descrithis.txt AdminName. text. trim () + "'and Password ='" incluthis.txt AdminPwd. text. trim () + "'";
DataTable dsTable = dbObj. GetDataSetStr (strSql, "tbAdmin ")
;
// Determine whether a user exists
If (dsTable. Rows. Count> 0)
{
Session ["AID"] = Convert. ToInt32 (dsTable. Rows [0] [0]. ToString (); // Save the user ID
Session ["AName"] = dsTable. Rows [0] [1]. ToString (); // Save the user name
Response. Write ("<script language = javascript> window. open ('adminindex. aspx '); window. close (); </script> ");
}
Else
{
Response. Write (ccObj. MessageBox ("the user name or password you entered is incorrect. Please enter it again! "));
}
}
Else
{
Response. Write (ccObj. MessageBox ("the verification code is incorrectly entered. Please enter it again! "));
}
}
}

Protected void btnCancel_Click (object sender, EventArgs e)
{
Response. Write ("<script> window. close (); location = 'javascript: history. go (-1) '; </script> ");
}
}

Product inventory management

The text box is used to search for a product, a gridview

<Asp: HyperLinkField HeaderText = "details" Text = "details" DataNavigateUrlFields = "BookID" DataNavigateUrlFormatString = "EditProduct. aspx? BookID = {0} ">
<ControlStyle Font-Underline = "False" ForeColor = "Black"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: HyperLinkField>

<Asp: CommandField HeaderText = "delete" ShowDeleteButton = "True">
<ControlStyle Font-Underline = "False" ForeColor = "Black"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: CommandField>

Public partial class Manger_Product: System. Web. UI. Page
{
CommonClass ccObj = new CommonClass ();
DBClass dbObj = new DBClass ();
GoodsClass gcObj = new GoodsClass ();
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
// Determine whether the "Search" button has been clicked
ViewState ["search"] = null;
GvBind (); // display product information
}
}
// Obtain the product name through the product category number
Public string GetClassName (int IntClassID)
{
String strClassName = gcObj. GetClass (IntClassID );
Return strClassName;
}
Public String GetVarStr (string strHotPrice)
{
Return ccObj. VarStr (strHotPrice, 2 );
}
/// <Summary>
/// Bind all product information
/// </Summary>
Public void gvBind ()
{
String strSql = "select * from tb_BookInfo ";
// Call the GetDataSetStr method in the public class to execute the SQL statement and return the data table of the data source.
DataTable dsTable = dbObj. GetDataSetStr (strSql, "tbBI ");
This. gvGoodsInfo. DataSource = dsTable. DefaultView;
This. gvGoodsInfo. DataKeyNames = new string [] {"BookID "};
This. gvGoodsInfo. DataBind ();
}
/// <Summary>
/// Bind product information to search
/// </Summary>
Public void gvSearchBind ()
{
DataTable dsTable = gcObj.search(this.txt Key. Text. Trim ());
This. gvGoodsInfo. DataSource = dsTable. DefaultView;
This. gvGoodsInfo. DataKeyNames = new string [] {"BookID "};
This. gvGoodsInfo. DataBind ();
}

Protected void gvGoodsInfo_PageIndexChanging (object sender, GridViewPageEventArgs e)
{
GvGoodsInfo. PageIndex = e. NewPageIndex;
If (ViewState ["search"]! = Null)
{
GvSearchBind (); // bind the queried item information
}
Else
{
GvBind (); // bind all product information
}
}

Protected void gvGoodsInfo_RowDeleting (object sender, GridViewDeleteEventArgs e)
{
Int IntBookID = Convert. ToInt32 (gvGoodsInfo. DataKeys [e. RowIndex]. Value); // obtain the product code
String strSql = "select count (*) from tb_Detail where BookID =" + IntBookID;
SqlCommand myCmd = dbObj. GetCommandStr (strSql );
// Determine whether the product can be deleted (for example, including the ID of the product in a detailed order)
If (Convert. ToInt32 (dbObj. ExecScalar (myCmd)> 0)
{
Response. Write (ccObj. MessageBox ("This item is in use and cannot be deleted! "));
}
Else
{
// Delete the specified item information
String strDelSql = "delete from tb_BookInfo where BookID =" + IntBookID;
SqlCommand myDelCmd = dbObj. GetCommandStr (strDelSql );
DbObj. ExecNonQuery (myDelCmd );
// Rebind the product
If (ViewState ["search"]! = Null)
{
GvSearchBind (); // bind the queried item information
}
Else
{
GvBind (); // bind all product information
}

}
}
Protected void btnSearch_Click (object sender, EventArgs e)
{
// Set the value of ViewState ["search"] object to 1.
ViewState ["search"] = 1;
GvSearchBind (); // bind the queried item information
}
}

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.