using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using PostCardHitsuji.DataClient.DAO;
using PostCardHitsuji.DataClient.Model;
using PostCardHitsuji.Ui.RowPanel;
using Hitsuji.Framework.Thread;
using Hitsuji.Framework.Utils;
using PostCardHitsuji.Global;

namespace PostCardHitsuji.Ui.Controls
{
    public partial class NewReseiverLayoutUserControl : UserControl
    {
        private ToolTip itemTip { get; set; }
        
        public NewReseiverLayoutUserControl()
        {
            InitializeComponent();
            itemTip = new ToolTip();
            
            settingLabel(labelReseiverPostal, buildReseiverPostalKey());
            settingLabel(labelReseiverAddress1, GlobalSettings.RESEIVER_ADDRESS1.Key);
            settingLabel(labelReseiverAddress2, GlobalSettings.RESEIVER_ADDRESS2.Key);
            settingLabel(labelReseiverAddress3, GlobalSettings.RESEIVER_ADDRESS3.Key);
            settingLabel(labelReseiverName1, GlobalSettings.RESEIVER_NAME1.Key);
            settingLabel(labelReseiverName2, GlobalSettings.RESEIVER_NAME2.Key);
            settingLabel(labelReseiverName3, GlobalSettings.RESEIVER_NAME3.Key);
            settingLabel(labelReseiverName4, GlobalSettings.RESEIVER_NAME4.Key);
            settingLabel(labelReseiverSuffix1, GlobalSettings.RESEIVER_SUFFIX1.Key);
            settingLabel(labelReseiverSuffix2, GlobalSettings.RESEIVER_SUFFIX2.Key);
            settingLabel(labelReseiverSuffix3, GlobalSettings.RESEIVER_SUFFIX3.Key);
            settingLabel(labelReseiverSuffix4, GlobalSettings.RESEIVER_SUFFIX4.Key);

            settingLabel(labelSenderPostal, buildSenderPostalKey());
            settingLabel(labelSenderAddress1, GlobalSettings.SENDER_ADDRESS1.Key);
            settingLabel(labelSenderAddress2, GlobalSettings.SENDER_ADDRESS2.Key);
            settingLabel(labelSenderAddress3, GlobalSettings.SENDER_ADDRESS3.Key);
            settingLabel(labelSenderName1, GlobalSettings.SENDER_NAME1.Key);
            settingLabel(labelSenderName2, GlobalSettings.SENDER_NAME2.Key);
            settingLabel(labelSenderName3, GlobalSettings.SENDER_NAME3.Key);
            settingLabel(labelSenderName4, GlobalSettings.SENDER_NAME4.Key);
            settingLabel(labelSenderTel, GlobalSettings.SENDER_TEL.Key);

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

        private void load(object sender, EventArgs ev)
        {
            postCardListView1.SearchPostCardAll();
            postCardListView1.OnListItemSelectedEvent += new ListViewItemSelectionChangedEventHandler(
                (listView, e) =>
                {
                    var view = listView as ListView;
                    if (e.Item == null || e.Item.Text.Equals("") || e.Item.ListView == null || !e.IsSelected) return;

                    var img = view.LargeImageList.Images[e.ItemIndex];
                    var title = view.Items[e.ItemIndex].Text;
                    var targetLayout = postCardListView1.getLayoutModelByName(title);

                    // UI表示
                    this.textBoxId.Text = targetLayout.Id;
                    this.textBoxLayoutName.Text = targetLayout.layoutName;
                    // レイアウトアイテム再設定
                    newPaperLayer1.clearMsgItemsAbsolutory();
                    foreach (var msg in targetLayout.MsgItemList)
                        newPaperLayer1.addMsgItem(msg.Name, msg, 
                            msg.Name.IndexOf("RESEIVER") >= 0 ? GlobalSettings.RESEIVER_RECTABGLE_COLOR : GlobalSettings.SENDER_RECTABGLE_COLOR);
                    
                    //
                    onSelectedLayoutItemChanged("EMP");
                    
                    // 表示リフレッシュ
                    newPaperLayer1.forceRefreshLayoutMethod();
                });

            attachLayoutItemPanel1.OnPropertyChangedEvent 
                += new EventHandler((obj, e) => { newPaperLayer1.forceRefreshLayoutMethod(); });

            buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
            newPaperLayer1.OnSelectedItemChangedEvent += new MouseEventHandler(
                (selectedRectangle, selectedItemChangedEvent) =>
                {
                    MsgItemContentModel selection = (selectedRectangle as MsgRectangle).model as MsgItemContentModel;
                    var key = selection.Name.IndexOf("RESEIVER_PRE") >= 0 || 
                              selection.Name.IndexOf("RESEIVER_POST") >= 0 ?
                                buildReseiverPostalKey() :
                              selection.Name.IndexOf("SENDER_PRE") >= 0 || 
                              selection.Name.IndexOf("SENDER_POST") >= 0 ?
                                buildSenderPostalKey() : 
                                selection.Name;
                    onSelectedLayoutItemChanged(key);
                });
        }

        private void settingLabel(Label label, string labelKey)
        {
            label.Tag = labelKey;
            label.Click += new EventHandler(onLabelClicked);
            label.DoubleClick += new EventHandler(onLabelDoubleClicked);
            label.MouseEnter += new EventHandler(
                (sender, e) =>
                {
                    var label_ = sender as Label;
                    if (label_.Tag == null) return;

                    var keys = label_.Tag.ToString();
                    string[] keyArray = keys.Split(':');

                    var txt = new System.Text.StringBuilder("");
                    foreach (var key in keyArray)
                    {
                        if (!newPaperLayer1.msgItems.ContainsKey(key))
                            continue;
                        var msgItem = newPaperLayer1.msgItems[key].model as MsgItemContentModel;
                        txt.Append("  ").AppendLine(msgItem.Name.Replace("RESEIVER_","").Replace("SENDER_", ""))
                            .Append("  x:").Append(msgItem.x.ToString())
                            .Append(" , y:").AppendLine(msgItem.y.ToString());
                    }
                    if (string.IsNullOrEmpty(txt.ToString()))
                        return;

                    itemTip.Show(txt.ToString(), 
                                 label_, 
                                 label_.Width - 5, 5);
                    itemTip.Active = true;
                });
            label.MouseLeave += new EventHandler(
                (sender, e) =>
                {
                    var label_ = sender as Label;
                    itemTip.Hide(label_);
                });
        }

        /// <summary>
        /// ラベルクリック
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="ev"></param>
        private void onLabelClicked(object sender, EventArgs ev)
        {
            onSelectedLayoutItemChanged((sender as Label).Tag.ToString());
            newPaperLayer1.forceRefreshLayoutMethod();
        }

        private void onLabelDoubleClicked(object sender, EventArgs ev)
        {
            var keys = (sender as Label).Tag.ToString();
            List<MsgItemContentModel> models = new List<MsgItemContentModel>();
            foreach (var rect in newPaperLayer1.msgItems.Values)
            {
                if (keys.IndexOf((rect.model as MsgItemContentModel).Name) >= 0)
                    (rect.model as MsgItemContentModel).Enable 
                        = (rect.model as MsgItemContentModel).Enable.Equals(false.ToString().ToUpper())
                        ? true.ToString().ToUpper() : false.ToString().ToUpper();
            }
            onSelectedLayoutItemChanged(keys);
            newPaperLayer1.forceRefreshLayoutMethod();
        }

        private void onSelectedLayoutItemChanged(string keys)
        {
            setLabelBackColor(keys);
            setPaperLayoutItemBackColor(keys);
            setModelToSelectionLabel(keys);
        }

        private void setLabelBackColor(string keys)
        {
            foreach (Control rLabel in flowLayoutPanel_Reseiver.Controls)
            {
                rLabel.BackColor = (rLabel.Tag.ToString().IndexOf(keys) >= 0)
                    ? Color.Pink : GlobalSettings.RESEIVER_RECTABGLE_COLOR;
            }
            foreach (Control sLabel in flowLayoutPanel_Sender.Controls)
            {
                sLabel.BackColor = (sLabel.Tag.ToString().IndexOf(keys) >= 0)
                    ? Color.Pink : GlobalSettings.SENDER_RECTABGLE_COLOR;
            }
        }

        private void setPaperLayoutItemBackColor(string keys)
        {
            foreach(var rect in newPaperLayer1.msgItems)
            {
                rect.Value.SolidBrush_.Color = (keys.IndexOf(rect.Key) >= 0)
                    ? Color.Pink : rect.Key.IndexOf("RESEIVER") >= 0 
                    ? GlobalSettings.RESEIVER_RECTABGLE_COLOR 
                    : GlobalSettings.SENDER_RECTABGLE_COLOR;
            }
        }

        private void setModelToSelectionLabel(string keys)
        {
            attachLayoutItemPanel1.Models = new List<MsgItemContentModel>();
            foreach (var itm in newPaperLayer1.msgItems.Values)
                if (keys.IndexOf((itm.model as MsgItemContentModel).Name) >= 0)
                    attachLayoutItemPanel1.Models.Add(itm.model as MsgItemContentModel);
            attachLayoutItemPanel1.Models = attachLayoutItemPanel1.Models;
        }

        private void checkBoxItem_checkedChanged(object sender, EventArgs ev)
        {
            var me = sender as CheckBox;
            MsgItemContentModel mod_ = null;
            foreach (var kvp in me.Tag as Dictionary<string, MsgItemContentModel>)
                mod_ = kvp.Value;
            me.CheckedChanged -= new EventHandler(checkBoxItem_checkedChanged);
            me.Checked = bool.Parse(mod_.Enable);
            me.CheckedChanged += new EventHandler(checkBoxItem_checkedChanged);

            attachLayoutItemPanel1.Models.Clear();
            foreach (var m in (me.Tag as Dictionary<string, MsgItemContentModel>).Values)
                attachLayoutItemPanel1.Models.Add(m);
            attachLayoutItemPanel1.Models = attachLayoutItemPanel1.Models;
        }

        private LayoutLineItemRow createLayoutLineRow_ReseiverPostal(LayoutLineItemRow row)
        {
            //var row = new LayoutLineItemRow();
            row.Name = GlobalSettings.RESEIVER_POSTAL.Key;
            row.FontSizeItems = GlobalSettings.SizeItems;
            row.Margin = new System.Windows.Forms.Padding(1);

            #region pre
            {//pre1
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.RESEIVER_PRE1.Key;
                mod.message = GlobalSettings.RESEIVER_PRE1.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            {//pre2
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.RESEIVER_PRE2.Key;
                mod.message = GlobalSettings.RESEIVER_PRE2.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            {//pre3
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.RESEIVER_PRE3.Key;
                mod.message = GlobalSettings.RESEIVER_PRE3.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            #endregion

            #region post
            {//post1
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.RESEIVER_POST1.Key;
                mod.message = GlobalSettings.RESEIVER_POST1.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            {//post2
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.RESEIVER_POST2.Key;
                mod.message = GlobalSettings.RESEIVER_POST2.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            {//post3
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.RESEIVER_POST3.Key;
                mod.message = GlobalSettings.RESEIVER_POST3.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            {//post4
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.RESEIVER_POST4.Key;
                mod.message = GlobalSettings.RESEIVER_POST4.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            #endregion

            row.CheckBoxTitleText = GlobalSettings.RESEIVER_POSTAL.Value;
            row.BackColor = Global.GlobalSettings.RESEIVER_RECTABGLE_COLOR;
            row.OnTitleCheckChangedEvent += new EventHandler(
                (sender, ev) =>
                {
                    var row_ = sender as LayoutLineItemRow;

                    foreach (MsgItemContentModel mod_ in row_.MsgModel.Values)
                    {
                        if (row_.IsChecked)
                        {
                            //ON
                            //アイテムの位置がはがきからはみ出ている場合は強制的に入れる
                            mod_.x = Math.Min(Math.Max(mod_.x, 0), newPaperLayer1.Width - 10);
                            mod_.y = Math.Min(Math.Max(mod_.y, 0), newPaperLayer1.Height - 10);
                            mod_.isMsgDirectVertical = true;
                            newPaperLayer1.addMsgItem(mod_.Name, mod_, GlobalSettings.RESEIVER_RECTABGLE_COLOR);

                        }
                        else
                            //OFF
                            newPaperLayer1.removeMsgItem(mod_.Name);

                    }
                });
            row.OnPropertyEditEnd += new EventHandler((sender, ev) => { newPaperLayer1.forceRefreshLayoutMethod(); });
            row.MsgModel = row.MsgModel;//イベントを発生させてＵＩに反映
            //参照を保持
            //rowPanels.Add(row.Name, row);

            return row;
        }

        private LayoutLineItemRow createLayoutLineRow_SenderPostal(LayoutLineItemRow row)
        {
            row.Name = GlobalSettings.SENDER_POSTAL.Key;
            row.FontSizeItems = GlobalSettings.SizeItems;
            row.Margin = new System.Windows.Forms.Padding(1);

            #region pre
            {//pre1
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.SENDER_PRE1.Key;
                mod.message = GlobalSettings.SENDER_PRE1.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                mod.width = 15;
                mod.height = 20;
                row.MsgModel.Add(mod.Name, mod);
            }
            {//pre2
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.SENDER_PRE2.Key;
                mod.message = GlobalSettings.SENDER_PRE2.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            {//pre3
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.SENDER_PRE3.Key;
                mod.message = GlobalSettings.SENDER_PRE3.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            #endregion

            #region post
            {//post1
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.SENDER_POST1.Key;
                mod.message = GlobalSettings.SENDER_POST1.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            {//post2
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.SENDER_POST2.Key;
                mod.message = GlobalSettings.SENDER_POST2.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            {//post3
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.SENDER_POST3.Key;
                mod.message = GlobalSettings.SENDER_POST3.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            {//post4
                var mod = new MsgItemContentModel();
                mod.Name = GlobalSettings.SENDER_POST4.Key;
                mod.message = GlobalSettings.SENDER_POST4.Value;
                mod.isMsgDirectVertical = true;
                mod.size = "12";
                row.MsgModel.Add(mod.Name, mod);
            }
            #endregion

            row.CheckBoxTitleText = GlobalSettings.SENDER_POSTAL.Value;
            row.BackColor = Global.GlobalSettings.SENDER_RECTABGLE_COLOR;
            row.OnTitleCheckChangedEvent += new EventHandler(
                (sender, ev) =>
                {
                    var row_ = sender as LayoutLineItemRow;
                    foreach (MsgItemContentModel mod_ in row_.MsgModel.Values)
                    {
                        if (row_.IsChecked)
                        {
                            //ON
                            //アイテムの位置がはがきからはみ出ている場合は強制的に入れる
                            mod_.x = Math.Min(Math.Max(mod_.x, 0), newPaperLayer1.Width - 10);
                            mod_.y = Math.Min(Math.Max(mod_.y, 0), newPaperLayer1.Height - 10);
                            mod_.isMsgDirectVertical = true;
                            newPaperLayer1.addMsgItem(mod_.Name, mod_, GlobalSettings.SENDER_RECTABGLE_COLOR);

                        }
                        else
                            //OFF
                            newPaperLayer1.removeMsgItem(mod_.Name);

                    }
                });
            row.OnPropertyEditEnd += new EventHandler((sender, ev) => { newPaperLayer1.forceRefreshLayoutMethod(); });

            //参照を保持
            //rowPanels.Add(row.Name, row);

            return row;
        }

        private void addPostItems_Reseiver()
        {
            #region pre1
            {
                var pre = new MsgItemContentModel();
                pre.Name = pre.message = GlobalSettings.RESEIVER_PRE1.Key;
                pre.x = 173;
                pre.y = 55;
                pre.width = 15;
                pre.height = 20;
                pre.message = Global.GlobalSettings.RESEIVER_PRE1.Value;
                newPaperLayer1.addMsgItem(pre.Name, pre, Global.GlobalSettings.RESEIVER_RECTABGLE_COLOR);
            }
            #endregion

            #region pre2
            {
                var pre = new MsgItemContentModel();
                pre.Name = pre.message = GlobalSettings.RESEIVER_PRE2.Key;
                pre.x = 201;
                pre.y = 55;
                pre.width = 15;
                pre.height = 20;
                pre.message = GlobalSettings.RESEIVER_PRE2.Value;
                newPaperLayer1.addMsgItem(pre.Name, pre, Global.GlobalSettings.RESEIVER_RECTABGLE_COLOR);
            }
            #endregion

            #region pre3
            {
                var pre = new MsgItemContentModel();
                pre.Name = pre.message = GlobalSettings.RESEIVER_PRE3.Key;
                pre.x = 229;
                pre.y = 55;
                pre.width = 15;
                pre.height = 20;
                pre.message = GlobalSettings.RESEIVER_PRE3.Value;
                newPaperLayer1.addMsgItem(pre.Name, pre, Global.GlobalSettings.RESEIVER_RECTABGLE_COLOR);
            }
            #endregion

            #region post1
            {
                var post = new MsgItemContentModel();
                post.Name = post.message = GlobalSettings.RESEIVER_POST1.Key;
                post.x = 260;
                post.y = 55;
                post.width = 15;
                post.height = 20;
                post.message = Global.GlobalSettings.RESEIVER_POST1.Value;
                newPaperLayer1.addMsgItem(post.Name, post, Global.GlobalSettings.RESEIVER_RECTABGLE_COLOR);
            }
            #endregion

            #region post2
            {
                var post = new MsgItemContentModel();
                post.Name = post.message = GlobalSettings.RESEIVER_POST2.Key;
                post.x = 288;
                post.y = 55;
                post.width = 15;
                post.height = 20;
                post.message = Global.GlobalSettings.RESEIVER_POST2.Value;
                newPaperLayer1.addMsgItem(post.Name, post, Global.GlobalSettings.RESEIVER_RECTABGLE_COLOR);
            }
            #endregion

            #region post3
            {
                var post = new MsgItemContentModel();
                post.Name = post.message = GlobalSettings.RESEIVER_POST3.Key;
                post.x = 316;
                post.y = 55;
                post.width = 15;
                post.height = 20;
                post.message = Global.GlobalSettings.RESEIVER_POST3.Value;
                newPaperLayer1.addMsgItem(post.Name, post, Global.GlobalSettings.RESEIVER_RECTABGLE_COLOR);
            }
            #endregion

            #region post4
            {
                var post = new MsgItemContentModel();
                post.Name = post.message = GlobalSettings.RESEIVER_POST4.Key;
                post.x = 344;
                post.y = 55;
                post.width = 15;
                post.height = 20;
                post.message = Global.GlobalSettings.RESEIVER_POST4.Value;
                newPaperLayer1.addMsgItem(post.Name, post, Global.GlobalSettings.RESEIVER_RECTABGLE_COLOR);
            }
            #endregion

        }

        private void removePostItems_Reseiver()
        {
            newPaperLayer1.removeMsgItem(GlobalSettings.RESEIVER_PRE1.Key);
            newPaperLayer1.removeMsgItem(GlobalSettings.RESEIVER_PRE2.Key);
            newPaperLayer1.removeMsgItem(GlobalSettings.RESEIVER_PRE3.Key);
            newPaperLayer1.removeMsgItem(GlobalSettings.RESEIVER_POST1.Key);
            newPaperLayer1.removeMsgItem(GlobalSettings.RESEIVER_POST2.Key);
            newPaperLayer1.removeMsgItem(GlobalSettings.RESEIVER_POST3.Key);
            newPaperLayer1.removeMsgItem(GlobalSettings.RESEIVER_POST4.Key);
        }

        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            if (!checkUpdate())
                return;

            if (MessageBox.Show(this, "選択された宛名レイアウトを更新します。よろしいですか？", "", MessageBoxButtons.YesNo) == DialogResult.No)
                return;

            updateDb();

            postCardListView1.SearchPostCardAll();
        }

        private bool checkUpdate()
        {
            if (string.IsNullOrEmpty(textBoxId.Text))
            {
                MessageBox.Show("レイアウトを選択してください。");
                return false;
            } 
            if (string.IsNullOrEmpty(textBoxLayoutName.Text))
            {
                MessageBox.Show("レイアウト名を入力してください。");
                return false;
            }
            return true;
        }

        private bool updateDb()
        {
            using (var daoFactory = new PostCardHitsuji.DataClient.DAO.DaoFactory())
            {
                daoFactory.beginTransaction();
                try
                {
                    //DAO生成
                    var dao = (IllustLayoutDao)daoFactory.getDao<LayoutIllustContentModel>(GlobalSettings.illLayoutDao_);
                    dao.inModel = new IllustLayoutContentModel();
                    dao.inModel.Id = textBoxId.Text;
                    dao.inModel.layoutName = textBoxLayoutName.Text;
                    //layoutInfo.year = ((KeyValuePair<string, string>)comboBoxYear.SelectedItem).Value;
                    dao.inModel.year = "0000";
                    dao.inModel.Enable = true.ToString().ToUpper();
                    dao.inModel.layoutType = IllustLayoutContentModel.LAYOUT_TYPE_RESEIVER;
                    dao.inModel.layoutVector = "V";

                    foreach (var rect in newPaperLayer1.msgItems.Values)
                        dao.inModel.MsgItemList.Add(rect.model as MsgItemContentModel);

                    //データ処理
                    dao.updateLayoutSimple(null);

                    daoFactory.commitTransaction();
                    return true;
                }
                catch (Exception ex)
                {
                    daoFactory.rollbackTransaction();
                    System.Windows.Forms.MessageBox.Show(ex.ToString());
                    return false;
                }
            }
        }

        private string buildReseiverPostalKey()
        {
            return GlobalSettings.RESEIVER_PRE1.Key + ":" +
                GlobalSettings.RESEIVER_PRE2.Key + ":" +
                GlobalSettings.RESEIVER_PRE3.Key + ":" +
                GlobalSettings.RESEIVER_POST1.Key + ":" +
                GlobalSettings.RESEIVER_POST2.Key + ":" +
                GlobalSettings.RESEIVER_POST3.Key + ":" +
                GlobalSettings.RESEIVER_POST4.Key;
        }
        private string buildSenderPostalKey()
        {
            return GlobalSettings.SENDER_PRE1.Key + ":" +
                GlobalSettings.SENDER_PRE2.Key + ":" +
                GlobalSettings.SENDER_PRE3.Key + ":" +
                GlobalSettings.SENDER_POST1.Key + ":" +
                GlobalSettings.SENDER_POST2.Key + ":" +
                GlobalSettings.SENDER_POST3.Key + ":" +
                GlobalSettings.SENDER_POST4.Key;
        }

    }
}
