using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace vmsnet.Setting
{
    public partial class fDesignSetting : Form
    {
        public fDesignSetting()
        {
            InitializeComponent();
            this.button1.Click += (s1, e1) => this.DialogResult = DialogResult.OK;
        }

        private void fDesignSetting_Load(object sender, EventArgs e)
        {
            tbfontnb.Text = PUB.DESIGN.font_nb;
            tbfontcellname.Text = PUB.DESIGN.font_cellname;
            tbfontcellvalue.Text = PUB.DESIGN.font_cellvalue;
            tbFontSummary.Text = PUB.DESIGN.font_summary;
            tbFontCellTitle.Text = PUB.DESIGN.font_celltitle;
            tbFontAvalue.Text = PUB.DESIGN.font_alarmvalue;
            tbFontKaValue.Text = PUB.DESIGN.font_kaValue;
            tbFontKaUnit.Text = PUB.DESIGN.font_kaUnit;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PUB.DESIGN.font_nb = tbfontnb.Text;
            PUB.DESIGN.font_cellname = tbfontcellname.Text;
            PUB.DESIGN.font_cellvalue = tbfontcellvalue.Text;
            PUB.DESIGN.font_summary = tbFontSummary.Text;
            PUB.DESIGN.font_celltitle = tbFontCellTitle.Text;
            PUB.DESIGN.font_alarmvalue = tbFontAvalue.Text;
            PUB.DESIGN.font_kaUnit = tbFontKaUnit.Text;
            PUB.DESIGN.font_kaValue = tbFontKaValue.Text;
            PUB.DESIGN.Save();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SetFontData(tbfontnb);
        }

        void SetFontData(TextBox tb)
        {
            using (var fd = new FontDialog())
            {
                fd.Font = PUB.GetFontFromStr(tb.Text);
                if (fd.ShowDialog() == DialogResult.OK)
                {
                    tb.Text = $"{fd.Font.Name},{fd.Font.Size},{(fd.Font.Bold ? 1 : 0)}";
                }
            }

        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SetFontData(tbfontcellname);
        }

        private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SetFontData(tbfontcellvalue);
        }

        private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SetFontData(tbFontSummary);
        }

        private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SetFontData(tbFontCellTitle);
        }

        private void linkLabel6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SetFontData(tbFontAvalue);
        }

        private void linkLabel7_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SetFontData(tbFontKaValue);
        }

        private void linkLabel8_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SetFontData(tbFontKaUnit);
        }
    }
}
