ATBQ2 1.0.0
dotnet add package ATBQ2 --version 1.0.0
NuGet\Install-Package ATBQ2 -Version 1.0.0
<PackageReference Include="ATBQ2" Version="1.0.0" />
<PackageVersion Include="ATBQ2" Version="1.0.0" />
<PackageReference Include="ATBQ2" />
paket add ATBQ2 --version 1.0.0
#r "nuget: ATBQ2, 1.0.0"
#:package ATBQ2@1.0.0
#addin nuget:?package=ATBQ2&version=1.0.0
#tool nuget:?package=ATBQ2&version=1.0.0
docker ---------------------------
docker-compose up -d
Остановить
docker-compose down
Пересобрать и запустить
docker-compose up -d --build
Перезапустить
docker-compose restart
Показать контейнеры
docker-compose ps
Логи
docker-compose logs api
yml
" services: db: image: mysql:8.0 ports: - "3307:3306" environment: MYSQL_ROOT_PASSWORD: qwe123 MYSQL_DATABASE: Bib api: build: . depends_on: - db ports: - "3000:8080" environment: DBHOST: db ASPNETCORE_ENVIRONMENT: Development "
mysql----------------------------------------------------- Scaffold-DbContext "Server=localhost;Port=3306;Database=publishing;User=root;Password=8989;" Pomelo.EntityFrameworkCore.MySql -OutputDir Model
програ-------------------------------------------------------------------------------------- 1 контекст optionsBuilder.UseMySql("server=db;port=3306; database=auth_system;user=root;password=qwe123", Microsoft.EntityFrameworkCore.ServerVersion.Parse("9.5.0-mysql"));
Контроллер--------------------------------------------------------
using Microsoft.AspNetCore.Mvc; using WebApplication7.Model; using Microsoft.EntityFrameworkCore;
namespace WebApplication7.Controllers { [ApiController] [Route("api/[controller]")] public class HomeController : Controller { private readonly DbInfoContext _context = new DbInfoContext();
public List<User> GetUsers()
{
return _context.Users.ToList();
}
[HttpPost("AddUser")]
public IActionResult AddUser([FromBody] User user)
{
_context.Users.Add(user);
_context.SaveChanges();
return Ok();
}
[HttpGet("GetTovar")]
public List<Tovar> GetTovars()
{
return _context.Tovars.ToList();
}
[HttpPost("AddTovar")]
public IActionResult AddTovar([FromBody] Tovar tovar)
{
_context.Tovars.Add(tovar);
_context.SaveChanges();
return Ok();
}
[HttpGet("GetPokupki")]
public IActionResult GetPokupki()
{
var result = from pokupka in _context.Pokupkis
join user in _context.Users on pokupka.UserId equals user.Id
join tovar in _context.Tovars on pokupka.TovarId equals tovar.Id
select new
{
Id = pokupka.Id,
UserName = user.Name,
TovarName = tovar.Name
};
return Ok(result.ToList());
}
[HttpPost("AddPokupka")]
public IActionResult AddPokupka([FromBody] PokupkaRequest request)
{
var pokupka = new Pokupki
{
Id = _context.Pokupkis.Max(p => p.Id) + 1,
UserId = request.UserId,
TovarId = request.TovarId
};
_context.Pokupkis.Add(pokupka);
_context.SaveChanges();
return Ok();
}
public class PokupkaRequest
{
public int UserId { get; set; }
public int TovarId { get; set; }
}
}
}
WPF--------------------------------------------------
MAINWINDOW----------------------------
<Grid> <Grid.RowDefinitions> <RowDefinition Height="163*"/> <RowDefinition Height="271*"/> </Grid.RowDefinitions> <StackPanel Margin="20,117,20,0" VerticalAlignment="Top" Grid.RowSpan="2"> <TextBlock Text="Вход" FontSize="20" Margin="0,0,0,10"/>
<TextBlock Text="Логин:"/>
<TextBox x:Name="txtUser" Margin="0,5,0,10"/>
<TextBlock Text="Пароль:"/>
<PasswordBox x:Name="txtPass" Margin="0,5,0,20"/>
<Button Content="Войти" Click="Login_Click" Height="30"/>
<TextBlock x:Name="txtError" Foreground="Red" Margin="0,10,0,0"/>
</StackPanel>
</Grid>
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private async void Login_Click(object sender, RoutedEventArgs e) { string user = txtUser.Text; string pass = txtPass.Password;
try
{
using (HttpClient client = new HttpClient())
{
string response = await client.GetStringAsync("http://localhost:3000/api/Home/GetUser");
if (response.Contains($"\"name\":\"{user}\""))
{
new NewsWindow().Show();
this.Close();
}
else
{
txtError.Text = "Неверные данные";
}
}
}
catch (Exception ex)
{
txtError.Text = ex.Message;
}
}
}
NewsWindow(ВЫВОД)-----------------------------------------
<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions>
<Button x:Name="btnAddUser" Content="Добавить пользователя"
Click="BtnAddUser_Click" Margin="10" Width="150" Height="30"/>
<DataGrid x:Name="dgNews" Grid.Row="1" Margin="10" AutoGenerateColumns="True"/>
</Grid>
public partial class NewsWindow : Window { public NewsWindow() { InitializeComponent(); LoadNews(); }
private async void LoadNews()
{
try
{
using (HttpClient client = new HttpClient())
{
string json = await client.GetStringAsync("http://localhost:3000/api/Home/GetPokupki");
var pokupkiList = new List<PokupkaItem>();
using (JsonDocument doc = JsonDocument.Parse(json))
{
foreach (var item in doc.RootElement.EnumerateArray())
{
var pokupka = new PokupkaItem
{
Id = item.GetProperty("id").GetInt32(),
UserName = item.GetProperty("userName").GetString(),
TovarName = item.GetProperty("tovarName").GetString()
};
pokupkiList.Add(pokupka);
}
}
dgNews.ItemsSource = pokupkiList;
}
}
catch (Exception ex)
{
MessageBox.Show("Ошибка: " + ex.Message);
}
}
private void BtnAddUser_Click(object sender, RoutedEventArgs e)
{
var addUserWindow = new AddUserWindow();
addUserWindow.ShowDialog();
LoadNews();
}
public class PokupkaItem
{
public int Id { get; set; }
public string UserName { get; set; }
public string TovarName { get; set; }
}
}
ADDUSERWINDOW------------------------------------
<Grid Margin="10">
<StackPanel>
<TextBlock Text="ID:" Margin="0,0,0,5"/>
<TextBox x:Name="txtId" Margin="0,0,0,10"/>
<TextBlock Text="Имя:" Margin="0,0,0,5"/>
<TextBox x:Name="txtName" Margin="0,0,0,20"/>
<Button x:Name="btnAdd" Content="Добавить"
Click="BtnAdd_Click" Height="30"/>
</StackPanel>
</Grid>
public partial class AddUserWindow : Window { public AddUserWindow() { InitializeComponent(); }
private async void BtnAdd_Click(object sender, RoutedEventArgs e)
{
try
{
if (string.IsNullOrEmpty(txtId.Text) || string.IsNullOrEmpty(txtName.Text))
{
MessageBox.Show("Заполните все поля");
return;
}
var user = new
{
id = int.Parse(txtId.Text),
name = txtName.Text
};
using (HttpClient client = new HttpClient())
{
string json = JsonSerializer.Serialize(user);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("http://localhost:3000/api/Home/AddUser", content);
if (response.IsSuccessStatusCode)
{
MessageBox.Show("Пользователь добавлен!");
this.Close();
}
else
{
MessageBox.Show("Ошибка: " + await response.Content.ReadAsStringAsync());
}
}
}
catch (FormatException)
{
MessageBox.Show("ID должен быть числом");
}
catch (Exception ex)
{
MessageBox.Show("Ошибка: " + ex.Message);
}
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|