Users can choose the export directory in auth settings; right-click on an invoice saves a UTF-8 CSV into that folder. Co-authored-by: Cursor <cursoragent@cursor.com>
124 lines
3.8 KiB
C#
124 lines
3.8 KiB
C#
using System;
|
||
using System.IO;
|
||
using Электронная_Фармация.Properties;
|
||
|
||
namespace Электронная_Фармация.Classes
|
||
{
|
||
/// <summary>
|
||
/// Shared application paths and API settings.
|
||
/// </summary>
|
||
public static class AppConfig
|
||
{
|
||
public const string DefaultApiBaseUrl = "https://24pharmdata.ru";
|
||
private const string LegacyApiBaseUrl = "http://195.34.241.84:9988";
|
||
private const string ApiBaseUrlEnvVar = "ELF_API_BASE_URL";
|
||
|
||
/// <summary>
|
||
/// Replaces known dead API URLs in saved user settings.
|
||
/// </summary>
|
||
public static void MigrateLegacySettings()
|
||
{
|
||
var current = Settings.Default.ApiBaseUrl;
|
||
if (string.IsNullOrWhiteSpace(current))
|
||
{
|
||
return;
|
||
}
|
||
|
||
var normalized = NormalizeApiBaseUrl(current);
|
||
if (string.Equals(normalized, LegacyApiBaseUrl, StringComparison.OrdinalIgnoreCase) ||
|
||
string.Equals(normalized, "http://195.34.241.84:9988", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
Settings.Default.ApiBaseUrl = DefaultApiBaseUrl;
|
||
Settings.Default.stringToken = string.Empty;
|
||
Settings.Default.Save();
|
||
AppDebugLog.Info("AppConfig", $"ApiBaseUrl мигрирован: {LegacyApiBaseUrl} -> {DefaultApiBaseUrl}");
|
||
}
|
||
}
|
||
|
||
public static string ApiBaseUrl
|
||
{
|
||
get
|
||
{
|
||
var fromSettings = Settings.Default.ApiBaseUrl;
|
||
if (!string.IsNullOrWhiteSpace(fromSettings))
|
||
{
|
||
return NormalizeApiBaseUrl(fromSettings);
|
||
}
|
||
|
||
var fromEnv = Environment.GetEnvironmentVariable(ApiBaseUrlEnvVar);
|
||
if (!string.IsNullOrWhiteSpace(fromEnv))
|
||
{
|
||
return NormalizeApiBaseUrl(fromEnv);
|
||
}
|
||
|
||
return DefaultApiBaseUrl;
|
||
}
|
||
}
|
||
|
||
public static string NormalizeApiBaseUrl(string url)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(url))
|
||
{
|
||
return DefaultApiBaseUrl;
|
||
}
|
||
|
||
url = url.Trim().TrimEnd('/');
|
||
if (!url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
|
||
!url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
url = "http://" + url;
|
||
}
|
||
|
||
return url;
|
||
}
|
||
|
||
public static string SqliteDbPath
|
||
{
|
||
get
|
||
{
|
||
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
|
||
var root = Path.Combine(baseDir, "efClient.db");
|
||
var data = Path.Combine(baseDir, "Data", "efClient.db");
|
||
if (File.Exists(root))
|
||
{
|
||
return root;
|
||
}
|
||
|
||
if (File.Exists(data))
|
||
{
|
||
return data;
|
||
}
|
||
|
||
return root;
|
||
}
|
||
}
|
||
|
||
public static string SqliteConnectionString
|
||
{
|
||
get { return $"Data Source={SqliteDbPath};Version=3;New=False;"; }
|
||
}
|
||
|
||
public static string LocationId
|
||
{
|
||
get { return Settings.Default.LocationId ?? string.Empty; }
|
||
}
|
||
|
||
public static void SetLocationId(string locationId)
|
||
{
|
||
Settings.Default.LocationId = (locationId ?? string.Empty).Trim();
|
||
Settings.Default.Save();
|
||
}
|
||
|
||
public static string InvoiceExportPath
|
||
{
|
||
get { return Settings.Default.InvoiceExportPath ?? string.Empty; }
|
||
}
|
||
|
||
public static void SetInvoiceExportPath(string path)
|
||
{
|
||
Settings.Default.InvoiceExportPath = (path ?? string.Empty).Trim();
|
||
Settings.Default.Save();
|
||
}
|
||
}
|
||
}
|