using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.FreeDb; using Mesnac.Action.ChemicalWeighing.MainDetailControl.Entity; using Mesnac.Action.ChemicalWeighing.ManualControl; using Mesnac.Controls.Default; using Steema.TeeChart.Export; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Action.ChemicalWeighing.LjReport.WetWaitTime { public class WetTimeCounting : ChemicalWeighingAction, IAction { //BtnOk MCDateTimePicker1 MCDataGridView1 private RuntimeParameter _runtime; MCButton btnOk; MCButton selectButton; MCButton WhiteWork; MCButton NightWork; MCButton DataExport; MCDateTimePicker mCDateTimePicker; MCDateTimePicker startDate; MCDateTimePicker startTime; MCDateTimePicker endDate; MCDateTimePicker endTime; MCDataGridView dataGridView; MCDataGridView moreData; DataTable dt; DataTable MoreDataTable; List list; List listMore; List listSet; public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须调用 this._runtime = runtime; var control = GetAllControls(); this.DataExport = control.FirstOrDefault(x => x.Name == "DataExport") as MCButton; mCDateTimePicker = control.FirstOrDefault(x => x.Name == "MCDateTimePicker1") as MCDateTimePicker; btnOk = control.FirstOrDefault(x => x.Name == "MCButton1") as MCButton; dataGridView = control.FirstOrDefault(x => x.Name == "MCDataGridView1") as MCDataGridView; selectButton = control.FirstOrDefault(x => x.Name == "SelectButton") as MCButton; WhiteWork = control.FirstOrDefault(x => x.Name == "WhiteWork") as MCButton; NightWork = control.FirstOrDefault(x => x.Name == "NightWork") as MCButton; moreData = control.FirstOrDefault(x => x.Name == "MoreData") as MCDataGridView; startDate = control.FirstOrDefault(x => x.Name == "startDate") as MCDateTimePicker; startTime = control.FirstOrDefault(x => x.Name == "startTime") as MCDateTimePicker; endDate = control.FirstOrDefault(x => x.Name == "endDate") as MCDateTimePicker; endTime = control.FirstOrDefault(x => x.Name == "endTime") as MCDateTimePicker; dataGridView.AutoGenerateColumns = true; mCDateTimePicker.Value = DateTime.Now.AddDays(0); startDate.Value = DateTime.Now.AddDays(-1); //startTime.Value = Convert.ToDateTime(DateTime.Now.ToString("08:00:00")); //endTime.Value = Convert.ToDateTime(DateTime.Now.ToString("20:00:00")); dt = new DataTable(); dt.Columns.Add("机台", typeof(string)); dt.Columns.Add("湿混等待时间", typeof(string)); dt.Columns.Add("RGV等待时间", typeof(string)); dt.Columns.Add("总等待时间", typeof(string)); MoreDataTable = new DataTable(); MoreDataTable.Columns.Add("湿混等待时间", typeof(string)); MoreDataTable.Columns.Add("RGV等待时间", typeof(string)); MoreDataTable.Columns.Add("总等待时间", typeof(string)); MoreDataTable.Columns.Add("起始时间", typeof(string)); MoreDataTable.Columns.Add("结束时间", typeof(string)); btnOk.Click += BtnOk_Click; selectButton.Click += SelectButton_Click; dataGridView.CellClick += MoreData_Click; dataGridView.CellValueChanged += MoreData_Click; WhiteWork.Click += WhiteWork_Click; NightWork.Click += NightWork_Click; DataExport.Click += DataExport_Click; } private void BtnOk_Click(object sender, EventArgs e) { dt.Rows.Clear(); DateTime time = mCDateTimePicker.Value; DateTime start = time.Date.AddHours(0); DateTime end = time.Date.AddHours(24); list = FreeSqlUnit.Instance.Select().Where(x => x.MixReadyStartTime >= start && x.RGVLeaveTime <= end).ToList(); DataTableSum(); dataGridView.DataSource = null; dataGridView.DataSource = dt; } private void SelectButton_Click(object sender, EventArgs e) { dt.Rows.Clear(); DateTime starttime = startDate.Value.Date.AddHours(startTime.Value.Hour).AddMinutes(startTime.Value.Minute).AddSeconds(startTime.Value.Second); DateTime endtime = endDate.Value.Date.AddHours(endTime.Value.Hour).AddMinutes(endTime.Value.Minute).AddSeconds(endTime.Value.Second); list = FreeSqlUnit.Instance.Select().Where(x => x.MixReadyStartTime >= starttime && x.RGVLeaveTime <= endtime).ToList(); DataTableSum(); dataGridView.DataSource = null; dataGridView.DataSource = dt; } /// /// 检索详细数据 /// /// /// private void MoreData_Click(object sender, EventArgs e) { MoreDataTable.Rows.Clear(); string dID = dataGridView.SelectedRows[0].Cells["机台"].Value as string; char[] a = dID.ToCharArray(); int le = a.Length - 1; char chr = a[le]; if (chr == '和') { return; } int num = int.Parse(chr.ToString()); listMore = list.Where(x => x.DeviceNo == num).ToList(); for (int i = 0; i < listMore.Count; i++) { var dr = MoreDataTable.NewRow(); dr[0] = TimeConvert(listMore[i].MixWaitTime); dr[1] = TimeConvert(listMore[i].RgvWaitTime); dr[2] = TimeConvert(listMore[i].MixWaitTime + listMore[i].RgvWaitTime); dr[3] = listMore[i].MixReadyStartTime; dr[4] = listMore[i].RGVLeaveTime; MoreDataTable.Rows.Add(dr); } moreData.AutoGenerateColumns = true; moreData.DataSource = null; moreData.DataSource = MoreDataTable; } private void WhiteWork_Click(object sender, EventArgs e) { dt.Rows.Clear(); DateTime nowTime = DateTime.Now; DateTime starttime; DateTime endtime; //如果大于当天8点 就展示当天的白班 否则展示上一个白班 if (nowTime >= DateTime.Now.Date.AddHours(8)) { starttime = DateTime.Now.Date.AddHours(7).AddMinutes(30); endtime = DateTime.Now.Date.AddHours(19).AddMinutes(30); } else { starttime = DateTime.Now.Date.AddHours(-17).AddMinutes(30); endtime = DateTime.Now.Date.AddHours(-5).AddMinutes(30); } list = FreeSqlUnit.Instance.Select().Where(x => x.MixReadyStartTime >= starttime && x.RGVLeaveTime <= endtime).ToList(); DataTableSum(); dataGridView.DataSource = null; dataGridView.DataSource = dt; } private void NightWork_Click(object sender, EventArgs e) { dt.Rows.Clear(); DateTime nowTime = DateTime.Now; DateTime starttime; DateTime endtime; //如果小于当天20点 就展示当天的前一个晚班 if (nowTime <= DateTime.Now.Date.AddHours(20)) { starttime = DateTime.Now.Date.AddHours(-5).AddMinutes(30); endtime = DateTime.Now.Date.AddHours(7).AddMinutes(30); } else { starttime = DateTime.Now.Date.AddHours(19).AddMinutes(30); endtime = DateTime.Now.Date.AddHours(31).AddMinutes(30); } list = FreeSqlUnit.Instance.Select().Where(x => x.MixReadyStartTime >= starttime && x.RGVLeaveTime <= endtime).ToList(); DataTableSum(); dataGridView.DataSource = null; dataGridView.DataSource = dt; } private void DataTableSum() { for (int i = 1; i <= 8; i++) { var dr = dt.NewRow(); dr[0] = "湿混机" + i; var MixWaitTime = list.Where(x => x.DeviceNo == i).Sum(x => x.MixWaitTime); dr[1] = TimeConvert(MixWaitTime); var RGVWaitTime = list.Where(x => x.DeviceNo == i).Sum(x => x.RgvWaitTime); dr[2] = TimeConvert(RGVWaitTime); var totalTime = MixWaitTime + RGVWaitTime; dr[3] = TimeConvert(totalTime); dt.Rows.Add(dr); } try { var edr = dt.NewRow(); edr[0] = "湿混等待时间总和"; edr[1] = TimeConvert(list.Sum(x => x.MixWaitTime)); dt.Rows.Add(edr); var edr1 = dt.NewRow(); edr1[0] = "RGV等待时间总和"; edr1[1] = TimeConvert(list.Sum(x => x.RgvWaitTime)); dt.Rows.Add(edr1); var edr2 = dt.NewRow(); edr2[0] = "总等待时间总和"; edr2[1] = TimeConvert(list.Sum(x => x.MixWaitTime + x.RgvWaitTime)); dt.Rows.Add(edr2); } catch (OverflowException ex) { MessageBox.Show("算术值溢出!请检查数据是否有误"); } } private string TimeConvert(int t) { int h = t / 3600; int m = (t / 60) % 60; int s = t % 60; if (h != 0) { return h + "时" + m + "分" + s + "秒"; } if (m != 0) { return m + "分" + s + "秒"; } return s + "秒"; } private void DataExport_Click(object sender, EventArgs e) { DateTime starttime = startDate.Value.Date.AddHours(startTime.Value.Hour).AddMinutes(startTime.Value.Minute).AddSeconds(startTime.Value.Second); DateTime endtime = endDate.Value.Date.AddHours(endTime.Value.Hour).AddMinutes(endTime.Value.Minute).AddSeconds(endTime.Value.Second); list = FreeSqlUnit.Instance.Select().Where(x => x.MixReadyStartTime >= starttime && x.RGVLeaveTime <= endtime).ToList(); Export export = new Export(list); } } }