利用jQueryEasyUi框架实现服务端数据显示以及利用http协议方式请求处理数据
1.一般处理文件:Handler1.ashx 主要处理来自客户端请求数据并返回相关信息
using System; using System.Collections.Generic; using System.Linq; using System.Web; using DBUtility; using System.Data; using System.Text; using CardServerBLL; using CardServerModel; using System.Web.Script.Serialization; using System.Web.Services.Description; namespace CardServer { /// <summary> /// Handler1 的摘要说明 /// </summary> public class Handler1 : IHttpHandler { SloteCardTimesBLL BLL = new SloteCardTimesBLL(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); var cardno = context.Request.Form[0];//获取到客户端传递的卡号信息 //string CardNo = context.Request["CardNO"]; SloteCardTimesModel slote = new SloteCardTimesModel(); StringBuilder strBuilder = new StringBuilder(); //查询条件 //if (!string.IsNullOrEmpty(cardno)) //{ // strBuilder.Append(" and CardNO=").Append(cardno).Append(" "); //} CustermListJSON custermListJSON = new CustermListJSON(); custermListJSON.rows = new List<CustermJSON>(); slote.CardNO = cardno;//传递参数刷卡账号 slote.SloteCardTime = DateTime.Now;//刷卡时间就是服务器现在时间 CustermBLL custerbll = new CustermBLL(); //根据卡号获得信息 List<CustermModel> list = custerbll.GetCustermListByCardNO(cardno); //custermListJSON.total=custerbll. string writeMsg = ""; //判断如果卡号存在就记录一笔刷卡记录 如果卡号不存在就不能操作 if (list != null) { //添加一笔刷卡记录到刷卡信息表中 if (BLL.Add(slote) > 0) { writeMsg = "刷卡记录添加成功!"; JavaScriptSerializer jss = new JavaScriptSerializer(); context.Response.Write(jss.Serialize(list)); } else { writeMsg = "刷卡记录添加失败!"; JavaScriptSerializer jss = new JavaScriptSerializer(); context.Response.Write(jss.Serialize(list)); } } else { writeMsg = "此账号不存在无权操作 不能刷卡!"; return; } //string sql = "select * from ak_SloteCardTimes" ; // int page = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0; // int size = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0; // string sort = context.Request.Form["sort"] != "" ? context.Request.Form["sort"] : ""; // string order = context.Request.Form["order"] != "" ? context.Request.Form["order"] : ""; // if (page < 1) return; // string orderField = sort.Replace("JSON_", ""); // string keyname = context.Request["searchKey"];//查询的关键字 // string keyvalue = context.Request["searchValue"];//查询的字段 // string strWhere = " where 1=1";//查询条件 // if (keyname != null) // { // strWhere += " and " + keyname + " like '%" + keyvalue + "%'"; // } // int count = BLL.GetList(strWhere).Tables[0].Rows.Count;//获取总数 // DataSet dsCuster = DataHandler.GetList(" ak_SloteCardTimes ", " CardNO,SloteCardTime ", "RecordID", size, page, count, false, false, strWhere); // string strJSON = JsonHelper.CreateJsonParameters(dsCuster.Tables[0], true, count); // context.Response.Clear(); // context.Response.ContentEncoding = Encoding.UTF8; // context.Response.ContentType = "application/json"; // context.Response.Write(strJSON); // context.Response.Flush(); // context.Response.End(); } public bool IsReusable { get { return false; } } class CustermListJSON { public int total { get; set; } public List<CustermJSON> rows { get; set; } } class CustermJSON { public string CustermID { get; set; } public string CustermName { get; set; } public string CardNO { get; set; } public string ClassName { get; set; } public string Sex { get; set; } public string SIDCard { get; set; } public string SchoolName { get; set; } public string HomeAddress { get; set; } public string Professional { get; set; } public CustermJSON(string CustermID, string CustermName, string CardNO, string ClassName, string Sex, string SIDCard, string SchoolName, string HomeAddress, string Professional) { this.CustermID = CustermID; this.CustermName = CustermName; this.CardNO = CardNO; this.ClassName = ClassName; this.Sex = Sex; this.SIDCard = SIDCard; this.SchoolName = SchoolName; this.HomeAddress = HomeAddress; this.Professional = Professional; } } } }
2.展现刷卡记录信息页面
<%@ Page Title="主页" Language="C#" AutoEventWireup="true" CodeBehind="SloteCardList.aspx.cs" Inherits="CardServer._Default" %> <script src="/JS/easyUI/jquery-1.7.2.min.js" type="text/javascript"></script> <script src="/JS/easyUI/jquery.easyui.min.js" type="text/javascript"></script> <script src="/JS/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script> <link href="/JS/easyUI/themes/gray/easyui.css" rel="stylesheet" type="text/css" /> <link href="/JS/easyUI/themes/icon.css" rel="stylesheet" type="text/css" /> <script src="/JS/wikmenu.js" type="text/javascript"></script> <script src="/JS/wikmain.js" type="text/javascript"></script> <%--列表 start--%> <form id="form_list" name="form_list" method="post"> <table id="tab_list"> <div class="easyui-panel" title="查询条件" style="width:1360px;height:55px" collapsible="true" > <div class="searchitem"> <label>用户名:</label> <input type="text" id="txtUsername" class="easyui-validatebox" /> <a href="#" class="easyui-linkbutton" onclick="btnsearch()" >查询</a></div> </div> </table> </form> <%--列表 end--%> <%--添加 修改 start--%> <div id="edit" class="easyui-dialog" title="编辑用户" style="width: 350px; height: 300px;" modal="true" closed="true" buttons="#edit-buttons"> <form id="form_edit" name="form_edit" method="post" url="SloteCardList.aspx"> <table class="table_edit"> <tr> <td class="tdal"> 用户名: </td> <td class="tdar"> <input id="ipt_CustermName" name="ipt_CustermName" type="text" class="easyui-validatebox" required="true" /> </td> </tr> <tr> <td class="tdal"> 卡号: </td> <td class="tdar"> <input id="ipt_CardNO" name="ipt_CardNO" type="text" class="easyui-validatebox" required="true" /> </td> </tr> <tr> <td class="tdal"> 班级: </td> <td class="tdar"> <input id="ipt_ClassName" name="ipt_ClassName" type="text" class="easyui-validatebox" required="true" /> </td> </tr> <tr> <td class="tdal"> 性别: </td> <td class="tdar"> <select id="ipt_Sex" class="easyui-combobox" name="ipt_Sex" editable="false"> <option value="0">男</option> <option value="1">女</option> </select> </td> </tr> <tr> <td class="tdal"> 身份证号: </td> <td class="tdar"> <input id="ipt_SIDCard" name="ipt_SIDCard" type="text" class="easyui-validatebox" required="true" /> </td> </tr> <tr> <td class="tdal"> 所属学校: </td> <td class="tdar"> <input id="ipt_SchoolName" name="ipt_SchoolName" type="text" class="easyui-validatebox" required="true" /> </td> </tr> <tr> <td class="tdal"> 家庭地址: </td> <td class="tdar"> <input id="ipt_HomeAddress" name="ipt_HomeAddress" type="text" class="easyui-validatebox" required="true" /> </td> </tr> <tr> <td class="tdal"> 职位: </td> <td class="tdar"> <input id="ipt_Professional" name="ipt_Professional" type="text" class="easyui-validatebox" required="true" /> </td> </tr> </table> </form> </div> <div id="edit-buttons"> <a id="btn_add" href="javascript:;" class="easyui-linkbutton">提交</a> <a href="javascript:;" class="easyui-linkbutton" onclick="$('#edit').dialog('close');return false;">取消</a> </div> <%--添加 修改 end--%> <script type="text/javascript"> $(function () { //初始化数据列表 InitGird(); }); //初始化表格 function InitGird() { $('#tab_list').datagrid({ title: '用户刷卡信息', //表格标题 loadMsg: '正在加载,请稍后...', url: '../CustermHandler.ashx?action=list', //请求数据的页面 sortName: 'CustermName', //排序字段 idField: 'CustermID', //标识字段,主键 iconCls: '', //标题左边的图标 width: '100%', //宽度 height: $(parent.document).find("#mainPanle").height() - 10 > 0 ? $(parent.document).find("#mainPanle").height() - 10 : 454, //高度 nowrap: false, //是否换行,True 就会把数据显示在一行里 striped: true, //True 奇偶行使用不同背景色 collapsible: false, //可折叠 sortOrder: 'desc', //排序类型 remoteSort: true, //定义是否从服务器给数据排序 //冻结的列,不会随横向滚动轴移动 frozenColumns: [[ {field: 'cbx', checkbox: true }, { title: '卡号', field: 'CardNO', width: 150, sortable: true }, { title: '姓名', field: 'CustermName', width: 120 } ]], columns: [[ { title: '性别', field: 'Sex', width: 80 }, { title: '班级', field: 'ClassName', width: 100 }, { title: '身份证号', field: 'SIDCard', width: 150 }, { title: '所属学校', field: 'SchoolName', width: 120 }, { title: '家庭地址', field: 'HomeAddress', width: 120 }, { title: '职位', field: 'Professional', width: 80 }, { title: '刷卡时间', field: 'SloteCardTime', width: 100 }, // field:'opt' "操作"的跨行,一定要带上field:'opt',当然,field可以是任何值,这个值不用从数据库中绑定,随便取.如果没有field的话,会弹出 "rowspan为空或不是对象"的错误 { title: '操作', field:'CustermID', width: 120,align:'center', formatter: function (value, rec,index) { var e = '<a href="#" mce_href="#" onclick="edit(\''+ rec.xsbh + '\')">编辑</a> '; var d = '<a href="#" mce_href="#" onclick="del(\''+ index +'\')">删除</a> '; return e+d; } } ]], // <div class="toolbar"> // toolbar: [{txt:'查找',iconCls:'icon-search'}], // </div> queryParams: { "action": "list" }, pagination: true, //是否开启分页 rownumbers: true, //行号 // pageNumber: 1, //默认索引页 // pageSize: 10, //默认一页数据条数 singleSelect:false,//是否单选 }); //设置分页控件 var p = $('#tab_list').datagrid('getPager'); $(p).pagination({ pageSize: 10,//每页显示的记录条数,默认为10 pageList: [10,15,20,30,50],//可以设置每页记录条数的列表 beforePageText: '第',//页数文本框前显示的汉字 afterPageText: '页 共 {pages} 页', displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录', onBeforeRefresh:function(){ $(this).pagination('loading'); alert('before refresh'); $(this).pagination('loaded'); } }); } function edit(bh) //转到编辑页面 { window.location.href='StuEdit.aspx?id='+bh; } function del(index){ //删除操作 $.messager.confirm('确认','确认删除?',function(row){ if(row){ var selectedRow = $('#tab_list').datagrid('getSelected'); //获取选中行 $.ajax({ url:'delHandler.ashx?id='+selectedRow.xsbh+'&type=stu', //加了个type,作用是以后不管什么删除,都可以转到这个ashx中处理 success:function(){alert('删除成功');} }); $('#tab_list').datagrid('deleteRow',index); } }) } </script>
后端代码:一般处理文件 CustermHandler.ashx
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using CardServerBLL; using CardServerModel; using System.Web.Script.Serialization; namespace CardServer { /// <summary> /// CustermHandler 的摘要说明 /// </summary> public class CustermHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; DataSet ds = new DataSet(); //点击datagrid的分页按钮,自动向后台发送2个参数,rows和page,代表每页记录数和页索引 string strWhere = context.Request.Form["ipt_search"]; String action = context.Request.Form["action"]; //获取刷卡信息列表 if (action.Equals("list")) { CustermListJSON custermlistJSON = new CustermListJSON(); custermlistJSON.rows = new List<CustermJSON>(); int row = int.Parse(context.Request["rows"].ToString()); int page = int.Parse(context.Request["page"].ToString()); CustermBLL custermbll=new CustermBLL(); List<CustermModel> list = custermbll.GetCustermListPage(row, page, strWhere); custermlistJSON.total = custermbll.GetCustermCount(strWhere); foreach (CustermModel cmodel in list) { custermlistJSON.rows.Add(new CustermJSON(cmodel.CustermID.ToString(), cmodel.CardNO, cmodel.CustermName, cmodel.Sex, cmodel.ClassName, cmodel.SIDCard, cmodel.SchoolName,cmodel.HomeAddress, cmodel.Professional, cmodel.SloteCardTime.ToString() )); //解析数据信息必须与前台绑定字段值顺序一致 } JavaScriptSerializer jss = new JavaScriptSerializer(); context.Response.Write(jss.Serialize(custermlistJSON)); } } /// <summary> /// 获取用户刷卡信息 /// </summary> /// <param name="pagesize"></param> /// <param name="pageindex"></param> /// <param name="strWhere"></param> /// <returns></returns> private DataSet GetCustermList(int pagesize, int pageindex, string strWhere) { CustermBLL BLL = new CustermBLL(); return BLL.GetListPage(pagesize, pageindex, strWhere); } public bool IsReusable { get { return false; } } class CustermListJSON { public int total { get; set; } public List<CustermJSON> rows { get; set; } } class CustermJSON { public string CustermID { get; set; } public string CustermName { get; set; } public string CardNO { get; set; } public string ClassName { get; set; } public string Sex { get; set; } public string SIDCard { get; set; } public string SchoolName { get; set; } public string HomeAddress { get; set; } public string Professional { get; set; } public string SloteCardTime{get;set;} public CustermJSON(string CustermID, string CardNO, string CustermName, string Sex, string ClassName, string SIDCard, string SchoolName, string HomeAddress, string Professional, string SloteCardTime)//顺序一致 { this.CustermID = CustermID; this.CustermName = CustermName; this.CardNO = CardNO; this.Sex = Sex; this.ClassName = ClassName; this.SIDCard = SIDCard; this.SchoolName = SchoolName; this.HomeAddress = HomeAddress; this.Professional = Professional; this.SloteCardTime = SloteCardTime; } } } }
3.实体层 CardServerModel
CustermModel:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CardServerModel { /// <summary> /// Custerm:实体类(属性说明自动提取数据库字段的描述信息) /// </summary> [Serializable] public partial class CustermModel { public CustermModel() { } #region Model private int _CustermID; private string _CustermName; private string _CardNO; private string _ClassName; private string _Sex; private string _SIDCard; private string _SchoolName; private string _HomeAddress; private string _Professional; private DateTime? _SloteCardTime; /// <summary> /// ID /// </summary> public int CustermID { set { _CustermID = value; } get { return _CustermID; } } /// <summary> /// 人员名称 /// </summary> public string CustermName { set { _CustermName = value; } get { return _CustermName; } } /// <summary> /// 卡号 /// </summary> public string CardNO { set { _CardNO = value; } get { return _CardNO; } } /// <summary> /// 班级 /// </summary> public string ClassName { set { _ClassName = value; } get { return _ClassName; } } /// <summary> /// 性别 /// </summary> public string Sex { set { _Sex = value; } get { return _Sex; } } /// <summary> /// 身份证 /// </summary> public string SIDCard { set { _SIDCard = value; } get { return _SIDCard; } } /// <summary> /// 学校 /// </summary> public string SchoolName { set { _SchoolName = value; } get { return _SchoolName; } } /// <summary> /// 家庭地址 /// </summary> public string HomeAddress { set { _HomeAddress = value; } get { return _HomeAddress; } } /// <summary> /// 职位 /// </summary> public string Professional { set { _Professional = value; } get { return _Professional; } } /// <summary> /// 刷卡时间 /// </summary> public DateTime ?SloteCardTime { set { _SloteCardTime = value; } get { return _SloteCardTime; } } #endregion Model } }
SloteCardTimesModel:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CardServerModel { /// <summary> /// SloteCardTimes:实体类(属性说明自动提取数据库字段的描述信息) /// </summary> [Serializable] public partial class SloteCardTimesModel { public SloteCardTimesModel() { } #region Model private int _RecordID; private string _CardNO; private DateTime _SloteCardTime; /// <summary> /// ID /// </summary> public int RecordID { set { _RecordID = value; } get { return _RecordID; } } /// <summary> /// 卡号 /// </summary> public string CardNO { set { _CardNO = value; } get { return _CardNO; } } /// <summary> /// 刷卡时间 /// </summary> public DateTime SloteCardTime { set { _SloteCardTime = value; } get { return _SloteCardTime; } } #endregion Model } }
4.业务逻辑处理层 CardServerBLL
CustermBLL:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using CardServerModel; using CardServerDAL; using System.Data; namespace CardServerBLL { /// <summary> /// 业务逻辑处理层 /// </summary> public partial class CustermBLL { private readonly CustermDAL dal = new CustermDAL(); public CustermBLL() { } /// <summary> /// 根据客户ID得到一个对象实体 /// </summary> public CardServerModel.CustermModel GetModel(int CustermID) { return dal.GetModel(CustermID); } /// <summary> /// 获得数据列表 /// </summary> public DataSet GetList(string strWhere) { return dal.GetList(strWhere); } /// <summary> /// 分页获得数据列表 /// </summary> public DataSet GetListPage(int pagesize, int pageindex, string strWhere) { return dal.GetListPage(pagesize, pageindex, strWhere); } /// <summary> /// 分页获取客户信息列表 /// </summary> /// <param name="pagesize"></param> /// <param name="pageindex"></param> /// <param name="strWhere"></param> /// <returns></returns> public List<CustermModel> GetCustermListPage(int pagesize, int pageindex, string strWhere) { return dal.GetCustermListPage(pagesize, pageindex, strWhere); } /// <summary> /// 获取记录数 /// </summary> /// <param name="strwhere"></param> /// <returns></returns> public int GetCustermCount(string strwhere) { try { return dal.GetCustermCount(strwhere); } catch (Exception e) { // LogRecordHelper.LogNote("ERROR", e.Message); throw e; } } /// <summary> /// 根据客户卡号得到一个对象实体 根据卡号获取信息 /// </summary> public CustermModel GetCustermByCardNO(string cardno) { return dal.GetCustermByCardNO(cardno); } public List<CustermModel> GetCustermListByCardNO(string cardno) { return dal.GetCustermListByCardNO(cardno); } } }
SloteCardTimesBLL:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using CardServerDAL; using CardServerModel; using System.Data; namespace CardServerBLL { public class SloteCardTimesBLL { private readonly SloteCardTimesDAL dal = new SloteCardTimesDAL(); public SloteCardTimesBLL() { } /// <summary> /// 增加一条数据 /// </summary> public int Add(SloteCardTimesModel model) { return dal.Add(model); } /// <summary> /// 获得数据列表 /// </summary> public DataSet GetList(string strWhere) { return dal.GetList(strWhere); } } }
5.数据访问处理层 CardServerDAL
CustermDAL:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using CardServerModel; using System.Data.SqlClient; using System.Data; using DBUtility; using System.Data.Common; namespace CardServerDAL { /// <summary> /// 数据访问操作类 /// </summary> public class CustermDAL { private String tableName = "ak_Custerms A left join ak_SloteCardTimes B on A.CardNO=B.CardNO"; /// <summary> /// 获得数据列表 /// </summary> public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select A.CustermName,A.Sex,A.ClassName,A.SIDCard,A.SchoolName,A.HomeAddress,A.Professional,B.SloteCardTime,B.CardNO"); strSql.Append(" FROM ak_Custerms A left join ak_SloteCardTimes B on A.CardNO=B.CardNO "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return SQLHelper.Query(strSql.ToString()); } /// <summary> /// 分页获得数据列表 /// </summary> public DataSet GetListPage(int pagesize, int pageindex, string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select A.CustermName,A.Sex,A.ClassName,A.SIDCard,A.SchoolName,A.HomeAddress,A.Professional,B.SloteCardTime,B.CardNO"); strSql.Append(" FROM ak_Custerms A left join ak_SloteCardTimes B on A.CardNO=B.CardNO "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return SQLHelper.Query(strSql.ToString()); } /// <summary> /// 分页获取数据列表信息 /// </summary> /// <param name="pagesize"></param> /// <param name="pageindex"></param> /// <param name="strWhere"></param> /// <returns></returns> public List<CustermModel> GetCustermListPage(int pagesize, int pageindex, string strWhere) { return DataSetToList(SQLHelper.getPagedData(" CustermID,A.CardNO,CustermName,Sex,ClassName,SIDCard ,SchoolName,HomeAddress,Professional,B.SloteCardTime ", "CustermName", strWhere, tableName, DBUtility.SQLHelper.OrderBy.DESC, pageindex, pagesize)); } private List<CardServerModel.CustermModel> DataSetToList(DataSet dataSet) { List<CustermModel> modelList = new List<CustermModel>(); DataTable dt = dataSet.Tables[0]; int rowsCount = dt.Rows.Count; if (rowsCount > 0) { CustermModel model; for (int n = 0; n < rowsCount; n++) { model = new CustermModel(); model.CustermID = Convert.ToInt32( dt.Rows[n]["CustermID"].ToString()); model.CustermName = dt.Rows[n]["CustermName"].ToString(); model.CardNO = dt.Rows[n]["CardNO"].ToString(); model.Sex = dt.Rows[n]["Sex"].ToString(); model.ClassName = dt.Rows[n]["ClassName"].ToString(); model.SIDCard = dt.Rows[n]["SIDCard"].ToString(); model.SchoolName = dt.Rows[n]["SchoolName"].ToString(); model.HomeAddress = dt.Rows[n]["HomeAddress"].ToString(); model.Professional = dt.Rows[n]["Professional"].ToString(); if (dt.Rows[n]["SloteCardTime"].ToString() != "") { model.SloteCardTime = DateTime.Parse(dt.Rows[n]["SloteCardTime"].ToString()); } modelList.Add(model); } } return modelList; } /// <summary> /// 获取记录数 /// </summary> /// <param name="strwhere"></param> /// <returns></returns> public int GetCustermCount(string where) { int count = 0; StringBuilder str = new StringBuilder(); str.Append(" select count(1) from "); str.Append(tableName); if (where != null) { str.Append(" where "); str.Append(where); count = (int)SQLHelper.GetSingle(str.ToString()); } else { count = (int)SQLHelper.GetSingle(str.ToString()); } return count; } /// <summary> /// 根据客户ID得到一个对象实体 /// </summary> public CustermModel GetModel(int CustermID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CustermID,CardNO,CustermName,Sex,ClassName,SIDCard,SchoolName,HomeAddress,Professional from ak_Custerms"); strSql.Append(" where CustermID=@CustermID"); SqlParameter[] parameters = { new SqlParameter("@CustermID", SqlDbType.Int,4) }; parameters[0].Value = CustermID; CustermModel model = new CustermModel(); DataSet ds = SQLHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["CustermID"].ToString() != "") { model.CustermID = int.Parse(ds.Tables[0].Rows[0]["CustermID"].ToString()); } model.CardNO = ds.Tables[0].Rows[0]["CardNO"].ToString(); model.CustermName = ds.Tables[0].Rows[0]["CustermName"].ToString(); model.ClassName = ds.Tables[0].Rows[0]["ClassName"].ToString(); if (ds.Tables[0].Rows[0]["Sex"].ToString() != "") { model.Sex = ds.Tables[0].Rows[0]["Sex"].ToString(); } model.SIDCard = ds.Tables[0].Rows[0]["SIDCard"].ToString(); model.SchoolName = ds.Tables[0].Rows[0]["SchoolName"].ToString(); model.HomeAddress = ds.Tables[0].Rows[0]["HomeAddress"].ToString(); model.Professional = ds.Tables[0].Rows[0]["Professional"].ToString(); return model; } else { return null; } } /// <summary> /// 根据客户卡号得到一个对象实体 根据卡号获取信息 /// </summary> public CustermModel GetCustermByCardNO(string cardno) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CustermID,CardNO,CustermName,Sex,ClassName,SIDCard,SchoolName,HomeAddress,Professional from ak_Custerms "); strSql.Append(" where CardNO=@CardNO "); SqlParameter[] parameters = { new SqlParameter("@CardNO", SqlDbType.VarChar,50)}; parameters[0].Value = cardno; CustermModel model = new CustermModel(); DataSet ds = SQLHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["CustermID"].ToString() != "") { model.CustermID = int.Parse(ds.Tables[0].Rows[0]["CustermID"].ToString()); } model.CardNO = ds.Tables[0].Rows[0]["CardNO"].ToString(); model.CustermName = ds.Tables[0].Rows[0]["CustermName"].ToString(); model.ClassName = ds.Tables[0].Rows[0]["ClassName"].ToString(); if (ds.Tables[0].Rows[0]["Sex"].ToString() != "") { model.Sex = ds.Tables[0].Rows[0]["Sex"].ToString(); } model.SIDCard = ds.Tables[0].Rows[0]["SIDCard"].ToString(); model.SchoolName = ds.Tables[0].Rows[0]["SchoolName"].ToString(); model.HomeAddress = ds.Tables[0].Rows[0]["HomeAddress"].ToString(); model.Professional = ds.Tables[0].Rows[0]["Professional"].ToString(); //if (ds.Tables[0].Rows[0]["EstablishedTime"].ToString() != "") //{ // model.EstablishedTime = DateTime.Parse(ds.Tables[0].Rows[0]["EstablishedTime"].ToString()); return model; } else { return null; } } /// <summary> /// 根据客户卡号得到一个对象实体 根据卡号获取信息 /// </summary> public List<CustermModel> GetCustermListByCardNO(string cardno) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CustermID,CardNO,CustermName,Sex,ClassName,SIDCard,SchoolName,HomeAddress,Professional from ak_Custerms "); strSql.Append(" where CardNO=@CardNO "); SqlParameter[] parameters = { new SqlParameter("@CardNO", SqlDbType.VarChar,50)}; parameters[0].Value = cardno; List<CustermModel> modelList = new List<CustermModel>(); DataSet ds = SQLHelper.Query(strSql.ToString(), parameters); //DataTable dt = ds.Tables[0]; //int rowsCount = dt.Rows.Count; if (ds.Tables[0].Rows.Count > 0) { for (int n = 0; n < ds.Tables[0].Rows.Count; n++) { CustermModel model = new CustermModel(); if (ds.Tables[0].Rows[0]["CustermID"].ToString() != "") { model.CustermID = int.Parse(ds.Tables[0].Rows[0]["CustermID"].ToString()); } model.CardNO = ds.Tables[0].Rows[0]["CardNO"].ToString(); model.CustermName = ds.Tables[0].Rows[0]["CustermName"].ToString(); model.ClassName = ds.Tables[0].Rows[0]["ClassName"].ToString(); if (ds.Tables[0].Rows[0]["Sex"].ToString() != "") { model.Sex = ds.Tables[0].Rows[0]["Sex"].ToString(); } model.SIDCard = ds.Tables[0].Rows[0]["SIDCard"].ToString(); model.SchoolName = ds.Tables[0].Rows[0]["SchoolName"].ToString(); model.HomeAddress = ds.Tables[0].Rows[0]["HomeAddress"].ToString(); model.Professional = ds.Tables[0].Rows[0]["Professional"].ToString(); //if (ds.Tables[0].Rows[0]["EstablishedTime"].ToString() != "") //{ // model.EstablishedTime = DateTime.Parse(ds.Tables[0].Rows[0]["EstablishedTime"].ToString()); modelList.Add(model); } } return modelList; } } }
SloteCardTimesDAL:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using CardServerModel; using System.Data.SqlClient; using System.Data; using DBUtility; namespace CardServerDAL { /// <summary> /// 数据访问类 /// </summary> public class SloteCardTimesDAL { /// <summary> /// 增加一条数据 /// </summary> public int Add(SloteCardTimesModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ak_SloteCardTimes("); strSql.Append("CardNO,SloteCardTime)"); strSql.Append(" values ("); strSql.Append("@CardNO,@SloteCardTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CardNO", SqlDbType.VarChar,50), new SqlParameter("@SloteCardTime", SqlDbType.DateTime)}; parameters[0].Value = model.CardNO; parameters[1].Value = model.SloteCardTime; object obj = SQLHelper.GetSingle(strSql.ToString(), parameters); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } } /// <summary> /// 获得数据列表 /// </summary> public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select RecordID,CardNO,SloteCardTime "); strSql.Append(" FROM ak_SloteCardTimes "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return SQLHelper.Query(strSql.ToString()); } } }