📄 webservice.cs
字号:
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System;
/// <summary>
/// Summary description for WebService.
/// </summary>
[WebServiceBinding(ConformanceClaims=WsiClaims.BP10,EmitConformanceClaims = true)]
public class WebService : System.Web.Services.WebService {
//该WebService主要用于执行数据库的存储过程
[WebMethod]
public DataSet orderinfo()//用于执行数据库中的orderinfo存储过程,返回客户订单详细信息
{
SqlConnection con=new SqlConnection();
con.ConnectionString="Server=localhost;Integrated Security=True;Database=flower;Persist Security Info=True";
con.Open();
SqlCommand com = new SqlCommand("orderinfo",con);//输入要执行的存储过程的名子
com.CommandType = CommandType.StoredProcedure;//指明要执行存储过程
SqlParameter parm=com.Parameters.Add("@userid",SqlDbType.VarChar ,20);//创建一个参数
parm.Value = Session["username"].ToString();//给该参数赋值
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = com;//执行存储过程
DataSet ds = new DataSet();
da.Fill(ds);//将存储过程结果添充到DS
con.Close();
return ds;
}
[WebMethod]
public int totalorder()//用于执行数据库中的totalorder存储过程,返回用户订单总数,用法同上
{
SqlConnection con=new SqlConnection();
con.ConnectionString="Server=localhost;Integrated Security=True;Database=flower;Persist Security Info=True";
con.Open();
SqlCommand com = new SqlCommand("totalorder",con);
com.CommandType = CommandType.StoredProcedure;
SqlParameter parm=com.Parameters.Add("@userid",SqlDbType.VarChar ,20);
parm.Value = Session["username"].ToString();
int a=(int)com.ExecuteScalar();
con.Close();
return a;
}
[WebMethod]
public double totalmoney()//用于执行数据库中的totalmoney存储过程,返回用户订单总额,用法同上
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Server=localhost;Integrated Security=True;Database=flower;Persist Security Info=True";
con.Open();
SqlCommand com = new SqlCommand("totalmoney", con);
com.CommandType = CommandType.StoredProcedure;
SqlParameter parm = com.Parameters.Add("@userid", SqlDbType.VarChar, 20);
parm.Value = Session["username"].ToString();
double a =Convert.ToDouble(com.ExecuteScalar());
con.Close();
return a;
}
[WebMethod]
public void updatelevel(string level)//用于执行数据库中的updatelevel存储过程,升级用户等级,用法同上
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Server=localhost;Integrated Security=True;Database=flower;Persist Security Info=True";
con.Open();
SqlCommand com = new SqlCommand("updatelevel", con);
com.CommandType = CommandType.StoredProcedure;
SqlParameter parm = com.Parameters.Add("@userid", SqlDbType.VarChar, 20);
parm.Value = Session["username"].ToString();
parm = com.Parameters.Add("@userlevel", SqlDbType.VarChar, 1);
parm.Value = level;
com.ExecuteNonQuery();
}
[WebMethod]
public int selectlevel()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Server=localhost;Integrated Security=True;Database=flower;Persist Security Info=True";
con.Open();
SqlCommand com = new SqlCommand("selectlevel", con);
com.CommandType = CommandType.StoredProcedure;
SqlParameter parm = com.Parameters.Add("@userid", SqlDbType.VarChar, 20);
parm.Value = Session["username"].ToString();
int result = Convert.ToInt32(com.ExecuteScalar());
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -