using Remontor.Connector;
using Remontor.Seacher;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Remontor.Setting
{
    public partial class SettingSCCMControl : UserControl
    {
        public SettingSCCMControl()
        {
            InitializeComponent();
            UpdateSetting();
            SMetodForm.EnableContextMenu(ib_server);
            SMetodForm.EnableContextMenu(ib_dataBase);

        }

        public void UpdateSetting()
        {
            if (SGlobalSetting.settingSCCM != null)
            {
                ib_server.Text = SGlobalSetting.settingSCCM.server;
                ib_dataBase.Text = SGlobalSetting.settingSCCM.dataBase;
                cb_on.Checked = SGlobalSetting.settingSCCM.on;

                SearchControl(cb_on.Checked);
            }
        }
        
        private void SearchControl(bool enable)
        {
            ib_server.Enabled = enable;
            ib_dataBase.Enabled = enable;
          
            bt_checkConnect.Enabled = enable;
          
        }

        private void cb_on_CheckedChanged(object sender, EventArgs e)
        {
            SearchControl(cb_on.Checked);
        }

        private void cb_windowsAuth_CheckedChanged(object sender, EventArgs e)
        {
          
        }

        public bool edited()
        {
            return (SGlobalSetting.settingSCCM.server != ib_server.Text ||
            SGlobalSetting.settingSCCM.dataBase != ib_dataBase.Text ||
            SGlobalSetting.settingSCCM.on != cb_on.Checked);

        }

        public void Save()
        {
            SGlobalSetting.settingSCCM.server = ib_server.Text;
            SGlobalSetting.settingSCCM.dataBase = ib_dataBase.Text;
            SGlobalSetting.settingSCCM.on = cb_on.Checked;


        }

        private void bt_checkConnect_Click(object sender, EventArgs e)
        {
            SConnector.FormMain.ShowOn = true;
            SeachSCCM SeacherCheck = new SeachSCCM(true);
            MessageBox.Show(SeacherCheck.CheckConnect(ib_server.Text,ib_dataBase.Text));
            SConnector.FormMain.ShowOn = false;
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }
    }
}

