using System;
using System.Collections.Generic;
using Model;
using System.Data;
using System.Data.SqlClient; namespace DAL
{
/// <summary>
/// 发布活动信息
/// </summary>
public class ActivityBulletinDA
{
/// <summary>
/// 发布活动
/// </summary>
/// <param name="activityBulletin"></param>
/// <returns></returns>
public static int Save(Model.ActivityBulletin activityBulletin)
{
if (activityBulletin.ID.HasValue)
{
return Update(activityBulletin);
}
else
{
return Insert(activityBulletin);
} } /// <summary>
/// 执行插入
/// </summary>
/// <param name="activityBulletin"></param>
/// <returns></returns>
internal static int Insert(Model.ActivityBulletin activityBulletin)
{
activityBulletin.ID = Guid.NewGuid();
string sql = @" INSERT INTO [dbo].[ActivityBulletin]
(
[ID],
[AssociationsID],
[Title] ,
[Details] ,
[Type] ,
[SponsorEnterpriseName] ,
[LinkMan],
[Phone],
[beginTime] ,
[endTime] ,
[imgName],
[TIndex],
[Recommend]
)
VALUES (
@ID,
@AssociationsID,
@Title ,
@Details ,
@Type ,
@SponsorEnterpriseName ,
@LinkMan ,
@Phone ,
@beginTime ,
@endTime ,
@imgName,
@TIndex,
@Recommend
)";
List<SqlParameter> parms = new List<SqlParameter>();
parms.Add(SqlHelper.CreateParameter("@ID", activityBulletin.ID));
parms.Add(SqlHelper.CreateParameter("@AssociationsID", activityBulletin.AssociationsID));
parms.Add(SqlHelper.CreateParameter("@Title", activityBulletin.Title));
parms.Add(SqlHelper.CreateParameter("@Details", activityBulletin.Details));
parms.Add(SqlHelper.CreateEnumParamter("@Type", activityBulletin.Type));
parms.Add(SqlHelper.CreateParameter("@SponsorEnterpriseName", activityBulletin.SponsorEnterpriseName));
parms.Add(SqlHelper.CreateParameter("@LinkMan", activityBulletin.LinkMan));
parms.Add(SqlHelper.CreateParameter("@Phone", activityBulletin.Phone));
parms.Add(SqlHelper.CreateParameter("@beginTime", activityBulletin.BeginTime));
parms.Add(SqlHelper.CreateParameter("@endTime", activityBulletin.EndTime));
parms.Add(SqlHelper.CreateParameter("@imgName", activityBulletin.IMGName));
parms.Add(SqlHelper.CreateParameter("@TIndex", ));
parms.Add(SqlHelper.CreateParameter("@Recommend", )); string connStr = SqlConnectionHelper.GetConnection();
int resultCount = SqlHelper.ExecuteNonQuery(connStr, CommandType.Text, sql, parms.ToArray());
return resultCount;
} /// <summary>
/// 执行更新
/// </summary>
/// <param name="activityBulletin"></param>
/// <returns></returns>
public static int Update( Model.ActivityBulletin activityBulletin)
{
string sql = @" UPDATE [dbo].[ActivityBulletin]
SET
[title] = ISNULL(@title, title),
[Details] =ISNULL(@Details, Details),
[Type] = ISNULL(@Type, Type),
[SponsorEnterpriseName] = ISNULL(@SponsorEnterpriseName, SponsorEnterpriseName),
[LinkMan] = ISNULL(@LinkMan, LinkMan),
[Phone] =ISNULL(@Phone, Phone),
[beginTime]=ISNULL(@beginTime, beginTime),
[endTime]=ISNULL(@endTime, endTime),
[IMGName]=ISNULL(@IMGName, IMGName),
[TIndex]=ISNULL(@TIndex, TIndex),
[Recommend]=ISNULL(@Recommend, Recommend)
WHERE ID=@ID"; List<SqlParameter> parms = new List<SqlParameter>();
parms.Add(SqlHelper.CreateParameter("@ID", activityBulletin.ID));
parms.Add(SqlHelper.CreateParameter("@title", activityBulletin.Title));
parms.Add(SqlHelper.CreateParameter("@Details", activityBulletin.Details));
parms.Add(SqlHelper.CreateEnumParamter("@Type", activityBulletin.Type));
parms.Add(SqlHelper.CreateParameter("@SponsorEnterpriseName", activityBulletin.SponsorEnterpriseName));
parms.Add(SqlHelper.CreateParameter("@LinkMan", activityBulletin.LinkMan));
parms.Add(SqlHelper.CreateParameter("@beginTime", activityBulletin.BeginTime));
parms.Add(SqlHelper.CreateParameter("@endTime", activityBulletin.EndTime));
parms.Add(SqlHelper.CreateParameter("@Phone", activityBulletin.Phone));
parms.Add(SqlHelper.CreateParameter("@IMGName", activityBulletin.IMGName));
parms.Add(SqlHelper.CreateParameter("@TIndex", activityBulletin.TIndex));
parms.Add(SqlHelper.CreateParameter("@Recommend", activityBulletin.Recommend)); string connStr = SqlConnectionHelper.GetConnection();
int resultCount = SqlHelper.ExecuteNonQuery(connStr, CommandType.Text, sql, parms.ToArray());
return resultCount;
} public List<Model.ActivityBulletin> GetInfo(ActivityBulletinQueryEntity query)
{
return GetActivityBulletinList(query);
} public static int Delete(Guid? id)
{
int count = ;
if (id.HasValue)
{
string sql = "delete from [ActivityBulletin] where [ID]=@ID";
List<SqlParameter> parms = new List<SqlParameter>();
parms.Add(SqlHelper.CreateParameter("@ID", id));
string connStr = SqlConnectionHelper.GetConnection();
count = SqlHelper.ExecuteNonQuery(connStr, CommandType.Text, sql, parms.ToArray());
}
return count;
} /// <summary>
/// 根据查询条件获取活动信息集合
/// </summary>
/// <returns></returns>
public static List<Model.ActivityBulletin> GetActivityBulletinList(ActivityBulletinQueryEntity query)
{
List<Model.ActivityBulletin> result = new List<Model.ActivityBulletin>();
string tempStr = string.Empty;
List<SqlParameter> parms = new List<SqlParameter>();
parms.Add(SqlHelper.CreateParameter("@RowCount", query.TotalRecord));
parms[].Direction = ParameterDirection.Output;
parms.Add(SqlHelper.CreateParameter("@PageIndex", query.PageIndex));
parms.Add(SqlHelper.CreateParameter("@PageSize", query.PageSize));
parms.Add(SqlHelper.CreateEnumParamter("@Type", query.Type));
parms.Add(SqlHelper.CreateEnumParamter("@ID", query.ActivityID));
parms.Add(SqlHelper.CreateParameter("@AssociationsID", query.AssociationsID));
parms.Add(SqlHelper.CreateParameter("@TIndex", query.TIndex));
parms.Add(SqlHelper.CreateParameter("@BlurInfo", query.BlurInfo));
parms.Add(SqlHelper.CreateParameter("@EndTime", query.EndTime));
string connStr = SqlConnectionHelper.GetConnection();
using (IDataReader reader = SqlHelper.ExecuteReader(connStr, CommandType.StoredProcedure, "Proc_GetActivityBulletinList", parms.ToArray()))
{
while (reader.Read())
{
result.Add(new Model.ActivityBulletin
{
Title = SqlHelper.ReadNullableString(reader, ),
IMGName = SqlHelper.ReadNullableString(reader, ),
Details = SqlHelper.ReadNullableString(reader, ),
ID = SqlHelper.ReadNullableValue<Guid>(reader, ),
BeginTime = SqlHelper.ReadNullableValue<DateTime>(reader, ),
Type = SqlHelper.ReadNullableEnum<AssociationsTypeEnum>(reader, ),
SponsorEnterpriseName= SqlHelper.ReadNullableString(reader, ),
LinkMan = SqlHelper.ReadNullableString(reader, ),
Phone = SqlHelper.ReadNullableString(reader, ),
EndTime = SqlHelper.ReadNullableValue<DateTime>(reader, ),
Recommend = SqlHelper.ReadNullableValue<int>(reader, ),
AssociationsID = SqlHelper.ReadNullableValue<Guid>(reader,),
TIndex = SqlHelper.ReadNullableValue<int>(reader,)
});
}
}
query.TotalRecord = (int)parms[].Value;
return result;
}
/// <summary>
/// 前10活动信息集合
/// </summary>
/// <returns></returns>
public static List<Model.ActivityBulletin> GetActivityBulletinList()
{
List<Model.ActivityBulletin> result = new List<Model.ActivityBulletin>();
string sql = @" SELECT top 10 id,title,imgName,Details,beginTime,Type,SponsorEnterpriseName,
LinkMan,Phone,endTime,Recommend,AssociationsID,TIndex FROM
[dbo].[ActivityBulletin] order by TIndex";
string connStr = SqlConnectionHelper.GetConnection();
using (IDataReader reader = SqlHelper.ExecuteReader(connStr, CommandType.Text, sql, null))
{
while (reader.Read())
{
result.Add(new Model.ActivityBulletin
{
ID = SqlHelper.ReadNullableValue<Guid>(reader, ),
Title = SqlHelper.ReadNullableString(reader, ),
IMGName = SqlHelper.ReadNullableString(reader, ),
Details = SqlHelper.ReadNullableString(reader, ),
BeginTime = SqlHelper.ReadNullableValue<DateTime>(reader, ),
Type = SqlHelper.ReadNullableEnum<AssociationsTypeEnum>(reader, ),
SponsorEnterpriseName = SqlHelper.ReadNullableString(reader, ),
LinkMan = SqlHelper.ReadNullableString(reader, ),
Phone = SqlHelper.ReadNullableString(reader, ),
EndTime = SqlHelper.ReadNullableValue<DateTime>(reader, ),
Recommend = SqlHelper.ReadNullableValue<int>(reader, ),
AssociationsID = SqlHelper.ReadNullableValue<Guid>(reader, ),
TIndex = SqlHelper.ReadNullableValue<int>(reader, )
});
}
}
return result;
}
/// <summary>
/// 活动信息集合根据时间
/// </summary>
/// <returns></returns>
public static List<Model.ActivityBulletin> GetActivityBulletinList(int count)
{
List<Model.ActivityBulletin> result = new List<Model.ActivityBulletin>();
string sql = string.Format(@" SELECT top {0} id,title FROM
[dbo].[ActivityBulletin] order by InDate Desc",count);
string connStr = SqlConnectionHelper.GetConnection();
using (IDataReader reader = SqlHelper.ExecuteReader(connStr, CommandType.Text, sql, null))
{
while (reader.Read())
{
result.Add(new Model.ActivityBulletin
{
ID = SqlHelper.ReadNullableValue<Guid>(reader, ),
Title = SqlHelper.ReadNullableString(reader, )
});
}
}
return result;
}
public static List<ActivityBulletin> GetMyActivityBulletinList(ActivityBulletinQueryEntity query)
{
List<Model.ActivityBulletin> result = new List<Model.ActivityBulletin>();
string tempStr = string.Empty; List<SqlParameter> parms = new List<SqlParameter>();
parms.Add(SqlHelper.CreateParameter("@RowCount", query.TotalRecord));
parms[].Direction = ParameterDirection.Output;
parms.Add(SqlHelper.CreateParameter("@PageIndex", query.PageIndex));
parms.Add(SqlHelper.CreateParameter("@PageSize", query.PageSize));
parms.Add(SqlHelper.CreateEnumParamter("@Type", query.Type));
parms.Add(SqlHelper.CreateEnumParamter("@ID", query.ActivityID));
parms.Add(SqlHelper.CreateParameter("@AssociationsID", query.AssociationsID));
parms.Add(SqlHelper.CreateParameter("@TIndex", query.TIndex));
parms.Add(SqlHelper.CreateParameter("@BlurInfo", query.BlurInfo));
parms.Add(SqlHelper.CreateParameter("@EndTime", query.EndTime));
parms.Add(SqlHelper.CreateParameter("@BeginTime", query.BeginTime)); string connStr = SqlConnectionHelper.GetConnection();
using (IDataReader reader = SqlHelper.ExecuteReader(connStr, CommandType.StoredProcedure, "Proc_GetMyActivityBulletinList", parms.ToArray()))
{
while (reader.Read())
{
result.Add(new Model.ActivityBulletin
{
Title = SqlHelper.ReadNullableString(reader, ),
IMGName = SqlHelper.ReadNullableString(reader, ),
Details = SqlHelper.ReadNullableString(reader, ),
ID = SqlHelper.ReadNullableValue<Guid>(reader, ),
BeginTime = SqlHelper.ReadNullableValue<DateTime>(reader, ),
Type = SqlHelper.ReadNullableEnum<AssociationsTypeEnum>(reader, ),
SponsorEnterpriseName = SqlHelper.ReadNullableString(reader, ),
LinkMan = SqlHelper.ReadNullableString(reader, ),
Phone = SqlHelper.ReadNullableString(reader, ),
EndTime = SqlHelper.ReadNullableValue<DateTime>(reader, ),
Recommend = SqlHelper.ReadNullableValue<int>(reader, ),
AssociationsID = SqlHelper.ReadNullableValue<Guid>(reader, ),
TIndex = SqlHelper.ReadNullableValue<int>(reader, )
});
}
}
query.TotalRecord = (int)parms[].Value;
return result;
}
}
}

ASP.NET部分代码示例的更多相关文章

  1. [代码示例]用Fine Uploader+ASP.NET MVC实现ajax文件上传

    原文 [代码示例]用Fine Uploader+ASP.NET MVC实现ajax文件上传 Fine Uploader(http://fineuploader.com/)是一个实现 ajax 上传文件 ...

  2. 微软代码示例:ASP.NET 2.0 三层架构应用程序教程系列

    本文转自:http://www.codeusing.com/hi/uephee.wen/resource/view/170.aspx 资源分类:微软代码示例               更新日期:20 ...

  3. My.Ioc 代码示例——实现自动注册/解析

    在很多 Ioc 容器中,当使用者向容器请求实现了某个契约类型 (Contract Type) 的服务时 (调用类似如下方法 container.Resolve(Type contractType)), ...

  4. 10个小技巧助您写出高性能的ASP.NET Core代码

    今天这篇文章我们来聊一聊如何提升并优化ASP.NET Core应用程序的性能,本文的大部分内容来自翻译,当然中间穿插着自己的理解,希望对大家有所帮助!话不多说开始今天的主题吧! 我们都知道性能是公共网 ...

  5. 高级渲染技巧和代码示例 GPU Pro 7

    下载代码示例 移动设备正呈现着像素越来越高,屏幕尺寸越来越小的发展趋势. 由于像素着色的能耗非常大,因此 DPI 的增加以及移动设备固有的功耗受限环境为降低像素着色成本带来了巨大的压力. MSAA 有 ...

  6. Java8-Function使用及Groovy闭包的代码示例

    导航 定位 概述 代码示例 Java-Function Groovy闭包 定位 本文适用于想要了解Java8 Function接口编程及闭包表达式的筒鞋. 概述 在实际开发中,常常遇到使用模板模式的场 ...

  7. [IOS 开发] 懒加载 (延迟加载) 的基本方式,好处,代码示例

    懒加载的好处: 1> 不必将创建对象的代码全部写在viewDidLoad方法中,代码的可读性更强 2> 每个属性的getter方法中分别负责各自的实例化处理,代码彼此之间的独立性强,松耦合 ...

  8. SELECT控件操作的JS代码示例

    SELECT控件操作的JS代码示例 1 检测是否有选中 if(objSelect.selectedIndex > -1) { //说明选中 } else { //说明没有选中 } 2.动态创建s ...

  9. 转:HIBERNATE一些_方法_@注解_代码示例---写的非常好

    HIBERNATE一些_方法_@注解_代码示例操作数据库7步骤 : 1 创建一个SessionFactory对象 2 创建Session对象 3 开启事务Transaction : hibernate ...

随机推荐

  1. mex (离散化+线段树)

    Time Limit: 3000 ms   Memory Limit: 256 MB Description 给你一个无限长的数组,初始的时候都为0,有3种操作: 操作1是把给定区间$[l,r]$设为 ...

  2. 将FTP映射至Windows

    在经常使用ftp传输文件的环境中,每次上传和下载文件都需要重新连接然后登录是非常繁琐的一件事情.我们可以将FTP空间映射到本地磁盘空间,免去输入地址以及账号.密码.方便我们日常中文件的上传和下载. 1 ...

  3. java数组:去重,增加,删除元素

    import java.util.List; import java.util.ArrayList; import java.util.Set; import java.util.HashSet; p ...

  4. 【Unity3D】Unity3D开发《我的世界》之二、创建一个立方体

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/unity_minecraft_02.html 这一篇的内容比较简单,因为所有理论内容都在上一篇中讲到了.但有两点需 ...

  5. MS SQL xp_instance_regwrite设置注册表疑惑

      以前写过一篇博文"MS SQL 日志记录管理",里面介绍了如何设置SQL Server的错误日志的最大归档数量,如果在SSMS的UI界面设置,可以从"Manageme ...

  6. 关于druid的配置说明

    <bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter"> & ...

  7. 实战DeviceIoControl 之四:获取硬盘的详细信息

    Q 用IOCTL_DISK_GET_DRIVE_GEOMETRY或IOCTL_STORAGE_GET_MEDIA_TYPES_EX只能得到很少的磁盘参数,我想获得包括硬盘序列号在内的更加详细的信息,有 ...

  8. Caused by: java.lang.ClassNotFoundException: com.mchange.v2.ser.Indirector

    1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help ...

  9. MySQL查询所有数据库表出错

    1.错误描述 1 queries executed, 0 success, 1 errors, 0 warnings 查询:show tables 错误代码: 1046 No database sel ...

  10. 事件驱动的Java框架

    事件驱动的三个要素: 事件源:能够接收外部事件的源体. 侦听器:能够接收事件源通知的对象. 事件处理程序:用于处理事件的对象.