📄 emp_idframe.cs
字号:
#region 命名空间
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
#endregion
namespace WindowsApplication
{
#region 类
/// <summary>
/// Emp_IDFrame 的摘要说明。
/// </summary>
public class Emp_IDFrame : System.Windows.Forms.Form
{
#region 控件集合...
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.TextBox textEmp_ID;
private System.Windows.Forms.TextBox textEmp_Name;
private System.Windows.Forms.ComboBox textDateCom;
private System.ComponentModel.IContainer components;
#endregion
#region 变量定义
private string strSql="select 职工号,职工名称 from Employee";
#endregion
#region 数据库变量
private ConnectionData conn=new ConnectionData();
private System.Windows.Forms.Timer currentDate;
private System.Windows.Forms.Button btnHistory;
private DataTable tempTable=new DataTable();
#endregion
#region 构造函数
public Emp_IDFrame()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Emp_IDFrame));
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textEmp_ID = new System.Windows.Forms.TextBox();
this.textEmp_Name = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.textDateCom = new System.Windows.Forms.ComboBox();
this.btnOk = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.currentDate = new System.Windows.Forms.Timer(this.components);
this.btnHistory = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// 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.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(304, 32);
this.label1.TabIndex = 0;
this.label1.Text = "员工编号";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.ForeColor = System.Drawing.SystemColors.ControlText;
this.label2.Location = new System.Drawing.Point(16, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 23);
this.label2.TabIndex = 1;
this.label2.Text = "编号:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// textEmp_ID
//
this.textEmp_ID.ForeColor = System.Drawing.Color.Blue;
this.textEmp_ID.Location = new System.Drawing.Point(104, 48);
this.textEmp_ID.Name = "textEmp_ID";
this.textEmp_ID.Size = new System.Drawing.Size(144, 21);
this.textEmp_ID.TabIndex = 2;
this.textEmp_ID.Text = "";
//
// textEmp_Name
//
this.textEmp_Name.ForeColor = System.Drawing.Color.Blue;
this.textEmp_Name.Location = new System.Drawing.Point(104, 88);
this.textEmp_Name.Name = "textEmp_Name";
this.textEmp_Name.Size = new System.Drawing.Size(144, 21);
this.textEmp_Name.TabIndex = 4;
this.textEmp_Name.Text = "";
//
// label3
//
this.label3.ForeColor = System.Drawing.SystemColors.ControlText;
this.label3.Location = new System.Drawing.Point(16, 88);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 23);
this.label3.TabIndex = 3;
this.label3.Text = "姓名:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label4
//
this.label4.ForeColor = System.Drawing.SystemColors.ControlText;
this.label4.Location = new System.Drawing.Point(16, 128);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(80, 23);
this.label4.TabIndex = 5;
this.label4.Text = "日期:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// textDateCom
//
this.textDateCom.ForeColor = System.Drawing.Color.Blue;
this.textDateCom.Location = new System.Drawing.Point(104, 128);
this.textDateCom.Name = "textDateCom";
this.textDateCom.Size = new System.Drawing.Size(144, 20);
this.textDateCom.TabIndex = 6;
//
// btnOk
//
this.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOk.ForeColor = System.Drawing.SystemColors.ControlText;
this.btnOk.Location = new System.Drawing.Point(24, 176);
this.btnOk.Name = "btnOk";
this.btnOk.TabIndex = 7;
this.btnOk.Text = "确定(&O)";
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
this.btnOk.MouseEnter += new System.EventHandler(this.btnOk_MouseEnter);
this.btnOk.MouseLeave += new System.EventHandler(this.btnOk_MouseLeave);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCancel.ForeColor = System.Drawing.SystemColors.ControlText;
this.btnCancel.Location = new System.Drawing.Point(200, 176);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 8;
this.btnCancel.Text = "取消(&C)";
this.btnCancel.MouseEnter += new System.EventHandler(this.btnOk_MouseEnter);
this.btnCancel.MouseLeave += new System.EventHandler(this.btnOk_MouseLeave);
//
// currentDate
//
this.currentDate.Enabled = true;
this.currentDate.Interval = 1000;
this.currentDate.Tick += new System.EventHandler(this.currentDate_Tick);
//
// btnHistory
//
this.btnHistory.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnHistory.ForeColor = System.Drawing.SystemColors.ControlText;
this.btnHistory.Location = new System.Drawing.Point(112, 176);
this.btnHistory.Name = "btnHistory";
this.btnHistory.TabIndex = 9;
this.btnHistory.Text = "记录(&H)";
this.btnHistory.Click += new System.EventHandler(this.btnHistory_Click);
this.btnHistory.MouseEnter += new System.EventHandler(this.btnOk_MouseEnter);
this.btnHistory.MouseLeave += new System.EventHandler(this.btnOk_MouseLeave);
//
// Emp_IDFrame
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(298, 223);
this.Controls.Add(this.btnHistory);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.textDateCom);
this.Controls.Add(this.label4);
this.Controls.Add(this.textEmp_Name);
this.Controls.Add(this.label3);
this.Controls.Add(this.textEmp_ID);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Cursor = System.Windows.Forms.Cursors.Hand;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Emp_IDFrame";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Emp_IDFrame";
this.Load += new System.EventHandler(this.Emp_IDFrame_Load);
this.ResumeLayout(false);
}
#endregion
#region 事件初始化...
private void Emp_IDFrame_Load(object sender, System.EventArgs e)
{
try
{
#region 初始化变量...
tempTable=ExcuteSql(strSql,"Employee");
#endregion
#region TextID加1事件...
this.textEmp_ID.Text=AddOne();
#endregion
}
catch(Exception ele)
{
MessageBox.Show(this,ele.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region 检查是否为空的函数
private bool CheckNull()
{
if(this.textEmp_ID.Text.Equals(""))
{
MessageBox.Show(this,"职工号不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textEmp_ID.Focus();
return true;
}
else if(this.textEmp_Name.Text.Equals(""))
{
MessageBox.Show(this,"职工名称不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textEmp_Name.Focus();
return true;
}
else if(this.textDateCom.Text.Equals(""))
{
MessageBox.Show(this,"日期不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textDateCom.Focus();
return true;
}
else
{
bool f=false;
try
{
f=CheckEmpIDISNot(tempTable);
}
catch(Exception ese)
{
MessageBox.Show(this,ese.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
return f;
}
}
#endregion
#region 清空函数
private void ClearText()
{
this.textEmp_ID.Text="";
this.textEmp_Name.Text="";
this.textDateCom.Text="";
}
#endregion
#region 确定事件...
private void btnOk_Click(object sender, System.EventArgs e)
{
try
{
if(CheckNull().Equals(true))
{
return;
}
confireFunction(tempTable);
}
catch(Exception ele)
{
MessageBox.Show(this,ele.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region 确定函数...
private void confireFunction(DataTable tempName)
{
string insertStr="Insert Into Employee(职工号,职工名称) Values('"+this.textEmp_ID.Text.ToString()+"','"+this.textEmp_Name.Text.ToString()+"')";
int k=conn.ExcuteStrSql(insertStr);
if(k>0)
{
MessageBox.Show(this,"操作成功啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.ClearText();
this.textEmp_ID.Focus();
#region TextID加1事件...
this.textEmp_ID.Text=AddOne();
#endregion
}
else
{
MessageBox.Show(this,"操作失败啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region TextID加1的函数...
private String AddOne()
{
string temp="";
int MaxID=1;
try
{
string selectMaxStr="select max(职工号)职工号 from Employee";
object result=conn.ExcuteStrSqlObject(selectMaxStr);
if(!(result.Equals(System.DBNull.Value)))
{
MaxID=Convert.ToInt32(result)+1;
}
}
catch(Exception esle)
{
MessageBox.Show(this,esle.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
temp=MaxID.ToString().Trim();
return temp;
}
#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 currentDate_Tick(object sender, System.EventArgs e)
{
this.textDateCom.Text=System.DateTime.Now.ToLongDateString().Trim();
}
#endregion
#region 判断职工号是否存在的函数
private bool CheckEmpIDISNot(DataTable tempName)
{
for(int i=0;i<tempName.Rows.Count;i++)
{
if(tempName.Rows[i][0].ToString().Trim().Equals(this.textEmp_ID.Text.ToString().Trim()))
{
MessageBox.Show(this,"此号码已经存在啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textEmp_ID.Focus();
this.ClearText();
return true;
}
}
return false;
}
#endregion
#region 鼠标移动变化莫测...
private void btnOk_MouseLeave(object sender, System.EventArgs e)
{
Button button=(Button)sender;
button.FlatStyle=FlatStyle.Flat;
button.Font=new Font("宋体",9);
}
private void btnOk_MouseEnter(object sender, System.EventArgs e)
{
Button button=(Button)sender;
button.FlatStyle=FlatStyle.Standard;
button.Font=new Font("楷体",10);
}
#endregion
#region 添加历史记录事件...
private void btnHistory_Click(object sender, System.EventArgs e)
{
try
{
HistoryData(tempTable);
}
catch(Exception elses)
{
MessageBox.Show(this,elses.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
}
#endregion
#region 添加历史记录的函数...
private void HistoryData(DataTable tempName)
{
}
#endregion
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -