📄 tb_hyadd.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using gyit.Data;
namespace itcrm.jxcManager
{
/// <summary>
/// tb_hyAdd 的摘要说明。
/// </summary>
public class tb_hyAdd : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txthy_ID;
protected System.Web.UI.WebControls.Button btnClear;
protected System.Web.UI.WebControls.Button btnReturn;
protected System.Web.UI.WebControls.Button btnSave;
protected System.Web.UI.WebControls.TextBox txtName;
DBOperator db;
string vid;
private void Page_Load(object sender, System.EventArgs e)
{
vid=Page.Request["id"];
db =DBOperator.CreateObject((string)ConfigurationSettings.AppSettings["DSN"]);
if(!Page.IsPostBack)
{
if(vid!=null)
{
QueryEdit(vid);
txthy_ID.Enabled=false;
}
else
{
Refresh();
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
this.btnReturn.Click += new System.EventHandler(this.btnReturn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
/// <summary>
/// 增加或修改
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSave_Click(object sender, System.EventArgs e)
{
string[] strPara =new string[2];
object[] strValues=new object[2];
strPara[0]="@hy_ID";
strPara[1]="@hy_Name";
strValues[0]=txthy_ID.Text;
strValues[1]=txtName.Text;
try
{
if(txthy_ID.Text!="")
{
if(txtName.Text!="")
{
if(vid!=null)
{
db.Open();
db.exeProc("Update_tb_hy",strPara,strValues);
db.Close();
Page.RegisterStartupScript("script","<script>alert('修改记录成功!')</script>");
}
else
{
db.Open();
db.exeProc("Add_tb_hy",strPara,strValues);
db.Close();
Page.RegisterStartupScript("script","<script>alert('增加记录成功!')</script>");
txtName.Text="";
Refresh();
}
}
else{Page.RegisterStartupScript("script","<script>alert('行业名称不能为空!')</script>");}
}
else{Page.RegisterStartupScript("script","<script>alert('行业编码不能为空!')</script>");}
}
catch(System.Exception ee)
{
Page.RegisterStartupScript("script","<script>alert('"+ee.Message+"')</script>");
}
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="who"></param>
private void QueryEdit(string who)
{
string strSql="select * from tb_hy where hy_ID='"+who+"'";
DataSet ds=new DataSet();
DataRow row=null;
db.Open();
ds=db.exeSqlForDataSet(strSql);
db.Close();
if(ds.Tables[0].Rows.Count>0)
{
row=ds.Tables[0].Rows[0];
txthy_ID.Text=row["hy_ID"].ToString();
txtName.Text=row["hy_Name"].ToString();
ds.Dispose();
}
}
/// <summary>
/// 清除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnClear_Click(object sender, System.EventArgs e)
{
//txthy_ID.Text="";
txtName.Text="";
}
private void btnReturn_Click(object sender, System.EventArgs e)
{
Page.Response.Redirect("tb_hy.aspx");
}
/// <summary>
/// 自动获得编号
/// </summary>
private void Refresh()
{
string dq_ID=txthy_ID.Text;
string strSql="select hy_ID from tb_hy order by ID";
DataSet ds=null;
db.Open();
ds=db.exeSqlForDataSet(strSql);
db.Close();
int count=ds.Tables[0].Rows.Count;
if(count==0)
{
txthy_ID.Text="100001";
}
else
{
count=ds.Tables[0].Rows.Count;
DataRow row=ds.Tables[0].Rows[count-1];
int len=row["hy_ID"].ToString().Length;
string str=(row["hy_ID"].ToString()).Substring(len-2,1);
if(str=="0")
{
string str1=(row["hy_ID"].ToString()).Substring(0,len-1);
string str2=(row["hy_ID"].ToString()).Substring(len-1,1);
int ID=Convert.ToInt32(str2)+1;
string Value=str1+ID.ToString();
txthy_ID.Text=Value;
}
else
{
string str1=(row["hy_ID"].ToString()).Substring(0,len-2);
string str2=(row["hy_ID"].ToString()).Substring(len-2,2);
int ID=Convert.ToInt32(str2)+1;
string Value=str1+ID.ToString();
txthy_ID.Text=Value;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -