ASP.NET部分代码示例

  1 using System;
  2 using System.Collections.Generic;
  3 using Model;
  4 using System.Data;
  5 using System.Data.SqlClient;
  6
  7
  8 namespace DAL
  9 {
 10     /// <summary>
 11     /// 发布活动信息
 12     /// </summary>
 13     public class ActivityBulletinDA
 14     {
 15         /// <summary>
 16         /// 发布活动
 17         /// </summary>
 18         /// <param name="activityBulletin"></param>
 19         /// <returns></returns>
 20         public static int Save(Model.ActivityBulletin activityBulletin)
 21         {
 22             if (activityBulletin.ID.HasValue)
 23             {
 24                 return Update(activityBulletin);
 25             }
 26             else
 27             {
 28                 return Insert(activityBulletin);
 29             }
 30
 31         }
 32
 33
 34         /// <summary>
 35         /// 执行插入
 36         /// </summary>
 37         /// <param name="activityBulletin"></param>
 38         /// <returns></returns>
 39         internal static int Insert(Model.ActivityBulletin activityBulletin)
 40         {
 41             activityBulletin.ID = Guid.NewGuid();
 42             string sql = @" INSERT  INTO [dbo].[ActivityBulletin]
 43                                     (
 44                                       [ID],
 45                                       [AssociationsID],
 46                                       [Title] ,
 47                                       [Details] ,
 48                                       [Type] ,
 49                                       [SponsorEnterpriseName] ,
 50                                       [LinkMan],
 51                                       [Phone],
 52                                       [beginTime] ,
 53                                       [endTime] ,
 54                                       [imgName],
 55                                       [TIndex],
 56                                       [Recommend]
 57                                     )
 58                             VALUES  (
 59                                       @ID,
 60                                       @AssociationsID,
 61                                       @Title ,
 62                                       @Details ,
 63                                       @Type ,
 64                                       @SponsorEnterpriseName ,
 65                                       @LinkMan ,
 66                                       @Phone ,
 67                                       @beginTime ,
 68                                       @endTime ,
 69                                       @imgName,
 70                                       @TIndex,
 71                                       @Recommend
 72                                     )";
 73             List<SqlParameter> parms = new List<SqlParameter>();
 74             parms.Add(SqlHelper.CreateParameter("@ID", activityBulletin.ID));
 75             parms.Add(SqlHelper.CreateParameter("@AssociationsID", activityBulletin.AssociationsID));
 76             parms.Add(SqlHelper.CreateParameter("@Title", activityBulletin.Title));
 77             parms.Add(SqlHelper.CreateParameter("@Details", activityBulletin.Details));
 78             parms.Add(SqlHelper.CreateEnumParamter("@Type", activityBulletin.Type));
 79             parms.Add(SqlHelper.CreateParameter("@SponsorEnterpriseName", activityBulletin.SponsorEnterpriseName));
 80             parms.Add(SqlHelper.CreateParameter("@LinkMan", activityBulletin.LinkMan));
 81             parms.Add(SqlHelper.CreateParameter("@Phone", activityBulletin.Phone));
 82             parms.Add(SqlHelper.CreateParameter("@beginTime", activityBulletin.BeginTime));
 83             parms.Add(SqlHelper.CreateParameter("@endTime", activityBulletin.EndTime));
 84             parms.Add(SqlHelper.CreateParameter("@imgName", activityBulletin.IMGName));
 85             parms.Add(SqlHelper.CreateParameter("@TIndex", 99));
 86             parms.Add(SqlHelper.CreateParameter("@Recommend", 0));
 87
 88             string connStr = SqlConnectionHelper.GetConnection();
 89             int resultCount = SqlHelper.ExecuteNonQuery(connStr, CommandType.Text, sql, parms.ToArray());
 90             return resultCount;
 91         }
 92
 93         /// <summary>
 94         /// 执行更新
 95         /// </summary>
 96         /// <param name="activityBulletin"></param>
 97         /// <returns></returns>
 98         public static int Update( Model.ActivityBulletin activityBulletin)
 99         {
100             string sql = @" UPDATE [dbo].[ActivityBulletin]
101                SET
102                   [title] = ISNULL(@title, title),
103                   [Details] =ISNULL(@Details, Details),
104                   [Type] = ISNULL(@Type, Type),
105                   [SponsorEnterpriseName] = ISNULL(@SponsorEnterpriseName, SponsorEnterpriseName),
106                   [LinkMan] = ISNULL(@LinkMan, LinkMan),
107                   [Phone] =ISNULL(@Phone, Phone),
108                   [beginTime]=ISNULL(@beginTime, beginTime),
109                   [endTime]=ISNULL(@endTime, endTime),
110                   [IMGName]=ISNULL(@IMGName, IMGName),
111                   [TIndex]=ISNULL(@TIndex, TIndex),
112                   [Recommend]=ISNULL(@Recommend, Recommend)
113                   WHERE [email protected]";
114
115             List<SqlParameter> parms = new List<SqlParameter>();
116             parms.Add(SqlHelper.CreateParameter("@ID", activityBulletin.ID));
117             parms.Add(SqlHelper.CreateParameter("@title", activityBulletin.Title));
118             parms.Add(SqlHelper.CreateParameter("@Details", activityBulletin.Details));
119             parms.Add(SqlHelper.CreateEnumParamter("@Type", activityBulletin.Type));
120             parms.Add(SqlHelper.CreateParameter("@SponsorEnterpriseName", activityBulletin.SponsorEnterpriseName));
121             parms.Add(SqlHelper.CreateParameter("@LinkMan", activityBulletin.LinkMan));
122             parms.Add(SqlHelper.CreateParameter("@beginTime", activityBulletin.BeginTime));
123             parms.Add(SqlHelper.CreateParameter("@endTime", activityBulletin.EndTime));
124             parms.Add(SqlHelper.CreateParameter("@Phone", activityBulletin.Phone));
125             parms.Add(SqlHelper.CreateParameter("@IMGName", activityBulletin.IMGName));
126             parms.Add(SqlHelper.CreateParameter("@TIndex", activityBulletin.TIndex));
127             parms.Add(SqlHelper.CreateParameter("@Recommend", activityBulletin.Recommend));
128
129             string connStr = SqlConnectionHelper.GetConnection();
130             int resultCount = SqlHelper.ExecuteNonQuery(connStr, CommandType.Text, sql, parms.ToArray());
131             return resultCount;
132         }
133
134         public List<Model.ActivityBulletin> GetInfo(ActivityBulletinQueryEntity query)
135         {
136             return GetActivityBulletinList(query);
137         }
138
139         public static int Delete(Guid? id)
140         {
141             int count = 0;
142             if (id.HasValue)
143             {
144                 string sql = "delete from [ActivityBulletin]  where [ID][email protected]";
145                 List<SqlParameter> parms = new List<SqlParameter>();
146                 parms.Add(SqlHelper.CreateParameter("@ID", id));
147                 string connStr = SqlConnectionHelper.GetConnection();
148                 count = SqlHelper.ExecuteNonQuery(connStr, CommandType.Text, sql, parms.ToArray());
149             }
150             return count;
151         }
152
153         /// <summary>
154         /// 根据查询条件获取活动信息集合
155         /// </summary>
156         /// <returns></returns>
157         public static List<Model.ActivityBulletin> GetActivityBulletinList(ActivityBulletinQueryEntity query)
158         {
159             List<Model.ActivityBulletin> result = new List<Model.ActivityBulletin>();
160             string tempStr = string.Empty;
161             List<SqlParameter> parms = new List<SqlParameter>();
162             parms.Add(SqlHelper.CreateParameter("@RowCount", query.TotalRecord));
163             parms[0].Direction = ParameterDirection.Output;
164             parms.Add(SqlHelper.CreateParameter("@PageIndex", query.PageIndex));
165             parms.Add(SqlHelper.CreateParameter("@PageSize", query.PageSize));
166             parms.Add(SqlHelper.CreateEnumParamter("@Type", query.Type));
167             parms.Add(SqlHelper.CreateEnumParamter("@ID", query.ActivityID));
168             parms.Add(SqlHelper.CreateParameter("@AssociationsID", query.AssociationsID));
169             parms.Add(SqlHelper.CreateParameter("@TIndex", query.TIndex));
170             parms.Add(SqlHelper.CreateParameter("@BlurInfo", query.BlurInfo));
171             parms.Add(SqlHelper.CreateParameter("@EndTime", query.EndTime));
172             string connStr = SqlConnectionHelper.GetConnection();
173             using (IDataReader reader = SqlHelper.ExecuteReader(connStr, CommandType.StoredProcedure, "Proc_GetActivityBulletinList", parms.ToArray()))
174             {
175                 while (reader.Read())
176                 {
177                     result.Add(new Model.ActivityBulletin
178                     {
179                         Title = SqlHelper.ReadNullableString(reader, 1),
180                         IMGName = SqlHelper.ReadNullableString(reader, 2),
181                         Details = SqlHelper.ReadNullableString(reader, 3),
182                         ID = SqlHelper.ReadNullableValue<Guid>(reader, 4),
183                         BeginTime = SqlHelper.ReadNullableValue<DateTime>(reader, 5),
184                         Type = SqlHelper.ReadNullableEnum<AssociationsTypeEnum>(reader, 6),
185                         SponsorEnterpriseName= SqlHelper.ReadNullableString(reader, 7),
186                         LinkMan = SqlHelper.ReadNullableString(reader, 8),
187                         Phone = SqlHelper.ReadNullableString(reader, 9),
188                         EndTime = SqlHelper.ReadNullableValue<DateTime>(reader, 10),
189                         Recommend = SqlHelper.ReadNullableValue<int>(reader, 11),
190                         AssociationsID = SqlHelper.ReadNullableValue<Guid>(reader,12),
191                         TIndex = SqlHelper.ReadNullableValue<int>(reader,13)
192                     });
193                 }
194             }
195             query.TotalRecord = (int)parms[0].Value;
196             return result;
197         }
198         /// <summary>
199         /// 前10活动信息集合
200         /// </summary>
201         /// <returns></returns>
202         public static List<Model.ActivityBulletin> GetActivityBulletinList()
203         {
204             List<Model.ActivityBulletin> result = new List<Model.ActivityBulletin>();
205             string sql = @" SELECT top 10 id,title,imgName,Details,beginTime,Type,SponsorEnterpriseName,
206                                 LinkMan,Phone,endTime,Recommend,AssociationsID,TIndex FROM
207                             [dbo].[ActivityBulletin] order by TIndex";
208             string connStr = SqlConnectionHelper.GetConnection();
209             using (IDataReader reader = SqlHelper.ExecuteReader(connStr, CommandType.Text, sql, null))
210             {
211                 while (reader.Read())
212                 {
213                     result.Add(new Model.ActivityBulletin
214                     {
215                         ID = SqlHelper.ReadNullableValue<Guid>(reader, 0),
216                         Title = SqlHelper.ReadNullableString(reader, 1),
217                         IMGName = SqlHelper.ReadNullableString(reader, 2),
218                         Details = SqlHelper.ReadNullableString(reader, 3),
219                         BeginTime = SqlHelper.ReadNullableValue<DateTime>(reader, 4),
220                         Type = SqlHelper.ReadNullableEnum<AssociationsTypeEnum>(reader, 5),
221                         SponsorEnterpriseName = SqlHelper.ReadNullableString(reader, 6),
222                         LinkMan = SqlHelper.ReadNullableString(reader, 7),
223                         Phone = SqlHelper.ReadNullableString(reader, 8),
224                         EndTime = SqlHelper.ReadNullableValue<DateTime>(reader, 9),
225                         Recommend = SqlHelper.ReadNullableValue<int>(reader, 10),
226                         AssociationsID = SqlHelper.ReadNullableValue<Guid>(reader, 11),
227                         TIndex = SqlHelper.ReadNullableValue<int>(reader, 12)
228                     });
229                 }
230             }
231             return result;
232         }
233         /// <summary>
234         /// 活动信息集合根据时间
235         /// </summary>
236         /// <returns></returns>
237         public static List<Model.ActivityBulletin> GetActivityBulletinList(int count)
238         {
239             List<Model.ActivityBulletin> result = new List<Model.ActivityBulletin>();
240             string sql = string.Format(@" SELECT top {0} id,title FROM
241                             [dbo].[ActivityBulletin] order by InDate Desc",count);
242             string connStr = SqlConnectionHelper.GetConnection();
243             using (IDataReader reader = SqlHelper.ExecuteReader(connStr, CommandType.Text, sql, null))
244             {
245                 while (reader.Read())
246                 {
247                     result.Add(new Model.ActivityBulletin
248                     {
249                         ID = SqlHelper.ReadNullableValue<Guid>(reader, 0),
250                         Title = SqlHelper.ReadNullableString(reader, 1)
251                     });
252                 }
253             }
254             return result;
255         }
256         public static List<ActivityBulletin> GetMyActivityBulletinList(ActivityBulletinQueryEntity query)
257         {
258             List<Model.ActivityBulletin> result = new List<Model.ActivityBulletin>();
259             string tempStr = string.Empty;
26
294             List<SqlParameter> parms = new List<SqlParameter>();
295             parms.Add(SqlHelper.CreateParameter("@RowCount", query.TotalRecord));
296             parms[0].Direction = ParameterDirection.Output;
297             parms.Add(SqlHelper.CreateParameter("@PageIndex", query.PageIndex));
298             parms.Add(SqlHelper.CreateParameter("@PageSize", query.PageSize));
299             parms.Add(SqlHelper.CreateEnumParamter("@Type", query.Type));
300             parms.Add(SqlHelper.CreateEnumParamter("@ID", query.ActivityID));
301             parms.Add(SqlHelper.CreateParameter("@AssociationsID", query.AssociationsID));
302             parms.Add(SqlHelper.CreateParameter("@TIndex", query.TIndex));
303             parms.Add(SqlHelper.CreateParameter("@BlurInfo", query.BlurInfo));
304             parms.Add(SqlHelper.CreateParameter("@EndTime", query.EndTime));
305             parms.Add(SqlHelper.CreateParameter("@BeginTime", query.BeginTime));
306
307             string connStr = SqlConnectionHelper.GetConnection();
308             using (IDataReader reader = SqlHelper.ExecuteReader(connStr, CommandType.StoredProcedure, "Proc_GetMyActivityBulletinList", parms.ToArray()))
309             {
310                 while (reader.Read())
311                 {
312                     result.Add(new Model.ActivityBulletin
313                     {
314                         Title = SqlHelper.ReadNullableString(reader, 1),
315                         IMGName = SqlHelper.ReadNullableString(reader, 2),
316                         Details = SqlHelper.ReadNullableString(reader, 3),
317                         ID = SqlHelper.ReadNullableValue<Guid>(reader, 4),
318                         BeginTime = SqlHelper.ReadNullableValue<DateTime>(reader, 5),
319                         Type = SqlHelper.ReadNullableEnum<AssociationsTypeEnum>(reader, 6),
320                         SponsorEnterpriseName = SqlHelper.ReadNullableString(reader, 7),
321                         LinkMan = SqlHelper.ReadNullableString(reader, 8),
322                         Phone = SqlHelper.ReadNullableString(reader, 9),
323                         EndTime = SqlHelper.ReadNullableValue<DateTime>(reader, 10),
324                         Recommend = SqlHelper.ReadNullableValue<int>(reader, 11),
325                         AssociationsID = SqlHelper.ReadNullableValue<Guid>(reader, 12),
326                         TIndex = SqlHelper.ReadNullableValue<int>(reader, 13)
327                     });
328                 }
329             }
330             query.TotalRecord = (int)parms[0].Value;
331             return result;
332         }
333     }
334 }
时间: 2024-10-13 07:45:12

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

c#/ASP.NET操作cookie(读写)代码示例

Cookie是存在硬盘上,IE存cookie的地方和Firefox存cookie的地方不一样.不同的操作系统也可能存cookie的地方不一样. 不同的浏览器会在各自的独立空间存放Cookie, 互不干涉以我的windows7, IE8为例,  cookie存在这: C:\Users\xiaoj\AppData\Local\Microsoft\Windows\Temporary Internet Files 注意: 缓存文件和cookie文件,是存在一起的, 都在这个目录下. 你也可以这样找, 打

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

Fine Uploader(http://fineuploader.com/)是一个实现 ajax 上传文件的 Javascript 组件. This project attempts to achieve a user-friendly file-uploading experience over the web. It's built as a Javascript plugin for developers looking to incorporate file-uploading int

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

本文转自:http://www.codeusing.com/hi/uephee.wen/resource/view/170.aspx 资源分类:微软代码示例               更新日期:2008-10-11 主页:http://msdn.microsoft.com/en-us/library/aa581769.aspx 语言:英文  授权形式:免费 微软 Scott Mitchell 为大家准备的 ASP.NET 2.0 三层架构应用程序系列教程,共35讲,分别有C#和VB.NET版本

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

今天这篇文章我们来聊一聊如何提升并优化ASP.NET Core应用程序的性能,本文的大部分内容来自翻译,当然中间穿插着自己的理解,希望对大家有所帮助!话不多说开始今天的主题吧! 我们都知道性能是公共网站取得成功的关键因素之一.如果一个网站的响应时间超过3秒,那么用户通常不会再此光顾(此网站).谷歌,Bing,百度以及其他搜索引擎也更倾向于推荐优化后的,移动友好的以及响应速度更快的网站. 作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/10507984.

计算DXFReader中多边形的面积代码示例

在DXFReader中, 一般的多边形的面积计算绝对值 其中K表是顶点的数目,它们的坐标,用于在求和和, 所以用下面的代码就可以计算出一个封闭的多段线的区域: view source print? 01 Dim Vertex As Object 02 Dim Entity As Object 03 Dim k As Long 04 Dim i As Long 05 Dim Area As Single 06 07 With DXFReader1 08 09  For Each Entity In

代码示例:一些简单技巧优化JavaScript编译器工作详解,让你写出高性能运行的更快JavaScript代码

告诉你一些简单的技巧来优化JavaScript编译器工作,从而让你的JavaScript代码运行的更快.尤其是在你游戏中发现帧率下降或是当垃圾回收器有大量的工作要完成的时候. 单一同态: 当你定义了一个两个参数的函数,编译器会接受你的定义,如果函数参数的类型.个数或者返回值的类型改变编译器的工作会变得艰难.通常情况下,单一同态的数据结构和个数相同的参数会让你的程序会更好的工作. function example(a, b) { // 期望a,b都为数值类型 console.log(++a * +

jquery操作单选钮代码示例

jquery操作单选钮代码示例:radio单选按钮是最重要的表单元素之一,下面介绍一下常用的几个jquery对radio单选按钮操作.一.取消选中: $(".theclass").each(function(){ if($(this).attr('checked')) { $(this).attr('checked',false); } }); 以上代码可以将class属性值为theclass的被选中单选按钮取消选中.二.获取被选中的单选按钮的值: var val=$('.thecla

Python实现各种排序算法的代码示例总结

Python实现各种排序算法的代码示例总结 作者:Donald Knuth 字体:[增加 减小] 类型:转载 时间:2015-12-11我要评论 这篇文章主要介绍了Python实现各种排序算法的代码示例总结,其实Python是非常好的算法入门学习时的配套高级语言,需要的朋友可以参考下 在Python实践中,我们往往遇到排序问题,比如在对搜索结果打分的排序(没有排序就没有Google等搜索引擎的存在),当然,这样的例子数不胜数.<数据结构>也会花大量篇幅讲解排序.之前一段时间,由于需要,我复习了

领域驱动开发推荐代码示例 — Microsoft NLayerApp

简介: Microsoft NLayerApp是由微软西班牙团队出品的基于.NET 4.0的“面向领域N层分布式架构”代码示例,在codeplex上的地址是:http://microsoftnlayerapp.codeplex.com/. 架构图: 点击查看大图 代码下载:http://microsoftnlayerapp.codeplex.com/releases/view/56660 所用到的软件: - Microsoft Visual Studio 2010  - Microsoft Ex