using System;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.Collections.Generic;
using CasunCommon.BaseUI;
using PMSUI.Config;
using System.Drawing;

namespace PMSUI
{
    public partial class DisplaySettingForm : CasunForm
    {

        public delegate void DelegatePass();
        public event DelegatePass PassHandle;
        public DisplaySettingForm()
        {
            InitializeComponent();
        }

        private void DisplaySettingForm_Load(object sender, EventArgs e)
        {
            Init();

            CasunUILib.ButtonHelps(btHelps);

            gp_Opt.Location = new Point(btHelps.Location.X, gp_Opt.Location.Y);
            gp_Opt1.Location = new Point(btHelps.Location.X, gp_Opt1.Location.Y);

            //CasunUILib.GroupBoxReadModel(gp_Read, PermissionLevel);
            CasunUILib.GroupBoxReadWriteModel(gp_Opt, PermissionLevel);
            CasunUILib.GroupBoxReadWriteModel(gp_Opt1, PermissionLevel);

            PassHandle += new DelegatePass(MainForm.Instance.BackColorChangeHandle);
        }

        private void Init()
        {
            tbColor.BackColor = CasunUILib.g_FormBackColor;

            //List<string> LanguageList = CasunModelDB.CDBManager.Instance.PMS_sys_Language.GetLanguage();
            List<string> LanguageList = PmsCoreDB.DBHost.Instance.Language.GetLanguage();

            cbLanguage.Items.AddRange(LanguageList.ToArray());
            if (LanguageList.Count > 0)
            {
                cbLanguage.SelectedIndex = 0;
            }
            cbLanguage.Text = CConfigManager.gs_globalConfig.gs_DisplayLanguage;
        }

        private void tbColor_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                tbColor.BackColor = colorDialog1.Color;
            }
        }

        private void btDisplay_Click(object sender, EventArgs e)
        {
            this.BackColor = tbColor.BackColor;

        }

        private void btSaveColor_Click(object sender, EventArgs e)
        {

            CasunUILib.g_FormBackColor = tbColor.BackColor;

            CConfigManager.gs_globalConfig.gs_FormBackColor_R = CasunUILib.g_FormBackColor.R;
            CConfigManager.gs_globalConfig.gs_FormBackColor_G = CasunUILib.g_FormBackColor.G;
            CConfigManager.gs_globalConfig.gs_FormBackColor_B = CasunUILib.g_FormBackColor.B;
            CConfigManager.SaveGlobalData();
            //MessageBox.Show("设置成功！");
            PassHandle();
        }

        private void btsaveLanguage_Click(object sender, EventArgs e)
        {

            CConfigManager.gs_globalConfig.gs_DisplayLanguage = cbLanguage.Text.ToString();
            CConfigManager.SaveGlobalData();
        }

        private void cbLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void btHelps_Click(object sender, EventArgs e)
        {
            MessageBox.Show(PMSUI.Config.CConfigManager.gs_FormHelpConfig.GetFormHelp(this.Name));

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }
    }
}
