📄 addcourse.cs
字号:
//
// statusBar1
//
this.statusBar1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.statusBar1.Location = new System.Drawing.Point(0, 224);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.statusBarPanel2,
this.statusBarPanel3});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(570, 31);
this.statusBar1.TabIndex = 14;
//
// statusBarPanel1
//
this.statusBarPanel1.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
this.statusBarPanel1.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.statusBarPanel1.Text = "班级";
this.statusBarPanel1.ToolTipText = "班级";
this.statusBarPanel1.Width = 46;
//
// statusBarPanel2
//
this.statusBarPanel2.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
this.statusBarPanel2.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.statusBarPanel2.Text = "学期";
this.statusBarPanel2.ToolTipText = "学期";
this.statusBarPanel2.Width = 46;
//
// statusBarPanel3
//
this.statusBarPanel3.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
this.statusBarPanel3.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.statusBarPanel3.Text = "课程";
this.statusBarPanel3.ToolTipText = "课程";
this.statusBarPanel3.Width = 46;
//
// AddCourse
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(570, 255);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.label6);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.comboBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "AddCourse";
this.Text = "添加课程";
this.Load += new System.EventHandler(this.AddCourse_Load);
this.Closed += new System.EventHandler(this.tjkc_Closed);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
this.ResumeLayout(false);
}
#endregion
public bool strisyear(string s)
{
if (s.Trim().Length!=4)
return (false);
else
{
int n=1;
for (int i=0;i<=s.Length-1;i++)
{
if (!System.Char.IsNumber(s[i]))
{
n=-1;
break;
}
}
if (n==1)
return (true);
else
return (false);
}
}
private void AddCourse_Load(object sender, System.EventArgs e)
{
try
{
oleDbConnection1.Open();
string sql="select specialtyid,specialtyname from specialtyinfo";
OleDbDataAdapter adp=new OleDbDataAdapter(sql,oleDbConnection1);
DataSet ds=new DataSet();
adp.Fill(ds,"specialtyinfo");
comboBox1.DataSource=ds.Tables["specialtyinfo"].DefaultView;
comboBox1.DisplayMember="specialtyname";
comboBox1.ValueMember="specialtyid";
textBox2.Text=System.DateTime.Now.Year.ToString().Trim();
}
catch (Exception ee)
{
Console.WriteLine(ee.Message);
}
}
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
if (textBox2.Text.Trim()!="" && textBox2.Text.Trim().Length==4 && strisyear(textBox2.Text.Trim()))
{
string sql="select classid,classname from classinfo where specialtyname='"+comboBox1.Text.ToString()+"' and year(enrolmenttime)="+textBox2.Text.ToString();
OleDbDataAdapter adp=new OleDbDataAdapter(sql,oleDbConnection1);
DataSet ds=new DataSet();
ds.Clear();
adp.Fill(ds,"classinfo");
if (ds.Tables["classinfo"].Rows.Count!=0)
{
comboBox2.DisplayMember="classname";
comboBox2.ValueMember="classid";
comboBox2.DataSource=ds.Tables[0].DefaultView;
}
else
comboBox2.DataSource=null;
}
else
comboBox2.DataSource=null;
}
private void comboBox2_TextChanged(object sender, System.EventArgs e)
{
statusBarPanel1.Text=comboBox2.Text;
}
private void button1_Click(object sender, System.EventArgs e)
{
if (comboBox2.Text.Trim()=="" || comboBox3.Text.Trim()=="" || textBox3.Text.Trim()=="")
MessageBox.Show("请正确选择班级、学期以及填写课程名称","提示");
else
{
string sql;
sql="select * from courseinfo where classid="+comboBox2.SelectedValue.ToString().Trim()+" and semester='"+comboBox3.Text.ToString()+"' and course='"+textBox3.Text.ToString()+"'";
OleDbCommand cmd=new OleDbCommand(sql,oleDbConnection1);
if (null==cmd.ExecuteScalar())
{
sql="insert into courseinfo (classid,semester,course) values ('"+comboBox2.SelectedValue+"','"+comboBox3.Text.ToString()+"','"+textBox3.Text.ToString()+"')";
cmd.CommandText=sql;
cmd.ExecuteNonQuery();
MessageBox.Show("班级课程添加成功","提示");
}
else
MessageBox.Show("在同一个班级同一个学期不能添加相同的课程","提示");
}
}
private void comboBox2_Click(object sender, System.EventArgs e)
{
}
private void comboBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (comboBox2.DataSource!=null)
{
string sql="select year(enrolmenttime) from classinfo where classid="+comboBox2.SelectedValue;
OleDbCommand cmd=new OleDbCommand(sql,oleDbConnection1);
int rxnf=Int32.Parse(cmd.ExecuteScalar().ToString());
sql="select length from classinfo where classid="+comboBox2.SelectedValue;
cmd.CommandText=sql;
int nianzhi=Int32.Parse(cmd.ExecuteScalar().ToString());
comboBox3.Items.Clear();
int nf=rxnf;
Object item=new object();
for (int i=1;i<=nianzhi*2;i++)
{
comboBox3.Items.Add(nf+""+((i+1)%2+1));
if (i%2==0) nf++;
}
}
else
{
comboBox3.SelectedIndex=-1;
comboBox3.Items.Clear();
}
}
private void tjkc_Closed(object sender, System.EventArgs e)
{
oleDbConnection1.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
textBox2.Clear();
comboBox2.DataSource=null;
comboBox2.Text="";
comboBox3.Items.Clear();
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void textBox2_Leave(object sender, System.EventArgs e)
{
if (!strisyear(textBox2.Text.Trim()))
{
MessageBox.Show("请输入合法的入学年份","错误提示");
textBox2.Text=System.DateTime.Now.Year.ToString().Trim();
comboBox2.DataSource=null;
}
}
private void comboBox3_TextChanged(object sender, System.EventArgs e)
{
}
private void comboBox3_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (comboBox3.Text.Trim()!="")
statusBarPanel2.Text=(int.Parse(comboBox3.Text.Trim())/10)+"-"+(int.Parse(comboBox3.Text.Trim())/10+1)+"年度第"+(int.Parse(comboBox3.Text.Trim())%10)+"学期";
else
statusBarPanel2.Text="";
}
private void textBox3_TextChanged(object sender, System.EventArgs e)
{
statusBarPanel3.Text=textBox3.Text;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -