private void button1_Click(object sender, EventArgs e)
        {
            byte[] data = new byte[208];
            int    nuid;

            try
            {
                if (OpenPort())
                {
                    if (CardAccess(NUID))
                    {
                        if (radioButton1.Checked)
                        {
                            serialPort1.Write(ded10, 0, ded10.Length);
                        }
                        else if (radioButton2.Checked)
                        {
                            serialPort1.Write(ded30, 0, ded30.Length);
                        }
                        else if (radioButton3.Checked)
                        {
                            serialPort1.Write(ded50, 0, ded50.Length);
                        }

                        if (Receive(data))
                        {
                            try
                            {
                                SqlConnection sqc = ConnectDB.GetConnection();
                                SqlCommand    cmd = new SqlCommand("insert into transactiondata values(@UserId,@Store,@Amount,getdate(),'Deduct');", sqc);
                                cmd.Parameters.Add("@UserId", comboBox1.SelectedValue);
                                cmd.Parameters.Add("@Store", comboBox2.Text);
                                cmd.Parameters.Add("@amount", readBalance().ToString());
                                int insertCount = cmd.ExecuteNonQuery();
                                if (insertCount > 0)
                                {
                                    MessageBox.Show("Purchase completed successfully.");
                                    lblCurrentBalance.Text = readBalance().ToString();
                                }
                                else
                                {
                                    MessageBox.Show("Some Error Occured.");
                                }
                            }
                            catch
                            {
                                MessageBox.Show("Some Error Occured.");
                            }


                            //txtboxBalance.Text = readBalance().ToString();
                            //DataGridViewRow row = (DataGridViewRow)dgv1.Rows[0].Clone();
                            //row.Cells[0].Value = DateTime.Now.ToString();
                            //nuid = (int)NUID[0] + (int)NUID[1] * 256 + (int)NUID[2] * 65536 + (int)NUID[3] * 16777216;
                            //row.Cells[1].Value = nuid.ToString("X");
                            //row.Cells[2].Value = txtboxBalance.Text;
                            //dgv1.Rows.Add(row);
                        }
                        else
                        {
                            MessageBox.Show("Operation error! Please try again.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Card read error.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            serialPort1.Close();
        }