using GeneralLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SunVoteARSPPT
{
public class ARSChoise : IResponse
{
///
/// 选择类
///
public SunVote.Choices Choise = null;
public SunVote.Sequence Sequence = null;//杨斌 2012-06-27 多选保留顺序
public SunVote.Vote Vote = null;//杨斌 2013-11-12
public SunVote.TrueFalse TrueFalse = null;//杨斌 2014-10-20
///
/// 硬件测试类
///
private SunVote.HardwareTest hardwareTest = null;
//杨斌 2012-06-27
private bool IsStartChoise = false;
private bool IsStartSequence = false;
//杨斌 2013-11-13
private bool IsStartVote = false;
//杨斌 2014-10-20
private bool IsStartTF = false;
///
/// 键盘模拟测试。杨斌 2015-03-30
///
private bool IsStartTest = false;
///
/// 构造函数
///
public ARSChoise()
{
Choise = new SunVote.Choices();
Sequence = new SunVote.Sequence();//杨斌 2012-06-27
TrueFalse = new SunVote.TrueFalse();//杨斌 2014-10-20
//事件绑定
Choise.KeyStatus += new SunVote.IChoicesEvents_KeyStatusEventHandler(Choise_KeyStatus);
Sequence.KeyStatus += new SunVote.ISequenceEvents_KeyStatusEventHandler(Choise_KeyStatus);//杨斌 2012-06-27
TrueFalse.KeyStatus += new SunVote.ITrueFalseEvents_KeyStatusEventHandler(TrueFalse_KeyStatus);//杨斌 2014-10-20
//杨斌 2013-11-12
Vote = new SunVote.Vote();
Vote.KeyStatus += new SunVote.IVoteEvents_KeyStatusEventHandler(Vote_KeyStatus);
//杨斌 2015-01-09
Choise.KeyStatusSN += new SunVote.IChoicesEvents_KeyStatusSNEventHandler(Choise_KeyStatusSN);
Sequence.KeyStatusSN += new SunVote.ISequenceEvents_KeyStatusSNEventHandler(Sequence_KeyStatusSN);
TrueFalse.KeyStatusSN += new SunVote.ITrueFalseEvents_KeyStatusSNEventHandler(TrueFalse_KeyStatusSN);
Vote.KeyStatusSN += new SunVote.IVoteEvents_KeyStatusSNEventHandler(Vote_KeyStatusSN);
//硬件测试类
hardwareTest = new SunVote.HardwareTest();
//键盘测试绑定事件
hardwareTest.KeyMonitorStatus += hardwareTest_KeyMonitorStatus;
//PVS事件。杨斌 2015-03-17
FrmPvsServer.GetFrmPvs().OnKeyVote += myPVS_KeyVote;
TagSet = new TagSet();
}
void hardwareTest_KeyMonitorStatus(string BaseTag, int KeyID, int InputStatus, int ChargeStatus, double BatteryVoltage, int RfIntensity)
{
////杨斌 2015-03-27。用电量测试模拟选择
string KeyValue = BatteryVoltage.ToString();
double KeyTime = 0;
if (ResponseType == ResponseType.Choice)
{
KeyValue = "ABCDEFGHIJ";
}
ResponsePar ObjResponseValue = new ResponsePar();
ObjResponseValue.BaseTag = BaseTag;
ObjResponseValue.KeyID = KeyID.ToString();
ObjResponseValue.KeyValue = KeyValue;
ObjResponseValue.Speed = KeyTime;
if (ResponseEventHander != null)
ResponseEventHander(ObjResponseValue);
}
void myPVS_KeyVote(int ID, int iMode, string sInfo)
{
ResponsePar ObjResponseValue = new ResponsePar();
//ObjResponseValue.BaseTag = BaseTag;
ObjResponseValue.KeyID = ID.ToString();
////杨斌 2015-03-27。用电量测试模拟选择
//if (ResponseType == ResponseType.Choice)
//{
// sInfo = "ABCDEFGHIJ,0";
//}
string KeyValue = "";
double KeyTime = 0;
switch (ResponseType)
{
case SunVoteARSPPT.ResponseType.Choice:
case SunVoteARSPPT.ResponseType.Group:
case SunVoteARSPPT.ResponseType.Judge:
case SunVoteARSPPT.ResponseType.Vote:
case SunVoteARSPPT.ResponseType.Grade:
string[] ary = sInfo.Split(new char[] { ',' });
KeyValue = ary[0];
if (ary.Length >= 2)
double.TryParse(ary[1], out KeyTime);
ObjResponseValue.KeyValue = KeyValue;
ObjResponseValue.Speed = KeyTime;
break;
}
//杨斌 2016-07-18 屏蔽乱码
if (!ARSChoise.JudgePVSSelectResult(ObjResponseValue.KeyValue))
return;
if (ResponseEventHander != null)
ResponseEventHander(ObjResponseValue);
}
///
/// 键盘状态事件
///
///
///
///
///
void Choise_KeyStatus(string BaseTag, int KeyID, string KeyValue, double KeyTime)
{
Choise_KeyStatusSN(BaseTag, KeyID.ToString(), KeyValue, KeyTime);
}
void Choise_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
{
ResponsePar ObjResponseValue = new ResponsePar();
ObjResponseValue.BaseTag = BaseTag;
ObjResponseValue.KeyID = KeySN;
ObjResponseValue.KeyValue = KeyValue;
ObjResponseValue.Speed = KeyTime;
if (ResponseEventHander != null)
ResponseEventHander(ObjResponseValue);
}
void Sequence_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
{
Choise_KeyStatusSN(BaseTag, KeySN, KeyValue, KeyTime);
}
///
/// 判断题键盘事件
/// 杨斌 2014-10-20
///
///
///
///
///
void TrueFalse_KeyStatus(string BaseTag, int KeyID, string KeyValue, double KeyTime)
{
Choise_KeyStatus(BaseTag, KeyID, KeyValue, KeyTime);
}
void TrueFalse_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
{
Choise_KeyStatusSN(BaseTag, KeySN, KeyValue, KeyTime);
}
///
/// 表决键盘状态
/// 杨斌 2013-11-12
///
///
///
///
void Vote_KeyStatus(string BaseTag, int KeyID, string KeyValue)
{
Choise_KeyStatus(BaseTag, KeyID, KeyValue, 0);
}
void Vote_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
{
Choise_KeyStatusSN(BaseTag, KeySN, KeyValue, KeyTime);
}
#region IResponse 成员
///
/// 基站连接类
///
public SunVote.BaseConnection BaseConnection { get; set; }
///
/// 反馈事件
///
public event ResponseEventHander ResponseEventHander;
public TagSet TagSet { get; set; }
///
/// 反馈类型
///
public ResponseType ResponseType { get; set; }
///
/// 启用
/// 修改:杨斌 2012-06-27
/// 杨斌 2015-03-16
///
public void Start()
{
//杨斌 2016-07-18
JudgePVSSelectMax = 0;
JudgePVSSelectMin = 0;
if (GlobalInfo.GetSdkType() == 0)
{
//设置参数
Choise.BaseConnection = BaseConnection;
//选项编号模式 0:按字母,1:按数字
Choise.OptionsMode = TagSet.GetValue(TagKey.KeypadPara_OptionMode).ToInt == 1 ? 0 : 1;//杨斌 2012-06-25
//修改模式
Choise.ModifyMode = (TagSet.GetValue(TagKey.KeypadPara_ModifyMode).ToInt == 0 ? 1 : 0);
//保密模式。杨斌 2016-02-15
Choise.SecrecyMode = TagSet.GetValue(TagKey.KeypadPara_SecrecyMode).ToInt;
bool bKeepSort = false;//是否保留多选顺序
Sequence.BaseConnection = Choise.BaseConnection;
Sequence.OptionsMode = Choise.OptionsMode;
Sequence.ModifyMode = Choise.ModifyMode;
Sequence.SecrecyMode = Choise.SecrecyMode;//杨斌 2016-02-15
Vote.BaseConnection = BaseConnection;//杨斌 2013-11-13
//杨斌 2014-10-20
TrueFalse.BaseConnection = BaseConnection;
TrueFalse.ModifyMode = Choise.ModifyMode;
TrueFalse.SecrecyMode = Choise.SecrecyMode;
switch (ResponseType)
{
case ResponseType.Choice:
//迫交模式
Choise.LessEnabled = TagSet.GetValue(TagKey.Choice_IisN).ToInt;
//Choise.LessEnabled = 0;//杨斌 2012-06-04 日本的不要
//选项个数
Choise.Options = TagSet.GetValue(TagKey.Choice_OptionCount).ToInt;
//可选个数
Choise.OptionalN = TagSet.GetValue(TagKey.Choice_OptionLimit).ToInt;
if (bKeepSort && (Choise.OptionalN > 1))//多选
{
Sequence.LessEnabled = Choise.LessEnabled;
Sequence.OptionalN = Choise.Options;
Sequence.OptionalCount = Choise.OptionalN;
}
break;
case ResponseType.Group:
//迫交模式
Choise.LessEnabled = 0;
//选项个数
Choise.Options = TagSet.GetValue(TagKey.Group_OptionCount).ToInt;
//可选个数
Choise.OptionalN = 1;
break;
case ResponseType.Judge:
TrueFalse.Mode = 1;//杨斌 2014-10-20
//迫交模式
Choise.LessEnabled = 0;
//选项个数
Choise.Options = 2;
//可选个数
Choise.OptionalN = 1;
break;
case ResponseType.Vote:
//迫交模式
Choise.LessEnabled = 0;
//选项个数
Choise.Options = TagSet.GetValue(TagKey.Vote_OptionCount).ToInt;
//可选个数
Choise.OptionalN = 1;
//杨斌 2013-11-12
if (Choise.Options == 2)
Vote.Mode = 1;
else
Vote.Mode = 0;
Vote.ModifyMode = Choise.ModifyMode;
Vote.SecrecyMode = Choise.SecrecyMode;
break;
case ResponseType.Grade:
//迫交模式
Choise.LessEnabled = 0;
//选项个数
Choise.Options = TagSet.GetValue(TagKey.Grade_OptionCount).ToInt;
//可选个数
Choise.OptionalN = 1;
break;
}
if (ResponseType == ResponseType.Vote)
{
Vote.StartMode = 1;
Vote.Start();
IsStartVote = true;
}
else
{
//杨斌 2014-10-20
if ((GlobalInfo.hardwareManage.KeyModel == "S50") && (ResponseType == ResponseType.Judge))
{
TrueFalse.StartMode = 1;
TrueFalse.Start();
IsStartTF = true;
}
else
{
//键盘模拟测试。杨斌 2015-03-30
IsStartTest = false;
if (IsStartTest)
{
IsStartSequence = false;
IsStartChoise = false;
hardwareTest.BaseConnection = BaseConnection;
hardwareTest.Start();
}
else
{
//杨斌 2012-06-27
if (bKeepSort && (Choise.OptionalN > 1))//多选
{
////Sequence.SecrecyMode = 0;//杨斌 2016-02-15
Sequence.StartMode = 1;
Sequence.Start();
IsStartSequence = true;
}
else
{
//保密模式
////Choise.SecrecyMode = 0;//杨斌 2016-02-15
Choise.StartMode = 1;
Choise.Start();
IsStartChoise = true;
}
}
}
}
}
else if (GlobalInfo.GetSdkType() == 1)
{
int iMax = 0;
int iMin = 0;
//选项编号模式 0:按字母,1:按数字
int iOptionsMode = TagSet.GetValue(TagKey.KeypadPara_OptionMode).ToInt == 1 ? 0 : 1;
int iModifyMode = TagSet.GetValue(TagKey.KeypadPara_ModifyMode).ToInt == 0 ? 1 : 0;
int pvsVoteMode = 0;
string pvsVoteSetting = "";
switch (ResponseType)
{
//case SunVoteARSPPT.ResponseType.SignIn:
// pvsVoteMode = 1;
// pvsVoteSetting = "1";
// break;
case ResponseType.Choice:
//选项个数
iMax = TagSet.GetValue(TagKey.Choice_OptionCount).ToInt;
//可选个数
iMin = TagSet.GetValue(TagKey.Choice_OptionLimit).ToInt;
pvsVoteMode = 5;
pvsVoteSetting = (iOptionsMode == 0 ? 1 : 2) + "," + iMax + "," + iMin;
//杨斌 2016-07-18
JudgePVSSelectMax = iMax;
JudgePVSSelectMin = iMin;
if (iMin > 1)//特殊型号,多选时必须可以修改。杨斌 2015-11-10
{
switch (GlobalInfo.hardwareManage.KeyModel)
{
case "W00":
case "W40":
iModifyMode = 1;
break;
}
}
////杨斌 用电量测试模拟选择题
//pvsVoteMode = 15;
//pvsVoteSetting = "0";
break;
case ResponseType.Group:
//选项个数
iMax = TagSet.GetValue(TagKey.Group_OptionCount).ToInt;
//可选个数
iMin = 1;
pvsVoteMode = 5;
pvsVoteSetting = (iOptionsMode == 0 ? 1 : 2) + "," + iMax + "," + iMin;
//杨斌 2016-07-18
JudgePVSSelectMax = iMax;
JudgePVSSelectMin = iMin;
break;
case ResponseType.Judge:
//选项个数
iMax = 2;
//可选个数
iMin = 1;
if (SystemConfig.KeypadType == "W00")
{
pvsVoteMode = 2;
pvsVoteSetting = (iModifyMode == 0 ? 1 : 3).ToString();
}
else
{
pvsVoteMode = 5;
pvsVoteSetting = (iOptionsMode == 0 ? 1 : 2) + "," + iMax + "," + iMin;
//杨斌 2016-07-18
JudgePVSSelectMax = iMax;
JudgePVSSelectMin = iMin;
}
break;
case ResponseType.Vote:
if (SystemConfig.KeypadType == "W00")
{
iMax = TagSet.GetValue(TagKey.Vote_OptionCount).ToInt;
pvsVoteMode = 2;
if (iMax >= 3)//三键
pvsVoteSetting = (iModifyMode == 0 ? 5 : 7).ToString();
else//二键
pvsVoteSetting = (iModifyMode == 0 ? 1 : 3).ToString();
////杨斌 用电量测试模拟选择题
//pvsVoteMode = 15;
//pvsVoteSetting = "0";
}
else
{
//选项个数
iMax = TagSet.GetValue(TagKey.Vote_OptionCount).ToInt;
//可选个数
iMin = 1;
pvsVoteMode = 5;
pvsVoteSetting = (iOptionsMode == 0 ? 1 : 2) + "," + iMax + "," + iMin;
//杨斌 2016-07-18
JudgePVSSelectMax = iMax;
JudgePVSSelectMin = iMin;
}
break;
case ResponseType.Grade:
//选项个数
iMax = TagSet.GetValue(TagKey.Grade_OptionCount).ToInt;
//可选个数
iMin = 1;
pvsVoteMode = 5;
pvsVoteSetting = (iOptionsMode == 0 ? 1 : 2) + "," + iMax + "," + iMin;
//杨斌 2016-07-18
JudgePVSSelectMax = iMax;
JudgePVSSelectMin = iMin;
break;
default:
return;
}
FrmPvsServer.GetFrmPvs().VoteStart(pvsVoteMode, pvsVoteSetting, iModifyMode);
}
}
private static int JudgePVSSelectMax = 0;
private static int JudgePVSSelectMin = 0;
///
/// 判断键盘数据乱码
/// 杨斌 2016-07-18
///
public static bool JudgePVSSelectResult(string result)
{
bool res = false;
try
{
if (JudgePVSSelectMax > 0)
{
if (result.Length <= JudgePVSSelectMin)
{
for (int i = 0; i < result.Length; i++)
{
string s = result.Substring(i, 1).ToUpper();
int n = Convert.ToInt32(s) - 64;
if ((n >= 1) && (n <= JudgePVSSelectMax))
res = true;
}
}
}
else
res = true;
}
catch(Exception ex)
{
res = true;
SystemLog.WriterLog(ex, false);
}
return res;
}
///
/// 停止
/// 修改:杨斌 2012-06-27
///
public void Stop()
{
if (GlobalInfo.GetSdkType() == 0)
{
if (IsStartChoise)
Choise.Stop();
if (IsStartSequence)
Sequence.Stop();//杨斌 2012-06-27
//杨斌 2013-11-13
if (IsStartVote)
Vote.Stop();
if (IsStartTF)
TrueFalse.Stop();
if (IsStartTest)//杨斌 2015-03-30
hardwareTest.Stop();
}
else if (GlobalInfo.GetSdkType() == 1)
{
FrmPvsServer.GetFrmPvs().VoteStop();
}
//杨斌 2013-11-13
IsStartChoise = false;
IsStartSequence = false;
IsStartVote = false;
IsStartTF = false;
IsStartTest = false;//杨斌 2015-03-30
}
#endregion
}
}