//ServerOperation类
public class ServerOperation
{
private const string PARM_QQ_NUMBER = "@ListQQ";
private const string SQL_INSERT_SERVER = "INSERT INTO QQList VALUES(@ListQQ)";
private const string SQL_DELECT_SERVER = "DELETE QQList WHERE ListQQ=@ListQQ";
public ServerOperation()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public bool InSertService(String qqnumber)
{
StringBuilder strsql = new StringBuilder();
SqlParameter parm = new SqlParameter(PARM_QQ_NUMBER, SqlDbType.NVarChar, 20);
SqlCommand CMD = new SqlCommand();
parm.Value = qqnumber;
CMD.Parameters.Add(parm);
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
strsql.Append(SQL_INSERT_SERVER);
conn.Open();
CMD.Connection = conn;
CMD.CommandType = CommandType.Text;
CMD.CommandText = strsql.ToString();
int val = CMD.ExecuteNonQuery();
CMD.Parameters.Clear();
if (val > 0)
{
return true;
}
else
{
return false;
}
}
}
public bool deleteService(String qqnumber)
{
StringBuilder strsql = new StringBuilder();
SqlParameter parm = new SqlParameter(PARM_QQ_NUMBER, SqlDbType.NVarChar, 20);
SqlCommand CMD = new SqlCommand();
parm.Value = qqnumber;
CMD.Parameters.Add(parm);
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
strsql.Append(SQL_DELECT_SERVER);
conn.Open();
CMD.Connection = conn;
CMD.CommandType = CommandType.Text;
CMD.CommandText = strsql.ToString();
int val = CMD.ExecuteNonQuery();
CMD.Parameters.Clear();
if (val > 0)
{
return true;
}
else
{
return false;
}
}
}
}
//提交页面
protected void Button1_Click(object sender, EventArgs e)
{
ServerOperation myserver = new ServerOperation();
bool result = myserver.InSertService(TextBox1.Text);
if (result)
{
Literall.Text = "成功";
ListBox1.DataBind();
TextBox1.Text = "";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
ServerOperation myserver = new ServerOperation();
bool result = myserver.deleteService(ListBox1.SelectedValue);
if (result)
{
Literall.Text = "成功";
ListBox1.DataBind();
}
}