📄 frmplatforg.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OracleClient;
using GlobleUtility;
using System.IO;
namespace PlatF
{
/// <summary>
/// 学校信息的维护界面。
/// </summary>
public class CfrmPlatFOrg : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBoxOrgName;
private System.Windows.Forms.TextBox textBoxOrgDesc;
private System.Windows.Forms.ToolBarButton toolBarButton8;
private System.Windows.Forms.ToolBar toolBarOrg;
private System.Windows.Forms.ToolBarButton tbrButtonSave;
private System.Windows.Forms.ToolBarButton tbrButtonEdit;
private System.Windows.Forms.ToolBarButton tbrButtonExit;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ImageList imageListtbr;
private System.ComponentModel.IContainer components;
public CfrmPlatFOrg()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CfrmPlatFOrg));
this.textBoxOrgName = new System.Windows.Forms.TextBox();
this.textBoxOrgDesc = new System.Windows.Forms.TextBox();
this.toolBarOrg = new System.Windows.Forms.ToolBar();
this.toolBarButton8 = new System.Windows.Forms.ToolBarButton();
this.tbrButtonSave = new System.Windows.Forms.ToolBarButton();
this.tbrButtonEdit = new System.Windows.Forms.ToolBarButton();
this.tbrButtonExit = new System.Windows.Forms.ToolBarButton();
this.imageListtbr = new System.Windows.Forms.ImageList(this.components);
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// textBoxOrgName
//
this.textBoxOrgName.Location = new System.Drawing.Point(72, 80);
this.textBoxOrgName.MaxLength = 20;
this.textBoxOrgName.Name = "textBoxOrgName";
this.textBoxOrgName.Size = new System.Drawing.Size(448, 21);
this.textBoxOrgName.TabIndex = 0;
this.textBoxOrgName.Text = "";
this.textBoxOrgName.TextChanged += new System.EventHandler(this.textBoxOrgName_TextChanged);
//
// textBoxOrgDesc
//
this.textBoxOrgDesc.Location = new System.Drawing.Point(72, 120);
this.textBoxOrgDesc.MaxLength = 250;
this.textBoxOrgDesc.Multiline = true;
this.textBoxOrgDesc.Name = "textBoxOrgDesc";
this.textBoxOrgDesc.Size = new System.Drawing.Size(448, 104);
this.textBoxOrgDesc.TabIndex = 1;
this.textBoxOrgDesc.Text = "";
//
// toolBarOrg
//
this.toolBarOrg.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton8,
this.tbrButtonSave,
this.tbrButtonEdit,
this.tbrButtonExit});
this.toolBarOrg.ButtonSize = new System.Drawing.Size(52, 52);
this.toolBarOrg.DropDownArrows = true;
this.toolBarOrg.ImageList = this.imageListtbr;
this.toolBarOrg.Location = new System.Drawing.Point(0, 0);
this.toolBarOrg.Name = "toolBarOrg";
this.toolBarOrg.ShowToolTips = true;
this.toolBarOrg.Size = new System.Drawing.Size(530, 58);
this.toolBarOrg.TabIndex = 7;
this.toolBarOrg.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBarOrg_ButtonClick);
//
// toolBarButton8
//
this.toolBarButton8.Enabled = false;
this.toolBarButton8.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbrButtonSave
//
this.tbrButtonSave.ImageIndex = 1;
this.tbrButtonSave.Text = "保存";
this.tbrButtonSave.ToolTipText = "保存";
//
// tbrButtonEdit
//
this.tbrButtonEdit.ImageIndex = 2;
this.tbrButtonEdit.Text = "修改";
this.tbrButtonEdit.ToolTipText = "修改";
//
// tbrButtonExit
//
this.tbrButtonExit.ImageIndex = 6;
this.tbrButtonExit.Text = "退出";
this.tbrButtonExit.ToolTipText = "退出";
//
// imageListtbr
//
this.imageListtbr.ImageSize = new System.Drawing.Size(32, 32);
this.imageListtbr.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListtbr.ImageStream")));
this.imageListtbr.TransparentColor = System.Drawing.Color.Transparent;
//
// label1
//
this.label1.BackColor = System.Drawing.SystemColors.Control;
this.label1.Location = new System.Drawing.Point(8, 80);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 23);
this.label1.TabIndex = 10;
this.label1.Text = "单位名称:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 120);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 23);
this.label2.TabIndex = 11;
this.label2.Text = "单位描述:";
//
// CfrmPlatFOrg
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(530, 231);
this.Controls.Add(this.toolBarOrg);
this.Controls.Add(this.textBoxOrgDesc);
this.Controls.Add(this.textBoxOrgName);
this.Controls.Add(this.label1);
this.Controls.Add(this.label2);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CfrmPlatFOrg";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "学校信息";
this.Load += new System.EventHandler(this.CfrmPlatFOrg_Load);
this.ResumeLayout(false);
}
#endregion
private void CfrmPlatFOrg_Load(object sender, System.EventArgs e)
{
OrgView();
}
/*********************************************
* 功能:显示当前OrgID为1的学校信息,通过调用
* 存储过程获得返回记录集
* *******************************************/
private void OrgView()
{
String mysql="select orgname,orgdesc from Charge_School_Info";
System.Data.OracleClient.OracleConnection myConn = Connection.DBConnection;
OracleCommand myCommand = new OracleCommand(mysql, myConn);
try
{
OracleDataReader myreader=myCommand.ExecuteReader();
if(myreader.Read())
{
textBoxOrgName.Text=myreader.GetString(0);
textBoxOrgDesc.Text=myreader.GetValue(1).ToString().Trim();
tbrButtonEdit.Enabled =true;
tbrButtonSave.Enabled =false;
textBoxOrgName.ReadOnly =true;
textBoxOrgDesc.ReadOnly =true;
}
else
{
MessageBox.Show ("不存在学校信息,请输入!");
}
}
catch(Exception ee)
{
ErrorCode E = new ErrorCode();
//E.ShowMessage(ErrorCode.E_8_DBUnknownError_Code);
MessageBox.Show ("发生未知数据库错误!");
tbrButtonEdit.Enabled =false;
tbrButtonSave.Enabled =true;
}
}
private void textBoxOrgName_TextChanged(object sender, System.EventArgs e)
{
if(ValidateParam())
{
//buttonSave.Enabled = true;
tbrButtonSave.Enabled =true;
}
else
{
//buttonSave.Enabled = false;
tbrButtonSave.Enabled =false;
}
}
private bool ValidateParam()
{
//检查数据的合法性。注意,这里只是简单地检查是否有字符输入。
if(textBoxOrgName.Text.Trim().Length == 0)
return false;
return true;
}
private void buttonSave_Click(object sender, System.EventArgs e)
{
int p_OrgID = 1; //指定学校ID号
//创建数据库连接
System.Data.OracleClient.OracleConnection myConn = Connection.DBConnection;
if (myConn == null)
{
return;
}
string mySql = "DELETE Charge_School_Info WHERE OrgID = "+p_OrgID;
OracleCommand delCommand = new OracleCommand(mySql, myConn);
OracleCommand inCommand = new OracleCommand ();
inCommand.Connection = myConn;
mySql = " INSERT INTO Charge_School_Info (OrgID,OrgName,OrgDesc) VALUES ("+p_OrgID+",'"+textBoxOrgName.Text.Trim()+"','"+textBoxOrgDesc.Text.Trim()+"')";
inCommand.CommandText = mySql;
inCommand.Connection = myConn;
try
{
delCommand.ExecuteNonQuery(); //删除已经存在的学校信息
inCommand.ExecuteNonQuery(); //保存新创建的学校信息
mySql = "COMMIT";
OracleCommand mitCommand = new OracleCommand(mySql, myConn);
mitCommand.ExecuteNonQuery();
MessageBox.Show("保存成功!");
//按钮属性更改
tbrButtonEdit.Enabled =true;
tbrButtonSave.Enabled =false;
textBoxOrgName.ReadOnly =true;
textBoxOrgDesc.ReadOnly =true;
}
catch
{
ErrorCode E = new ErrorCode();
E.ShowMessage(ErrorCode.E_8_DBUnknownError_Code);
}
myConn.Close();
}
private void buttonExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void toolBarOrg_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch(toolBarOrg.Buttons.IndexOf(e.Button))
{
//“保存”按钮点击事件
case 1:
this.buttonSave_Click(sender,e);
break;
//“修改”按钮点击事件
case 2:
tbrButtonEdit.Enabled =false;//“修改”按钮变为不可用
tbrButtonSave.Enabled =true;//“保存”按钮变为可用
textBoxOrgName.ReadOnly =false;//“单位名称”文本框可编辑
textBoxOrgDesc.ReadOnly =false;//“单位描述”文本框可编辑
break;
//“退出”按钮点击事件
case 3:
this.buttonExit_Click(sender,e);
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -