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. Sping Boot入门到实战之入门篇(四):Spring Boot自动化配置

    该篇为Sping Boot入门到实战系列入门篇的第四篇.介绍Spring Boot自动化配置的基本原理与实现.   Spring Boot之所以受开发者欢迎, 其中最重要的一个因素就是其自动化配置特性 ...

  2. 面试为什么需要了解JVM

    匠心零度 转载请注明原创出处,谢谢! 说在前面 如果你经常注意面试题,你会发现现在面试题多多少少会含有jvm相关的面试题,之前也把一些jvm面试题汇总了下:面试题系列一,那么为什么现在面试需要了解或者 ...

  3. FMECA分析

    FMECA是针对产品所有可能的故障,并根据对故障模式的分析,确定每种故障模式对产品工作的影响,找出单点故障,并按故障模式的严重度及其发生概率确定其危害性.所谓单点故障指的是引起产品故障的,且没有冗余或 ...

  4. php session函数

    session_start() 开启session 使用session前需要使用该函数 session_id() 获取当前回话的sessionid session_save_path($path) 如 ...

  5. R语言 文本挖掘 tm包 使用

    #清除内存空间 rm(list=ls()) #导入tm包 library(tm) library(SnowballC) #查看tm包的文档 #vignette("tm") ##1. ...

  6. PowerManager和PowerManager.WakeLock详解

    最近在做项目过程中,有一个LocalPush的需求,需要保持屏幕点亮一段时间,并且在这个时间里,启动Service来执行请求服务器的操作,拿到热点的数据.所以,就找了一下相关的android开源项目. ...

  7. stm32 fsmc 功能讲解(转)

    LCD有如下控制线:CS:Chip Select 片选,低电平有效RS:Register Select 寄存器选择WR:Write 写信号,低电平有效RD:Read 读信号,低电平有效RESET:重启 ...

  8. WebService之CXF注解之三(Service接口实现类)

    ITeacherServiceImpl.java: /** * @Title:ITeacherServiceImpl.java * @Package:com.you.service.impl * @D ...

  9. Hibernate中的条件查询完成类

    Hibernate中的条件查询有以下三个类完成: 1.Criteria:代表一次查询 2.Criterion:代表一个查询条件 3.Restrictions:产生查询条件的工具类

  10. Linux显示检查设置文件中的语法是否正确

    Linux显示检查设置文件中的语法是否正确 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ apachectl [conflgtest] 程序"apa ...