/
Ermoha
/
SqlDataDrivers
Обзор
Документация
Войти
/
Ermoha
/
SqlDataDrivers
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
AppHelper.cs
89 строк
2 KB
ermoh
Добавьте файлы проекта.
26 май 2026, 22:28
26 май 2026, 22:28
b563253
Код
Авторство
О чём код?
using System; using System.Drawing; using System.IO; using System.Windows.Forms; namespace Demo { internal static class AppHelper { public static string Escape(string text) { if (text == null) { return ""; } 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) { if (string.IsNullOrWhiteSpace(relativePath)) { relativePath = @"Images\picture.png"; } if (Path.IsPathRooted(relativePath)) { return relativePath; } return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, relativePath); } public static Image LoadImage(string relativePath) { string path = GetFilePath(relativePath); if (!File.Exists(path)) { path = GetFilePath(@"Images\picture.png"); } using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { using (Image image = Image.FromStream(stream)) { return new Bitmap(image); } } } public static void SetAppIcon(Form form) { string iconPath = GetFilePath(@"Images\AppIcon.ico"); if (File.Exists(iconPath)) { try { form.Icon = new Icon(iconPath); } catch { } } } public static void ShowError(string message) { MessageBox.Show(message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } public static void ShowInfo(string message) { MessageBox.Show(message, "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }