using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using DevComponents.DotNetBar; using System.Data.OracleClient; using Cyberpipe; namespace EMS { public partial class FrmLog : Office2007Form { private PanelEx panelEx1; private ButtonX btn_query; private Label label1; private DateTimePicker dateTimePicker_end; private DateTimePicker dateTimePicker_start; private LabelX labelX1; private Bar bar1; string macId; private int currentpage = 1; private int lastpage = 1; private LabelItem lab_page_msg; private ButtonItem btn_page_first; private ButtonItem btn_page_pre; private ComboBoxItem combo_page_num; private ButtonItem btn_page_next; private ButtonItem btn_page_last; private DevComponents.DotNetBar.Controls.DataGridViewX dataGridViewX1; private DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn dbid; private DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn rowno; private DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn equipment; private DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn operate; private DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn operate_time; private DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn username; private int pagesize = 16; public FrmLog() { InitializeComponent(); } public FrmLog(string macId) { this.macId = macId; InitializeComponent(); } private void FrmLog_Load(object sender, EventArgs e) { dateTimePicker_end.Value = DateTime.Now; dateTimePicker_start.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); reloadDataGrid(currentpage); } private void reloadDataGrid(int pageIndex) { if (dateTimePicker_start.Value.CompareTo(dateTimePicker_end.Value) > 0) { MessageBox.Show("开始日期不能大于结束日期!"); return; } string sqlrows = "select * from (select rownum as rowno,dbid,equipment,operate,operate_time,username from loginfo where equipment='" + macId + "' "; string sqlcount = "select count(*) from loginfo where equipment='" + macId + "' "; if (null != dateTimePicker_start.Value) { sqlrows += "and operate_time>=to_date('" + dateTimePicker_start.Value.ToShortDateString() + "','yyyy-MM-dd') "; sqlcount += "and operate_time>=to_date('" + dateTimePicker_start.Value.ToShortDateString() + "','yyyy-MM-dd') "; } if (null != dateTimePicker_end.Value) { DateTime time = dateTimePicker_end.Value; sqlrows += "and operate_time<=to_date('" + time.AddDays(1).ToShortDateString() + "','yyyy-MM-dd') "; sqlcount += "and operate_time<=to_date('" + time.AddDays(1).ToShortDateString() + "','yyyy-MM-dd') "; } sqlrows += "and rownum<=" + (pagesize * pageIndex) + ") table_alias where table_alias.rowno>=" + ((pageIndex - 1) * pagesize + 1); sqlrows += " order by operate_time desc"; int rows = int.Parse(OracleUtils.ExecuteScalar(OracleUtils.ConnectionString, CommandType.Text, sqlcount).ToString()); int pages = 0; if (rows % pagesize == 0) { pages = rows / pagesize; } else { pages = rows / pagesize + 1; } lastpage = pages; lab_page_msg.Text = "共" + rows + "条记录,每页" + pagesize + "条,第" + pageIndex + "页,共" + pages + "页"; combo_page_num.Items.Clear(); for (int i = 1; i <= pages; i++) { combo_page_num.Items.Add(new ComboBoxItem(i.ToString(), i.ToString())); } if (lastpage == 1) { btn_page_first.Enabled = false; btn_page_pre.Enabled = false; btn_page_last.Enabled = false; btn_page_next.Enabled = false; } else if (currentpage == 1) { btn_page_first.Enabled = false; btn_page_pre.Enabled = false; btn_page_last.Enabled = true; btn_page_next.Enabled = true; } else if (currentpage == lastpage) { btn_page_first.Enabled = true; btn_page_pre.Enabled = true; btn_page_last.Enabled = false; btn_page_next.Enabled = false; } else { btn_page_first.Enabled = true; btn_page_pre.Enabled = true; btn_page_last.Enabled = true; btn_page_next.Enabled = true; } DataTable table = OracleUtils.ExecuteDataset(OracleUtils.ConnectionString, CommandType.Text, sqlrows).Tables[0]; dataGridViewX1.DataSource = table; } private void InitializeComponent() { System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle34 = new System.Windows.Forms.DataGridViewCellStyle(); this.panelEx1 = new DevComponents.DotNetBar.PanelEx(); this.btn_query = new DevComponents.DotNetBar.ButtonX(); this.label1 = new System.Windows.Forms.Label(); this.dateTimePicker_end = new System.Windows.Forms.DateTimePicker(); this.dateTimePicker_start = new System.Windows.Forms.DateTimePicker(); this.labelX1 = new DevComponents.DotNetBar.LabelX(); this.bar1 = new DevComponents.DotNetBar.Bar(); this.lab_page_msg = new DevComponents.DotNetBar.LabelItem(); this.btn_page_first = new DevComponents.DotNetBar.ButtonItem(); this.btn_page_pre = new DevComponents.DotNetBar.ButtonItem(); this.combo_page_num = new DevComponents.DotNetBar.ComboBoxItem(); this.btn_page_next = new DevComponents.DotNetBar.ButtonItem(); this.btn_page_last = new DevComponents.DotNetBar.ButtonItem(); this.dataGridViewX1 = new DevComponents.DotNetBar.Controls.DataGridViewX(); this.dbid = new DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn(); this.rowno = new DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn(); this.equipment = new DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn(); this.operate = new DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn(); this.operate_time = new DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn(); this.username = new DevComponents.DotNetBar.Controls.DataGridViewLabelXColumn(); this.panelEx1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.bar1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewX1)).BeginInit(); this.SuspendLayout(); // // panelEx1 // this.panelEx1.CanvasColor = System.Drawing.SystemColors.Control; this.panelEx1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; this.panelEx1.Controls.Add(this.btn_query); this.panelEx1.Controls.Add(this.label1); this.panelEx1.Controls.Add(this.dateTimePicker_end); this.panelEx1.Controls.Add(this.dateTimePicker_start); this.panelEx1.Controls.Add(this.labelX1); this.panelEx1.Dock = System.Windows.Forms.DockStyle.Top; this.panelEx1.Location = new System.Drawing.Point(0, 0); this.panelEx1.Name = "panelEx1"; this.panelEx1.Size = new System.Drawing.Size(634, 34); this.panelEx1.Style.Alignment = System.Drawing.StringAlignment.Center; this.panelEx1.Style.BackColor1.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground; this.panelEx1.Style.BackColor2.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2; this.panelEx1.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine; this.panelEx1.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder; this.panelEx1.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText; this.panelEx1.Style.GradientAngle = 90; this.panelEx1.TabIndex = 2; // // btn_query // this.btn_query.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; this.btn_query.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; this.btn_query.Location = new System.Drawing.Point(341, 4); this.btn_query.Name = "btn_query"; this.btn_query.Size = new System.Drawing.Size(75, 23); this.btn_query.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; this.btn_query.TabIndex = 3; this.btn_query.Text = "查询"; this.btn_query.Click += new System.EventHandler(this.btn_query_Click); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(195, 9); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(11, 12); this.label1.TabIndex = 2; this.label1.Text = "-"; // // dateTimePicker_end // this.dateTimePicker_end.Location = new System.Drawing.Point(212, 5); this.dateTimePicker_end.Name = "dateTimePicker_end"; this.dateTimePicker_end.Size = new System.Drawing.Size(123, 21); this.dateTimePicker_end.TabIndex = 1; // // dateTimePicker_start // this.dateTimePicker_start.Location = new System.Drawing.Point(66, 5); this.dateTimePicker_start.Name = "dateTimePicker_start"; this.dateTimePicker_start.Size = new System.Drawing.Size(123, 21); this.dateTimePicker_start.TabIndex = 1; // // labelX1 // this.labelX1.AutoSize = true; // // // this.labelX1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square; this.labelX1.Location = new System.Drawing.Point(10, 7); this.labelX1.Name = "labelX1"; this.labelX1.Size = new System.Drawing.Size(50, 16); this.labelX1.TabIndex = 0; this.labelX1.Text = "日期范围"; // // bar1 // this.bar1.AntiAlias = true; this.bar1.Dock = System.Windows.Forms.DockStyle.Bottom; this.bar1.Items.AddRange(new DevComponents.DotNetBar.BaseItem[] { this.lab_page_msg, this.btn_page_first, this.btn_page_pre, this.combo_page_num, this.btn_page_next, this.btn_page_last}); this.bar1.Location = new System.Drawing.Point(0, 351); this.bar1.Name = "bar1"; this.bar1.Size = new System.Drawing.Size(634, 28); this.bar1.Stretch = true; this.bar1.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; this.bar1.TabIndex = 3; this.bar1.TabStop = false; this.bar1.Text = "bar1"; // // lab_page_msg // this.lab_page_msg.Name = "lab_page_msg"; this.lab_page_msg.PaddingLeft = 30; this.lab_page_msg.PaddingRight = 30; this.lab_page_msg.Text = "labelItem1"; // // btn_page_first // this.btn_page_first.Name = "btn_page_first"; this.btn_page_first.Text = "|<首页"; this.btn_page_first.Click += new System.EventHandler(this.btn_page_first_Click); // // btn_page_pre // this.btn_page_pre.Name = "btn_page_pre"; this.btn_page_pre.Text = "<上一页"; this.btn_page_pre.Click += new System.EventHandler(this.btn_page_pre_Click); // // combo_page_num // this.combo_page_num.DropDownHeight = 106; this.combo_page_num.ItemHeight = 17; this.combo_page_num.Name = "combo_page_num"; this.combo_page_num.SelectedIndexChanged += new System.EventHandler(this.combo_page_num_SelectedIndexChanged); // // btn_page_next // this.btn_page_next.Name = "btn_page_next"; this.btn_page_next.Text = "下一页>"; this.btn_page_next.Click += new System.EventHandler(this.btn_page_next_Click); // // btn_page_last // this.btn_page_last.Name = "btn_page_last"; this.btn_page_last.Text = "尾页>|"; this.btn_page_last.Click += new System.EventHandler(this.btn_page_last_Click); // // dataGridViewX1 // this.dataGridViewX1.AllowUserToAddRows = false; this.dataGridViewX1.AllowUserToDeleteRows = false; this.dataGridViewX1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridViewX1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridViewX1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dbid, this.rowno, this.equipment, this.operate, this.operate_time, this.username}); dataGridViewCellStyle34.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle34.BackColor = System.Drawing.SystemColors.Window; dataGridViewCellStyle34.ForeColor = System.Drawing.SystemColors.ControlText; dataGridViewCellStyle34.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle34.SelectionForeColor = System.Drawing.SystemColors.ControlText; dataGridViewCellStyle34.WrapMode = System.Windows.Forms.DataGridViewTriState.False; this.dataGridViewX1.DefaultCellStyle = dataGridViewCellStyle34; this.dataGridViewX1.Dock = System.Windows.Forms.DockStyle.Fill; this.dataGridViewX1.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(170)))), ((int)(((byte)(170)))), ((int)(((byte)(170))))); this.dataGridViewX1.Location = new System.Drawing.Point(0, 34); this.dataGridViewX1.Name = "dataGridViewX1"; this.dataGridViewX1.ReadOnly = true; this.dataGridViewX1.RowTemplate.Height = 23; this.dataGridViewX1.Size = new System.Drawing.Size(634, 317); this.dataGridViewX1.TabIndex = 4; // // dbid // this.dbid.DataPropertyName = "dbid"; this.dbid.HeaderText = "dbid"; this.dbid.Name = "dbid"; this.dbid.ReadOnly = true; this.dbid.Visible = false; // // rowno // this.rowno.DataPropertyName = "rowno"; this.rowno.HeaderText = "rowno"; this.rowno.Name = "rowno"; this.rowno.ReadOnly = true; this.rowno.Visible = false; // // equipment // this.equipment.DataPropertyName = "equipment"; this.equipment.HeaderText = "设备"; this.equipment.Name = "equipment"; this.equipment.ReadOnly = true; this.equipment.TextAlignment = System.Drawing.StringAlignment.Center; // // operate // this.operate.DataPropertyName = "operate"; this.operate.HeaderText = "操作"; this.operate.Name = "operate"; this.operate.ReadOnly = true; this.operate.TextAlignment = System.Drawing.StringAlignment.Center; // // operate_time // this.operate_time.DataPropertyName = "operate_time"; this.operate_time.HeaderText = "操作时间"; this.operate_time.Name = "operate_time"; this.operate_time.ReadOnly = true; this.operate_time.TextAlignment = System.Drawing.StringAlignment.Center; // // username // this.username.DataPropertyName = "username"; this.username.HeaderText = "操作人"; this.username.Name = "username"; this.username.ReadOnly = true; this.username.TextAlignment = System.Drawing.StringAlignment.Center; // // FrmLog // this.ClientSize = new System.Drawing.Size(634, 379); this.Controls.Add(this.dataGridViewX1); this.Controls.Add(this.bar1); this.Controls.Add(this.panelEx1); this.DoubleBuffered = true; this.Name = "FrmLog"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "设备日志查看"; this.Load += new System.EventHandler(this.FrmLog_Load); this.panelEx1.ResumeLayout(false); this.panelEx1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.bar1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewX1)).EndInit(); this.ResumeLayout(false); } private void btn_query_Click(object sender, EventArgs e) { currentpage = 1; reloadDataGrid(currentpage); } private void btn_page_first_Click(object sender, EventArgs e) { currentpage = 1; reloadDataGrid(currentpage); } private void btn_page_pre_Click(object sender, EventArgs e) { currentpage--; if (currentpage <= 0) { currentpage = 1; } reloadDataGrid(currentpage); } private void btn_page_next_Click(object sender, EventArgs e) { currentpage++; if (currentpage > lastpage) { currentpage = lastpage; } reloadDataGrid(currentpage); } private void btn_page_last_Click(object sender, EventArgs e) { currentpage = lastpage; reloadDataGrid(currentpage); } private void combo_page_num_SelectedIndexChanged(object sender, EventArgs e) { if (!String.IsNullOrEmpty(combo_page_num.Text.Trim())) { currentpage = int.Parse(combo_page_num.Text.Trim()); reloadDataGrid(currentpage); } } } }