예제 #1
0
        public static long Insert(c_voteuserEntity item)
        {
            long id = 0;

            try
            {
                DataTable dt = DBAccess.DataAccess.Miou_GetDataSetBySql(DBAccess.LogUName, string.Format("select * from {0} where {1} = {2} ;", tableName, keyName, 0)).Tables[0];
                dt.TableName = tableName;
                DataRow dr = dt.NewRow();
                item.createtime = DateTime.Now;
                item.lasttime   = item.createtime;
                DBAccess.FillDataRow(ref dr, item);
                List <long> ids = new List <long>();

                dt.Rows.Add(dr);

                if (DBAccess.DataAccess.Miou_UpdateDataTablesNoTranWithIndentity(DBAccess.LogUName
                                                                                 , new List <DataTable> {
                    dt
                }, out ids).StartsWith("000"))
                {
                    if (ids.Count > 0)
                    {
                        id = ids[0];
                    }
                }
            }
            catch (Exception ex)
            {
                string ss = ex.ToString();
            }
            return(id);
        }
예제 #2
0
        public static bool Update(c_voteuserEntity item, ref string info)
        {
            bool rv = true;

            try
            {
                DataTable dt = DBAccess.DataAccess.Miou_GetDataSetBySql(DBAccess.LogUName, string.Format("select * from {0} where {1} = {2} ;", tableName, keyName, item.usvoteid)).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    item.lasttime = DateTime.Now;
                    DataRow dr = dt.Rows[0];
                    DBAccess.FillDataRow(ref dr, item);

                    string vs = DBAccess.DataAccess.Miou_UpdateDataSet(DBAccess.LogUName, tableName, "*", "1<>1", "", dt);
                    if (!vs.StartsWith("000000"))
                    {
                        rv   = false;
                        info = vs.Substring(6);
                    }
                }
                else
                {
                    rv   = false;
                    info = "找不到记录!";
                }
            }
            catch (Exception ex)
            {
                info = ex.Message;
                rv   = false;
            }

            return(rv);
        }
예제 #3
0
        public static c_voteuserEntity GetByKeyId(int id, ref string info)
        {
            try
            {
                c_voteuserEntity entity = new c_voteuserEntity();
                DataTable        dt     = DBAccess.DataAccess.Miou_GetDataSetBySql(DBAccess.LogUName, string.Format("select * from {0} where {1} = {2} ;", tableName, keyName, id)).Tables[0];
                var list = DBAccess.GetEntityList <c_voteuserEntity>(dt);
                if (list != null && list.Count > 0)
                {
                    entity = list[0];
                }

                return(entity);
            }
            catch (Exception ex)
            {
                info = ex.Message;
                return(new c_voteuserEntity());
            }
        }
예제 #4
0
        public JsonResult joinvoteitem(int vid, int ivid)
        {
            if (!Common.HeistMon.HMon.GetInstance().AddMon("joinvoteitem_" + base.GetUserid(), 20))
            {
                this.HttpContext.Response.Write("FireWall!");
                this.HttpContext.Response.End();
                return(null);
            }


            AjaxResult ajax = new AjaxResult();

            ajax.ErrorMessage = "";
            ajax.RetCode      = 1;


            var u = GetUser();

            if (u == null || u.uid <= 0)
            {
                ajax.ErrorMessage = "用户未登录.";
                return(Json(ajax));
            }
            if (!u.wkccheckpass)
            {
                ajax.ErrorMessage = "请先验证钱包有效性.";
                return(Json(ajax));
            }

            string info = "";
            var    list = c_voteDal.GetListByWhere(" and voteid=" + vid, ref info);

            if (list == null || list.Count == 0)
            {
                ajax.ErrorMessage = "数据未找到.";
                return(Json(ajax));
            }
            if (list[0].enddate <= DateTime.Now.Date)
            {
                ajax.ErrorMessage = "投票已结束,不能操作.";
                return(Json(ajax));
            }
            if (list[0].votestatus != 2)
            {
                ajax.ErrorMessage = "投票已结束,不能操作.";
                return(Json(ajax));
            }
            var slist = c_voteitemDal.GetByKeyId(ivid, ref info);

            if (slist == null || slist.svoteid <= 0)
            {
                ajax.ErrorMessage = "投票项未找到.";
                return(Json(ajax));
            }
            lock (u)
            {
                int useritem = c_voteuserDal.GetCountByWhere(" and voteid=" + vid + " and uid=" + u.uid);
                if (list[0].votetype == 1)
                {
                    useritem = c_voteuserDal.GetCountByWhere(" and svoteid=" + ivid + " and uid=" + u.uid);
                }
                if (useritem > 0)
                {
                    ajax.ErrorMessage = "您已经投过票.";
                    return(Json(ajax));
                }
                else
                {
                    var userinfo = uinfoDal.GetByKeyId(u.uid, ref info);
                    if (userinfo == null)
                    {
                        ajax.ErrorMessage = "用户信息有未找到.";
                        return(Json(ajax));
                    }
                    c_voteuserEntity obj = new c_voteuserEntity();
                    obj.uid        = u.uid;
                    obj.svoteid    = ivid;
                    obj.voteid     = vid;
                    obj.createtime = DateTime.Now;
                    obj.wkcaddress = userinfo.wkcaddress;
                    obj.wkcamount  = 0;
                    #region 获取wkc余额
                    if (obj.wkcaddress.Trim() == "")
                    {
                        ajax.ErrorMessage = "未绑定钱包地址.";
                        return(Json(ajax));
                    }
                    try
                    {
                        WebClient MyWebClient = new WebClient();
                        MyWebClient.Credentials = CredentialCache.DefaultCredentials;                                               //获取或设置用于向Internet资源的请求进行身份验证的网络凭据
                        Byte[] pageData = MyWebClient.DownloadData("http://xxx?action=getamount&address=" + obj.wkcaddress.Trim()); //从指定网站下载数据
                        string pageHtml = Encoding.Default.GetString(pageData);                                                     //如果获取网站页面采用的是GB2312,则使用这句
                                                                                                                                    //string pageHtml = Encoding.UTF8.GetString(pageData); //如果获取网站页面采用的是UTF-8,则使用这句
                        if (pageHtml.Length > 22 && pageHtml.Trim() == "-99")
                        {
                            ajax.ErrorMessage = "未获取到钱包余额.";
                            return(Json(ajax));
                        }
                        double amount = 0;
                        double.TryParse(pageHtml, out amount);
                        obj.wkcamount   = amount;
                        obj.getamountok = 1;

                        double joinvoteprice = 0;
                        if (LinkTokenSQ.MvcApplication.Syspar.ContainsKey("joinvoteprice"))
                        {
                            double.TryParse(LinkTokenSQ.MvcApplication.Syspar["joinvoteprice"].keyvalue, out joinvoteprice);
                        }
                        long id = c_voteuserDal.Insert(obj);
                        if (id > 0)
                        {
                            if (joinvoteprice > 0)
                            {
                                if (DBAccess.UserPay(u.uid, joinvoteprice) != 1)
                                {
                                    c_voteuserDal.Del(id.ToString(), ref info);
                                    ajax.ErrorMessage = "支付失败,可能账户余额不足.";
                                    return(Json(ajax));
                                }
                            }

                            ajax.ErrorMessage = vid.ToString();
                        }
                        else
                        {
                            ajax.ErrorMessage = "投票失败,请重试试.";
                            return(Json(ajax));
                        }
                    }
                    catch
                    {
                        ajax.ErrorMessage = "未获取到钱包余额.";
                        return(Json(ajax));
                    }
                    #endregion
                }
            }


            ajax.RetCode = 0;
            return(Json(ajax));
        }