using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.PowerPoint;
using GeneralLib;
namespace SunVoteARSPPT
{
public partial class PanelOrder : UserControl, IPanel, IPanelChange
{
TagSet mTagSet = null;
public TagSet TagSet
{
get { return mTagSet; }
set
{
mTagSet = value;
ucResponsePara.TagSet = value;
ucKeypadPara.TagSet = value;
}
}
public PanelOrder()
{
InitializeComponent();
FrmSystemSet.LanguageSetEvent += new FrmSystemSet.LanguageSetEventHander(FrmSystemSet_LanguageSetEvent);
FrmVoteBar.PanelEnabledEvent += new FrmVoteBar.PanelEnabledEventHander(FrmVoteBar_PanelEnabledEvent);
gbxChoise.Resize += gbxChoise_Resize;
pnlScoreAnswer.Resize += pnlScoreAnswer_Resize;
//设置控件大小
//杨斌 2015-04-10
//ucResponsePara.HideVoteRate();
ucResponsePara.ShowSet(true, false);
ucKeypadPara.Top = ucResponsePara.Bottom + 6;
this.Height = ucKeypadPara.Bottom;
////GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
UpdateLan();//杨斌 2016-06-01
//杨斌 2012-06-11
switch (GlobalInfo.OEMLogo)
{
case OEMLogos.oem3eAnalyzer:
//ucKeypadPara.Visible = false;
//if (ucKeypadPara.cboSubmitMode.SelectedIndex != 0)
// ucKeypadPara.cboSubmitMode.SelectedIndex = 0;
//this.Height = ucResponsePara.Bottom;
break;
case OEMLogos.SunVote:
default:
break;
}
//杨斌 2012-06-25
ucKeypadPara.cboOptionMode.SelectedIndex = 0;
ucKeypadPara.cboOptionMode.Enabled = false;
}
void gbxChoise_Resize(object sender, EventArgs e)
{
int pos = gbxChoise.ClientSize.Width / 2;
int w = pos - 3;
nudOptionCount.Left = pos;
//nudOptionCount.Width = w;
nudOptionLimit.Left = pos;
//nudOptionLimit.Width = w;
}
void pnlScoreAnswer_Resize(object sender, EventArgs e)
{
int pos = pnlScoreAnswer.ClientSize.Width / 2;
int w = pos - 3;
lblScoreWrong.Left = pos;
//lblScoreWrong.Width = w;
nudScoreWrong.Left = pos;
//nudScoreWrong.Width = w;
}
void FrmVoteBar_PanelEnabledEvent(bool enabled)
{
this.Enabled = enabled;
}
///
/// 刷新语言。杨斌 2016-06-01
///
private void UpdateLan()
{
GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
lblCorrectAnswerMatch.Text = lblCorrectAnswer.Text;
}
void FrmSystemSet_LanguageSetEvent()
{
UpdateLan();//杨斌 2016-06-01
////GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
}
private void PanelOrder_Load(object sender, EventArgs e)
{
InitItemScore();
////GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
UpdateLan();//杨斌 2016-06-01
//杨斌 2015-05-22
decimal max = nudOptionCount.Value;
//if (GlobalInfo.GetSdkType() == 1)
// if (max > 8)
// max = 8;
nudOptionLimit.Maximum = max;
}
private void btnChartSet_Click(object sender, EventArgs e)
{
new FrmChartSet().ShowDialog();
}
private void rbtScoreAnswer_CheckedChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_ScoreMode, rbtScoreItem.Checked ? 1 : 0);
ShowScorePanel();
LoadCorrectAnwser();//杨斌 2016-06-02
//杨斌 2014-04-22
Globals.SunVoteARSAddIn.PPTEdit.Panel.ucChartPara.Visible = rbtScoreItem.Checked;
if (rbtScoreItem.Checked)//杨斌 2016-01-21
Globals.SunVoteARSAddIn.PPTEdit.Panel.ucChartPara.InitPanelPar(true, true, true, true, true, true);
Globals.SunVoteARSAddIn.PPTEdit.InitChart(true, Globals.SunVoteARSAddIn.PPTEdit.SlideEdit);
}
private void rbtScoreItem_CheckedChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_ScoreMode, rbtScoreItem.Checked ? 1 : 0);
ShowScorePanel();
//杨斌 2014-04-22
Globals.SunVoteARSAddIn.PPTEdit.Panel.ucChartPara.Visible = rbtScoreItem.Checked;
Globals.SunVoteARSAddIn.PPTEdit.InitChart(true, Globals.SunVoteARSAddIn.PPTEdit.SlideEdit);
}
private void rbtScoreMatch_CheckedChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_ScoreMode, 2);//计分模式3,按配对匹配项计分
LoadCorrectAnwser();//杨斌 2016-06-02
ShowScorePanel();
}
private void ShowScorePanel()
{
pnlScoreAnswer.Visible = rbtScoreAnswer.Checked;
//杨斌 2016-06-01
dgvScore.Visible = rbtScoreItem.Checked || rbtScoreMatch.Checked;
lblCorrectAnswerMatch.Visible = txtCorrectAnswerMatch.Visible = rbtScoreMatch.Checked;
if (rbtScoreMatch.Checked)
{
chkAABB.Enabled = nudOptionLimit.Enabled = false;
chkIisN.Enabled = false;
nudOptionLimit.Value = nudOptionCount.Value;
chkIisN.Checked = true;
chkAABB.Checked = false;
TagSet.SetValue(TagKey.Order_IisN, chkIisN.Checked ? 1 : 0);
TagSet.SetValue(TagKey.Order_AABB, chkAABB.Checked ? 1 : 0);
}
else
{
chkAABB.Enabled = nudOptionLimit.Enabled = true;
chkIisN.Enabled = !chkAABB.Checked;
}
}
private void InitItemScore()
{
//dgvScore.RowCount = 5;
//for (int i = 0; i < dgvScore.Rows.Count; i++)
//{
// dgvScore.Rows[0].Cells[0].Value = "1/A";
// dgvScore.Rows[0].Cells[1].Value = "0";
// dgvScore.Rows[0].Cells[2].Value = "2/B";
// dgvScore.Rows[0].Cells[3].Value = "0";
//}
int optionCount = (int)nudOptionCount.Value;
bool colFirst = true;
dgvScore.Columns[0].HeaderText = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "dgvScore_0", "序号");
dgvScore.Columns[1].HeaderText = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "dgvScore_1", "分数");
if (colFirst)//逐列,与正确答案的控件一致
{
if (optionCount <= 5)
{
dgvScore.ColumnCount = 2;
dgvScore.RowCount = optionCount;
}
else
{
dgvScore.ColumnCount = 4;
dgvScore.RowCount = 5;
dgvScore.Columns[2].HeaderText = dgvScore.Columns[0].HeaderText;
dgvScore.Columns[3].HeaderText = dgvScore.Columns[1].HeaderText;
}
ControlOper.SetGridRowH(dgvScore);//杨斌 2016-03-04
for (int col = 0; col < dgvScore.Columns.Count; col++)
dgvScore.Columns[col].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
int num = 0;
for (int col = 0; col < dgvScore.Columns.Count; col += 2)
{
for (int row = 0; row < dgvScore.Rows.Count; row++)
{
num++;
if (num <= optionCount)
{
dgvScore.Rows[row].Cells[col].Value = num;//PPTOper.FormatNumABC(num, true);//数字/字母
//加载分数
dgvScore.Rows[row].Cells[col + 1].Value = "0";
}
else
{
dgvScore.Rows[row].Cells[col].Value = "";
dgvScore.Rows[row].Cells[col + 1].Value = "";
}
}
}
}
else//逐行
{
if (optionCount <= 1)
{
dgvScore.ColumnCount = 2;
dgvScore.RowCount = 1;
}
else
{
dgvScore.ColumnCount = 4;
dgvScore.RowCount = optionCount / 2 + ((optionCount % 2) > 0 ? 1 : 0);
dgvScore.Columns[2].HeaderText = dgvScore.Columns[0].HeaderText;
dgvScore.Columns[3].HeaderText = dgvScore.Columns[1].HeaderText;
}
ControlOper.SetGridRowH(dgvScore);//杨斌 2016-03-04
int num = 0;
for (int row = 0; row < dgvScore.Rows.Count; row++)
{
for (int col = 0; col < dgvScore.Columns.Count; col++)
{
num++;
int m = col * 2;
if (num <= optionCount)
{
dgvScore.Rows[row].Cells[m].Value = PPTOper.FormatNumABC(num, true);//数字/字母
//加载分数
//double score = TagSet.LoadValue(TagSet.GetName(TagKey.Order_ScoreItem_) + num.ToString(), 0);
dgvScore.Rows[row].Cells[m + 1].Value = "0";
}
else
{
dgvScore.Rows[row].Cells[m].Value = "";
dgvScore.Rows[row].Cells[m + 1].Value = "";
}
}
}
}
}
private void nudChoiseLimit_ValueChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_OptionLimit, nudOptionLimit.Value);
txtCorrectAnswer.MaxLength = Convert.ToInt32(nudOptionLimit.Value);
try
{
string sAnswer = "";
for (int i = 0; i < Convert.ToInt32(nudOptionLimit.Value); i++)
{
if (i == 9)
sAnswer += "0";
else
sAnswer += (i + 1).ToString();
}
txtCorrectAnswer.Text = sAnswer;
txtCorrectAnswerMatch.Text = sAnswer;//杨斌 2016-06-02
SaveCorrectAnwser(txtCorrectAnswer);
}
catch { }
}
private void btnOptionText_Click(object sender, EventArgs e)
{
new FrmOptionTextSelect().ShowDialog();//杨斌 2013-01-24;
}
///
/// 加载参数面板数据
///
public void LoadData()
{
try
{
ucResponsePara.LoadData();
ucKeypadPara.LoadData();
ControlOper.TrySetNumericUpDownValue(nudOptionCount, TagSet.LoadValue(TagKey.Order_OptionCount, nudOptionCount.Value).ToInt);
ControlOper.TrySetNumericUpDownValue(nudOptionLimit, TagSet.LoadValue(TagKey.Order_OptionLimit, nudOptionLimit.Value).ToInt);
//if (chkAABB.Enabled)
chkAABB.Checked = TagSet.LoadValue(TagKey.Order_AABB, chkAABB.Checked ? 1 : 0).ToBoolean;
//if (chkIisN.Enabled)
chkIisN.Checked = TagSet.LoadValue(TagKey.Order_IisN, chkIisN.Checked ? true : false).ToBoolean;
chkCDBA.Checked = true;
//杨斌 2016-05-30
int scoreMode = TagSet.LoadValue(TagKey.Order_ScoreMode, 0).ToInt;
if (scoreMode == 1)
rbtScoreItem.Checked = true;
else if (scoreMode == 2)
rbtScoreMatch.Checked = true;
else
rbtScoreAnswer.Checked = true;
//if (TagSet.LoadValue(TagKey.Order_ScoreMode, rbtScoreItem.Checked ? 1 : 0).ToInt == 1)
// rbtScoreItem.Checked = true;
//else
// rbtScoreAnswer.Checked = true;
ControlOper.TrySetNumericUpDownValue(nudScoreRight, TagSet.LoadValue(TagKey.Order_ScoreRight, nudScoreRight.Value).ToInt);
ControlOper.TrySetNumericUpDownValue(nudScoreWrong, TagSet.LoadValue(TagKey.Order_ScoreWrong, nudScoreWrong.Value).ToInt);
LoadCorrectAnwser();
LoadOptionScore();//加载选项分数
ShowScorePanel();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public void ChangeData(TagKey tagKey, object value)
{
if (tagKey == TagKey.Order_OptionCount)
ControlOper.TrySetNumericUpDownValue(nudOptionCount, TagSet.LoadValue(tagKey, nudOptionCount.Value).ToInt);
}
private void nudOptionCount_ValueChanged(object sender, EventArgs e)
{
//杨斌 2015-05-22
decimal max = nudOptionCount.Value;
//if (GlobalInfo.GetSdkType() == 1)
// if (max > 8)
// max = 8;
nudOptionLimit.Maximum = max;
TagSet.SetValue(TagKey.Order_OptionCount, nudOptionCount.Value);
//if (nudOptionLimit.Value = nudOptionCount.Value)
// nudOptionLimit.Value = nudOptionCount.Value;
InitItemScore();
LoadOptionScore();
SaveOptionScore();//保存选项分数
if (!Globals.SunVoteARSAddIn.PPTEdit.LockOptionTextChange)//判断是否选项文本在修改,杨斌 2012-03-05
{
Globals.SunVoteARSAddIn.PPTEdit.ModifyOptionText(Convert.ToInt32(nudOptionCount.Value));
}
Globals.SunVoteARSAddIn.PPTEdit.InitChart(true, Globals.SunVoteARSAddIn.PPTEdit.SlideEdit, autoFit: true);//杨斌 2014-04-22
}
private void chkAABB_CheckedChanged(object sender, EventArgs e)
{
if (!chkAABB.Enabled) return;
TagSet.SetValue(TagKey.Order_AABB, chkAABB.Checked ? 1 : 0);
if (chkAABB.Checked)
{
chkIisN.Enabled = false;
chkIisN.Checked = false;
TagSet.SetValue(TagKey.Order_IisN, 0);
}
else
{
chkIisN.Enabled = true;
}
}
private void chkIisN_CheckedChanged(object sender, EventArgs e)
{
if (!chkIisN.Enabled) return;
TagSet.SetValue(TagKey.Order_IisN, chkIisN.Checked ? 1 : 0);
}
private void nudScoreRight_ValueChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_ScoreRight, nudScoreRight.Value);
}
private void nudScoreWrong_ValueChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_ScoreWrong, nudScoreWrong.Value);
}
///
/// 获得排序的正确答案字符串,用于保存到Tag。如120->1,2,10
/// 杨斌 2014-02-18
///
///
///
public static string GetOrderCorrectAnswer(string numList)
{
string Answer = "";
for (int i = 0; i < numList.Length; i++)
{
if (i > 0)
Answer += ",";
if (numList.Substring(i, 1) == "0")
Answer += "10";
else
Answer += numList.Substring(i, 1);
}
return Answer;
}
private void SaveCorrectAnwser(TextBox txtAnswer)
{
string Anwser = "";
for (int i = 0; i < txtAnswer.Text.Length; i++)
{
if (i > 0)
Anwser += ",";
if (txtAnswer.Text.Substring(i, 1) == "0")
Anwser += "10";
else
Anwser += txtAnswer.Text.Substring(i, 1);
}
TagSet.SetValue(TagKey.Order_CorrectAnswer, Anwser);
}
private void LoadCorrectAnwser()
{
string Anwser = TagSet.LoadValue(TagKey.Order_CorrectAnswer, "").Value;
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];
}
}
txtCorrectAnswer.Text = Anwser;
txtCorrectAnswerMatch.Text = Anwser;//杨斌 2016-06-02
}
private void txtCorrectAnswer_TextChanged(object sender, EventArgs e)
{
SaveCorrectAnwser(txtCorrectAnswer);
Globals.SunVoteARSAddIn.PPTEdit.RefreshLabelEdit(DataLabelType.ANSWER);//杨斌 2012-03-15
}
//杨斌 2016-06-02
private void txtCorrectAnswerMatch_TextChanged(object sender, EventArgs e)
{
SaveCorrectAnwser(txtCorrectAnswerMatch);
}
private void txtCorrectAnswer_KeyPress(object sender, KeyPressEventArgs e)
{
//阻止从键盘输入键
e.Handled = true;
//当输入为0-9的数字、小数点、回车和退格键时不阻止
//允许最小分数和最大分数只能是整数
if (e.KeyChar >= '0' && e.KeyChar <= '9' || e.KeyChar == 13 || e.KeyChar == (char)8)
{
e.Handled = false;
}
//2013-2-19 赵丽 不允许输入重复字符
//for (int i = 0; i < txtCorrectAnswer.Text.Length; i++)
//{
// string sVal=txtCorrectAnswer.Text
// if()
// {
// e.Handled =false ;
// break;
// }
//}
}
private void dgvScore_CellClick(object sender, DataGridViewCellEventArgs e)
{
if ((e.ColumnIndex % 2) == 0) return;
if ((e.RowIndex + 1 + (e.ColumnIndex - 1) / 2 * dgvScore.Rows.Count) > nudOptionCount.Value) return;
dgvScore.BeginEdit(true);
}
private void dgvScore_MouseLeave(object sender, EventArgs e)
{
dgvScore.EndEdit();
}
private void dgvScore_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
SaveOptionScore();
}
private void LoadOptionScore()
{
string optionScore = TagSet.LoadValue(TagKey.Order_ScoreOption, "").Value;
int optionCount = (int)nudOptionCount.Value;
Dictionary dicScore = PublicFunction.GetItemScore(optionScore);
int num = 0;
for (int col = 0; col < dgvScore.Columns.Count; col += 2)
{
for (int row = 0; row < dgvScore.Rows.Count; row++)
{
num++;
if (num <= optionCount)
{
//分数
if (dicScore.ContainsKey(num))
dgvScore.Rows[row].Cells[col + 1].Value = dicScore[num].ToString();
else
dgvScore.Rows[row].Cells[col + 1].Value = "0";
}
}
}
}
private void SaveOptionScore()
{
int optionCount = (int)nudOptionCount.Value;
string optionScore = "";
Dictionary dicScore = new Dictionary();
int num = 0;
for (int col = 0; col < dgvScore.Columns.Count; col += 2)
{
for (int row = 0; row < dgvScore.Rows.Count; row++)
{
num++;
if (num <= optionCount)
{
double score = 0;
try
{
score = new ConvertOper(dgvScore.Rows[row].Cells[col + 1].Value.ToString()).ToDouble;
//限制分数。杨斌 2012-11-07
double scoreMin = -100;
double scoreMax = 100;
switch (GlobalInfo.OEMLogo)
{
case OEMLogos.oem3eAnalyzer:
if (score < scoreMin)
{
score = scoreMin;
dgvScore.Rows[row].Cells[col + 1].Value = score.ToString();
}
if (score > scoreMax)
{
score = scoreMax;
dgvScore.Rows[row].Cells[col + 1].Value = score.ToString();
}
break;
default:
break;
}
}
catch { score = 0; }
dicScore.Add(num, score);
}
}
}
int[] aryNum = new int[dicScore.Count];
double[] aryScore = new double[dicScore.Count];
dicScore.Keys.CopyTo(aryNum, 0);
dicScore.Values.CopyTo(aryScore, 0);
for (int i = 0; i < dicScore.Count; i++)
{
if (aryScore[i] != 0)
{
if ((optionScore.Length > 0))
optionScore += PublicFunction.SplitItemScore;//杨斌 2019-07-19
optionScore += aryNum[i].ToString() + "=" + aryScore[i].ToString();
}
}
TagSet.SetValue(TagKey.Order_ScoreOption, optionScore);
}
}
}