📄 t_ycy.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.Data.SqlClient;
using System.Configuration;
using gyit.Data;
namespace itcrm.jxcManager
{
/// <summary>
/// t_ycy 的摘要说明。
/// </summary>
public class t_ycy : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtRemark;
protected System.Web.UI.WebControls.TextBox txtPlaceID;
protected System.Web.UI.WebControls.TextBox txtbz_ID;
protected System.Web.UI.WebControls.TextBox txtPlace;
protected System.Web.UI.WebControls.TextBox txtTime;
protected System.Web.UI.WebControls.TextBox txtWeight;
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.TextBox txtSe;
protected System.Web.UI.WebControls.TextBox txtThg;
protected System.Web.UI.WebControls.TextBox txtMhg;
protected System.Web.UI.WebControls.TextBox txtValue;
protected System.Web.UI.WebControls.TextBox txtBound;
protected System.Web.UI.WebControls.Button btnAdd;
protected System.Web.UI.WebControls.Button btnClear;
protected System.Web.UI.WebControls.TextBox txtycy_ID;
protected System.Web.UI.WebControls.TextBox txtdq_ID;
protected System.Web.UI.WebControls.TextBox txthy_ID;
DBOperator db;
protected System.Web.UI.WebControls.Button brnReturn;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator3;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator4;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator5;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator6;
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)
{
txtTime.Text=System.DateTime.Now.ToShortDateString();
if(vid!=null)
{
QueryEdit(vid);
txtycy_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.brnReturn.Click += new System.EventHandler(this.brnReturn_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[15];
object[] strValues=new object[15];
strPara[0]="@ycy_ID";
strPara[1]="@dq_ID";
strPara[2]="@PlaceID";
strPara[3]="@hy_ID";
strPara[4]="@bz_ID";
strPara[5]="@Place";
strPara[6]="@Time";
strPara[7]="@Weight";
strPara[8]="@Name";
strPara[9]="@Se";
strPara[10]="@Mhg";
strPara[11]="@Thg";
strPara[12]="@Value";
strPara[13]="@Bound";
strPara[14]="@Remark";
strValues[0]=txtycy_ID.Text;
strValues[1]=txtdq_ID.Text;
strValues[2]=txtPlaceID.Text;
strValues[3]=txthy_ID.Text;
strValues[4]=txtbz_ID.Text;
strValues[5]=txtPlace.Text;
strValues[6]=txtTime.Text;
strValues[7]=txtWeight.Text;
strValues[8]=txtName.Text;
strValues[9]=txtSe.Text;
strValues[10]=txtThg.Text;
strValues[11]=txtMhg.Text;
strValues[12]=txtValue.Text;
strValues[13]=txtBound.Text;
strValues[14]=txtRemark.Text;
try
{
if(txtycy_ID.Text!="")
{
if(txtdq_ID.Text!="")
{
if(txthy_ID.Text!="")
{
if(txtbz_ID.Text!="")
{
if(txtName.Text!="")
{
if(vid!=null)
{
db.Open();
db.exeProc("Update_t_ycy",strPara,strValues);
db.Close();
Page.RegisterStartupScript("script","<script>alert('修改记录成功!')</script>");
}
else
{
db.Open();
db.exeProc("Add_t_ycy",strPara,strValues);
db.Close();
Page.RegisterStartupScript("script","<script>alert('增加记录成功!')</script>");
btnClear_Click(sender,e);
Refresh();
}
}
else{Page.RegisterStartupScript("script","<script>alert('鱼名称不能为空!')</script>");}
}
else{Page.RegisterStartupScript("script","<script>alert('标准编号不能为空!')</script>");}
}
else{Page.RegisterStartupScript("script","<script>alert('行业编号不能为空!')</script>");}
}
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="sender"></param>
/// <param name="e"></param>
private void btnClear_Click(object sender, System.EventArgs e)
{
//txtycy_ID.Text="";
txtdq_ID.Text="";
txtPlaceID.Text="";
txthy_ID.Text="";
txtbz_ID.Text="";
txtPlace.Text="";
//txtTime.Text="";
txtWeight.Text="";
txtName.Text="";
txtSe.Text="";
txtThg.Text="";
txtMhg.Text="";
txtValue.Text="";
txtBound.Text="";
txtRemark.Text="";
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="who"></param>
private void QueryEdit(string who)
{
string strSql="select * from t_ycy where ycy_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];
txtycy_ID.Text=row["ycy_ID"].ToString();
txtdq_ID.Text=row["dq_ID"].ToString();
txtPlaceID.Text=row["PlaceID"].ToString();
txthy_ID.Text=row["hy_ID"].ToString();
txtbz_ID.Text=row["bz_ID"].ToString();
txtPlace.Text=row["Place"].ToString();
txtTime.Text=row["Time"].ToString();
txtWeight.Text=row["Weight"].ToString();
txtName.Text=row["Name"].ToString();
txtSe.Text=row["Se"].ToString();
txtMhg.Text=row["Mhg"].ToString();
txtThg.Text=row["Thg"].ToString();
txtValue.Text=row["Value"].ToString();
txtBound.Text=row["Bound"].ToString();
txtRemark.Text=row["Remark"].ToString();
ds.Dispose();
}
}
private void brnReturn_Click(object sender, System.EventArgs e)
{
Page.Response.Redirect("t_ycyAdd.aspx");
}
/// <summary>
/// 自动获得编号
/// </summary>
private void Refresh()
{
string ycy_ID=txtycy_ID.Text;
string strSql="select ycy_ID from t_ycy order by ID";
DataSet ds=null;
db.Open();
ds=db.exeSqlForDataSet(strSql);
db.Close();
int count=ds.Tables[0].Rows.Count;
if(count==0)
{
txtycy_ID.Text="200001";
}
else
{
count=ds.Tables[0].Rows.Count;
DataRow row=ds.Tables[0].Rows[count-1];
int len=row["ycy_ID"].ToString().Length;
string str=(row["ycy_ID"].ToString()).Substring(len-2,1);
if(str=="0")
{
string str1=(row["ycy_ID"].ToString()).Substring(0,len-1);
string str2=(row["ycy_ID"].ToString()).Substring(len-1,1);
int ID=Convert.ToInt32(str2)+1;
string Value=str1+ID.ToString();
txtycy_ID.Text=Value;
txtPlaceID.Text=Value;
}
else
{
string str1=(row["ycy_ID"].ToString()).Substring(0,len-2);
string str2=(row["ycy_ID"].ToString()).Substring(len-2,2);
int ID=Convert.ToInt32(str2)+1;
string Value=str1+ID.ToString();
txtycy_ID.Text=Value;
txtPlaceID.Text=Value;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -