Advertisement
Pioneer221

Untitled

Feb 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9.  
  10. using ustawienia = Integrator.Properties.Settings;
  11.  
  12. namespace Integrator
  13. {
  14.     partial class Ustawienia : Form
  15.     {
  16.         private Class_Data _polaczenie = null;
  17.         private string _flaga;
  18.  
  19.         public Ustawienia(String flaga)
  20.         {
  21.             _flaga = flaga;
  22.             InitializeComponent();
  23.         }
  24.         //otwiernie okna ustawienia dla cel lub zrodlo
  25.         private void Ustawienia_Load(object sender, EventArgs e)
  26.         {
  27.             try
  28.             {
  29.                 switch (this._flaga)
  30.                 {
  31.                     case "zrodlo":
  32.                         bt_zapisz.Enabled = false;
  33.                         tb_host.Text = ustawienia.Default.zrodlo_host;
  34.                         tb_port.Text = ustawienia.Default.zrodlo_port;
  35.                         tb_baza.Text = ustawienia.Default.zrodlo_baza;
  36.                         tb_login.Text = ustawienia.Default.zrodlo_login;
  37.                         tb_haslo.Text = ustawienia.Default.zrodlo_haslo;
  38.                         break;
  39.  
  40.                     case "cel":
  41.                         bt_zapisz.Enabled = false;
  42.                         tb_host.Text = ustawienia.Default.cel_host;
  43.                         tb_port.Text = ustawienia.Default.cel_port;
  44.                         tb_baza.Text = ustawienia.Default.cel_baza;
  45.                         tb_login.Text = ustawienia.Default.cel_login;
  46.                         tb_haslo.Text = ustawienia.Default.cel_haslo;
  47.                         break;
  48.                 }
  49.             }
  50.             catch(Exception ex)
  51.             {
  52.                 MessageBox.Show(ex.Message, "WINDOW OPENING ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  53.             }
  54.         }
  55.         //ustawianie portu
  56.         private void tb_port_TextChanged(object sender, EventArgs e)
  57.         {
  58.             try
  59.             {
  60.                 if (tb_port.Text != "")
  61.                 {
  62.                     if (!char.IsDigit(tb_port.Text, tb_port.Text.Length - 1))
  63.                     {
  64.                         //tb_port.Text = tb_port.Text.Substring(0, tb_port.Text.Length - 1);
  65.                         tb_port.Text = "";
  66.                         tb_port.Select(tb_port.Text.Length, 0);
  67.                     }
  68.                 }
  69.             }
  70.             catch(Exception ex)
  71.             {
  72.                 MessageBox.Show(ex.Message, "INSERTING DATA ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  73.             }
  74.         }
  75.         //funkcja sprawdzająca połączenie z bazą
  76.         private void bt_test_Click(object sender, EventArgs e)
  77.         {
  78.             try
  79.             {
  80.                 _polaczenie = new Class_Data();
  81.  
  82.                 _polaczenie.Connect_MsSQL(tb_host.Text, tb_port.Text, tb_baza.Text, tb_login.Text, tb_haslo.Text);
  83.  
  84.                 if (_polaczenie.error_db != null)
  85.                 {
  86.                     bt_zapisz.Enabled = false;
  87.                     throw new Exception(this._polaczenie.error_db);
  88.                 }
  89.                 else
  90.                 {
  91.                     MessageBox.Show("TEST CONNETION CORRECT!", "CONNECTION TEST", MessageBoxButtons.OK, MessageBoxIcon.Information);
  92.  
  93.                     bt_zapisz.Enabled = true;
  94.  
  95.                     if (_polaczenie.isOpen_MsSQL())
  96.                     {
  97.                         _polaczenie.Close_MsSQL();
  98.                     }
  99.                 }
  100.             }
  101.             catch (Exception ex)
  102.             {
  103.                 MessageBox.Show(ex.Message, "CONNECTION TEST ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
  104.             }
  105.         }
  106.         //funkcja zapisująca dane w zrodlo lub cel
  107.         private void bt_zapisz_Click(object sender, EventArgs e)
  108.         {
  109.             try
  110.             {
  111.                 switch (_flaga)
  112.                 {
  113.                     case "zrodlo":
  114.                         ustawienia.Default.zrodlo_host = tb_host.Text;
  115.                         ustawienia.Default.zrodlo_port = tb_port.Text;
  116.                         ustawienia.Default.zrodlo_baza = tb_baza.Text;
  117.                         ustawienia.Default.zrodlo_login = tb_login.Text;
  118.                         ustawienia.Default.zrodlo_haslo = tb_haslo.Text;
  119.                         ustawienia.Default.Save();
  120.                         Close();
  121.                         break;
  122.  
  123.                     case "cel":
  124.                         ustawienia.Default.cel_host = tb_host.Text;
  125.                         ustawienia.Default.cel_port = tb_port.Text;
  126.                         ustawienia.Default.cel_baza = tb_baza.Text;
  127.                         ustawienia.Default.cel_login = tb_login.Text;
  128.                         ustawienia.Default.cel_haslo = tb_haslo.Text;
  129.                         ustawienia.Default.Save();
  130.                         Close();
  131.                         break;
  132.                 }
  133.  
  134.             }
  135.             catch (Exception ex)
  136.             {
  137.                 MessageBox.Show(ex.Message, "SETTINGS SAVE ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  138.             }
  139.         }
  140.         //zamkniecie okna ustawienia
  141.         private void bt_anuluj_Click(object sender, EventArgs e)
  142.         {
  143.             try
  144.             {
  145.                 Close();
  146.             }
  147.             catch (Exception ex)
  148.             {
  149.                 MessageBox.Show(ex.Message, "CANCELLING ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  150.             }
  151.         }
  152.     }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement