protected void init_form(string ctrID) { if (!string.IsNullOrEmpty(ctrID)) { _WG_OnGoingGiftsEntity = DataProvider.GetInstance().GetWG_OnGoingGiftsEntity(int.Parse(ctrID)); TextBox_Code.Text = _WG_OnGoingGiftsEntity.Code.ToString(); TextBox_MenberID.Text = _WG_OnGoingGiftsEntity.MenberID.ToString(); TextBox_GiftID.Text = _WG_OnGoingGiftsEntity.GiftID.ToString(); TextBox_Count.Text = _WG_OnGoingGiftsEntity.Count.ToString(); TextBox_Status.Text = _WG_OnGoingGiftsEntity.Status.ToString(); } }
public void ProcessRequest(HttpContext context) { context.Response.AddHeader("Access-Control-Allow-Origin", "*"); context.Response.AddHeader("Access-Control-Allow-Methods", "POST"); context.Response.AddHeader("Access-Control-Allow-Headers", "x-requested-with,content-type"); context.Response.ContentType = "text/plain"; JsonBaseObject jbo = new JsonBaseObject(); string result = string.Empty; try {//giftid,userid,validatecode string giftID = context.Request["giftID"]; string menberID = context.Request["menberID"]; string giftCount = context.Request["giftCount"]; string status = context.Request["status"];//0已兑换,1已领取 int count = 0; int.TryParse(giftCount, out count); if (string.IsNullOrEmpty(giftID) || string.IsNullOrEmpty(menberID) || string.IsNullOrEmpty(giftCount)) { //失败 jbo.code = -1; jbo.data = null; jbo.message = "礼物或领取人不存在,或兑换礼物的个数不能小于等于0"; jbo.success = false; } else { WG_GiftsEntity ge = DataProvider.GetInstance().GetWG_GiftsEntity(int.Parse(giftID)); WG_MenberEntity me = DataProvider.GetInstance().GetWG_MenberEntity(int.Parse(menberID)); if (null != ge && null != me && me.Scores >= ge.NeedScores * count && ge.Count >= count) { //1.在ongoinggift表中新增一条记录 WG_OnGoingGiftsEntity ogge = new WG_OnGoingGiftsEntity(); //领取码=年月日时分秒+id后四位(不够四位前补零) string timespan = DateTime.Now.ToString("yyyyMMddhhmmss"); string idSub = string.Empty; if (me.ID.ToString().Length < 4) idSub = me.ID.ToString().PadLeft(4, '0'); else { idSub = me.ID.ToString().Substring(me.ID.ToString().Length - 4, 4); } ogge.Code = idSub + timespan; ogge.MenberID = int.Parse(menberID); ogge.GiftID = int.Parse(giftID); ogge.Status = int.Parse(status); ogge.Count = count; ogge.CreateDate = DateTime.Now; int addresult = DataProvider.GetInstance().AddWG_OnGoingGifts(ogge); if (addresult >= 0) { //2.扣除兑换者的积分 me.Scores = me.Scores - ge.NeedScores * count; if (!DataProvider.GetInstance().UpdateWG_Menber(me)) { //失败 jbo.code = -1; jbo.data = null; jbo.message = "扣除兑换者积分异常"; jbo.success = false; } else { //3.礼物表中的数量减去相应的数量 ge.Count = ge.Count - count; if (!DataProvider.GetInstance().UpdateWG_Gifts(ge)) { //失败 jbo.code = -1; jbo.data = null; jbo.message = "减去礼物剩余数量异常"; jbo.success = false; } else { //成功 jbo.code = 0; jbo.data = null; jbo.message = "成功"; jbo.success = true; } } } else { //失败 jbo.code = -1; jbo.data = null; jbo.message = "加入领取队列出错"; jbo.success = false; } } else { //失败 jbo.code = -1; jbo.data = null; jbo.message = "礼物不存在或积分不够"; jbo.success = false; } } } catch (Exception ex) { //失败 jbo.code = -1; jbo.data = null; jbo.message = "接口调用过程中出现其他错误"; jbo.success = false; } #region 返回json result = JsonSerializer<JsonBaseObject>(jbo); context.Response.Write(result); #endregion }
protected void WG_OnGoingGiftsAdd() { #region 判断是否可空 var _Code = Request.Form["TextBox_Code"]; if (string.IsNullOrEmpty(_Code)) { Alert("[ 兑换码 ]不能为空"); return; } var _MenberID = Request.Form["TextBox_MenberID"]; if (string.IsNullOrEmpty(_MenberID)) { Alert("[ 会员ID ]不能为空"); return; } var _GiftID = Request.Form["TextBox_GiftID"]; if (string.IsNullOrEmpty(_GiftID)) { Alert("[ 礼物ID ]不能为空"); return; } var _Count = Request.Form["TextBox_Count"]; if (string.IsNullOrEmpty(_Count)) { Alert("[ 数量 ]不能为空"); return; } var _Status = Request.Form["TextBox_Status"]; if (string.IsNullOrEmpty(_Status)) { Alert("[ 状态 ]不能为空"); return; } #endregion #region 获取数据 WG_OnGoingGiftsEntity _WG_OnGoingGiftsEntity = new WG_OnGoingGiftsEntity(); _WG_OnGoingGiftsEntity.Code =Convert.ToString(_Code.ToString()); _WG_OnGoingGiftsEntity.MenberID =Convert.ToInt32(_MenberID.ToString()); _WG_OnGoingGiftsEntity.GiftID =Convert.ToInt32(_GiftID.ToString()); _WG_OnGoingGiftsEntity.Count =Convert.ToInt32(_Count.ToString()); _WG_OnGoingGiftsEntity.Status =Convert.ToInt32(_Status.ToString()); _WG_OnGoingGiftsEntity.CreateDate =DateTime.Now; try { DataProvider.GetInstance().AddWG_OnGoingGifts(_WG_OnGoingGiftsEntity); } catch { WriteLog("WG_OnGoingGiftsAdd", "添加WG_OnGoingGifts", "插入数据库时出错", Common.DailyUtility.MideSmsType.LogType.SystemLog); Alert("添加数据时出错,请重试"); return; } Alert("添加WG_OnGoingGifts成功"); }
private MideFrameWork.Data.Entity.WG_OnGoingGiftsEntity GetWG_OnGoingGifts(DataRow dr) { MideFrameWork.Data.Entity.WG_OnGoingGiftsEntity info = new MideFrameWork.Data.Entity.WG_OnGoingGiftsEntity(); if(DBNull.Value==dr["ID"]) info.ID=0; else info.ID=int.Parse(dr["ID"].ToString()); if(DBNull.Value==dr["Code"]) info.Code= string.Empty; else info.Code= dr["Code"].ToString(); if(DBNull.Value==dr["MenberID"]) info.MenberID=0; else info.MenberID=int.Parse(dr["MenberID"].ToString()); if(DBNull.Value==dr["GiftID"]) info.GiftID=0; else info.GiftID=int.Parse(dr["GiftID"].ToString()); if(DBNull.Value==dr["Count"]) info.Count=0; else info.Count=int.Parse(dr["Count"].ToString()); if(DBNull.Value==dr["Status"]) info.Status=0; else info.Status=int.Parse(dr["Status"].ToString()); if(DBNull.Value==dr["CreateDate"]) info.CreateDate=DateTime.Now; else info.CreateDate=DateTime.Parse(dr["CreateDate"].ToString()); return info; }