📄 addmsg_2.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace xajh.chat
{
/// <summary>
/// 使用物品。
/// </summary>
public class addmsg_2 : System.Web.UI.Page
{
private string[] v_max;
private int fg;
private void Page_Load(object sender, System.EventArgs e)
{
if (this.Session["info"] == null)
{
this.Response.Write ("<script language=javascript type=text/javascript>top.location.href='../error.aspx?v=relogin'</script>");
return;
}
x.UserInfo info = (x.UserInfo) this.Session["info"];
xajh.chat.msg chat = new xajh.chat.msg();
chat.Start(info.UserName, info.RoomID, info.LastSaid);
string v1 = this.Request.Form["v1"].Trim();//对谁
string v2 = this.Request.Form["v2"].Trim();//名称
int v3 = int.Parse(this.Request.Form["v3"]);//数量
if (v1 == "" || v1 == "大家" || v2 == "" || v3 <= 0)
{
return;
}
if (((x.RoomInfo) this.Application["byts_xajh_chat_roominfo_" + info.RoomID]).CanUseThing == false)
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('站长规定本房间禁止使用物品!')</script>");
return;
}
if (info.CloseDoor == true)
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('你目前处于闭关状态,无法使用物品!')</script>");
return;
}
string didid;
if (v1 == info.UserName)
{
didid = info.DataID;
}
else
{
if (((ArrayList) this.Application["byts_xajh_chat_online_" + info.RoomID]).IndexOf(v1) == -1)
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('该聊友不在本聊天室内,无法对其使用物品!')</script>");
return;
}
string[] toinfo = var.public_onlineinfo[v1].ToString().Split('|');
if (toinfo[7] == "true")
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('" + v1 + " 目前处于闭关状态,无法对其使用物品!')</script>");
return;
}
didid = toinfo[1];
}
OleDbConnection MyConn = new OleDbConnection(var.public_conn);
MyConn.Open();
OleDbCommand MyComm = new OleDbCommand(@"select * from [拥有物品] where [名称]=? and [拥有]='" + info.UserName + "' and [类型]<>'卡片'", MyConn);
MyComm.Parameters.Add(new System.Data.OleDb.OleDbParameter("名称", System.Data.OleDb.OleDbType.VarWChar, 10, "名称"));
MyComm.Parameters["名称"].Value = v2;
OleDbDataReader dr = MyComm.ExecuteReader();
if (dr.Read())
{
if ((bool)dr["针对自己"] != true && v1 == info.UserName)
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('" + v2 + " 不能对自己使用!')</script>");
dr.Close();
MyConn.Close();
MyConn.Dispose();
return;
}
if ((bool)dr["针对别人"] != true && v1 != info.UserName)
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('" + v2 + " 不能对别人使用!')</script>");
dr.Close();
MyConn.Close();
MyConn.Dispose();
return;
}
if ((int)dr["等级最小"] != -1 && info.Grade < (int)dr["等级最小"])
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('等级小于 " + dr["等级最小"] + " 不能使用 " + v2 + "!')</script>");
dr.Close();
MyConn.Close();
MyConn.Dispose();
return;
}
if ((int)dr["等级最大"] != -1 && info.Grade > (int)dr["等级最大"])
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('等级大于 " + dr["等级最大"] + " 不能使用 " + v2 + "!')</script>");
dr.Close();
MyConn.Close();
MyConn.Dispose();
return;
}
if ((int)dr["战级最小"] != -1 && info.FGrade < (int)dr["战级最小"])
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('战斗等级小于 " + dr["战级最小"] + " 不能使用 " + v2 + "!')</script>");
dr.Close();
MyConn.Close();
MyConn.Dispose();
return;
}
if ((int)dr["战级最大"] != -1 && info.FGrade > (int)dr["战级最大"])
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('战斗等级大于 " + dr["战级最大"] + " 不能使用 " + v2 + "!')</script>");
dr.Close();
MyConn.Close();
MyConn.Dispose();
return;
}
if ((int)dr["会员最小"] != -1 && info.Gold < (int)dr["会员最小"])
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('会员等级小于 " + dr["会员最小"] + " 不能使用 " + v2 + "!')</script>");
dr.Close();
MyConn.Close();
MyConn.Dispose();
return;
}
if ((int)dr["会员最大"] != -1 && info.Gold > (int)dr["会员最大"])
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('会员等级大于 " + dr["会员最大"] + " 不能使用 " + v2 + "!')</script>");
dr.Close();
MyConn.Close();
MyConn.Dispose();
return;
}
if (dr["性别限制"].ToString() == "boy" && info.Sex != "boy")
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('性别必须为 男 才能使用 " + v2 + "!')</script>");
dr.Close();
MyConn.Close();
MyConn.Dispose();
return;
}
if (dr["性别限制"].ToString() == "girl" && info.Sex != "girl")
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('性别必须为 女 才能使用 " + v2 + "!')</script>");
dr.Close();
MyConn.Close();
MyConn.Dispose();
return;
}
if (v3 > (int)dr["数量"])
{
this.Response.Write ("<script language=javascript type=text/javascript>alert('你只有 " + dr["数量"] + " 件 " + v2 + ",不能使用 " + v3 + " 件!')</script>");
dr.Close();
MyConn.Close();
MyConn.Dispose();
return;
}
string othertj = dr["其他限制"].ToString();
string c1 = dr["字段名称1"].ToString();
int c1_sta = (int) dr["数值开始1"];
int c1_end = (int) dr["数值结束1"];
string c2 = dr["字段名称2"].ToString();
int c2_sta = (int) dr["数值开始2"];
int c2_end = (int) dr["数值结束2"];
string c3 = dr["字段名称3"].ToString();
int c3_sta = (int) dr["数值开始3"];
int c3_end = (int) dr["数值结束3"];
string updatenumber;
if ((int)dr["数量"] == v3)
{
updatenumber = "delete from [拥有物品] where [id]=" + dr["id"];
}
else
{
updatenumber = "update [拥有物品] set [数量]=[数量]-" + v3 + " where [id]=" + dr["id"];
}
dr.Close();
if (othertj != "(无)")
{
MyComm.CommandText = @"select null from [注册用户] where [id]=" + info.DataID + " and " + othertj;
dr = MyComm.ExecuteReader();
if (dr.Read())
{
dr.Close();
}
else
{
dr.Close();
MyConn.Close();
MyConn.Dispose();
this.Response.Write ("<script language=javascript type=text/javascript>alert(\"必须符合 " + othertj + " 才能使用 " + v2 + "!\")</script>");
return;
}
}
string sql = "";
if (c1 != "(无)")
{
sql = "[" + c1 + "],";
}
if (c2 != "(无)")
{
sql += "[" + c2 + "],";
}
if (c3 != "(无)")
{
sql += "[" + c3 + "],";
}
MyComm.CommandText = @"select " + sql + "[会员],[等级],[战斗等级] from [注册用户] where [id]=" + didid;
dr = MyComm.ExecuteReader();
if (dr.Read())
{
v_max = var.public_goldmax[(int)dr["会员"]].Split('|');
switch (var.public_maxfor)
{
case "等级":
fg = (int) dr["等级"];
break;
case "战斗等级":
fg = (int) dr["战斗等级"];
break;
default:
fg = 1;
break;
}
System.Random MyRan = new System.Random();
sql = "";
string str = "";
int temp_int;
if (c1 != "(无)")
{
temp_int = MyRan.Next(c1_sta, c1_end + 1) * v3;
if (temp_int > 0)
{
str = c1 + "增加<font class=\\\"byts\\\">" + temp_int + "</font>,";
temp_int = checkint(c1, (int)dr[c1] + temp_int);
sql = "[" + c1 + "]=" + temp_int + ",";
}
else if (temp_int < 0)
{
str = c1 + "减少<font class=\\\"byts\\\">" + Math.Abs(temp_int) + "</font>,";
temp_int = checkint(c1, (int)dr[c1] - Math.Abs(temp_int));
sql = "[" + c1 + "]=" + temp_int + ",";
}
else
{
str = c1 + "无变化,";
}
}
if (c2 != "(无)")
{
temp_int = MyRan.Next(c2_sta, c2_end + 1) * v3;
if (temp_int > 0)
{
str += c2 + "增加<font class=\\\"byts\\\">" + temp_int + "</font>,";
temp_int = checkint(c2, (int)dr[c2] + temp_int);
sql += "[" + c2 + "]=" + temp_int + ",";
}
else if (temp_int < 0)
{
str += c2 + "减少<font class=\\\"byts\\\">" + Math.Abs(temp_int) + "</font>,";
temp_int = checkint(c2, (int)dr[c2] - Math.Abs(temp_int));
sql += "[" + c2 + "]=" + temp_int + ",";
}
else
{
str += c2 + "无变化,";
}
}
if (c3 != "(无)")
{
temp_int = MyRan.Next(c3_sta, c3_end + 1) * v3;
if (temp_int > 0)
{
str += c3 + "增加<font class=\\\"byts\\\">" + temp_int + "</font>,";
temp_int = checkint(c3, (int)dr[c3] + temp_int);
sql += "[" + c3 + "]=" + temp_int + ",";
}
else if (temp_int < 0)
{
str += c3 + "减少<font class=\\\"byts\\\">" + Math.Abs(temp_int) + "</font>,";
temp_int = checkint(c3, (int)dr[c3] - Math.Abs(temp_int));
sql += "[" + c3 + "]=" + temp_int + ",";
}
else
{
str += c3 + "无变化,";
}
}
dr.Close();
MyComm.CommandText = updatenumber;
MyComm.ExecuteNonQuery();
if (sql != "")
{
MyComm.CommandText = @"update [注册用户] set " + sql.Substring(0, sql.Length - 1) + " where [id]=" + didid;
MyComm.ExecuteNonQuery();
}
MyConn.Close();
MyConn.Dispose();
string[] aword = new string[9];
aword[0] = "ran";
aword[1] = info.UserName;
aword[2] = v1;
aword[3] = "sys.gif";
aword[4] = "";
aword[5] = "";
aword[6] = "##对%%使用了<font class=\\\"byts\\\">" + v3 + "</font>件<font class=\\\"byts\\\">" + v2 + "</font>,只见%%" + str.Substring(0, str.Length - 1) + "。";
aword[7] = "使用";
aword[8] = DateTime.Now.ToLongTimeString();
chat.Add(aword, info);
}
else
{
dr.Close();
MyConn.Close();
MyConn.Dispose();
this.Response.Write ("<script language=javascript type=text/javascript>alert('用户名未找到!')</script>");
}
}
else
{
dr.Close();
MyConn.Close();
MyConn.Dispose();
this.Response.Write ("<script language=javascript type=text/javascript>alert('不存在此物品!')</script>");
}
}
private int checkint(string v1, int v2)
{
if (v2 < 0)
{
v2 =0;
}
else
{
int maxnum;
switch(v1)
{
case "点券":
maxnum = int.Parse(v_max[0]) * fg;
break;
case "武功":
maxnum = int.Parse(v_max[1]) * fg;
break;
case "内力":
maxnum = int.Parse(v_max[2]) * fg;
break;
case "体力":
maxnum = int.Parse(v_max[3]) * fg;
break;
case "攻击":
maxnum = int.Parse(v_max[4]) * fg;
break;
case "防御":
maxnum = int.Parse(v_max[5]) * fg;
break;
case "智力":
maxnum = int.Parse(v_max[6]) * fg;
break;
case "生命":
maxnum = int.Parse(v_max[7]) * fg;
break;
case "魅力":
maxnum = int.Parse(v_max[8]) * fg;
break;
case "精确":
maxnum = int.Parse(v_max[9]) * fg;
break;
default:
maxnum = v2;
break;
}
if (v2 > maxnum)
{
v2 = maxnum;
}
}
return v2;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -