using Stone.Common; using Stone.Entity; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Stone.WinModule.JISData { public partial class frmJISLABCompare : Stone.WinModule.frmBase { public frmJISLABCompare() { InitializeComponent(); this.txtStartDate1.Value = DateTime.Now; this.txtStartDate2.Value = DateTime.Now.AddDays(10); this.txtReleaseDate1.Value = DateTime.Now.AddDays(-7); this.txtReleaseDate2.Value = DateTime.Now; } private void frmJISLABCompare_Load(object sender, EventArgs e) { } private void txtPartNumber_OnSelectClick(object sender, EventArgs e) { try { Stone.WinModule.BasicData.frmProduct frm = new BasicData.frmProduct(); frm.m_Base = new WinBiz.BasicData.F_Product(); frm.init(); if (frm.ShowSelect("") == DialogResult.OK) { this.txtPartNumber.Text = frm.SelectValue; } frm.Dispose(); } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } private void btnQuery_Click(object sender, EventArgs e) { try { if (!MyValidator.IsEmpty(this.txtPartNumber, "")) return; if ((this.txtStartDate2.Value - this.txtStartDate1.Value).TotalDays > 60) throw new Exception("需求日期范围不能大于60天"); string PartNumber = this.txtPartNumber.Text.Trim(); string StartDate1 = this.txtStartDate1.Value.ToString("yyyy-MM-dd"); string StartDate2 = this.txtStartDate2.Value.ToString("yyyy-MM-dd"); string ReleaseDate1 = this.txtReleaseDate1.Value.ToString("yyyy-MM-dd 00:00:00"); string ReleaseDate2 = this.txtReleaseDate2.Value.ToString("yyyy-MM-dd 23:59:59"); //if (Convert.ToDateTime(StartDate1) > Convert.ToDateTime(StartDate2)) //{ // throw new Exception("需求开始日期不能大于结束日期"); //} Entity_t_JIS_Lab_All t_JIS_Lab_All = new Entity_t_JIS_Lab_All(); DataTable dtData = t_JIS_Lab_All.GetData( $"startDate, quantity, releaseId", $"[PartNumber]='{PartNumber}' and [StartDate]>='{StartDate1}' and [StartDate]<='{StartDate2}' and " + $"[Time]>='{ReleaseDate1}' and [Time]<='{ReleaseDate2}'", $"[releaseId] asc, [StartDate] asc").Tables[0]; DataTable dtShow = new DataTable(); dtShow.Columns.Add("releaseId"); DateTime d = Convert.ToDateTime(StartDate1); while (true) { dtShow.Columns.Add(d.ToString("yyyy-MM-dd")); d = d.AddDays(1); if (d > Convert.ToDateTime(StartDate2)) break; } foreach (DataRow drData in dtData.Rows) { string releaseId = drData["releaseId"].ToString(); string startDate = Convert.ToDateTime(drData["startDate"]).ToString("yyyy-MM-dd"); int quantity = Convert.ToInt32(drData["quantity"]); DataRow[] drs = dtShow.Select($"[releaseId]='{releaseId}'"); if (drs.Length == 0) { DataRow drNew = dtShow.NewRow(); drNew["releaseId"] = releaseId; drNew[startDate] = quantity; dtShow.Rows.Add(drNew); } else { if (drs[0][startDate] == DBNull.Value) drs[0][startDate] = 0; drs[0][startDate] = Convert.ToInt32(drs[0][startDate]) + quantity; } } this.dgrdView.DataSource = dtShow; this.lblState.Text = "记录:" + dtShow.Rows.Count; } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } private void btnExport_Click(object sender, EventArgs e) { MyExport.ShowExport(this.dgrdView); } } }