组合查询一直是我一个头疼的事情,经过我不懈努力,终于在看了多次博客找了n多资料后实现了,现在拿出来和大家共享,希望大家指正!
首先是界面:
'/************************************************* '作者:许恕'小组: '说明:转换组合查询汉字为代码的类'创建日期:2013.3.8'版本号:v1.0.0'*********************************************/Public Class CombineCheckChangeStringBLL ' /// <summary> ' /// depiction:<改方法是转换上下机字符> ' /// </summary> ' /// <param name="<strCombinestring>"><上下机实体></param> ' /// <returns> ' ///<返回上下机实体> ' /// </returns> Public Function ChangeOnlineRecordString(strCombinestring As Entity.CombineselectEntity) As Entity.CombineselectEntity '转换字段 strCombinestring.FIEldname1 = ChangeOnlineRecordFIEldname(strCombinestring.FIEldname1) strCombinestring.FIEldname2 = ChangeOnlineRecordFIEldname(strCombinestring.FIEldname2) strCombinestring.FIEldname3 = ChangeOnlineRecordFIEldname(strCombinestring.FIEldname3) '装换 *** 作符 strCombinestring.OperationalChar1 = ChangeOperationalChar(strCombinestring.OperationalChar1) strCombinestring.OperationalChar2 = ChangeOperationalChar(strCombinestring.OperationalChar2) strCombinestring.OperationalChar3 = ChangeOperationalChar(strCombinestring.OperationalChar3) '转换关系符 strCombinestring.Relationchar1 = ChangeRelationchar(strCombinestring.Relationchar1) strCombinestring.Relationchar2 = ChangeRelationchar(strCombinestring.Relationchar2) Return strCombinestring End Function' /// <summary> ' /// depiction:<改方法是转换上下机字符-字段> ' /// </summary> ' /// <param name="<strOnline>"><上下机字符></param> ' /// <returns> ' ///<返回上字符串> ' /// </returns> Public Function ChangeOnlineRecordFIEldname(strOnline As String) As String Dim strOnlineReturn As String Select Case strOnline Case "卡号" strOnlineReturn = "card_ID" Case "上机日期" strOnlineReturn = "online_date" Case "上机时间" strOnlineReturn = "online_time" Case "机房号" strOnlineReturn = "computer_no" Case Else strOnlineReturn = "" End Select Return strOnlineReturn End Function ' /// <summary> ' /// depiction:<改方法是转换字符- *** 作符> ' /// </summary> ' /// <param name="<strOnline>"><上下机字符></param> ' /// <returns> ' ///<返回上字符串> ' /// </returns> Public Function ChangeOperationalChar(strChange As String) As String Dim strRenturn As String Select Case strChange Case "大于" strRenturn = " > " Case "小于" strRenturn = " < " Case "等于" strRenturn = " = " Case "不等于" strRenturn = " <> " Case Else strRenturn = " " End Select Return strRenturn End Function ' /// <summary> ' /// depiction:<改方法是转换关系字符> ' /// </summary> ' /// <param name="<strOnline>"><上下机字符></param> ' /// <returns> ' ///<返回上字符串> ' /// </returns> Public Function ChangeRelationchar(strChange As String) As String Dim strRenturn As String Select Case strChange Case "并且" strRenturn = " and " Case "或者" strRenturn = " or " Case Else strRenturn = "" End Select Return strRenturn End FunctionEnd Class'/************************************************* '作者:许恕'小组: '说明:上机事务的类'创建日期:2013.2.28'版本号:v1.0.0'*********************************************/Public Class OnlineBLL' /// <summary> ' /// depiction:<改方法是组合查询上机信息> ' /// </summary> ' /// <param name="<checkString>"><组合查询实体></param> ' /// <returns> ' ///<返回datatable> ' /// </returns> Public Function CombineCheckOnlineRecord(enCheckString As Entity.CombineselectEntity) As Datatable '改变组合查询的字符为英文 Dim ChangeStringBLL As New CombineCheckChangeStringBLL enCheckString = ChangeStringBLL.ChangeOnlineRecordString(enCheckString) '查询内容 Dim RecordFactory As New Factory.RecordFactory Dim IOnlineRecordDAL As IDAL.IOnlineRecordSeverDAL Dim OnlineDatatable As Datatable IOnlineRecordDAL = RecordFactory.CreatOnlineRecordSeverDAL() OnlineDatatable = IOnlineRecordDAL.CombineCheckOnlineRecord(enCheckString) '返回查询到的内容 Return OnlineDatatable End FunctionEnd Class
放到DAL 层我们的实现就简单了,我们拼接字符串查询就可以了
imports Systemimports System.Dataimports System.Data.sqlClIEntimports System.Configuration'/************************************************* '作者:许恕'小组: '说明:组合查询字符组合成sql的类'创建日期:2013.3.9'版本号:v1.0.0'*********************************************/Public Class GroupCombinesqlStringDAL ' /// <summary> ' /// depiction:<改方法是组合上机查询语句> ' /// </summary> ' /// <param name="<enCheckString>"><组合查询字符实体></param> ' /// <returns> ' ///<返回string> ' /// </returns> Public Shared Function GroupOnlinesqlString(enCheckString As Entity.CombineselectEntity) As String Dim strsql As String strsql = "Select * from T_OnlineRecord where " & enCheckString.FIEldname1 & enCheckString.OperationalChar1 & " @SelectString1 " If enCheckString.Relationchar1 = "" Then Return strsql End If strsql = strsql & enCheckString.Relationchar1 & " " & enCheckString.FIEldname2 & enCheckString.OperationalChar2 & " @SelectString2 " If enCheckString.Relationchar2 = "" Then Return strsql End If strsql = strsql & enCheckString.Relationchar1 & " " & enCheckString.FIEldname2 & enCheckString.OperationalChar2 & " @SelectString2 " Return strsql End FunctionEnd Class'/************************************************* '作者:许恕'小组: '说明:对用户表 *** 作的类'创建日期:2013.2.28 16:00'版本号:v1.0.0'*********************************************/Public Class sqlSeverOnlineRecordSeverDAL : Implements IDAL.IOnlineRecordSeverDAL' /// <summary> ' /// depiction:<改方法是组合查询记录> ' /// </summary> ' /// <param name="<enCard>"><查询实体></param> ' /// <returns> ' ///<返回datatable> ' /// </returns>Public Function CombineCheckOnlineRecord(enCheckString As Entity.CombineselectEntity) As Datatable Implements IDAL.IOnlineRecordSeverDAL.CombineCheckOnlineRecord '创建sqlhelper类 Dim usersqlHelper As New sqlHelper.sqlHelper 'SQL语句 Dim strsql As String Dim OnlineDatatable As Datatable 'SQL查询语句 strsql = GroupCombinesqlStringDAL.GroupOnlinesqlString(enCheckString) '设置参数 Dim sqlParams As sqlParameter() If enCheckString.Relationchar1 = "" Then sqlParams = { New sqlParameter("@SelectString1",enCheckString.SelectString1) } End If If enCheckString.Relationchar2 = "" And enCheckString.Relationchar1 <> "" Then sqlParams = { New sqlParameter("@SelectString1",enCheckString.SelectString1),New sqlParameter("@SelectString2",enCheckString.SelectString2) } End If If enCheckString.Relationchar2 <> "" And enCheckString.Relationchar1 <> "" Then sqlParams = { New sqlParameter("@SelectString1",enCheckString.SelectString2),New sqlParameter("@SelectString3",enCheckString.SelectString3) } End If '执行 OnlineDatatable = usersqlHelper.ExecuteSelect(strsql,CommandType.Text,sqlParams) Return OnlineDatatable End FunctionEnd Class
最后是结果:我们艰苦的奋斗有了结果: 总结
以上是内存溢出为你收集整理的vb.net机房收费系统—组合查询的实现全部内容,希望文章能够帮你解决vb.net机房收费系统—组合查询的实现所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)