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 FBS0000
{
    public partial class fMinutes :FCOMMON.fBase
    {
        int idx = -1;
        public fMinutes()
        {
            InitializeComponent();
            Properties.Settings.Default["gwcs"] = FCOMMON.info.CS;
            this.dsMSSQL.minutes.TableNewRow += minutes_TableNewRow;
        }

        void minutes_TableNewRow(object sender, DataTableNewRowEventArgs e)
        {
            e.Row["wuid"] = FCOMMON.info.Login.no;
            e.Row["wdate"] = DateTime.Now;
            e.Row["stime"] = DateTime.Now;
            e.Row["etime"] = DateTime.Now.AddHours(1);
            e.Row["title"] = "Subject";
        }

        private void __Load(object sender, EventArgs e)
        {
            EnsureVisibleAndUsableSize();
            this.Show();
            Application.DoEvents();

            refreshData();
        }
   
        void refreshData()
        {
            //refresh data
            this.ta.Fill(this.dsMSSQL.minutes);
            this.dv1.AutoResizeColumns();
        }


        private void autoColumnSizeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.dv1.AutoResizeColumns();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            refreshData();
        }

        private void dv1_DoubleClick(object sender, EventArgs e)
        {
            if(idx == -1)
            {
                FCOMMON.Util.MsgE("선택된 대상이 없습니다.");
                return;
            }
            var f = new fMinutesDetail(idx);
            f.ShowDialog();
        }

        private void bs_CurrentChanged(object sender, EventArgs e)
        {
            idx = -1;
            var drv = bs.Current as DataRowView;
            if (drv == null) return;
            var dr = drv.Row as dsMSSQL.minutesRow;
            idx = dr.idx;
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            try
            {
                var cnt = this.ta.Update(this.dsMSSQL.minutes);
            }
            catch (Exception ex)
            {
                FCOMMON.Util.MsgE(ex.Message);
            }
        }
    }
}
