FrmProductsUseStatistics.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. namespace LYFZ.Software.MainBusiness.StatisticalInquiry
  7. {
  8. public partial class FrmProductsUseStatistics : LYFZ.Software.UI.StatisticalInquiry.FrmProductsUseStatistics
  9. {
  10. private string _strQuery = "";
  11. private string _strWhere = "";
  12. public FrmProductsUseStatistics()
  13. {
  14. this.Load += FrmProductsUseStatistics_Load;
  15. this.Shown += FrmProductsUseStatistics_Shown;
  16. // 查询按钮;
  17. this.btn_query.Click += Btn_query_Click;
  18. // 复选框;
  19. this.cb_has_pickup.CheckedChanged += Cb_has_pickup_CheckedChanged;
  20. // 时间picker;
  21. this.dtp_start.ValueChanged += Dtp_ValueChanged;
  22. this.dtp_end.ValueChanged += Dtp_ValueChanged;
  23. // 导出xls;
  24. this.btn_export_xls.Click += Btn_export_xls_Click;
  25. }
  26. private void Btn_export_xls_Click(object sender, EventArgs e)
  27. {
  28. if (this.dgv.Rows.Count == 0)
  29. MessageBox.Show("没有数据可导出");
  30. this.dgv.ExportDataTable();
  31. }
  32. public void InitColumns(string strColumns /*逗号分隔*/, string strHideFields = ""/*逗号分隔*/, bool IsSort = false)
  33. {
  34. DataGridViewTextBoxColumn column = null;
  35. if (!string.IsNullOrEmpty(strColumns))
  36. {
  37. // 有必须的话, 清空之前的列头信息;
  38. this.dgv.Rows.Clear();
  39. this.dgv.Columns.Clear();
  40. List<string> listColumns = strColumns.Split(',').ToList();
  41. List<string> listHideFields = strHideFields.Split(',').ToList();
  42. for (int i = 0; i < listColumns.Count; i++)
  43. {
  44. column = new DataGridViewTextBoxColumn();
  45. column.ReadOnly = true;
  46. column.Name = listColumns[i].Trim();
  47. column.HeaderText = listColumns[i].Trim();
  48. // 是否有隐藏列;
  49. if (listHideFields.Contains(listColumns[i].Trim()))
  50. column.Visible = false;
  51. // 是否排序;
  52. if (IsSort)
  53. column.SortMode = DataGridViewColumnSortMode.Automatic;
  54. this.dgv.Columns.Add(column);
  55. }
  56. this.dgv.ColumnHeadersHeight = 25;
  57. this.dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  58. }
  59. }
  60. /// <summary>
  61. /// 填充数据;
  62. /// </summary>
  63. private void PaddingData()
  64. {
  65. // 清空以前的数据;
  66. this.dgv.Rows.Clear();
  67. // 查询数据;
  68. System.Data.DataTable dt = LYFZ.DAL.DAL_ErpOrderProductList.GetProductsUsage(this.cb_has_pickup.Checked, this.dtp_start.Value, this.dtp_end.Value);
  69. if (dt != null )
  70. {
  71. this.lb_count.Text = "当前商品数量: " + dt.Rows.Count;
  72. foreach (System.Data.DataRow dr in dt.Rows )
  73. {
  74. int index = this.dgv.Rows.Add();
  75. this.dgv.Rows[index].Cells[0].Value = dr["Prod_DividedShop"].ToString();
  76. this.dgv.Rows[index].Cells[1].Value = dr["Prod_Number"].ToString();
  77. this.dgv.Rows[index].Cells[2].Value = dr["Prod_Name"].ToString();
  78. this.dgv.Rows[index].Cells[3].Value = dr["Prod_Unit"].ToString();
  79. this.dgv.Rows[index].Cells[4].Value = dr["Prod_ClassName"].ToString();
  80. this.dgv.Rows[index].Cells[5].Value = dr["Prod_CostPrice"].ToString();
  81. this.dgv.Rows[index].Cells[6].Value = dr["Prod_SalesPrice"].ToString();
  82. this.dgv.Rows[index].Cells[7].Value = dr["Usage"].ToString();
  83. }
  84. }
  85. }
  86. private void Dtp_ValueChanged(object sender, EventArgs e)
  87. {
  88. if (this.dtp_start.Value > this.dtp_end.Value)
  89. MessageBoxCustom.Show("开始时间不能大于结束时间");
  90. else
  91. {
  92. PaddingData();
  93. }
  94. }
  95. private void Cb_has_pickup_CheckedChanged(object sender, EventArgs e)
  96. {
  97. PaddingData();
  98. }
  99. private void Btn_query_Click(object sender, EventArgs e)
  100. {
  101. PaddingData();
  102. }
  103. // 窗口显示事件;
  104. private void FrmProductsUseStatistics_Shown(object sender, EventArgs e)
  105. {
  106. PaddingData();
  107. }
  108. // 窗口加载事件;
  109. private void FrmProductsUseStatistics_Load(object sender, EventArgs e)
  110. {
  111. // 初始化datagridview字段;
  112. InitColumns("分店ID, 商品编号, 商品名称, 商品单位, 商品类名, 商品成本, 商品售价, 使用数量", "分店ID, 商品编号");
  113. // 设置默认时间段, 一个月前;
  114. this.dtp_start.Value = DateTime.Now.AddMonths(-1);
  115. }
  116. }
  117. }