using FCOMMON;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Project
{
    public partial class fSetting : fBase
    {
       

        public fSetting()
        {
            InitializeComponent();

            this.KeyDown += (s1, e1) => {
                if (e1.KeyCode == Keys.Escape)
                    this.Close();
                if (DateTime.Now > Pub.LastInputTime) Pub.LastInputTime = DateTime.Now;
            };
            this.MouseMove += (s1, e1) => { if (DateTime.Now > Pub.LastInputTime) Pub.LastInputTime = DateTime.Now; };
            this.FormClosed += __Closed;
        }

        private void __Closed(object sender, FormClosedEventArgs e)
        {
           
        }

        private void __Load(object sender, EventArgs e)
        {
            EnsureVisibleAndUsableSize();
            this.propertyGrid1.SelectedObject = Pub.setting;
            this.propertyGrid1.Refresh();

            this.dataSet1.Clear();
            //this.dataSet1.Merge(Pub.mdm.dataSet);
            this.dataSet1.AcceptChanges();

           // this.chkLogIO.DataBindings.Add(new Binding("Checked", Pub.setting, "Log_IO", false, DataSourceUpdateMode.OnPropertyChanged));
           
        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            this.bsUser.EndEdit();
            this.bsModel.EndEdit();
            this.Invalidate();

            //var f = new Dialog.fPassword();
            //if (f.ShowDialog() != DialogResult.OK) return;
            //var pass = f.tbInput.Text;
            //if (pass != Pub.setting.Password_Setup)
            //{
            //    Util.MsgE("Password incorrect");
            //    return;
            //}

            if(this.dataSet1.HasChanges())
            {
                //Pub.mdm.dataSet.Clear();
                //Pub.mdm.dataSet.Merge(this.dataSet1);
                //Pub.mdm.dataSet.AcceptChanges();
                //Pub.mdm.SaveData(Manager.ModelManager.eModelType.Users);
                //Pub.mdm.SaveData(Manager.ModelManager.eModelType.Model);
            }
            DialogResult = DialogResult.OK;
        }

    }
}

