updateform.cs
来自「初学Csharp」· CS 代码 · 共 577 行 · 第 1/2 页
CS
577 行
this.button_OK.TabIndex = 1;
this.button_OK.Text = "更新";
this.button_OK.Click += new System.EventHandler(this.button_OK_Click);
//
// button_close
//
this.button_close.Location = new System.Drawing.Point(208, 312);
this.button_close.Name = "button_close";
this.button_close.Size = new System.Drawing.Size(80, 24);
this.button_close.TabIndex = 2;
this.button_close.Text = "关闭";
this.button_close.Click += new System.EventHandler(this.button_close_Click);
//
// UpdateForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(424, 349);
this.Controls.Add(this.button_close);
this.Controls.Add(this.button_OK);
this.Controls.Add(this.groupBox1);
this.Name = "UpdateForm";
this.Text = "修改代码信息";
this.Load += new System.EventHandler(this.AddForm_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void AddForm_Load(object sender, System.EventArgs e)
{
OleDbCommand command=new OleDbCommand();
OleDbDataAdapter oleAdapter=new OleDbDataAdapter();
DataSet dset=new DataSet();
connection.Open();
command.Connection=connection;
string sqlstr;
sqlstr="select LANNAME from LanguageInfo";
command.CommandText=sqlstr;
OleDbDataReader DataReader=command.ExecuteReader();
//初始化语言类别等属性
try
{
while(DataReader.Read())
{
this.comboBox_Lan.Items.Add(DataReader.GetString(0));
}
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
DataReader.Close();
////
sqlstr="select FORMNAME from FormInfo";
command.CommandText=sqlstr;
DataReader=command.ExecuteReader();
try
{
while(DataReader.Read())
{
this.comboBox_form.Items.Add(DataReader.GetString(0));
}
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
DataReader.Close();
////
sqlstr="select PLATFORMNAME from PlatformInfo";
command.CommandText=sqlstr;
DataReader=command.ExecuteReader();
try
{
while(DataReader.Read())
{
this.comboBox_plat.Items.Add(DataReader.GetString(0));
}
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
DataReader.Close();
////
sqlstr="select CLASSNAME from CLASSINFO";
command.CommandText=sqlstr;
DataReader=command.ExecuteReader();
try
{
while(DataReader.Read())
{
this.comboBox_class.Items.Add(DataReader.GetString(0));
}
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
DataReader.Close();
connection.Close();
//载入待更新的信息//////////////
this.comboBox_class.Text=(string)m_UpdataRow["CLASSNAME"];
this.comboBox_form.Text=(string)m_UpdataRow["FORMNAME"];
this.comboBox_plat.Text=(string)m_UpdataRow["PLATFORMNAME"];
this.comboBox_Lan.Text= (string)m_UpdataRow["LANNAME"];
this.textBox_dict.Text=(string)m_UpdataRow["DIRECTORY"];
this.textBox_func.Text= (string)m_UpdataRow["FUNCDSC"];
this.textBox_key.Text =(string)m_UpdataRow["KEYWORD"];
this.textBox_sourceNum.Text =((int)m_UpdataRow["SCRNUM"]).ToString();
////////////////
DateTime date1=DateTime.Now;
this.textBox_Cdata.Text=date1.ToString();
}
private void button_openfile_Click(object sender, System.EventArgs e)
{
}
public void SetConnection(OleDbConnection conn)
{
connection=conn;
}
private void groupBox1_Enter(object sender, System.EventArgs e)
{
}
private void button_close_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void button_OK_Click(object sender, System.EventArgs e)
{
//拷贝文件到指定目录
//插入信息
//1检查数据有效性
if(this.comboBox_class.Text=="")
{
MessageBox.Show("领域不能为空","错误");
return;
}
if(this.comboBox_plat.Text=="")
{
MessageBox.Show("平台不能为空","错误");
return;
}
if(this.comboBox_Lan.Text=="")
{
MessageBox.Show("语言不能为空","错误");
return;
}
if(this.comboBox_form.Text=="")
{
MessageBox.Show("类别不能为空","错误");
return;
}
if(this.textBox_key.Text=="")
{
MessageBox.Show("关键词不能为空","错误");
return;
}
#region 查询各属性对应ID
OleDbCommand command=new OleDbCommand();
OleDbDataReader DataReader;
string sqlstr;
string lanid="",platid="",formid="",classid="";
DateTime date=DateTime.Now;
//////////////////////
sqlstr="select LANID from LanguageInfo where LANNAME='"+comboBox_Lan.Text+"'";
command.Connection=connection;
command.CommandText=sqlstr;
connection.Open();
DataReader=command.ExecuteReader();
try
{
if(DataReader.Read())
lanid=DataReader.GetString(0);
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
finally
{
DataReader.Close();
}
sqlstr="select FORMID from FormInfo where FORMNAME='"+comboBox_form.Text+"'";
command.CommandText=sqlstr;
DataReader=command.ExecuteReader();
try
{
if(DataReader.Read())
formid=DataReader.GetString(0);
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
finally
{
DataReader.Close();
}
sqlstr="select PLATFORMID from PlatformInfo where PLATFORMNAME='"+comboBox_plat.Text+"'";
command.CommandText=sqlstr;
DataReader=command.ExecuteReader();
try
{
if(DataReader.Read())
platid=DataReader.GetString(0);
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
finally
{
DataReader.Close();
}
sqlstr="select CLASSID from CLASSINFO where CLASSNAME='"+comboBox_class.Text+"'";
command.CommandText=sqlstr;
DataReader=command.ExecuteReader();
try
{
if(DataReader.Read())
classid=DataReader.GetString(0);
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
finally
{
DataReader.Close();
}
connection.Close();
#endregion
//3更新//(SCRNUM,CLASSID,FORMID,LANID,FUNCDSC,KEYWORD,PLATFORMID,DIRECTORY)
sqlstr="Update SourceInfo SET "+"CLASSID='"+classid+"',FORMID='"+formid+"',LANID='"+lanid+"',FUNCDSC='"+this.textBox_func.Text+"',KEYWORD='"+this.textBox_key.Text+"',PLATFORMID='"+platid+"',DIRECTORY='"+this.textBox_dict.Text+"'"+" where SCRNUM="+this.textBox_sourceNum.Text;
command.CommandText=sqlstr;
connection.Open();
try
{
command.ExecuteNonQuery();
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
finally
{
connection.Close();
}
//////////
m_UpdataRow["CLASSNAME"]=this.comboBox_class.Text;
m_UpdataRow["FORMNAME"]=this.comboBox_form.Text;
m_UpdataRow["PLATFORMNAME"]=this.comboBox_plat.Text;
m_UpdataRow["LANNAME"]=this.comboBox_Lan.Text;
m_UpdataRow["DIRECTORY"]=this.textBox_dict.Text;
m_UpdataRow["FUNCDSC"]=this.textBox_func.Text;
m_UpdataRow["KEYWORD"] =this.textBox_key.Text;
m_UpdataRow["SCRNUM"]=int.Parse( this.textBox_sourceNum.Text);
}
private void comboBox_Lan_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.textBox_dict.Text = "\\"+this.comboBox_Lan.Text+"\\";
}
public void SetCurrentUpdateRow(DataRow r)
{
this.m_UpdataRow=r;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?