UcResponsePara.cs 12.6 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.PowerPoint;
using GeneralLib;
using System.IO;

namespace SunVoteARSPPT
{
    public partial class UcResponsePara : UserControl, IPanel
    {
        public TagSet TagSet { get; set; }
        /// <summary>
        /// 防止设置语言时触发SelectedIndexChanged事件
        /// </summary>
        public bool readOnly = false;
        public UcResponsePara()
        {
            InitializeComponent();
            try
            {
                FrmSystemSet.LanguageSetEvent += new FrmSystemSet.LanguageSetEventHander(FrmSystemSet_LanguageSetEvent);
                FrmSystemSet.GlobalSetChangeEvent += new FrmSystemSet.GlobalSetChangeEventHander(FrmSystemSet_GlobalSetChangeEvent);
                gbxNameAuthorize.Resize += gbxNameAuthorize_Resize;
                //设置控件大小
                this.Height = gbxNameAuthorize.Bottom;
                LoadComboBox();
                //GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
            }
            catch (Exception ex)
            {
                SystemLog.WriterLog(ex);
            }
        }

        void gbxNameAuthorize_Resize(object sender, EventArgs e)
        {
            int pos = gbxNameAuthorize.ClientSize.Width / 2;
            int w = pos - 3;
            rbtNameModeOff.Left = pos;
            rbtNameModeOff.Width = w;

            cboCanVote.Left = pos;
            cboCanVote.Width = w;

            cboBackMusic.Left = pos;
            cboBackMusic.Width = w;

            cboFieldVoteRate.Left = pos;
            cboFieldVoteRate.Width = w;
        }

        void FrmSystemSet_GlobalSetChangeEvent()
        {
            try
            {
                if (gbxNameAuthorize.Enabled)
                {
                    rbtNameModeOn.Checked = Convert.ToInt32(TagSet.GetValue(TagKey.ResponsePara_NameMode).Value) == 1;
                    rbtNameModeOff.Checked = Convert.ToInt32(TagSet.GetValue(TagKey.ResponsePara_NameMode).Value) == 0;
                }
            }
            catch { }
        }
        /// <summary>
        /// 语言设置
        /// </summary>
        void FrmSystemSet_LanguageSetEvent()
        {
            readOnly = true;
            GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
            LoadMusicSet();//杨斌 2015-04-10
            int index = ComboBoxOper.GetIndexByValue(cboCanVote, TagSet.GetValue(TagKey.ResponsePara_CanVote).Value);
            cboCanVote.SelectedIndex = index;
            readOnly = false;
        }

        private void UcResponsePara_Load(object sender, EventArgs e)
        {
            if (GlobalInfo.SysLanguage == null) return;
            GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
            LoadMusicSet();//杨斌 2015-04-10
            //设置默认值
            if (cboCanVote.Items.Count > 0)
                cboCanVote.SelectedIndex = 0;
        }

        /// <summary>
        /// 补充从现有词条加载新功能语言。杨斌 2015-05-07
        /// </summary>
        private void LoadMusicSet()
        {
            lblBackMusic.Text = GlobalInfo.SysLanguage.LPT.ReadString("FrmSystemSet", "lvwSound_Item_0", "背景音效");

            List<string> lstItem = new List<string>();
            lstItem.Add(GlobalInfo.SysLanguage.LPT.ReadString("FrmSystemSet", "FrmSystemSet", "系统设置"));

            string musicFile = "";
            string musicFilePre = "";
            if (TagSet != null)//杨斌 2016-06-07
            {
                musicFile = TagSet.GetValue(TagKey.ResponsePara_SlideBackMusic).Value;
                if (string.IsNullOrEmpty(musicFile))
                    musicFilePre = TagSet.GetValue(TagKey.ResponsePara_SlideBackMusicPre).Value;
                else
                {
                    if (musicFilePre != musicFile)
                    {
                        musicFilePre = musicFile;
                        TagSet.SetValue(TagKey.ResponsePara_SlideBackMusicPre, musicFilePre);
                    }
                }
                if (!string.IsNullOrEmpty(musicFilePre))
                    lstItem.Add(musicFilePre);
            }

            lstItem.Add(GlobalInfo.SysLanguage.LPT.ReadString("FrmSystemSet", "btnSoundBrowse", "浏览..."));

            cboBackMusic.Enabled = false;
            cboBackMusic.Items.Clear();

            foreach (var v in lstItem)
            {
                cboBackMusic.Items.Add(v);
            }
            if (string.IsNullOrEmpty(musicFile))
                cboBackMusic.SelectedIndex = 0;
            else
                cboBackMusic.SelectedIndex = 1;

            cboBackMusic.Enabled = true;

        }

        /// <summary>
        /// 加载参数面板数据
        /// </summary>
        public void LoadData()
        {
            if (TagSet == null) return;

            var iniSet = INIControl.GetInstances(GlobalInfo.SYSTEM_CONFIG_PATH);//杨斌 2019-06-12
            int defNameMode = iniSet.ReadInt("VoteSet", "NameMode", 0);//杨斌 2019-06-12

            //杨斌 2014-10-27
            cboFieldVoteRate.Items.Clear();
            cboFieldVoteRate.Items.Add("");
            RosterList rost = new RosterList();
            if (rost.RosterEnabled)
            {
                rost.LoadCloumn(GlobalInfo.DBOperation);
                for (int i = 1; i < rost.Columns.Count; i++)
                {
                    cboFieldVoteRate.Items.Add(rost.Columns[i].ColumnName);
                }
            }
            ComboBoxOper.SetComboText(cboFieldVoteRate, TagSet.GetValue(TagKey.ResponsePara_VoteRateField).Value);

            //if (TagSet.LoadValue(TagKey.ResponsePara_NameMode, rbtNameModeOn.Checked ? 1 : 0).ToInt == 1)
            if (TagSet.LoadValue(TagKey.ResponsePara_NameMode, 1 - defNameMode).ToInt == 1)//杨斌 2019-06-12
                rbtNameModeOn.Checked = true;
            else
                rbtNameModeOff.Checked = true;
            int index = ComboBoxOper.GetIndexByValue(cboCanVote, TagSet.LoadValue(TagKey.ResponsePara_CanVote, "cvAll").Value);
            cboCanVote.SelectedIndex = index;
            //cboCanVote.SelectedIndex = TagSet.LoadValue(TagKey.ResponsePara_CanVote, 0).ToInt;

            //杨斌 2015-04-10
            cboBackMusic.Enabled = false;
            string musicFile = TagSet.GetValue(TagKey.ResponsePara_SlideBackMusic).Value;
            if (!string.IsNullOrEmpty(musicFile))
            {
                if (cboBackMusic.Items.Count >= 2)
                    cboBackMusic.Items[1] = musicFile;
                else
                {
                    if (cboBackMusic.Items.Count < 1)
                        cboBackMusic.Items.Add("");
                    cboBackMusic.Items.Add(musicFile);
                }
                cboBackMusic.SelectedIndex = 1;
            }
            else
                cboBackMusic.SelectedIndex = 0;
            cboBackMusic.Enabled = true;

            SetVoteRateEnabled();//杨斌 2014-10-27
        }

        /// <summary>
        /// 隐藏投票权重
        /// 杨斌 2014-11-06
        /// </summary>
        //public void HideVoteRate()
        //{
        //    lblFieldVoteRate.Visible = false;
        //    cboFieldVoteRate.Visible = false;
        //    gbxNameAuthorize.Height = cboBackMusic.Bottom + 12;//杨斌 2015-04-10
        //    this.Height = gbxNameAuthorize.Bottom;
        //}

        /// <summary>
        /// 显示或隐藏参数。杨斌 2015-04-10
        /// </summary>
        /// <param name="showOther"></param>
        /// <param name="showRate"></param>
        public void ShowSet(bool showOther = true, bool showRate = true)
        {
            rbtNameModeOn.Visible = rbtNameModeOff.Visible = showOther;
            lblAuthorize.Visible = cboCanVote.Visible = showOther;
            lblFieldVoteRate.Visible = cboFieldVoteRate.Visible = showRate;
            if (showOther)
            {
                cboCanVote.Top = rbtNameModeOff.Bottom + 5;//杨斌 2016-02-03
                lblAuthorize.Top = cboCanVote.Top + 3;

                cboBackMusic.Top = cboCanVote.Bottom + 5;
                lblBackMusic.Top = cboBackMusic.Top + 3;
            }
            else
            {
                cboBackMusic.Top = rbtNameModeOff.Top;
                lblBackMusic.Top = cboBackMusic.Top + 3;
            }
            if (showRate)
            {
                cboFieldVoteRate.Top = cboBackMusic.Bottom + 5;
                lblFieldVoteRate.Top = cboFieldVoteRate.Top + 3;

                gbxNameAuthorize.Height = cboFieldVoteRate.Bottom + 12;
            }
            else
            {
                gbxNameAuthorize.Height = cboBackMusic.Bottom + 12;
            }
            this.Height = gbxNameAuthorize.Bottom;
        }

        /// <summary>
        /// 设置签到码签到是否启用
        /// 杨斌 2014-10-27
        /// </summary>
        private void SetVoteRateEnabled()
        {
            lblFieldVoteRate.Enabled = cboFieldVoteRate.Enabled = GlobalInfo.response.CanVoteRate();//杨斌 2014-10-27
        }

        private void rbtNameMode_CheckedChanged(object sender, EventArgs e)
        {
            if (TagSet == null) return;
            TagSet.SetValue(TagKey.ResponsePara_NameMode, rbtNameModeOn.Checked ? 1 : 0);
        }

        private void cboCanVote_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (TagSet == null) return;
                if (TagSet.ReadOnlyPPT) return;
                string cboValue = ((ComboItem)cboCanVote.Items[cboCanVote.SelectedIndex]).EnumValue;
                if (!readOnly)
                    Globals.SunVoteARSAddIn.ShowCanVoteSet(cboValue);
                //防止返回上次设置时反复调用ShowCanVoteSet方法
                readOnly = true;
                int index = ComboBoxOper.GetIndexByValue(cboCanVote, TagSet.LoadValue(TagKey.ResponsePara_CanVote, "cvAll").Value);
                cboCanVote.SelectedIndex = index;
                readOnly = false;
                //cboCanVote.SelectedIndex = TagSet.LoadValue(TagKey.ResponsePara_CanVote, 0).ToInt;
                //FrmVoteBar.ActivateSlideShowWindow();
            }
            catch (Exception ex)
            {
            }
        }

        /// <summary>
        /// 加载下拉框的值
        /// </summary>
        private void LoadComboBox()
        {
            cboCanVote.Items.Clear();
            cboCanVote.Items.Add(new ComboItem(0, "所有人", "cvAll"));
            cboCanVote.Items.Add(new ComboItem(1, "指定名单", "cvPerson"));
            cboCanVote.Items.Add(new ComboItem(2, "指定题目选项", "cvTopic"));
            cboCanVote.DisplayMember = "Name";
            cboCanVote.ValueMember = "EnumValue";
        }

        /// <summary>
        /// 权重字段。杨斌 2014-10-27
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cboFieldVoteRate_SelectedIndexChanged(object sender, EventArgs e)
        {
            //杨斌 2015-04-30
            if (TagSet == null) return;
            if (TagSet.ReadOnlyPPT) return;
            TagSet.SetValue(TagKey.ResponsePara_VoteRateField, cboFieldVoteRate.Text);
        }

        private void cboBackMusic_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!cboBackMusic.Enabled) return;
            if (readOnly) return;//杨斌 2015-04-13
            try
            {
                int max = cboBackMusic.Items.Count - 1;
                if (cboBackMusic.SelectedIndex == max)
                {
                    string path = FrmSystemSet.OpenSoundFile();
                    if (path.Length > 0)
                    {
                        FileInfo fi = new FileInfo(path);
                        if (!fi.Exists) return;
                        string file = fi.Name;

                        //若工程目录下没有则复制,总是取相对路径
                        string pathSound = GlobalInfo.SOUND_DIR + file;
                        if (!(new FileInfo(pathSound).Exists)) fi.CopyTo(pathSound, true);

                        TagSet.SetValue(TagKey.ResponsePara_SlideBackMusic, file);
                    }
                }
                else if (cboBackMusic.SelectedIndex == 0)
                {
                    TagSet.SetValue(TagKey.ResponsePara_SlideBackMusic, "");
                }
                else
                {
                    TagSet.SetValue(TagKey.ResponsePara_SlideBackMusic, cboBackMusic.Items[1].ToString());
                }
                LoadMusicSet();

            }
            catch (Exception ex)
            {

            }
        }

    }
}