/*-------------------------------------------------------------------------------------------
* 答题正确率
* 创建:杨斌 2011-12-01
* 修改:杨斌 2012-03-01
* ----------------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GeneralLib;
using Microsoft.Office.Interop.PowerPoint;
namespace SunVoteARSPPT
{
public partial class FrmAnalyzeRateOption : Form
{
///
/// 图表类
///
public ManageChart Chart = null;
public FrmAnalyzeRateOption()
{
InitializeComponent();
}
//退出
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 是否正在加载窗体
///
private bool IsLoading = false;
//窗体加载
private void FrmAnalyzeRateOption_Load(object sender, EventArgs e)
{
GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
lvwOptionRate.Columns[0].Text = " " + lvwOptionRate.Columns[0].Text;
IsLoading = true;
ResponseDB.UpdateSlideIndexToDB();
Chart = new ManageChart();
Chart.MsChart = this.MSChart;
MSChart.Dock = DockStyle.Fill;
ControlOper.SetPosCheckBoxToListViewHead(lvwOptionRate, chkSelectAllOptionRate);//杨斌 2012-11-16
LoadSlide();
ShowTopicInfo();
LoadSlideOptionRate();
ShowChartRateOption();
IsLoading = false;
//杨斌 2014-07-25
List lstRadio = new List();
lstRadio.Add(GlobalInfo.IniCtlSystem.ReadString(this.Name, "ChartDataLabel", ""));
lstRadio.Add(GlobalInfo.IniCtlSystem.ReadString(this.Name, "ChartType", ""));
ControlOper.SetControlCheck(this, lstRadio);
//杨斌 2019-07-04
if (SelectSlideID > 0)
{
foreach (ListViewItem v in lvwSlide.Items)
{
if ((v.Tag + "") == ("'" + SelectSlideID + "'"))
{
v.Selected = true;
}
}
}
}
///
/// 查询的反馈题目类型
///
private const string cResponseType = "'Group','Choice','Judge','Vote','Grade'";//,'Number','Text' 因没选项报错。杨斌 2015-01-16
///
/// 加载反馈幻灯片信息
///
private void LoadSlide()
{
try
{
lvwSlide.Items.Clear();
//加载数据
string sql = "Select * From ST_Topic" +
" WHERE (((ST_Topic.TT_ID) IN(" + cResponseType + ")) AND (Len(ST_Topic.T_ID)<12))" +
" Order By T_Index Asc";
GlobalInfo.DBOperation.OpenDataSet(sql);
System.Data.DataTable tb = GlobalInfo.DBOperation.DataSet.Tables[0];
for (int iRow = 0; iRow < tb.Rows.Count; iRow++)
{
DataRow row = tb.Rows[iRow];
ListViewItem item = lvwSlide.Items.Add(row["T_Index"].ToString());
item.SubItems.Add(row["T_Title"].ToString());
item.Tag = "'" + row["T_ID"].ToString() + "'";//存放题目ID
item.SubItems[0].Tag = row["TT_ID"] + "";//杨斌 2018-06-20
}
GlobalInfo.DBOperation.CloseDataSet();
//默认选中题目
if (lvwSlide.Items.Count > 0) lvwSlide.Items[0].Selected = true;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 加载题目反馈结果的选项比率,按高比率低排序
///
private void LoadSlideOptionRate()
{
try
{
lvwOptionRate.Items.Clear();//杨斌 空白的需清理,放在return前面
ListViewItem selItem = null;
if (lvwSlide.SelectedItems.Count > 0)
selItem = lvwSlide.SelectedItems[0];
if (selItem == null) return;
string topicID = selItem.Tag.ToString();
//杨斌 2018-06-20
string topicType = selItem.SubItems[0].Tag + "";
bool haveCorrect = ((topicType == "Choice") || (topicType == "Judge"));//"'Group','Choice','Judge','Vote','Grade'"
//杨斌 2019-10-10。修正没有正确答案的题目显示错误选项百分比
if (haveCorrect)
{
bool hasCorrectAsw = false;
string responseType = "'Choice','Judge'";
Dictionary> dicTopicPar = ReportEx.GetTopicPar(responseType);
string tid = topicID.Trim('\'');
if (dicTopicPar[tid].ContainsKey("CorrectAnswer"))
hasCorrectAsw = !string.IsNullOrEmpty(dicTopicPar[tid]["CorrectAnswer"]);
haveCorrect = hasCorrectAsw;
}
//杨斌 2012-10-24
string sql = "SELECT ST_Response.R_Result, ST_Response.R_Correct, Count(ST_Response.R_Result) AS R_ResultCount" +
" FROM ST_Response" +
" GROUP BY ST_Response.R_Result, ST_Response.R_Correct, ST_Response.T_ID" +
" HAVING (((ST_Response.T_ID)=" + topicID + "))" +
" ORDER BY ST_Response.R_Correct DESC, Count(ST_Response.R_Result) DESC, ST_Response.R_Result ASC";
GlobalInfo.DBOperation.OpenDataSet(sql);
System.Data.DataTable tb = GlobalInfo.DBOperation.DataSet.Tables[0];
int countResult = 0;
//杨斌 2012-06-29
bool bABCD = PPTOper.IsABCDItemBySlideId(ConvertOper.Convert(topicID.Replace("'", "")).ToInt);
for (int iRow = 0; iRow < tb.Rows.Count; iRow++)
{
DataRow row = tb.Rows[iRow];
string result = row["R_Result"].ToString();
//杨斌 2012-06-29
if (bABCD)
result = PPTOper.FormatNumABC(result);
result = PublicFunction.TrimEndStr(result, ",");
//杨斌 2012-11-14
string sR = GlobalInfo.SysLanguage.LPT.ReadString("FrmAnalyzeRateCorrect", "lblLegentCorrect", "Right");
string sW = GlobalInfo.SysLanguage.LPT.ReadString("FrmAnalyzeRateCorrect", "lblLegentWrong", "Wrong");
byte[] aR = System.Text.Encoding.Unicode.GetBytes(sR);
byte[] aW = System.Text.Encoding.Unicode.GetBytes(sW);
if (aR.Length > aW.Length)
{
sW = sW.PadRight(aR.Length - aW.Length + 1, ' ');
}
else if (aR.Length < aW.Length)
{
sR = sR.PadRight(aW.Length - sR.Length + 1, ' ');
}
if (haveCorrect)//杨斌 2018-06-20
{
if (ConvertOper.Convert(row["R_Correct"].ToString()).ToInt > 0)
result = sR + " " + result;
else
result = sW + " " + result;
}
ListViewItem item = lvwOptionRate.Items.Add(result);
int countItem = ConvertOper.Convert(row["R_ResultCount"].ToString()).ToInt;
countResult += countItem;
item.SubItems.Add(row["R_ResultCount"].ToString());
item.Tag = ConvertOper.Convert(row["R_ResultCount"].ToString()).ToInt;
}
for (int i = 0; i < lvwOptionRate.Items.Count; i++)
{
ListViewItem item = lvwOptionRate.Items[i];
item.SubItems[1].Text += " / " + (ConvertOper.Convert(item.SubItems[1].Text).ToInt / (double)countResult).ToString("P2");
}
lvwOptionRate.Tag = countResult;//记住分母
GlobalInfo.DBOperation.CloseDataSet();
//全选
chkSelectAllOptionRate.Checked = (lvwOptionRate.Items.Count > 0);
ControlOper.SelectAllListViewItem(lvwOptionRate, chkSelectAllOptionRate.Checked);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 显示选项选择率图表
///
private void ShowChartRateOption()
{
try
{
MSChart.Visible = false;
ListViewItem selItem = null;
if (lvwSlide.SelectedItems.Count > 0)
selItem = lvwSlide.SelectedItems[0];
int selectCount = lvwOptionRate.CheckedItems.Count;
if ((selItem == null) || (selectCount < 1)) return;
//取值
double countResult = 0;
string[] lab = new string[selectCount];
double[] data = new double[selectCount];
for (int i = 0; i < lvwOptionRate.CheckedItems.Count; i++)
{
ListViewItem item = lvwOptionRate.CheckedItems[i];
lab[i] = item.Text;//图例文本
data[i] = ConvertOper.Convert(item.Tag.ToString()).ToInt;//数据值
countResult += data[i];
}
//图例文本
Chart.LegentText = lab;
Chart.XValue = lab;
//数据值
Chart.YValues = new List();
Chart.YValues.Add(data);
//分母
Chart.LabelDenominator = ConvertOper.Convert(lvwOptionRate.Tag.ToString()).ToInt;
//图表类型
RadioButton rbtChartType = ControlOper.GetChecked(rbtChartType1);
Chart.ChartType = EnumName.GetEnum(rbtChartType.Tag.ToString());
Chart.Is3D = (rbtChartType.Name.IndexOf("3D") > 0);
//图表数据标签样式
RadioButton rbtChartDataLabel = ControlOper.GetChecked(rbtChartDataLabel1);
Chart.LabelType = EnumName.GetEnum(rbtChartDataLabel.Tag.ToString());
//图表图例显示
switch (Chart.ChartType)
{
case ChartTypes.ctPie://饼图则显示图例
Chart.LegendEnable = true;
Chart.LegentDocking = LegentDockings.ldRight;
break;
default:
Chart.LegendEnable = false;
break;
}
//图表高度
Chart.Width = MSChart.Width;
Chart.Height = MSChart.Height;
//图表标题显示题目标题。杨斌 2015-07-07
if (lvwSlide.SelectedItems.Count > 0)
{
System.Windows.Forms.DataVisualization.Charting.Chart mChart = Chart.MsChart;
mChart.Titles.Clear();
mChart.Titles.Add(lvwSlide.SelectedItems[0].SubItems[1].Text);
mChart.Titles[0].Alignment = ContentAlignment.TopCenter;
mChart.Titles[0].Font = Chart.ItemLabelFont;
}
Chart.UpdateChart();//刷新图表
MSChart.Visible = true;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 加载题目信息
///
private void ShowTopicInfo()
{
try
{
//获取题目ID和标题
ListViewItem selItem = null;
if (lvwSlide.SelectedItems.Count > 0)
selItem = lvwSlide.SelectedItems[0];
if (selItem == null) return;
string topicText = selItem.SubItems[1].Text;
string topicID = selItem.Tag.ToString();
//获取选项个数
int optionCount = 0;
string sql = "SELECT ST_TopicPar.T_ID, ST_TopicPar.TP_Value" +
" FROM ST_TopicPar" +
" WHERE (((ST_TopicPar.T_ID) In (" + topicID + ")) AND ((ST_TopicPar.TP_Name)='OptionCount'))";
GlobalInfo.DBOperation.OpenDataSet(sql);
System.Data.DataTable tb = GlobalInfo.DBOperation.DataSet.Tables[0];
for (int iRow = 0; iRow < tb.Rows.Count; iRow++)
{
DataRow row = tb.Rows[iRow];
optionCount = ConvertOper.Convert(row["TP_Value"].ToString()).ToInt;
}
GlobalInfo.DBOperation.CloseDataSet();
//获取选项文本
string[] aryWherePar = new string[optionCount];
for (int i = 0; i < optionCount; i++)
{
aryWherePar[i] = "'OptionText_" + (i + 1).ToString() + "'";
}
string wherePar = string.Join(",", aryWherePar);
string[] aryOptionText = new string[optionCount];//Key=题目ID,Item=选项文本[]
sql = "SELECT DISTINCT ST_TopicPar.T_ID, ST_TopicPar.TP_Name, ST_TopicPar.TP_Value" +
" FROM ST_TopicPar" +
" WHERE (((ST_TopicPar.TP_Name) In (" + wherePar + ")) AND ((ST_TopicPar.T_ID) In (" + topicID + ")))" +
" ORDER BY ST_TopicPar.T_ID, ST_TopicPar.TP_Name";
GlobalInfo.DBOperation.OpenDataSet(sql);
tb = GlobalInfo.DBOperation.DataSet.Tables[0];
for (int iRow = 0; iRow < tb.Rows.Count; iRow++)
{
DataRow row = tb.Rows[iRow];
string id = "'" + row["T_ID"].ToString() + "'";
string tName = row["TP_Name"].ToString();
string tValue = row["TP_Value"].ToString();
int index = ConvertOper.Convert(tName.Replace("OptionText_", "")).ToInt - 1;
//杨斌 2012-06-29
//aryOptionText[index] = (iRow + 1).ToString() + "." + tValue;
bool bABCD = PPTOper.IsABCDItemBySlideId(ConvertOper.Convert(row["T_ID"].ToString()).ToInt);
if (bABCD)
aryOptionText[index] = PPTOper.FormatNumABC(iRow + 1, false) + ". " + tValue;
else
aryOptionText[index] = (iRow + 1).ToString() + "." + tValue;
}
GlobalInfo.DBOperation.CloseDataSet();
if (topicText.Length < 1) topicText = "Slide " + selItem.Text;
string text = topicText;
text += "\r\n\r\n";
text += string.Join("\r\n", aryOptionText);
txtTopicInfo.Text = text;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
int SelectSlideID = 0;
public void ShowDialogAndTrySelect(int slideID)
{
//ShowChartFull();
SelectSlideID = slideID;
this.ShowDialog();
}
///
/// 是否全屏
///
private bool IsFullScreen = false;
private System.Drawing.Point OldFrmPoint;
private Size OldFrmSize;
private System.Drawing.Point OldPnlPoint;
private Size OldPnlSize;
///
/// 全屏显示图表
///
private void ShowChartFull()
{
if (IsFullScreen)
{
IsFullScreen = false;
this.ControlBox = true;
this.Text = this.Tag.ToString();
pnlChart.Dock = DockStyle.None;
this.Location = OldFrmPoint;
this.Size = OldFrmSize;
pnlChart.Location = OldPnlPoint;
pnlChart.Size = OldPnlSize;
pnlChart.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
}
else
{
IsFullScreen = true;
OldFrmPoint = this.Location;
OldFrmSize = this.Size;
OldPnlPoint = pnlChart.Location;
OldPnlSize = pnlChart.Size;
this.Tag = this.Text;
this.Text = "";
this.ControlBox = false;
pnlChart.Dock = DockStyle.Fill;
pnlChart.BringToFront();
this.Location = new System.Drawing.Point(0, 0);
//杨斌 2014-09-17
Screen scrShow = ControlOper.GetSecondScreen();
this.Size = new Size(scrShow.Bounds.Width, scrShow.Bounds.Height);
}
ControlOper.CenterForm(this, IsFullScreen);//杨斌 2014-09-17
}
//选择题目时加载选项选择率排序,并自动选中选择率,显示图表
private void lvwSlide_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsLoading) return;
ShowTopicInfo();
LoadSlideOptionRate();
ShowChartRateOption();
}
//选择显示的结果选项
private void lvwOptionRate_ItemChecked(object sender, ItemCheckedEventArgs e)
{
if (IsLoading) return;
IsLoading = true;
chkSelectAllOptionRate.Checked = ((lvwOptionRate.CheckedItems.Count > 0) && (lvwOptionRate.CheckedItems.Count == lvwOptionRate.Items.Count));
IsLoading = false;
ShowChartRateOption();
}
//全选结果选项
private void chkSelectAllOptionRate_CheckedChanged(object sender, EventArgs e)
{
if (IsLoading) return;
IsLoading = true;
ControlOper.SelectAllListViewItem(lvwOptionRate, chkSelectAllOptionRate.Checked);
IsLoading = false;
ShowChartRateOption();
}
//选择图表数据标签类型
private void rbtChartDataLabel_CheckedChanged(object sender, EventArgs e)
{
if (IsLoading) return;
ShowChartRateOption();
GlobalInfo.IniCtlSystem.WriteValue(this.Name, "ChartDataLabel", (sender as Control).Name);//杨斌 2014-07-25
}
//选择图表样式
private void rbtChartType_CheckedChanged(object sender, EventArgs e)
{
if (IsLoading) return;
ShowChartRateOption();
GlobalInfo.IniCtlSystem.WriteValue(this.Name, "ChartType", (sender as Control).Name);//杨斌 2014-07-25
}
//双击全屏
private void pnlChart_DoubleClick(object sender, EventArgs e)
{
ShowChartFull();
}
//窗体按键响应
private void FrmAnalyzeRateOption_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Escape:
if (IsFullScreen)
ShowChartFull();
else
this.Close();
break;
}
}
private void btnShowFull_Click(object sender, EventArgs e)
{
}
}
}