コード例 #1
0
        /* Auxiliary methods */
        private void Connection()
        {
            try
            {
                if (PinCorrectness())
                {
                    gunaCircleProgressBar1.Value = 0;
                    pass = pin_txtbox.Text;

                    con.Open();
                    using (SqlCommand cmd = new SqlCommand("select * from Users where Pin=@pin", con)
                    {
                        Connection = con
                    })
                    {
                        SqlParameter param1 = new SqlParameter
                        {
                            ParameterName = "@pin",
                            Value         = pin_txtbox.Text
                        };
                        cmd.Parameters.Add(param1);
                        cmd.ExecuteNonQuery();

                        DataTable      dt = new DataTable();
                        SqlDataAdapter da = new SqlDataAdapter(cmd);
                        da.Fill(dt);

                        i = Convert.ToInt32(dt.Rows.Count.ToString());

                        if (i == 0) /* There is no one with written pin */
                        {
                            pin_txtbox.Text = null;
                            string            message = "Do you want to try again?";
                            string            title   = "Wrong password";
                            MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                            DialogResult      result  = MessageBox.Show(message, title, buttons);
                            if (result.Equals(DialogResult.No))
                            {
                                UserForm fm2 = new UserForm();
                                this.Hide();
                                fm2.Show();
                            }
                            label3.Text = null;
                            con.Close();
                        }

                        else
                        {
                            gunaCircleProgressBar1.Visible = true;
                            timer1.Start();

                            SqlDataReader dr = cmd.ExecuteReader();
                            if (dr.Read())
                            {
                                namef   = dr[1].ToString();
                                namel   = dr[2].ToString();
                                balance = dr[3].ToString() + "$";
                            }
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error 404: " + ex);
            }
        }