📄 employeeframe.cs
字号:
#region 命名空间...
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Data;
using System.Data.SqlClient;
#endregion
namespace WindowsApplication
{
#region 声明结构...用来赋值给treeview的Tag属性
public struct TreeNodeTag
{
public string department_ID;//节点记录的ID
public string department_Name;//节点的名称
public int department_IsExpand;//节点未/已展开过 ,未1,已2
public int department_Type;//节点的类型 //该值为0代表此节点是最高节点,该值为1代表此节点是部级单位类型,该值为2代表此节点是科室类型
}
#endregion
public class EmployeeFrame : System.Windows.Forms.Form
{
#region 控件声明...
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TreeView treeView;
private System.Windows.Forms.StatusBar emp_Status;
private System.Windows.Forms.StatusBarPanel emp_ID;
private System.Windows.Forms.StatusBarPanel emp_Date;
private System.Windows.Forms.StatusBarPanel emp_Time;
private System.Windows.Forms.StatusBarPanel emp_Operator;
private System.Windows.Forms.StatusBarPanel emp_statusBar;
private System.Windows.Forms.ImageList imageList;
private System.Windows.Forms.Timer currentTime;
private System.Windows.Forms.DataGrid dataGird;
private System.ComponentModel.IContainer components;
#endregion
#region 构造函数
public EmployeeFrame()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region 变量定义
private string searchDepartmentName="Select distinct 部门名称 from Department";
private ConnectionData conn=new ConnectionData();
private DataSet dsDataSet=new DataSet();
private DataTable dsTable=new DataTable();
#endregion
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(EmployeeFrame));
this.treeView = new System.Windows.Forms.TreeView();
this.imageList = new System.Windows.Forms.ImageList(this.components);
this.label1 = new System.Windows.Forms.Label();
this.emp_Status = new System.Windows.Forms.StatusBar();
this.emp_ID = new System.Windows.Forms.StatusBarPanel();
this.emp_Date = new System.Windows.Forms.StatusBarPanel();
this.emp_Time = new System.Windows.Forms.StatusBarPanel();
this.emp_Operator = new System.Windows.Forms.StatusBarPanel();
this.emp_statusBar = new System.Windows.Forms.StatusBarPanel();
this.dataGird = new System.Windows.Forms.DataGrid();
this.currentTime = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.emp_ID)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.emp_Date)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.emp_Time)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.emp_Operator)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.emp_statusBar)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataGird)).BeginInit();
this.SuspendLayout();
//
// treeView
//
this.treeView.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.treeView.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
this.treeView.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.treeView.ImageList = this.imageList;
this.treeView.Location = new System.Drawing.Point(0, 40);
this.treeView.Name = "treeView";
this.treeView.Size = new System.Drawing.Size(160, 432);
this.treeView.TabIndex = 0;
this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
//
// imageList
//
this.imageList.ImageSize = new System.Drawing.Size(16, 16);
this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
this.imageList.TransparentColor = System.Drawing.Color.Transparent;
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
this.label1.Cursor = System.Windows.Forms.Cursors.Hand;
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label1.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(776, 40);
this.label1.TabIndex = 1;
this.label1.Text = "部门信息";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// emp_Status
//
this.emp_Status.Cursor = System.Windows.Forms.Cursors.Hand;
this.emp_Status.Location = new System.Drawing.Point(0, 470);
this.emp_Status.Name = "emp_Status";
this.emp_Status.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.emp_ID,
this.emp_Date,
this.emp_Time,
this.emp_Operator,
this.emp_statusBar});
this.emp_Status.ShowPanels = true;
this.emp_Status.Size = new System.Drawing.Size(776, 32);
this.emp_Status.TabIndex = 3;
//
// emp_ID
//
this.emp_ID.Icon = ((System.Drawing.Icon)(resources.GetObject("emp_ID.Icon")));
this.emp_ID.Text = "部门名称:";
this.emp_ID.Width = 150;
//
// emp_Date
//
this.emp_Date.Icon = ((System.Drawing.Icon)(resources.GetObject("emp_Date.Icon")));
this.emp_Date.Text = "日期:";
this.emp_Date.Width = 150;
//
// emp_Time
//
this.emp_Time.Icon = ((System.Drawing.Icon)(resources.GetObject("emp_Time.Icon")));
this.emp_Time.Text = "时间:";
this.emp_Time.Width = 150;
//
// emp_Operator
//
this.emp_Operator.Icon = ((System.Drawing.Icon)(resources.GetObject("emp_Operator.Icon")));
this.emp_Operator.Text = "操作员:";
this.emp_Operator.Width = 150;
//
// emp_statusBar
//
this.emp_statusBar.Icon = ((System.Drawing.Icon)(resources.GetObject("emp_statusBar.Icon")));
this.emp_statusBar.Text = "部门状态:";
this.emp_statusBar.Width = 200;
//
// dataGird
//
this.dataGird.AlternatingBackColor = System.Drawing.Color.GhostWhite;
this.dataGird.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.dataGird.BackColor = System.Drawing.Color.GhostWhite;
this.dataGird.BackgroundColor = System.Drawing.Color.Lavender;
this.dataGird.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.dataGird.CaptionBackColor = System.Drawing.Color.RoyalBlue;
this.dataGird.CaptionForeColor = System.Drawing.Color.White;
this.dataGird.CaptionVisible = false;
this.dataGird.DataMember = "";
this.dataGird.FlatMode = true;
this.dataGird.Font = new System.Drawing.Font("Tahoma", 8F);
this.dataGird.ForeColor = System.Drawing.Color.MidnightBlue;
this.dataGird.GridLineColor = System.Drawing.Color.RoyalBlue;
this.dataGird.HeaderBackColor = System.Drawing.Color.MidnightBlue;
this.dataGird.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
this.dataGird.HeaderForeColor = System.Drawing.Color.Lavender;
this.dataGird.LinkColor = System.Drawing.Color.Teal;
this.dataGird.Location = new System.Drawing.Point(160, 40);
this.dataGird.Name = "dataGird";
this.dataGird.ParentRowsBackColor = System.Drawing.Color.Lavender;
this.dataGird.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
this.dataGird.ReadOnly = true;
this.dataGird.SelectionBackColor = System.Drawing.Color.Teal;
this.dataGird.SelectionForeColor = System.Drawing.Color.PaleGreen;
this.dataGird.Size = new System.Drawing.Size(616, 432);
this.dataGird.TabIndex = 2;
//
// currentTime
//
this.currentTime.Enabled = true;
this.currentTime.Interval = 1000;
this.currentTime.Tick += new System.EventHandler(this.currentTime_Tick);
//
// EmployeeFrame
//
this.AutoScaleBaseSize = new System.Drawing.Size(7, 14);
this.BackColor = System.Drawing.SystemColors.Info;
this.ClientSize = new System.Drawing.Size(776, 502);
this.Controls.Add(this.emp_Status);
this.Controls.Add(this.dataGird);
this.Controls.Add(this.label1);
this.Controls.Add(this.treeView);
this.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "EmployeeFrame";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "EmployeeFrame";
this.Load += new System.EventHandler(this.EmployeeFrame_Load);
((System.ComponentModel.ISupportInitialize)(this.emp_ID)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.emp_Date)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.emp_Time)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.emp_Operator)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.emp_statusBar)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGird)).EndInit();
this.ResumeLayout(false);
}
#endregion
#region 初始化节点函数
#endregion
#region 变量初始化...
private void EmployeeFrame_Load(object sender, System.EventArgs e)
{
#region 初始化DataGrid控件...
DataTable departmentTable=new DataTable();
departmentTable=ExcuteSql("select * from Department","Department");
this.dataGird.DataSource=departmentTable;
#endregion
#region 初始化TreeView控件
#region //为结构TreeNodeTag分配内存
TreeNodeTag tagTemp=new TreeNodeTag();
#endregion
#region 根节点...
TreeNode rootNode=new TreeNode("部门");
#endregion
try
{
dsDataSet=conn.ExcuteDataSetResult(searchDepartmentName,"Department");
dsTable=dsDataSet.Tables[0];
for(int i=0;i<dsTable.Rows.Count;i++)
{
rootNode.Nodes.Add(dsTable.Rows[i][0].ToString().Trim());
rootNode.ImageIndex=2;
rootNode.SelectedImageIndex=2;
}
this.treeView.Nodes.Add(rootNode);
}
catch(Exception exel)
{
MessageBox.Show(this,exel.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
#endregion
#region 初始化工具栏上的信息...
this.emp_Date.Text="日期:"+System.DateTime.Now.ToLongDateString();
this.emp_Operator.Text="操作员:"+landFrame.strName;
this.emp_ID.Text="部门名称:技术部";
#endregion
}
#endregion
#region 列表事件...
private void treeView_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
}
#endregion
#region DataFunction
private DataTable ExcuteSql(string strSql,string tableName)
{
DataSet dsSet=new DataSet();
DataTable dsTable=new DataTable();
try
{
dsSet=conn.ExcuteDataSetResult(strSql,tableName);
dsTable=dsSet.Tables[0];
}
catch(Exception eles)
{
MessageBox.Show(this,eles.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
return dsTable;
}
#endregion
#region 处理时间事件...
private void currentTime_Tick(object sender, System.EventArgs e)
{
this.emp_Time.Text="时间"+System.DateTime.Now.ToLongTimeString().Trim();
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -