📄 cdlgcreateitem.cs
字号:
using System;
using System.Data;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OracleClient;
using GlobleUtility;
namespace Charge
{
/// <summary>
/// CdlgCreateItem 的摘要说明。
/// </summary>
public class CdlgCreateItem : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtItemName;
private System.Windows.Forms.ComboBox cbbDept;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtDesc;
private System.Windows.Forms.Button btnOK;
private System.Collections.ArrayList ArrDeptID = null;//用来装载部门ID号
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public CdlgCreateItem()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
ArrDeptID=new ArrayList();
ArrDeptID.Clear();
}
/// <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.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtDesc = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.cbbDept = new System.Windows.Forms.ComboBox();
this.txtItemName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.btnOK = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtDesc);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.cbbDept);
this.groupBox1.Controls.Add(this.txtItemName);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(0, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(408, 200);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "项目信息";
//
// txtDesc
//
this.txtDesc.Location = new System.Drawing.Point(120, 120);
this.txtDesc.Multiline = true;
this.txtDesc.Name = "txtDesc";
this.txtDesc.Size = new System.Drawing.Size(216, 72);
this.txtDesc.TabIndex = 5;
this.txtDesc.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(24, 120);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 23);
this.label3.TabIndex = 4;
this.label3.Text = "部门描述:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// cbbDept
//
this.cbbDept.Location = new System.Drawing.Point(120, 72);
this.cbbDept.Name = "cbbDept";
this.cbbDept.Size = new System.Drawing.Size(216, 20);
this.cbbDept.TabIndex = 3;
//
// txtItemName
//
this.txtItemName.Location = new System.Drawing.Point(120, 32);
this.txtItemName.Name = "txtItemName";
this.txtItemName.Size = new System.Drawing.Size(216, 21);
this.txtItemName.TabIndex = 2;
this.txtItemName.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 23);
this.label2.TabIndex = 1;
this.label2.Text = "收费部门:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 23);
this.label1.TabIndex = 0;
this.label1.Text = "项目名称:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(152, 216);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 1;
this.btnOK.Text = "确定";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// CdlgCreateItem
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(408, 245);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "CdlgCreateItem";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "创建项目";
this.Load += new System.EventHandler(this.CdlgCreateItem_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void CdlgCreateItem_Load(object sender, System.EventArgs e)
{
//页面载入事件导入部门名称
System.Data.OracleClient.OracleConnection myconn = Connection.DBConnection;
if(myconn==null)
{
return;
}
string mysql="Select DeptID,DeptName From charge_dept_info Order By DeptID";
OracleCommand mycommand=new OracleCommand(mysql, myconn);
OracleDataReader myreader=null;
try
{
myreader = mycommand.ExecuteReader();
}
catch(Exception ee)
{
MessageBox.Show("数据库查询出错,消息如下:\r\n"+ee.Message,"消息:",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
while(myreader.Read())
{
ArrDeptID.Add(myreader.GetInt32(0));
cbbDept.Items.Add(myreader.GetString(1));
}
myreader.Close();
myreader.Dispose();
myconn.Close();
}
private void btnOK_Click(object sender, System.EventArgs e)
{
if((txtItemName.Text.Trim()=="")|(cbbDept.SelectedIndex<0))
{
MessageBox.Show("请输入信息!");
return;
}
int deptid=Convert.ToInt32(ArrDeptID[cbbDept.SelectedIndex]);
System.Data.OracleClient.OracleConnection myconn = Connection.DBConnection;
if(myconn==null)
{
return;
}
string mysql="insert into charge_items values(Seq_charge_items_ID.NEXTVAL,'"+txtItemName.Text.Trim()+"',"+deptid+",'"+
txtDesc.Text.Trim()+"',0)";
OracleCommand mycommand=new OracleCommand(mysql, myconn);
try
{
mycommand.ExecuteNonQuery();
}
catch(Exception ee)
{
MessageBox.Show("数据库插入出错,消息如下:\r\n"+ee.Message,"消息:",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
MessageBox.Show("创建收费项目成功!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -