public string SetHistoriaPrzelewow(TransferHistory history) { 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 Historiaprzelewow(id_user, typ, waluta, kwota, data) values(@IDuser,@Typ,@Waluta,@Kwota,@Data)", conect); cmd.Parameters.AddWithValue("@IDuser", history.UserID); cmd.Parameters.AddWithValue("Typ", history.Type); cmd.Parameters.AddWithValue("@Waluta", history.Currency); cmd.Parameters.AddWithValue("@Kwota", history.Amount); cmd.Parameters.AddWithValue("@Data", history.Date); int result = cmd.ExecuteNonQuery(); if (result == 1) { Message = string.Format("Przelew został wykonany: Uzytkownik ID:{0}, Typ przelewu:{1}, Waluta:{2}, Kwota:{3}, Data:{4}", history.UserID, history.Type, history.Currency, history.Amount, history.Date); } else { Message = string.Format("Wystąpił błąd przelewu."); } conect.Close(); return(Message); }
public string GetHistoriaPrzelewow(TransferHistory history) { string Message = string.Empty; List <TransferHistory> historyList = new List <TransferHistory>(); 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("SELECT typ, waluta, kwota, data FROM Historiaprzelewow WHERE id_user=@ID", conect); cmd.Parameters.AddWithValue("@ID", SqlDbType.Int); object parameter; if (history.UserID == null) { cmd.Parameters["@ID"].Value = DBNull.Value; } else { cmd.Parameters["@ID"].Value = history.UserID; } parameter = cmd.Parameters["@ID"].Value; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { historyList.Add(new TransferHistory() { UserID = history.UserID, Type = reader.GetString(0), Currency = reader.GetString(1), Amount = reader.GetDecimal(2), Date = reader.GetDateTime(3) }); } foreach (TransferHistory line in historyList) { Message += line.Type + line.Currency + line.Amount + line.Date + ";"; } conect.Close(); return(Message); }