📄 tb_gwrbzadd.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_gwrbzAdd 的摘要说明。
/// </summary>
public class tb_gwrbzAdd : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtBM;
protected System.Web.UI.WebControls.TextBox txtBound;
protected System.Web.UI.WebControls.TextBox txtRemark;
protected System.Web.UI.WebControls.Button btnClear;
protected System.Web.UI.WebControls.Button btnReturn;
protected System.Web.UI.WebControls.Button btnAdd;
protected System.Web.UI.WebControls.TextBox txtbz_ID;
DBOperator db;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.TextBox txtValue;
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);
txtbz_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.btnAdd.Click += new System.EventHandler(this.btnAdd_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 btnAdd_Click(object sender, System.EventArgs e)
{
string[] strPara =new string[5];
object[] strValues=new object[5];
strPara[0]="@bz_ID";
strPara[1]="@BM";
strPara[2]="@Bound";
strPara[3]="@Value";
strPara[4]="@Remark";
strValues[0]=txtbz_ID.Text;
strValues[1]=txtBM.Text;
strValues[2]=txtBound.Text;
strValues[3]=txtValue.Text;
strValues[4]=txtRemark.Text;
try
{
if(txtbz_ID.Text!="")
{
if(txtBM.Text!="")
{
if(vid!=null)
{
string strSql="Update tb_gwrbz Set BM='"+txtBM.Text+"',Bound='"+txtBound.Text+"',Value='"+txtValue.Text+"',Remark='"+txtRemark.Text+"' where bz_ID='"+txtbz_ID.Text+"'";
db.Open();
db.exeSql(strSql);
db.Close();
Page.RegisterStartupScript("script","<script>alert('修改记录成功!')</script>");
}
else
{
db.Open();
db.exeProc("Add_tb_gwrbz",strPara,strValues);
db.Close();
Page.RegisterStartupScript("script","<script>alert('增加记录成功!')</script>");
txtBM.Text="";
txtValue.Text="";
txtBound.Text="";
txtRemark.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_gwrbz where bz_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];
txtbz_ID.Text=row["bz_ID"].ToString();
txtBM.Text=row["BM"].ToString();
txtValue.Text=row["Value"].ToString();
txtBound.Text=row["Bound"].ToString();
txtRemark.Text=row["Remark"].ToString();
ds.Dispose();
}
}
/// <summary>
/// 清除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnClear_Click(object sender, System.EventArgs e)
{
txtbz_ID.Text="";
txtBM.Text="";
txtValue.Text="";
txtBound.Text="";
txtRemark.Text="";
}
private void btnReturn_Click(object sender, System.EventArgs e)
{
Page.Response.Redirect("tb_gwrbz.aspx");
}
/// <summary>
/// 自动获得编号
/// </summary>
private void Refresh()
{
string dq_ID=txtbz_ID.Text;
string strSql="select bz_ID from tb_gwrbz order by ID";
DataSet ds=null;
db.Open();
ds=db.exeSqlForDataSet(strSql);
db.Close();
int count=ds.Tables[0].Rows.Count;
if(count==0)
{
txtbz_ID.Text="100001";
}
else
{
count=ds.Tables[0].Rows.Count;
DataRow row=ds.Tables[0].Rows[count-1];
int len=row["bz_ID"].ToString().Length;
string str=(row["bz_ID"].ToString()).Substring(len-2,1);
if(str=="0")
{
string str1=(row["bz_ID"].ToString()).Substring(0,len-1);
string str2=(row["bz_ID"].ToString()).Substring(len-1,1);
int ID=Convert.ToInt32(str2)+1;
string Value=str1+ID.ToString();
txtbz_ID.Text=Value;
}
else
{
string str1=(row["bz_ID"].ToString()).Substring(0,len-2);
string str2=(row["bz_ID"].ToString()).Substring(len-2,2);
int ID=Convert.ToInt32(str2)+1;
string Value=str1+ID.ToString();
txtbz_ID.Text=Value;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -