public static int DoRegisterNewPassword(PasswordInfo passwordDetails)
        {
            int returnVal = 0;
            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();

            try
            {
                //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();

                //define the connection used by the command object
                msqlCommand.Connection = msqlConnection;

                msqlCommand.CommandText = "INSERT INTO password(passwordId,name,email,userId,password,secretQuestion,secretAnswer,otherInfo) "
                                                   + "VALUES(@passwordId,@name,@email,@userId,@password,@secretQuestion,@secretAnswer,@otherInfo)";

                msqlCommand.Parameters.AddWithValue("@passwordId", passwordDetails.id);
                msqlCommand.Parameters.AddWithValue("@name", passwordDetails.name);
                msqlCommand.Parameters.AddWithValue("@email", passwordDetails.email);
                msqlCommand.Parameters.AddWithValue("@userId", passwordDetails.userId);
                msqlCommand.Parameters.AddWithValue("@password", passwordDetails.password);
                msqlCommand.Parameters.AddWithValue("@secretQuestion", passwordDetails.scrtqstn);
                msqlCommand.Parameters.AddWithValue("@secretAnswer", passwordDetails.scrtans);
                msqlCommand.Parameters.AddWithValue("@otherInfo", passwordDetails.otherInfo);

                msqlCommand.ExecuteNonQuery();

                returnVal = 1;
            }
            catch (Exception er)
            {
                returnVal = 0;
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }
            return returnVal;
        }
Example #2
0
        private static List<PasswordInfo> QueryAllPasswordList()
        {
            List<PasswordInfo> PasswordList = new List<PasswordInfo>();

            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();

            try
            {   //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
                msqlCommand.Connection = msqlConnection;

                msqlCommand.CommandText = "Select * From password ;";
                MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();

                while (msqlReader.Read())
                {
                    PasswordInfo Password = new PasswordInfo();

                    Password.id = msqlReader.GetString("id");
                    Password.name = msqlReader.GetString("name");
                    Password.email = msqlReader.GetString("email");
                    Password.userId = msqlReader.GetString("userId");
                    Password.password = msqlReader.GetString("password");
                    Password.scrtqstn = msqlReader.GetString("secretQuestion");
                    Password.scrtans = msqlReader.GetString("secretAnswer");
                    Password.otherInfo = msqlReader.GetString("otherInfo");

                    PasswordList.Add(Password);
                }

            }
            catch (Exception er)
            {
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }

            return PasswordList;
        }
        private void paswrdSave_Click(object sender, RoutedEventArgs e)
        {
            DNBSNData.PasswordInfo newPassword = new DNBSNData.PasswordInfo();

            newPassword.id = GenerateId();
            newPassword.name = passNameTB.Text;
            newPassword.email = emailforpassTB.Text;
            newPassword.userId = userIdTB.Text;
            newPassword.password = pawsrdTB.Text;
            newPassword.scrtqstn = scrtQstnTB.Text;
            newPassword.scrtans = secrtAnsTB.Text;
            newPassword.otherInfo = othersInfoTB.Text;

            DNBSNDb.DbInteraction.DoRegisterNewPassword(newPassword);
            passNameTB.Text = emailforpassTB.Text = userIdTB.Text = pawsrdTB.Text = scrtQstnTB.Text = secrtAnsTB.Text = othersInfoTB.Text = "";

            addpassInfoExpndr.IsExpanded = false;
            fetchPasswordData();
        }