123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.StatisticalInquiry
- {
- public partial class FrmProductsUseStatistics : LYFZ.Software.UI.StatisticalInquiry.FrmProductsUseStatistics
- {
- private string _strQuery = "";
- private string _strWhere = "";
- public FrmProductsUseStatistics()
- {
- this.Load += FrmProductsUseStatistics_Load;
- this.Shown += FrmProductsUseStatistics_Shown;
- // 查询按钮;
- this.btn_query.Click += Btn_query_Click;
- // 复选框;
- this.cb_has_pickup.CheckedChanged += Cb_has_pickup_CheckedChanged;
- // 时间picker;
- this.dtp_start.ValueChanged += Dtp_ValueChanged;
- this.dtp_end.ValueChanged += Dtp_ValueChanged;
- // 导出xls;
- this.btn_export_xls.Click += Btn_export_xls_Click;
- }
- private void Btn_export_xls_Click(object sender, EventArgs e)
- {
- if (this.dgv.Rows.Count == 0)
- MessageBox.Show("没有数据可导出");
- this.dgv.ExportDataTable();
- }
- public void InitColumns(string strColumns /*逗号分隔*/, string strHideFields = ""/*逗号分隔*/, bool IsSort = false)
- {
- DataGridViewTextBoxColumn column = null;
- if (!string.IsNullOrEmpty(strColumns))
- {
- // 有必须的话, 清空之前的列头信息;
- this.dgv.Rows.Clear();
- this.dgv.Columns.Clear();
- List<string> listColumns = strColumns.Split(',').ToList();
- List<string> listHideFields = strHideFields.Split(',').ToList();
- for (int i = 0; i < listColumns.Count; i++)
- {
- column = new DataGridViewTextBoxColumn();
- column.ReadOnly = true;
- column.Name = listColumns[i].Trim();
- column.HeaderText = listColumns[i].Trim();
- // 是否有隐藏列;
- if (listHideFields.Contains(listColumns[i].Trim()))
- column.Visible = false;
- // 是否排序;
- if (IsSort)
- column.SortMode = DataGridViewColumnSortMode.Automatic;
- this.dgv.Columns.Add(column);
- }
- this.dgv.ColumnHeadersHeight = 25;
- this.dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- }
- }
- /// <summary>
- /// 填充数据;
- /// </summary>
- private void PaddingData()
- {
- // 清空以前的数据;
- this.dgv.Rows.Clear();
- // 查询数据;
- System.Data.DataTable dt = LYFZ.DAL.DAL_ErpOrderProductList.GetProductsUsage(this.cb_has_pickup.Checked, this.dtp_start.Value, this.dtp_end.Value);
- if (dt != null )
- {
- this.lb_count.Text = "当前商品数量: " + dt.Rows.Count;
- foreach (System.Data.DataRow dr in dt.Rows )
- {
- int index = this.dgv.Rows.Add();
- this.dgv.Rows[index].Cells[0].Value = dr["Prod_DividedShop"].ToString();
- this.dgv.Rows[index].Cells[1].Value = dr["Prod_Number"].ToString();
- this.dgv.Rows[index].Cells[2].Value = dr["Prod_Name"].ToString();
- this.dgv.Rows[index].Cells[3].Value = dr["Prod_Unit"].ToString();
- this.dgv.Rows[index].Cells[4].Value = dr["Prod_ClassName"].ToString();
- this.dgv.Rows[index].Cells[5].Value = dr["Prod_CostPrice"].ToString();
- this.dgv.Rows[index].Cells[6].Value = dr["Prod_SalesPrice"].ToString();
- this.dgv.Rows[index].Cells[7].Value = dr["Usage"].ToString();
- }
- }
- }
- private void Dtp_ValueChanged(object sender, EventArgs e)
- {
- if (this.dtp_start.Value > this.dtp_end.Value)
- MessageBoxCustom.Show("开始时间不能大于结束时间");
- else
- {
- PaddingData();
- }
- }
- private void Cb_has_pickup_CheckedChanged(object sender, EventArgs e)
- {
- PaddingData();
- }
- private void Btn_query_Click(object sender, EventArgs e)
- {
- PaddingData();
- }
- // 窗口显示事件;
- private void FrmProductsUseStatistics_Shown(object sender, EventArgs e)
- {
- PaddingData();
- }
- // 窗口加载事件;
- private void FrmProductsUseStatistics_Load(object sender, EventArgs e)
- {
- // 初始化datagridview字段;
- InitColumns("分店ID, 商品编号, 商品名称, 商品单位, 商品类名, 商品成本, 商品售价, 使用数量", "分店ID, 商品编号");
- // 设置默认时间段, 一个月前;
- this.dtp_start.Value = DateTime.Now.AddMonths(-1);
- }
- }
- }
|