private void commitData()
        {
            try
            {
                DBHelper helper = new DBHelper(dbType, dbSource, dbUserId, dbPassword, dbName, dbIntegratedSecurity);

                List<IDbDataParameter> sqlParamList = new List<IDbDataParameter>();
                sqlParamList.Add(new SqlParameter("@KEY", this.textBoxProductKey.Text));
                sqlParamList.Add(new SqlParameter("@SN", this.textBoxSN.Text));
                int count = 0;

                count = Convert.ToInt32(helper.ExecuteScalar(@"SELECT COUNT([ID]) FROM [PostKey]
                where [key] = @KEY and [sn] != @SN and [IsValid] = 'true'", CommandType.Text, sqlParamList.ToArray()));

                if (count > 0)
                {
                    MessageBox.Show("无法重复提交相同的密钥!", "提交失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                sqlParamList = new List<IDbDataParameter>();
                sqlParamList.Add(new SqlParameter("@KEY", this.textBoxProductKey.Text));
                sqlParamList.Add(new SqlParameter("@SN", this.textBoxSN.Text));
                object result = helper.ExecuteScalar(@"SELECT [IsValid] FROM [PostKey]
                                    where [sn]=@SN", CommandType.Text, sqlParamList.ToArray());

                bool isValid = result == null ? false : Convert.ToBoolean(result);

                sqlParamList = new List<IDbDataParameter>();
                sqlParamList.Add(new SqlParameter("@KEY", this.textBoxProductKey.Text));
                sqlParamList.Add(new SqlParameter("@SN", this.textBoxSN.Text));
                sqlParamList.Add(new SqlParameter("@WIFI", this.textBoxWifiMacAddress.Text));
                sqlParamList.Add(new SqlParameter("@BT", this.textBoxBluetoothMacAddress.Text));
                sqlParamList.Add(new SqlParameter("@IMEI", this.textBoxImei.Text));
                sqlParamList.Add(new SqlParameter("@POST_TIME", DateTime.Now));
                sqlParamList.Add(new SqlParameter("@ProductKeyID", this.product_id));

                if (result == null )
                {
                    count = helper.ExecuteNonQuery(@"INSERT INTO [PostKey]
                            ([key],[sn],[wifiMac],[bluetoothMac],[imei],[post_time],[ProductKeyID])
                             VALUES
                            (@KEY,@SN,@WIFI,@BT,@IMEI,@POST_TIME,@ProductKeyID)", CommandType.Text, sqlParamList.ToArray());

                }
                else if(!isValid)
                {
                    count = helper.ExecuteNonQuery(@"UPDATE [PostKey] SET
                            [key]=@KEY,[wifiMac]=@WIFI,[bluetoothMac]=@BT,[imei]=@IMEI,[ProductKeyID]= @ProductKeyID ,[LatestModifiedDate]=@POST_TIME,[IsValid]='true'
                            WHERE [sn]=@SN", CommandType.Text, sqlParamList.ToArray());
                }
                else
                {
                    MessageBox.Show("无法重复提交相同的序列号!", "提交失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (count > 0)
                {
                    MessageBox.Show("提交成功", "操作结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提交失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Invoke(new MyDelegate(updateUI), MSG_COMMIT_END);
            }
        }
 private void checkDatabaseConnection()
 {
     try
     {
         DBHelper helper = new DBHelper(dbType, dbSource, dbUserId, dbPassword, dbName, dbIntegratedSecurity);
         int resut = Convert.ToInt32(helper.ExecuteScalar("select count(ID) from [PostKey]", CommandType.Text, null));
         MessageBox.Show("数据库连接正常", "测试数据库连接", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show("数据库连接失败!\n" + ex.Message, "测试数据库连接", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         this.Invoke(new MyDelegate(updateUI), MSG_CHECK_CONNECTION_END);
     }
 }