using System ;
using System.Collections.Generic ;
using System.Configuration ;
using System.Data ;
using System.Data.Common ;
using System.Data.Entity.Migrations ;
using System.Diagnostics ;
using System.Linq ;
using System.Text ;
using System.Web ;
using System.Web.Mvc ;
using DSWeb.Areas.CommMng.DAL ;
using DSWeb.Areas.CommMng.Models ;
using DSWeb.Areas.MvcShipping.Helper ;
using DSWeb.Common.DB ;
using DSWeb.EntityDA ;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL ;
using DSWeb.MvcShipping.Helper ;
using DSWeb.TruckMng.Comm.Cookie ;
using HcUtility.Comm ;
using java.net ;
using Microsoft.Practices.EnterpriseLibrary.Data ;
namespace DSWeb.SysMng.DAL.SysRoleTaskQuery
{
public class SysRoleTaskQueryDAL
{
public static List < Sys_Role_Task_Query_md > GetDataList ( int start , int limit , string sort , string condition , ref int count )
{
var cdc = new CommonDataContext ( ) ;
var Condition = new Condition_RoleTaskQuery ( ) ;
try
{
Condition = JsonConvert . Deserialize < Condition_RoleTaskQuery > ( condition ) ;
}
catch {
}
//QueryCollection queries = new QueryCollection();
if ( Condition ! = null ) //&&
{
QueryCollection queries = new QueryCollection ( ) ;
//queries.Add(new Query { Name = "GID", Operator = Query.Operators.Equal, Value = Guid.Empty });
if ( Condition . GID ! = null )
queries . Add ( new Query { Name = "GID" , Operator = Query . Operators . Equal , Value = Condition . GID } ) ;
if ( Condition . RoleId ! = null )
queries . Add ( new Query { Name = "RoleId" , Operator = Query . Operators . Equal , Value = Condition . RoleId } ) ;
if ( ! string . IsNullOrWhiteSpace ( Condition . MODECNNAME ) )
queries . Add ( new Query { Name = "MODECNNAME" , Operator = Query . Operators . Contains , Value = Condition . MODECNNAME } ) ;
if ( ! string . IsNullOrWhiteSpace ( Condition . BSTYPE ) )
queries . Add ( new Query { Name = "BSTYPE" , Operator = Query . Operators . Contains , Value = Condition . BSTYPE } ) ;
//var dataList = cdc.Sys_Role_Task_Query.Where(queries.AsExpression<Sys_Role_Task_Query_md>(Query.Condition.AndAlso)).ToList();
var result = new List < Sys_Role_Task_Query_md > ( ) ;
if ( queries = = null | | queries . Count = = 0 )
{
result = cdc . Sys_Role_Task_Query . Where ( x = > 1 = = 1 ) . ToList ( ) ;
}
else
{
result = cdc . Sys_Role_Task_Query . Where ( queries . AsExpression < Sys_Role_Task_Query_md > ( Query . Condition . AndAlso ) )
//.Where(queries2.AsExpression<OP_SEAE_CLIENT>(Query.Condition.AndAlso))
. ToList ( ) ;
}
count = result . Count ( ) ;
var list0 = result . Skip ( start ) . Take ( limit ) . ToList ( ) ;
return list0 ;
}
else
{
var AllList = cdc . Sys_Role_Task_Query . Where ( x = > 1 = = 1 ) . ToList ( ) ;
if ( AllList ! = null & & AllList . Count > 0 )
{
count = AllList . Count ( ) ;
AllList = AllList . Skip ( start ) . Take ( limit ) . ToList ( ) ;
return AllList ;
}
else
{
count = 0 ;
return new List < Sys_Role_Task_Query_md > ( ) ;
}
}
}
public static System . Web . Mvc . ContentResult SaveQuery ( string USERID , string ModName , string formName , string sqlcontext ) {
var jsonRespose = new JsonResponse
{
Success = true ,
Message = "" ,
Data = null
} ;
var cdc = new CommonDataContext ( ) ;
var rec = cdc . Sys_Role_Task_Query . Where ( x = > x . MODNAME = = ModName & & x . SQLCONTEXT = = "" ) . ToList ( ) ;
if ( rec = = null | | rec . Count = = 0 )
{
jsonRespose . AddError ( "无可录制的项目" ) ;
}
else {
var record = rec [ 0 ] ;
record . SQLCONTEXT = sqlcontext ;
record . FormName = formName + "Search" ;
var user_query_setting = MsBaseInfoDAL . GetUserQuerySetting ( USERID , record . FormName ) ;
if ( user_query_setting ! = null & & user_query_setting . FIELDVALUES ! = "" )
{
record . FIELDVALUES = user_query_setting . FIELDVALUES ;
}
//cdc.Sys_Role_Task_Query.AddOrUpdate(record);
cdc . SaveChanges ( ) ;
}
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public static string GetUserRoleTaskQueryList ( string USERID ) {
var result = new List < TaskListItem > ( ) ;
var cdc = new CommonDataContext ( ) ;
var _userlist = cdc . VW_user_all . Where ( x = > x . USERID = = USERID ) . ToList ( ) ;
if ( _userlist = = null | | _userlist . Count = = 0 ) {
return JsonConvert . Serialize ( new { success = true , message = "查询失败" , total = 0 } ) ;
}
var user = _userlist [ 0 ] ;
var userrolelist = cdc . user_role . Where ( x = > x . USERID = = USERID ) . ToList ( ) ;
var querylist = cdc . Sys_Role_Task_Query . Where ( x = > x . ISSTOP = = false ) . ToList ( ) ;
bool 该 用 户 是 否 需 要 显 示 该 待 办 项 ( Sys_Role_Task_Query_md item )
{
var r = false ;
if ( item . RoleId ! = null )
{
if ( userrolelist . Exists ( x = > x . ROLEID = = item . RoleId . ToString ( ) ) )
{
return true ;
}
}
else if ( ! string . IsNullOrWhiteSpace ( item . SQLSTR ) ) {
//下面为测试用
//item.SQLSTR = " select count(*) _count from user_action where ACTIONID in(select gid from [action] where MODULEID in( select gid From sys_module where [NAME]='modExchangesUnit')) and USERID='#USERID#' ";//1BEC90E1-9780-472F-90C2-0C6390C044A4
var strSql = item . SQLSTR . Replace ( "#USERID#" , USERID ) ;
var _count = 0 ;
try {
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
_count = reader [ "_count" ] = = null ? 0 : Convert . ToInt32 ( reader [ "_count" ] ) ;
}
reader . Close ( ) ;
}
if ( _count > 0 ) return true ;
}
catch ( Exception e ) {
return false ;
}
}
return r ;
}
foreach ( var rec in querylist )
{
if ( 该 用 户 是 否 需 要 显 示 该 待 办 项 ( rec ) ) {
var newrec = new TaskListItem ( ) ;
newrec . BSTYPE = rec . BSTYPE ;
var _condition = rec . GetCondition ( user . USERID ) ;
newrec . CT = BasicDataRefDAL . GetTotalCount ( rec . FormName , _condition , user . USERID , user . SHOWNAME , user . COMPANYID ) ;
newrec . CONDITION = HttpUtility . UrlEncode ( _condition ) . Replace ( "+" , "%20" ) ;
newrec . URL = rec . URL ;
newrec . MODCNAME = rec . BSTYPE ;
newrec . MODNAME = rec . MODNAME ;
newrec . BSMSG = $"当前有[{newrec.CT}]条数据" ;
newrec . GID = rec . GID . ToString ( ) ;
newrec . SORT = rec . SORT ;
result . Add ( newrec ) ;
}
}
result = result . OrderBy ( o = > o . SORT ) . ToList ( ) ;
return JsonConvert . Serialize ( new { success = true , message = "查询成功" , total = result . Count , rows = result . ToArray ( ) } ) ;
}
}
}