PanelSlideCompChart.cs 6.08 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 PanelSlideCompChart : UserControl, IPanel, IPanelChange
    {
        TagSet mTagSet = null;
        public TagSet TagSet
        {
            get { return mTagSet; }
            set
            {
                mTagSet = value;
                //ucKeypadPara.TagSet = value;
            }
        }

        private bool IsLoad = false;

        public PanelSlideCompChart()
        {
            InitializeComponent();            

            FrmSystemSet.LanguageSetEvent += new FrmSystemSet.LanguageSetEventHander(FrmSystemSet_LanguageSetEvent);
            FrmVoteBar.PanelEnabledEvent += new FrmVoteBar.PanelEnabledEventHander(FrmVoteBar_PanelEnabledEvent);
            //设置控件大小
            this.Height = gbxSet.Bottom;
            GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
            gbxSet.Text = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnSlideCompChart", "对比分析");//杨斌 2014-12-12            
        }

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

        void FrmSystemSet_LanguageSetEvent()
        {
            GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
            gbxSet.Text = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnSlideCompChart", "对比分析");//杨斌 2014-12-12
        }

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

        /// <summary>
        /// 加载的Slide列表
        /// </summary>
        private List<int> LstSlideIds = new List<int>();

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

            LstSlideIds.Clear();
            cboSlide1.Items.Clear();
            cboSlide2.Items.Clear();
            Presentation pres = Globals.SunVoteARSAddIn.Application.ActivePresentation;
            for (int i = 1; i <= pres.Slides.Count; i++)
            {
                Slide sld = pres.Slides[i];
                ResponseType type = PPTOper.GetSlideType(sld);
                switch (type)
                {
                    case ResponseType.Group:
                    case ResponseType.Choice:
                    case ResponseType.Judge:
                    case ResponseType.Vote:
                    case ResponseType.Grade:
                        string title = i + ". " + PPTOper.GetSlideTitle(sld);
                        cboSlide1.Items.Add(title);
                        cboSlide2.Items.Add(title);
                        LstSlideIds.Add(sld.SlideID);
                        break;
                }

            }

            List<int> lstIds = GetSlideCompIds(Globals.SunVoteARSAddIn.PPTEdit.SlideEdit);
            if (lstIds.Count >= 1)
            {
                int n = LstSlideIds.IndexOf(lstIds[0]);
                if (n >= 0)
                    cboSlide1.SelectedIndex = n;
            }
            if (lstIds.Count >= 2)
            {
                int n = LstSlideIds.IndexOf(lstIds[1]);
                if (n >= 0)
                    cboSlide2.SelectedIndex = n;
            }

            IsLoad = false;

            Globals.SunVoteARSAddIn.PPTEdit.InitChart(false, Globals.SunVoteARSAddIn.PPTEdit.SlideEdit);
        }

        /// <summary>
        /// 获取比较的Slide
        /// 杨斌 2014-12-10
        /// </summary>
        /// <param name="sld"></param>
        /// <returns></returns>
        public static List<int> GetSlideCompIds(Slide sld)
        {
            List<int> res = new List<int>();
            try
            {
                TagSet tagSet = new TagSet(sld.Tags);
                string sIds = tagSet.GetValue(TagKey.SlideCompChartIds).Value;
                string[] aryId = sIds.Split(new char[] { ',' });

                foreach (string sId in aryId)
                {
                    int nId = ConvertOper.Convert(sId).ToInt;
                    Slide sldFind = null;
                    try
                    {
                        sldFind = Globals.SunVoteARSAddIn.Application.ActivePresentation.Slides.FindBySlideID(nId);
                    }
                    catch { }
                    if (sldFind != null)
                        res.Add(nId);
                }
            }
            catch (Exception ex)
            {
                SystemLog.WriterLog(ex);
            }
            return res;
        }

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

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

        private string GetSlideIdsSet()
        {
            string res = "";
            try
            {
                if (cboSlide1.SelectedIndex >= 0)
                {
                    res += LstSlideIds[cboSlide1.SelectedIndex].ToString();
                }
                if (cboSlide2.SelectedIndex >= 0)
                {
                    if (res.Length > 0)
                        res += ",";
                    res += LstSlideIds[cboSlide2.SelectedIndex].ToString();
                }
            }
            catch { }
            return res;
        }

        private void cboSlide_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (IsLoad) return;
            TagSet.SetValue(TagKey.SlideCompChartIds, GetSlideIdsSet());
            Globals.SunVoteARSAddIn.PPTEdit.InitChart(false, Globals.SunVoteARSAddIn.PPTEdit.SlideEdit);
        }

    }
}