using DevExpress.XtraRichEdit.Model; using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.FreeDb; using Mesnac.Controls.Default; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Runtime.InteropServices.ComTypes; using System.Text; using System.Threading.Tasks; namespace Mesnac.Action.ChemicalWeighing.Qu { public class Bao : 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 == "SelectButton") 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] = "全部"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = 1; dr[1] = "未解决"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = 0; dr[1] = "解决"; dataTable.Rows.Add(dr); mCCombobox.DataSource = dataTable; Sel(); } private void SelectButton_Click(object sender, EventArgs e) { Sel(); } private void Sel() { var a=Convert.ToDateTime(GetA()); var b= Convert.ToDateTime(GetB()); int state = Convert.ToInt16(mCCombobox.MCValue.ToString()); var list= FreeDb.FreeSqlUnit.Instance.Queryable().Where(x=>x.UpdateTime>a) .Where(x=>x.UpdateTime-1,x=>x.Status==state) .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)); foreach (var x in list) { var dr=dt.NewRow(); dr[0] = x.CnInfo; dr[1] = x.OtherInfo; dr[2]= Convert.ToDateTime(x.CreateTime).ToString("yyyy-MM-dd hh:mm:ss"); dr[3] = Convert.ToDateTime(x.UpdateTime).ToString("yyyy-MM-dd hh:mm:ss"); dr[4] = "已解决"; if (x.Status == 1) { dr[4] = "未解决"; } 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(); } } }