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>
95 lines
4.1 KiB
C#
95 lines
4.1 KiB
C#
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);
|
||
}
|
||
}
|
||
}
|