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

namespace Remontor.Setting
{
    public partial class settingAppControl : UserControl
    {
        public settingAppControl()
        {
            InitializeComponent();
            UpdateSetting();
            SMetodForm.EnableContextMenu(path);
            SMetodForm.EnableContextMenu(nb_ItemHistorySize);
            SMetodForm.EnableContextMenu(TbUrl);
            SMetodForm.EnableContextMenu(NbItemSizePhoto);
            SMetodForm.EnableContextMenu(NbX);
            SMetodForm.EnableContextMenu(NbY); 
            SMetodForm.EnableContextMenu(NbWidth);
            SMetodForm.EnableContextMenu(NbHeight);
            SMetodForm.EnableContextMenu(TbDlgName);

        }
        public void UpdateSetting()
        {
            if (SGlobalSetting.settingApp != null)
            {
                path.Text = SGlobalSetting.settingApp.pathApp;
                nb_ItemHistorySize.Value = SGlobalSetting.settingApp.sizeHistoryItem;
                TbUrl.Text = SGlobalSetting.settingApp.urlPhoto;
                NbItemSizePhoto.Value= SGlobalSetting.settingApp.sizePhotoItem;
                NbX.Value = SGlobalSetting.settingApp.xPosDoble;
                NbY.Value = SGlobalSetting.settingApp.yPosDoble;
                NbWidth.Value = SGlobalSetting.settingApp.WidthDoble;
                NbHeight.Value = SGlobalSetting.settingApp.HeightDoble;
                TbDlgName.Text = SGlobalSetting.settingApp.DialogName;
                cbConnectMode.Checked = SGlobalSetting.settingApp.ConnectMode;
                cbStartMode.Checked = SGlobalSetting.settingApp.StartMode;
            }
        }


        public void Save()
        {
            SGlobalSetting.settingApp.pathApp = path.Text;
            SGlobalSetting.settingApp.sizeHistoryItem = (int)nb_ItemHistorySize.Value;
            SGlobalSetting.settingApp.urlPhoto = TbUrl.Text;
            SGlobalSetting.settingApp.sizePhotoItem = (int)NbItemSizePhoto.Value;
            SGlobalSetting.settingApp.xPosDoble = (int)NbX.Value;
            SGlobalSetting.settingApp.yPosDoble = (int)NbY.Value;
            SGlobalSetting.settingApp.WidthDoble = (int)NbWidth.Value;
            SGlobalSetting.settingApp.HeightDoble = (int)NbHeight.Value;
            SGlobalSetting.settingApp.DialogName = TbDlgName.Text;
            SGlobalSetting.settingApp.ConnectMode = cbConnectMode.Checked;
            SGlobalSetting.settingApp.StartMode = cbStartMode.Checked;
        }

        public bool edited()
        {
            return (SGlobalSetting.settingApp.pathApp != path.Text ||
                SGlobalSetting.settingApp.sizeHistoryItem  != (int)nb_ItemHistorySize.Value ||
                SGlobalSetting.settingApp.urlPhoto != TbUrl.Text ||
                SGlobalSetting.settingApp.sizePhotoItem != (int)NbItemSizePhoto.Value ||
                SGlobalSetting.settingApp.xPosDoble != (int)NbX.Value ||
                SGlobalSetting.settingApp.yPosDoble != (int)NbY.Value ||
                SGlobalSetting.settingApp.WidthDoble != (int)NbWidth.Value ||
                SGlobalSetting.settingApp.HeightDoble != (int)NbHeight.Value ||
                SGlobalSetting.settingApp.DialogName != TbDlgName.Text ||
                SGlobalSetting.settingApp.ConnectMode != cbConnectMode.Checked ||
                SGlobalSetting.settingApp.StartMode != cbStartMode.Checked
                );

        }

        private void bt_path_open_Click(object sender, EventArgs e)
        {
            SConnector.FormMain.ShowOn = true;
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                path.Text = openFileDialog1.FileName;
            }
            SConnector.FormMain.ShowOn = false;
        }

        private void numericUpDown3_ValueChanged(object sender, EventArgs e)
        {

        }

        private void BtSetCurrentPos_Click(object sender, EventArgs e)
        {
            NbX.Value = SConnector.FormMain.Location.X;
            NbY.Value = SConnector.FormMain.Location.Y;
            NbWidth.Value = SConnector.FormMain.Width;
            NbHeight.Value = SConnector.FormMain.Height;
        }
    }
}
