📄 kq.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace kaoqin
{
public partial class kq : Form
{
string check = "";
public kq()
{
InitializeComponent();
}
private void kaoqin_Load(object sender, EventArgs e)
{
BindData();
}
private void BindData()
{
this.comboBox2.Items.Clear();
this.lblKaoqin.Text = DB.userName;
string sql = "select * from vwKaoqin where name='"+DB.userName+"'";
DataTable dt = DB.getTable(sql);
for (int i = 0; i < dt.Rows.Count; i++)
{
this.comboBox2.Items.Add(dt.Rows[i]["className"].ToString().Trim());
}
dt.Clear();
sql = "select * from [user] where name='"+DB.userName+"'";
dt = DB.getTable(sql);
this.lblKaoqin.Text = dt.Rows[0]["realName"].ToString().Trim();
}
private void BindText()
{
this.textBox1.Text = this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber, 2].ToString();
this.textBox2.Text = this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber, 1].ToString();
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
string sql = "select * from vwStudent where className='" + this.comboBox2.SelectedItem.ToString() + "'";
DataTable dt = DB.getTable(sql);
this.dataGrid1.DataSource = dt;
}
private void dataGrid1_Navigate(object sender, NavigateEventArgs ne)
{
}
private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
{
this.groupBox1.Enabled = true;
if (this.dataGrid1.CurrentRowIndex == -1)
{
this.textBox1.Text = "";
this.textBox2.Text = "";
return;
}
for (int i = 0; i < check.Length; i++)
{
if (check[i].ToString().Trim() == this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber, 0].ToString().Trim())
{
this.groupBox1.Enabled = false;
return;
}
else
{
this.groupBox1.Enabled = true;
}
}
BindText();
}
private void kaoqin()
{
string yidao = "0";
string cidao = "0";
string zaotui = "0";
string kuangke = "0";
string qingjia = "0";
if (this.radioButton1.Checked == true)
{
yidao = "1";
}
if (this.radioButton2.Checked == true)
{
cidao = "1";
}
if (this.radioButton3.Checked == true)
{
zaotui = "1";
}
if (this.radioButton4.Checked == true)
{
kuangke = "1";
}
if (this.radioButton5.Checked == true)
{
qingjia = "1";
}
string studentID = this.textBox2.Text.Trim();
string kaoqinID = DB.getID("select kaoqinID from [user] where name='"+DB.userName+"'") ;
string sql = "insert into kaoqin(studentID,kaoqinID,yidao,cidao,zaotui,kuangke,qingjia)values "+
" ('" + studentID + "','" + kaoqinID + "','" + yidao + "','" + cidao+ "','" + zaotui+ "','" + kuangke+ "','" + qingjia+ "')";
if (DB.executeSql(sql))
{
MessageBox.Show("操作成功!");
check += this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,0].ToString();
this.groupBox1.Enabled = false;
}
else
{
MessageBox.Show("操作失败!");
}
}
private void button1_Click(object sender, EventArgs e)
{
if (this.dataGrid1.CurrentRowIndex == -1)
{
MessageBox.Show("请选择要考勤的学生!");
this.dataGrid1.Focus();
return;
}
for (int i = 0; i < check.Length; i++)
{
if (check[i].ToString().Trim() == this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber, 0].ToString().Trim())
{
this.groupBox1.Enabled = false;
MessageBox.Show("此学生已经考勤!");
return;
}
else
{
this.groupBox1.Enabled = true;
}
}
if (MessageBox.Show("此操作将不能修改,你确定要进行此操作吗?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
{
return;
}
kaoqin();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -