📄 form1.cs
字号:
foreach (Label L in labelLeftAll)
L.Top += (i++);
}
// //////////////////////////////
if (e.KeyCode == Keys.Left)
{
foreach (TextBox newOb in textBoxLeft)
newOb.Width--;
}
if (e.KeyCode == Keys.Right)
{
foreach (TextBox newOb in textBoxLeft)
newOb.Width++;
}
}
// ///////////////////////////
}
private void danhao_TextChanged(object sender, EventArgs e)
{
}
private void From1_FormClosing(object sender, FormClosingEventArgs e)
{
if (isChange || isNew)
{
if (MessageBox.Show("资料已被修改是否保存?", "是否退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
selectCmd = " insert into 成绩管理系统 (学号,姓名,年级,班级,性别,出身年月,籍贯,职位,成绩,图片路径) values ('" + this.danhao.Text + "','" + this.sencansulian.Text + "','" + this.wancensijian.Text + "','" + this.sougongjia.Text + "','" + this.dianhanjia1.Text + "','" + this.dianhanjia2.Text + "','" + this.xialiaojia.Text + "','" + this.duandajia.Text + "','" + this.cicun.Text + "','" + filePath + "')";
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
OleDbCommand cmd = new OleDbCommand(selectCmd, conn);
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("保存成功");
this.isChange = false;
this.isNew = false;
}
catch
{
if (MessageBox.Show("是否保存修改?", "是否保存修改", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
int no = 0;
selectCmd = "update 成绩管理系统 set 姓名 = '" + this.sencansulian.Text + "',年级 = '" + this.wancensijian.Text + "',班级 = '" + this.sougongjia.Text + "',性别 = '" + this.dianhanjia1.Text + "',出身年月 = '" + this.dianhanjia2.Text + "',籍贯 = '" + this.xialiaojia.Text + "',职位 = '" + this.duandajia.Text + "',成绩 = '" + this.cicun.Text + "',图片路径 = '" + this.filePath + "' where 学号 = '" + this.danhao.Text + "'";
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
OleDbCommand cmd = new OleDbCommand(selectCmd, conn);
no = cmd.ExecuteNonQuery();
conn.Close();
if (no == 1)
MessageBox.Show("修改成功");
else
MessageBox.Show("当前页不存在");
isNew = false;
isChange = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
}
private void ziti_Click(object sender, EventArgs e)
{
if (fontDialog1.ShowDialog() == DialogResult.OK)
{
label2.Font = label3.Font = label4.Font = label5.Font = label6.Font = label7.Font = label8.Font = label9.Font = label10.Font = label11.Font = label12.Font = label13.Font = label14.Font = fontDialog1.Font;
danhao.Font = cicun.Font = sencansulian.Font = wancensijian.Font = sougongjia.Font = dianhanjia1.Font = dianhanjia2.Font = xialiaojia.Font = duandajia.Font = fontDialog1.Font;
}
}
int x, y;
private void sencansulian_MouseDown(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
}
private void sencansulian_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
//TextBox newL = (TextBox)sender;
//newL.Top -= (y - e.Y);
//newL.Left -= (x - e.X);
foreach (TextBox newT in textBoxLeft)
{
newT.Top -= (y - e.Y);
newT.Left -= (x - e.X);
}
}
else
{
x = e.X;
y = e.Y;
}
}
private void cicun_MouseDown(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
}
private void cicun_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
RichTextBox newL = (RichTextBox)sender;
newL.Top -= (y - e.Y);
newL.Left -= (x - e.X);
//x = e.X;
//y = e.Y;
}
else
{
x = e.X;
y = e.Y;
}
}
private void danhao_MouseDown(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
}
private void danhao_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
TextBox newL = (TextBox)sender;
newL.Top -= (y - e.Y);
newL.Left -= (x - e.X);
textBox1.Top = danhao.Top;
textBox1.Left = danhao.Left;
//x = e.X;
//y = e.Y;
}
else
{
x = e.X;
y = e.Y;
}
}
private void cicun_KeyDown(object sender, KeyEventArgs e)
{
isChange = true;
if (e.Shift)
{
if (e.KeyCode == Keys.Up)
{
RichTextBox newOb = (RichTextBox)sender;
newOb.Height++;
}
if (e.KeyCode == Keys.Down)
{
RichTextBox newOb = (RichTextBox)sender;
newOb.Height--;
}
if (e.KeyCode == Keys.Left)
{
RichTextBox newOb = (RichTextBox)sender;
newOb.Width--;
}
if (e.KeyCode == Keys.Right)
{
RichTextBox newOb = (RichTextBox)sender;
newOb.Width++;
}
}
}
private void label4_MouseDown(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
}
private void label4_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
//TextBox newL = (TextBox)sender;
//newL.Top -= (y - e.Y);
//newL.Left -= (x - e.X);
foreach (Label newT in labelLeftAll)
{
newT.Top -= (y - e.Y);
newT.Left -= (x - e.X);
}
}
else
{
x = e.X;
y = e.Y;
}
}
bool isReset = false;
private void 恢复到ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("是否将窗体位置恢复到初始状态。这个设置不会影响内部数据。如果选“是”则重新启动程序后将恢复到初始的状态。", "是否恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
isReset = true;
}
}
public void findWitchPage()
{
string selectCmd;
selectCmd = "select count(页数) from 成绩管理系统 where 页数 <= (select 页数 from 成绩管理系统 where 学号 = '" + this.danhao.Text + "')";
OleDbConnection conn;
OleDbCommand cmd;
OleDbDataReader reader;
conn = new OleDbConnection(connStr);
conn.Open();
cmd = new OleDbCommand(selectCmd, conn);
reader = cmd.ExecuteReader();
reader.Read();
textBox2.Text = reader[0].ToString();
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
if (isChange)
{
if (MessageBox.Show("资料已被修改是否保存?", "是否保存", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
selectCmd = " insert into 成绩管理系统 (学号,姓名,年级,班级,性别,出身年月,籍贯,职位,成绩,图片路径) values ('" + this.danhao.Text + "','" + this.sencansulian.Text + "','" + this.wancensijian.Text + "','" + this.sougongjia.Text + "','" + this.dianhanjia1.Text + "','" + this.dianhanjia2.Text + "','" + this.xialiaojia.Text + "','" + this.duandajia.Text + "','" + this.cicun.Text + "','" + filePath + "')";
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
OleDbCommand cmd = new OleDbCommand(selectCmd, conn);
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("保存成功");
this.isChange = false;
this.isNew = false;
}
catch
{
try
{
int no = 0;
selectCmd = "update 成绩管理系统 set 姓名 = '" + this.sencansulian.Text + "',年级 = '" + this.wancensijian.Text + "',班级 = '" + this.sougongjia.Text + "',性别 = '" + this.dianhanjia1.Text + "',出身年月 = '" + this.dianhanjia2.Text + "',籍贯 = '" + this.xialiaojia.Text + "',职位 = '" + this.duandajia.Text + "',成绩 = '" + this.cicun.Text + "',图片路径 = '" + this.filePath + "' where 学号 = '" + this.danhao.Text + "'";
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
OleDbCommand cmd = new OleDbCommand(selectCmd, conn);
no = cmd.ExecuteNonQuery();
conn.Close();
if (no == 1)
MessageBox.Show("修改成功");
else
MessageBox.Show("当前页不存在");
isNew = false;
isChange = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
this.danhao.Text = wancensijian.Text = this.sencansulian.Text = this.sougongjia.Text = dianhanjia1.Text = dianhanjia2.Text = xialiaojia.Text = duandajia.Text = cicun.Text = "";
}
else
{
this.danhao.Text = wancensijian.Text = this.sencansulian.Text = this.sougongjia.Text = dianhanjia1.Text = dianhanjia2.Text = xialiaojia.Text = duandajia.Text = cicun.Text = "";
}
isChange = isNew = false;
try
{
int i = this.i;
if (Int32.Parse(textBox2.Text) - 1 < myDataTable.Rows.Count)
{
i = Int32.Parse(textBox2.Text) - 1;
this.danhao.Text = myDataTable.Rows[i][0].ToString();
this.sencansulian.Text = myDataTable.Rows[i][1].ToString();
this.wancensijian.Text = myDataTable.Rows[i][2].ToString();
this.sougongjia.Text = myDataTable.Rows[i][3].ToString();
this.dianhanjia1.Text = myDataTable.Rows[i][4].ToString();
this.dianhanjia2.Text = myDataTable.Rows[i][5].ToString();
this.xialiaojia.Text = myDataTable.Rows[i][6].ToString();
this.duandajia.Text = myDataTable.Rows[i][7].ToString();
this.cicun.Text = myDataTable.Rows[i][8].ToString();
this.pictureBox1.Image = null;
}
if (myDataTable.Rows[i][9].ToString() == "")
{
this.pictureBox1.Image = null;
}
else
{
this.pictureBox1.Image = new Bitmap(myDataTable.Rows[i][9].ToString());
}
findWitchPage();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
[Serializable]
public class saveFont
{
public Font newFont;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -