private void btlogin_Click(object sender, System.EventArgs e)
{   string UserID = userid.Text;
string Pwd = pwd.Text;
    string mySql = "select Count(*) from Manager where UserName='"+UserID+"' and Pwd ='"+Pwd+"'";
SqlConnection connection = null ;
try
{
try 
{
connection = SqlHelper.GetConnection();
}
catch
{
MessageBox.Show("The connection with the database can't be established", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
} Int32 count = (Int32)SqlHelper.ExecuteScalar(connection,CommandType.Text,mySql);
if (count > 0)
{
DialogResult = DialogResult.OK; //把登陆帐号写入Users.xml文件
DataSet ds = new DataSet();
string filename = "Users.xml";
ds.ReadXmlSchema(filename);
DataRow dr = ds.Tables[0].NewRow();
dr[0] = userid.Text;
ds.Tables[0].Rows.Add(dr);
ds.WriteXml(filename);
}
else
{
DialogResult = DialogResult.None;
MessageBox.Show("登陆帐号或密码错误,请重新输入!","登陆错误",MessageBoxButtons.OK,MessageBoxIcon.Error);

}
}
catch(Exception ex)
{
string errMessage = "";
for( Exception tempException = ex; tempException != null ; tempException = tempException.InnerException )
{
errMessage += tempException.Message + Environment.NewLine + Environment.NewLine;
} MessageBox.Show( string.Format( "There are some problems while trying to use the Data Access Application block, please check the following error messages: {0}"
+ Environment.NewLine + "This test requires some modifications to the Northwind database. Please make sure the database has been initialized using the SetUpDataBase.bat database script, or from the  Install Quickstart option on the Start menu.", errMessage ), 
"Application error", MessageBoxButtons.OK, MessageBoxIcon.Error );
}
finally
{ if(connection != null)
connection.Dispose();
} } private void btcancel_Click(object sender, System.EventArgs e)
{
Application.Exit();
} private void pwd_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyValue == (char)13)
{
              btlogin.Focus();

}
} private void Flogin_Load(object sender, System.EventArgs e)
{   
//从Users.xml文件读出登陆帐号
DataSet ds = new DataSet();
FileStream fs = new FileStream("Users.xml",FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
fs.Close();
DataRow dr = ds.Tables[0].Rows[0];
userid.Text = dr[0].ToString(); }
}