页面一:
<%@ Page Language="C#" MasterPageFile="~/MasterPage/MasterXP.master" AutoEventWireup="true" CodeFile="DrugList.aspx.cs" Inherits="ViewPage_DrugList" Title="药品信息" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>
<fieldset>
<legend >查询条件</legend>
<table style ="width :100%; text-align :center ">
<tr style ="width :100%; text-align :center ">
<td style ="width :100%; text-align :center "><asp:Label ID ="lbldrugName" runat ="server" Text ="药品名称"></asp:Label>
<asp:TextBox ID ="txtTiaoJianDrugName" runat ="server" Width="20%" AutoComplete="Off"></asp:TextBox>
</td>
</tr>
<tr style ="width :100%; text-align :center ">
<td style ="width :100%; text-align :center ">
<asp:Button ID ="btnQueryDrugName" runat ="server" Text ="查询" PostBackUrl="~/ViewPage/ShowDrugInfor.aspx" />
<asp:Button ID="btnAddInfor" runat ="server" Text ="新增"
οnclick="btnAddInfor_Click" />
</td>
</tr>
</table>
</fieldset>
<div >
<asp:ScriptManager ID ="SMShowAllInformation" runat ="server" EnablePartialRendering ="true" ></asp:ScriptManager>
<asp:UpdatePanel ID ="updatePanelAllInformation" runat ="server" UpdateMode ="Always" >
<ContentTemplate>
<div id ="display" runat ="server" ></div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</asp:Content>
页面二:
<%@ Page Language="C#" MasterPageFile="~/MasterPage/MasterXP.master" AutoEventWireup="true" CodeFile="ShowDrugInfor.aspx.cs" Inherits="ViewPage_ShowDrugInfor" Title="无标题页" %>
<%@ PreviousPageType VirtualPath ="~/ViewPage/DrugList.aspx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table cellpadding ="1" cellspacing="0" border ="0" width ="100%" bgcolor="#7e7e7e">
<tr>
<td align ="center" style ="width :100%" valign ="top">
<table cellpadding ="1" cellspacing ="0" border ="0" width ="100%" bgcolor="#7e7e7e">
<tr>
<td colspan ="4" style =" text-align :center; background-color :#7e7e7e"><strong >药品基本信息</strong></td>
</tr>
<tr bgcolor="#ffffff">
<td style =" width :20%; text-align :left ">药品编号</td>
<td style =" width :30%"> <asp:TextBox runat ="server" ID ="txtDrugID"></asp:TextBox></td>
<td style =" width :20%; text-align :left">药品名称</td>
<td style ="width :30%"><asp:TextBox runat="server" ID ="txtDrugName"></asp:TextBox></td>
</tr>
<tr bgcolor="#ffffff">
<td style ="width :20%; text-align :left ">药品单价(元)</td>
<td style="width :30%"><asp:TextBox runat ="server" ID ="txtDrugPrice"></asp:TextBox></td>
<td style ="width :20%; text-align :left ">库存数量</td>
<td style =" width :30%"><asp:TextBox runat ="server" ID="txtCount"></asp:TextBox></td>
</tr>
<tr bgcolor="#ffffff">
<td style ="width :20%; text-align :left ">药品归类</td>
<td style="width :30%"><asp:TextBox runat ="server" ID="txtClasser"></asp:TextBox></td>
<td style ="width :20%; text-align :left ">计量单位</td>
<td style =" width :30%"><asp:TextBox runat ="server" ID ="txtUnit"></asp:TextBox></td>
</tr>
<tr bgcolor="#ffffff">
<td style ="width :20%; text-align :left ">生产商</td>
<td style="width :30%"><asp:TextBox runat ="server" ID ="txtProduce"></asp:TextBox></td>
<td style ="width :20%; text-align :left ">有效期</td>
<td style =" width :30%"><asp:TextBox runat ="server" ID ="txtValidity"></asp:TextBox></td>
</tr>
<tr bgcolor="#ffffff">
<td style ="width:20%; text-align :left">药品功效</td>
<td style ="width :80%" colspan ="3" ><asp:TextBox runat ="server" ID="txtEfficacy"></asp:TextBox></td>
</tr>
<tr bgcolor="#ffffff">
<td colspan ="4" style ="width :100%; text-align :center ">
<asp:Button runat ="server" ID ="btnUpdate" Text ="修改(U)"
οnclick="btnUpdate_Click" />
<asp:Button runat ="server" ID ="btnDelete" Text ="删除(D)"
οnclick="btnDelete_Click" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Content>
页面一的代码如下:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Sql;
using System.Data.SqlClient;
public partial class ViewPage_DrugList : System.Web.UI.Page
{
classConn DrugInforCon = new classConn(); //classconn 是一个类,用于从config中来实现数据库的链接
public string strcon;
public int totalInfor=0;
public int pagesize = 5;
public int pageCount = 0;
protected void Page_Load(object sender, EventArgs e)
{
dbBind();
}
protected void dbBind()
{
strcon = DrugInforCon.Greensqlcon();
SqlConnection con = new SqlConnection(strcon);
con.Open();
string sqlstr1 = "select * from DrugInformation";
SqlDataAdapter da = new SqlDataAdapter(sqlstr1, con);
DataSet ds = new DataSet();
da.Fill(ds, "DrugInformation");
string StrResultsHolder;
StrResultsHolder = "<table border=1>";
StrResultsHolder += "<tr>";
ds.Tables["DrugInformation"].Columns[0].ColumnName = "DrugID";
ds.Tables["DrugInformation"].Columns[1].ColumnName = "DrugName";
ds.Tables["DrugInformation"].Columns[2].ColumnName = "DrugPrice";
ds.Tables["DrugInformation"].Columns[3].ColumnName = "DrugCount";
ds.Tables["DrugInformation"].Columns[4].ColumnName = "DrugClasser";
ds.Tables["DrugInformation"].Columns[5].ColumnName = "DrugUnit";
ds.Tables["DrugInformation"].Columns[6].ColumnName = "Producer";
ds.Tables["DrugInformation"].Columns[7].ColumnName = "ValidityDate";
ds.Tables["DrugInformation"].Columns[8].ColumnName = "ProduceEfficacy";
foreach (DataColumn C in ds.Tables["DrugInformation"].Columns)
{
StrResultsHolder += "<td>" + C.ColumnName + "</td>";
}
StrResultsHolder += "</tr>";
foreach (DataRow R in ds.Tables["DrugInformation"].Rows)
{
StrResultsHolder += "<tr><td width=10%>" + R["DrugID"] + "</td>" + "<td width=10%>" + R["DrugName"] + "</td>" + "<td width=10%>" + R["DrugPrice"] + "</td>" +
"<td width=10%>" + R["DrugCount"] + "</td>" + "<td width=10%>" + R["DrugClasser"] + "</td>" + "<td width=10%>" + R["DrugUnit"] + "</td>" +
"<td width=10%>" + R["Producer"] + "</td>" + "<td width=10%>" + R["ValidityDate"] + "</td>" + "<td width=20%>" + R["ProduceEfficacy"] + "</td></tr>";
}
StrResultsHolder += "</table>";
display.InnerHtml = StrResultsHolder;
}
protected void btnAddInfor_Click(object sender, EventArgs e)
{
Response.Redirect("~/ViewPage/MedicineAdd.aspx", true);
}
public TextBox DrugListText
{
get { return txtTiaoJianDrugName; } //把txtTiaoJianDrugName公开,使其能够在ShowDrugInfor页面获取
}
}
页面二的.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Sql;
using System.Data.SqlClient;
public partial class ViewPage_ShowDrugInfor : System.Web.UI.Page
{
WebService ss = new WebService();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox textValue = PreviousPage.DrugListText;
string QueryValue = textValue.Text;
SqlDataReader inforValue = ss.getInformationForQuery(QueryValue, "GetSingleDrugInfor");
if (inforValue.HasRows)
{
while (inforValue.Read())
{
txtDrugID.Text = inforValue["DrugID"].ToString();
txtDrugName.Text = inforValue["DrugName"].ToString();
txtDrugPrice.Text = inforValue["DrugPrice"].ToString();
txtCount.Text = inforValue["DrugCount"].ToString();
txtClasser.Text = inforValue["DrugClasser"].ToString();
txtEfficacy.Text = inforValue["ProduceEfficacy"].ToString();
txtProduce.Text = inforValue["Producer"].ToString();
txtUnit.Text = inforValue["DrugUnit"].ToString();
txtValidity.Text = inforValue["ValidityDate"].ToString();
txtDrugName.ReadOnly = true;
}
}
}
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
string updateDrugID = txtDrugID.Text.ToString();
string updateDrugName = txtDrugName.Text.ToString();
string updateDrugPrice = txtDrugPrice.Text.ToString();
string updateDrugCount = txtCount.Text.ToString();
string updateDrugUnit = txtUnit.Text.ToString();
string updateDrugProduce = txtProduce.Text.ToString();
string updateEfficacy = txtEfficacy.Text.ToString();
DateTime updateValidity = Convert.ToDateTime(txtValidity.Text.ToString());
string updateclasser = txtClasser.Text.ToString();
bool UpYesOrNO = ss.UpdateDrugInfor(updateDrugID, updateDrugName, updateDrugPrice, updateDrugCount, updateclasser, updateDrugUnit,updateDrugProduce, updateValidity, updateEfficacy, "UpdateDrugInfor");
if (UpYesOrNO)
{
ClientScript.RegisterOnSubmitStatement(this.GetType(), "Information", "<script language='JavaScript' defer> alert('修改成功!');windows.close();</script>");
txtClasser.Text = null; txtCount.Text = null; txtDrugID.Text = null; txtDrugName.Text = null; txtDrugPrice.Text = null;
txtEfficacy.Text = null; txtProduce.Text = null; txtUnit.Text = null; txtValidity.Text = null;
Response .Redirect ("~/ViewPage/DrugList.aspx",true );
}
else
{
ClientScript.RegisterOnSubmitStatement(this.GetType(), "Information", "<script language='JavaScript' defer> alert('修改失败!');windows.close();</script>");
txtClasser.Text = null; txtCount.Text = null; txtDrugID.Text = null; txtDrugName.Text = null; txtDrugPrice.Text = null;
txtEfficacy.Text = null; txtProduce.Text = null; txtUnit.Text = null; txtValidity.Text = null;
Response.Redirect("~/ViewPage/DrugList.aspx", true);
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
string DeleteName = txtDrugName.Text.ToString();
txtDrugName.ReadOnly = true;
bool DeleteY_N = ss.DeleteDrugInformation(DeleteName, "DeleteDrugInformation");
if (DeleteY_N)
{
ClientScript.RegisterOnSubmitStatement(this.GetType(), "Information", "<script language='JavaScript' defer> alert('删除成功!');windows.close();</script>");
Response.Redirect("~/ViewPage/DrugList.aspx", true);
}
else
{
ClientScript.RegisterOnSubmitStatement(this.GetType(), "Information", "<script language='JavaScript' defer> alert('删除失败!');windows.close();</script>");
Response.Redirect("~/ViewPage/DrugList.aspx", true);
}
}
}
用到的webservice:
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data ;
using System.Data.Sql;
using System.Data.SqlClient;
/// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
classConn greenconn = new classConn();
public string str;
[webmethod]
public bool addDrugInforWeb(string MID, string MName, string Mprice,int MCount,int MClasser,string MUnit,string MProduce, DateTime MValidity, string MEfficacy, string AddDrugInfor)
{
str = greenconn.Greensqlcon();
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand cmd = new SqlCommand(AddDrugInfor, con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter id = new SqlParameter("@DrugID", DbType.String);
SqlParameter name= new SqlParameter("@DrugName", DbType.String);
SqlParameter price = new SqlParameter("@DrugPrice", DbType.String);
SqlParameter count = new SqlParameter("@DrugCount", DbType.Int32 );
SqlParameter classer = new SqlParameter("@DrugClasser", DbType.Int32 );
SqlParameter Drugunit = new SqlParameter("@DrugUnit", DbType.String);
SqlParameter producer=new SqlParameter ("@Producer",DbType.String );
SqlParameter data = new SqlParameter("@ValidityData", DbType.DateTime);
SqlParameter efficacy = new SqlParameter("@ProduceEfficacy", DbType.String);
id.Value = MID;
name.Value = MName;
price.Value = Mprice;
count.Value = MCount;
classer.Value = MClasser;
Drugunit.Value = MUnit;
producer.Value = MProduce;
data.Value = MValidity;
efficacy.Value = MEfficacy;
cmd.Parameters.Add(id);
cmd.Parameters.Add(name);
cmd.Parameters.Add(price);
cmd.Parameters.Add(count);
cmd.Parameters.Add(classer);
cmd.Parameters.Add(Drugunit);
cmd.Parameters.Add(producer);
cmd.Parameters.Add(data);
cmd.Parameters.Add(efficacy);
if (cmd.ExecuteNonQuery()== 1)
{ return true; }
else
{ return false; }
}
[WebMethod] //从textbox中获取值,用于信息的查询
public SqlDataReader getInformationForQuery(string drugname,string GetSingleDrugInfor)
{
str = greenconn.Greensqlcon();
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlCommand cmd = new SqlCommand(GetSingleDrugInfor, conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter name = new SqlParameter("@DrugName", DbType.String);
name.Value = drugname;
cmd.Parameters.Add(name);
SqlDataReader dr = cmd.ExecuteReader();
return dr;
}
[WebMethod] //修改数据库信息
public bool UpdateDrugInfor(string UpDrugID, string UpDrugName, string UpPrice, string UpCount, string UpClasser, string UpUnit, string UpProduce, DateTime UpValidity, string UpEfficacy, string UpdateDrugInfor)
{
str= greenconn.Greensqlcon();
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlCommand cmd=new SqlCommand (UpdateDrugInfor ,conn );
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter DrugID = new SqlParameter("@DrugID", DbType.String);
SqlParameter DrugName = new SqlParameter("@DrugName", DbType.String);
SqlParameter Price = new SqlParameter("@DrugPrice", DbType.String);
SqlParameter count = new SqlParameter("@DrugCount", DbType.String);
SqlParameter classer = new SqlParameter("@DrugClasser", DbType.String);
SqlParameter Drugunit = new SqlParameter("@DrugUnit", DbType.String);
SqlParameter produce = new SqlParameter("@Producer", DbType.String);
SqlParameter validity = new SqlParameter("@ValidityDate", DbType.String);
SqlParameter efficacy = new SqlParameter("@ProduceEfficacy", DbType.String);
DrugID.Value = UpDrugID; DrugName.Value = UpDrugName; Price.Value = UpPrice;
count.Value = UpCount; classer.Value = UpClasser; Drugunit.Value = UpUnit; produce.Value = UpProduce;
validity.Value = UpValidity; efficacy.Value = UpEfficacy;
cmd.Parameters.Add(DrugID); cmd.Parameters.Add(DrugName); cmd.Parameters.Add(Price); cmd.Parameters.Add(count);
cmd.Parameters.Add(classer); cmd.Parameters.Add(Drugunit); cmd.Parameters.Add(produce); cmd.Parameters.Add(validity); cmd.Parameters.Add(efficacy);
if (cmd.ExecuteNonQuery()==1)
{
return true;
}
else
{
return false;
}
}
[WebMethod] //删除信息
public bool DeleteDrugInformation(string DrugName, string DeleteDrugInformation)
{
str = greenconn.Greensqlcon();
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand cmd = new SqlCommand(DeleteDrugInformation, con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter name = new SqlParameter("@DrugName", DbType.String);
name.Value = DrugName;
cmd.Parameters.Add(name);
if (cmd.ExecuteNonQuery() == 1)
{ return true; }
else
{ return false; }
}
}