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

【员工考核】查询优化:

1.日期下拉列表格式调整,显示六个月
2.明细表格根据日期选择显示对应数据
parent 5118eb68
......@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
//
using Tools.MyUtils;
using Tools.UI;
namespace Tools
{
......@@ -32,7 +33,7 @@ namespace Tools
Utils.SaveJsonConfig(m);
}
Application.Run(new wMain());
Application.Run(new wEvaluationOfEmployee());
}
//UI未处理异常
......
......@@ -37,10 +37,10 @@
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.tsbHelp = new System.Windows.Forms.ToolStripButton();
this.dgvDetail = new System.Windows.Forms.DataGridView();
this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Who = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Minus = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Reason = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.CreateUserName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.CreateDate = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.LastModifiedUserName = new System.Windows.Forms.DataGridViewTextBoxColumn();
......@@ -102,6 +102,7 @@
this.tscbMonth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.tscbMonth.Name = "tscbMonth";
this.tscbMonth.Size = new System.Drawing.Size(140, 25);
this.tscbMonth.SelectedIndexChanged += new System.EventHandler(this.tscbMonth_SelectedIndexChanged);
//
// toolStripSeparator2
//
......@@ -122,10 +123,10 @@
this.dgvDetail.BackgroundColor = System.Drawing.SystemColors.Window;
this.dgvDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column4,
this.Column2,
this.Column1,
this.Column3,
this.ID,
this.Who,
this.Minus,
this.Reason,
this.CreateUserName,
this.CreateDate,
this.LastModifiedUserName,
......@@ -139,34 +140,34 @@
this.dgvDetail.Size = new System.Drawing.Size(1094, 472);
this.dgvDetail.TabIndex = 3;
//
// Column4
// ID
//
this.Column4.DataPropertyName = "ID";
this.Column4.HeaderText = "记录编号";
this.Column4.Name = "Column4";
this.Column4.ReadOnly = true;
this.ID.DataPropertyName = "ID";
this.ID.HeaderText = "记录编号";
this.ID.Name = "ID";
this.ID.ReadOnly = true;
//
// Column2
// Who
//
this.Column2.DataPropertyName = "Who";
this.Column2.HeaderText = "员工姓名";
this.Column2.Name = "Column2";
this.Column2.ReadOnly = true;
this.Who.DataPropertyName = "Who";
this.Who.HeaderText = "员工姓名";
this.Who.Name = "Who";
this.Who.ReadOnly = true;
//
// Column1
// Minus
//
this.Column1.DataPropertyName = "Minus";
this.Column1.HeaderText = "减分";
this.Column1.Name = "Column1";
this.Column1.ReadOnly = true;
this.Minus.DataPropertyName = "Minus";
this.Minus.HeaderText = "减分";
this.Minus.Name = "Minus";
this.Minus.ReadOnly = true;
//
// Column3
// Reason
//
this.Column3.DataPropertyName = "Reason";
this.Column3.HeaderText = "减分原因";
this.Column3.Name = "Column3";
this.Column3.ReadOnly = true;
this.Column3.Width = 350;
this.Reason.DataPropertyName = "Reason";
this.Reason.HeaderText = "减分原因";
this.Reason.Name = "Reason";
this.Reason.ReadOnly = true;
this.Reason.Width = 350;
//
// CreateUserName
//
......@@ -226,10 +227,10 @@
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripComboBox tscbMonth;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.DataGridViewTextBoxColumn Column4;
private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
private System.Windows.Forms.DataGridViewTextBoxColumn ID;
private System.Windows.Forms.DataGridViewTextBoxColumn Who;
private System.Windows.Forms.DataGridViewTextBoxColumn Minus;
private System.Windows.Forms.DataGridViewTextBoxColumn Reason;
private System.Windows.Forms.DataGridViewTextBoxColumn CreateUserName;
private System.Windows.Forms.DataGridViewTextBoxColumn CreateDate;
private System.Windows.Forms.DataGridViewTextBoxColumn LastModifiedUserName;
......
......@@ -16,17 +16,26 @@ namespace Tools.UI
public partial class wEvaluationOfEmployee : wEditBasic
{
/// <summary>
/// 上个月起始日期
/// 查询最近几个月的数据
/// </summary>
string LastMonthStart => DateTime.Now.AddMonths(-1).ToString("yyyy-MM-01");
private const int RECENT_MONTHS = 6;
/// <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 DataRow CurrentEditRow;
int EditID = 0;
/// <summary>
/// 是否加载完成
/// </summary>
private bool IsShown = false;
public wEvaluationOfEmployee()
{
......@@ -44,6 +53,9 @@ namespace Tools.UI
//初始化
this.InitData();
this.InitUI();
IsShown = true;
this.tscbMonth.SelectedIndex = 0;
}
public override void InitData()
{
......@@ -51,7 +63,7 @@ namespace Tools.UI
string sql = $@"DECLARE @IsPrincipal BIT = {Convert.ToInt32(LoginInfo.IsPrincipal)}
IF(@IsPrincipal = 0)
SELECT * FROM FTT_EvaluationOfEmployee
WHERE Who = '{LoginInfo.UserName}' AND CreateDate > '{this.LastMonthStart}';
WHERE Who = '{LoginInfo.UserName}' AND CreateDate >= '{BeginDate}-01';
ELSE
BEGIN
......@@ -65,7 +77,7 @@ namespace Tools.UI
INNER JOIN dbo.AC_GroupTree gt ON gt.ID = gu.GroupTreeID
WHERE u.Name = '{LoginInfo.UserName}')
) u ON u.Name = e.Who
WHERE e.CreateDate > '{this.LastMonthStart}'
WHERE e.CreateDate >= '{BeginDate}-01'
END";
this._ds = this._db.GetData(sql, "FTT_EvaluationOfEmployee");
......@@ -75,10 +87,8 @@ namespace Tools.UI
this.InitGridView(this.dgvDetail, false, true);
this.dgvDetail.DataSource = this._ds.Tables[0].DefaultView;
this.dgvDetail.CellMouseClick += DgvDetail_CellMouseClick;
//初始化工具栏月份下拉项
this.tscbMonth.Items.Add(this.ThisMonthStart);
this.tscbMonth.Items.Add(this.LastMonthStart);
this.tscbMonth.SelectedIndex = 0;
for (int i = 0; i < RECENT_MONTHS; i++)
this.tscbMonth.Items.Add(DateTime.Now.AddMonths(i * -1).ToString("yyyy-MM"));
}
......@@ -116,7 +126,15 @@ namespace Tools.UI
}
IsAdd = false;
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)
......@@ -127,7 +145,7 @@ namespace Tools.UI
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"); //开始日期所在月份的最后一天
//考勤数据-分组
var dic = new Dictionary<string, List<DataRow>>();
......@@ -168,7 +186,8 @@ namespace Tools.UI
var rowIndex = this.dgvDetail.CurrentRow.Index;
if (rowIndex < 0 || rowIndex >= this._ds.Tables[0].DefaultView.Count)
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
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 @@
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</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>
</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>
</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>
</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>
</metadata>
<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