Exemple #1
0
        public string UpdateStanKonta(AccountDetails account)
        {
            string        Message;
            SqlConnection conect = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=KantorDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");

            conect.Open();
            SqlCommand select      = new SqlCommand("SELECT ilosc FROM Stankonta WHERE id_user=@IDuser AND waluta=@Waluta", conect);
            decimal    amountValue = 0;

            select.Parameters.AddWithValue("@IDuser", account.UserID);
            select.Parameters.AddWithValue("@Waluta", account.Currency);
            SqlDataReader reader = select.ExecuteReader();

            if (reader.Read())
            {
                amountValue = reader.GetDecimal(0);
            }
            conect.Close();
            conect.Open();
            SqlCommand cmd = new SqlCommand("UPDATE Stankonta SET ilosc = @Ilosc WHERE id_user = @IDuser AND waluta = @Waluta", conect);

            amountValue += account.Amount;
            cmd.Parameters.AddWithValue("@IDuser", account.UserID);
            cmd.Parameters.AddWithValue("@Waluta", account.Currency);
            cmd.Parameters.AddWithValue("@Ilosc", amountValue);
            int result = cmd.ExecuteNonQuery();

            if (result == 1)
            {
                Message = string.Format("Stan konta został zaktualizowany: Uzytkownik ID:{0}, Waluta:{1}, Kwota:{2}", account.UserID, account.Currency, account.Amount);
            }
            else
            {
                Message = string.Format("Wystąpił błąd aktualizacji.");
            }
            conect.Close();
            return(Message);
        }
Exemple #2
0
        public string UpgradeStanKonta(AccountDetails account)
        {
            string        Message;
            SqlConnection conect = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=KantorDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");

            conect.Open();
            SqlCommand cmd = new SqlCommand("insert into Stankonta(id_user, waluta, ilosc) values(@IDuser,@Waluta,@Ilosc)", conect);

            cmd.Parameters.AddWithValue("@IDuser", account.UserID);
            cmd.Parameters.AddWithValue("@Waluta", account.Currency);
            cmd.Parameters.AddWithValue("@Ilosc", account.Amount);
            int result = cmd.ExecuteNonQuery();

            if (result == 1)
            {
                Message = string.Format("Stan konta został zaktualizowany: Uzytkownik ID:{0}, Waluta:{1}, Kwota:{2}", account.UserID, account.Currency, account.Amount);
            }
            else
            {
                Message = string.Format("Wystąpił błąd aktualizacji.");
            }
            conect.Close();
            return(Message);
        }