最近有用VS 2005 .NET Compact Framework 庫開發一個PDA智能設備應用程序,該PDA採用WinCE5.0嵌入式操作系統及SQL Server CE 數據庫,本程序主要功能是:閱讀二代居民身份證信息及保存、打印來訪登記信息。
以下是程序部分截屏:
以下是“登記攜帶物品”函數實現:
//登記攜帶物品
private void btnDJWP_Click(object sender, EventArgs e)
{
string szIDCode = tbIDCode.Text.Trim();
if (szIDCode == null || szIDCode.Equals(""))
{
MessageBox.Show("請先讀身份證!");
return;
}
if (this.connection.State.Equals(ConnectionState.Closed))
this.connection.Open();
// Dispose previous SqlCeCommand and previous SqlCeResultSet
if (null != this.command) this.command.Dispose();
//Creates a Command with the associated connection
this.command = this.connection.CreateCommand();
SqlCeTransaction tx = this.connection.BeginTransaction();
this.command.Transaction = tx;
try
{
//保存攜帶物品
string szQuery =
"INSERT INTO Article " +
"( [ArtName], [ArtCount], [ArtDesc], [IDCode], [InTime] ) " +
"VALUES( @ArtName, @ArtCount, @ArtDesc, @IDCode, @InTime )";
this.command.CommandText = szQuery;
this.command.Parameters.Add("@ArtName", SqlDbType.NVarChar, 20).Value = tbArtName.Text.Trim();
// 略... ...
this.command.ExecuteNonQuery();
tx.Commit();
MessageBox.Show("物品登記成功!");
cbDept.Focus();
}
catch (Exception ex)
{
tx.Rollback();
MessageBox.Show("物品登記錯誤:" + ex.Message);
}
finally
{
if (this.connection != null && !this.connection.State.Equals(ConnectionState.Closed))
{
this.connection.Close();
}
}
}
【友情鏈接 | 櫥窗推薦】