private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if (this.CustomerDropDownList.Items.Count == 0 || this.ProductsListBox.Items.Count == 0) { this.CustomerDropDownList.Items.Clear(); this.ProductsListBox.Items.Clear();
// Lab 2 // Get an instance of OrderProcessing // Populate product list by calling GetProducts // Iterate through each row in the resulting dataset // For each create a description string that includes // the ProductName column, the UnitPrice column and whether // or not the product is "in stock" (column StockedInternal // is true) or "orderable". // Create an instance of ListItem, setting text to the // description, and the value to a string of the ProductID. // Add the ListItem instance to ProductsListBox.Items. OrderProcessing scOrderProcessing = new OrderProcessing(); ProductDataSet dsProducts; string status,description; dsProducts = scOrderProcessing.GetProducts(); for (int i = 0; i < dsProducts._GetProducts.Count; i++) { status = (dsProducts._GetProducts[i].StockedInternal ? "in stock " : "orderable"); description = String.Format("{0} - {1} - ${2}", dsProducts._GetProducts[i].ProductName, status, dsProducts._GetProducts[i].UnitPrice); this.ProductsListBox.Items.Add( new ListItem(description, dsProducts._GetProducts[i].ProductID.ToString())); } // TODO Lab 3: // Call GetCustomers on OrderProcessing // saving results to an instance of CustomerDataSet. // Iterate through each row in _GetCustomers up to _GetCustomers.Count. // For each create a new ListItem, setting text to the CompanyName // and value to the sting of the CustomerID. // Add the ListItem instance to CustomerDropDownList.Items. // Check that more than 1 customer was returned, before setting // this.CustomerDropDownList.SelectedIndex. // Remove the following temp lines of code. CustomerDataSet dsCustomers = scOrderProcessing.GetCustomers(); for (int i = 0; i < dsCustomers._GetCustomers.Count; i++) { this.CustomerDropDownList.Items.Add( new ListItem(dsCustomers._GetCustomers[i].CompanyName, dsCustomers._GetCustomers[i].CustomerID.ToString())); } this.CustomerDropDownList.SelectedIndex = 0; // Initialize quantity this.QuantityTextBox.Text = "1"; } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.PlaceOrderButton.Click += new System.EventHandler(this.PlaceOrderButton_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion public void PlaceOrderButton_Click(object sender, System.EventArgs e) { if (this.QuantityTextBox.Text.Length == 0) { this.Message.Text = "Invalid quantity"; return; } if (!Char.IsNumber(this.QuantityTextBox.Text, 0)) { this.Message.Text = "Invalid quantity"; return; }
if (this.ProductsListBox.SelectedItem == null) { this.Message.Text = "Please select a product."; return; } try { int quantity = Int32.Parse(this.QuantityTextBox.Text); int customerID = Int32.Parse(this.CustomerDropDownList.SelectedItem.Value); int productID = Int32.Parse(this.ProductsListBox.SelectedItem.Value); // TODO Lab 4: OrderProcessing scOrderProcessing = new OrderProcessing(); scOrderProcessing.PlaceOrder(customerID, productID, quantity); this.Message.Text = this.CustomerDropDownList.SelectedItem.Text + " order submitted."; } catch (Exception ex) { this.Message.Text = "Order submission failed: " + ex.Message; } } } }
//AssmblyInfo.cs using System.Reflection; using System.Runtime.CompilerServices;// // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. // [assembly: AssemblyTitle("")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrade("")] [assembly: AssemblyCulture("")] // // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below:[assembly: AssemblyVersion("1.0.*")]// // In order to sign your assembly you must specify a key to use. Refer to the // Microsoft .NET Framework documentation for more information on assembly signing. // // Use the attributes below to control which key is used for signing. // // Notes: // (*) If no key is specified, the assembly is not signed. // (*) KeyName refers to a key that has been installed in the Crypto Service // Provider (CSP) on your machine. KeyFile refers to a file which contains // a key. // (*) If the KeyFile and the KeyName values are both specified, the // following processing occurs: // (1) If the KeyName can be found in the CSP, that key is used. // (2) If the KeyName does not exist and the KeyFile does exist, the key // in the KeyFile is installed into the CSP and used. // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. // When specifying the KeyFile, the location of the KeyFile should be // relative to the "project output directory". The location of the project output // directory is dependent on whether you are working with a local or web project. // For local projects, the project output directory is defined as // <Project Directory>\obj\<Configuration>. For example, if your KeyFile is // located in the project directory, you would specify the AssemblyKeyFile // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] // For web projects, the project output directory is defined as // %HOMEPATH%\VSWebCache\<Machine Name>\<Project Directory>\obj\<Configuration>. // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework // documentation for more information on this. // [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] [assembly: AssemblyKeyName("")]
private int iLoginCounts=0;
private USER m_user;
然后你可以在登录窗体的OK按钮的Click事件中如下处理:
this.btOK.Enabled = false; //禁止使用确定按钮重复确认
string strUserName = txtUserName.Text;
string strPassword = txtPassword.Text;
if(this.m_user == null)
this.m_user = new USER(strUserName,strPassword);
else
this.m_user.SetUser(strUserName,strPassword);
if (this.m_user.Valid)
{
Main_Frm main_Frm = new Main_Frm(this.m_user);
main_Frm.Show();
this.Visible = false;
}
else
{
txtPassword.Focus();
txtPassword.SelectAll();
this.btOK.Enabled = true; //当输入错误时,重新让用户输入
MessageBox.Show("您输入的用户名或密码错误,请重新输入!" ,"Warning ",MessageBoxButtons.OK ,MessageBoxIcon.Error);
//当用户输入次数超过三次时,退出系统
iLoginCounts++;
if(iLoginCounts >=3)
this.Close();
}
现在关键的是如何处理这个User类,这个类应该包括什么信息...
你的验证是分布式的么?--就是有很多用户并发的在不同地方访问你。如果是,使用COM+服务吧。不必编写任何代码,就可以使用Windows 2000/XP/2003 提供的极其高效的验证机制,呵呵。源码我贴一部分,你看看--这是一个订单发布界面,C#实现
//Placeorder.aspx
<%@ Page language="c#" Codebehind="PlaceOrder.aspx.cs" AutoEventWireup="false" Inherits="_2557.WebOrderForm" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Place Order</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="OrderForm" runat="server">
<asp:dropdownlist id="CustomerDropDownList" style="Z-INDEX: 101; LEFT: 127px; POSITION: absolute; TOP: 73px" runat="server" Width="305px"></asp:dropdownlist>
<asp:Label id="Label3" style="Z-INDEX: 107; LEFT: 127px; POSITION: absolute; TOP: 321px" runat="server" Font-Names="Arial">Quantity</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 106; LEFT: 33px; POSITION: absolute; TOP: 113px" runat="server" Font-Bold="True" Font-Names="Arial">Products</asp:Label>
<asp:label id="Label1" style="Z-INDEX: 102; LEFT: 33px; POSITION: absolute; TOP: 73px" runat="server" Font-Bold="True" Font-Names="Arial" Width="82px">Customer</asp:label>
<asp:listbox id="ProductsListBox" style="Z-INDEX: 103; LEFT: 127px; POSITION: absolute; TOP: 113px" runat="server" Width="305px" Height="191px"></asp:listbox>
<asp:button id="PlaceOrderButton" style="Z-INDEX: 104; LEFT: 307px; POSITION: absolute; TOP: 318px" runat="server" Width="92px" Text="Place Order"></asp:button>
<asp:Label id="Message" style="Z-INDEX: 105; LEFT: 127px; POSITION: absolute; TOP: 357px" runat="server" Width="313px" Font-Bold="True" Font-Names="Arial"></asp:Label>
<asp:TextBox id="QuantityTextBox" style="Z-INDEX: 108; LEFT: 208px; POSITION: absolute; TOP: 318px" runat="server" Width="53px">0</asp:TextBox>
<asp:Label id="Label4" style="Z-INDEX: 109; LEFT: 33px; POSITION: absolute; TOP: 26px" runat="server" Width="390px" Font-Names="Arial" Font-Bold="True" Font-Size="Larger">Northwind Traders Order Entry</asp:Label></form>
</body>
</HTML>
//////////////////////////////////////////
placeorder.aspx.cs
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;namespace _2557
{
public class WebOrderForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList CustomerDropDownList;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button OrderButton;
protected System.Web.UI.WebControls.Label Message;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox QuantityTextBox;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Button PlaceOrderButton;
protected System.Web.UI.WebControls.ListBox ProductsListBox;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here if (this.CustomerDropDownList.Items.Count == 0 ||
this.ProductsListBox.Items.Count == 0)
{
this.CustomerDropDownList.Items.Clear();
this.ProductsListBox.Items.Clear();
// Lab 2
// Get an instance of OrderProcessing
// Populate product list by calling GetProducts
// Iterate through each row in the resulting dataset
// For each create a description string that includes
// the ProductName column, the UnitPrice column and whether
// or not the product is "in stock" (column StockedInternal
// is true) or "orderable".
// Create an instance of ListItem, setting text to the
// description, and the value to a string of the ProductID.
// Add the ListItem instance to ProductsListBox.Items.
OrderProcessing scOrderProcessing = new OrderProcessing();
ProductDataSet dsProducts;
string status,description; dsProducts = scOrderProcessing.GetProducts();
for (int i = 0; i < dsProducts._GetProducts.Count; i++)
{
status = (dsProducts._GetProducts[i].StockedInternal ?
"in stock " : "orderable");
description = String.Format("{0} - {1} - ${2}",
dsProducts._GetProducts[i].ProductName,
status,
dsProducts._GetProducts[i].UnitPrice);
this.ProductsListBox.Items.Add(
new ListItem(description,
dsProducts._GetProducts[i].ProductID.ToString()));
} // TODO Lab 3:
// Call GetCustomers on OrderProcessing
// saving results to an instance of CustomerDataSet.
// Iterate through each row in _GetCustomers up to _GetCustomers.Count.
// For each create a new ListItem, setting text to the CompanyName
// and value to the sting of the CustomerID.
// Add the ListItem instance to CustomerDropDownList.Items.
// Check that more than 1 customer was returned, before setting
// this.CustomerDropDownList.SelectedIndex.
// Remove the following temp lines of code. CustomerDataSet dsCustomers = scOrderProcessing.GetCustomers(); for (int i = 0; i < dsCustomers._GetCustomers.Count; i++)
{
this.CustomerDropDownList.Items.Add(
new ListItem(dsCustomers._GetCustomers[i].CompanyName,
dsCustomers._GetCustomers[i].CustomerID.ToString()));
} this.CustomerDropDownList.SelectedIndex = 0; // Initialize quantity
this.QuantityTextBox.Text = "1";
}
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.PlaceOrderButton.Click += new System.EventHandler(this.PlaceOrderButton_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
public void PlaceOrderButton_Click(object sender, System.EventArgs e)
{
if (this.QuantityTextBox.Text.Length == 0)
{
this.Message.Text = "Invalid quantity";
return;
} if (!Char.IsNumber(this.QuantityTextBox.Text, 0))
{
this.Message.Text = "Invalid quantity";
return;
}
if (this.ProductsListBox.SelectedItem == null)
{
this.Message.Text = "Please select a product.";
return;
} try
{
int quantity = Int32.Parse(this.QuantityTextBox.Text);
int customerID = Int32.Parse(this.CustomerDropDownList.SelectedItem.Value);
int productID = Int32.Parse(this.ProductsListBox.SelectedItem.Value); // TODO Lab 4:
OrderProcessing scOrderProcessing = new OrderProcessing();
scOrderProcessing.PlaceOrder(customerID, productID, quantity); this.Message.Text = this.CustomerDropDownList.SelectedItem.Text + " order submitted.";
}
catch (Exception ex)
{
this.Message.Text = "Order submission failed: " + ex.Message;
}
} }
}
using System.Reflection;
using System.Runtime.CompilerServices;//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrade("")]
[assembly: AssemblyCulture("")] //
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:[assembly: AssemblyVersion("1.0.*")]//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the "project output directory". The location of the project output
// directory is dependent on whether you are working with a local or web project.
// For local projects, the project output directory is defined as
// <Project Directory>\obj\<Configuration>. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// For web projects, the project output directory is defined as
// %HOMEPATH%\VSWebCache\<Machine Name>\<Project Directory>\obj\<Configuration>.
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]