using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.IO; using System.Net; using System.Media; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Web.Script.Serialization; using System.Windows.Forms; using Microsoft.Win32; namespace CozsanBildirim { public class Config { public string BaseUrl { get; set; } public string Token { get; set; } public string Username { get; set; } public bool AutoStart { get; set; } public string NotificationSound { get; set; } } public class ApiResponse { public bool ok { get; set; } public string error { get; set; } public string token { get; set; } public string username { get; set; } public List notifications { get; set; } public int unread_count { get; set; } } public class NotificationItem { public int id { get; set; } public string title { get; set; } public string message { get; set; } public string url { get; set; } public string created_at { get; set; } } static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new TrayApplicationContext()); } } public class TrayApplicationContext : ApplicationContext { private readonly NotifyIcon tray; private readonly System.Windows.Forms.Timer timer; private readonly JavaScriptSerializer json = new JavaScriptSerializer(); private Config config; private string lastUrl; private int lastNotificationId; private bool busy; private ToolStripMenuItem statusItem; private ToolStripMenuItem unreadItem; private NotificationStackForm notificationForm; private DateTime lastErrorNotice = DateTime.MinValue; private readonly Control uiInvoker; private readonly Icon baseTrayIcon; private Icon badgeTrayIcon; private readonly HashSet knownNotificationIds = new HashSet(); private bool initialPollCompleted; [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern bool DestroyIcon(IntPtr handle); private static string AppDir { get { string dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CozsanMetal", "Bildirim"); Directory.CreateDirectory(dir); return dir; } } private static string ConfigPath { get { return Path.Combine(AppDir, "config.json"); } } public TrayApplicationContext() { config = LoadConfig(); uiInvoker = new Control(); uiInvoker.CreateControl(); tray = new NotifyIcon(); baseTrayIcon = (Icon)SystemIcons.Information.Clone(); tray.Icon = baseTrayIcon; tray.Text = "Çözsan Metal Bildirim"; tray.Visible = true; tray.BalloonTipClicked += delegate { OpenLastNotification(); }; tray.MouseClick += delegate(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) return; RunOnUi(delegate { if (notificationForm == null || notificationForm.IsDisposed) { notificationForm = new NotificationStackForm(); notificationForm.NotificationClicked += delegate(object s, NotificationClickedEventArgs args) { OpenNotification(args.Item); }; } notificationForm.ShowNearTray(false); }); }; tray.DoubleClick += delegate { RunOnUi(delegate { if (notificationForm != null && !notificationForm.IsDisposed) notificationForm.ShowNearTray(false); }); }; var menu = new ContextMenuStrip(); menu.Items.Add("Sistemi Aç", null, delegate { OpenSystem(); }); menu.Items.Add("Bildirimleri Göster", null, delegate { RunOnUi(delegate { if (notificationForm != null && !notificationForm.IsDisposed) notificationForm.ShowNearTray(false); }); }); menu.Items.Add("Ayarlar", null, delegate { ShowSettings(); }); menu.Items.Add("Şimdi Kontrol Et", null, delegate { PollAsync(true); }); menu.Items.Add("Test Bildirimi", null, delegate { ShowTestNotification(); }); unreadItem = new ToolStripMenuItem("Okunmamış: 0"); unreadItem.Enabled = false; menu.Items.Add(unreadItem); statusItem = new ToolStripMenuItem("Durum: Başlatılıyor"); statusItem.Enabled = false; menu.Items.Add(statusItem); menu.Items.Add(new ToolStripSeparator()); menu.Items.Add("Çıkış", null, delegate { ExitApp(); }); tray.ContextMenuStrip = menu; timer = new System.Windows.Forms.Timer(); timer.Interval = 3000; timer.Tick += delegate { PollAsync(false); }; timer.Start(); if (string.IsNullOrWhiteSpace(config.BaseUrl) || string.IsNullOrWhiteSpace(config.Token)) ShowSettings(); else PollAsync(false); } private Config LoadConfig() { try { if (File.Exists(ConfigPath)) return json.Deserialize(File.ReadAllText(ConfigPath, Encoding.UTF8)) ?? new Config(); } catch { } return new Config { BaseUrl = "http://192.168.1.10/cozsan-metal", AutoStart = true, NotificationSound = "Asterisk" }; } private void SaveConfig() { File.WriteAllText(ConfigPath, json.Serialize(config), Encoding.UTF8); SetAutoStart(config.AutoStart); } private void SetAutoStart(bool enabled) { try { using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true)) { if (enabled) key.SetValue("CozsanMetalBildirim", "\"" + Application.ExecutablePath + "\""); else key.DeleteValue("CozsanMetalBildirim", false); } } catch { } } private string ApiUrl(string action) { return config.BaseUrl.TrimEnd('/') + "/api_windows_notifications.php?action=" + Uri.EscapeDataString(action); } private void ShowSettings() { using (var form = new SettingsForm(config)) { if (form.ShowDialog() != DialogResult.OK) return; config.BaseUrl = form.BaseUrl.Trim().TrimEnd('/'); config.AutoStart = form.AutoStart; config.NotificationSound = form.NotificationSound; if (!string.IsNullOrWhiteSpace(form.Password)) { try { var values = new System.Collections.Specialized.NameValueCollection(); values["action"] = "login"; values["username"] = form.Username.Trim(); values["password"] = form.Password; values["device"] = Environment.MachineName; using (var wc = new WebClient()) { wc.Encoding = Encoding.UTF8; byte[] response = wc.UploadValues(config.BaseUrl + "/api_windows_notifications.php", "POST", values); var result = json.Deserialize(Encoding.UTF8.GetString(response)); if (result == null || !result.ok || string.IsNullOrWhiteSpace(result.token)) throw new Exception(result != null ? result.error : "Sunucudan geçersiz cevap alındı."); config.Token = result.token; config.Username = result.username; } } catch (WebException ex) { MessageBox.Show(ReadWebError(ex), "Bağlantı Hatası", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (Exception ex) { MessageBox.Show(ex.Message, "Giriş Hatası", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else if (string.IsNullOrWhiteSpace(config.Token)) { MessageBox.Show("İlk kurulumda kullanıcı adı ve şifre gereklidir.", "Eksik Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } SaveConfig(); tray.Text = "Çözsan Metal - " + (config.Username ?? "Bildirim"); PollAsync(true); } } private void PollAsync(bool manual) { if (busy || string.IsNullOrWhiteSpace(config.Token) || string.IsNullOrWhiteSpace(config.BaseUrl)) return; busy = true; ThreadPool.QueueUserWorkItem(delegate { try { using (var wc = new WebClient()) { wc.Encoding = Encoding.UTF8; wc.Headers["X-Notification-Token"] = config.Token; string raw = wc.DownloadString(ApiUrl("poll") + "&limit=100&token=" + Uri.EscapeDataString(config.Token)); var result = json.Deserialize(raw); if (result == null || !result.ok) throw new Exception(result != null ? result.error : "Sunucudan geçersiz cevap alındı."); SetStatus("Durum: Bağlı - " + DateTime.Now.ToString("HH:mm:ss")); UpdateUnreadCount(result.unread_count); var unreadNotifications = result.notifications ?? new List(); int newCount = 0; lock (knownNotificationIds) { var currentUnreadIds = new HashSet(); foreach (var item in unreadNotifications) { if (item == null) continue; currentUnreadIds.Add(item.id); if (knownNotificationIds.Add(item.id)) newCount++; } // Remove IDs that are no longer unread, so browser-read items disappear on the next poll. knownNotificationIds.RemoveWhere(id => !currentUnreadIds.Contains(id)); } // İlk açılışta bilgisayar kapalıyken birikmiş okunmamış bildirimler varsa // pencereyi göster ve sesi bir kez çal. Sonraki sorgularda yalnızca yeni // bildirimler geldiğinde tekrar uyarı verilir. bool shouldNotify = newCount > 0 && (initialPollCompleted || unreadNotifications.Count > 0); SyncNotificationBatch(unreadNotifications, result.unread_count, shouldNotify); if (shouldNotify) PlayNotificationSound(); else if (manual && unreadNotifications.Count == 0) ShowInfo("Kontrol tamamlandı", "Yeni bildirim bulunamadı."); initialPollCompleted = true; } } catch (WebException ex) { string detail = ReadWebError(ex); SetStatus("Durum: Bağlantı hatası"); if (ex.Response is HttpWebResponse && ((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Unauthorized) { config.Token = ""; SaveConfig(); ShowError("Oturum geçersiz", "Ayarlar bölümünden tekrar giriş yapın."); } else if (manual || (DateTime.Now - lastErrorNotice).TotalMinutes >= 5) { lastErrorNotice = DateTime.Now; ShowError("Sunucu bağlantı hatası", detail); } } catch (Exception ex) { SetStatus("Durum: Hata"); if (manual || (DateTime.Now - lastErrorNotice).TotalMinutes >= 5) { lastErrorNotice = DateTime.Now; ShowError("Bildirim kontrol hatası", ex.Message); } } finally { busy = false; } }); } private void RunOnUi(Action action) { if (action == null || uiInvoker == null || uiInvoker.IsDisposed) return; try { if (uiInvoker.InvokeRequired) uiInvoker.BeginInvoke((MethodInvoker)delegate { action(); }); else action(); } catch { } } private void SetStatus(string text) { RunOnUi(delegate { if (statusItem != null) statusItem.Text = text; }); } private void ShowInfo(string title, string message) { tray.BalloonTipTitle = title; tray.BalloonTipText = message; tray.BalloonTipIcon = ToolTipIcon.Info; tray.ShowBalloonTip(6000); } private void ShowError(string title, string message) { tray.BalloonTipTitle = title; tray.BalloonTipText = string.IsNullOrWhiteSpace(message) ? "Bilinmeyen hata" : message; tray.BalloonTipIcon = ToolTipIcon.Error; tray.ShowBalloonTip(9000); } private void ShowTestNotification() { ShowInfo("Çözsan Metal Test", "Windows bildirim programı çalışıyor."); PlayNotificationSound(); } private void UpdateUnreadCount(int count) { RunOnUi(delegate { count = Math.Max(0, count); if (unreadItem != null) unreadItem.Text = "Okunmamış: " + count; string user = string.IsNullOrWhiteSpace(config.Username) ? "Bildirim" : config.Username; tray.Text = ("Çözsan Metal - " + user + " | Okunmamış: " + count); if (tray.Text.Length > 63) tray.Text = tray.Text.Substring(0, 63); SetTrayBadge(count); if (notificationForm != null && !notificationForm.IsDisposed) notificationForm.SetUnreadCount(count); }); } private void PlayNotificationSound() { RunOnUi(delegate { try { string sound = string.IsNullOrWhiteSpace(config.NotificationSound) ? "Asterisk" : config.NotificationSound; switch (sound) { case "Exclamation": SystemSounds.Exclamation.Play(); break; case "Hand": SystemSounds.Hand.Play(); break; case "Question": SystemSounds.Question.Play(); break; case "Beep": SystemSounds.Beep.Play(); break; case "Double Beep": Console.Beep(1050, 130); Thread.Sleep(70); Console.Beep(1250, 160); break; case "Soft Chime": Console.Beep(880, 110); Thread.Sleep(45); Console.Beep(1175, 140); break; case "Triple Chime": Console.Beep(740, 100); Thread.Sleep(45); Console.Beep(988, 110); Thread.Sleep(45); Console.Beep(1319, 150); break; case "Rising": Console.Beep(650, 90); Thread.Sleep(35); Console.Beep(850, 90); Thread.Sleep(35); Console.Beep(1100, 130); break; case "Gentle": Console.Beep(784, 120); Thread.Sleep(80); Console.Beep(988, 160); break; case "Urgent": Console.Beep(1200, 120); Thread.Sleep(55); Console.Beep(1200, 120); Thread.Sleep(55); Console.Beep(1450, 180); break; case "Doorbell": Console.Beep(988, 180); Thread.Sleep(100); Console.Beep(659, 260); break; case "Success": Console.Beep(523, 90); Thread.Sleep(35); Console.Beep(659, 90); Thread.Sleep(35); Console.Beep(784, 160); break; case "Short Pulse": Console.Beep(1000, 80); Thread.Sleep(45); Console.Beep(1000, 80); break; case "Low Alert": Console.Beep(520, 180); Thread.Sleep(70); Console.Beep(620, 180); break; case "Silent": break; default: SystemSounds.Asterisk.Play(); break; } } catch { try { Console.Beep(1000, 180); } catch { } } }); } private void SetTrayBadge(int count) { try { if (badgeTrayIcon != null) { tray.Icon = baseTrayIcon; badgeTrayIcon.Dispose(); badgeTrayIcon = null; } if (count <= 0) { tray.Icon = baseTrayIcon; return; } using (var bitmap = new Bitmap(32, 32)) using (var graphics = Graphics.FromImage(bitmap)) { graphics.Clear(Color.Transparent); graphics.DrawIcon(baseTrayIcon, new Rectangle(0, 0, 32, 32)); graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; string badgeText = count > 99 ? "99+" : count.ToString(); int badgeSize = badgeText.Length >= 3 ? 20 : 17; int x = 32 - badgeSize; int y = 0; using (var brush = new SolidBrush(Color.FromArgb(220, 35, 45))) graphics.FillEllipse(brush, x, y, badgeSize, badgeSize); using (var pen = new Pen(Color.White, 1.4F)) graphics.DrawEllipse(pen, x, y, badgeSize, badgeSize); using (var font = new Font("Segoe UI", badgeText.Length >= 3 ? 6.2F : 7.5F, FontStyle.Bold, GraphicsUnit.Point)) using (var textBrush = new SolidBrush(Color.White)) { var format = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; graphics.DrawString(badgeText, font, textBrush, new RectangleF(x, y - 0.5F, badgeSize, badgeSize), format); } IntPtr handle = bitmap.GetHicon(); try { using (var temp = Icon.FromHandle(handle)) badgeTrayIcon = (Icon)temp.Clone(); } finally { DestroyIcon(handle); } } tray.Icon = badgeTrayIcon; } catch { tray.Icon = baseTrayIcon; } } private void SyncNotificationBatch(List items, int unreadCount, bool showForNewItems) { RunOnUi(delegate { if (notificationForm == null || notificationForm.IsDisposed) { notificationForm = new NotificationStackForm(); notificationForm.NotificationClicked += delegate(object sender, NotificationClickedEventArgs e) { OpenNotification(e.Item); }; } notificationForm.SetUnreadCount(unreadCount); // Some server responses may temporarily contain the unread count // without returning the rows themselves. Do not erase the visible // cards in that case. A zero unread count is the only authoritative // signal that all notifications were read. if (unreadCount <= 0) { notificationForm.SyncNotifications(new List()); notificationForm.Hide(); return; } if (items != null && items.Count > 0) notificationForm.SyncNotifications(items); if (showForNewItems) notificationForm.ShowNearTray(true); // During the 3-second synchronization, do not call ShowNearTray(false). // That method is reserved for manual opening and intentionally stops // the one-minute auto-hide timer. Keeping the visible window untouched // here allows the automatic popup to close after the full minute. }); } private void OpenNotification(NotificationItem item) { if (item == null) return; string absolute = config.BaseUrl.TrimEnd('/') + "/" + (item.url ?? "index.php").TrimStart('/'); lastUrl = absolute; lastNotificationId = item.id; TryOpen(absolute); MarkNotificationRead(item.id); } private void MarkNotificationRead(int notificationId) { if (notificationId <= 0) return; ThreadPool.QueueUserWorkItem(delegate { try { using (var wc = new WebClient()) { wc.Encoding = Encoding.UTF8; wc.Headers["X-Notification-Token"] = config.Token; wc.DownloadString(ApiUrl("mark_read") + "¬ification_id=" + notificationId + "&token=" + Uri.EscapeDataString(config.Token)); } RunOnUi(delegate { if (notificationForm != null && !notificationForm.IsDisposed) notificationForm.RemoveNotification(notificationId); }); PollAsync(false); } catch { } }); } private void OpenLastNotification() { if (string.IsNullOrWhiteSpace(lastUrl)) { OpenSystem(); return; } int notificationId = lastNotificationId; string url = lastUrl; TryOpen(url); if (notificationId > 0) MarkNotificationRead(notificationId); } private void OpenSystem() { if (!string.IsNullOrWhiteSpace(config.BaseUrl)) TryOpen(config.BaseUrl); } private static void TryOpen(string url) { try { Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); } catch { } } private static string ReadWebError(WebException ex) { try { using (var reader = new StreamReader(ex.Response.GetResponseStream())) return reader.ReadToEnd(); } catch { return ex.Message; } } private void ExitApp() { timer.Stop(); tray.Visible = false; tray.Dispose(); if (badgeTrayIcon != null) badgeTrayIcon.Dispose(); if (baseTrayIcon != null) baseTrayIcon.Dispose(); if (uiInvoker != null && !uiInvoker.IsDisposed) uiInvoker.Dispose(); Application.Exit(); } } public class NotificationClickedEventArgs : EventArgs { public NotificationItem Item { get; private set; } public NotificationClickedEventArgs(NotificationItem item) { Item = item; } } public class NotificationStackForm : Form { private readonly Label countLabel; private readonly FlowLayoutPanel listPanel; private readonly HashSet displayedIds = new HashSet(); private readonly System.Windows.Forms.Timer autoHideTimer; public event EventHandler NotificationClicked; public NotificationStackForm() { Text = "Çözsan Metal Bildirimleri"; Width = 410; Height = 520; FormBorderStyle = FormBorderStyle.FixedToolWindow; ShowInTaskbar = false; TopMost = true; StartPosition = FormStartPosition.Manual; BackColor = Color.FromArgb(245, 248, 252); Font = new Font("Segoe UI", 9F); var header = new Panel { Dock = DockStyle.Top, Height = 64, BackColor = Color.FromArgb(17, 58, 86) }; var title = new Label { Left = 16, Top = 9, Width = 285, Height = 25, Text = "Çözsan Metal Bildirimleri", ForeColor = Color.White, BackColor = Color.Transparent, Font = new Font("Segoe UI", 11F, FontStyle.Bold), AutoEllipsis = true }; countLabel = new Label { Left = 16, Top = 36, Width = 285, Height = 19, Text = "Okunmamış: 0", ForeColor = Color.FromArgb(210, 226, 238), BackColor = Color.Transparent }; var close = new Button { Text = "×", Width = 34, Height = 30, Left = 350, Top = 16, Anchor = AnchorStyles.Top | AnchorStyles.Right, FlatStyle = FlatStyle.Flat, ForeColor = Color.White, BackColor = Color.FromArgb(17, 58, 86), TabStop = false, UseVisualStyleBackColor = false }; close.FlatAppearance.BorderSize = 0; close.Click += delegate { Hide(); }; header.Controls.Add(title); header.Controls.Add(countLabel); header.Controls.Add(close); listPanel = new FlowLayoutPanel { Dock = DockStyle.Fill, FlowDirection = FlowDirection.TopDown, WrapContents = false, AutoScroll = true, Padding = new Padding(10), BackColor = Color.FromArgb(245, 248, 252) }; Controls.Add(listPanel); Controls.Add(header); autoHideTimer = new System.Windows.Forms.Timer(); autoHideTimer.Interval = 60000; autoHideTimer.Tick += delegate { autoHideTimer.Stop(); Hide(); }; FormClosing += delegate(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; Hide(); } }; } public void SetUnreadCount(int count) { countLabel.Text = "Okunmamış: " + Math.Max(0, count); } public void AddNotifications(IEnumerable items) { var ordered = new List(); if (items != null) { foreach (var item in items) { if (item != null) ordered.Add(item); } } ordered.Sort(delegate(NotificationItem a, NotificationItem b) { return b.id.CompareTo(a.id); }); foreach (var item in ordered) { if (displayedIds.Contains(item.id)) continue; displayedIds.Add(item.id); listPanel.Controls.Add(CreateCard(item)); } } public void SyncNotifications(IEnumerable items) { var incoming = new Dictionary(); if (items != null) { foreach (var item in items) { if (item != null) incoming[item.id] = item; } } var toRemove = new List(); foreach (Control c in listPanel.Controls) { var existing = c.Tag as NotificationItem; if (existing == null || !incoming.ContainsKey(existing.id)) toRemove.Add(c); } foreach (var c in toRemove) { var existing = c.Tag as NotificationItem; listPanel.Controls.Remove(c); c.Dispose(); if (existing != null) displayedIds.Remove(existing.id); } AddNotifications(incoming.Values); // Newest notification stays at the top; older notifications move downward. var orderedControls = new List(); foreach (Control c in listPanel.Controls) orderedControls.Add(c); orderedControls.Sort(delegate(Control a, Control b) { var itemA = a.Tag as NotificationItem; var itemB = b.Tag as NotificationItem; int idA = itemA != null ? itemA.id : 0; int idB = itemB != null ? itemB.id : 0; return idB.CompareTo(idA); }); for (int i = 0; i < orderedControls.Count; i++) listPanel.Controls.SetChildIndex(orderedControls[i], i); // Visibility is controlled by the real unread count from the server. // Do not hide here because a short polling response may contain no rows // while unread items still exist. } private Control CreateCard(NotificationItem item) { var card = new Panel { Width = 360, Height = 108, Margin = new Padding(0, 0, 0, 9), BackColor = Color.White, Cursor = Cursors.Hand, Tag = item }; card.Paint += delegate(object sender, PaintEventArgs e) { e.Graphics.DrawRectangle(Pens.LightGray, 0, 0, card.Width - 1, card.Height - 1); }; var title = new Label { Left = 12, Top = 10, Width = 326, Height = 21, Text = string.IsNullOrWhiteSpace(item.title) ? "Çözsan Metal" : item.title, Font = new Font("Segoe UI", 9.5F, FontStyle.Bold), ForeColor = Color.FromArgb(22, 45, 72), AutoEllipsis = true, Cursor = Cursors.Hand, Tag = item }; var message = new Label { Left = 12, Top = 34, Width = 326, Height = 44, Text = string.IsNullOrWhiteSpace(item.message) ? "Yeni bildirim" : item.message, ForeColor = Color.FromArgb(50, 61, 75), AutoEllipsis = true, Cursor = Cursors.Hand, Tag = item }; var date = new Label { Left = 12, Top = 80, Width = 326, Height = 16, Text = item.created_at ?? "", ForeColor = Color.Gray, Font = new Font("Segoe UI", 8F), Cursor = Cursors.Hand, Tag = item }; EventHandler click = delegate(object sender, EventArgs e) { var control = sender as Control; var clicked = control != null ? control.Tag as NotificationItem : item; if (clicked != null && NotificationClicked != null) NotificationClicked(this, new NotificationClickedEventArgs(clicked)); }; card.Click += click; title.Click += click; message.Click += click; date.Click += click; card.Controls.Add(title); card.Controls.Add(message); card.Controls.Add(date); return card; } public void RemoveNotification(int id) { Control target = null; foreach (Control c in listPanel.Controls) { var item = c.Tag as NotificationItem; if (item != null && item.id == id) { target = c; break; } } if (target != null) { listPanel.Controls.Remove(target); target.Dispose(); displayedIds.Remove(id); } if (listPanel.Controls.Count == 0) Hide(); } public void ShowNearTray(bool restartAutoHide) { var area = Screen.PrimaryScreen.WorkingArea; Location = new Point(area.Right - Width - 12, area.Bottom - Height - 12); // Manual opening from the tray must never inherit an old timer. autoHideTimer.Stop(); if (!Visible) Show(); BringToFront(); Activate(); // Automatic popup stays visible for a full minute. // Manual opening stays visible until the user closes it. if (restartAutoHide) autoHideTimer.Start(); } } public class SettingsForm : Form { private TextBox txtUrl; private TextBox txtUser; private TextBox txtPassword; private CheckBox chkAuto; private ComboBox cmbSound; public string BaseUrl { get { return txtUrl.Text; } } public string Username { get { return txtUser.Text; } } public string Password { get { return txtPassword.Text; } } public bool AutoStart { get { return chkAuto.Checked; } } public string NotificationSound { get { return cmbSound.SelectedItem != null ? cmbSound.SelectedItem.ToString() : "Asterisk"; } } public SettingsForm(Config config) { Text = "Çözsan Metal Bildirim Ayarları"; Width = 520; Height = 405; StartPosition = FormStartPosition.CenterScreen; FormBorderStyle = FormBorderStyle.FixedDialog; MaximizeBox = false; MinimizeBox = false; Font = new Font("Segoe UI", 10F); var lblInfo = new Label { Left = 24, Top = 18, Width = 455, Height = 42, Text = "Sunucu adresini ve kendi sistem hesabınızı girin. Şifre yalnızca ilk bağlantıda kullanılır; bilgisayarda saklanmaz." }; Controls.Add(lblInfo); Controls.Add(new Label { Left = 24, Top = 72, Width = 140, Text = "Sistem adresi" }); txtUrl = new TextBox { Left = 165, Top = 68, Width = 310, Text = config.BaseUrl ?? "" }; Controls.Add(txtUrl); Controls.Add(new Label { Left = 24, Top = 112, Width = 140, Text = "Kullanıcı adı" }); txtUser = new TextBox { Left = 165, Top = 108, Width = 310, Text = config.Username ?? "" }; Controls.Add(txtUser); Controls.Add(new Label { Left = 24, Top = 152, Width = 140, Text = "Şifre" }); txtPassword = new TextBox { Left = 165, Top = 148, Width = 310, UseSystemPasswordChar = true }; Controls.Add(txtPassword); Controls.Add(new Label { Left = 24, Top = 192, Width = 140, Text = "Bildirim sesi" }); cmbSound = new ComboBox { Left = 165, Top = 188, Width = 210, DropDownStyle = ComboBoxStyle.DropDownList }; cmbSound.Items.AddRange(new object[] { "Asterisk", "Exclamation", "Hand", "Question", "Beep", "Double Beep", "Soft Chime", "Triple Chime", "Rising", "Gentle", "Urgent", "Doorbell", "Success", "Short Pulse", "Low Alert", "Silent" }); string selectedSound = string.IsNullOrWhiteSpace(config.NotificationSound) ? "Asterisk" : config.NotificationSound; cmbSound.SelectedItem = selectedSound; if (cmbSound.SelectedIndex < 0) cmbSound.SelectedIndex = 0; Controls.Add(cmbSound); var btnSoundTest = new Button { Left = 385, Top = 186, Width = 90, Height = 29, Text = "Sesi Dene" }; btnSoundTest.Click += delegate { try { string sound = cmbSound.SelectedItem != null ? cmbSound.SelectedItem.ToString() : "Asterisk"; switch (sound) { case "Exclamation": SystemSounds.Exclamation.Play(); break; case "Hand": SystemSounds.Hand.Play(); break; case "Question": SystemSounds.Question.Play(); break; case "Beep": SystemSounds.Beep.Play(); break; case "Double Beep": Console.Beep(1050,130); Thread.Sleep(70); Console.Beep(1250,160); break; case "Soft Chime": Console.Beep(880,110); Thread.Sleep(45); Console.Beep(1175,140); break; case "Triple Chime": Console.Beep(740,100); Thread.Sleep(45); Console.Beep(988,110); Thread.Sleep(45); Console.Beep(1319,150); break; case "Rising": Console.Beep(650,90); Thread.Sleep(35); Console.Beep(850,90); Thread.Sleep(35); Console.Beep(1100,130); break; case "Gentle": Console.Beep(784,120); Thread.Sleep(80); Console.Beep(988,160); break; case "Urgent": Console.Beep(1200,120); Thread.Sleep(55); Console.Beep(1200,120); Thread.Sleep(55); Console.Beep(1450,180); break; case "Doorbell": Console.Beep(988,180); Thread.Sleep(100); Console.Beep(659,260); break; case "Success": Console.Beep(523,90); Thread.Sleep(35); Console.Beep(659,90); Thread.Sleep(35); Console.Beep(784,160); break; case "Short Pulse": Console.Beep(1000,80); Thread.Sleep(45); Console.Beep(1000,80); break; case "Low Alert": Console.Beep(520,180); Thread.Sleep(70); Console.Beep(620,180); break; case "Silent": break; default: SystemSounds.Asterisk.Play(); break; } } catch { } }; Controls.Add(btnSoundTest); chkAuto = new CheckBox { Left = 165, Top = 230, Width = 310, Text = "Windows açılışında otomatik çalıştır", Checked = config.AutoStart }; Controls.Add(chkAuto); var intervalInfo = new Label { Left = 165, Top = 260, Width = 310, Height = 22, Text = "Kontrol aralığı: 3 saniye" }; Controls.Add(intervalInfo); var btnSave = new Button { Left = 270, Top = 305, Width = 98, Height = 34, Text = "Kaydet", DialogResult = DialogResult.OK }; var btnCancel = new Button { Left = 377, Top = 305, Width = 98, Height = 34, Text = "İptal", DialogResult = DialogResult.Cancel }; Controls.Add(btnSave); Controls.Add(btnCancel); AcceptButton = btnSave; CancelButton = btnCancel; } } }