/
DaNN26
/
SQLProvider
Обзор
Документация
Войти
/
DaNN26
/
SQLProvider
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
AppHelper.cs
75 строк
2 KB
DaNN
Добавьте файлы проекта.
27 май 2026, 12:50
27 май 2026, 12:50
4fe37b9
Код
Авторство
О чём код?
using System; using System.Drawing; using System.IO; using System.Windows.Forms; namespace Demo { internal static class AppHelper { private const string PlaceholderImage = @"Images\picture.png"; private const string ApplicationIcon = @"Images\AppIcon.ico"; public static string Escape(string text) { return (text ?? "").Replace("'", "''"); } public static string SqlText(string text) { if (string.IsNullOrWhiteSpace(text)) { return "NULL"; } return "N'" + Escape(text.Trim()) + "'"; } public static string GetFilePath(string relativePath) { var path = string.IsNullOrWhiteSpace(relativePath) ? PlaceholderImage : relativePath; return Path.IsPathRooted(path) ? path : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path); } public static Image LoadImage(string relativePath) { var path = GetFilePath(relativePath); if (!File.Exists(path)) { path = GetFilePath(PlaceholderImage); } using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { using (var image = Image.FromStream(stream)) { return new Bitmap(image); } } } public static void SetAppIcon(Form form) { var iconPath = GetFilePath(ApplicationIcon); if (!File.Exists(iconPath)) { return; } try { form.Icon = new Icon(iconPath); } catch { } } public static void ShowError(string message) { MessageBox.Show(message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }