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 fHolyday_Add : FCOMMON.fBase
    {
        Boolean bInit = false;
        dsMSSQL.HolydayRow dr;

        public fHolyday_Add(int idx)
        {
            InitializeComponent();
            if(idx == -1)
            {
                dr = this.dsMSSQL.Holyday.NewHolydayRow();
                dr.sdate = DateTime.Parse( DateTime.Now.Year.ToString() + "-01-01");
                dr.edate = dr.sdate;
                dr.wuid = FCOMMON.info.Login.no;
                dr.wdate = DateTime.Now;
                dr.term = 0.0;
                dr.cate = "10";
                dr.gcode = FCOMMON.info.Login.gcode;
                dr.uid = FCOMMON.info.Login.no;
                this.dsMSSQL.Holyday.AddHolydayRow(dr);
            }   
            else
            {
                ta.FillByIdx(this.dsMSSQL.Holyday, FCOMMON.info.Login.gcode, idx);
                this.dr = this.dsMSSQL.Holyday.Rows[0] as dsMSSQL.HolydayRow;
            }

            this.cmbUser.DataSource = FCOMMON.DBM.getUserTable(); 
            this.cmbUser.DisplayMember = "dispName";
            this.cmbUser.ValueMember = "id";
            this.bs.DataSource = dr;
        }
        public fHolyday_Add() : this(-1) { }


        private void __Load(object sender, EventArgs e)
        {
            bInit = true;
            this.Show();
            Application.DoEvents();
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            //기본값처리
       

            this.Validate();
            this.bs.EndEdit();
            this.dr.EndEdit();

            try
            {
                
                this.ta.Update(this.dr);
                dr.AcceptChanges();
                DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception eX)
            {
                FCOMMON.Util.MsgE(eX.Message);
            }

            
            
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            if (!bInit) return;

            
            //if(dateTimePicker1.Value > this.dateTimePicker2.Value)
            //    this.dateTimePicker2.Value = dateTimePicker1.Value;
            //RefreshTerm();
          

        }

        void RefreshTerm()
        {
            //var ts = dateTimePicker2.Value - dateTimePicker1.Value;
            //var days = Math.Ceiling(ts.TotalDays) + 1;
            //this.numericUpDown1.Value = (decimal)days;
            //this.dr.term = days;
        }
        private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
        {
            if (!bInit) return;
            RefreshTerm();
        }
    }
}
