Пример #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         SqlConnection sqc = ConnectDB.GetConnection();
         SqlCommand    cmd = new SqlCommand("insert into users values(@firstname,@lastname,@email,@phone,@address);", sqc);
         cmd.Parameters.Add("@firstname", txtFirstName.Text);
         cmd.Parameters.Add("@lastname", txtLastName.Text);
         cmd.Parameters.Add("@email", txtEmail.Text);
         cmd.Parameters.Add("@phone", txtPhoneNo.Text);
         cmd.Parameters.Add("@address", txtAddress.Text);
         int insertCount = cmd.ExecuteNonQuery();
         if (insertCount > 0)
         {
             MessageBox.Show("User Registered Successfully.");
         }
         else
         {
             MessageBox.Show("Some Error Occured.");
         }
     }
     catch
     {
         MessageBox.Show("Some Error Occured.");
     }
 }
Пример #2
0
        private void AddBalance_Load(object sender, EventArgs e)
        {
            try
            {
                if (CheckPorts(cbCOM) == false)
                {
                    MessageBox.Show("No COM Ports found on this computer.\nTry reconnecting USB cable and restart application.",
                                    "No COM Ports detected.",
                                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    this.Close();
                }
                SqlConnection  sqc  = ConnectDB.GetConnection();
                SqlCommand     cmd  = new SqlCommand("Select Firstname,Id from Users", sqc);
                SqlDataAdapter sdra = new SqlDataAdapter(cmd);
                DataSet        ds   = new DataSet();
                sdra.Fill(ds);
                comboBox1.DataSource    = ds.Tables[0];
                comboBox1.ValueMember   = "Id";
                comboBox1.DisplayMember = "Firstname";

                GetBalance();
            }
            catch
            {
                MessageBox.Show("Some Error Occured.");
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "admin")
            {
                try
                {
                    SqlConnection  sqc  = ConnectDB.GetConnection();
                    SqlCommand     cmd  = new SqlCommand("Select * from Users", sqc);
                    SqlDataAdapter sdra = new SqlDataAdapter(cmd);
                    DataSet        ds   = new DataSet();
                    sdra.Fill(ds);
                    dataGridView1.DataSource = ds.Tables[0];

                    SqlCommand     cmd1  = new SqlCommand("Select  * from TransactionData", sqc);
                    SqlDataAdapter sdra1 = new SqlDataAdapter(cmd1);
                    DataSet        ds1   = new DataSet();
                    sdra1.Fill(ds1);
                    dataGridView2.DataSource = ds1.Tables[0];
                }
                catch
                {
                    MessageBox.Show("Some Error Occured.");
                }
            }
            else
            {
                MessageBox.Show("Please enter correct password.");
            }
        }
Пример #4
0
        private void HomeSelfTopUp_Load(object sender, EventArgs e)
        {
            try
            {
                SqlConnection  sqc  = ConnectDB.GetConnection();
                SqlCommand     cmd  = new SqlCommand("Select top 5 * from Users", sqc);
                SqlDataAdapter sdra = new SqlDataAdapter(cmd);
                DataSet        ds   = new DataSet();
                sdra.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];

                SqlCommand     cmd1  = new SqlCommand("Select top 5 * from TransactionData", sqc);
                SqlDataAdapter sdra1 = new SqlDataAdapter(cmd1);
                DataSet        ds1   = new DataSet();
                sdra1.Fill(ds1);
                dataGridView2.DataSource = ds1.Tables[0];
            }
            catch
            {
                MessageBox.Show("Some Error Occured.");
            }
        }
Пример #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            string[] carddetails = new string[] { "1111111111111111", "22222222222222222", "3333333333333333", "4444444444444444" };
            if (Array.IndexOf(carddetails, txtcreditcards.Text) == 1)
            {
                byte[] data = new byte[208];
                int    nuid;
                try
                {
                    if (OpenPort())
                    {
                        if (CardAccess(NUID))
                        {
                            int amount = 0;
                            if (radioButton1.Checked)
                            {
                                serialPort1.Write(inc10, 0, inc10.Length);
                                amount = 10;
                            }
                            else if (radioButton2.Checked)
                            {
                                serialPort1.Write(inc30, 0, inc30.Length);
                                amount = 30;
                            }
                            else if (radioButton3.Checked)
                            {
                                serialPort1.Write(inc50, 0, inc50.Length);
                                amount = 50;
                            }


                            if (Receive(data))
                            {
                                try
                                {
                                    SqlConnection sqc = ConnectDB.GetConnection();
                                    SqlCommand    cmd = new SqlCommand("insert into transactiondata values(@UserId,@Store,@Amount,getdate(),'TopUp');", 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("Card recharged successfully.");
                                        lblCurrentBalance.Text = readBalance().ToString();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Some Error Occured.");
                                    }
                                }
                                catch
                                {
                                    MessageBox.Show("Some Error Occured.");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Operation error! Please try again.");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Card read error.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBox.Show("Invalid Card Details....");
            }

            serialPort1.Close();
        }
        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();
        }