예제 #1
0
 private void btnSignin_Click(object sender, EventArgs e)
 {
     try
     {
         string sql = "SELECT COUNT(*) FROM users WHERE username=@username AND password=@password";
         using (SqlCeConnection conn = new SqlCeConnection(com.getConnectionString()))
         {
             using (SqlCeCommand cmd = new SqlCeCommand(sql, conn))
             {
                 cmd.Parameters.AddWithValue("@username", txtUsername.Text);
                 cmd.Parameters.AddWithValue("@password", txtPassword.Text);
                 conn.Open();
                 var reader = cmd.ExecuteScalar().ToString();
                 if (reader == "1")
                 {
                     Main main = new Main();
                     main.Show();
                     this.Hide();
                 }
                 else
                 {
                     MessageBox.Show(Properties.strings.login_msg_invlidUaernamePassword);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #2
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtPassword.Text != txtConfirmPassword.Text)
                {
                    MessageBox.Show(Properties.strings.register_msg_passwordNotMatch, "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                string sql = "insert into users (username,password,role) Values (@username,@password,@role);";
                using (SqlCeConnection conn = new SqlCeConnection(com.getConnectionString()))
                {
                    using (SqlCeCommand cmd = new SqlCeCommand(sql, conn))
                    {
                        cmd.Parameters.AddWithValue("@username", txtUsername.Text.Trim());
                        cmd.Parameters.AddWithValue("@password", txtPassword.Text.Trim());
                        cmd.Parameters.AddWithValue("@role", "specialist");
                        conn.Open();
                        short result = (short)cmd.ExecuteNonQuery();

                        if (result > 0)
                        {
                            MessageBox.Show(Properties.strings.register_msg_registerSuccessfully, "خطأ", MessageBoxButtons.OK);
                            Hide();
                            Login login = new Login();
                            login.Show();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }