using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using GeneralLib;
namespace SunVoteARSPPT
{
public class Demo : IResponse
{
///
/// 演示模式类
///
public Imitation DemoMode = null;
///
/// 要演示的键盘编号
///
public static string[] Keypads { get; set; }
public static Dictionary PollList { get; set; }
///
/// 签到码列表
/// 2012-06-18
///
public static Dictionary SignCodeList { get; set; }
///
/// 构造函数
///
public Demo()
{
DemoMode = new Imitation();
DemoMode.KeyIDList = new List();
DemoMode.Interval = 500;//杨斌 2012-06-27 模拟太快了按键音效太密
DemoMode.DemoCreat += new DemoCreatEvt(DemoMode_DemoCreat);
}
///
/// 演示模式收取数据
///
///
void DemoMode_DemoCreat(DemoResult Result)
{
if (DemoMode.DemoType.GetType().Name == "ChoiceDemo")
{
Result.Value = Result.Value.Replace("10", "0");
Result.Value = Result.Value.Replace(",", "");
}
Result.Value = ConvertOper.DoNumberString(Result.Value);//杨斌 2013-08-29
ResponsePar ObjResponseValue = new ResponsePar();
ObjResponseValue.BaseTag = "1";
ObjResponseValue.KeyID = Result.KeyID.ToString();
ObjResponseValue.KeyValue = Result.Value;
if (ResponseType == ResponseType.Poll)
{
if (PollList.ContainsKey(Result.Value))
{
//if (GlobalInfo.OEMLogo2 == OEMLogos2.oemSunVoteMultiPoll)
//杨斌 2017-02-13
if (PanelPoll.IsUseMultiPoll(Globals.SunVoteARSAddIn.PPTShow.SlideShow))
{
//杨斌 2018-11-22。SDK分段式选举与数字选举不兼容,数字选举模式4值为"1=4",而分段式模式7值为"01-4"
int UseModeLimitNumber = TagSet.GetValue(TagKey.Poll_UseModeLimitNumber).ToInt;
if (UseModeLimitNumber == 1)
ObjResponseValue.KeyValue = Result.Value + "-" + PollList[Result.Value];
else
ObjResponseValue.KeyValue = Result.Value + "=" + PollList[Result.Value];
}
else
ObjResponseValue.KeyValue = PollList[Result.Value];
}
}
//2012-06-19 添加签到码签到的演示模式
if ((ResponseType == ResponseType.SignIn) && (TagSet.GetValue(TagKey.SignIn_Mode).ToInt > 0))//杨斌 2017-03-30
{
//if (SignCodeList.ContainsKey(Result.Value))
// ObjResponseValue.KeyValue = SignCodeList[Result.Value];
}
ObjResponseValue.Speed = Result.Speed;
//多选收到的按键进行排序,与硬件一致,如21转为12。杨斌 2012-11-07
//注意choice.OptionsMode = 1才有效,否则0要放到最后
int n0 = ObjResponseValue.KeyValue.IndexOf('0');
switch (ResponseType)
{
case ResponseType.Choice:
if (n0 >= 0)
{
ObjResponseValue.KeyValue = ObjResponseValue.KeyValue.Replace('0', 'J');
}
char[] ary = ObjResponseValue.KeyValue.ToCharArray();
Array.Sort(ary);
ObjResponseValue.KeyValue = new string(ary);
if (n0 >= 0)
{
ObjResponseValue.KeyValue = ObjResponseValue.KeyValue.Replace('J', '0');
}
break;
default:
break;
}
ResponseEventHander(ObjResponseValue);
}
///
/// 初始化键盘范围
/// 修改:杨斌 2012-06-27 模拟太快了按键音效太密
///
///
private bool IniKeypadArea()
{
//if (Keypads == null)
// throw (new ApplicationException(l.LPT.ReadString("DemoSDK", "initialize", "没有初始化演示的键盘范围")));
//if (Keypads.Length < 1)
// throw (new ApplicationException(GlobalInfo.LPT.ReadString("DemoSDK", "setting", "没有设置演示的键盘范围")));
DemoMode.KeyIDList.Clear();
DemoMode.ResultList.Clear();//重新反馈或清空结果时调用
for (int i = 0; i < Keypads.Length; i++)
{
DemoMode.KeyIDList.Add(Keypads[i]);
}
//根据设置的键盘数动态设置反馈事件的触发时间间隔
int interval = 500;
//2012-06-14 赵丽 键盘个数为0时报错
if (DemoMode.KeyIDList.Count != 0)
{
interval = 10 * 1000 / DemoMode.KeyIDList.Count;
//杨斌 2014-04-22
int max = 200;
if (interval > max)
interval = max;
}
//interval = interval > 500 ? 500 : interval;//杨斌 2012-10-15,去掉此行
DemoMode.Interval = interval;
return true;
}
#region IResponse 成员
public event ResponseEventHander ResponseEventHander;
///
/// 开始演示投票
///
public void Start()
{
IniKeypadArea();
switch (ResponseType)
{
case ResponseType.Choice:
IniChoice();
break;
case ResponseType.Grade:
IniGrade();
break;
case ResponseType.Group:
IniGroup();
break;
case ResponseType.Vote:
IniVote();
break;
case ResponseType.Judge:
IniJudge();
break;
case ResponseType.Number:
IniNumber();
break;
case ResponseType.Order:
IniOrder();
break;
case ResponseType.Poll:
IniPoll();
break;
case ResponseType.Score:
IniScore();
break;
case ResponseType.SignIn:
IniSigIn();
break;
default:
break;
}
DemoMode.Start();
}
///
/// 选择题初始化参数
///
private void IniChoice()
{
ChoiceDemo choice = new ChoiceDemo();
choice.IsForced = TagSet.GetValue(TagKey.Choice_IisN).ToBoolean;//杨斌 2012-06-27 演示模式时应判断是否迫选
choice.IsABC = true;//TagSet.GetValue(TagKey.KeypadPara_OptionMode).ToInt;//杨斌 2012-06-27
choice.OptionCount = TagSet.GetValue(TagKey.Choice_OptionCount).ToInt;
choice.LimitCount = TagSet.GetValue(TagKey.Choice_OptionLimit).ToInt;
choice.IsOrderly = true;
DemoMode.DemoType = choice;
}
///
/// 等级初始化参数
///
private void IniGrade()
{
ChoiceDemo grade = new ChoiceDemo();
grade.IsForced = false;//杨斌 2012-06-27
grade.IsABC = true;//TagSet.GetValue(TagKey.KeypadPara_OptionMode).ToInt;//杨斌 2012-06-27
grade.LimitCount = 1;
grade.OptionCount = TagSet.GetValue(TagKey.Grade_OptionCount).ToInt;
DemoMode.DemoType = grade;
}
///
/// 分组初始化参数
///
private void IniGroup()
{
ChoiceDemo gruop = new ChoiceDemo();
gruop.IsForced = false;//杨斌 2012-06-27
gruop.IsABC = true;//TagSet.GetValue(TagKey.KeypadPara_OptionMode).ToInt == 1 ? 0 : 1;//杨斌 2012-06-27
gruop.LimitCount = 1;
gruop.OptionCount = TagSet.GetValue(TagKey.Group_OptionCount).ToInt;
DemoMode.DemoType = gruop;
}
///
/// 判断初始化参数
///
private void IniJudge()
{
ChoiceDemo judge = new ChoiceDemo();
judge.IsForced = false;//杨斌 2012-06-27
judge.IsABC = true;//TagSet.GetValue(TagKey.KeypadPara_OptionMode).ToInt == 1 ? 0 : 1;//杨斌 2012-06-27
judge.LimitCount = 1;
judge.OptionCount = 2;
DemoMode.DemoType = judge;
}
//初始化表决
private void IniVote()
{
ChoiceDemo vote = new ChoiceDemo();
vote.IsForced = false;//杨斌 2012-06-27
vote.IsABC = true;//TagSet.GetValue(TagKey.KeypadPara_OptionMode).ToInt == 1 ? 0 : 1;//杨斌 2012-06-27
vote.LimitCount = 1;
vote.OptionCount = TagSet.GetValue(TagKey.Vote_OptionCount).ToInt;
DemoMode.DemoType = vote;
}
///
/// 数值初始化
///
private void IniNumber()
{
NumberDemo number = new NumberDemo();
//number.MaxLength = 10;
string lowRange = TagSet.GetValue(TagKey.Number_LowRange).Value;
string highRange = TagSet.GetValue(TagKey.Number_HighRange).Value;
string dec = TagSet.GetValue(TagKey.Number_DecimalFormat).Value;
number.Decimal = (dec.Trim() == "") ? 0 : (ConvertOper.Convert(dec).ToInt);//Convert.ToInt32有问题。杨斌 2012-11-15
//最小值
number.MinVal = (lowRange.Trim() == "") ? -9999999 : (ConvertOper.Convert(lowRange).ToInt);//Convert.ToInt32有问题。杨斌 2012-11-15
//最大值
number.MaxVal = (highRange.Trim() == "") ? 9999999 : (ConvertOper.Convert(highRange).ToInt);//Convert.ToInt32有问题。杨斌 2012-11-15
DemoMode.DemoType = number;
}
///
/// 初始化排序
///
private void IniOrder()
{
ChoiceDemo order = new ChoiceDemo();
order.IsForced = TagSet.GetValue(TagKey.Order_IisN).ToBoolean;//杨斌 2012-06-27 演示模式时应判断是否迫选
order.IsABC = true;//TagSet.GetValue(TagKey.KeypadPara_OptionMode).ToInt == 1 ? 0 : 1;//杨斌 2012-06-27
order.OptionCount = TagSet.GetValue(TagKey.Order_OptionCount).ToInt;
order.LimitCount = TagSet.GetValue(TagKey.Order_OptionLimit).ToInt;
order.IsOrderly = false;
DemoMode.DemoType = order;
}
///
/// 初始化选举
///
private void IniPoll()
{
NumberDemo poll = new NumberDemo();
poll.Decimal = 0;
//poll.MaxLength = 10;
if (PollList.Count > 0)
{
//最小值
poll.MinVal = 0;
//最大值
poll.MaxVal = PollList.Count - 1;
}
else//杨斌 2014-10-24
{
//最小值
poll.MinVal = 8801;
//最大值
poll.MaxVal = 8820;
}
DemoMode.DemoType = poll;
}
///
/// 初始化分数
///
private void IniScore()
{
NumberDemo score = new NumberDemo();
string lowRange = TagSet.GetValue(TagKey.Score_LowRange).Value;
string highRange = TagSet.GetValue(TagKey.Score_HighRange).Value;
string dec = TagSet.GetValue(TagKey.Score_DecimalFormat).Value;
//score.MaxLength = 10;
score.Decimal = (dec.Trim() == "") ? 0 : (ConvertOper.Convert(dec).ToInt);//Convert.ToInt32有问题。杨斌 2012-11-15
//最小值
score.MinVal = (lowRange.Trim() == "") ? 0 : (ConvertOper.Convert(lowRange).ToInt);//Convert.ToInt32有问题。杨斌 2012-11-15
//最大值
score.MaxVal = (highRange.Trim() == "") ? 99999 : (ConvertOper.Convert(highRange).ToInt);//Convert.ToInt32有问题。杨斌 2012-11-15
DemoMode.DemoType = score;
}
///
/// 初始化签到
///
private void IniSigIn()
{
BaseDemo signIn = new BaseDemo();
signIn.ResultValue = "1";
DemoMode.DemoType = signIn;
}
///
/// 键盘测试
///
public void KeyTestStart()
{
ChoiceDemo vote = new ChoiceDemo();
vote.OptionCount = 3;
vote.LimitCount = 1;
DemoMode.DemoType = vote;
DemoMode.Start();
}
public void Stop()
{
DemoMode.Stop();
}
///
/// 基站连接类,演示模式不需要
///
public SunVote.BaseConnection BaseConnection { get; set; }
///
/// 幻灯片容器
///
public TagSet TagSet { get; set; }
///
/// 反馈类型
///
public ResponseType ResponseType { get; set; }
#endregion
}
}