FrmSearchRecord.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. using LYFZ.Software.MainBusiness.DoorCityProcess;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. namespace LYFZ.Software.MainBusiness.FinancialManagement.Payroll
  11. {
  12. public partial class FrmSearchRecord : LYFZ.Software.UI.FinancialManagement.Payroll.FrmSearchRecord
  13. {
  14. public string N_NameText;
  15. public string N_NameTag;
  16. public string N_Name;
  17. private delegate void UpdateControl();
  18. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  19. LYFZ.BLL.BLL_AllViewSet AllViewSetbll = new BLL.BLL_AllViewSet();
  20. public FrmSearchRecord()
  21. {
  22. }
  23. /// <summary>
  24. /// 窗体加载事件
  25. /// </summary>
  26. /// <param name="sender"></param>
  27. /// <param name="e"></param>
  28. protected override void FrmSearchRecord_Shown(object sender, EventArgs e)
  29. {
  30. try
  31. {
  32. this.txtTimeStart.Text = SDateTime.Now.ToString("yyyy-MM") + "-01";
  33. this.txtTimeEnd.Text = Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM") + "-01").AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd");
  34. if (this.N_NameText == "全部" || this.N_Name == "Department")//所有员工
  35. {
  36. this.dgv.Visible = false;
  37. this.btnDelete.Visible = false;
  38. this.TotalAllPerformance();
  39. }
  40. else
  41. {
  42. this.dgvAll.Visible = false;
  43. this.GetWage(this.N_NameTag, this.txtTimeStart.DateValue, this.txtTimeEnd.DateValue);
  44. }
  45. // 权限
  46. this.btnDelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StatisticalInquiryAllWagesCompetence, CustomAttributes.OperatingAuthority.Delete);
  47. this.btnExPort.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StatisticalInquiryAllWagesCompetence, CustomAttributes.OperatingAuthority.DataExport);
  48. }
  49. catch (Exception ex)
  50. { MessageBoxCustom.Show(ex.Message); }
  51. }
  52. /// <summary>
  53. /// 获取数据
  54. /// </summary>
  55. /// <param name="EmployeeName"></param>
  56. /// <param name="StartTime"></param>
  57. /// <param name="EndTime"></param>
  58. public void GetWage(string EmployeeName, string StartTime, string EndTime)
  59. {
  60. this.dgv.Rows.Clear();
  61. StringBuilder str = new StringBuilder();
  62. DataTable dt = new DataTable();
  63. str.Append(" Wcr_PerformanceTimeStart>='" + this.txtTimeStart.DateValue + "' and Wcr_PerformanceTimeEnd<='" + this.txtTimeEnd.DateValue + "'");
  64. str.Append(" and Wcr_EmployeeID = '" + EmployeeName + "'");
  65. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  66. {
  67. 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];
  68. if (dt.Rows.Count > 0)
  69. {
  70. this.Invoke(new UpdateControl(delegate()
  71. {
  72. decimal PerformanceSum = 0;
  73. decimal PieceSum = 0;
  74. decimal CommissionSum = 0;
  75. for (int t = 0; t < dt.Rows.Count; t++)
  76. {
  77. #region
  78. DataGridViewRow dgvr = new DataGridViewRow();
  79. DataGridViewCell cell = null;
  80. //ID
  81. cell = new DataGridViewTextBoxCell();
  82. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  83. dgvr.Cells.Add(cell);
  84. //录入时间
  85. cell = new DataGridViewTextBoxCell();
  86. cell.Value = Convert.ToDateTime(dt.Rows[t]["Wcr_CreateDateTime"]).ToString("yyyy-MM-dd HH:mm").Trim();
  87. dgvr.Cells.Add(cell);
  88. //员工姓名
  89. cell = new DataGridViewTextBoxCell();
  90. cell.Value = dt.Rows[t]["User_Name"].ToString().Trim();
  91. dgvr.Cells.Add(cell);
  92. //提成方案名称
  93. cell = new DataGridViewTextBoxCell();
  94. if (dt.Rows[t]["Wcr_CommissionScheme"].ToString().Trim() == "计件提成")
  95. { cell.Value = dt.Rows[t]["Wcr_CommissionScheme"].ToString().Trim(); }
  96. else
  97. { cell.Value = dt.Rows[t]["Sc_ClassName"].ToString(); }
  98. dgvr.Cells.Add(cell);
  99. //当前业绩
  100. cell = new DataGridViewTextBoxCell();
  101. cell.Value = Convert.ToDecimal(dt.Rows[t]["Wcr_CurrentPerformance"]).ToString("N2").Trim();
  102. PerformanceSum += Convert.ToDecimal(dt.Rows[t]["Wcr_CurrentPerformance"]);
  103. dgvr.Cells.Add(cell);
  104. //计件提成
  105. cell = new DataGridViewTextBoxCell();
  106. cell.Value = Convert.ToDecimal(dt.Rows[t]["Wcr_PieceCommission"]).ToString("N2").Trim();
  107. PieceSum += Convert.ToDecimal(dt.Rows[t]["Wcr_PieceCommission"]);
  108. dgvr.Cells.Add(cell);
  109. //提成工资
  110. cell = new DataGridViewTextBoxCell();
  111. cell.Value = Convert.ToDecimal(dt.Rows[t]["Wcr_CommissionWages"]).ToString("N2").Trim();
  112. CommissionSum += Convert.ToDecimal(dt.Rows[t]["Wcr_CommissionWages"]);
  113. dgvr.Cells.Add(cell);
  114. //录入人名称
  115. cell = new DataGridViewTextBoxCell();
  116. cell.Value = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable.Rows.Find(dt.Rows[t]["Wcr_CreateName"])["User_Name"].ToString();
  117. dgvr.Cells.Add(cell);
  118. this.dgv.Rows.Add(dgvr);
  119. #endregion
  120. }
  121. this.dgv.ClearSelection();
  122. int rows = this.dgv.Rows.Add();
  123. this.dgv.Rows[rows].Cells[1].Value = "统计:";
  124. this.dgv.Rows[rows].Cells[4].Value = PerformanceSum.ToString("N2");
  125. this.dgv.Rows[rows].Cells[5].Value = PieceSum.ToString("N2");
  126. this.dgv.Rows[rows].Cells[6].Value = CommissionSum.ToString("N2");
  127. }));
  128. }
  129. });
  130. }
  131. /// <summary>
  132. /// 统计所有业绩
  133. /// </summary>
  134. public void TotalAllPerformance()
  135. {
  136. this.dgvAll.Rows.Clear();
  137. string StrDtpStart = this.txtTimeStart.Text;
  138. string StrDtpEnd = this.txtTimeEnd.Text;
  139. string StrWhere = "";
  140. if (this.N_Name == "Department")//统计部门
  141. { StrWhere = " And User_Department='" + N_NameTag + "'"; }
  142. #region 部门
  143. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  144. {
  145. string ExecuteSql = orbll.GetView_CustomReturnExecuteSql("tb_ErpUser", StrWhere: "User_Status='在职'" + StrWhere, ShowColumnName: "User_Name,User_EmployeeID");
  146. 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");
  147. DataSet dtSet = orbll.GetView_Custom(ExecuteSql);
  148. DataTable dt = dtSet.Tables["ds"];
  149. DataTable tbl = dtSet.Tables["ds1"];
  150. tbl.PrimaryKey = new DataColumn[] { tbl.Columns["Wcr_EmployeeID"] };
  151. this.Invoke(new UpdateControl(delegate()
  152. {
  153. for (int t = 0; t < dt.Rows.Count; t++)
  154. {
  155. DataGridViewRow dgvr = new DataGridViewRow();
  156. DataGridViewCell cell = null;
  157. //员工编号
  158. cell = new DataGridViewTextBoxCell();
  159. cell.Value = dt.Rows[t]["User_EmployeeID"].ToString().Trim();
  160. dgvr.Cells.Add(cell);
  161. //员工姓名
  162. cell = new DataGridViewTextBoxCell();
  163. cell.Value = dt.Rows[t]["User_Name"].ToString().Trim();
  164. dgvr.Cells.Add(cell);
  165. //当前业绩
  166. cell = new DataGridViewTextBoxCell();
  167. DataRow dtRow = tbl.Rows.Find(dt.Rows[t]["User_EmployeeID"].ToString().Trim());
  168. if (dtRow != null)
  169. { cell.Value = dtRow["当前业绩"]; }
  170. else
  171. { cell.Value = "0.00"; }
  172. //DataTable dt_P = AllViewSetbll.GetErpWageCommissionRecords("当前业绩", " and 业绩开始时间>='" + txtTimeStart.Text + "' and 业绩结束时间<='" + txtTimeEnd.Text + "' and 员工编号='" + dt.Rows[t]["User_EmployeeID"].ToString().Trim() + "'").Tables[0];
  173. //if (!string.IsNullOrEmpty(dt_P.Rows[0]["业绩"].ToString()))
  174. //{ cell.Value = dt_P.Rows[0]["业绩"].ToString(); }
  175. //else
  176. //{ cell.Value = "0.00"; }
  177. dgvr.Cells.Add(cell);
  178. //计件提成
  179. cell = new DataGridViewTextBoxCell();
  180. DataRow dtRow2 = tbl.Rows.Find(dt.Rows[t]["User_EmployeeID"].ToString().Trim());
  181. if (dtRow2 != null)
  182. { cell.Value = dtRow2["计件提成"]; }
  183. else
  184. { cell.Value = "0.00"; }
  185. //dt_P = AllViewSetbll.GetErpWageCommissionRecords("计件提成", " and 业绩开始时间>='" + txtTimeStart.Text + "' and 业绩结束时间<='" + txtTimeEnd.Text + "' and 员工编号='" + dt.Rows[t]["User_EmployeeID"].ToString().Trim() + "'").Tables[0];
  186. //if (!string.IsNullOrEmpty(dt_P.Rows[0]["业绩"].ToString()))
  187. //{ cell.Value = dt_P.Rows[0]["业绩"].ToString(); }
  188. //else
  189. //{ cell.Value = "0.00"; }
  190. dgvr.Cells.Add(cell);
  191. //提成工资
  192. cell = new DataGridViewTextBoxCell();
  193. DataRow dtRow3 = tbl.Rows.Find(dt.Rows[t]["User_EmployeeID"].ToString().Trim());
  194. if (dtRow3 != null)
  195. { cell.Value = dtRow3["提成工资"]; }
  196. else
  197. { cell.Value = "0.00"; }
  198. //dt_P = AllViewSetbll.GetErpWageCommissionRecords("提成工资", " and 业绩开始时间>='" + txtTimeStart.Text + "' and 业绩结束时间<='" + txtTimeEnd.Text + "' and 员工编号='" + dt.Rows[t]["User_EmployeeID"].ToString().Trim() + "'").Tables[0];
  199. //if (!string.IsNullOrEmpty(dt_P.Rows[0]["业绩"].ToString()))
  200. //{ cell.Value = dt_P.Rows[0]["业绩"].ToString(); }
  201. //else
  202. //{ cell.Value = "0.00"; }
  203. dgvr.Cells.Add(cell);
  204. this.dgvAll.Rows.Add(dgvr);
  205. }
  206. this.dgvAll.ClearSelection();
  207. }));
  208. });
  209. #endregion
  210. }
  211. /// <summary>
  212. /// 删除
  213. /// </summary>
  214. /// <param name="sender"></param>
  215. /// <param name="e"></param>
  216. protected override void btnDelete_Click(object sender, EventArgs e)
  217. {
  218. try
  219. {
  220. if (this.dgv.SelectedRows.Count == 0)
  221. { MessageBoxCustom.Show("请选中你要删除的数据!"); return; }
  222. if (this.dgv.CurrentRow.Cells["Column2"].Value.ToString() == "统计:")
  223. { MessageBoxCustom.Show("此行不可删除!"); return; }
  224. if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  225. {
  226. LYFZ.BLL.BLL_ErpWageCommissionRecords bll = new BLL.BLL_ErpWageCommissionRecords();
  227. int id = Convert.ToInt32(this.dgv.CurrentRow.Cells["ID"].Value);
  228. if (bll.Delete(id))
  229. {
  230. string logsContent = "删除工资提成记录:" + this.dgv.CurrentRow.Cells["Column3"].Value.ToString() + " " + this.dgv.CurrentRow.Cells["Column4"].Value.ToString();
  231. LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.删除工资提成记录, logsContent, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
  232. //统计个人工资提成
  233. this.GetWage(this.N_NameTag, this.txtTimeStart.Text, this.txtTimeEnd.Text);
  234. MessageBoxCustom.Show("删除成功!");
  235. }
  236. }
  237. }
  238. catch (Exception ex)
  239. { MessageBoxCustom.Show(ex.Message); }
  240. }
  241. /// <summary>
  242. /// 查询
  243. /// </summary>
  244. /// <param name="sender"></param>
  245. /// <param name="e"></param>
  246. protected override void btnSelect_Click(object sender, EventArgs e)
  247. {
  248. if (this.N_NameText == "全部" || this.N_Name == "Department")//所有员工
  249. {
  250. this.dgv.Visible = false;
  251. this.btnDelete.Visible = false;
  252. this.TotalAllPerformance();
  253. }
  254. else
  255. {
  256. this.dgvAll.Visible = false;
  257. this.GetWage(this.N_NameTag, this.txtTimeStart.DateValue, this.txtTimeEnd.DateValue);
  258. }
  259. }
  260. /// <summary>
  261. /// 排序
  262. /// </summary>
  263. /// <param name="sender"></param>
  264. /// <param name="e"></param>
  265. protected override void dgvAll_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  266. {
  267. if (e.Column.Name == "员工姓名" || e.Column.Name == "业绩金额")
  268. { e.SortResult = (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) > 0) ? 1 : (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) < 0) ? -1 : 0; }
  269. //否则,按字符串比较
  270. else
  271. { e.SortResult = System.String.Compare(Convert.ToString(e.CellValue1), Convert.ToString(e.CellValue2)); }
  272. e.Handled = true;//不能省掉,不然没效果
  273. }
  274. /// <summary>
  275. /// 导出
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. protected override void btnExPort_Click(object sender, EventArgs e)
  280. {
  281. if (this.dgv.Visible)
  282. { this.dgv.ExportDataTable(); }
  283. else if (this.dgvAll.Visible)
  284. { this.dgvAll.ExportDataTable(); }
  285. }
  286. }
  287. }