/*-------------------------------------------------------------------------------------------
* 与PPT内容相关的操作,如:标题,选项文本
* 创建:杨斌 2011-11-23
* 修改:杨斌 2012-03-13
* ----------------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.PowerPoint;
using System.Windows.Forms;
using System.IO;
using GeneralLib;
using System.Diagnostics;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;
using System.Drawing;
namespace SunVoteARSPPT
{
///
/// 与PPT内容相关的操作
///
public class PPTOper
{
private const string PPT_DataBase = "ARS_PPTDB";
private const string PPT_DataBaseID = "ARS_PPT_DBName";
public static string GetSlideTitle(Slide slide)
{
string res = "";
try
{
if (slide.Shapes.HasTitle == Microsoft.Office.Core.MsoTriState.msoTrue)
{
res = slide.Shapes.Title.TextFrame.TextRange.Text;
res = res.Replace("\v", "\r\n");//杨斌 2014-07-21
if (res == "")
res = "Slide " + slide.SlideIndex;
}
else//杨斌 2014-06-03
{
foreach (Shape sha in slide.Shapes)
{
switch (sha.Type)
{
case Microsoft.Office.Core.MsoShapeType.msoTextBox:
case Microsoft.Office.Core.MsoShapeType.msoPlaceholder://杨斌 2014-06-06
if (res.Length > 0)
res += "\r\n";
if (sha.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue)
res += sha.TextFrame.TextRange.Text;
break;
}
}
}
if (res.Length < 1)//杨斌 2014-06-03
res = "Slide " + slide.SlideIndex;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 获取内容
/// 杨斌 2014-06-06
///
///
///
public static string GetSlideInfo(Slide slide)
{
string res = "";
try
{
Shape shaT = null;
int idT = 0;
if (slide.Shapes.HasTitle == Microsoft.Office.Core.MsoTriState.msoTrue)
{
shaT = slide.Shapes.Title;
idT = shaT.Id;
res = shaT.TextFrame.TextRange.Text;
res = res.Replace("\v", "\r\n");//杨斌 2014-07-21
if (res == "")
res = "Slide " + slide.SlideIndex;
}
foreach (Shape sha in slide.Shapes)
{
if (sha.Id != idT)
{
switch (sha.Type)
{
case Microsoft.Office.Core.MsoShapeType.msoTextBox:
case Microsoft.Office.Core.MsoShapeType.msoPlaceholder:
if (res.Length > 0)
res += "\r\n\r\n";
if (sha.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue)
res += sha.TextFrame.TextRange.Text;
break;
}
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 删除幻灯片TAG值
///
///
///
public static void RemoveTags(TagSet tagSet, string key)
{
try
{
int[] delIndex = new int[tagSet.Tags.Count];
string[] delName = new string[tagSet.Tags.Count];
int j = 0;
string s = "";
for (int i = 1; i <= tagSet.Tags.Count; i++)
{
if (tagSet.Tags.Name(i).IndexOf(key.ToUpper()) > 0)
{
j++;
delIndex[j] = i;
delName[j] = tagSet.Tags.Name(i).ToString();
}
}
if (delIndex == null) { return; }
//索引变化
j = 0;
//2012-10-12 赵丽 根据名称删除,索引变化 更改选项答案设置清空的问题
for (int i = 0; i < delName.Length; i++)
{
try
{
if (delName[i] != null)
tagSet.Tags.Delete(delName[i]);
}
catch { }
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 清空名单授权
///
public static void ClearPersonAuthor()
{
try
{
foreach (Slide slide in Globals.SunVoteARSAddIn.PPTEdit.PPT.ActivePresentation.Slides)
{
TagSet tagSet = new TagSet();
tagSet.Tags = slide.Tags;
for (int i = 1; i <= tagSet.Tags.Count; i++)
{
RemoveTags(tagSet, "ResponsePara_CanVoteGroup");
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
public static string GetOrderCorrectAnwser(TagSet tagSet)
{
string Anwser = tagSet.LoadValue(TagKey.Order_CorrectAnswer, "").Value;
try
{
string[] ary;
ary = Anwser.Split(',');
Anwser = "";
for (int i = 0; i < ary.Length; i++)
{
if (ary[i] != "")
{
if (ary[i] == "10")
ary[i] = "0";
Anwser += ary[i];
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return Anwser;
}
public static string FormatNumABC(int num, bool addNum)
{
string res = num.ToString();
try
{
res = Convert.ToChar(64 + num).ToString();
if (addNum)
res = num + "/" + res;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 转换:"1,2,10"为"A,B,J"
/// 创建:杨斌 2012-06-27
/// 修改:杨斌 2012-07-02
///
///
///
public static string FormatNumABC(string numberList)
{
string res = numberList;
try
{
string[] ary = numberList.Split(new char[] { ',' });
for (int i = 0; i < ary.Length; i++)
{
int num = ConvertOper.Convert(ary[i]).ToInt;
if ((num >= 1) && (num <= 26))
ary[i] = FormatNumABC(num, false);
}
res = string.Join(",", ary);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// ABC转为1,2,3
/// 杨斌 2014-02-19
///
///
///
public static string FormartABCNum(string abcList)
{
string res = abcList;
try
{
List lstNum = new List();
string[] ary = abcList.Split(new char[] { ',' });
for (int i = 0; i < ary.Length; i++)
{
int num = ConvertOper.Convert(ary[i]).ToInt;
if ((num >= 1) && (num <= 10))
{
string sNum = num.ToString();
if (!lstNum.Contains(sNum))
lstNum.Add(sNum);
}
}
abcList = abcList.ToUpper();
for (int i = 0; i < abcList.Length; i++)
{
int num = Convert.ToInt32(abcList[i]) - 64;
if ((num >= 1) && (num <= 10))
{
string sNum = num.ToString();
if (!lstNum.Contains(sNum))
lstNum.Add(sNum);
}
}
res = string.Join(",", lstNum.ToArray());
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 123..0->ABC..J
/// 创建:杨斌 2012-10-22
///
///
///
public static string FormatNumABCEx(string numberList)
{
string res = "";
try
{
for (int i = 0; i < numberList.Length; i++)
{
string s = numberList.Substring(i, 1);
string option = s;
switch (s)
{
case "1":
option = "A";
break;
case "2":
option = "B";
break;
case "3":
option = "C";
break;
case "4":
option = "D";
break;
case "5":
option = "E";
break;
case "6":
option = "F";
break;
case "7":
option = "G";
break;
case "8":
option = "H";
break;
case "9":
option = "I";
break;
case "0":
option = "J";
break;
default:
break;
}
res = res + option;
}
}
catch (Exception ex)
{
res = numberList;
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 从幻灯片ID查询选项是否为ABCD格式
/// 创建:杨斌 2012-06-29
///
///
///
public static bool IsABCDItemBySlideId(int slideId)
{
bool bABCD = false;
Presentation pres = Globals.SunVoteARSAddIn.Application.ActivePresentation;
if (pres != null)
{
try
{
Slide sldFind = pres.Slides.FindBySlideID(slideId);
if (sldFind != null)
{
TagSet tagSetFind = new TagSet(sldFind.Tags);
bABCD = (tagSetFind.GetValue(TagKey.KeypadPara_OptionMode).ToInt == 1);
}
}
catch { }
}
return bABCD;
}
///
/// 设置幻灯片标题,调试用。杨斌 2015-05-21
///
///
public static void SetSlideShowTitle(string txt)
{
try
{
Slide sld = null;
Shape sha = null;
try
{
sld = Globals.SunVoteARSAddIn.PPTShow.SlideShow;
if (sld.Shapes.HasTitle == Microsoft.Office.Core.MsoTriState.msoTrue)
sha = sld.Shapes.Title;
if (sha == null)
return;
}
catch { }
sha.TextFrame.TextRange.Text = txt;
sha.TextFrame.TextRange.Font.Size = 20;
}
catch (Exception ex)
{
//SystemLog.WriterLog(ex, false);
}
}
///
/// 设置幻灯片标题,无标题或内容为空才设置
///
///
///
public static void SetSlideTitle(Slide slide, string title)
{
if (slide == null) return;
try
{
Shape shaTitle = null;
if (slide.Shapes.HasTitle == Microsoft.Office.Core.MsoTriState.msoTrue)
{
shaTitle = slide.Shapes.Title;
}
else
{
try
{
shaTitle = slide.Shapes.AddTitle();//不是带标题样式会报错
}
catch { }
}
if (shaTitle != null)
{
TagSet tagSet = new TagSet(shaTitle.Tags);
bool bSet = false;
if (shaTitle.TextFrame.TextRange.Text.Length > 0)
bSet = (tagSet.GetValue(TagKey.SlideTitle_AutoSet).ToInt == 1);
else
bSet = true;
if (bSet)
{
//判断文本是否需要改变,以免使ppt文件没修改也提示要保存 杨斌 2012-03-02
if (shaTitle.TextFrame.TextRange.Text != title)
{
shaTitle.TextFrame.TextRange.Text = title;
tagSet.SetValue(TagKey.SlideTitle_AutoSet, 1);
tagSet.SetValue(TagKey.SlideTitle_AutoSetText, title);
}
}
shaTitle.Top = 10;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
///
/// 获取新建或转换的反馈类型标题
/// 创建:杨斌 2012-05-29
///
/// 反馈类型
/// 子类型,从0开始,如判断的Yes/No,True/False,Wright/Wrong
///
public static string GetTitleSlide(ResponseType type, int style)
{
string title = "Title";
try
{
switch (type)
{
case ResponseType.SignIn:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleSignIn", "请签到");//Please sign in.
break;
case ResponseType.Group:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleGroup", "请选择分组");//Please select team.
break;
case ResponseType.Choice:
//2012-08-01 日本更新
switch (style)
{
case 0://单选
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleChoice", "请选择...");//Please make your selection...
break;
case 1://多选
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleChoice_M", "请选择...");//Please make your selection...
break;
}
break;
case ResponseType.Judge:
switch (style)
{
case 0://Yes No
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleJudgeYesNo", "您的判断是?");//Do you agree?
break;
case 1://True False
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleJudgeTrueFalse", "您的判断是?");//What is your opinion?
break;
case 2://Wright Wrong
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleJudgeRightWrong", "您的判断是?");//What is your opinion?
break;
}
break;
case ResponseType.Order:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleOrder", "请排列顺序");//Please make your sorting.
break;
case ResponseType.Number:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleNumber", "请给出数值");//Please give your number.
break;
case ResponseType.Text://杨斌 2015-01-12
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleText", "请输入文本");//Please give your text.
break;
case ResponseType.Vote:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleVote", "请表决");//Do you agree?
break;
case ResponseType.Grade:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleGrade", "您的意见是?");//What is your opinion?
break;
case ResponseType.Score:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitleScore", "请给出您的分数");//Please give your score.
break;
case ResponseType.Poll:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "TitlePoll", "请投出您的选票号码");//Please make your polling.
break;
case ResponseType.ScoreRankChart://杨斌 2014-08-07
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnRankVoter", "人员排行"); ;
break;
case ResponseType.ScoreRankGroupChart:
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnRankGroup", "分组排行"); ;
break;
case ResponseType.ScoreRankGroupMVP://杨斌 2015-06-03
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnRankChartGroupMVP", "团队最佳个人排行"); ;
break;
case ResponseType.SlideCompChart:
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnSlideCompChart", "对比分析"); ;
break;
case ResponseType.SlideCompGroup://杨斌 2017-01-19
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnAnalyzeSlideGroup", "分组对比");
break;
case ResponseType.OperatorSlide://杨斌 2015-07-22
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "OperatorSlide", "To start the presentation please enter your name:");
break;
case ResponseType.CompVote://杨斌 2017-06-07
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnCompVote", "YNA Result");
break;
default:
break;
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return title;
}
///
/// 获取转换的反馈类型标题,子类型默认为新建子菜单的其中一种样式
/// 创建:杨斌 2012-05-29
///
/// 反馈类型
///
public static string GetTitleSlide(ResponseType type)
{
return GetTitleSlide(type, 0);
}
public static string GetChoiseTitle(ResponseType type, int style)
{
return GetTitleSlide(type, style);
}
///
/// 获取幻灯片反馈类型标题,以后需改成从语言包读取
/// 说明:这里用作:反馈类型描述语言 杨斌 2012-02-14
/// 修改:杨斌 2012-05-29
///
///
///
public static string GetTitle(ResponseType type)
{
string title = "";
try
{
switch (type)
{
case ResponseType.SignIn:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "SignIn", "签到");
break;
case ResponseType.Group:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "Group", "分组");
break;
case ResponseType.Choice:
////修改标志 赵丽 2012-05-04 区分单选和多选的标题
//TagSet tagSet = new TagSet();
//if (Globals.SunVoteARSAddIn.PPTShow.IsShowSlide)
// tagSet.Tags = Globals.SunVoteARSAddIn.PPTShow.SlideShow.Tags;
//else
// tagSet.Tags = Globals.SunVoteARSAddIn.PPTEdit.SlideEdit.Tags;
//int iCount = tagSet.GetValue(TagKey.Choice_OptionLimit).ToInt;
//if (iCount == 1)
// title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "SingleChoice", "单选");
//else
// title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "MultiChoice", "多选");
//上面代码判断单选多选不正确,暂只显示选择。杨斌 2012-05-29
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "Choice", "选择");
break;
case ResponseType.Judge:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "Judge", "判断");
break;
case ResponseType.Order:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "Order", "排序");
break;
case ResponseType.Number:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "Number", "数字");
break;
case ResponseType.Vote:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "Vote", "表决");
break;
case ResponseType.Grade:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "Grade", "评议");
break;
case ResponseType.Score:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "Score", "评分");
break;
case ResponseType.Poll:
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "Poll", "选举");
break;
case ResponseType.ScoreRankChart://杨斌 2014-08-07
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnRankVoter", "人员排行"); ;
break;
case ResponseType.ScoreRankGroupChart:
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnRankGroup", "分组排行"); ;
break;
case ResponseType.ScoreRankGroupMVP://杨斌 2015-06-03
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnRankChartGroupMVP", "团队最佳个人排行"); ;
break;
case ResponseType.SlideCompChart://杨斌 2014-12-10
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnSlideCompChart", "对比分析"); ;
break;
case ResponseType.SlideCompGroup://杨斌 2017-01-19
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnAnalyzeSlideGroup", "分组对比"); ;
break;
case ResponseType.OperatorSlide://杨斌 2015-07-22
title = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "OperatorSlide", "To start the presentation please enter your name:"); ;
break;
case ResponseType.CompVote://杨斌 2017-06-07
title = GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "btnCompVote", "Number Vote Result");
break;
default:
break;
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return title;
}
///
/// 获取选项文本数组,创建模板用
/// 修改:杨斌 2012-05-29
///
/// 反馈类型
/// 选项个数
///
public static string[] GetOptionText(ResponseType type, int count, int maxOption = 10)
{
if (count < 1) return null;
//杨斌 2018-02-02
if (count > maxOption)
count = maxOption;
string[] ary = new string[count];
try
{
switch (type)
{
case ResponseType.SignIn:
if (count >= 1)
ary[0] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "Signed", "已签到");
if (count >= 2)
ary[1] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "UnSignIn", "未签到");
if (count >= 3)
ary[2] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "SignFail", "签到失败");
break;
case ResponseType.Group:
for (int i = 0; i < count; i++)
ary[i] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "GroupOption", "分组") + (i + 1).ToString();
break;
case ResponseType.Choice:
for (int i = 0; i < count; i++)
ary[i] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "ChoiceOption", "选项") + (i + 1).ToString();
break;
case ResponseType.Judge://是否,对错,TrueFalse
ary[0] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "JudgeYes", "是");
ary[1] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "JudgeNo", "否");
break;
case ResponseType.Order:
for (int i = 0; i < count; i++)
ary[i] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "OrderOption", "选项") + (i + 1).ToString();
break;
case ResponseType.Number:
ary = null;
break;
case ResponseType.Vote:
if (count >= 1)
ary[0] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "VoteAgree", "赞成");
if (count >= 2)
ary[1] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "VoteAgainst", "反对");
if (count >= 3)
ary[2] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "VoteAbstain", "弃权");
break;
case ResponseType.Grade:
for (int i = 0; i < count; i++)
ary[i] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "GradeOption", "选项") + (i + 1).ToString();
break;
case ResponseType.Score:
ary = null;
break;
case ResponseType.Poll:
ary = null;
break;
default:
ary = null;
break;
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return ary;
}
///
/// 从幻灯片获取选项文本
/// 创建:杨斌 2012-03-26
///
///
///
public static string[] GetOptionTextBySlide(Slide slide)
{
string[] res = null;
try
{
Shape sha = GetOptionTextLinkShape(slide);
if (sha != null)
{
res = GetShapeOptionText(sha);
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
return res;
}
///
/// 获取对象的选项文本
///
///
///
public static string[] GetShapeOptionText(Shape shape)
{
string[] split = new string[1];
if (shape == null) return null;
if (shape.HasTextFrame != Microsoft.Office.Core.MsoTriState.msoTrue) return null;
string[] ary = null;
try
{
string text = shape.TextFrame.TextRange.Text;
//if (text.IndexOf("\r") == -1)
// split[0] = "\n";
//else
// split[0] = "\r";
//杨斌 2012-03-05 格式化\r\n
text = text.Replace("\r\n", "\r");
text = text.Replace("\n", "\r");
split[0] = "\r";
ary = text.Split(split, 0);
//去掉多余的空行
string[] ary2 = null;
if (ary.Length > 1)
{
List lst = new List();
for (int i = 0; i < ary.Length; i++)
{
if (ary[i].Length > 0)
lst.Add(ary[i]);
}
ary2 = new string[lst.Count];
lst.CopyTo(ary2);
ary = ary2;
}
for (int i = 0; i < ary.Length; i++)
ary[i] = ary[i].Replace("\v", "\r\n");
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return ary;
}
///
/// 从幻灯片获取选项文本
///
///
///
public static string[] GetOptionTextBySlide(Slide sld, int optionCount)
{
if (optionCount < 1) return null;
string[] res = new string[optionCount];
for (int i = 0; i < res.Length; i++)//杨斌 2014-08-13
res[i] = (i + 1).ToString();
try
{
if (sld != null) //杨斌 2014-08-13
{
if (sld.Tags != null) //杨斌 2014-08-14
{
TagSet tagSet = new TagSet(sld.Tags);
Shape sha = GetOptionTextLinkShape(sld);
if (sha != null)
{
string[] ary = GetShapeOptionText(sha);
for (int i = 0; i < optionCount; i++)
{
if (i < ary.Length)
res[i] = ary[i];
}
}
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
return res;
}
///
/// 格式化数组为对象文本
///
///
///
public static string FormatShapeOptionText(string[] aryOptionText)
{
if (aryOptionText == null) return "";
string text = "";
try
{
//文本
for (int i = 0; i < aryOptionText.Length; i++)
{
//aryOptionText[i] = aryOptionText[i].Replace("\r\n", "\v");
//杨斌 2012-03-14
aryOptionText[i] = aryOptionText[i].Replace("\r\n", "\r");
aryOptionText[i] = aryOptionText[i].Replace("\n", "\r");
aryOptionText[i] = aryOptionText[i].Replace("\r", "\v");
}
text = string.Join("\r\n", aryOptionText);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return text;
}
///
/// 添加数字题模板
///
///
public static void SetNumberTempText(Shape shape)
{
try
{
shape.TextFrame.TextRange.Text = "9*3+(5-2)=?";
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 设置文本形状格式:1234,ABCD
/// 创建:杨斌 2012-06-26
///
///
///
public static void SetShapeOptionFormat(Shape shape, bool bABCD)
{
if (shape == null) return;
try
{
if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoFalse) return;//杨斌 2014-06-03
shape.TextFrame.TextRange.Paragraphs(-1, -1).ParagraphFormat.Alignment = PpParagraphAlignment.ppAlignLeft;
if (shape.TextFrame.TextRange.Paragraphs(-1, -1).ParagraphFormat.Bullet.Type != PpBulletType.ppBulletNumbered)
shape.TextFrame.TextRange.Paragraphs(-1, -1).ParagraphFormat.Bullet.Type = PpBulletType.ppBulletNumbered;
shape.TextFrame.TextRange.Paragraphs(-1, -1).ParagraphFormat.Bullet.Style =
bABCD ? PpNumberedBulletStyle.ppBulletAlphaUCPeriod : PpNumberedBulletStyle.ppBulletArabicPeriod;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// ToDo:自动搜索选项文本,并设置为题目选项
/// 杨斌 2012-03-02
///
///
///
///
public static bool SetSlideOptionText(Slide slide, bool bABCD)
{
return false;
}
///
/// 添加文本。
/// 杨斌 2015-01-14
///
///
///
///
public static Shape AddShapeText(Slide slide, ChartPositon cp, string text, float fontSize)
{
Shape shape = null;
if (slide == null) return shape;
try
{
//插入对象
shape = slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
cp.Left, cp.Top, cp.Width, cp.Height);
//文本
shape.TextFrame.TextRange.Text = text;
//字体
shape.TextFrame.TextRange.Font.Size = fontSize;//字体大小
shape.TextFrame2.AutoSize = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
//行距
//shape.TextFrame.TextRange.ParagraphFormat.LineRuleWithin = Microsoft.Office.Core.MsoTriState.msoTrue;
//shape.TextFrame.TextRange.ParagraphFormat.SpaceWithin = 1;
//重新设定高度
shape.Height = (slide.Master.Height - shape.Top - slide.Master.Height / 20) - 28;
shape.TextFrame.VerticalAnchor = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorMiddle;
shape.TextFrame.HorizontalAnchor = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
shape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendToBack);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return shape;
}
///
/// 添加一个选项文本框
///
///
///
///
///
public static Shape AddShapeOptionText(Slide slide, string optionText, bool bABCD)
{
Shape shape = null;
if (slide == null) return shape;
if (optionText == null) return shape;
if (optionText.Length < 1) return shape;
try
{
//插入对象
shape = slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
slide.Master.Width / 20, (slide.Master.Height / (float)4.5) - 28, slide.Master.Width / 2, (slide.Master.Height / 3) - 28);
//文本
SetShapeOptionText(shape, optionText, bABCD);
//字体
shape.TextFrame.TextRange.Font.Size = 22;//字体大小
shape.TextFrame2.AutoSize = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
//行距
shape.TextFrame.TextRange.ParagraphFormat.LineRuleWithin = Microsoft.Office.Core.MsoTriState.msoTrue;
shape.TextFrame.TextRange.ParagraphFormat.SpaceWithin = 2;
//重新设定高度
shape.Height = (slide.Master.Height - shape.Top - slide.Master.Height / 20) - 28;
SetOptionTextLinkShape(slide, shape);//自动关联
shape.Name = "optionText";
shape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendToBack);
//设置字体,并且修改日语语言包(选项文本:選択肢->オプション)。杨斌 2012-11-12
try
{
string fontName = GlobalInfo.SysLanguage.GetSysFontName();
//shape.TextFrame.TextRange.Font.Name = fontName;//不更改字体。杨斌 2014-11-05
}
catch { }
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return shape;
}
///
/// 设置对象的选项文本
///
///
///
///
public static void SetShapeOptionText(Shape shape, string optionText, bool bABCD)
{
if (shape == null) return;
if (optionText == null) return;
if (optionText.Length < 1) return;
try
{
//文本
shape.TextFrame.TextRange.Text = optionText;
//编号格式
//shape.TextFrame.TextRange.Paragraphs(-1, -1).ParagraphFormat.Alignment = PpParagraphAlignment.ppAlignLeft;
//杨斌 2014-08-06
if (shape.TextFrame.TextRange.Paragraphs(-1, -1).ParagraphFormat.Bullet.Type != PpBulletType.ppBulletNumbered)
shape.TextFrame.TextRange.Paragraphs(-1, -1).ParagraphFormat.Bullet.Type = PpBulletType.ppBulletNumbered;
PpNumberedBulletStyle style = bABCD ? PpNumberedBulletStyle.ppBulletAlphaUCPeriod : PpNumberedBulletStyle.ppBulletArabicPeriod;
if (shape.TextFrame.TextRange.Paragraphs(-1, -1).ParagraphFormat.Bullet.Style != style)
shape.TextFrame.TextRange.Paragraphs(-1, -1).ParagraphFormat.Bullet.Style = style;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 设置指定文本对象为选项文本
/// 创建:杨斌 2013-01-25
///
///
///
public static void SetShapeOptionText(Shape shape, bool bABCD)
{
if (shape == null) return;
Slide slide = (Slide)(shape.Parent);
string[] ary = null;
string optionText = "";
try
{
//文本
ary = GetShapeOptionText(shape);
optionText = PPTOper.FormatShapeOptionText(ary);
TagSet tagSet = new TagSet(slide.Tags);
//重新设置选项文本
tagSet.SetValue(TagKey.Slide_OptionText, optionText);
////2012-11-21 数据字体根据选项个数变化 赵丽
//PPTOper.SetFontSize(optionCount, tagSet);
//字体
shape.TextFrame.TextRange.Font.Size = 22;//字体大小
shape.TextFrame2.AutoSize = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
//行距
shape.TextFrame.TextRange.ParagraphFormat.LineRuleWithin = Microsoft.Office.Core.MsoTriState.msoTrue;
shape.TextFrame.TextRange.ParagraphFormat.SpaceWithin = 2;
//重新设定高度
shape.Height = (slide.Master.Height - shape.Top - slide.Master.Height / 20) - 28;
SetOptionTextLinkShape(slide, shape);//自动关联
//shape.Name = "optionText";
shape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendToBack);
//设置字体,并且修改日语语言包(选项文本:選択肢->オプション)。杨斌 2012-11-12
try
{
string fontName = GlobalInfo.SysLanguage.GetSysFontName();
}
catch { }
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
public static void AddRankTable(Slide slide, int iCount)
{
if (iCount == 0) return;
if (iCount > 50) iCount = 50;
int tableCount = Convert.ToInt32(iCount / 10) + ((iCount % 10) > 0 ? 1 : 0);
float tableWidth = (slide.Master.Width - 20) / tableCount;
for (int i = 0; i < 5; i++)
{
foreach (Shape s in slide.Shapes)
{
if (s.Name == "PollRank" + i.ToString())
s.Delete();
}
}
for (int i = 0; i < tableCount; i++)
{
Shape sha = slide.Shapes.AddTable(11, 2, i * tableWidth + 10, 80, tableWidth, 380);
sha.Name = "PollRank" + i.ToString();
//sha.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankPoll", "dgvRank_0", "名次");
sha.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankPoll", "dgvRank_1", "候选人编号");
sha.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankPoll", "dgvRank_2", "候选人名称");
sha.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendToBack);
}
//sha.Table.Cell(1, 4).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankPoll", "dgvRank_3", "票数");
}
///
/// 添加数字题模板
///
///
///
public static Shape AddShapeNumberTemp(Slide slide)
{
Shape shape = null;
if (slide == null) return shape;
foreach (Shape sha in slide.Shapes)
{
if (sha.Name == "NumberTemp") { return shape; }
}
shape = slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
slide.Master.Width / 20, slide.Master.Height / (float)4.5, slide.Master.Width / 2, slide.Master.Height / 3);
SetNumberTempText(shape);
shape.TextFrame.TextRange.Font.Size = 40;
shape.TextFrame2.AutoSize = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;
//行距
shape.TextFrame.TextRange.ParagraphFormat.LineRuleWithin = Microsoft.Office.Core.MsoTriState.msoTrue;
shape.TextFrame.TextRange.ParagraphFormat.SpaceWithin = 2;
//重新设定高度
shape.Height = slide.Master.Height - shape.Top - slide.Master.Height / 20 - 100;
shape.Name = "NumberTemp";
shape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendToBack);
return shape;
}
///
/// 设置关联选项文本的Shape
/// 若关联,对象文本与Tags选项文本同步
///
/// 幻灯片
/// 关联的对象,null=不关联
public static void SetOptionTextLinkShape(Slide slide, Shape shape)
{
if (slide == null) return;
try
{
TagSet tagSet = new TagSet(slide.Tags);
if (shape != null)
tagSet.SetValue(TagKey.Slide_OptionText_ShapeID, shape.Id.ToString());
else
tagSet.SetValue(TagKey.Slide_OptionText_ShapeID, "");
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
}
///
/// 获取关联选项文本的Shape
///
///
///
public static Shape GetOptionTextLinkShape(Slide slide)
{
if (slide == null) return null;
Shape shape = null;
Shape shapeTemp = null;
try
{
TagSet tagSet = null;
try
{
tagSet = new TagSet(slide.Tags);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
if (tagSet == null)
return shape;
int id = tagSet.GetValue(TagKey.Slide_OptionText_ShapeID).ToInt;
if (id > 0)
{
for (int i = 1; i <= slide.Shapes.Count; i++)
{
shapeTemp = slide.Shapes[i];
if (shapeTemp != null)
{
try
{
if (shapeTemp.Id == id)
{
shape = shapeTemp;
break;
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
}
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return shape;
}
///
/// 插入表格
///
///
///
///
public static Shape InsertDataTable(DataTabAttributes dt, Slide SlideEdit)
{
Shape res = null;
try
{
//生成标签
if (dt.Style == "AVGScoreTableGroup")
{
string group = "";
Dictionary dicG = FrmScoreGroupRate.GetDicScoreGroupRate(SlideEdit, out group);
Shape sha = null;
if (dicG.Count > 0)
{
//杨斌 2015-11-24
sha = SlideEdit.Shapes.AddTable(dicG.Count + 1, 4, dt.Left, dt.Top, dt.Width, dt.Height);
int row = 1;
sha.Table.Cell(row, 1).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "ScoreGroupTitle", "组别");
sha.Table.Cell(row, 2).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "participate", "参与人数");
sha.Table.Cell(row, 3).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "votingnumber", "反馈人数");
sha.Table.Cell(row, 4).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "ScoreGroupAVG", "平均分");
foreach (var v in dicG)
{
row++;
sha.Table.Cell(row, 1).Shape.TextFrame.TextRange.Text = v.Key;
sha.Table.Cell(row, 2).Shape.TextFrame.TextRange.Text = "0";
sha.Table.Cell(row, 3).Shape.TextFrame.TextRange.Text = "0";
sha.Table.Cell(row, 4).Shape.TextFrame.TextRange.Text = "0";//v.Value.ToString();
for (int col = 1; col <= sha.Table.Columns.Count; col++)
{
sha.Table.Cell(1, col).Shape.TextFrame.TextRange.Font.Color.RGB = Color.Black.ToArgb();
sha.Table.Cell(1, col).Shape.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoFalse;
}
sha.ThreeD.ContourWidth = 0;
}
for (int i = 1; i <= sha.Table.Rows.Count; i++)
{
for (int col = 1; col <= sha.Table.Columns.Count; col++)
{
sha.Table.Cell(i, col).Shape.TextFrame.TextRange.Font.Size = 15;
}
}
}
if (sha != null)
{
sha.Name = dt.Style;
res = sha;
}
}
else if (dt.Style == "AVGScoreTableGroupDetail")
{
Shape sha = null;
//杨斌 2015-11-24
sha = SlideEdit.Shapes.AddTable(11, 3, dt.Left, dt.Top, dt.Width, dt.Height);
int row = 1;
sha.Table.Cell(row, 1).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "ScoreGroupDetailNo", "键盘编号");
sha.Table.Cell(row, 2).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "ScoreGroupDetailName", "姓名");
sha.Table.Cell(row, 3).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "ScoreGroupDetailScore", "分数");
sha.ThreeD.ContourWidth = 0;
for (int i = 1; i <= sha.Table.Rows.Count; i++)
{
for (int col = 1; col <= sha.Table.Columns.Count; col++)
{
sha.Table.Cell(i, col).Shape.TextFrame.TextRange.Font.Size = 13;
sha.Table.Cell(i, col).Shape.TextFrame.TextRange.Font.Color.RGB = Color.Black.ToArgb();
sha.Table.Cell(i, col).Shape.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoFalse;
}
}
if (sha != null)
{
sha.Name = dt.Style;
res = sha;
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
return res;
}
return res;
}
///
/// 插入标签
/// 修改:杨斌 2012-03-13
///
///
///
public static Shape InsertDataTab(DataTabAttributes dt, Slide SlideEdit)
{
Shape res = null;
//如果页面已有该类型的数据标签,则不再添加
foreach (Shape shape in SlideEdit.Shapes)
if (shape.Name == dt.Style)
return res;
try
{
//生成标签
Shape sha = SlideEdit.Shapes.AddShape(dt.ShapeType, dt.Left, dt.Top, dt.Width, dt.Height);
res = sha;
//设置标签名称
sha.Name = dt.Style;
//设置标签字体粗细
sha.TextFrame.TextRange.Font.Bold = dt.FontBold;
//设置文本内容
sha.TextFrame.TextRange.Text = dt.Text;
//设置字体大小
sha.TextFrame.TextRange.Font.Size = dt.FontSize;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
return res;
}
return res;
}
///
/// 是否存在数据标签
/// 0-计时器,1-应到人数,2-反馈人数,3-正确答案,4-答对人数,5-评分总分,6-评分平均分,
/// 7-反馈人数百分比,8-反馈人数数值+百分比,9-答对人数百分比,10-答对人数数值+百分比,11-参与人数
/// 创建:杨斌 2012-03-13
///
/// 标签类型
/// 当前编辑的幻灯片
///
public static bool HasDataTab(int type, Slide SlideEdit)
{
bool bType = false;
try
{
DataTabAttributes dt = new DataTabAttributes(type);
if (SlideEdit != null)
{
foreach (Shape shape in SlideEdit.Shapes)
{
if (shape.Name == dt.Style)
{
bType = true;
}
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return bType;
}
///
/// 设置数据标签的位置
/// 修改:杨斌 2014-04-14
///
///
public static void SetDataTabPosition(Slide slide)
{
Dictionary dicShape = new Dictionary();
dicShape.Add("DUENO", null);
dicShape.Add("SIGNED", null);//实到人数。杨斌 2018-12-25
dicShape.Add("NOTSIGNED", null);//未到人数。杨斌 2019-01-14
dicShape.Add("PARTICIPATE", null);//参与人数在反馈人数前。杨斌 2014-07-22
dicShape.Add("VOTENO", null);
dicShape.Add("VOTENOP", null);
dicShape.Add("VOTENOPV", null);
dicShape.Add("VotingMissSigned", null);//已到未按人数。杨斌 2019-01-14
dicShape.Add("VOTEMiss", null);//杨斌 2015-04-20
dicShape.Add("VOTEMissP", null);
dicShape.Add("VOTEMissPV", null);
dicShape.Add("VOTEMEAN", null);
dicShape.Add("VoteMedian", null);//杨斌 2016-03-29
dicShape.Add("VoteRange", null);//杨斌 2016-03-29
dicShape.Add("GradeAvg", null);//杨斌 2019-06-27
dicShape.Add("ANSWER", null);
dicShape.Add("CRRECTNO", null);
dicShape.Add("CRRECTNOP", null);
dicShape.Add("CRRECTNOPV", null);
dicShape.Add("VotePassResult", null);//杨斌 2018-07-30
dicShape.Add("PARTICIPATE_Men", null);//杨斌 2018-07-30
dicShape.Add("VOTENO_Men", null);//杨斌 2018-07-30
dicShape.Add("VOTENOP_Men", null);//杨斌 2018-07-30
dicShape.Add("VOTENOPV_Men", null);//杨斌 2018-07-30
int count = 0;
float totalWidth = 0;
foreach (Shape s in slide.Shapes)
{
if (dicShape.ContainsKey(s.Name))
{
dicShape[s.Name] = s;
totalWidth += s.Width;
count++;
}
}
if (count < 1) return;
float wSpace = 5;
float nowLeft = (slide.Master.Width - totalWidth - (count - 1) * wSpace) / 2;
Shape[] arySha = new Shape[dicShape.Count];
dicShape.Values.CopyTo(arySha, 0);
for (int i = 0; i < arySha.Length; i++)
{
Shape s = arySha[i];
if (s != null)
{
s.Left = nowLeft;
nowLeft = s.Left + s.Width + wSpace;
}
}
}
///
/// 设置数值或填空表格正确答案
/// 杨斌 2015-01-16
///
///
public static void SetTableNumberRankCorrect(Slide SlideEdit)
{
try
{
if (SlideEdit == null) return;
Shape sha = null;
try
{
sha = SlideEdit.Shapes["ARS_TableNumberRank"];
}
catch { }
if (sha == null) return;
if (sha.HasTable != Microsoft.Office.Core.MsoTriState.msoTrue) return;
TagSet tagSet = new TagSet(SlideEdit.Tags);
string correctAsw = tagSet.GetValue(TagKey.Number_CorrectAnswer).Value;
bool isVoted = (tagSet.GetValue(TagKey.Slide_IsResponsed).ToInt == 1);
int row = 2;
if (correctAsw.Length > 0)
{
sha.Table.Cell(row, 1).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "answer", "正确答案");
sha.Table.Cell(row, 2).Shape.TextFrame.TextRange.Text = isVoted ? correctAsw : "";// correctAsw;//杨斌 2015-05-26
row++;
}
else
{
sha.Table.Cell(row, 2).Shape.TextFrame.TextRange.Text = "";
}
int rank = 1;
for (int i = row; i <= sha.Table.Rows.Count - 1; i++)
{
sha.Table.Cell(i, 1).Shape.TextFrame.TextRange.Text = rank.ToString();
rank++;
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 插入数值题或填空表格
/// 杨斌 2015-01-16
///
///
///
public static Shape InsertTableNumberRank(Slide SlideEdit)
{
Shape res = null;
try
{
TagSet tagSet = new TagSet(SlideEdit.Tags);
string correctAsw = tagSet.GetValue(TagKey.Number_CorrectAnswer).Value;
bool hasCorrectAnswer = (correctAsw.Length > 0);
string[,] aryTable = null;
int rowCount = 7;
if (hasCorrectAnswer)
rowCount++;
aryTable = new string[rowCount, 3];
aryTable[0, 0] = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankVoter", "dgvRank_0", "名次");
aryTable[0, 1] = GlobalInfo.SysLanguage.LPT.ReadString("FrmReport", "dgvVoteDetail_R_Result", "按键值");
aryTable[0, 2] = GlobalInfo.SysLanguage.LPT.ReadString("ReportExcel", "Votes", "票数");
int nRow = 1;
if (hasCorrectAnswer)
{
aryTable[nRow, 0] = GlobalInfo.SysLanguage.LPT.ReadString("PPTOper", "answer", "正确答案");
nRow++;
}
int rank = 0;
for (int i = nRow; i <= rowCount - 2; i++)
{
rank++;
aryTable[i, 0] = rank.ToString();
}
aryTable[rowCount - 1, 0] = GlobalInfo.SysLanguage.LPT.ReadString("ReportExcel", "Others", "其他");
res = PPTOper.InsertTable(aryTable, SlideEdit, 300, 150, 350, 270);
res.Name = "ARS_TableNumberRank";
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 插入数值题表格
/// 杨斌 2014-10-22
///
///
///
public static Shape InsertTablePollRank(Slide SlideEdit)
{
Shape res = null;
try
{
string[,] aryTable = new string[11, 4];
aryTable[0, 0] = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankVoter", "dgvRank_0", "名次");
aryTable[0, 1] = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankPoll", "dgvRank_1", "候选编号");
aryTable[0, 2] = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankVoter", "dgvRank_2", "姓名");
aryTable[0, 3] = GlobalInfo.SysLanguage.LPT.ReadString("ReportExcel", "Votes", "票数");
for (int i = 1; i <= 9; i++)
aryTable[i, 0] = i.ToString();
aryTable[10, 0] = GlobalInfo.SysLanguage.LPT.ReadString("ReportExcel", "Others", "其他");
float w = SlideEdit.Design.SlideMaster.Width;
float h = SlideEdit.Design.SlideMaster.Height;
res = PPTOper.InsertTable(aryTable, SlideEdit, 50, 90, w - 100, h - 170);
res.Name = "ARS_TablePollRank";
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 显示投票人数和选项数,不计权重的。杨斌 2016-11-11
/// 更新:插入时,编辑改变选项个数时,表格行数,和数据刷新;投票时
///
public static void ShowTableVoteCount(Slide sld, bool beInit, LabelTypes labType, int percentDec, bool isHide = false)
{
if ((GlobalInfo.OEMLogo != OEMLogos.oemPowerVote)
&& (GlobalInfo.OEMLogo != OEMLogos.oemAngage))//杨斌 2018-03-22
return;
TagSet tagSet = new TagSet(sld.Tags);
ResponseType rType = GetSlideType(sld);
string labName = "VoteNumber";
string tableName = "VoteNumberTable";
string votePassResultName = "VotePassResult";//杨斌 2018-07-26
Shape shaLab = null;
Shape shaTable = null;
int optCount = 0;
switch (rType)
{
case ResponseType.SignIn:
optCount = 2;
break;
case ResponseType.Group:
optCount = tagSet.GetValue(TagKey.Group_OptionCount).ToInt;
break;
case ResponseType.Choice:
optCount = tagSet.GetValue(TagKey.Choice_OptionCount).ToInt;
break;
case ResponseType.Judge:
optCount = 2;
break;
case ResponseType.Vote:
optCount = tagSet.GetValue(TagKey.Vote_OptionCount).ToInt;
break;
case ResponseType.Grade:
optCount = tagSet.GetValue(TagKey.Grade_OptionCount).ToInt;
break;
default:
break;
}
int rowCount = optCount + 1;
//double submitNum = tagSet.GetValue(TagKey.Slide_SubmitNum).ToInt;//反馈人数
int dueno = tagSet.GetValue(TagKey.Slide_Dueno).ToInt;//参与人数
int submitNum = GlobalInfo.response.ResponseDataList.Count;//反馈人数
bool isPlay = Globals.SunVoteARSAddIn.PPTShow.IsShowSlide;
Microsoft.Office.Core.MsoTriState show = Microsoft.Office.Core.MsoTriState.msoTrue;
if (isPlay)
show = GlobalInfo.response.ShowPicture ? Microsoft.Office.Core.MsoTriState.msoTrue : Microsoft.Office.Core.MsoTriState.msoFalse;
foreach (Shape sha in sld.Shapes)
{
if (sha.Name == labName)
{
shaLab = sha;
shaLab.Visible = show;
}
if (sha.Name == votePassResultName)//杨斌 2018-07-26
{
sha.Visible = show;
}
else if (sha.Name == tableName)
{
shaTable = sha;
shaTable.Visible = show;
}
}
if (isHide)
return;
if (beInit)
{
if (shaTable == null)
{
string[,] aryTable = new string[rowCount, 1];
aryTable[0, 0] = GlobalInfo.SysLanguage.LPT.ReadString("ReportExcel", "Votes", "Votes"); ;
float w = sld.Design.SlideMaster.Width;
float h = sld.Design.SlideMaster.Height;
shaTable = PPTOper.InsertTable(aryTable, sld, w * 0.75f, h * 0.15f, w * 0.18f, h * 0.5f);
shaTable.Name = tableName;
for (int i = 1; i <= rowCount; i++)
{
shaTable.Table.Columns[1].Cells[i].Shape.TextFrame.HorizontalAnchor = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
shaTable.Table.Columns[1].Cells[i].Shape.TextFrame.VerticalAnchor = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorMiddle;
}
}
if (shaLab == null)
{
shaLab = sld.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, shaTable.Left, shaTable.Top + shaTable.Height + 10, shaTable.Width, 50);
shaLab.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoTrue;
shaLab.TextFrame.TextRange.Font.Size = 16;
shaLab.TextFrame.TextRange.Text = submitNum + "";
shaLab.Name = labName;
}
}
try
{
if (shaTable != null)
{
if (shaTable.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue)
{
for (int i = shaTable.Table.Rows.Count; i < rowCount; i++)
{
shaTable.Table.Rows.Add();
shaTable.Table.Columns[1].Cells[i].Shape.TextFrame.HorizontalAnchor = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
shaTable.Table.Columns[1].Cells[i].Shape.TextFrame.VerticalAnchor = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorMiddle;
}
for (int i = shaTable.Table.Rows.Count; i > rowCount; i--)
shaTable.Table.Rows[i].Delete();
for (int i = 1; i <= optCount; i++)
{
string opt = (i - 1).ToString();
double itemCount = 0;
if (GlobalInfo.response.ResponseOptionListNoRate.Keys.Contains(opt)) //有反馈数据
itemCount = GlobalInfo.response.ResponseOptionListNoRate[opt];
string showVal = itemCount + "";
switch (labType)
{
case LabelTypes.ltPercent:
showVal = ConvertOper.GetPercent(itemCount, submitNum, percentDec);
break;
case LabelTypes.ltNumberValueAndPercent:
showVal += "; " + ConvertOper.GetPercent(itemCount, submitNum, percentDec);
break;
}
shaTable.Table.Rows[i + 1].Cells[1].Shape.TextFrame.TextRange.Text = showVal;
}
}
}
if (shaLab != null)
{
if (shaLab.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue)
shaLab.TextFrame.TextRange.Text = submitNum + "";
//ShowLabelData(shaLab, "8888");
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 评分竞价排行。杨斌 2017-09-21
///
public static Shape ShowTableScoreRank(Slide SlideEdit, bool beInit = true)
{
Shape res = null;
string tableName = "ARS_TableScoreRank";
try
{
foreach (Shape sha in SlideEdit.Shapes)
{
if (sha.Name == tableName)
{
res = sha;
break;
}
}
if ((res == null) && !beInit)
return res;
if (res == null)
{
float w = SlideEdit.Design.SlideMaster.Width;
float h = SlideEdit.Design.SlideMaster.Height;
res = PPTOper.InsertTable(SlideEdit, 11, 5, 40, 110, w - 80, h - 190);
res.Name = tableName;
//需翻译
res.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankVoter", "dgvRank_1", "键盘编号");
res.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("RankScoreName", "dgvRank_2", "竞拍人");
res.Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("RankScorePrice", "dgvRank_3", "竞拍价(单位:万)");
res.Table.Cell(1, 4).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("FrmReport", "dgvVoteDetail_R_Time", "提交时间");
res.Table.Cell(1, 5).Shape.TextFrame.TextRange.Text = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankVoter", "dgvRank_0", "排名");
}
if (!beInit)
{
List lsRank = new List();
RosterList Roster = RosterList.RosterLoad;
foreach (var v in GlobalInfo.response.LstResponseData)
{
RankScorePrice row = new RankScorePrice();
int.TryParse(v.KeyID, out row.keyID);
row.keySN = v.KeyID;
if (Roster.RosterEnabled)
{
RosterRow rr = Roster.GetRowByKeyId(v.KeyID);
if (rr != null)
row.name = rr.Cells[1];
}
double.TryParse(v.KeyValue, out row.price);
row.time = v.Time;
lsRank.Add(row);
}
if (res.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue)
{
for (int i = 2; i <= res.Table.Rows.Count; i++)
{
for (int j = 1; j <= res.Table.Columns.Count; j++)
res.Table.Cell(i, j).Shape.TextFrame.TextRange.Text = "";
}
if (lsRank.Count > 0)
{
lsRank = lsRank.OrderByDescending(o => o.price).ThenByDescending(o => o.time).ThenBy(o => o.keyID).ThenBy(o => o.keySN).ToList();
lsRank[0].rank = 1;
for (int i = 1; i < lsRank.Count; i++)
{
if (lsRank[i].price == lsRank[i - 1].price)
lsRank[i].rank = lsRank[i - 1].rank;
else
lsRank[i].rank = i + 1;
}
int n = 0;
for (int i = 2; i <= res.Table.Rows.Count; i++)
{
if (n >= lsRank.Count)
break;
if (res.Table.Columns.Count >= 1)
res.Table.Cell(i, 1).Shape.TextFrame.TextRange.Text = lsRank[n].keySN;
if (res.Table.Columns.Count >= 5)
{
res.Table.Cell(i, 2).Shape.TextFrame.TextRange.Text = lsRank[n].name;
res.Table.Cell(i, 3).Shape.TextFrame.TextRange.Text = lsRank[n].price + "";
res.Table.Cell(i, 4).Shape.TextFrame.TextRange.Text = lsRank[n].time.ToString("HH:mm:ss");
res.Table.Cell(i, 5).Shape.TextFrame.TextRange.Text = lsRank[n].rank + "";
}
else if (res.Table.Columns.Count >= 4)
{
res.Table.Cell(i, 2).Shape.TextFrame.TextRange.Text = lsRank[n].price + "";
res.Table.Cell(i, 3).Shape.TextFrame.TextRange.Text = lsRank[n].time.ToString("HH:mm:ss");
res.Table.Cell(i, 4).Shape.TextFrame.TextRange.Text = lsRank[n].rank + "";
}
n++;
}
}
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 插入MVP排行榜
/// 杨斌 2015-06-09
///
///
///
public static Shape ShowTableMVP(Slide SlideEdit, bool beInit = true)
{
Shape res = null;
string tableName = "ARS_TableGroupMVP";
TagSet tagSet = new TagSet(SlideEdit.Tags);
string sGroup = tagSet.GetValue(TagKey.RankChartColShow).Value;
if (sGroup.Length < 1)
sGroup = GlobalInfo.response.ShowNameCol;
try//杨斌 2015-07-07
{
string[,] aryTable = new string[11, 4];
RosterList roster = new RosterList();
roster.LoadCloumn(GlobalInfo.DBOperation);
string rosName = roster.Columns[0].ColumnName;
if (roster.RosterEnabled)
rosName = roster.Columns[1].ColumnName;
foreach (Shape sha in SlideEdit.Shapes)
{
if (sha.Name == tableName)
{
res = sha;
break;
}
}
//杨斌 2015-07-08
if (res != null)
{
if (res.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue)
{
for (int i = 2; i <= res.Table.Rows.Count; i++)
{
for (int j = 1; j <= res.Table.Columns.Count; j++)
res.Table.Cell(i, j).Shape.TextFrame.TextRange.Text = "";
}
}
}
if (beInit)
{
aryTable[0, 0] = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankVoter", "dgvRank_0", "名次");
aryTable[0, 1] = sGroup;
aryTable[0, 2] = rosName;//GlobalInfo.SysLanguage.LPT.ReadString("FrmRankVoter", "dgvRank_2", rosName);
aryTable[0, 3] = GlobalInfo.SysLanguage.LPT.ReadString("FrmRankVoter", "dgvRank_3", "得分");//杨斌 2015-07-15
}
else
{
List lst = Globals.SunVoteARSAddIn.PPTEdit.GetRankGroupMVPData(SlideEdit);
for (int i = 0; i < lst.Count; i++)
{
int n = i + 1;
aryTable[i, 0] = lst[i].rank.ToString();
aryTable[i, 1] = lst[i].group.ToString();
aryTable[i, 2] = lst[i].name.ToString();
aryTable[i, 3] = lst[i].score.ToString();
}
}
if (res == null)
{
float w = SlideEdit.Design.SlideMaster.Width;
float h = SlideEdit.Design.SlideMaster.Height;
res = PPTOper.InsertTable(aryTable, SlideEdit, 50, 90, w - 100, h - 170);
res.Name = tableName;
}
else
{
//杨斌 2015-06-15
if (res.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue)
{
res.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = sGroup;
if (!beInit)//杨斌 2015-07-07
{
res.Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = rosName;
}
}
PPTOper.FillTableData(res, aryTable, 2, 1);
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
public static void GetCompVoteSlideIDs(TagSet tagSet, out string idYes, out string idNo, out string idAbs)
{
idYes = "0";
idNo = "0";
idAbs = "0";
string ids = tagSet.GetValue(TagKey.SlideCompVoteIds).Value;
if (!string.IsNullOrEmpty(ids))
{
string[] aryIds = ids.Split(',');
if (aryIds.Length >= 1)
idYes = aryIds[0];
if (aryIds.Length >= 2)
idNo = aryIds[1];
if (aryIds.Length >= 3)
idAbs = aryIds[2];
}
}
///
/// 获取PowerVote定制的数字表决结果。权重总票数=无效票数+(有效票数=赞成+反对+弃权)
///
public static List GetCompVoteRes(Slide sld)
{
List res = new List();
try
{
TagSet tagSet = new TagSet(sld.Tags);
RosterList Roster = RosterList.RosterLoad;
bool rosterEnabled = Roster.RosterEnabled;
int indexVoteWeightCol = 0;
for (int i = 0; i < Roster.Columns.Count; i++)
{
if (rosterEnabled && (Roster.Columns[i].ColumnName == GlobalInfo.response.VoteWeightCol))//杨斌 2017-06-09
{
indexVoteWeightCol = i;
}
}
double total = 0;
double dOK = 0;
double dYes = 0;
double dNo = 0;
double dAbs = 0;
if (indexVoteWeightCol > 0)
{
for (int i = 0; i < Roster.Rows.Count; i++)
{
total += ConvertOper.Convert(Roster.Rows[i].Cells[indexVoteWeightCol]).ToDouble;
}
Dictionary> dicVote = new Dictionary>();
//Dictionary dicVoteWeight = new Dictionary();
string ids = tagSet.GetValue(TagKey.SlideCompVoteIds).Value;
if (!string.IsNullOrEmpty(ids))
{
string[] aryIds = ids.Split(',');
string idYes = "0";
string idNo = "0";
string idAbs = "0";
if (aryIds.Length >= 1)
idYes = aryIds[0];
if (aryIds.Length >= 2)
idNo = aryIds[1];
if (aryIds.Length >= 3)
idAbs = aryIds[2];
string tidQ = string.Join(",", idYes, idNo, idAbs);
var voteRes = ReportEx.GetVoterResultPar(tidQ);
double voteYes = 0;
double voteNo = 0;
double voteAbs = 0;
foreach (var v in voteRes)
{
foreach (var vv in v.Value)
{
string vid = vv.Key;
double dVote = ConvertOper.Convert(vv.Value.Result + "").ToDouble;
if (!dicVote.ContainsKey(vid))
{
List lstVote = new List() { 0, 0, 0, 0 };
dicVote.Add(vid, lstVote);
//dicVoteWeight.Add(vid, 0);
}
dicVote[vid][0] += dVote;
if (v.Key == idYes)
dicVote[vid][1] += dVote;
if (v.Key == idNo)
dicVote[vid][2] += dVote;
if (v.Key == idAbs)
dicVote[vid][3] += dVote;
}
}
foreach (var v in dicVote)
{
RosterRow rr = Roster.GetRowByVoterID(v.Key);
if (rr != null)
{
double weight = ConvertOper.Convert(rr.Cells[indexVoteWeightCol]).ToDouble;
//dicVoteWeight[v.Key] = weight;
if (v.Value[0] <= weight)
{
dOK += dicVote[v.Key][0];
dYes += dicVote[v.Key][1];
dNo += dicVote[v.Key][2];
dAbs += dicVote[v.Key][3];
}
}
}
}
}
else
{
}
res.Add(total);//***总票数
res.Add(total - dOK);//***无效票数=总票数-有效票数
res.Add(dOK);//***有效票数=赞成+反对+弃权
res.Add(dYes);//***反对
res.Add(dNo);//***弃权
res.Add(dAbs);//***赞成
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 显示数字表决对比。PowerVote定制。杨斌 2017-06-07
///
public static Shape ShowTableCompVote(Slide SlideEdit, bool beInit = true)
{
Shape res = null;
string tableName = "ARS_TableCompVote";
TagSet tagSet = new TagSet(SlideEdit.Tags);
//string sGroup = tagSet.GetValue(TagKey.RankChartColShow).Value;
RosterList Roster = RosterList.RosterLoad;
bool rosterEnabled = Roster.RosterEnabled;
int colWeight = 0;
if (rosterEnabled && !string.IsNullOrEmpty(GlobalInfo.response.VoteWeightCol))
{
for (int i = 0; i < Roster.Columns.Count; i++)
{
if (Roster.Columns[i].ColumnName == GlobalInfo.response.VoteWeightCol)
{
colWeight = i;
break;
}
}
}
try
{
//杨斌 2018-10-30
string idYes = "0";
string idNo = "0";
string idAbs = "0";
GetCompVoteSlideIDs(tagSet, out idYes, out idNo, out idAbs);//杨斌 2018-10-30
string[,] aryTable = new string[10, 2];//杨斌 2018-10-30。增加一行做表决通过结果
//aryTable[0, 0] = "Associés ORPI:";//自定义留空
//aryTable[1, 0] = "Présents ou représentés:";//***总票数
//aryTable[2, 0] = "";
//aryTable[3, 0] = "Résolution N°2";//标题栏
//aryTable[4, 0] = "Voix Nulles:";//***无效票数=总票数-有效票数
//aryTable[5, 0] = "Voix Exprimées:";//***有效票数=赞成+反对+弃权
//aryTable[6, 0] = "Voix Contre:";//***反对
//aryTable[7, 0] = "Voix ABS:";//***弃权
//aryTable[8, 0] = "Voix Pour:";//***赞成
aryTable[0, 0] = "";//自定义留空
aryTable[1, 0] = "Present";//***总票数
aryTable[2, 0] = "";
aryTable[3, 0] = "Resolution No.";//标题栏
aryTable[4, 0] = "Not counted";//***无效票数=总票数-有效票数
aryTable[5, 0] = "Voted";//***有效票数=赞成+反对+弃权
aryTable[6, 0] = "For";//***赞成
aryTable[7, 0] = "Against";//***反对
if (idAbs != "0")//杨斌 2018-10-30
aryTable[8, 0] = "Abstain";//***弃权
else
aryTable[8, 0] = "";//***弃权
aryTable[9, 0] = "Vote Pass Result";//杨斌 2018-10-30
for (int i = 0; i <= 9; i++)
{
if ((i == 8) && (idAbs == "0"))//杨斌 2018-10-30
aryTable[i, 0] = "";
else
aryTable[i, 0] = GlobalInfo.SysLanguage.LPT.ReadString("PanelSlideCompVote", "TableLine" + i, aryTable[i, 0]);
//杨斌 2018-10-15
aryTable[i, 0] = aryTable[i, 0].Replace(" ** ", "");
aryTable[i, 0] = aryTable[i, 0].Replace(" **", "");
//if (i == 3)
// aryTable[i, 0] += SlideEdit.SlideIndex;
}
foreach (Shape sha in SlideEdit.Shapes)
{
if (sha.Name == tableName)
{
res = sha;
break;
}
}
if (res != null)//清理数据
{
if (res.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue)
{
for (int i = 2; i <= res.Table.Rows.Count; i++)
{
for (int j = res.Table.Columns.Count; j <= res.Table.Columns.Count; j++)
res.Table.Cell(i, j).Shape.TextFrame.TextRange.Text = "";
}
}
}
if (beInit)//初始化
{
}
//数据填充
List lstData = GetCompVoteRes(SlideEdit);
if (lstData.Count > 0)
{
aryTable[1, 1] = lstData[0] + "";//***总票数
aryTable[4, 1] = lstData[1] + "";//***无效票数=总票数-有效票数
aryTable[5, 1] = lstData[2] + "";//***有效票数=赞成+反对+弃权
//aryTable[6, 1] = lstData[4] + "";//***反对
//aryTable[7, 1] = lstData[5] + "";//***弃权
//aryTable[8, 1] = lstData[3] + "";//***赞成
//杨斌 2018-08-01
aryTable[6, 1] = lstData[3] + "";//***赞成
aryTable[7, 1] = lstData[4] + "";//***反对
if (idAbs != "0")//杨斌 2018-10-30
aryTable[8, 1] = lstData[5] + "";//***弃权
else
aryTable[8, 1] = "";//***弃权
}
if (res == null)
{
float w = SlideEdit.Design.SlideMaster.Width;
float h = SlideEdit.Design.SlideMaster.Height;
res = PPTOper.InsertTable(aryTable, SlideEdit, w * 0.55f, h * 0.3f, w * 0.4f, h * 0.4f);
res.Name = tableName;
res.Table.Columns[1].Width = res.Width * 0.75f;
res.Table.Columns[2].Width = res.Width * 0.2f;
PPTOper.FillTableData(res, aryTable, 1, 1);
}
else
{
try
{
res.Table.Cell(2, 2).Shape.TextFrame.TextRange.Text = lstData[0] + "";//***总票数
res.Table.Cell(5, 2).Shape.TextFrame.TextRange.Text = lstData[1] + "";//***无效票数=总票数-有效票数
res.Table.Cell(6, 2).Shape.TextFrame.TextRange.Text = lstData[2] + "";//***有效票数=赞成+反对+弃权
//res.Table.Cell(7, 2).Shape.TextFrame.TextRange.Text = lstData[4] + "";//***反对
//res.Table.Cell(8, 2).Shape.TextFrame.TextRange.Text = lstData[5] + "";//***弃权
//res.Table.Cell(9, 2).Shape.TextFrame.TextRange.Text = lstData[3] + "";//***赞成
//杨斌 2018-08-01
res.Table.Cell(7, 2).Shape.TextFrame.TextRange.Text = lstData[3] + "";//***赞成
res.Table.Cell(8, 2).Shape.TextFrame.TextRange.Text = lstData[4] + "";//***反对
if (idAbs != "0")//杨斌 2018-10-30
{
res.Table.Cell(9, 2).Shape.TextFrame.TextRange.Text = lstData[5] + "";//***弃权
if (string.IsNullOrEmpty(res.Table.Cell(9, 1).Shape.TextFrame.TextRange.Text))
res.Table.Cell(9, 1).Shape.TextFrame.TextRange.Text = aryTable[8, 0];
}
else
{
res.Table.Cell(9, 2).Shape.TextFrame.TextRange.Text = "";//***弃权
res.Table.Cell(9, 1).Shape.TextFrame.TextRange.Text = "";
}
if (res.Table.Rows.Count >= 10)//杨斌 2018-11-13
{
string pass = GlobalInfo.SysLanguage.LPT.ReadString("PanelVote", "VotePass", "Pass");
string noPass = GlobalInfo.SysLanguage.LPT.ReadString("PanelVote", "VoteNotPass", "Not Pass");
bool isPass = PPTEdit.IsVotePass(SlideEdit, lstData[3], lstData[0], lstData[2], lstData[4]);//杨斌 2019-05-22
string passResult = isPass ? pass : noPass;
res.Table.Cell(10, 2).Shape.TextFrame.TextRange.Text = passResult;
}
}
catch { }
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 插入表格
/// 杨斌 2014-10-22
///
///
///
///
///
///
///
///
public static Shape InsertTable(string[,] aryTable, Slide SlideEdit, float x, float y, float w, float h)
{
Shape res = null;
try
{
res = SlideEdit.Shapes.AddTable(aryTable.GetLength(0), aryTable.GetLength(1), x, y, w, h);
FillTableData(res, aryTable);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
public static Shape InsertTable(Slide SlideEdit, int rows, int cols, float x, float y, float w, float h)
{
Shape res = null;
try
{
res = SlideEdit.Shapes.AddTable(rows, cols, x, y, w, h);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 填入表格数据
/// 杨斌 2014-10-22
///
///
///
public static void FillTableData(Shape shaTable, string[,] aryTable)
{
FillTableData(shaTable, aryTable, 1, 1);
}
///
/// 填入表格数据,从startRow,startCol开始,适合保持表头,只填数据
/// 杨斌 2014-10-22
///
///
///
///
///
public static void FillTableData(Shape shaTable, string[,] aryTable, int startRow, int startCol)
{
try
{
if (shaTable.HasTable != Microsoft.Office.Core.MsoTriState.msoTrue)
return;
if (startRow < 1)
startRow = 1;
if (startCol < 1)
startCol = 1;
for (int row = 1; row <= aryTable.GetLength(0); row++)
{
if ((row + startRow - 1) <= shaTable.Table.Rows.Count)
{
for (int col = 1; col <= aryTable.GetLength(1); col++)
{
if ((col + startCol - 1) <= shaTable.Table.Columns.Count)
shaTable.Table.Cell(row + startRow - 1, col + startCol - 1).Shape.TextFrame.TextRange.Text = aryTable[row - 1, col - 1];
}
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 时 间:2011-12-26
/// 创建人:赵丽
/// 插入数据标签
/// 0-计时器,1-应到人数,2-反馈人数,3-正确答案,4-答对人数,5-评分总分,6-评分平均分,
/// 7-反馈人数百分比,8-反馈人数数值+百分比,9-答对人数百分比,10-答对人数数值+百分比,11-参与人数,12-平均值Mean
/// 13-未按人数,14-未按人数百分比,15-未按人数数值+百分比
/// 16-评委分组平均分,17-评委分组平均分表格
/// 杨斌 2016-03-29。19-median中间值,20-range投票范围
/// 21-表决通过结果。杨斌 2018-07-25
/// 22-参与人数-不带权重。杨斌 2018-07-30
/// 23-反馈人数-不带权重。杨斌 2018-07-30
/// 24-反馈人数百分比-不带权重。杨斌 2018-07-30
/// 25-反馈人数百分比数值-不带权重。杨斌 2018-07-30
/// 26-实到人数。杨斌 2018-12-20
/// 29-评议平均分。杨斌 2019-06-27
/// 杨斌 2012-03-12 补充注释11
///
/// 标签类型
public static Shape MenuInsertDataTab(int type, Slide SlideEdit)
{
Shape res = null;
try
{
//杨斌 2015-04-13
TagSet tagSet = new TagSet(SlideEdit.Tags);
string colName = tagSet.GetValue(TagKey.ResponsePara_VoteRateField).Value;
bool isRate = (colName.Length > 0);
DataTabAttributes dt = new DataTabAttributes(type, isRate);
if (SlideEdit != null)
{
//bool bType = false;
//foreach (Shape shape in SlideEdit.Shapes)
for (int i = SlideEdit.Shapes.Count; i > 0; i--)
{
Shape shape = SlideEdit.Shapes[i];
//杨斌 2012-03-23
switch (type)
{
case 2://反馈人数
case 7://反馈人数百分比
case 8://反馈人数数值+百分比
switch (shape.Name)
{
case "VOTENO":
case "VOTENOP":
case "VOTENOPV":
dt.Left = shape.Left;
dt.Top = shape.Top;
dt.Width = shape.Width;
dt.Height = shape.Height;
shape.Delete();
break;
}
break;
case 13://未按人数。杨斌 2015-04-20
case 14:
case 15:
switch (shape.Name)
{
case "VOTEMiss"://杨斌 2015-04-20
case "VOTEMissP":
case "VOTEMissPV":
dt.Left = shape.Left;
dt.Top = shape.Top;
dt.Width = shape.Width;
dt.Height = shape.Height;
shape.Delete();
break;
}
break;
case 4:
case 9:
case 10://答对人数
switch (shape.Name)
{
case "CRRECTNO":
case "CRRECTNOP":
case "CRRECTNOPV":
dt.Left = shape.Left;
dt.Top = shape.Top;
dt.Width = shape.Width;
dt.Height = shape.Height;
shape.Delete();
break;
}
break;
case 23:
case 24:
case 25://反馈人数
switch (shape.Name)
{
case "VOTENO_Men"://杨斌 2018-07-30
case "VOTENOP_Men"://杨斌 2018-07-30
case "VOTENOPV_Men"://杨斌 2018-07-30
dt.Left = shape.Left;
dt.Top = shape.Top;
dt.Width = shape.Width;
dt.Height = shape.Height;
shape.Delete();
break;
}
break;
default:
if (shape.Name == dt.Style)
{
//杨斌 保持以前的位置和大小,杨斌 2012-03-23
dt.Left = shape.Left;
dt.Top = shape.Top;
dt.Width = shape.Width;
dt.Height = shape.Height;
shape.Delete();
}
break;
}
}
//插入后选中对象
if (type == 17)//杨斌 2015-07-29
{
}
else
{
res = InsertDataTab(dt, SlideEdit);
}
//置于顶层
if (res != null)//杨斌 2014-09-05
res.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoBringForward);
//计时器需要保存值,杨斌 2012-03-23
if ((type == 0) && (res != null))
{
PPTOper.SaveShapeTimer(res);
}
}
SetDataTabPosition(SlideEdit);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
///
/// 清除当前幻灯片的数据
/// 创建 赵丽
///
public static void ClearCurrentSlide()
{
GlobalInfo.response.CurrentSlide = Globals.SunVoteARSAddIn.PPTEdit.SlideEdit;
// //2012-10-09 清除图表位置改变
TagSet tagSet = new TagSet();
tagSet.Tags = Globals.SunVoteARSAddIn.PPTEdit.SlideEdit.Tags;
PPTOper.SaveChartPosition(GlobalInfo.response.CurrentSlide, tagSet);
tagSet.SetValue(TagKey.Responsed, 0);
tagSet.SetValue(TagKey.Slide_IsResponsed, 0);//杨斌 2014-06-18
//2012-06-14 赵丽 重新设置图表显示时间
PPTOper.ReSetTimer(GlobalInfo.response.CurrentSlide);//杨斌 2015-04-08
PPTOper.ReSetShowTime(GlobalInfo.response.CurrentSlide);
GlobalInfo.response.ClearResponse();
GlobalInfo.response.SetOrderOptionText(Globals.SunVoteARSAddIn.PPTEdit.SlideEdit, false);//杨斌 2014-04-25
GlobalInfo.response.RefreshLable();//杨斌 2016-03-31
//清空数据库中的值
string slideId = GlobalInfo.response.CurrentSlide.SlideID.ToString();
ResponseDB.DeleteResponseInfo(slideId);
ResponseDB.DeleteResponseTopic(slideId);
//杨斌 2015-05-26
if ((Globals.SunVoteARSAddIn.PPTEdit.ResponseTypeSlideEdit == ResponseType.Number) ||
(Globals.SunVoteARSAddIn.PPTEdit.ResponseTypeSlideEdit == ResponseType.Text))
ResponseDB.ShowTableNumberRank(Globals.SunVoteARSAddIn.PPTEdit.SlideEdit, true);
PPTOper.SetTableNumberRankCorrect(Globals.SunVoteARSAddIn.PPTEdit.SlideEdit);
if (Globals.SunVoteARSAddIn.PPTEdit.ResponseTypeSlideEdit == ResponseType.Score)//杨斌 2017-09-21
PPTOper.ShowTableScoreRank(Globals.SunVoteARSAddIn.PPTEdit.SlideEdit, false);
//杨斌 2017-12-08
if ((Globals.SunVoteARSAddIn.PPTShow.IsShowSlide) && (Globals.SunVoteARSAddIn.PPTShow.SlideShow != null)
&& (Globals.SunVoteARSAddIn.PPTShow.SlideShow.SlideID == Globals.SunVoteARSAddIn.PPTEdit.SlideEdit.SlideID))
VoteServer.ClearVote();
}
///
/// 清除所有幻灯片的数据
/// 创建 赵丽
///
public static void ClearAllSlide()
{
TagSet tagSet = new TagSet();
foreach (Slide slide in Globals.SunVoteARSAddIn.PPTEdit.PPT.ActivePresentation.Slides)
{
GlobalInfo.response.CurrentSlide = slide;
//2012-10-09 清除数据位置改变
tagSet.Tags = slide.Tags;
PPTOper.SaveChartPosition(slide, tagSet);
tagSet.SetValue(TagKey.Responsed, 0);
tagSet.SetValue(TagKey.Slide_IsResponsed, 0);//杨斌 2014-06-18
//2012-06-14 赵丽 重新设置图表显示时间
GlobalInfo.response.ClearResponse();
//2012-10-09 清除所有幻灯片 更新计时器时间
PPTOper.ReSetTimer(slide);
PPTOper.ReSetShowTime(slide);
GlobalInfo.response.SetOrderOptionText(Globals.SunVoteARSAddIn.PPTEdit.SlideEdit, false);//杨斌 2014-04-25
GlobalInfo.response.RefreshLable();//杨斌 2016-03-31
//清空数据库中的值
string slideId = slide.SlideID.ToString();
ResponseDB.DeleteResponseInfo(slideId);
ResponseDB.DeleteResponseTopic(slideId);
//杨斌 2015-05-26
ResponseType responseType = EnumName.GetEnum(tagSet.GetValue(TagKey.ResponseType).Value);
if ((responseType == ResponseType.Number) ||
(responseType == ResponseType.Text))
ResponseDB.ShowTableNumberRank(slide, true);
PPTOper.SetTableNumberRankCorrect(slide);
if (responseType == ResponseType.Score)//杨斌 2017-09-21
PPTOper.ShowTableScoreRank(slide, false);
//杨斌 2017-12-08
if ((Globals.SunVoteARSAddIn.PPTShow.IsShowSlide) && (Globals.SunVoteARSAddIn.PPTShow.SlideShow != null)
&& (Globals.SunVoteARSAddIn.PPTShow.SlideShow.SlideID == slide.SlideID))
VoteServer.ClearVote();
}
}
///
/// 设置标签的显示
/// 杨斌 2015-07-30
///
///
///
public static void SetLableVisible(string shapeName, Microsoft.Office.Core.MsoTriState msoTS)
{
try
{
bool find = false;
Slide slide = Globals.SunVoteARSAddIn.PPTEdit.SlideEdit;
foreach (Shape shape in slide.Shapes)
{
if (shape.Name == shapeName)
{
shape.Visible = msoTS;
find = true;
}
}
if ((msoTS == Microsoft.Office.Core.MsoTriState.msoTrue) && (!find))
{
if (shapeName == "AVGScoreGroup")
{
DataTabAttributes dt = new DataTabAttributes(16, false);
InsertDataTab(dt, slide);
}
if (shapeName == "AVGScoreTableGroup")
{
DataTabAttributes dt = new DataTabAttributes(17, false);
InsertDataTable(dt, slide);
}
if (shapeName == "AVGScoreTableGroupDetail")
{
DataTabAttributes dt = new DataTabAttributes(18, false);
InsertDataTable(dt, slide);
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 导入数据库文件
///
/// 文件路径
public static bool Importmdb(string zipPath, Microsoft.Office.Interop.PowerPoint.Presentation pres)
{
try
{
string tempPath = GlobalInfo.SYSTEM_BACKUP + "BackupTemp";
if (Directory.Exists(tempPath))
{
try
{
DeleteFile(tempPath);
}
catch { }
}
if (!Directory.Exists(tempPath))
Directory.CreateDirectory(tempPath);
//解压
UnZipFile(zipPath, tempPath);
string[] filenames = Directory.GetFiles(tempPath);
//导出的文件名
string fileName = "";
//导出的文件名不带扩展名
string fileNameNoc = "";
foreach (string file in filenames)
{
if (file.Substring(file.Length - 3, 3) == "mdb")
{
fileName = file.Substring(file.LastIndexOf("\\") + 1);
fileNameNoc = fileName.Substring(0, fileName.LastIndexOf("."));
break;
}
}
string mdbPath = tempPath + "\\" + fileNameNoc + ".mdb";
bool reSetDBName = false;
if (pres.Tags[PPT_DataBaseID].Length > 0 && pres.Tags[PPT_DataBaseID] != null)
{
//string DBName = INIControl.GetInstances(fileNameNoc + ".ini").ReadString("Backup", "DBName", GlobalInfo.DBName);
//需要判断ini文件是否存在,若不存在,直接导入数据库。杨斌 2012-03-22
string fileIni = tempPath + "\\" + fileNameNoc + ".ini";
string DBName = "";
if (File.Exists(fileIni))
{
DBName = INIControl.GetInstances(fileIni).ReadString("Backup", "DBName", GlobalInfo.DBName);
}
else
{
DBName = mdbPath;
int i = DBName.LastIndexOf("\\");
if (i >= 0)
{
DBName = DBName.Substring(i + 1);
}
}
try
{
File.Copy(mdbPath, GlobalInfo.DB_PATH + DBName, true);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
//杨斌 2012-03-22
//需要判断ini文件是否存在,以及关联的ppt文件是否存在
//若ini文件存在,关联的ppt文件也存在,则导入数据库后,打开ppt文件
//杨斌 2015-07-02
List lstFile = new List();
lstFile.Add(tempPath + @"\" + fileNameNoc + ".pptx");
lstFile.Add(tempPath + @"\" + fileNameNoc + ".ppt");
foreach (var v in lstFile)
{
if (File.Exists(fileIni) && File.Exists(v))
{
pres.Close();
pres = Globals.SunVoteARSAddIn.PPTEdit.PPT.Presentations.Open(v);
}
else//若ini不存在,直接导入数据库。若ini文件存在,但关联的ppt文件不存在,也直接导入数据库。
{
Globals.SunVoteARSAddIn.PPTEdit.OpenPresDB(pres);
}
}
}
return true;
}
catch (Exception ex)
{
return false;
}
}
///
/// 转换Zip压缩读出的文件名,防止乱码
/// 杨斌 2014-09-28
///
///
///
public static string ParseName(string source)
{
byte[] sourceByte = new byte[source.Length];
for (int i = 0; i < source.Length; i++)
{
sourceByte[i] = (byte)source[i];
}
return Encoding.Default.GetString(sourceByte);
}
///
/// 压缩文件
/// 创建:杨斌 2012-05-31
///
/// 被压缩的文件目录
/// 输出的压缩文件
private static void CreateZipFile(string filesDir, string zipFilePath)
{
if (!Directory.Exists(filesDir))
{
Console.WriteLine("Cannot find directory '{0}'", filesDir);
return;
}
try
{
string[] filenames = Directory.GetFiles(filesDir);
using (ZipOutputStream s = new ZipOutputStream(File.Create(zipFilePath)))
{
s.SetLevel(9); // 压缩级别 0-9
//s.Password = "123"; //Zip压缩文件密码
byte[] buffer = new byte[4096]; //缓冲区大小
foreach (string file in filenames)
{
//string file2 = ParseName(file);//杨斌 2014-09-28
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
s.Finish();
s.Close();
}
}
catch (Exception ex)
{
Console.WriteLine("Exception during processing {0}", ex);
}
}
///
/// 解压文件
/// 创建:杨斌 2012-05-31
///
/// 待解压的压缩文件
/// 解压的文件目录
private static void UnZipFile(string zipFilePath, string filesDir)
{
if (!File.Exists(zipFilePath))
{
Console.WriteLine("Cannot find file '{0}'", zipFilePath);
return;
}
using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFilePath)))
{
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
Console.WriteLine(theEntry.Name);
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
// create directory
if (directoryName.Length > 0)
{
Directory.CreateDirectory(directoryName);
}
if (fileName != String.Empty)
{
//防止还原当前文件时报错 2012-06-06
try
{
using (FileStream streamWriter = File.Create(filesDir + "\\" + theEntry.Name))
{
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
}
}
catch { }
}
}
}
}
///
/// 导出数据库文件
///
/// 文件路径
public static string Exportmdb(string mdbPath, Microsoft.Office.Interop.PowerPoint.Presentation pres)
{
string res = "";
try
{
//2012-09-25 赵丽 备份后保存 未保存更新
string oldFullName = pres.FullName;
//导出的文件目录
string filePath = mdbPath.Substring(0, mdbPath.LastIndexOf("\\"));
//导出的文件名
string fileName = mdbPath.Substring(mdbPath.LastIndexOf("\\") + 1);
//导出的文件名不带扩展名
string fileNameNoc = fileName.Substring(0, fileName.LastIndexOf("."));
//删除文件
string tempPath = GlobalInfo.SYSTEM_BACKUP + "BackupTemp";
try
{
if (Directory.Exists(tempPath))
{
DeleteFile(tempPath);
}
}
catch { }
if (!Directory.Exists(tempPath))
Directory.CreateDirectory(tempPath);
File.Copy(GlobalInfo.DB_PATH + pres.Tags[PPT_DataBaseID], tempPath + "\\" + fileNameNoc + ".mdb", true);
string backupPath = tempPath + "\\" + fileNameNoc + ".ini";
string sTemp = tempPath + "\\temp.ini";
File.Copy(GlobalInfo.SYSTEM_BACKUP + "Backup.ini", sTemp, true);
INIControl.GetInstances(sTemp).WriteValue("Backup", "DBName", GlobalInfo.DBName);
new FileInfo(sTemp).MoveTo(backupPath);
pres.SaveCopyAs(tempPath + "\\" + fileNameNoc + ".pptx");//杨斌 2015-11-12
//压缩文件
string zipPath = filePath + "\\" + fileNameNoc + ".arsz";
CreateZipFile(tempPath, zipPath);
return zipPath;
}
catch (Exception ex)
{
}
return res;
}
///
/// 删除文件夹下所有文件
/// 创建标志 赵丽 2012-06-06
///
///
private static void DeleteFile(string dirPath)
{
try
{
string[] strFiles = Directory.GetFiles(dirPath);
foreach (string strFile in strFiles)
{
File.Delete(strFile);
}
}
catch { }
}
///
/// 显示数据标签的数据
/// 创建:杨斌 2012-03-15
///
/// 形状
/// 数据
public static void ShowLabelData(Shape shape, string data)
{
if (shape == null) return;
try
{
string lblText = shape.TextFrame.TextRange.Text.Trim();
string[] s = lblText.Split(':');
//lblText = s[0] + ":" + data;
lblText = s[0].TrimEnd(' ') + " : " + data;//杨斌 2019-06-06
shape.TextFrame.TextRange.Text = lblText;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
}
///
/// 获取指定类型的数据标签对象集合
/// 创建:杨斌 2012-03-16
///
///
///
///
public static List GetDataLabelShape(Slide slide, DataLabelType labelType)
{
List res = new List();
try
{
string shapeName = EnumName.GetName(labelType);
foreach (Shape shape in slide.Shapes)
{
if (shape.Name == shapeName)
{
res.Add(shape);
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
return res;
}
///
/// 显示或隐藏表格
/// 杨斌 2014-10-24
///
///
///
///
public static void ShowShapeTable(Slide slide, string findName, bool isShow)
{
try
{
if (slide == null) return;
foreach (Shape shape in slide.Shapes)
{
if ((shape.Name == findName) && (shape.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue))
{
if (isShow)
shape.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
else
shape.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
}
///
/// 显示或隐藏反馈幻灯片指定类型标签
/// 创建:杨斌 2012-03-16
///
///
///
///
public static void ShowDataLabel(Slide slide, DataLabelType labelType, bool isShow, bool playSoundCorrectAnswer = true)
{
try
{
if (slide == null) return;
string findName = EnumName.GetName(labelType);
bool isFind = false;
foreach (Shape shape in slide.Shapes)
{
if (labelType == DataLabelType.ANSWER)
{
if (shape.Name == "CorrectShape")
{
isFind = true;
if (isShow)
{
shape.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
}
else
{
shape.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
}
}
}
if (shape.Name == findName)
{
isFind = true;
string temp = shape.TextFrame.TextRange.Text;
shape.TextFrame.TextRange.Text = "";
if (isShow)
shape.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
else
shape.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
shape.TextFrame.TextRange.Text = temp;
}
}
if (playSoundCorrectAnswer && isShow && isFind)//杨斌 2019-01-09
{
if (GlobalInfo.sysConfig.CorrectAnswerSoundEnabled)
GlobalInfo.DXSoundPlay.Play(GlobalInfo.Sund_Key_ShowCorrectAnswer);
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
}
///
/// 显示或隐藏反馈幻灯片正确答案标签
/// 创建:杨斌 2012-03-16
/// 修改:杨斌 2012-07-02
///
///
///
public static void ShowCorrectAnswer(Slide slide, bool isShow, bool playSoundCorrectAnswer = true)
{
if (slide == null) return;
ShowDataLabel(slide, DataLabelType.ANSWER, isShow, playSoundCorrectAnswer);
}
///
/// 改变反馈幻灯片正确答案显示或不显示
/// 创建:杨斌 2012-03-15
///
///
public static void ShowCorrectAnswerChange(Slide slide)
{
Shape shaFind = null;
try
{
if (slide == null) return;
string findName = EnumName.GetName(DataLabelType.ANSWER);
foreach (Shape shape in slide.Shapes)
{
if ((shape.Name == findName))
{
string stemp = shape.TextFrame.TextRange.Text;
shape.TextFrame.TextRange.Text = "";
if (shaFind == null)
{
shaFind = shape;
if (shape.Visible == Microsoft.Office.Core.MsoTriState.msoTrue)
shaFind.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
else
shaFind.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
}
else
{
shape.Visible = shaFind.Visible;
}
shape.TextFrame.TextRange.Text = stemp;
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
}
///
/// 获取正确答案显示状态
/// 创建:杨斌 2012-03-15
///
///
///
public static bool GetShowCorrectAnswer(Slide slide)
{
bool res = false;
try
{
if (slide != null)
{
string findName = EnumName.GetName(DataLabelType.ANSWER);
foreach (Shape shape in slide.Shapes)
{
if ((shape.Name == findName) || (shape.Name == "CorrectShape"))//杨斌 2015-01-26
{
res = (shape.Visible == Microsoft.Office.Core.MsoTriState.msoTrue);
break;
}
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
return res;
}
///
/// 重置计时器,清除,清空重投时,调用
/// 创建:杨斌 2012-03-16
///
public static void ReSetTimer(Slide slide)
{
try
{
List lstShape = PPTOper.GetDataLabelShape(slide, DataLabelType.TIMER);
TagSet tagSet = new TagSet(slide.Tags);
foreach (Shape shape in lstShape)
{
//杨斌 2015-04-08。复制的计时器没有时间设置
string tv = tagSet.GetValue(TagKey.ResponseTimer).Value;
if (string.IsNullOrEmpty(tv))
tagSet.SetValue(TagKey.ResponseTimer, shape.TextFrame.TextRange.Text);
else
shape.TextFrame.TextRange.Text = tagSet.GetValue(TagKey.ResponseTimer).Value;
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 重新设置图表显示时机
/// 创建 赵丽 2012-06-14
///
///
public static void ReSetShowTime(Slide slide)
{
try
{
TagSet tagSet = new TagSet(slide.Tags);
tagSet.SetValue(TagKey.Pictrue_ShowByHand, 0);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 保存计时器值
/// 创建:杨斌 2012-03-16
///
///
public static void SaveShapeTimer(Shape shape)
{
if (shape == null) return;
try
{
if (shape.Name == EnumName.GetName(DataLabelType.TIMER))
{
string lblText = shape.TextFrame.TextRange.Text;
int countSec = ConvertOper.TimeToSecond(lblText);
if (countSec > 0)
{
Slide slide = ((Slide)(shape.Parent));
TagSet TagSetSlide = new TagSet(slide.Tags);
TagSetSlide.SetValue(TagKey.ResponseTimer, lblText);
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
}
///
/// 是否存在图表
/// 创建 赵丽
///
public static void RefreshAllIsExistChart()
{
TagSet tagSet = new TagSet();
foreach (Slide slide in Globals.SunVoteARSAddIn.PPTEdit.PPT.ActivePresentation.Slides)
{
tagSet.Tags = slide.Tags;
tagSet.SetValue(TagKey.IsExistChart, false);
foreach (Shape shape in slide.Shapes)
{
if (shape.Name == "pic")
tagSet.SetValue(TagKey.IsExistChart, true);
}
}
}
///
/// 是否存在图表
/// 创建 赵丽
///
public static void RefreshOneIsExistChart(Slide slide)
{
TagSet tagSet = new TagSet();
tagSet.Tags = slide.Tags;
tagSet.SetValue(TagKey.IsExistChart, false);
foreach (Shape shape in slide.Shapes)
{
if (shape.Name == "pic")
tagSet.SetValue(TagKey.IsExistChart, true);
}
}
///
/// 保存图表的位置
/// 创建标志 赵丽 2012-05-2
///
///
///
public static void SaveChartPosition(Slide slide, TagSet tagSet)
{
try
{
foreach (Shape s in slide.Shapes)
{
if (s.Name == "pic")
{
ChartTypes chartType = EnumName.GetEnum(tagSet.GetValue(TagKey.ChartPara_Type).Value);
switch (chartType)
{
case ChartTypes.ctBar:
case ChartTypes.ctBarBox:
tagSet.SetValue(TagKey.Picture_Left_Bar, s.Left);
tagSet.SetValue(TagKey.Picture_Top_Bar, s.Top);
//修改标志 赵丽 2012-06-06 保存图表大小
tagSet.SetValue(TagKey.Picture_Height_Bar, s.Height);
tagSet.SetValue(TagKey.Picture_Width_Bar, s.Width);
break;
case ChartTypes.ctColumn:
case ChartTypes.ctColumnBox:
tagSet.SetValue(TagKey.Picture_Left_Column, s.Left);
tagSet.SetValue(TagKey.Picture_Top_Column, s.Top);
//修改标志 赵丽 2012-06-06 保存图表大小
tagSet.SetValue(TagKey.Picture_Height_Column, s.Height);
tagSet.SetValue(TagKey.Picture_Width_Column, s.Width);
break;
case ChartTypes.ctPie:
tagSet.SetValue(TagKey.Picture_Left_Pie, s.Left);
tagSet.SetValue(TagKey.Picture_Top_Pie, s.Top);
//修改标志 赵丽 2012-06-06 保存图表大小
tagSet.SetValue(TagKey.Picture_Height_Pie, s.Height);
tagSet.SetValue(TagKey.Picture_Width_Pie, s.Width);
break;
}
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
}
///
/// 设置图表字体的大小
/// 2012-11-21 赵丽
///
///
///
public static void SetFontSize(int optionCount, TagSet tagSet)
{
if (tagSet == null) return;
string chartType = tagSet.GetValue(TagKey.ChartPara_Type).Value;
ResponseType responseType = Globals.SunVoteARSAddIn.PPTEdit.ResponseTypeSlideEdit;
switch (responseType)
{
case ResponseType.Choice:
optionCount = tagSet.GetValue(TagKey.Choice_OptionCount).ToInt;
break;
case ResponseType.Group:
optionCount = tagSet.GetValue(TagKey.Group_OptionCount).ToInt;
break;
case ResponseType.Grade:
optionCount = tagSet.GetValue(TagKey.Grade_OptionCount).ToInt;
break;
}
if (chartType == "ctBar")
{
tagSet.SetValue(TagKey.ChartPara_DataLabelFontSize, 14);
}
else
{
//2012-11-21 数据字体根据选项个数变化 赵丽
if (optionCount <= 5)
tagSet.SetValue(TagKey.ChartPara_DataLabelFontSize, 14);
if ((optionCount > 5) && (optionCount < 8))
{
tagSet.SetValue(TagKey.ChartPara_DataLabelFontSize, 12);
}
if (optionCount >= 8)
tagSet.SetValue(TagKey.ChartPara_DataLabelFontSize, 8);
}
}
///
/// 获取反馈类型
/// 杨斌 2014-12-08
///
///
///
public static ResponseType GetSlideType(Slide sld)
{
TagSet tagSet = new TagSet(sld.Tags);
ResponseType res = ResponseTypeName.GetEnum(tagSet.GetValue(TagKey.ResponseType).Value);
return res;
}
///
/// 删除图表。杨斌 2014-12-22
///
///
public static void DeleteChartShow(Slide sld)
{
foreach (Shape shape in sld.Shapes)
{
if (shape.Name == "pic")
shape.Delete();
}
}
///
/// 设置或添加正确答案标记。
/// 杨斌 2015-01-23
///
///
///
///
public static void SetCorrectShape(Slide sld, bool beAdd, Image img)
{
try
{
string correctAsw = Globals.SunVoteARSAddIn.PPTEdit.GetSlideCorrectAnswer(sld, Globals.SunVoteARSAddIn.PPTEdit.ResponseTypeSlideEdit);
string[] aryAsw = correctAsw.Split(new char[] { ',' });
List lstAsw = new List();
foreach (var v in aryAsw)
{
int n = ConvertOper.Convert(v).ToInt;
if (n > 0)
lstAsw.Add(n);
}
List lst = new List();
Shape sha = null;
foreach (Shape s in sld.Shapes)
{
if (s.Name == "CorrectShape")
{
lst.Add(s);
}
}
float H = 50;
float SizeA = 42;
PointF P = new PointF(SizeA, SizeA);
Shape shaOpt = PPTOper.GetOptionTextLinkShape(sld);
if (shaOpt != null)
{
string[] opt = GetShapeOptionText(shaOpt);
int count = 1;
if (opt.Length > 0)
count = opt.Length;
if (shaOpt.TextFrame.TextRange.Text.Length > 0)//杨斌 2016-12-09
H = shaOpt.TextFrame.TextRange.Paragraphs(-1, -1).BoundHeight / count;
P.X = shaOpt.Left;
P.Y = shaOpt.Top;
}
string path = GlobalInfo.PICTURETEMP_PATH + "temp.png";
img.Save(path);
if (!beAdd)
{
if (lst.Count < 1)
return;
}
foreach (Shape s in lst)
s.Delete();
for (int i = 0; i < lstAsw.Count; i++)
{
sha = sld.Shapes.AddPicture(path, Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, P.X - 36, P.Y + H * (lstAsw[i] - 1) + 18, SizeA, SizeA);
sha.Name = "CorrectShape";
sha.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoBringToFront);
}
File.Delete(path);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
public static byte[] GetFileData(string path)
{
byte[] res = null;
try
{
FileStream fs = new FileStream(path, FileMode.Open);
res = new byte[fs.Length];
fs.Read(res, 0, res.Length);
fs.Close();
}
catch (Exception ex)
{
string sErr = ex + "";
//SystemLog.WriterLog(ex, false);
}
return res;
}
public static byte[] GetSlidePic(Slide sld)
{
byte[] res = null;
try
{
if (sld != null)
{
string dir = GlobalInfo.APP_DIR + @"\Temp\";
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
string path = dir + "SS" + sld.SlideIndex + ".jpg";
sld.Export(path, "jpg");
//Presentation pres = sld.Parent as Presentation;
res = GetFileData(path);
File.Delete(path);
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, false);
}
return res;
}
public static int GetVoteChartItemCount(Slide sld)
{
int itemCount = 0;
TagSet tagSet = new TagSet(Globals.SunVoteARSAddIn.PPTShow.SlideShow.Tags);
switch (Globals.SunVoteARSAddIn.PPTShow.ResponseType)
{
case ResponseType.Choice:
itemCount = tagSet.GetValue(TagKey.Choice_OptionCount).ToInt;
break;
case ResponseType.Group:
itemCount = tagSet.GetValue(TagKey.Group_OptionCount).ToInt;
break;
case ResponseType.Judge:
itemCount = 2;
break;
case ResponseType.Order:
itemCount = tagSet.GetValue(TagKey.Order_OptionCount).ToInt;
break;
case ResponseType.Vote:
itemCount = tagSet.GetValue(TagKey.Vote_OptionCount).ToInt;
break;
case ResponseType.Grade:
itemCount = tagSet.GetValue(TagKey.Grade_OptionCount).ToInt;
break;
}
return itemCount;
}
}
}