最近写了个小小的活动,前端页面有一个按钮 按钮调用事件如下:
function fn_getInfo()
{
$.get("../Code/Ajax.ashx?type=2&uarea=" + currselectvalue + "&urole=" + args + "&rid=" + Math.random(), "", function(responseValue) {
...............}
}
这个异步调用的方法如下:
public string ToSendPrizesUser()
{
.........................................
int xx = 查询日志 (日志方法加了try {}cathc{}块 默认值返回-1 )
if(xx ==0)
{
result = ToPrizes() 方法如下
}else { result = 0;}
return result;
}
        public static int ToPrizes(.............................................................)
        {
            int result = 0;
            TransactionOptions option = new TransactionOptions();
            option.IsolationLevel = System.Transactions.IsolationLevel.RepeatableRead;
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, option))
            {
                try
                {
                    DataView dv = GetRoleInfo(.....);
                    if (dv.Count > 0)
                    {
                        DataRowView dr = dv[0];
                        int dwi = 方法(调用接口发送数据);
                        if (dwi == 5)  // 发送成功
                        {
                              //写日志 
                            int logi = Code.DecemberActiveLog.AddActiveLog(.....................l);
                            if (logi > 0) //日志写成功
                            {
                                result = 1;//成功
                            }
                        }
                    }
                    scope.Complete(); 
                }
                catch (Exception ex) { throw ex; }
                finally { scope.Dispose(); } 
            }
            return result;
        }
日志查询方法:
        public static int ToolsDayExists(int userid)
        {
            int result = -1;
            StringBuilder strsql = new StringBuilder();
            strsql.AppendFormat(@"SELECT Count(*) FROM NovemberSendLog WHERE UserID = '{0}' ", userid);
            try
            {
                object obj = SqlHelper.ExecuteScalar(Config.ConnectionString, CommandType.Text, strsql.ToString());
                if (obj != DBNull.Value && obj != null)
                {
                    result = int.Parse(obj.ToString());
                }
            }
            catch
            { result = -1; }
            return result;
        }
出现问题,有及个别用户产生了两条日志记录!情况如下:
222.137.149.186        2           1           2010-12-08 23: 32:21.000       1     
222.137.149.186        2           1           2010-12-08 23:32:22.000       0    
我对异步也不是很熟悉,只是用起来比较简单,不知道哪位大侠能帮我分析下 问题出在那里?
不求详解,有个思路就行~ 万分感谢!
你希望每个用户只有一条记录,那么就存在一个唯一值的问题,在网络上,一般是用IP地址来做判断吧。
首先,你可以先根据IP地址在数据库里搜索下,如果已经存在该IP,那么就不用插入该数据,同时在页面提示“已经提交过了”的提示即可。。。
用cookie
试试用存储过程