📄 leave.cs
字号:
lblRecord.Text=position+"/"+count+"条记录";
}
private void Combo_Fill()
{
try
{
this.Connection1.Open();
this.commandStr="select * from LeaveType";
this.Command1.CommandText=this.commandStr;
this.DataReader1=this.Command1.ExecuteReader();
while(this.DataReader1.Read())
{
this.comboLeaveType.Items.Add(this.DataReader1[1].ToString());
this.comboLeaveType2.Items.Add(this.DataReader1[1].ToString());
}
}
catch(Exception E)
{
MessageBox.Show(E.ToString());
}
finally
{
this.Connection1.Close();
}
}
private void btnApply_Click(object sender, System.EventArgs e)
{
try
{
this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].EndCurrentEdit();
if(this.Connection1.State==ConnectionState.Closed)
this.Connection1.Open();
OleDbCommandBuilder commandbuilder1=new OleDbCommandBuilder(this.dataAdapter1);
this.dataAdapter1.Update(this.DataSetLeaveRecord,"LeaveRecord");
this.DataSetLeaveRecord.AcceptChanges();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
this.Connection1.Close();
}
this.Buttons_Control(false);
}
private void btnNext_Click(object sender, System.EventArgs e)
{
int position=this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Position;
int count=this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Count;
if(position>=count-1)
{
this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Position=0;
}
else
{
this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Position+=1;
}
this.lblRecord_Change();
}
private void btnLast_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Position=this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Count-1;
this.lblRecord_Change();
}
private void btnFirst_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Position=0;
this.lblRecord_Change();
}
private void btnPrevious_Click(object sender, System.EventArgs e)
{
int position=this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Position;
int count=this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Count;
if(position==0)
{
this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Position=count-1;
}
else
{
this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Position-=1;
}
this.lblRecord_Change();
}
private void btnDelete_Click(object sender, System.EventArgs e)
{
if((this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Count>0)&
(MessageBox.Show("真的要删除此记录吗","确定删除",MessageBoxButtons.OKCancel,MessageBoxIcon.Question).Equals(DialogResult.OK)))
{
try
{
int position=this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].Position;
this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].RemoveAt(position);
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.lblRecord_Change();
}
else
return;
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
this.Buttons_Control(true);
this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].AddNew();
}
public void ErrorHandle(System.Exception E)
{
MessageBox.Show(E.ToString());
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
try
{
this.BindingContext[this.DataSetLeaveRecord,"LeaveRecord"].CancelCurrentEdit();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.Buttons_Control(false);
}
private void Buttons_Control(bool IsValid)
{
if(IsValid)
{
this.btnCancel.Enabled=true;
this.btnApply.Enabled=true;
this.dataGrid1.ReadOnly=false;
this.textEmployeeID.Enabled=true;
this.textRemark.Enabled=true;
this.comboLeaveType.Enabled=true;
this.dateTimePicker1.Enabled=true;
this.dateTimePicker2.Enabled=true;
this.textDays.Enabled=true;
}
else
{
this.btnCancel.Enabled=false;
this.btnApply.Enabled=false;
this.dataGrid1.ReadOnly=true;
this.textEmployeeID.Enabled=false;
this.textRemark.Enabled=false;
this.textDays.Enabled=false;
this.comboLeaveType.Enabled=false;
this.dateTimePicker1.Enabled=false;
this.dateTimePicker2.Enabled=false;
}
}
private void btnModify_Click(object sender, System.EventArgs e)
{
this.Buttons_Control(true);
}
private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(this.tabControl1.SelectedIndex==1)
{
this.DataSetView_LeaveRecord.Clear();
this.dataAdapter2.Fill(this.DataSetView_LeaveRecord,"LeaveRecord");
}
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
try
{
DataViewLeave.Table=this.DataSetView_LeaveRecord.Tables[0];
DataViewLeave.RowFilter=this.SearchStr_Made();
this.dataGrid2.DataSource=DataViewLeave;
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
this.Connection1.Close();
}
if(DataViewLeave.Count==0)
MessageBox.Show("没有符合查询条件的记录","没有记录",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textEmployeeID2.Clear();
this.comboLeaveType.Text="";
this.checkBox1.Checked=false;
}
private string SearchStr_Made()
{
string searchStr=null;
bool first=true;
if(this.textEmployeeID2.Text!="")
{
searchStr="EmployeeID="+"'"+this.textEmployeeID2.Text+"'";
first=false;
this.selectStr1="职工号:"+this.textEmployeeID2.Text;
}
if(this.comboLeaveType2.Text!="")
{
if(first)
{
searchStr="LeaveType="+"'"+this.comboLeaveType2.Text+"'";
first=false;
this.selectStr1="请假类型:"+this.comboLeaveType2.Text;
}
else
{
searchStr=searchStr+" and LeaveType="+"'"+this.comboLeaveType2.Text+"'";
this.selectStr1+=" 请假类型:"+this.comboLeaveType2.Text;
}
}
if(this.checkBox1.Checked)
{
if(first)
{
searchStr="Date>"+"'"+this.dateTimePicker3.Text+"'"+" and "+"Date<"+"'"+this.dateTimePicker4.Text+"'" ;
this.selectStr1="日期:在"+this.dateTimePicker3.Text+"和"+this.dateTimePicker4.Text+"之间";
}
else
{
searchStr=searchStr+" and (Date>"+"'"+this.dateTimePicker3.Text+"'"+" and "+"Date<"+"'"+this.dateTimePicker4.Text+"')";
this.selectStr1+=" 日期:在"+this.dateTimePicker3.Text+"和"+this.dateTimePicker4.Text+"之间";
}
}
return searchStr;
}
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 btnExcel_Click(object sender, System.EventArgs e)
{
Excel.Application myExcel = new Excel.Application ( ) ;
myExcel.Application.Workbooks.Add ( true ) ;
//让Excel文件可见
myExcel.Visible=true;
//第一行为报表名称
myExcel.Cells[1,4]="请假查询记录";
myExcel.Cells[2,3]="查询条件:";
myExcel.Cells[2,4]=this.selectStr1;
myExcel.Cells[3,6]="'"+DateTime.Now.ToShortDateString().ToString();
//逐行写入数据,
for(int i=0;i<9;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.DataViewLeave.Count;i++)
{
for(int j=0;j<9;j++)
{
//以单引号开头,表示该单元格为纯文本
myExcel.Cells[6+i,1+j]="'"+this.DataViewLeave[i][j].ToString();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -