Commit acc93c2a authored by 徐盼盼's avatar 徐盼盼

【员工考核】查询优化:

1.日期下拉列表格式调整,显示六个月
2.明细表格根据日期选择显示对应数据
parent 5118eb68
...@@ -7,6 +7,7 @@ using System.Threading.Tasks; ...@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
// //
using Tools.MyUtils; using Tools.MyUtils;
using Tools.UI;
namespace Tools namespace Tools
{ {
...@@ -32,7 +33,7 @@ namespace Tools ...@@ -32,7 +33,7 @@ namespace Tools
Utils.SaveJsonConfig(m); Utils.SaveJsonConfig(m);
} }
Application.Run(new wMain()); Application.Run(new wEvaluationOfEmployee());
} }
//UI未处理异常 //UI未处理异常
......
...@@ -37,10 +37,10 @@ ...@@ -37,10 +37,10 @@
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.tsbHelp = new System.Windows.Forms.ToolStripButton(); this.tsbHelp = new System.Windows.Forms.ToolStripButton();
this.dgvDetail = new System.Windows.Forms.DataGridView(); this.dgvDetail = new System.Windows.Forms.DataGridView();
this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Who = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Minus = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Reason = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.CreateUserName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.CreateUserName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.CreateDate = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.CreateDate = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.LastModifiedUserName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.LastModifiedUserName = new System.Windows.Forms.DataGridViewTextBoxColumn();
...@@ -102,6 +102,7 @@ ...@@ -102,6 +102,7 @@
this.tscbMonth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.tscbMonth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.tscbMonth.Name = "tscbMonth"; this.tscbMonth.Name = "tscbMonth";
this.tscbMonth.Size = new System.Drawing.Size(140, 25); this.tscbMonth.Size = new System.Drawing.Size(140, 25);
this.tscbMonth.SelectedIndexChanged += new System.EventHandler(this.tscbMonth_SelectedIndexChanged);
// //
// toolStripSeparator2 // toolStripSeparator2
// //
...@@ -122,10 +123,10 @@ ...@@ -122,10 +123,10 @@
this.dgvDetail.BackgroundColor = System.Drawing.SystemColors.Window; this.dgvDetail.BackgroundColor = System.Drawing.SystemColors.Window;
this.dgvDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgvDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dgvDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column4, this.ID,
this.Column2, this.Who,
this.Column1, this.Minus,
this.Column3, this.Reason,
this.CreateUserName, this.CreateUserName,
this.CreateDate, this.CreateDate,
this.LastModifiedUserName, this.LastModifiedUserName,
...@@ -139,34 +140,34 @@ ...@@ -139,34 +140,34 @@
this.dgvDetail.Size = new System.Drawing.Size(1094, 472); this.dgvDetail.Size = new System.Drawing.Size(1094, 472);
this.dgvDetail.TabIndex = 3; this.dgvDetail.TabIndex = 3;
// //
// Column4 // ID
// //
this.Column4.DataPropertyName = "ID"; this.ID.DataPropertyName = "ID";
this.Column4.HeaderText = "记录编号"; this.ID.HeaderText = "记录编号";
this.Column4.Name = "Column4"; this.ID.Name = "ID";
this.Column4.ReadOnly = true; this.ID.ReadOnly = true;
// //
// Column2 // Who
// //
this.Column2.DataPropertyName = "Who"; this.Who.DataPropertyName = "Who";
this.Column2.HeaderText = "员工姓名"; this.Who.HeaderText = "员工姓名";
this.Column2.Name = "Column2"; this.Who.Name = "Who";
this.Column2.ReadOnly = true; this.Who.ReadOnly = true;
// //
// Column1 // Minus
// //
this.Column1.DataPropertyName = "Minus"; this.Minus.DataPropertyName = "Minus";
this.Column1.HeaderText = "减分"; this.Minus.HeaderText = "减分";
this.Column1.Name = "Column1"; this.Minus.Name = "Minus";
this.Column1.ReadOnly = true; this.Minus.ReadOnly = true;
// //
// Column3 // Reason
// //
this.Column3.DataPropertyName = "Reason"; this.Reason.DataPropertyName = "Reason";
this.Column3.HeaderText = "减分原因"; this.Reason.HeaderText = "减分原因";
this.Column3.Name = "Column3"; this.Reason.Name = "Reason";
this.Column3.ReadOnly = true; this.Reason.ReadOnly = true;
this.Column3.Width = 350; this.Reason.Width = 350;
// //
// CreateUserName // CreateUserName
// //
...@@ -226,10 +227,10 @@ ...@@ -226,10 +227,10 @@
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripComboBox tscbMonth; private System.Windows.Forms.ToolStripComboBox tscbMonth;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.DataGridViewTextBoxColumn Column4; private System.Windows.Forms.DataGridViewTextBoxColumn ID;
private System.Windows.Forms.DataGridViewTextBoxColumn Column2; private System.Windows.Forms.DataGridViewTextBoxColumn Who;
private System.Windows.Forms.DataGridViewTextBoxColumn Column1; private System.Windows.Forms.DataGridViewTextBoxColumn Minus;
private System.Windows.Forms.DataGridViewTextBoxColumn Column3; private System.Windows.Forms.DataGridViewTextBoxColumn Reason;
private System.Windows.Forms.DataGridViewTextBoxColumn CreateUserName; private System.Windows.Forms.DataGridViewTextBoxColumn CreateUserName;
private System.Windows.Forms.DataGridViewTextBoxColumn CreateDate; private System.Windows.Forms.DataGridViewTextBoxColumn CreateDate;
private System.Windows.Forms.DataGridViewTextBoxColumn LastModifiedUserName; private System.Windows.Forms.DataGridViewTextBoxColumn LastModifiedUserName;
......
...@@ -16,17 +16,26 @@ namespace Tools.UI ...@@ -16,17 +16,26 @@ namespace Tools.UI
public partial class wEvaluationOfEmployee : wEditBasic public partial class wEvaluationOfEmployee : wEditBasic
{ {
/// <summary> /// <summary>
/// 上个月起始日期 /// 查询最近几个月的数据
/// </summary> /// </summary>
string LastMonthStart => DateTime.Now.AddMonths(-1).ToString("yyyy-MM-01"); private const int RECENT_MONTHS = 6;
/// <summary> /// <summary>
/// 本月起始日期 /// 起始日期
/// </summary> /// </summary>
string ThisMonthStart => DateTime.Now.ToString("yyyy-MM-01"); private string BeginDate => DateTime.Now.AddMonths( -1 * (RECENT_MONTHS - 1)).ToString("yyyy-MM");
// 当前编辑ID
private int EditID;
// 是否新增
public static bool IsAdd = false; public static bool IsAdd = false;
// 当前编辑行
public static DataRow CurrentEditRow; public static DataRow CurrentEditRow;
int EditID = 0;
/// <summary>
/// 是否加载完成
/// </summary>
private bool IsShown = false;
public wEvaluationOfEmployee() public wEvaluationOfEmployee()
{ {
...@@ -44,6 +53,9 @@ namespace Tools.UI ...@@ -44,6 +53,9 @@ namespace Tools.UI
//初始化 //初始化
this.InitData(); this.InitData();
this.InitUI(); this.InitUI();
IsShown = true;
this.tscbMonth.SelectedIndex = 0;
} }
public override void InitData() public override void InitData()
{ {
...@@ -51,7 +63,7 @@ namespace Tools.UI ...@@ -51,7 +63,7 @@ namespace Tools.UI
string sql = $@"DECLARE @IsPrincipal BIT = {Convert.ToInt32(LoginInfo.IsPrincipal)} string sql = $@"DECLARE @IsPrincipal BIT = {Convert.ToInt32(LoginInfo.IsPrincipal)}
IF(@IsPrincipal = 0) IF(@IsPrincipal = 0)
SELECT * FROM FTT_EvaluationOfEmployee SELECT * FROM FTT_EvaluationOfEmployee
WHERE Who = '{LoginInfo.UserName}' AND CreateDate > '{this.LastMonthStart}'; WHERE Who = '{LoginInfo.UserName}' AND CreateDate >= '{BeginDate}-01';
ELSE ELSE
BEGIN BEGIN
...@@ -65,7 +77,7 @@ namespace Tools.UI ...@@ -65,7 +77,7 @@ namespace Tools.UI
INNER JOIN dbo.AC_GroupTree gt ON gt.ID = gu.GroupTreeID INNER JOIN dbo.AC_GroupTree gt ON gt.ID = gu.GroupTreeID
WHERE u.Name = '{LoginInfo.UserName}') WHERE u.Name = '{LoginInfo.UserName}')
) u ON u.Name = e.Who ) u ON u.Name = e.Who
WHERE e.CreateDate > '{this.LastMonthStart}' WHERE e.CreateDate >= '{BeginDate}-01'
END"; END";
this._ds = this._db.GetData(sql, "FTT_EvaluationOfEmployee"); this._ds = this._db.GetData(sql, "FTT_EvaluationOfEmployee");
...@@ -75,10 +87,8 @@ namespace Tools.UI ...@@ -75,10 +87,8 @@ namespace Tools.UI
this.InitGridView(this.dgvDetail, false, true); this.InitGridView(this.dgvDetail, false, true);
this.dgvDetail.DataSource = this._ds.Tables[0].DefaultView; this.dgvDetail.DataSource = this._ds.Tables[0].DefaultView;
this.dgvDetail.CellMouseClick += DgvDetail_CellMouseClick; this.dgvDetail.CellMouseClick += DgvDetail_CellMouseClick;
//初始化工具栏月份下拉项 for (int i = 0; i < RECENT_MONTHS; i++)
this.tscbMonth.Items.Add(this.ThisMonthStart); this.tscbMonth.Items.Add(DateTime.Now.AddMonths(i * -1).ToString("yyyy-MM"));
this.tscbMonth.Items.Add(this.LastMonthStart);
this.tscbMonth.SelectedIndex = 0;
} }
...@@ -116,7 +126,15 @@ namespace Tools.UI ...@@ -116,7 +126,15 @@ namespace Tools.UI
} }
IsAdd = false; IsAdd = false;
wEditEvaluation wEdit = new wEditEvaluation(CurrentEditRow); wEditEvaluation wEdit = new wEditEvaluation(CurrentEditRow);
wEdit.ShowDialog(); if (wEdit.ShowDialog() == DialogResult.OK)
{
// 修改后同步刷新
dgvDetail.CurrentRow.Cells["Who"].Value = CurrentEditRow["Who"];
dgvDetail.CurrentRow.Cells["Minus"].Value = CurrentEditRow["Minus"];
dgvDetail.CurrentRow.Cells["Reason"].Value = CurrentEditRow["Reason"];
dgvDetail.CurrentRow.Cells["LastModifiedUserName"].Value = CurrentEditRow["LastModifiedUserName"];
dgvDetail.CurrentRow.Cells["LastModifiedDate"].Value = CurrentEditRow["LastModifiedDate"];
}
} }
//事件:生成报告 //事件:生成报告
private void tsbGenReport_Click(object sender, EventArgs e) private void tsbGenReport_Click(object sender, EventArgs e)
...@@ -127,7 +145,7 @@ namespace Tools.UI ...@@ -127,7 +145,7 @@ namespace Tools.UI
return; return;
} }
//生成开始、结束日期 //生成开始、结束日期
string startDate = this.tscbMonth.Text; string startDate = this.tscbMonth.Text + "-01";
string endDate = Convert.ToDateTime(startDate).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd"); //开始日期所在月份的最后一天 string endDate = Convert.ToDateTime(startDate).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd"); //开始日期所在月份的最后一天
//考勤数据-分组 //考勤数据-分组
var dic = new Dictionary<string, List<DataRow>>(); var dic = new Dictionary<string, List<DataRow>>();
...@@ -168,7 +186,8 @@ namespace Tools.UI ...@@ -168,7 +186,8 @@ namespace Tools.UI
var rowIndex = this.dgvDetail.CurrentRow.Index; var rowIndex = this.dgvDetail.CurrentRow.Index;
if (rowIndex < 0 || rowIndex >= this._ds.Tables[0].DefaultView.Count) if (rowIndex < 0 || rowIndex >= this._ds.Tables[0].DefaultView.Count)
return; return;
CurrentEditRow = this._ds.Tables[0].Rows[rowIndex]; EditID = Convert.ToInt32(dgvDetail.CurrentRow.Cells["ID"].Value);
CurrentEditRow = this._ds.Tables[0].Select($"ID = {EditID}")[0];
} }
...@@ -211,5 +230,30 @@ namespace Tools.UI ...@@ -211,5 +230,30 @@ namespace Tools.UI
return result; return result;
} }
// 选择月份后,数据同步月份
private void tscbMonth_SelectedIndexChanged(object sender, EventArgs e)
{
if (!IsShown)
return;
dgvDetail.DataSource = GetFilterData().AsDataView();
}
/// <summary>
/// 获取过滤月份后数据表
/// </summary>
/// <returns></returns>
private DataTable GetFilterData()
{
//生成开始、结束日期
string startDate = this.tscbMonth.Text + "-01";
string endDate = Convert.ToDateTime(startDate).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd"); //开始日期所在月份的最后一天
DataRow[] rows = this._ds.Tables[0].Select($"CreateDate >= '{startDate}' AND CreateDate <= '{endDate}'");
DataTable dt = this._ds.Tables[0].Clone();
Array.ForEach(rows, row =>
{
dt.Rows.Add(row.ItemArray);
});
return dt;
}
} }
} }
...@@ -120,16 +120,16 @@ ...@@ -120,16 +120,16 @@
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="Column4.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="Who.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="Minus.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="Column3.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="Reason.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="CreateUserName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="CreateUserName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment