📄 frmemployees.cs
字号:
this.comboBoxEx1.Name = "comboBoxEx1";
this.comboBoxEx1.Size = new System.Drawing.Size(56, 22);
this.comboBoxEx1.TabIndex = 7;
this.comboBoxEx1.Text = "男";
//
// cboMan
//
this.cboMan.Text = "男";
//
// cboWomen
//
this.cboWomen.Text = "女";
//
// labelX3
//
this.labelX3.Location = new System.Drawing.Point(8, 48);
this.labelX3.Name = "labelX3";
this.labelX3.Size = new System.Drawing.Size(56, 23);
this.labelX3.TabIndex = 6;
this.labelX3.Text = "地址:";
//
// labelX2
//
this.labelX2.Location = new System.Drawing.Point(200, 48);
this.labelX2.Name = "labelX2";
this.labelX2.Size = new System.Drawing.Size(75, 23);
this.labelX2.TabIndex = 4;
this.labelX2.Text = "部门名称:";
//
// textBoxX1
//
this.textBoxX1.AutoSize = false;
//
// textBoxX1.Border
//
this.textBoxX1.Border.Class = "TextBoxBorder";
this.textBoxX1.Location = new System.Drawing.Point(80, 8);
this.textBoxX1.Name = "textBoxX1";
this.textBoxX1.Size = new System.Drawing.Size(104, 21);
this.textBoxX1.TabIndex = 3;
//
// labelX1
//
this.labelX1.Location = new System.Drawing.Point(8, 8);
this.labelX1.Name = "labelX1";
this.labelX1.Size = new System.Drawing.Size(75, 23);
this.labelX1.TabIndex = 2;
this.labelX1.Text = "员工姓名:";
//
// dataGrid1
//
this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.ActiveCaptionText;
this.dataGrid1.CaptionBackColor = System.Drawing.Color.LightSkyBlue;
this.dataGrid1.DataMember = "";
this.dataGrid1.GridLineColor = System.Drawing.Color.Orange;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.HotTrack;
this.dataGrid1.Location = new System.Drawing.Point(0, 80);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(616, 240);
this.dataGrid1.TabIndex = 1;
this.toolTip1.SetToolTip(this.dataGrid1, "双击一条记录进行操作");
this.dataGrid1.Click += new System.EventHandler(this.dataGrid1_Click);
this.dataGrid1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.dataGrid1_MouseMove);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 324);
this.statusBar1.Name = "statusBar1";
this.statusBar1.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(612, 32);
this.statusBar1.TabIndex = 0;
this.statusBar1.Text = "statusBar1";
this.toolTip1.SetToolTip(this.statusBar1, "双击一条记录进行操作");
//
// toolTip1
//
this.toolTip1.ShowAlways = true;
//
// printDocument1
//
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
// printPreviewDialog1
//
this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
this.printPreviewDialog1.Document = this.printDocument1;
this.printPreviewDialog1.Enabled = true;
this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
this.printPreviewDialog1.Location = new System.Drawing.Point(487, 17);
this.printPreviewDialog1.MinimumSize = new System.Drawing.Size(375, 250);
this.printPreviewDialog1.Name = "printPreviewDialog1";
this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
this.printPreviewDialog1.Visible = false;
//
// pageSetupDialog1
//
this.pageSetupDialog1.Document = this.printDocument1;
//
// frmEmployees
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(616, 421);
this.Controls.Add(this.panel1);
this.Controls.Add(this.toolBar1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "frmEmployees";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "员工资料增加";
this.Load += new System.EventHandler(this.frmEmployees_Load);
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void frmEmployees_Load(object sender, System.EventArgs e)
{
this.toolBar1.Buttons[1].Enabled=false;
//员工信息
try
{
EmployeeBS = new EmployeeBS();
ds=EmployeeBS.select();
this.dataGrid1.DataSource=ds;
this.dataGrid1.DataMember="Employee";
da=new SqlDataAdapter("select * from Branch",this.con);
da.Fill(ds,"Branch");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
private void dataGrid1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.toolTip1.SetToolTip(this.dataGrid1,"单击一条记录进行修改操作");
}
//工具拦的操作
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch(this.toolBar1.Buttons.IndexOf(e.Button))
{
case 0:this.textBoxX1.Text="";this.comboBoxEx3.Text="";
this.textBoxX1.Focus();this.textBoxX3.Text="";
this.textBoxX4.Text="";this.textBoxX5.Text="";
this.toolBar1.Buttons[1].Enabled=true;
this.EID=0;
break;
case 1:
if(this.textBoxX1.Text=="")
{
MessageBox.Show("员工姓名不能为空");
return;
}
else if(this.comboBoxEx3.Text=="")
{
MessageBox.Show("部门名称不能为空");
return;
}
else
{
if(EID==0)
{
for(int i=0;i<ds.Tables["Branch"].Rows.Count;i++)
{
if(ds.Tables["Branch"].Rows[i][1].Equals(this.comboBoxEx3.Text))
{
BranchID=ds.Tables["Branch"].Rows[i][0].ToString();
}
}
this.EmployeeBE=new Employee();
this.EmployeeBS=new EmployeeBS();
EmployeeBE.EmployeeName=this.textBoxX1.Text;
EmployeeBE.EmployeeSex=this.comboBoxEx1.Text;
EmployeeBE.EmployeeAge=Convert.ToInt32(this.textBoxX5.Text);
EmployeeBE.EmployeeEDU=this.comboBoxEx2.Text;
EmployeeBE.EmployeeAddress=this.textBoxX4.Text;
EmployeeBE.BranchName=BranchID;
EmployeeBE.Reamark=this.textBoxX3.Text;
EmployeeBS.employee=EmployeeBE;
try
{
EmployeeBS.insert();
MessageBox.Show("保存成功");
this.toolBar1.Buttons[1].Enabled=false;
EmployeeBS = new EmployeeBS();
ds=EmployeeBS.select();
this.dataGrid1.DataSource=ds;
this.dataGrid1.DataMember="Employee";
this.textBoxX1.Text="";
this.textBoxX3.Text="";
this.textBoxX4.Text="";
this.textBoxX5.Text="";
this.comboBoxEx2.Text="";
this.comboBoxEx3.Text="";
this.EID=0;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
else
{
for(int i=0;i<ds.Tables["Branch"].Rows.Count;i++)
{
if(ds.Tables["Branch"].Rows[i][1].Equals(this.comboBoxEx3.Text))
{
BranchID=ds.Tables["Branch"].Rows[i][0].ToString();
}
}
this.EmployeeBE=new Employee();
this.EmployeeBS=new EmployeeBS();
EmployeeBE.EmployeeName=this.textBoxX1.Text;
EmployeeBE.EmployeeSex=this.comboBoxEx1.Text;
EmployeeBE.EmployeeAge=Convert.ToInt32(this.textBoxX5.Text);
EmployeeBE.EmployeeEDU=this.comboBoxEx2.Text;
EmployeeBE.EmployeeAddress=this.textBoxX4.Text;
EmployeeBE.BranchName=BranchID;
EmployeeBE.Reamark=this.textBoxX3.Text;
EmployeeBE.EmployeeID=this.EID;
EmployeeBS.employee=EmployeeBE;
try
{
EmployeeBS.update();
MessageBox.Show("修改成功");
this.toolBar1.Buttons[1].Enabled=false;
this.textBoxX1.Text="";
this.textBoxX3.Text="";
this.textBoxX4.Text="";
this.textBoxX5.Text="";
this.comboBoxEx2.Text="";
this.comboBoxEx3.Text="";
EmployeeBS = new EmployeeBS();
ds=EmployeeBS.select();
this.dataGrid1.DataSource=ds;
this.dataGrid1.DataMember="Employee";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}
break;//保存
case 2:
this.toolBar1.Buttons[1].Enabled=true;
if(this.textBoxX1.Text !="")
{
this.textBoxX1.Focus();this.textBoxX1.SelectAll();
this.toolBar1.Buttons[1].Enabled=true;
}
else
{
MessageBox.Show("请单击一条记录");
return;
}
break;
// case 3:
// int EmployeeID=Convert.ToInt32(this.ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][7]);
// EmployeeBE.EmployeeID=EmployeeID;
// EmployeeBS.employee=EmployeeBE;
// try
// {
// EmployeeBS.delete();
// MessageBox.Show("删除成功");
// EmployeeBS = new EmployeeBS();
// this.ds=EmployeeBS.select();
// this.dataGrid1.DataSource=ds;
// this.dataGrid1.DataMember="Employee";
// }
// catch(Exception ex)
// {
// MessageBox.Show(ex.Message);
// }
// break;//删除
case 3:
this.printPreviewDialog1.ShowDialog();
break;//打印
case 4:this.Close();break;
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font objFont = new Font("Tahoma",11,FontStyle.Underline);
Brush objBrush = Brushes.Black;
Pen objPen = new Pen(objBrush);
objPen.Width = 2;
//向打印预缆窗口中添加内容
int nLeft = this.pageSetupDialog1.PageSettings.Margins.Left;
int nTop = this.pageSetupDialog1.PageSettings.Margins.Top;
int nWidth = this.pageSetupDialog1.PageSettings.PaperSize.Width-
(this.pageSetupDialog1.PageSettings.Margins.Left +
this.pageSetupDialog1.PageSettings.Margins.Right);
int nHeight = this.pageSetupDialog1.PageSettings.PaperSize.Height-
(this.pageSetupDialog1.PageSettings.Margins.Top +
this.pageSetupDialog1.PageSettings.Margins.Bottom);
//打印出表头
e.Graphics.DrawString("员工信息",new Font("Garamond",40,FontStyle.Bold),Brushes.Blue,nLeft+200,nTop+10);
e.Graphics.DrawString("员工姓名",objFont,objBrush,nLeft+10,nTop+60);
e.Graphics.DrawString("部门名称",objFont,objBrush,nLeft+100,nTop+60);
e.Graphics.DrawString("员工备注",objFont,objBrush,nLeft+180,nTop+60);
e.Graphics.DrawString("性别",objFont,objBrush,nLeft+300,nTop+60);
e.Graphics.DrawString("年龄",objFont,objBrush,nLeft+420,nTop+60);
e.Graphics.DrawString("学历",objFont,objBrush,nLeft+500,nTop+60);
e.Graphics.DrawString("地址",objFont,objBrush,nLeft+600,nTop+60);
e.Graphics.DrawString("员工ID",objFont,objBrush,nLeft+650,nTop+60);
//打印具体数据
try
{
HouseBS.EmployeeBS employee=new EmployeeBS();
this.ds=employee.select();
int nLine=1;
foreach( DataRow rows in this.ds.Tables[0].Rows)
{
e.Graphics.DrawString(rows[0].ToString(),objFont,objBrush,nLeft+10,nTop+60+nLine*30);
e.Graphics.DrawString(rows[1].ToString(),objFont,objBrush,nLeft+100,nTop+60+nLine*30);
e.Graphics.DrawString(rows[2].ToString(),objFont,objBrush,nLeft+180,nTop+60+nLine*30);
e.Graphics.DrawString(rows[3].ToString(),objFont,objBrush,nLeft+300,nTop+60+nLine*30);
e.Graphics.DrawString(rows[4].ToString(),objFont,objBrush,nLeft+420,nTop+60+nLine*30);
e.Graphics.DrawString(rows[5].ToString(),objFont,objBrush,nLeft+500,nTop+60+nLine*30);
e.Graphics.DrawString(rows[6].ToString(),objFont,objBrush,nLeft+600,nTop+60+nLine*30);
e.Graphics.DrawString(rows[7].ToString(),objFont,objBrush,nLeft+650,nTop+60+nLine*30);
nLine++;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void dataGrid1_Click(object sender, System.EventArgs e)
{
this.toolBar1.Buttons[1].Enabled=false;
string EName=Convert.ToString(this.ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][0]);
string BranchName=Convert.ToString(this.ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][1]);
string Reamark=Convert.ToString(this.ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][2]);
string EmployeeSex=Convert.ToString(this.ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][3]);
int EmployeeAge=Convert.ToInt32(this.ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][4]);
string EmployeeAddress=Convert.ToString(this.ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][6]);
string EmployeeEDU=Convert.ToString(this.ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][5]);
this.EID=Convert.ToInt32(this.ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][7]);
this.textBoxX1.Text=EName;
this.comboBoxEx3.Text=BranchName;
this.textBoxX3.Text=Reamark;
this.textBoxX4.Text=EmployeeAddress;
this.textBoxX5.Text=EmployeeAge.ToString();
this.comboBoxEx1.Text=EmployeeSex;
this.comboBoxEx2.Text=EmployeeEDU;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -