源代码:

string depAll = (ddl_dep1.SelectedValue == "") ? "" : ddl_dep1.SelectedValue + '%';
string dep = ddl_dep1.SelectedValue.Split('/')[].ToString();
string strSql_dep = "Select * from dep where DEP_CLASS=2 AND dep_all_code LIKE '" + depAll + "' AND dep_code in (SELECT DISTINCT DEP2 FROM depview WHERE dep3 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID.ToUpper() + "') OR dep2 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID.ToUpper() + "') )Order By LDAP";
if (Request["account"] == null)
{
strSql_dep = strSql_dep.Replace("SELECT dep_code FROM person_limits", "SELECT user_dep FROM users");
}
DataTable dt_dep2 = cOracle.ProduceData(strSql_dep);
DataTable dtCount = cOracle.ProduceData("SELECT COUNT(*) FROM depview WHERE dep3 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID + "') AND dep1='" + dep + "' UNION all SELECT COUNT(*) FROM depview d WHERE dep1='" + dep + "'");
}
if (dtCount.Rows.Count == )
{
if (dtCount.Rows[][].ToString() == dtCount.Rows[][].ToString())
{
ddl_dep2.Items.Add(new ListItem(base.GetLocalResourceObject("PleaseSelect").ToString(), ""));
}
}
foreach (DataRow dr in dt_dep2.Rows)
{
ddl_dep2.Items.Add(new ListItem(dr["DEP_NAME"].ToString().Trim(), dr["DEP_ALL_CODE"].ToString().Trim()));
}

重写为LINQ:

string strSql_dep = "Select * from dep where DEP_CLASS=2 AND dep_all_code LIKE '" + depAll + "' AND dep_code in (SELECT DISTINCT DEP2 FROM depview WHERE dep3 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID.ToUpper() + "')  OR dep2 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID.ToUpper() + "')  )Order By LDAP";
// Xudaxia:修改EF
depAll = (ddl_dep1.SelectedValue == "") ? "" : ddl_dep1.SelectedValue;
IPERSON_LIMITSRepository personLimRep = new PERSON_LIMITSRepository(DatabaseFactory.GetFactory());
IDEPVIEWRepository depViewRep = new DEPVIEWRepository(DatabaseFactory.GetFactory());
IDEPRepository depRepository = new DEPRepository(DatabaseFactory.GetFactory());
IEnumerable<string> dep_codes = from p in personLimRep.GetAll()
where p.ACCOUNT.ToUpper() == UserID.ToUpper()
select p.DEP_CODE;
IEnumerable<string> DEP2s = (from d in depViewRep.GetAll()
where dep_codes.Contains(d.DEP3) ||
dep_codes.Contains(d.DEP2)
select d.DEP2).Distinct();
var query = from d in depRepository.GetAll()
where d.DEP_CLASS == &&
d.DEP_ALL_CODE.StartsWith(depAll) &&
DEP2s.Contains(d.DEP_CODE)
select d; if (Request["account"] == null)
{
strSql_dep = strSql_dep.Replace("SELECT dep_code FROM person_limits", "SELECT user_dep FROM users");
// Xudaxia:修改EF
IUSERSRepository userRep = new USERSRepository(DatabaseFactory.GetFactory());
dep_codes = from u in userRep.GetAll()
where u.ACCOUNT.ToUpper() == UserID.ToUpper()
select u.USER_DEP;
DEP2s = (from d in depViewRep.GetAll()
where dep_codes.Contains(d.DEP3) ||
dep_codes.Contains(d.DEP2)
select d.DEP2).Distinct();
query = from d in depRepository.GetAll()
where d.DEP_CLASS == &&
d.DEP_ALL_CODE.StartsWith(depAll) &&
DEP2s.Contains(d.DEP_CODE)
select d;
}
//DataTable dt_dep2 = cOracle.ProduceData(strSql_dep);
// Xudaxia:修改EF
DataTable dt_dep2 = query.ToDataTable();
//DataTable dtCount = cOracle.ProduceData("SELECT COUNT(*) FROM depview WHERE dep3 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID + "') AND dep1='" + dep + "' UNION all SELECT COUNT(*) FROM depview d WHERE dep1='" + dep + "'"); dep_codes = from p in personLimRep.GetAll()
where p.ACCOUNT.ToUpper() == UserID
select p.DEP_CODE;
int count1 = (from d in depViewRep.GetAll()
where dep_codes.Contains(d.DEP3) &&
d.DEP1 == dep
select d).Count();
int count2 = depViewRep.GetMany(d => d.DEP1 == dep).Count();
//if (dtCount.Rows.Count == 2)
//{
// if (dtCount.Rows[0][0].ToString() == dtCount.Rows[1][0].ToString())
// {
// ddl_dep2.Items.Add(new ListItem(base.GetLocalResourceObject("PleaseSelect").ToString(), ""));
// }
//}
if (count1 == count2)
{
ddl_dep2.Items.Add(new ListItem(base.GetLocalResourceObject("PleaseSelect").ToString(), ""));
}
foreach (DataRow dr in dt_dep2.Rows)
{
ddl_dep2.Items.Add(new ListItem(dr["DEP_NAME"].ToString().Trim(), dr["DEP_ALL_CODE"].ToString().Trim()));
}

LINQ 多条件写法的更多相关文章

  1. 白话LINQ系列2---以代码演进方式学习LINQ必备条件

    今天,我们通过一个简单的示例代码的演进过程,来学习LINQ必备条件:隐式类型局部变量:对象集合初始化器:委托:匿名函数:lambda表达式:扩展方法:匿名类型.废话不多说,我们直接进入主题. 一.实现 ...

  2. 学习LINQ必备条件

    转自:http://www.cnblogs.com/VolcanoCloud/p/4451302.html 学习LINQ必备条件:隐式类型局部变量:对象集合初始化器:委托:匿名函数:lambda表达式 ...

  3. EntityFramework linq 多条件查询,不定条件查询

    一.场景描述: 开发的时候,有些查询功能,往往查询的条件是不确定的,用户没有填的不参与到查询中去. 如图1所示,用户可能只要给根据名称来查询即可,有时候开始时间和结束时间并不需要填写. 图 1 二.解 ...

  4. 转 --简单解决Linq多条件组合问题

    本文笔者用清晰的实例,解决了Linq多条件问题,思路十分的清晰,笔者也很细心的做了描述,希望能给你带来帮助. 最近有个项目准备功能改版,师兄吩咐:尽可能地做到万般皆Linq,所以很多东西都要从存储过程 ...

  5. Linq动态条件

    很多情况下,我们开发程序,需要动态拼接SQL查询语句; 比如  select top 1 * from User where age= 18  and  name = 'renruiquan' 其中红 ...

  6. linq 多条件查询

    Linq 进行多条件查询的时候使用PredicateBuilder帮助类可以很好的解决. 类的源码: public static class PredicateBuilder { /// <su ...

  7. LINQ多条件OR模糊查询

    本文章转载:http://www.cnblogs.com/guyun/archive/2012/10/18/2729888.html 需求是这样的,有一张表tbl(Key[int],Value[str ...

  8. Linq查询条件里有可空字段比较时报错variable '<>h__TransparentIdentifier2' of type referenced from scope '', but it is not defined

    当我运行下面的linq查询时报了这个错,   1: var result = (from so in svcContext.new_sales_orderSet 2: join soitem in s ...

  9. Linq in条件查询

    Linq 实现sql中的not in和in条件查询   T-SQL的IN: Select ProductID, ProductName, CategoryID From dbo.Products Wh ...

随机推荐

  1. clang failed with exit code 1 的常见情况

    1:文件重复,如生成了一份  xxx副本.m 2:reachablity.h 这个文件经常重复. 以上优先检查 .

  2. Entity Framework 学习初级篇1--EF基本概况

    转自:http://www.cnblogs.com/Tally/archive/2012/09/14/2685011.html 最近在学习研究微软的EF,通过这时间的学习研究,感觉这个EF目前来说还不 ...

  3. 基础算法(搜索):NOIP 2015 斗地主

    Description 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据牌的数码表示如下:3& ...

  4. OpenCV学习(一)

    环境:OpenCV 2.4.4 VS2010 第一个Demo,显示一张图片 #include "opencv2/highgui/highgui.hpp" int main( int ...

  5. zabbix邮件告警

    Zabbix邮件告警看了很多文档,写的那叫一个蛋疼,明明没有发出去邮件,硬要糊弄观众,我也跟着被糊弄. 操作系统环境: CentOS 5.5 x84_64位 Zabbix版本2.2.3 Web服务器: ...

  6. linux IPC总结——管道

    管道 管道是unix ipc的最古老形式,是一种在内存中的特殊文件,只能在具有公共祖先的进程之间使用(即父子进程,兄弟进程). 管道由pipe函数创建 #include <unistd.h> ...

  7. 3 视频里weekend05、06、07的可靠性 + HA原理、分析、机制 + weekend01、02、03、04、05、06、07的分布式集群搭建

    现在,我们来验证分析下,zookeeper集群的可靠性 现在有weekend05.06.07 将其一个关掉, 分析,这3个zookeeper集群里,杀死了weekend06,还存活weekend05. ...

  8. Yii框架zii.widgets.grid自定义按钮,ajax触发事件并提示

    相关类手册: http://www.yiichina.com/api/CButtonColumn   buttons 属性 public array $buttons; the configurati ...

  9. linux下如何执行PHP脚本

    Linux 下如何直接执行 php 脚本? 下面是部分 php 命令行参数. 用法 php [-q] [-h] [-s] [-v] [-i] [-f ] | { [args...]} -q 安静模式, ...

  10. 【转】[精华] 跟我一起写 Makefile

    陈皓 概述  —— 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的程序员,m ...