using LYFZ.Software.MainBusiness.DoorCityProcess; 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; namespace LYFZ.Software.MainBusiness.FinancialManagement.Payroll { public partial class FrmSearchRecord : LYFZ.Software.UI.FinancialManagement.Payroll.FrmSearchRecord { public string N_NameText; public string N_NameTag; public string N_Name; private delegate void UpdateControl(); LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder(); LYFZ.BLL.BLL_AllViewSet AllViewSetbll = new BLL.BLL_AllViewSet(); public FrmSearchRecord() { } /// /// 窗体加载事件 /// /// /// protected override void FrmSearchRecord_Shown(object sender, EventArgs e) { try { this.txtTimeStart.Text = SDateTime.Now.ToString("yyyy-MM") + "-01"; this.txtTimeEnd.Text = Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM") + "-01").AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd"); if (this.N_NameText == "全部" || this.N_Name == "Department")//所有员工 { this.dgv.Visible = false; this.btnDelete.Visible = false; this.TotalAllPerformance(); } else { this.dgvAll.Visible = false; this.GetWage(this.N_NameTag, this.txtTimeStart.DateValue, this.txtTimeEnd.DateValue); } // 权限 this.btnDelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StatisticalInquiryAllWagesCompetence, CustomAttributes.OperatingAuthority.Delete); this.btnExPort.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StatisticalInquiryAllWagesCompetence, CustomAttributes.OperatingAuthority.DataExport); } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 获取数据 /// /// /// /// public void GetWage(string EmployeeName, string StartTime, string EndTime) { this.dgv.Rows.Clear(); StringBuilder str = new StringBuilder(); DataTable dt = new DataTable(); str.Append(" Wcr_PerformanceTimeStart>='" + this.txtTimeStart.DateValue + "' and Wcr_PerformanceTimeEnd<='" + this.txtTimeEnd.DateValue + "'"); str.Append(" and Wcr_EmployeeID = '" + EmployeeName + "'"); LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker) { dt = orbll.GetView_Custom("tb_ErpWageCommissionRecords left Join tb_ErpSystemCategory on Wcr_CommissionScheme = Sc_ClassCode Left Join dbo.tb_ErpUser on User_EmployeeID = Wcr_EmployeeID", StrWhere: str.ToString(), ShowColumnName: "tb_ErpWageCommissionRecords.ID,User_Name,Wcr_CommissionScheme,Sc_ClassName,Wcr_CurrentPerformance,Wcr_PieceCommission,Wcr_CommissionWages,Wcr_CreateDateTime,Wcr_CreateName").Tables[0]; if (dt.Rows.Count > 0) { this.Invoke(new UpdateControl(delegate() { decimal PerformanceSum = 0; decimal PieceSum = 0; decimal CommissionSum = 0; for (int t = 0; t < dt.Rows.Count; t++) { #region DataGridViewRow dgvr = new DataGridViewRow(); DataGridViewCell cell = null; //ID cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["ID"].ToString().Trim(); dgvr.Cells.Add(cell); //录入时间 cell = new DataGridViewTextBoxCell(); cell.Value = Convert.ToDateTime(dt.Rows[t]["Wcr_CreateDateTime"]).ToString("yyyy-MM-dd HH:mm").Trim(); dgvr.Cells.Add(cell); //员工姓名 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["User_Name"].ToString().Trim(); dgvr.Cells.Add(cell); //提成方案名称 cell = new DataGridViewTextBoxCell(); if (dt.Rows[t]["Wcr_CommissionScheme"].ToString().Trim() == "计件提成") { cell.Value = dt.Rows[t]["Wcr_CommissionScheme"].ToString().Trim(); } else { cell.Value = dt.Rows[t]["Sc_ClassName"].ToString(); } dgvr.Cells.Add(cell); //当前业绩 cell = new DataGridViewTextBoxCell(); cell.Value = Convert.ToDecimal(dt.Rows[t]["Wcr_CurrentPerformance"]).ToString("N2").Trim(); PerformanceSum += Convert.ToDecimal(dt.Rows[t]["Wcr_CurrentPerformance"]); dgvr.Cells.Add(cell); //计件提成 cell = new DataGridViewTextBoxCell(); cell.Value = Convert.ToDecimal(dt.Rows[t]["Wcr_PieceCommission"]).ToString("N2").Trim(); PieceSum += Convert.ToDecimal(dt.Rows[t]["Wcr_PieceCommission"]); dgvr.Cells.Add(cell); //提成工资 cell = new DataGridViewTextBoxCell(); cell.Value = Convert.ToDecimal(dt.Rows[t]["Wcr_CommissionWages"]).ToString("N2").Trim(); CommissionSum += Convert.ToDecimal(dt.Rows[t]["Wcr_CommissionWages"]); dgvr.Cells.Add(cell); //录入人名称 cell = new DataGridViewTextBoxCell(); cell.Value = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable.Rows.Find(dt.Rows[t]["Wcr_CreateName"])["User_Name"].ToString(); dgvr.Cells.Add(cell); this.dgv.Rows.Add(dgvr); #endregion } this.dgv.ClearSelection(); int rows = this.dgv.Rows.Add(); this.dgv.Rows[rows].Cells[1].Value = "统计:"; this.dgv.Rows[rows].Cells[4].Value = PerformanceSum.ToString("N2"); this.dgv.Rows[rows].Cells[5].Value = PieceSum.ToString("N2"); this.dgv.Rows[rows].Cells[6].Value = CommissionSum.ToString("N2"); })); } }); } /// /// 统计所有业绩 /// public void TotalAllPerformance() { this.dgvAll.Rows.Clear(); string StrDtpStart = this.txtTimeStart.Text; string StrDtpEnd = this.txtTimeEnd.Text; string StrWhere = ""; if (this.N_Name == "Department")//统计部门 { StrWhere = " And User_Department='" + N_NameTag + "'"; } #region 部门 LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker) { string ExecuteSql = orbll.GetView_CustomReturnExecuteSql("tb_ErpUser", StrWhere: "User_Status='在职'" + StrWhere, ShowColumnName: "User_Name,User_EmployeeID"); ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpWageCommissionRecords", StrWhere: "Wcr_PerformanceTimeStart>='" + StrDtpStart + "' and Wcr_PerformanceTimeEnd<='" + StrDtpEnd + "'", ShowColumnName: "Wcr_EmployeeID,sum(Wcr_CurrentPerformance) AS 当前业绩,sum(Wcr_PieceCommission) AS 计件提成,sum(Wcr_CommissionWages) AS 提成工资", StrGroupBy: "Wcr_EmployeeID"); DataSet dtSet = orbll.GetView_Custom(ExecuteSql); DataTable dt = dtSet.Tables["ds"]; DataTable tbl = dtSet.Tables["ds1"]; tbl.PrimaryKey = new DataColumn[] { tbl.Columns["Wcr_EmployeeID"] }; this.Invoke(new UpdateControl(delegate() { for (int t = 0; t < dt.Rows.Count; t++) { DataGridViewRow dgvr = new DataGridViewRow(); DataGridViewCell cell = null; //员工编号 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["User_EmployeeID"].ToString().Trim(); dgvr.Cells.Add(cell); //员工姓名 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["User_Name"].ToString().Trim(); dgvr.Cells.Add(cell); //当前业绩 cell = new DataGridViewTextBoxCell(); DataRow dtRow = tbl.Rows.Find(dt.Rows[t]["User_EmployeeID"].ToString().Trim()); if (dtRow != null) { cell.Value = dtRow["当前业绩"]; } else { cell.Value = "0.00"; } //DataTable dt_P = AllViewSetbll.GetErpWageCommissionRecords("当前业绩", " and 业绩开始时间>='" + txtTimeStart.Text + "' and 业绩结束时间<='" + txtTimeEnd.Text + "' and 员工编号='" + dt.Rows[t]["User_EmployeeID"].ToString().Trim() + "'").Tables[0]; //if (!string.IsNullOrEmpty(dt_P.Rows[0]["业绩"].ToString())) //{ cell.Value = dt_P.Rows[0]["业绩"].ToString(); } //else //{ cell.Value = "0.00"; } dgvr.Cells.Add(cell); //计件提成 cell = new DataGridViewTextBoxCell(); DataRow dtRow2 = tbl.Rows.Find(dt.Rows[t]["User_EmployeeID"].ToString().Trim()); if (dtRow2 != null) { cell.Value = dtRow2["计件提成"]; } else { cell.Value = "0.00"; } //dt_P = AllViewSetbll.GetErpWageCommissionRecords("计件提成", " and 业绩开始时间>='" + txtTimeStart.Text + "' and 业绩结束时间<='" + txtTimeEnd.Text + "' and 员工编号='" + dt.Rows[t]["User_EmployeeID"].ToString().Trim() + "'").Tables[0]; //if (!string.IsNullOrEmpty(dt_P.Rows[0]["业绩"].ToString())) //{ cell.Value = dt_P.Rows[0]["业绩"].ToString(); } //else //{ cell.Value = "0.00"; } dgvr.Cells.Add(cell); //提成工资 cell = new DataGridViewTextBoxCell(); DataRow dtRow3 = tbl.Rows.Find(dt.Rows[t]["User_EmployeeID"].ToString().Trim()); if (dtRow3 != null) { cell.Value = dtRow3["提成工资"]; } else { cell.Value = "0.00"; } //dt_P = AllViewSetbll.GetErpWageCommissionRecords("提成工资", " and 业绩开始时间>='" + txtTimeStart.Text + "' and 业绩结束时间<='" + txtTimeEnd.Text + "' and 员工编号='" + dt.Rows[t]["User_EmployeeID"].ToString().Trim() + "'").Tables[0]; //if (!string.IsNullOrEmpty(dt_P.Rows[0]["业绩"].ToString())) //{ cell.Value = dt_P.Rows[0]["业绩"].ToString(); } //else //{ cell.Value = "0.00"; } dgvr.Cells.Add(cell); this.dgvAll.Rows.Add(dgvr); } this.dgvAll.ClearSelection(); })); }); #endregion } /// /// 删除 /// /// /// protected override void btnDelete_Click(object sender, EventArgs e) { try { if (this.dgv.SelectedRows.Count == 0) { MessageBoxCustom.Show("请选中你要删除的数据!"); return; } if (this.dgv.CurrentRow.Cells["Column2"].Value.ToString() == "统计:") { MessageBoxCustom.Show("此行不可删除!"); return; } if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { LYFZ.BLL.BLL_ErpWageCommissionRecords bll = new BLL.BLL_ErpWageCommissionRecords(); int id = Convert.ToInt32(this.dgv.CurrentRow.Cells["ID"].Value); if (bll.Delete(id)) { string logsContent = "删除工资提成记录:" + this.dgv.CurrentRow.Cells["Column3"].Value.ToString() + " " + this.dgv.CurrentRow.Cells["Column4"].Value.ToString(); LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.删除工资提成记录, logsContent, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name); //统计个人工资提成 this.GetWage(this.N_NameTag, this.txtTimeStart.Text, this.txtTimeEnd.Text); MessageBoxCustom.Show("删除成功!"); } } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 查询 /// /// /// protected override void btnSelect_Click(object sender, EventArgs e) { if (this.N_NameText == "全部" || this.N_Name == "Department")//所有员工 { this.dgv.Visible = false; this.btnDelete.Visible = false; this.TotalAllPerformance(); } else { this.dgvAll.Visible = false; this.GetWage(this.N_NameTag, this.txtTimeStart.DateValue, this.txtTimeEnd.DateValue); } } /// /// 排序 /// /// /// protected override void dgvAll_SortCompare(object sender, DataGridViewSortCompareEventArgs e) { if (e.Column.Name == "员工姓名" || e.Column.Name == "业绩金额") { e.SortResult = (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) > 0) ? 1 : (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) < 0) ? -1 : 0; } //否则,按字符串比较 else { e.SortResult = System.String.Compare(Convert.ToString(e.CellValue1), Convert.ToString(e.CellValue2)); } e.Handled = true;//不能省掉,不然没效果 } /// /// 导出 /// /// /// protected override void btnExPort_Click(object sender, EventArgs e) { if (this.dgv.Visible) { this.dgv.ExportDataTable(); } else if (this.dgvAll.Visible) { this.dgvAll.ExportDataTable(); } } } }