Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Linq;
- using System.Reflection;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using ustawienia = Integrator.Properties.Settings;
- namespace Integrator
- {
- partial class Ustawienia : Form
- {
- private Class_Data _polaczenie = null;
- private string _flaga;
- public Ustawienia(String flaga)
- {
- _flaga = flaga;
- InitializeComponent();
- }
- //otwiernie okna ustawienia dla cel lub zrodlo
- private void Ustawienia_Load(object sender, EventArgs e)
- {
- try
- {
- switch (this._flaga)
- {
- case "zrodlo":
- bt_zapisz.Enabled = false;
- tb_host.Text = ustawienia.Default.zrodlo_host;
- tb_port.Text = ustawienia.Default.zrodlo_port;
- tb_baza.Text = ustawienia.Default.zrodlo_baza;
- tb_login.Text = ustawienia.Default.zrodlo_login;
- tb_haslo.Text = ustawienia.Default.zrodlo_haslo;
- break;
- case "cel":
- bt_zapisz.Enabled = false;
- tb_host.Text = ustawienia.Default.cel_host;
- tb_port.Text = ustawienia.Default.cel_port;
- tb_baza.Text = ustawienia.Default.cel_baza;
- tb_login.Text = ustawienia.Default.cel_login;
- tb_haslo.Text = ustawienia.Default.cel_haslo;
- break;
- }
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message, "WINDOW OPENING ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- //ustawianie portu
- private void tb_port_TextChanged(object sender, EventArgs e)
- {
- try
- {
- if (tb_port.Text != "")
- {
- if (!char.IsDigit(tb_port.Text, tb_port.Text.Length - 1))
- {
- //tb_port.Text = tb_port.Text.Substring(0, tb_port.Text.Length - 1);
- tb_port.Text = "";
- tb_port.Select(tb_port.Text.Length, 0);
- }
- }
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message, "INSERTING DATA ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- //funkcja sprawdzająca połączenie z bazą
- private void bt_test_Click(object sender, EventArgs e)
- {
- try
- {
- _polaczenie = new Class_Data();
- _polaczenie.Connect_MsSQL(tb_host.Text, tb_port.Text, tb_baza.Text, tb_login.Text, tb_haslo.Text);
- if (_polaczenie.error_db != null)
- {
- bt_zapisz.Enabled = false;
- throw new Exception(this._polaczenie.error_db);
- }
- else
- {
- MessageBox.Show("TEST CONNETION CORRECT!", "CONNECTION TEST", MessageBoxButtons.OK, MessageBoxIcon.Information);
- bt_zapisz.Enabled = true;
- if (_polaczenie.isOpen_MsSQL())
- {
- _polaczenie.Close_MsSQL();
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "CONNECTION TEST ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- //funkcja zapisująca dane w zrodlo lub cel
- private void bt_zapisz_Click(object sender, EventArgs e)
- {
- try
- {
- switch (_flaga)
- {
- case "zrodlo":
- ustawienia.Default.zrodlo_host = tb_host.Text;
- ustawienia.Default.zrodlo_port = tb_port.Text;
- ustawienia.Default.zrodlo_baza = tb_baza.Text;
- ustawienia.Default.zrodlo_login = tb_login.Text;
- ustawienia.Default.zrodlo_haslo = tb_haslo.Text;
- ustawienia.Default.Save();
- Close();
- break;
- case "cel":
- ustawienia.Default.cel_host = tb_host.Text;
- ustawienia.Default.cel_port = tb_port.Text;
- ustawienia.Default.cel_baza = tb_baza.Text;
- ustawienia.Default.cel_login = tb_login.Text;
- ustawienia.Default.cel_haslo = tb_haslo.Text;
- ustawienia.Default.Save();
- Close();
- break;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "SETTINGS SAVE ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- //zamkniecie okna ustawienia
- private void bt_anuluj_Click(object sender, EventArgs e)
- {
- try
- {
- Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "CANCELLING ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement