源代码:

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. Hadoop之Pig安装

    Pig可以看做是Hadoop的客户端软件,使用Pig Latin语言可以实现排序.过滤.求和.分组等操作. Pig的安装步骤: 一.去Pig的官方网站下载.http://pig.apache.org/ ...

  2. openstack libtray

    OpenStack packages¶ Distributions release OpenStack packages as part of the distribution or using ot ...

  3. IoC/DIP其实是一种管理思想

    关于IoC的的概念提出来已经很多年了,其被用于一种面象对像的设计.我在这里再简单的回顾一下这个概念.我先谈技术,再说管理. 话说,我们有一个开关要控制一个灯的开和关这两个动作,最常见也是最没有技术含量 ...

  4. General: Know How to Use InetAddress

    Modern applications often need the ability to learn information about hosts out on the network. One ...

  5. 数字集成电路设计-8-一个简单sobel图像边缘检测加速器的设计,实现,仿真与综合

    引言 图像视频处理等多媒体领域是FPGA应用的最主要的方面之一,边缘检测是图像处理和计算机视觉中的基本问题,所以也是最常用的,随着数据量的不断增加以及对实时性的要求,一般软件已经不能满足实际需要,这时 ...

  6. 解决Ubuntu Server 12.04换了网卡MAC地址后 网络不可用的问题.

    重装了系统,新建了一个ubuntu虚拟机,加载原来的镜像,结果启动后网络变得不正常了,提示信息 Waiting for network configuration...Waiting up to 60 ...

  7. 高性能MySql进化论(十一):常见查询语句的优化

    总结一下常见查询语句的优化方式 1        COUNT 1.       COUNT的作用 ·        COUNT(table.filed)统计的该字段非空值的记录行数 ·         ...

  8. mdk编译遇见的错误(LX4F120H),望各位指点迷津

    程序如下 #define tBoolean int#define GPIO_PORTA_BASE g_pulGPIOBaseAddrs[0]#include "lib/gpio.h" ...

  9. 追踪CPU跑满 堆栈调试

    http://blog.donghao.org/2014/04/24/%E8%BF%BD%E8%B8%AAcpu%E8%B7%91%E6%BB%A1/

  10. 自定义String类,并且实现在STL容器中添加自定义的类型

    13.44 编写标准库string类的简化版本,命名String.你的类应该至少有一个默认构造函数和一个接受C风格字符串指针参数的构造函数.使用allocator为你的String类分配所需内存. 1 ...