/// <summary> /// Request for buy an item. /// </summary> /// <param name="callback"></param> public static void RequestBuyItem(string itemid, int quantity, GrdEventHandler <GrdPurchaseRequest> callback) { Dictionary <string, string> pars = new Dictionary <string, string>(); pars["itemid"] = itemid; pars["quantity"] = quantity.ToString(); handler.Post((data) => { Dictionary <string, object> result = GetObjectData(data); if (callback != null) { int error = int.Parse(result["error"].ToString()); GrdEventArgs <GrdPurchaseRequest> args = null; if (error == 0) { GrdPurchaseRequest request = new GrdPurchaseRequest(); request.RequestId = result["requestid"].ToString(); args = new GrdEventArgs <GrdPurchaseRequest>(error, "", data, request); } else { args = new GrdEventArgs <GrdPurchaseRequest>(error, result["message"].ToString(), data, null); } callback(error, args); } }, "requestpurchase", pars); }
public static void CheckItemStatus(string requestid, GrdEventHandler <GrdPurchaseStatus> callback) { Dictionary <string, string> pars = new Dictionary <string, string>(); pars["requestid"] = requestid; handler.Post((data) => { Dictionary <string, object> result = GetObjectData(data); if (callback != null) { int error = int.Parse(result["error"].ToString()); string msg = ""; GrdPurchaseStatus status = GrdPurchaseStatus.NewRequest; if (error != 0) { msg = result["message"].ToString(); } else { status = (GrdPurchaseStatus)int.Parse(result["status"].ToString()); } GrdEventArgs <GrdPurchaseStatus> args = new GrdEventArgs <GrdPurchaseStatus>(error, msg, data, status); callback(error, args); } }, "checkpurchasestatus", pars); }
/// <summary> /// Get the qrcode from text /// </summary> /// <param name="text">The text to encode to QR code</param> /// <param name="callback">Call when server response QR code.</param> public static void GetQRCode(string text, GrdEventHandler <Texture2D> callback) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("text", text); dic.Add("type", "1"); handler.Post((data) => { if (callback != null) { Dictionary <string, object> result = GetObjectData((string)data); Texture2D texture = null; int error = int.Parse(result["error"].ToString()); string message = text; if (error == 0) { string qrcode = result["qrcode"].ToString(); if (qrcode.Length > 0) { qrcode = qrcode.Substring("data:image/image/png;base64,".Length); } try { texture = GetTexture(qrcode); } catch { error = 1; } } else { text = result["message"].ToString(); } GrdEventArgs <Texture2D> args = new GrdEventArgs <Texture2D>(error, data, text, texture); callback(error, args); } }, "qrcode", dic); }
public static void GetItemsInfo(string[] itemCodes, GrdEventHandler <GrdItem[]> callback) { Dictionary <string, string> pars = new Dictionary <string, string>(); pars["items"] = string.Join(",", itemCodes); handler.Post((data) => { Dictionary <string, object> result = GetObjectData(data); if (callback != null) { int error = int.Parse(result["error"].ToString()); string msg = ""; List <GrdItem> items = new List <GrdItem>(); if (error == 0) { List <object> ls = (List <object>)result["items"]; for (int i = 0; i < ls.Count; i++) { Dictionary <string, object> dic = (Dictionary <string, object>)ls[i]; GrdItem item = new GrdItem(); item.itemcode = dic["itemcode"].ToString(); item.itemname = dic["itemname"].ToString(); item.price = decimal.Parse(dic["price"].ToString()); item.itemicon = dic["itemicon"].ToString(); items.Add(item); } } else { msg = result["message"].ToString(); } GrdEventArgs <GrdItem[]> args = new GrdEventArgs <GrdItem[]>(error, msg, data, items.ToArray()); callback(error, args); } }, "getappitems", pars); }