📄 checkinoutfrm.cs
字号:
private void CheckInOutfrm_Load(object sender, System.EventArgs e)
{
try
{
this.Connection1.Open();
this.dataAdapterViewCheckIn.Fill(this.DataSetViewCheckIn,"View_CheckInRecord");
this.dataAdapterViewCheckOut.Fill(this.DataSetViewCheckOut,"View_CheckOutRecord");
}
catch(Exception E)
{
MessageBox.Show(E.ToString());
}
finally
{
this.Connection1.Close();
}
this.Table_Fill();
this.DataSet_Fill();
}
private void DataSet_Fill()
{
this.dataGrid1.DataSource=this.CheckInTable;
this.dataGrid3.DataSource=this.CheckOutTable;
}
private void Table_Fill()
{
DataColumn EmployeeID=new DataColumn("教师编号");
EmployeeID.DataType=typeof(System.Char);
DataColumn CheckType=new DataColumn("签到类型",typeof(System.Char));
DataColumn Date=new DataColumn("签到时间",typeof(System.DateTime));
this.CheckInTable.Columns.Add("教师编号");
this.CheckInTable.Columns.Add("签到类型");
this.CheckInTable.Columns.Add("签到时间");
this.CheckOutTable.Columns.Add("教师编号");
this.CheckOutTable.Columns.Add("签离类型");
this.CheckOutTable.Columns.Add("签离时间");
}
private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
{
switch(this.tabControl1.SelectedIndex)
{
case 2:
this.DataSetViewCheckIn.Clear();
this.dataAdapterViewCheckIn.Fill(this.DataSetViewCheckIn,"View_CheckInRecord");
break;
case 3:
this.DataSetViewCheckOut.Clear();
this.dataAdapterViewCheckOut.Fill(this.DataSetViewCheckOut,"View_CheckOutRecord");
this.dataGrid4.Refresh();
break;
}
}
private void btnCheckIn_Click_1(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 教师签到(教师编号,签到类型,签到时间) values("+"'"+this.textTeacherID1.Text+"',"+"'"+checktype+"'"+","+"'"+checktime+"'"+")";
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["教师编号"]=this.textTeacherID1.Text;
newCheckIn["签到类型"]=checktype;
newCheckIn["签到时间"]=DateTime.Now.ToString();
this.CheckInTable.Rows.Add(newCheckIn);
this.textTeacherID1.Clear();
this.dataGrid1.Refresh();
}
private void btnCheckOut_Click_1(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 教师签离(教师编号,签离类型,签离时间) values("+"'"+this.textTeacherID3.Text+"',"+"'"+checktype+"'"+","+"'"+checktime+"'"+")";
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["教师编号"]=this.textTeacherID3.Text;
newCheckOut["签离类型"]=checktype;
newCheckOut["签离时间"]=DateTime.Now.ToString();
this.CheckOutTable.Rows.Add(newCheckOut);
this.textTeacherID3.Clear();
this.dataGrid3.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.dataGrid2.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.textTeacherID2.Clear();
this.comboCheckInType.Text="";
this.checkBox1.Checked=false;
}
private string CheckInStr_Made()
{
string searchStr=null;
bool first=true;
if(this.textTeacherID2.Text!="")
{
searchStr="教师编号="+"'"+this.textTeacherID2.Text+"'";
first=false;
}
if(this.comboCheckInType.Text!="")
{
if(first)
{
searchStr="签到类型="+"'"+this.comboCheckInType.Text+"'";
first=false;
}
else
{
searchStr=searchStr+" and 签到类型="+"'"+this.comboCheckInType.Text+"'";
}
}
if(this.checkBox1.Checked)
{
if(first)
{
searchStr="签到时间>"+"'"+this.dateTimePicker1.Text+"'"+" and "+"签到时间<"+"'"+this.dateTimePicker2.Text+"'" ;
}
else
{
searchStr=searchStr+" and (签到时间>"+"'"+this.dateTimePicker1.Text+"'"+" and "+"签到时间<"+"'"+this.dateTimePicker2.Text+"')";
}
}
return searchStr;
}
private void btnCheckOutSearch_Click(object sender, System.EventArgs e)
{
try
{
this.Connection1.Open();
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.textTeacherID4.Clear();
this.comboCheckOutType.Text="";
this.checkBox2.Checked=false;
this.dataGrid4.Refresh();
}
private string CheckOutStr_Made()
{
string searchStr=null;
bool first=true;
if(this.textTeacherID4.Text!="")
{
searchStr="教师编号="+"'"+this.textTeacherID4.Text+"'";
first=false;
}
if(this.comboCheckOutType.Text!="")
{
if(first)
{
searchStr="签离类型="+"'"+this.comboCheckOutType.Text+"'";
first=false;
}
else
{
searchStr=searchStr+" and 签离类型="+"'"+this.comboCheckOutType.Text+"'";
}
}
if(this.checkBox2.Checked)
{
if(first)
searchStr="签离时间>"+"'"+this.dateTimePicker3.Text+"'"+" and "+"签离时间<"+"'"+this.dateTimePicker4.Text+"'" ;
else
searchStr=searchStr+" and (签离时间>"+"'"+this.dateTimePicker3.Text+"'"+" and "+"签离时间<"+"'"+this.dateTimePicker4.Text+"')";
}
return searchStr;
}
private void btnCheckInCancel_Click(object sender, System.EventArgs e)
{
this.textTeacherID2.Clear();
this.comboCheckInType.Text="";
this.checkBox1.Checked=false;
}
private void btnCheckOutCancel_Click(object sender, System.EventArgs e)
{
this.textTeacherID4.Clear();
this.comboCheckOutType.Text="";
this.checkBox2.Checked=false;
}
public void ErrorHandle(System.Exception E)
{
MessageBox.Show(E.ToString());
}
private void textTeacherID3_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if(this.textTeacherID3.Text.Trim().Length ==0)
{
e.Cancel=true;
MessageBox.Show("教师编号不能为空");
}
else
{
bool isEqule = false;
for(int i=0;i<this.myTable.Rows.Count;i++)
{
this.myRow=myTable.Rows[i];
if(myRow[0].ToString().Trim() ==this.textTeacherID3.Text.ToString().Trim())
{
isEqule = true;
break;
}
}
if(isEqule== false)
{
MessageBox.Show ("你输入的教师编号不存在");
e.Cancel = true;
}
}
}
private void textTeacherID1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if(this.textTeacherID1.Text.Trim().Length ==0)
{
e.Cancel=true;
MessageBox.Show("教师编号不能为空");
}
else
{
bool isEqule = false;
for(int i=0;i<this.myTable.Rows.Count;i++)
{
this.myRow=myTable.Rows[i];
if(myRow[0].ToString().Trim() ==this.textTeacherID1.Text.ToString().Trim())
{
isEqule = true;
break;
}
}
if(isEqule== false)
{
MessageBox.Show ("你输入的教师编号不存在");
e.Cancel = true;
}
}
}
private void checkBox1_CheckedChanged_1(object sender, System.EventArgs e)
{
if(this.checkBox1.Checked)
{
this.dateTimePicker1.Enabled=true;
this.dateTimePicker2.Enabled=true;
}
else
{
this.dateTimePicker1.Enabled=false;
this.dateTimePicker2.Enabled=false;
}
}
private void checkBox2_CheckedChanged(object sender, System.EventArgs e)
{
if(this.checkBox2.Checked)
{
this.dateTimePicker3.Enabled=true;
this.dateTimePicker4.Enabled=true;
}
else
{
this.dateTimePicker3.Enabled=false;
this.dateTimePicker4.Enabled=false;
}
}
private void btncancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -