📄 custometype.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.Shared;
using CrystalDecisions;
using CrystalDecisions.CrystalReports.Engine;
public partial class custometype : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindClassData();
}
}
private void BindClassData()
{
///获取用户数据
String s = "customertype";
edit cla = new edit();
DataSet dr = cla.GetCustomertypefo(s);
///设置GridView的数据源,并绑定数据
GridView.DataSource = dr;
GridView.DataBind();//数据绑定
///关闭数据读取器
// dr.Close();
}
protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
String ctcodeID;
// Int32.TryParse(GridView.Rows[e.NewEditIndex].Cells[0].Text, out ctcodeID);
ctcodeID = GridView.Rows[e.NewEditIndex].Cells[0].Text;
Response.Redirect("update1.aspx?ctcodeID=" + ctcodeID);
}
protected void GridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string temp = GridView.Rows[e.RowIndex].Cells[0].Text;
edit cla = new edit();
String cmdtext = "delete from customertype where customertpyecode=" + "'" + temp + "'";
cla.execute(cmdtext);
Response.Write("<script>alert('" + "更新数据成功,请妥善保管好数据!" + "');</script>");
BindClassData();
}
protected void CrystalReportViewer1_Init(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (ctypecode.Text.Trim().Equals(""))
{
Response.Write("<script>alert('" + "请重新填写!" + "');</script>");
}
else
{
String cmdtext = "insert into customertype values("
+ "'" + ctypecode.Text.Trim() + "',"
+ "'" + ctypename.Text.Trim() + "')";
int nResult = -1;
edit cla = new edit();
nResult = cla.execute(cmdtext);
if (nResult != -1)
{
Response.Write("<script>alert('" + "注册新客户类型!" + "');</script>");
ctypecode.Text = "";
ctypename.Text = "";
}
else
{
Response.Write("<script>alert('" + "有错误,请调试程序!" + "');</script>");
}
}
BindClassData();
}
protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView.PageIndex = e.NewPageIndex;
BindClassData();
}
protected void Button2_Click(object sender, EventArgs e)
{
string type = DropDownList1.SelectedValue.ToString();
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
///创建Command
/// SqlCommand myCommand = new SqlCommand("select * from " + table + "", myConnection);//table 为各个表
string cmd = "select * from customer,relation where customertypecode='" + type + "' and customer.customercode=relation.customercode";
SqlDataAdapter myda = new SqlDataAdapter(cmd , myConnection);
///定义DataSet
DataSet dr = new DataSet("typeDataset");
try
{
///打开链接
myConnection.Open();
///读取数据
myda.Fill(dr, "ctype");
// dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException ex)
{
///抛出异常
throw new Exception(ex.Message, ex) ;
}
finally
{
myConnection.Close();
}
///返回DataSet
if(dr.Tables[0].Rows.Count==0)
{
Response.Write("<script>alert('" + "没有相关纪录!" + "');</script>");
}
else
{
GridView1.DataSource = dr;
GridView1.DataBind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindClassData();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -