📄 check.cs
字号:
}
}
private void btnCheckIn_Click(object sender, System.EventArgs e)
{
string checktype;
System.DateTime checktime=DateTime.Now;
if(checktime.Hour<8)
checktype="按时";
else if(8<checktime.Hour&checktime.Hour<10)
checktype="迟到";
else
checktype="缺勤";
this.commandStr="insert into CheckInRecord(EmployeeID,CheckType) values("+"'"+this.textEmployeeID1.Text+"',"+"'"+checktype+"'"+")";
this.Command1.CommandText=this.commandStr;
try
{
this.Connection1.Open();
this.Command1.ExecuteNonQuery();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
this.Connection1.Close();
}
DataRow newCheckIn=this.CheckInTable.NewRow();
newCheckIn["EmployeeID"]=this.textEmployeeID1.Text;
newCheckIn["CheckType"]=checktype;
newCheckIn["Date"]=DateTime.Now.ToString();
this.CheckInTable.Rows.Add(newCheckIn);
this.textEmployeeID1.Clear();
this.dataGrid1.Refresh();
}
private void btnCheckOut_Click(object sender, System.EventArgs e)
{
string checktype;
System.DateTime checktime=DateTime.Now;
if(checktime.Hour>=18)
checktype="按时";
else if(14<checktime.Hour&checktime.Hour<18)
checktype="早退";
else
checktype="缺勤";
this.commandStr="insert into CheckOutRecord(EmployeeID,CheckType) values("+"'"+this.textEmployeeID2.Text+"',"+"'"+checktype+"'"+")";
this.Command1.CommandText=this.commandStr;
try
{
this.Connection1.Open();
this.Command1.ExecuteNonQuery();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
this.Connection1.Close();
}
DataRow newCheckOut=this.CheckOutTable.NewRow();
newCheckOut["EmployeeID"]=this.textEmployeeID2.Text;
newCheckOut["CheckType"]=checktype;
newCheckOut["Date"]=DateTime.Now.ToString();
this.CheckOutTable.Rows.Add(newCheckOut);
this.textEmployeeID2.Clear();
this.dataGrid2.Refresh();
}
private void btnCheckInSearch_Click(object sender, System.EventArgs e)
{
try
{
this.Connection1.Open();
this.CheckInDataView.Table=this.DataSetViewCheckIn.Tables["View_CheckInRecord"];
this.CheckInDataView.RowFilter=this.CheckInStr_Made();
this.dataGrid3.DataSource=this.CheckInDataView;
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
this.Connection1.Close();
}
if(this.CheckInDataView.Count==0)
MessageBox.Show("没有符合查询条件的记录","没有记录",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textEmployeeID3.Clear();
this.comboCheckInType.Text="";
this.comboInDepartment.Text="";
this.checkBox1.Checked=false;
}
private string CheckInStr_Made()
{
string searchStr=null;
bool first=true;
if(this.textEmployeeID3.Text!="")
{
searchStr="EmployeeID="+"'"+this.textEmployeeID3.Text+"'";
first=false;
this.selectStrViewCheckIn="职工号:"+this.textEmployeeID3.Text;
}
if(this.comboCheckInType.Text!="")
{
if(first)
{
searchStr="CheckType="+"'"+this.comboCheckInType.Text+"'";
first=false;
this.selectStrViewCheckIn="签到类型:"+this.comboCheckInType.Text;
}
else
{
searchStr=searchStr+" and CheckType="+"'"+this.comboCheckInType.Text+"'";
this.selectStrViewCheckIn+=" 签到类型:"+this.comboCheckInType.Text;
}
}
if(this.comboInDepartment.Text!="")
{
if(first)
{
searchStr="Department="+"'"+this.comboInDepartment.Text+"'";
first=false;
this.selectStrViewCheckIn="部门:"+this.comboInDepartment.Text;
}
else
{
searchStr=searchStr+" and Department="+"'"+this.comboInDepartment.Text+"'";
this.selectStrViewCheckIn+="部门:"+this.comboInDepartment.Text;
}
}
if(this.checkBox1.Checked)
{
if(first)
{
searchStr="Date>"+"'"+this.dateTimePicker3.Text+"'"+" and "+"Date<"+"'"+this.dateTimePicker4.Text+"'" ;
this.selectStrViewCheckIn="日期:在"+this.dateTimePicker3.Text+"和"+this.dateTimePicker4.Text+"之间";
}
else
{
searchStr=searchStr+" and (Date>"+"'"+this.dateTimePicker3.Text+"'"+" and "+"Date<"+"'"+this.dateTimePicker4.Text+"')";
this.selectStrViewCheckIn+=" 日期:在"+this.dateTimePicker3.Text+"和"+this.dateTimePicker4.Text+"之间";
}
}
return searchStr;
}
private void btnCheckInCancel_Click(object sender, System.EventArgs e)
{
this.textEmployeeID3.Clear();
this.comboCheckInType.Text="";
this.checkBox1.Checked=false;
}
private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
if(this.checkBox1.Checked)
{
this.dateTimePicker3.Enabled=true;
this.dateTimePicker4.Enabled=true;
}
else
{
this.dateTimePicker3.Enabled=false;
this.dateTimePicker4.Enabled=false;
}
}
private void btnCheckInExport_Click(object sender, System.EventArgs e)
{
Excel.Application myExcel = new Excel.Application ( ) ;
myExcel.Application.Workbooks.Add ( true ) ;
//让Excel文件可见
myExcel.Visible=true;
//第一行为报表名称
myExcel.Cells[1,2]="签到查询记录";
myExcel.Cells[2,1]="查询条件:";
myExcel.Cells[2,2]=this.selectStrViewCheckIn;
myExcel.Cells[3,3]="'"+DateTime.Now.ToShortDateString().ToString();
//逐行写入数据,
for(int i=0;i<5;i++)
{
myExcel.Cells[4,1+i]=this.myData[i];
}
//myExcel.Cells[3,1]="职工号码";
//myExcel.Cells[3,2]="职工姓名";
//myExcel.Cells[3,3]="签到日前";
//myExcel.Cells[3,4]="是否按时";
for(int i=0;i<this.CheckInDataView.Count;i++)
{
for(int j=0;j<5;j++)
{
//以单引号开头,表示该单元格为纯文本
myExcel.Cells[6+i,1+j]="'"+this.CheckInDataView[i][j].ToString();
}
}
}
private void btnCheckOutExport_Click(object sender, System.EventArgs e)
{
Excel.Application myExcel = new Excel.Application ( ) ;
myExcel.Application.Workbooks.Add ( true ) ;
//让Excel文件可见
myExcel.Visible=true;
//第一行为报表名称
myExcel.Cells[1,2]="签到查询记录";
myExcel.Cells[2,3]="'"+DateTime.Now.ToShortDateString().ToString();
//逐行写入数据,
for(int i=0;i<5;i++)
{
myExcel.Cells[3,1+i]=this.myData[i];
}
//myExcel.Cells[3,1]="职工号码";
//myExcel.Cells[3,2]="职工姓名";
//myExcel.Cells[3,3]="签到日前";
//myExcel.Cells[3,4]="是否按时";
for(int i=0;i<this.CheckOutDataView.Count;i++)
{
for(int j=0;j<5;j++)
{
//以单引号开头,表示该单元格为纯文本
myExcel.Cells[5+i,1+j]="'"+this.CheckOutDataView[i][j].ToString();
}
}
}
private void btnCheckOutCancel_Click(object sender, System.EventArgs e)
{
this.textEmployeeID4.Clear();
this.comboCheckOutType.Text="";
this.checkBox2.Checked=false;
}
private void checkBox2_CheckedChanged(object sender, System.EventArgs e)
{
if(this.checkBox2.Checked)
{
this.dateTimePicker1.Enabled=true;
this.dateTimePicker2.Enabled=true;
}
else
{
this.dateTimePicker1.Enabled=false;
this.dateTimePicker2.Enabled=false;
}
}
private void btnCheckOutSearch_Click(object sender, System.EventArgs e)
{
try
{
this.Connection1.Open();
//this.dataAdapterCheckOut.Fill(this.DataSetCheckOutRecord,"View_CheckOutRecord");
this.CheckOutDataView.Table=this.DataSetViewCheckOut.Tables["View_CheckOutRecord"];
CheckOutDataView.RowFilter=this.CheckOutStr_Made();
dataGrid4.DataSource=this.CheckOutDataView;
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
this.Connection1.Close();
}
if(CheckOutDataView.Count==0)
MessageBox.Show("没有符合查询条件的记录","没有记录",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textEmployeeID4.Clear();
this.comboCheckOutType.Text="";
this.comboOutDepartment.Text="";
this.checkBox2.Checked=false;
this.dataGrid4.Refresh();
}
private string CheckOutStr_Made()
{
string searchStr=null;
bool first=true;
if(this.textEmployeeID4.Text!="")
{
searchStr="EmployeeID="+"'"+this.textEmployeeID4.Text+"'";
first=false;
}
if(this.comboCheckOutType.Text!="")
{
if(first)
{
searchStr="CheckType="+"'"+this.comboCheckOutType.Text+"'";
first=false;
}
else
{
searchStr=searchStr+" and CheckType="+"'"+this.comboCheckOutType.Text+"'";
}
}
if(this.comboOutDepartment.Text!="")
{
if(first)
{
searchStr="Department="+"'"+this.comboOutDepartment.Text+"'";
first=false;
}
else
{
searchStr=searchStr+" and Department="+"'"+this.comboOutDepartment.Text+"'";
}
}
if(this.checkBox2.Checked)
{
if(first)
searchStr="Date>"+"'"+this.dateTimePicker1.Text+"'"+" and "+"Date<"+"'"+this.dateTimePicker2.Text+"'" ;
else
searchStr=searchStr+" and (Date>"+"'"+this.dateTimePicker1.Text+"'"+" and "+"Date<"+"'"+this.dateTimePicker2.Text+"')";
}
return searchStr;
}
public void ErrorHandle(System.Exception E)
{
MessageBox.Show(E.ToString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -