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;
using YARTE.UI.Buttons;

namespace FCM0000
{
    public partial class fRequestItem_Add : FCOMMON.fBase
    {
        dsMSSQL.RequestItemRow dr = null;
        public fRequestItem_Add(dsMSSQL.RequestItemRow dr_)
        {
            InitializeComponent();
            dr = dr_;
            PredefinedButtonSets.SetupDefaultButtons(this.tbRemark);
        }

        private void __Load(object sender, EventArgs e)
        {
            //프로젝트 리스트를 가져와서 cmb에 연결해준다.
            var projectDT = FCOMMON.DBM.getProjectData();
            this.cmProject.DataSource = projectDT;
            this.cmProject.DisplayMember = "KeyValue";
            this.cmProject.ValueMember = "Key";


            this.bs.DataSource = this.dr;
            if (this.dr.RowState == DataRowState.Detached)
            {
                //자로에서 불러와서 그 값을 가져온다.
                var taMF = new DSMailTableAdapters.MailFormTableAdapter();
                var data = taMF.GetByCate(FCOMMON.info.Login.gcode, "BY");
                if (data != null && data.Rows.Count > 0)
                {
                    var drForm = data.Rows[0] as DSMail.MailFormRow;
                    this.tbItem.Text = drForm.title;
                    this.tbRemark.Html = drForm.body;

                    dr.tolist = drForm.tolist;
                    dr.bcclist = drForm.bcc;
                    dr.cclist = drForm.cc;
                    dr.EndEdit();
                }
            }

            if (this.dr.RowState != DataRowState.Deleted)
            {
                lbBCC.Text = dr.bcclist;
                lbCC.Text = dr.cclist;
                lbTo.Text = dr.tolist;
                tbRemark.Html = dr.remark;
            }
        }

        private void requestItemBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.bs.EndEdit();
            DialogResult = System.Windows.Forms.DialogResult.OK;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.dr.cclist != lbCC.Text)
                this.dr.cclist = lbCC.Text;
            if (this.dr.tolist != lbTo.Text)
                this.dr.tolist = lbTo.Text;
            if (this.dr.bcclist != lbBCC.Text)
                this.dr.bcclist = lbBCC.Text;
            if (this.dr.remark != tbRemark.Html)
                this.dr.remark = tbRemark.Html;

            this.Invalidate();
            this.bs.EndEdit();

            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void remarkLabel_Click(object sender, EventArgs e)
        {
            var dlg = FCOMMON.Util.MsgQ("메일 형식을 초기화 하시겠습니까?");
            if (dlg != System.Windows.Forms.DialogResult.Yes) return;
            
            //자로에서 불러와서 그 값을 가져온다.
            var taMF = new DSMailTableAdapters.MailFormTableAdapter();
            var data = taMF.GetByCate( FCOMMON.info.Login.gcode, "BY");
            if (data != null && data.Rows.Count > 0)
            {
                var drForm = data.Rows[0] as DSMail.MailFormRow;
                this.tbRemark.Html = drForm.body;
            }
        }

    }
}
