📄 form1.cs
字号:
}
private void button2_Click(object sender, EventArgs e)
{
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 = "";
}
}
private void baocun_Click(object sender, EventArgs e)
{
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 From1_Load(object sender, EventArgs e)
{
////////////////////////////初始化textbox数组,label数组
textBoxLeft = new TextBox[] {sencansulian,wancensijian,sougongjia,dianhanjia1,dianhanjia2,xialiaojia,duandajia };
labelLeftAll = new Label[] {label4,label5,label6,label7,label8,label9,label10 };
////////////////////////////
// RegistryKey hklm = Registry.CurrentUser;
// RegistryKey software = hklm.OpenSubKey("Software");
// if(software.GetValue("width").ToString() != "")
// {
// this.Width = Convert.ToInt32(software.GetValue("width").ToString());
// }
// if(software.GetValue("height").ToString() != "")
// {
// this.Height = Convert.ToInt32(software.GetValue("height").ToString());
// }
if (metrics == null)
{
metrics = Registry.CurrentUser.OpenSubKey(@"Software", true);
metrics = metrics.CreateSubKey("成绩管理系统");
metrics.SetValue("width", this.Width.ToString());
metrics.SetValue("height", this.Height.ToString());
// metrics.SetValue("font", this.cicun.Font);
}
else
{
try
{
this.Width = Convert.ToInt32(metrics.GetValue("width").ToString());
this.Height = Convert.ToInt32(metrics.GetValue("height").ToString());
//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 = metrics.GetValue("font");
// /////////////////////////加载控件位置
foreach (Control c in this.Controls)
{
c.Left = Convert.ToInt32(metrics.GetValue(c.Name.ToString() + ".Left"));
c.Top = Convert.ToInt32(metrics.GetValue(c.Name.ToString() + ".Top"));
}
// //////////////////////////
}
catch
{}
}
// /////////////////////////////////加载字体
try
{
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MyFile.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
newsaveFont = (saveFont)formatter.Deserialize(stream);
stream.Close();
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 = newsaveFont.newFont;
danhao.Font = cicun.Font = sencansulian.Font = wancensijian.Font = sougongjia.Font = dianhanjia1.Font = dianhanjia2.Font = xialiaojia.Font = duandajia.Font = newsaveFont.newFont;
}
catch { }
// ////////////////////////
// ////////////////////////运行背景
try
{
System.Diagnostics.Process.Start("背景.exe");
}
catch
{ }
}
saveFont newsaveFont = new saveFont();
private void From1_FormClosed(object sender, FormClosedEventArgs e)
{
// ///////////////关闭背景
try
{
System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("背景");
foreach (System.Diagnostics.Process p in process)
{
p.Kill();
}
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
// //////////////////////////
if (isReset)
{
softwareM.DeleteSubKeyTree("成绩管理系统");
}
else
{
metrics.SetValue("width", this.Width.ToString());
metrics.SetValue("height", this.Height.ToString());
// ///////////////保存控件的位置
foreach (Control c in this.Controls)
{
metrics.SetValue(c.Name.ToString() + ".Left", c.Left.ToString());
metrics.SetValue(c.Name.ToString() + ".Top", c.Top.ToString());
}
// ///////////////
// //////////////////保存字体
newsaveFont.newFont = this.label4.Font;
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, newsaveFont);
//formatter.Serialize(stream, label1);
stream.Close();
// ///////////////////////////
}
Application.Exit();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//changeForm();
try
{
e.Graphics.DrawImage(memoryImage, Convert.ToInt32(zoubianju.Text), Convert.ToInt32(sanbianju.Text));
//returnForm();
}
catch (Exception ex6)
{
MessageBox.Show(ex6.Message);
//returnForm();
}
//returnForm();
}
private void dayin_Click(object sender, EventArgs e)
{
this.TopMost = false;
CaptureScreen();
printDocument1.Print();
this.TopMost = true;
}
private void dayinyulan_Click(object sender, EventArgs e)
{
this.TopMost = false;
//changeForm();
CaptureScreen();
printPreviewDialog1.ShowDialog();
//returnForm();
this.TopMost = true;
}
private void sancu_Click(object sender, EventArgs e)
{
if (MessageBox.Show("是否删除当前页?", "是否删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
selectCmd = "delete from 成绩管理系统 where 学号 = '" + this.danhao.Text + "'";
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
OleDbCommand cmd = new OleDbCommand(selectCmd, conn);
if (cmd.ExecuteNonQuery() == 0)
{
MessageBox.Show("当前页不存在");
}
else
{
MessageBox.Show("删除成功");
}
conn.Close();
this.isChange = false;
this.isNew = false;
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message);
}
}
}
private void From1_DragDrop(object sender, DragEventArgs e)
{
isChange = true;
try
{
this.pictureBox1.Image = new Bitmap(((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString());
filePath = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
}
catch (Exception ex5)
{
MessageBox.Show(ex5.Message);
}
}
private void From1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Link;
else e.Effect = DragDropEffects.None;
}
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
this.pictureBox1.Image = null;
filePath = "";
isChange = true;
}
//private void danhao_TextChanged(object sender, EventArgs e)
//{
//}
private void danhao_KeyDown(object sender, KeyEventArgs e)
{
isChange = true;
// ///////////////////////////使大小改变
if (e.Shift)
{
// ///////////////////////////////间隔变大
if (e.KeyCode == Keys.Up)
{
int i = 0;
foreach (TextBox newOb in textBoxLeft)
newOb.Top += (i--);
i = 0;
foreach (Label L in labelLeftAll)
L.Top += (i--);
}
if (e.KeyCode == Keys.Down)
{
int i = 0;
foreach (TextBox newOb in textBoxLeft)
newOb.Top += (i++);
i = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -