using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using web;
using System.Data.SqlClient;
using System.Data;
public partial class buy2 : System.Web.UI.Page
{
public string comment;
public static int g;
public float gold;
public int goldoffer;
public static int id;
public int igold;
public int iprice;
public int iyb;
public int isbb;
public static int itemid;
public string name;
public static int p;
public string pic;
public float price;
public int priceoffer;
public string vip;
public float yuanbao;
public static int yb;
public int yboffer;
public string YUANBAOSHOPURLS
{
get
{
if (base.Request.QueryString["ybshop"] != null && base.Request.QueryString["ybshop"].ToString() == "1")
{
return "1";
}
return "0";
}
}
public bool YUANBAOSHOP
{
get
{
if (YUANBAOSHOPURLS == "1")
{
return true;
}
return false;
}
}
public string SHOWYUANBAOSHOP
{
get
{
if (YUANBAOSHOP)
{
return "none";
}
return "inline";
}
}
private void InitializeComponent()
{
this.Submit1.ServerClick += new EventHandler(this.Submit1_ServerClick);
this.Submit2.ServerClick += new EventHandler(this.Submit2_ServerClick);
base.Load += new EventHandler(this.Page_Load);
}
protected override void OnInit(EventArgs e)
{
this.InitializeComponent();
base.OnInit(e);
}
protected void Page_Load(object sender, EventArgs e)
{
if (YUANBAOSHOP)
{
Submit1.Visible = true;
Submit2.Visible = false;
}
else
{
Submit1.Visible = true;
Submit2.Visible = true;
}
if (this.Session["useridx"] != null)
{
if (!this.Page.IsPostBack)
{
this.DropDownList1.DataSource = new DataProviders().ExecuteSqlDs("select character_idx,character_name from mhgame..tb_character where substring(character_name,1,1)!='@' and user_idx=" + this.Session["useridx"].ToString(), "DropDownList1");
this.DropDownList1.DataTextField = "character_name";
this.DropDownList1.DataValueField = "character_idx";
this.DropDownList1.DataBind();
for (int i = 0; i < this.DropDownList1.Items.Count; i++)
{
this.DropDownList1.Items[i].Text = new system().ConvertToBig5(this.DropDownList1.Items[i].Text.ToString(), 950);
}
}
}
else
{
base.Response.Redirect("login.aspx?returnurl=/shop.aspx");
}
if (base.Request.QueryString["id"] != null)
{
DataProviders providers = new DataProviders();
id = int.Parse(base.Request.QueryString["ID"]);
SqlDataReader reader = providers.ExecuteSqlDataReader("select a.*,b.isbb from web_item a,web_itemtype b where a.type=b.id and a.id=" + id);
if (reader.Read())
{
this.name = reader["name"].ToString();
this.comment = reader["comment"].ToString();
itemid = int.Parse(reader["itemid"].ToString());
this.isbb = int.Parse(reader["isbb"].ToString());
this.pic = reader["pic"].ToString();
this.price = float.Parse(reader["price"].ToString());
this.gold = float.Parse(reader["gold"].ToString());
this.yuanbao = float.Parse(reader["yuanbao"].ToString());
this.iprice = (int)this.price;
this.igold = (int)this.gold;
this.iyb = (int)this.yuanbao;
this.priceoffer = (int)(this.price * float.Parse(base.Application["game.vipoffer"].ToString()));
this.goldoffer = (int)(this.gold * float.Parse(base.Application["game.vipoffer"].ToString()));
this.yboffer = (int)(this.yuanbao * float.Parse(base.Application["game.vipoffer"].ToString()));
p = (int)this.price;
g = (int)this.gold;
yb = (int)this.yuanbao;
if (this.Session["weblevel"].ToString() == "1")
{
p = this.priceoffer;
g = this.goldoffer;
yb = this.yboffer;
this.vip = "黃金會員";
}
if (this.Session["weblevel"].ToString() == "2")
{
p = this.priceoffer;
g = this.goldoffer;
yb = this.yboffer;
this.vip = "白金會員";
}
if (this.Session["weblevel"].ToString() == "3")
{
p = this.priceoffer;
g = this.goldoffer;
yb = this.yboffer;
this.vip = "鑽石會員";
}
else if (this.Session["weblevel"].ToString() == "0")
{
p = (int)this.price;
g = (int)this.gold;
yb = this.yboffer;
this.vip = "普通會員";
}
}
else
{
reader.Close();
providers.CloseConn();
base.Response.Redirect("shop.aspx");
}
reader.Close();
providers.CloseConn();
if (igold == 0 && iyb > 0) Submit2.Visible = false;
}
else
{
base.Response.Redirect("shop.aspx");
}
}
private void Submit1_ServerClick(object sender, EventArgs e)
{
if (this.DropDownList1.Items.Count == 0)
{
base.Response.Write("");
}
else
{
int chaidxs = int.Parse(this.DropDownList1.SelectedValue);
int useridx = int.Parse(this.Session["useridx"].ToString());
string str = buyitem(this.Session["userid"].ToString(), useridx, chaidxs, itemid, p, g, yb, this.isbb, 0);
base.Response.Write("");
}
}
private void Submit2_ServerClick(object sender, EventArgs e)
{
if (this.DropDownList1.Items.Count == 0)
{
base.Response.Write("");
}
else
{
int chaidxs = int.Parse(this.DropDownList1.SelectedValue);
int useridx = int.Parse(this.Session["useridx"].ToString());
string str = buyitem(this.Session["userid"].ToString(), useridx, chaidxs, itemid, p, g, yb, this.isbb, 1);
base.Response.Write("");
}
}
public string buyitem(string userid, int useridx, int chaidxs, int itemid, int price, int gold, int yb, int isbb, int kind)
{
int num;
SqlParameter[] parameters = new SqlParameter[]
{ new SqlParameter("@userid", SqlDbType.VarChar, 50), new SqlParameter("@useridx", SqlDbType.Int, 8),
new SqlParameter("@chaidx", SqlDbType.Int, 8), new SqlParameter("@itemid", SqlDbType.Int, 8),
new SqlParameter("@price", SqlDbType.Int, 8), new SqlParameter("@gold", SqlDbType.Int, 8),
new SqlParameter("@yb", SqlDbType.Int, 8), new SqlParameter("@kind", SqlDbType.Int, 8),
new SqlParameter("@isbb", SqlDbType.Int, 8) };
parameters[0].Value = userid;
parameters[1].Value = useridx;
parameters[2].Value = chaidxs;
parameters[3].Value = itemid;
parameters[4].Value = price;
parameters[5].Value = gold;
parameters[6].Value = yb;
parameters[7].Value = kind;
parameters[8].Value = isbb;
switch (new DataProviders().RunProcedure("Web_BuyItem", parameters, out num))
{
case 0:
this.Session["webgold"] = int.Parse(this.Session["webgold"].ToString()) - gold;
return "物品購買成功,請登陸遊戲使用,普通物品放在物品欄,百寶物品放在百寶倉庫。";
case 1:
return "請先退出遊戲至登陸界面後再來購物!";
case 2:
return "沒有這個角色!";
case 3:
return "物品ID不正確,請聯繫管理員小墨或小香!";
case 4:
return "你的金幣不夠哦,請再仔細核實價格!";
case 44:
return "你的元寶不夠哦,請再仔細核實價格!";
case 5:
return "你的遊戲幣不夠哦,請再仔細核實價格!";
case 6:
return "你的物品欄已經滿了,去清空一下再來吧!";
case 7:
return "你的百寶倉庫已經滿了,去清空一下再來吧!";
}
return "系統級錯誤,請聯繫管理員!";
}
}