PanelRankMVP.cs 11 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;

namespace SunVoteARSPPT
{
    public partial class PanelRankMVP : UserControl, IPanel, IPanelChange
    {
        TagSet mTagSet = null;
        public TagSet TagSet
        {
            get { return mTagSet; }
            set
            {
                mTagSet = value;
                //ucKeypadPara.TagSet = value;
            }
        }

        private bool IsGroupRank = false;

        private bool IsLoad = false;

        public PanelRankMVP()
        {
            InitializeComponent();

            //IsGroupRank = isGroup;

            FrmSystemSet.LanguageSetEvent += new FrmSystemSet.LanguageSetEventHander(FrmSystemSet_LanguageSetEvent);
            FrmVoteBar.PanelEnabledEvent += new FrmVoteBar.PanelEnabledEventHander(FrmVoteBar_PanelEnabledEvent);
            gbxRankSet.Resize += gbxRankSet_Resize;
            //设置控件大小
            //this.Height = ucKeypadPara.Bottom;
            GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
        }

        void gbxRankSet_Resize(object sender, EventArgs e)
        {
            int pos = gbxRankSet.ClientSize.Width / 2;
            int w = pos - 3;

            cboGroupType.Left = pos;
            cboGroupType.Width = w;

            cboColShow.Left = pos;
            cboColShow.Width = w;

            cboRankCount.Left = pos;
            cboRankCount.Width = w;

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

        private void InitType()
        {
            RosterList rost = new RosterList();
            if (rost.RosterEnabled)
                rost.LoadCloumn(GlobalInfo.DBOperation);
            cboColShow.Items.Clear();

            if (IsGroupRank)
            {
                gbxRankSet.Text = GlobalInfo.SysLanguage.LPT.ReadString("PanelRankMVP", "RankSetGroup", "分组排行设置");

                if (rost.RosterEnabled)
                {
                    for (int i = 1; i < rost.Columns.Count; i++)
                    {
                        cboColShow.Items.Add(rost.Columns[i].ColumnName);
                    }
                }
                Presentation pres = Globals.SunVoteARSAddIn.Application.ActivePresentation;
                if (pres != null)
                {
                    foreach (Slide sld in pres.Slides)
                    {
                        TagSet tagSet = new TagSet(sld.Tags);
                        ResponseType type = ResponseTypeName.GetEnum((tagSet.GetValue(TagKey.ResponseType).Value));
                        if (type == ResponseType.Group)
                        {
                            string groupName = tagSet.GetValue(TagKey.Slide_GroupName).Value;
                            //string title = PPTOper.GetSlideTitle(sld);
                            cboColShow.Items.Add(groupName);
                        }
                    }
                }

            }
            else
            {
                gbxRankSet.Text = GlobalInfo.SysLanguage.LPT.ReadString("PanelRankMVP", "RankSetVoter", "人员排行设置");

                if (rost.RosterEnabled)
                {
                    for (int i = 0; i < rost.Columns.Count; i++)
                    {
                        cboColShow.Items.Add(rost.Columns[i].ColumnName);
                    }
                }
                else
                {
                    cboColShow.Items.Add(GlobalInfo.SysLanguage.LPT.ReadString("FrmRankVoter", "KeypadID", "键盘编号"));
                }
            }

            cboRankCount.Items.Clear();
            for (int i = 1; i <= 10; i++)
            {
                cboRankCount.Items.Add(i.ToString());
            }

            cboRankMode.Items.Clear();
            cboRankMode.Items.Add(GlobalInfo.SysLanguage.LPT.ReadString("PanelRankMVP", "RankSetMode1", "向前累计"));
            cboRankMode.Items.Add(GlobalInfo.SysLanguage.LPT.ReadString("PanelRankMVP", "RankSetMode2", "上一张"));
            cboRankMode.Items.Add(GlobalInfo.SysLanguage.LPT.ReadString("PanelRankMVP", "RankSetMode3", "自定义选择"));
        }

        void FrmVoteBar_PanelEnabledEvent(bool enabled)
        {
            this.Enabled = enabled;
        }

        void FrmSystemSet_LanguageSetEvent()
        {
            GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
            //LoadData();//屏蔽此行。杨斌 2014-11-05
        }

        public Color PanelColor
        {
            get
            {
                return this.BackColor;
            }
            set
            {
                this.BackColor = value;
                //gbxChoise.BackColor = value;
            }
        }

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

            IsLoad = true;

            InitType();

            try
            {
                cboRankMode.SelectedIndex = TagSet.LoadValue(TagKey.RankChartRankMode, 0).ToInt;
            }
            catch
            {
                cboRankMode.SelectedIndex = 0;
            }

            string showName = TagSet.LoadValue(TagKey.RankChartColShow, "").Value;
            if ((showName.Length < 1) && (cboColShow.Items.Count > 0))
            {
                if ((GlobalInfo.response.ShowNameCol.Length > 0) && (cboRankMode.SelectedIndex == 0))
                {
                    if (cboColShow.Items.Contains(GlobalInfo.response.ShowNameCol))
                        showName = GlobalInfo.response.ShowNameCol;
                    else
                        showName = cboColShow.Items[0].ToString();
                }
                else
                    showName = cboColShow.Items[0].ToString();
            }
            ComboBoxOper.SetComboText(cboColShow, showName);
            //切换名单导致选择项为-1,重新选择。杨斌 2015-03-06
            if (cboColShow.SelectedIndex < 0)
            {
                if (cboColShow.Items.Count > 0)
                {
                    if (GlobalInfo.response.EnableList)
                    {
                        if (cboColShow.Items.Count >= 2)
                            showName = cboColShow.Items[1].ToString();
                    }
                    else
                        showName = cboColShow.Items[0].ToString();

                    ComboBoxOper.SetComboText(cboColShow, showName);
                }
            }            

            //杨斌 2014-09-12
            string setShow = TagSet.GetValue(TagKey.RankChartColShow).Value;
            if (setShow != showName)
            {
                bool btemp = TagSet.ReadOnlyPPT;
                TagSet.ReadOnlyPPT = false;
                TagSet.SetValue(TagKey.RankChartColShow, showName);
                TagSet.ReadOnlyPPT = btemp;
            }

            ComboBoxOper.SetComboText(cboRankCount, TagSet.LoadValue(TagKey.RankChartRankCount, "3").Value);


            //ucKeypadPara.LoadData();

            //ControlOper.TrySetNumericUpDownValue(nudOptionCount, TagSet.LoadValue(TagKey.Group_OptionCount, nudOptionCount.Value).ToInt);

            IsLoad = false;

            ShowRankChart(Globals.SunVoteARSAddIn.PPTEdit.SlideEdit, true);//beInit改成true。杨斌 2018-04-03
        }

        public void ChangeData(TagKey tagKey, object value)
        {
            //if (tagKey == TagKey.Group_OptionCount)
            //    ControlOper.TrySetNumericUpDownValue(nudOptionCount, TagSet.LoadValue(tagKey, nudOptionCount.Value).ToInt);
        }

        private void PanelRankChart_Load(object sender, EventArgs e)
        {
            //GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
            //InitType();
        }
        
        private void cboGroupType_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void cboColShow_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (IsLoad) return;
            ////if (TagSet.ReadOnlyPPT) return;
            //TagSet.SetValue(TagKey.RankChartColShow, cboColShow.Text);
            //ShowRankChart(Globals.SunVoteARSAddIn.PPTEdit.SlideEdit, true);//杨斌 2014-09-04
        }

        private void cboRankCount_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (IsLoad) return;
            ////if (TagSet.ReadOnlyPPT) return;
            //TagSet.SetValue(TagKey.RankChartRankCount, cboRankCount.Text);
            //ShowRankChart(Globals.SunVoteARSAddIn.PPTEdit.SlideEdit, true);//杨斌 2014-09-04
        }

        private void cboRankMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (IsLoad) return;
            ////if (TagSet.ReadOnlyPPT) return;
            //if (cboRankMode.SelectedIndex == 2)
            //{
            //    FrmChartRankSet frmSet = new FrmChartRankSet();
            //    frmSet.ShowDialog();
            //    if (frmSet.DialogResult != DialogResult.OK)
            //    {
            //        try
            //        {
            //            cboRankMode.SelectedIndex = TagSet.LoadValue(TagKey.RankChartRankMode, 0).ToInt;
            //        }
            //        catch
            //        {
            //            cboRankMode.SelectedIndex = 0;
            //        }
            //        return;
            //    }
            //}
            //TagSet.SetValue(TagKey.RankChartRankMode, cboRankMode.SelectedIndex);
            //ShowRankChart(Globals.SunVoteARSAddIn.PPTEdit.SlideEdit, true);//杨斌 2014-09-04
        }

        public void ShowRankChart(Slide sld, bool beInit)
        {
            return;
            //杨斌 2014-11-05
            if (FrmSystemSet.IsChangingLanguage)
                return;

            //int count = TagSet.GetValue(TagKey.RankChartRankCount).ToInt;
            //string[] aryOpt = new string[count];
            //double[] aryScore = new double[count];

            //for (int i = 0; i < count; i++)
            //{
            //    aryOpt[i] = "姓名" + (i + 1);
            //    aryScore[i] = 60 + i;
            //}

            //string optionText = PPTOper.FormatShapeOptionText(aryOpt);
            ////插入选项文本
            //Shape sha = PPTOper.GetOptionTextLinkShape(sld);
            //if (sha == null)
            //    PPTOper.AddShapeOptionText(sld, optionText, false);
            //else
            //    PPTOper.SetShapeOptionText(sha, optionText, false);

            //////2012-11-21 数据字体根据选项个数变化 赵丽
            //PPTOper.SetFontSize(count, TagSet);
            Shape shaCha = null;
            //bool beInit = true;//传参。杨斌 2014-09-04
            foreach (Shape s in sld.Shapes)
            {
                if (s.Name == "pic")
                {
                    shaCha = s;
                    //shaCha.Delete();
                    //beInit = false;//传参。杨斌 2014-09-04
                    break;
                }
            }

            Globals.SunVoteARSAddIn.PPTEdit.InitChart(beInit, sld);
        }

    }
}