using System;
using System.Collections.Generic;
using System.Windows.Forms;
using PostCardHitsuji.DataClient.Model;
using PostCardHitsuji.DataClient.DAO;
using PostCardHitsuji.Global;

namespace PostCardHitsuji.Ui.RowPanel
{
    public partial class AddressFloatRowPanel : BaseFloatPanel
    {
        public event EventHandler OnInsertedEvent;
        public event EventHandler OnUpdatedEvent;

        public AddressFloatRowPanel()
        {
            InitializeComponent();

            this.Load += new EventHandler(onLoad);
        }

        protected void onLoad(object sender, EventArgs ev)
        {
            //パネル上のボタン、ラベル、その他各コントロールの見た目（色など）の設定
            this.BackColor = base.BackColor;
            attachAttribute_Color(this.label2);
            attachAttribute_Color(this.label3);
            attachAttribute_Color(this.checkBoxEnable);
        }

        protected override void notifyModelChanged()
        {
            prepareUiControls();
            modelToUi();
        }

        protected override void notifyPropertyChanged(object sender, EventArgs ev)
        {

        }

        private void prepareUiControls()
        {
            //コンボボックスアイテム準備
            
        }

        /// <summary>
        /// データ移動　ＵＩからモデルへ
        /// </summary>
        /// <param name="model"></param>
        public void uiToModel(Hitsuji.Framework.DataClient.Model.IContentModel refModel)
        {
            var mod = refModel as AddressContentModel;
            mod.Id = (this.Model as AddressContentModel).Id;
            mod.Enable = checkBoxEnable.Checked.ToString().ToUpper();
            mod.postalPre = textBoxPostalPre.Text;
            mod.postalPost = textBoxPostalPost.Text;
            mod.address1 = textBoxAddress1.Text;
            mod.address2 = textBoxAddress2.Text;
        }

        /// <summary>
        /// データ移動　モデルからＵＩへ
        /// </summary>
        private void modelToUi()
        {
            var model_ = Model == null ? new AddressContentModel() : Model as AddressContentModel;
            this.checkBoxEnable.Checked = bool.Parse(model_.Enable);
            this.textBoxAddress1.Text = model_.address1;
            this.textBoxAddress2.Text = model_.address2;
            this.textBoxPostalPre.Text = model_.postalPre;
            this.textBoxPostalPost.Text = model_.postalPost;
        }

        protected override void margeUiToModel(Hitsuji.Framework.DataClient.Model.IContentModel refModel)
        {
            uiToModel(refModel);
        }
    }
}
