public int Count(LinkSourceInfo oLink) { string sql = @" if exists( select top 1 * from linksource where urlsource=@urlsource and countdate=@countdate) update linksource set visitcount = visitcount + @visitcount where urlsource=@urlsource and countdate=@countdate else insert into linksource(urlsource, countdate, visitcount) values(@urlsource, @countdate, @visitcount)"; sql = sql.Replace("@urlsource", Util.ToSqlString(oLink.URLSource)); sql = sql.Replace("@countdate", Util.ToSqlString(oLink.CountDate)); sql = sql.Replace("@visitcount",oLink.VisitCount.ToString()); SqlCommand cmd = new SqlCommand(sql); return SqlHelper.ExecuteNonQuery(cmd); }
public void Count(string urlSource) { //ʹ�����hash���棬��ÿ�ε�urlsource�������ݿ�Ϊ50��һ���¡� //�ŵ���Ǽ��������ݿ�ĸ��� //ȱ�� 1 urlSource����ܶ࣬�ͻ�Ƚ�ռ���ڴ�, ����ﵽ1000�����ϣ�Ҫ���Ǹ����㷨��������Ŀ��Ҫ̫�ࡣ // 2 ����ָ�������������Ҳ����˵50������Ÿ��£����Ի��ڵڶ������Ϊ����ԭ��ǿ�Ƹ��¡������Ҫ�������������һ��daemon���������daemon �ľ�����Ի���Ҫ���ǡ� // 3 �����ʹ�ڴ��е����ݶ�ʧ����ɵ����ƫ� �����Ҫ��������Կ�����application end �¼��д���� lock ( locker ) { if ( !ht.Contains(urlSource)) { //������������url��������һ���� LinkSourceInfo oLinkSource = new LinkSourceInfo(); oLinkSource.CountDate = DateTime.Now.ToString(AppConst.DateFormat); oLinkSource.URLSource = urlSource; oLinkSource.VisitCount = 1; ht.Add(urlSource, oLinkSource); } else { LinkSourceInfo oLinkSource = ht[urlSource] as LinkSourceInfo; string nowTime = DateTime.Now.ToString(AppConst.DateFormat); //���ht�е�url���ǽ���ļ�¼�����ȸ�������ļ�¼�������ݿ⡣�����������url����Ϊ1�� if ( oLinkSource.CountDate != nowTime ) { new LinkSourceDac().Count(oLinkSource); oLinkSource.CountDate = nowTime; oLinkSource.VisitCount = 1; } else { //����ǽ����,������һ oLinkSource.VisitCount++; //�����ǰ��������500�����µ����ݿ⡣ if ( oLinkSource.VisitCount >= 5) { new LinkSourceDac().Count(oLinkSource); // oLinkSource.VisitCount = 0; } } } } }
public int Insert(LinkSourceInfo oParam) { string sql = @"INSERT INTO LinkSource ( URLSource, VisitCount, CountDate ) VALUES ( @URLSource, @VisitCount, @CountDate );set @SysNo = SCOPE_IDENTITY();"; SqlCommand cmd = new SqlCommand(sql); SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4); SqlParameter paramURLSource = new SqlParameter("@URLSource", SqlDbType.NVarChar,300); SqlParameter paramVisitCount = new SqlParameter("@VisitCount", SqlDbType.Int,4); SqlParameter paramCountDate = new SqlParameter("@CountDate", SqlDbType.NVarChar,10); paramSysNo.Direction = ParameterDirection.Output; if ( oParam.URLSource != AppConst.StringNull) paramURLSource.Value = oParam.URLSource; else paramURLSource.Value = System.DBNull.Value; if ( oParam.VisitCount != AppConst.IntNull) paramVisitCount.Value = oParam.VisitCount; else paramVisitCount.Value = System.DBNull.Value; if ( oParam.CountDate != AppConst.StringNull) paramCountDate.Value = oParam.CountDate; else paramCountDate.Value = System.DBNull.Value; cmd.Parameters.Add(paramSysNo); cmd.Parameters.Add(paramURLSource); cmd.Parameters.Add(paramVisitCount); cmd.Parameters.Add(paramCountDate); return SqlHelper.ExecuteNonQuery(cmd, out oParam.SysNo); }
public void map(LinkSourceInfo oParam, DataRow tempdr) { oParam.SysNo = Util.TrimIntNull(tempdr["SysNo"]); oParam.URLSource = Util.TrimNull(tempdr["URLSource"]); oParam.VisitCount = Util.TrimIntNull(tempdr["VisitCount"]); oParam.CountDate = Util.TrimNull(tempdr["CountDate"]); }
public void Import() { if ( !AppConfig.IsImportable) throw new BizException("Is Importable is false"); /* do not use the following code after Data Pour in */ string sql = " select top 1 * from linksource "; DataSet ds = SqlHelper.ExecuteDataSet(sql); if ( Util.HasMoreRow(ds) ) throw new BizException("the table linksource is not empty"); TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; options.Timeout = TransactionManager.DefaultTimeout; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { string sql1 = @"select * from ipp2003..visitsourcelog"; DataSet ds1 = SqlHelper.ExecuteDataSet(sql1); foreach(DataRow dr1 in ds1.Tables[0].Rows) { LinkSourceInfo oInfo = new LinkSourceInfo(); map(oInfo, dr1); oInfo.CountDate = Util.TrimDateNull(oInfo.CountDate).ToString(AppConst.DateFormat); new LinkSourceDac().Insert(oInfo); } scope.Complete(); } }