elfisa-pharmacy/src/ElectronicPharmacy/HelpForms/HF_Registration.cs
Magomed fd5bd18c66 Add per-pharmacy carts and client-side summed discount pricing.
Apply available buyer/price-list/region discounts to summary.price on download, keep consignee carts separate, and harden SQLite startup/migrations.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-30 14:07:47 +03:00

95 lines
4.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Net.Http;
using System.Windows.Forms;
using Elfisa.UI.Helpers;
using Elfisa.UI.Theming;
using Электроннаяармация.Classes;
using Электроннаяармация.Properties;
namespace Электроннаяармация.HelpForms
{
public partial class HF_Registration : Form
{
public HF_Registration()
{
InitializeComponent();
Shown += (_, __) => WindowChromeHelper.ApplyTitleBarTheme(this, ThemeManager.Colors);
}
private void btnCloseThis_Click(object sender, EventArgs e)
{
Close();
}
private async void btnConfirmRegistration_Click(object sender, EventArgs e)
{
btnConfirmRegistration.Enabled = false;
btnCloseThis.Enabled = false;
UseWaitCursor = true;
string strLogin = (txtLogin.Text ?? string.Empty).Trim();
string strPassword = txtPassword.Text ?? string.Empty;
if (strLogin.Length > 0 && strPassword.Length > 0)
{
string apiUrl = string.IsNullOrWhiteSpace(Settings.Default.ApiBaseUrl)
? AppConfig.DefaultApiBaseUrl
: Settings.Default.ApiBaseUrl;
LoginRequest loginRequest = new LoginRequest();
loginRequest.Username = strLogin;
loginRequest.Password = strPassword.Trim();
var client = new ApiClient(AppConfig.NormalizeApiBaseUrl(apiUrl));
AppDebugLog.Info("Auth", $"Попытка авторизации. Сервер={client.BaseUrl}, login={loginRequest.Username}");
try
{
string token = await client.LoginAsync(loginRequest.Username, loginRequest.Password);
// Сохраняем только логин и токен; пароль в настройках не храним.
Settings.Default.stringLogin = strLogin;
Settings.Default.stringPassword = string.Empty;
Settings.Default.stringToken = token;
Settings.Default.ApiBaseUrl = client.BaseUrl;
Settings.Default.Save();
AppDebugLog.Info("Auth", $"Авторизация успешна. token={AppDebugLog.MaskToken(token)}");
ToastNotification.ShowSuccess("Авторизация успешно выполнена");
DialogResult = DialogResult.OK;
Close();
return;
}
catch (UnauthorizedAccessException ex)
{
AppDebugLog.Error("Auth", "Ошибка авторизации", ex);
ToastNotification.ShowError($"Ошибка авторизации: {ex.Message}");
}
catch (HttpRequestException ex)
{
AppDebugLog.Error("Auth", "Ошибка сети при авторизации", ex);
ToastNotification.ShowError($"Ошибка сети: {ex.Message}");
}
}
else
{
UiDialogs.ShowError("Есть незаполненные данные. Регистрация программы не пройдена", "Ошибка ввода", this);
}
btnConfirmRegistration.Enabled = true;
btnCloseThis.Enabled = true;
UseWaitCursor = false;
}
private void HF_Registration_Load(object sender, EventArgs e)
{
UiThemeHelper.ApplyToControlTree(this);
WindowChromeHelper.ApplyDialogChrome(this, panel1, label3);
// Только последний успешный логин; пароль пользователь вводит каждый раз.
txtLogin.Text = Settings.Default.stringLogin ?? string.Empty;
txtPassword.Text = string.Empty;
checkTokenGained.Checked = !string.IsNullOrWhiteSpace(Settings.Default.stringToken);
}
}
}