using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Dto; using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service; using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service.Impl; using DevComponents.DotNetBar.Controls; using DevComponents.Editors; using DevComponents.Editors.DateTimeAdv; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Windows.Forms; namespace Casic.Birmm.RbFreqStandMeasure.info { public partial class InfoCtrlForm : UserControl { private DataTable devList = null; private int totalCount = 0; // 总行数 private int currentPage = 1; // 当前页码 private int pageCount = 0; // 总页数 private readonly int limitCount = 10; // 每页数据条数,当前页面的表格固定为10条 JObject condition = new JObject(); // 查询条件 DeviceService deviceService = new DeviceServiceImpl(); #region 输入框默认文字 public readonly string DefaultDevName = "请输入仪器名称"; public readonly string DefaultDevModel = "请输入仪器型号"; public readonly string DefaultDevCode = "请输入仪器编号"; public readonly string DefaultCustomComp = "请输入送检单位名称"; public readonly string DefaultCustomName = "请输入联系人"; #endregion #region 样式常量定义 private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F64D7 private readonly Color tableForeColor = Color.White; private readonly Font titleFont = new Font("微软雅黑", 14F, FontStyle.Regular, GraphicsUnit.Pixel, 134); private readonly Color inputBlack = Color.FromArgb(51, 51, 51); // #333333 private readonly Color inputDefault = Color.FromArgb(204, 204, 204); // #CCCCCC #endregion public InfoCtrlForm() { InitializeComponent(); this.inputDevStatus.SelectedIndex = 0; // 仪器状态默认选择“全部” // 进入页面时默认查询所有的数据 totalCount = GetTotalCount(condition); // 初始化表格并加载数据 InitTableDevList(); LoadDevList(condition); } private void InitTableDevList() { tableDevList.Columns.Clear(); tableDevList.Rows.Clear(); // 添加标题栏 Panel tableHeader = new Panel { BackColor = tableForeColor, Size = new Size(964, 40), Location = new Point(0, 0) }; tableHeader.BackColor = titleBackColor; tableDevList.Controls.Add(tableHeader); // 序号 Label colNo = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "序号", Location = new Point(0, 0), Size = new Size(80, 40) }; tableDevList.Controls.Add(colNo); colNo.BringToFront(); // 登记时间 Label colRegTime = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "登记时间", Location = new Point(80, 0), Size = new Size(164, 40) }; tableDevList.Controls.Add(colRegTime); colRegTime.BringToFront(); // 仪器名称 Label colDevName = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "仪器名称", Location = new Point(244, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colDevName); colDevName.BringToFront(); // 仪器型号 Label colDevType = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "仪器型号", Location = new Point(364, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colDevType); colDevType.BringToFront(); // 仪器编号 Label colDevNo = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "仪器编号", Location = new Point(484, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colDevNo); colDevNo.BringToFront(); // 客户名称 Label colCustomName = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "客户名称", Location = new Point(604, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colCustomName); colCustomName.BringToFront(); // 设备状态 Label colDevStatus = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "设备状态", Location = new Point(724, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colDevStatus); colDevStatus.BringToFront(); // 通道号 Label colChannelNo = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "通道号", Location = new Point(844, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colChannelNo); colChannelNo.BringToFront(); } private void LoadDevList(JObject condition) { devList = new DataTable(); // 设置表格的列 devList.Columns.Add("index", Type.GetType("System.String")); devList.Columns.Add("regTime", Type.GetType("System.String")); devList.Columns.Add("devName", Type.GetType("System.String")); devList.Columns.Add("devModel", Type.GetType("System.String")); devList.Columns.Add("devCode", Type.GetType("System.String")); devList.Columns.Add("customName", Type.GetType("System.String")); devList.Columns.Add("status", Type.GetType("System.String")); devList.Columns.Add("channelNo", Type.GetType("System.String")); devList.Columns.Add("id", Type.GetType("System.Int32")); // 分页查询数据库 string devName = ""; string devModel = ""; string devCode = ""; string devStatus = ""; string customComp = ""; string customName = ""; int page = 1; if (condition.Property("devName") != null) { devName = condition.Property("devName").Value.ToString(); } if (condition.Property("devModel") != null) { devModel = condition.Property("devModel").Value.ToString(); } if (condition.Property("devCode") != null) { devCode = condition.Property("devCode").Value.ToString(); } if (condition.Property("devStatus") != null) { devStatus = condition.Property("devStatus").Value.ToString(); } if (condition.Property("customComp") != null) { customComp = condition.Property("customComp").Value.ToString(); } if (condition.Property("customName") != null) { customName = condition.Property("customName").Value.ToString(); } if (condition.Property("page") != null) { page = Convert.ToInt32(condition.Property("page").Value.ToString()); } // 获取总条数 totalCount = deviceService.getTotalCount(devName, devCode, devModel, customComp, customName, devStatus); // 获取当前页的数据 List<DeviceDto> queryList = deviceService.searchPage(devName, devCode, devModel, customComp, customName, devStatus, page, limitCount); if (null != queryList && queryList.Count > 0) { // 重新计算页码数据 pageCount = Decimal.ToInt32(Math.Ceiling((decimal) totalCount / limitCount)); ((Label)this.Controls.Find("labelPageCount", true)[0]).Text = "共 " + totalCount + " 条,每页 " + limitCount + " 条,共 " + pageCount + " 页"; ((Label)this.Controls.Find("labelCurrentPage", true)[0]).Text = currentPage.ToString(); int i = 0; foreach ( DeviceDto device in queryList ) { int index = (page-1) * limitCount + i + 1; devList.Rows.Add(index, device.RegTime, device.DevName, device.DevModel, device.DevCode, device.CustomerName, device.StatusName, device.Channel, device.Id); i++; } this.Controls.Find("panelNodata", true)[0].Hide(); this.Controls.Find("panelPage", true)[0].Show(); } else { this.Controls.Find("panelNodata", true)[0].Show(); this.Controls.Find("panelPage", true)[0].Hide(); } tableDevList.DataSource = devList; // width=964px tableDevList.Columns[0].Width = 80; tableDevList.Columns[1].Width = 164; tableDevList.Columns[2].Width = 120; tableDevList.Columns[3].Width = 120; tableDevList.Columns[4].Width = 120; tableDevList.Columns[5].Width = 120; tableDevList.Columns[6].Width = 120; tableDevList.Columns[7].Width = 120; tableDevList.Columns[8].Width = 0; tableDevList.Columns[8].Visible = false; // id不显示 tableDevList.Columns[0].ReadOnly = true; tableDevList.Columns[1].ReadOnly = true; tableDevList.Columns[2].ReadOnly = true; tableDevList.Columns[3].ReadOnly = true; tableDevList.Columns[4].ReadOnly = true; tableDevList.Columns[5].ReadOnly = true; tableDevList.Columns[6].ReadOnly = true; tableDevList.Columns[7].ReadOnly = true; tableDevList.Columns[8].ReadOnly = true; } private int GetTotalCount(JObject condition) { string devName = ""; string devModel = ""; string devCode = ""; string devStatus = ""; string customComp = ""; string customName = ""; if (condition.Property("devName") != null) { devName = condition.Property("devName").Value.ToString(); } if (condition.Property("devModel") != null) { devModel = condition.Property("devModel").Value.ToString(); } if (condition.Property("devCode") != null) { devCode = condition.Property("devCode").Value.ToString(); } if (condition.Property("devStatus") != null) { devStatus = condition.Property("devStatus").Value.ToString(); } if (condition.Property("customComp") != null) { customComp = condition.Property("customComp").Value.ToString(); } if (condition.Property("customName") != null) { customName = condition.Property("customName").Value.ToString(); } int total = deviceService.getTotalCount(devName, devCode, devModel, customComp, customName, devStatus); return total; } private void btnAdd_Click(object sender, EventArgs e) { AddDevDlg addDevDlg = new AddDevDlg(); addDevDlg.HideMaskAction += () => { this.HideMask(); }; this.ShowMask(); addDevDlg.StartPosition = FormStartPosition.CenterParent; // 指定窗口弹出在父窗口的中间位置 // 设置默认值 DateTimeInput startTimeInput = (DateTimeInput) addDevDlg.Controls.Find("startTime", true)[0]; startTimeInput.Value = DateTime.Now; DateTimeInput endTimeInput = (DateTimeInput)addDevDlg.Controls.Find("endTimeEst", true)[0]; endTimeInput.Value = DateTime.Now.AddDays(1); addDevDlg.ShowDialog(); } private MaskForm maskForm; private void ShowMask() { maskForm = new MaskForm(this.Parent.Parent.Location, this.Parent.Parent.Size); maskForm.Show(); } private void HideMask() { if (maskForm != null) { maskForm.Close(); } } private void btnQuery_Click(object sender, EventArgs e) { string devName = CheckInputText("inputDevName", DefaultDevName); string devModel = CheckInputText("inputDevModel", DefaultDevModel); string devCode = CheckInputText("inputDevCode", DefaultDevCode); string customComp = CheckInputText("inputCustomComp", DefaultCustomComp); string customName = CheckInputText("inputCustomName", DefaultCustomName); ComboBoxEx statusSelect = (ComboBoxEx)this.Controls.Find("inputDevStatus", true)[0]; string devStatus = (string)((ComboItem)statusSelect.SelectedItem).Value; condition.RemoveAll(); condition.Add("devName", devName); condition.Add("devModel", devModel); condition.Add("devCode", devCode); condition.Add("devStatus", devStatus); condition.Add("customComp", customComp); condition.Add("customName", customName); condition.Add("page", 1); // 查询数据 LoadDevList(condition); } private string CheckInputText(string inputName, string defaultText) { string name = ((TextBoxX)this.Controls.Find(inputName, true)[0]).Text; if (name == defaultText) { return ""; } else { return name; } } private void inputClick(string inputName, string defaultText, object sender) { string name = CheckInputText(inputName, defaultText); ((TextBoxX)sender).Text = name; ((TextBoxX)sender).ForeColor = inputBlack; } private void inputLeave(string inputName, string defaultText, object sender) { string name = CheckInputText(inputName, defaultText); if (name == "") { ((TextBoxX)sender).Text = defaultText; ((TextBoxX)sender).ForeColor = inputDefault; } } private void inputDevName_Click(object sender, EventArgs e) { inputClick("inputDevName", DefaultDevName, sender); } private void inputDevName_Leave(object sender, EventArgs e) { inputLeave("inputDevName", DefaultDevName, sender); } private void inputDevModel_Click(object sender, EventArgs e) { inputClick("inputDevModel", DefaultDevModel, sender); } private void inputDevModel_Leave(object sender, EventArgs e) { inputLeave("inputDevModel", DefaultDevModel, sender); } private void inputDevCode_Click(object sender, EventArgs e) { inputClick("inputDevCode", DefaultDevCode, sender); } private void inputDevCode_Leave(object sender, EventArgs e) { inputLeave("inputDevCode", DefaultDevCode, sender); } private void inputCustomComp_Click(object sender, EventArgs e) { inputClick("inputCustomComp", DefaultCustomComp, sender); } private void inputCustomComp_Leave(object sender, EventArgs e) { inputLeave("inputCustomComp", DefaultCustomComp, sender); } private void inputCustomName_Click(object sender, EventArgs e) { inputClick("inputCustomName", DefaultCustomName, sender); } private void inputCustomName_Leave(object sender, EventArgs e) { inputLeave("inputCustomName", DefaultCustomName, sender); } private void btnPre_Click(object sender, EventArgs e) { if (currentPage > 1) { currentPage -= 1; condition.Remove("page"); condition.Add("page", currentPage); LoadDevList(condition); } } private void btnNext_Click(object sender, EventArgs e) { if (currentPage < pageCount) { currentPage += 1; condition.Remove("page"); condition.Add("page", currentPage); LoadDevList(condition); } } private void btnDetail_Click(object sender, EventArgs e) { } } }