源代码:

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. eclipse环境NDK问题汇总

    1. 配置NDK路径设置 可以在cygwin中通过vim修改,也可以在windows安装目录中修改 home\<你的用户名>\.bash_profile 文件中最后添加环境变量 NDK=/ ...

  2. C# json

    C# 解析 json JSON(全称为JavaScript Object Notation) 是一种轻量级的数据交换格式.它是基于JavaScript语法标准的一个子集. JSON采用完全独立于语言的 ...

  3. HDU-1339 A Simple Task

    http://acm.hdu.edu.cn/showproblem.php?pid=1339 正常做法超时,要有点小技巧存在. A Simple Task Time Limit: 2000/1000 ...

  4. jquery mobile 前言

    引用js: <link rel="stylesheet" href="../jquery.mobile-1.1.0/jquery.mobile-1.1.0.css& ...

  5. Bzoj 1674: [Usaco2005]Part Acquisition dijkstra,堆

    1674: [Usaco2005]Part Acquisition Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 337  Solved: 162[Sub ...

  6. Cocoa深入学习:NSOperationQueue、NSRunLoop和线程安全

    http://blog.cnbluebox.com/blog/2014/07/01/cocoashen-ru-xue-xi-nsoperationqueuehe-nsoperationyuan-li- ...

  7. Linux内核是如何创建一个新进程的?

    进程描述 进程描述符(task_struct) 用来描述进程的数据结构,可以理解为进程的属性.比如进程的状态.进程的标识(PID)等,都被封装在了进程描述符这个数据结构中,该数据结构被定义为task_ ...

  8. poj 3468 A Simple Problem with Integers【线段树区间修改】

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 79137   ...

  9. Linux安装Team Service Agent

    (1)下载linux agent文件(在windows中下载后,通过WinSCP复制至linux服务器中) 或者可以在linux直接下载文件(直接下载不会因为网络问题而导致传输中断) 首先使用命令建立 ...

  10. js select级联,上面分类,下面是内容

    js select级联,上面分类,下面是内容. js级联效果如下: 分类: 请选择 水果 蔬菜 其他 内容: // html和js代码如下:     <html>      <hea ...