/*-------------------------------------------------------------------------------------------
* 评议得分颜色矩阵
* ----------------------------------------------------------------------------------------*/
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;
namespace SunVoteARSPPT
{
public partial class FrmAnalyzeGradeColor : Form
{
public FrmAnalyzeGradeColor()
{
InitializeComponent();
dgvData.Dock = DockStyle.Fill;
dgvData.ColumnCount = 10;
dgvData.RowCount = 10;
foreach (DataGridViewRow row in dgvData.Rows)
{
row.MinimumHeight = dgvData.ColumnHeadersHeight;
}
dgvData.DefaultCellStyle.SelectionBackColor = dgvData.DefaultCellStyle.BackColor;
dgvData.DefaultCellStyle.ForeColor = dgvData.DefaultCellStyle.ForeColor;
foreach (DataGridViewColumn col in dgvData.Columns)
{
col.SortMode = DataGridViewColumnSortMode.NotSortable;
}
dgvData.Rows[0].Cells[0].Style.BackColor = Color.Blue;
dgvData.Rows[0].Cells[0].Style.SelectionBackColor = Color.Blue;
dgvData.ColumnHeadersHeightChanged += DgvData_ColumnHeadersHeightChanged;
}
private void DgvData_ColumnHeadersHeightChanged(object sender, EventArgs e)
{
ShowGride();
}
//public FrmAnalyzeGradeColor(bool isCross)
//{
// InitializeComponent();
// lblSlide.Left = lvwSlide.Left;
// lblSlide.Visible = false;
// lvwSlide.Height += lvwSlide.Top - lblSlide.Top;
// lvwSlide.Top = lblSlide.Top;
// chkSelectAllSlide.Visible = true;
// chkSelectAllSlide.Top = lblSlide.Top + 4;
//}
//关闭窗体
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 是否正在加载窗体
///
private bool IsLoading = false;
//加载窗体
private void FrmAnalyzeSlide_Load(object sender, EventArgs e)
{
IsLoading = true;
ResponseDB.UpdateSlideIndexToDB();
//此处加语言翻译过程
GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
//设置字体。杨斌 2019-06-27
float fontSize = 14;
dgvData.ColumnHeadersDefaultCellStyle.Font = new Font(dgvData.ColumnHeadersDefaultCellStyle.Font.Name, fontSize);
dgvData.DefaultCellStyle.Font = new Font(dgvData.DefaultCellStyle.Font.Name, fontSize);
dgvData.RowHeadersDefaultCellStyle.Font = new Font(dgvData.RowHeadersDefaultCellStyle.Font.Name, fontSize);
dgvData.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
ControlOper.SetPosCheckBoxToListViewHead(lvwSlide, chkSelectAllSlide);//杨斌 2012-11-16
Roster = RosterList.RosterLoad;
LstKeyID = LoadKeyID();
InitColor();
LoadSlide();
ShowGride();
IsLoading = false;
//List lstRadio = new List();
//lstRadio.Add(GlobalInfo.IniCtlSystem.ReadString(this.Name, "ChartDataLabel", ""));
//lstRadio.Add(GlobalInfo.IniCtlSystem.ReadString(this.Name, "ChartType", ""));
//ControlOper.SetControlCheck(this, lstRadio);
}
///
/// 查询的反馈题目类型
///
private const string cResponseType = "'Grade'";
///
/// 加载反馈幻灯片信息
///
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);
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
}
GlobalInfo.DBOperation.CloseDataSet();
////默认选中题目
//if (lvwSlide.Items.Count > 0) lvwSlide.Items[0].Checked = true;
//默认选中所有。杨斌 2019-05-27
chkSelectAllSlide.Checked = true;
ControlOper.SelectAllListViewItem(lvwSlide, chkSelectAllSlide.Checked);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
RosterList Roster = new RosterList();
Dictionary DicColor = new Dictionary();
Dictionary DicScore = new Dictionary();
void InitColor()
{
try
{
//分值:完全同意5,同意4,一般3,不同意2,完全不同意1,不知道0,未按0
//按键:反过来,完全同意"1"。。。不知道"6",未按""
List ls = new List { "0,177,80", "147,209,80", "255,193,0", "255,0,0", "193,0,0", "255,255,255" };
for (int i = 0; i < ls.Count; i++)
{
var ary = ls[i].Split(',');
DicColor.Add((i + 1).ToString(), Color.FromArgb(ConvertOper.Convert(ary[0]).ToInt,
ConvertOper.Convert(ary[1]).ToInt, ConvertOper.Convert(ary[2]).ToInt));
}
DicColor.Add("", Color.Black);//未按
for (int i = 1; i <= ls.Count - 1; i++)
{
DicScore.Add(i.ToString(), ls.Count - i);
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
private void SetCellColor(DataGridViewCell cell, string value)
{
try
{
Color color = Color.Black;
if (DicColor.ContainsKey(value))
color = DicColor[value];
cell.Style.BackColor = cell.Style.SelectionBackColor = color;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
List LstKeyID = new List();
List LoadKeyID()
{
List res = new List();
try
{
if (Roster.RosterEnabled)
{
for (int i = 0; i < Roster.Rows.Count; i++)
{
var keyID = Roster.Rows[i].Cells[Roster.KeypadIdColumnIndex];
res.Add(keyID);
}
}
if (res.Count < 1)
{
List ls = FrmImportSlideSelect.GetNumRange(GlobalInfo.hardwareManage.RangeOfKey);
foreach (var v in ls)
{
res.Add(v.ToString());
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
internal class KeyValueScore
{
internal string KeyID = "";
internal string Result = "";
internal double Score = 0;
}
internal class TopicResult
{
internal string TopicID = "";
internal string TopicText = "";
internal double ScoreSum = 0;
internal Dictionary DicKeyValueScore = new Dictionary();
}
///
/// 刷新图表
///
private void ShowGride()
{
try
{
dgvData.Rows.Clear();
dgvData.Columns.Clear();
//获取题目ID和标题
int topicCount = lvwSlide.CheckedItems.Count;
if (topicCount < 1) return;
Dictionary dicData = new Dictionary();
List lstTID = new List();
for (int i = 0; i < topicCount; i++)
{
string tid = lvwSlide.CheckedItems[i].Tag.ToString();
lstTID.Add(tid);
TopicResult data = new TopicResult();
tid = tid.Replace("'", "");
data.TopicID = tid;
data.TopicText = lvwSlide.CheckedItems[i].Text + ". " + lvwSlide.CheckedItems[i].SubItems[1].Text;
dicData.Add(tid, data);
}
string topicIDs = string.Join(",", lstTID);
var dicRes = ReportEx.GetVoterResultPar(topicIDs);
var dicTopic = ReportEx.GetTopicParA(topicIDs);
foreach (var v in dicRes)
{
string tid = v.Key;
foreach (var vv in v.Value)
{
double score = 0;
string value = vv.Value.Result;
if (DicScore.ContainsKey(value))
score = DicScore[value];
KeyValueScore keyValueScore = new KeyValueScore();
keyValueScore.KeyID = vv.Value.KeyID;
keyValueScore.Result = vv.Value.Result;
keyValueScore.Score = score;
dicData[tid].DicKeyValueScore.Add(vv.Value.KeyID, keyValueScore);
dicData[tid].ScoreSum += score;
}
}
List lstKey = new List();
if (LstKeyID.Count > 0)
{
lstKey = LstKeyID.ToList();
}
else
{
foreach (var v in dicRes)
{
foreach (var vv in v.Value)
{
if (!lstKey.Contains(vv.Value.KeyID))
lstKey.Add(vv.Value.KeyID);
}
}
}
lstKey = lstKey.OrderBy(o => o.PadLeft(12, '0')).ToList();
if (rbtViewRank.Checked)
{
dicData = dicData.OrderByDescending(o => o.Value.ScoreSum).ToDictionary(o => o.Key, o => o.Value);
foreach (var v in dicData)
{
v.Value.DicKeyValueScore = v.Value.DicKeyValueScore.OrderByDescending(o => o.Value.Score).ToDictionary(o => o.Key, o => o.Value);
}
}
//题目标题
dgvData.RowCount = topicCount;
int n = 0;
foreach (var v in dicData)
{
dgvData.Rows[n].HeaderCell.Value = v.Value.TopicText;
dgvData.Rows[n].Height = dgvData.ColumnHeadersHeight;
n++;
}
//键盘编号
dgvData.ColumnCount = lstKey.Count;
for (int i = 0; i < lstKey.Count; i++)
{
if (rbtViewData.Checked)
dgvData.Columns[i].HeaderText = lstKey[i];
else
dgvData.Columns[i].HeaderText = "";
dgvData.Columns[i].Width = dgvData.ColumnHeadersHeight;
}
//数据
n = 0;
foreach (var v in dicData)
{
string tid = v.Key;//.Replace("'", "");
var lstValScore = v.Value.DicKeyValueScore.Values.ToList();
foreach (DataGridViewColumn col in dgvData.Columns)
{
if (rbtViewData.Checked)
{
string keyID = col.HeaderText;
if (v.Value.DicKeyValueScore.ContainsKey(keyID))
{
string value = v.Value.DicKeyValueScore[keyID].Result;
SetCellColor(dgvData.Rows[n].Cells[col.Index], value);
}
else
{
SetCellColor(dgvData.Rows[n].Cells[col.Index], "");
}
}
else
{
if (col.Index < lstValScore.Count)
{
SetCellColor(dgvData.Rows[n].Cells[col.Index], lstValScore[col.Index].Result);
}
else
{
SetCellColor(dgvData.Rows[n].Cells[col.Index], "");
}
}
}
n++;
//if (dicRes.ContainsKey(tid))
//{
// foreach (DataGridViewColumn col in dgvData.Columns)
// {
// string value = "";
// foreach (var vv in dicRes[tid])
// {
// Dictionary dicValScore = vv.Value;
// if (vv.Value.KeyID == col.HeaderText)
// {
// value = vv.Value.Result;
// break;
// }
// }
// SetCellColor(dgvData.Rows[n].Cells[col.Index], value);
// }
//}
//else
//{
// foreach (DataGridViewColumn col in dgvData.Columns)
// {
// SetCellColor(dgvData.Rows[n].Cells[col.Index], "");
// }
//}
//n++;
}
foreach (DataGridViewColumn col in dgvData.Columns)//杨斌 2019-06-06
{
col.SortMode = DataGridViewColumnSortMode.NotSortable;
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
///
/// 是否全屏
///
private bool IsFullScreen = false;
private Point OldFrmPoint;
private Size OldFrmSize;
private 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 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 chkSelectAllSlide_CheckedChanged(object sender, EventArgs e)
{
if (IsLoading) return;
IsLoading = true;
ControlOper.SelectAllListViewItem(lvwSlide, chkSelectAllSlide.Checked);
IsLoading = false;
ShowGride();
}
//勾选中题目
private void lvwSlide_ItemChecked(object sender, ItemCheckedEventArgs e)
{
if (IsLoading) return;
IsLoading = true;
chkSelectAllSlide.Checked = ((lvwSlide.CheckedItems.Count > 0) && (lvwSlide.CheckedItems.Count == lvwSlide.Items.Count));
IsLoading = false;
ShowGride();
}
//设置图表样式
private void rbtViewType_CheckedChanged(object sender, EventArgs e)
{
if (IsLoading) return;
ShowGride();
//GlobalInfo.IniCtlSystem.WriteValue(this.Name, "ChartType", (sender as Control).Name);//杨斌 2014-07-25
}
//双击全屏
private void pnlChart_DoubleClick(object sender, EventArgs e)
{
ShowChartFull();
}
//窗体按键响应
private void FrmAnalyzeSlide_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Escape:
if (IsFullScreen)
ShowChartFull();
else
this.Close();
break;
}
}
private void lvwSlide_SelectedIndexChanged(object sender, EventArgs e)
{
ShowGride();//杨斌 2014-10-21
}
private void btnExport_Click(object sender, EventArgs e)
{
string title = rbtViewData.Text;
if (rbtViewRank.Checked)
title = rbtViewRank.Text;
PublicFunction.ExportToExcelEx(dgvData, this.Text);
}
private void btnShowFull_Click(object sender, EventArgs e)
{
ShowChartFull();
}
private void dgvData_DoubleClick(object sender, EventArgs e)
{
ShowChartFull();
}
}
}