using Mesnac.Action.Base; using Mesnac.Controls.Base; using Mesnac.Controls.Default; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Linq; using Mesnac.Action.ChemicalWeighing.FreeDb; namespace Mesnac.Action.ChemicalWeighing.Su { public class SuSongInit: ChemicalWeighingAction, IAction { MCDateTimePicker startDate; MCDateTimePicker startTime; MCDateTimePicker endDate; MCDateTimePicker endTime; MCButton SelectButton; MCDataGridView MoreData; MCCombobox mCCombobox; public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用的 var control = GetAllControls(); 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; SelectButton = control.FirstOrDefault(x => x.Name == "WhiteWork") as MCButton; SelectButton.Click += SelectButton_Click; ; MoreData = control.FirstOrDefault(x => x.Name == "MoreData") as MCDataGridView; MoreData.AutoGenerateColumns = true; startTime.MCValue = DateTime.Now.AddHours(-5); mCCombobox = control.FirstOrDefault(x => x.Name == "MCCombobox1") as MCCombobox; DataTable dataTable = new DataTable(); dataTable.Columns.Add("CmbValue", typeof(string)); dataTable.Columns.Add("CmbDisplay", typeof(string)); var dr = dataTable.NewRow(); dr[0] = 1; dr[1] = "输送A"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = 2; dr[1] = "输送B"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = 3; dr[1] = "输送C"; dataTable.Rows.Add(dr); mCCombobox.DataSource = dataTable; Sel(); } private void SelectButton_Click(object sender, EventArgs e) { Sel(); } string[] destinations = new string[] { "大仓A", "大仓B", "大仓C", "大仓D", "大仓E", "大仓F", "大仓G", "大仓H", "大仓I", "大仓J", "大仓K", "大仓L", "大仓M", "大仓N", "大仓O", "大仓P", "大仓Q", "大仓R", "大仓S", "大仓T", "大仓U", "大仓V", "大仓W", "大仓X", "大仓Y", "大仓Z" }; private void Sel() { var a = Convert.ToDateTime(GetA()); var b = Convert.ToDateTime(GetB()); int ab= Convert.ToInt32(mCCombobox.MCValue); var list = FreeDb.FreeSqlUnit.Instance.Queryable().Where(x => x.CreateTime > a) .Where(x => x.CreateTime < b) .Where(x=>x.No==ab) .Take(1000).OrderByDescending(x => x.UpdateTime).ToList(); var dt = new DataTable(); dt.Columns.Add("输送线路", typeof(string)); dt.Columns.Add("源仓", typeof(string)); dt.Columns.Add("方式", typeof(string)); dt.Columns.Add("目标仓", typeof(string)); dt.Columns.Add("数量", typeof(string)); dt.Columns.Add("开始时间", typeof(string)); dt.Columns.Add("更新时间", typeof(string)); dt.Columns.Add("状态", typeof(string)); foreach (var x in list) { var dr = dt.NewRow(); String aa = ""; if (x.No == 1) aa = "A"; if (x.No == 2) aa = "B"; if (x.No == 3) aa = "C"; dr[0] = "输送线路"+aa; dr[1] = x.Soure; dr[2] = x.Model; string shu = ""; if (x.Model == 1) { shu = "A"; } if (x.Model == 2) { shu = "A"; } if (x.Model == 3) { shu = "A+B"; } dr[2] = shu; dr[3] = x.Destination; if (x.Destination >= 0) { string info = destinations[x.Destination]; dr[3] = info; } dr[4] = x.Number; dr[5] = Convert.ToDateTime(x.CreateTime).ToString("yyyy-MM-dd hh:mm:ss"); dr[6] = Convert.ToDateTime(x.UpdateTime).ToString("yyyy-MM-dd hh:mm:ss"); dr[7] = x.Remark; dt.Rows.Add(dr); } MoreData.AutoGenerateColumns = true; MoreData.DataSource = null; MoreData.DataSource = dt; } private string GetA() { return Convert.ToDateTime(startDate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(startTime.MCValue).ToShortTimeString(); } private string GetB() { return Convert.ToDateTime(endDate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(endTime.MCValue).ToShortTimeString(); } } }