using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Web.Mvc ;
using DSWeb.Areas.SysMng.DAL.SysTask ;
using DSWeb.Areas.SysMng.Models.SysTask ;
using DSWeb.TruckMng.Comm.Cookie ;
using DSWeb.TruckMng.Helper ;
using DSWeb.TruckMng.Helper.Repository ;
using HcUtility.Comm ;
using HcUtility.Core ;
using DSWeb.Areas.CommMng.DAL ;
using DSWeb.SoftMng.Filter ;
namespace DSWeb.Areas.SysMng.Controllers
{
/// <summary>
///
/// </summary>
[JsonRequestBehavior]
public class SysTaskController : Controller
{
public ActionResult Index ( )
{
return View ( ) ;
}
public ActionResult ProgressIndex ( )
{
return View ( ) ;
}
public ActionResult Execution ( )
{
return View ( ) ;
}
public ActionResult Sys_Task_Progress ( )
{
return View ( ) ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetTaskState ( int start , int limit , string sort , string condition )
{
var dataList = SysTaskDAL . GetTaskState ( condition ) ;
var list = dataList . Skip ( start ) . Take ( limit ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = list . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
//查看某个state中属性里是否包含某个单词
public ContentResult TaskGetWord ( string KEY , string WORD )
{
var result = SysTaskDAL . TaskGetWord ( KEY , WORD ) ;
var json = JsonConvert . Serialize ( new { Success = result } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult GetTaskState_Combox ( string PROP5 )
{
var condition = "PROP5='" + PROP5 + "'" ;
var dataList = SysTaskDAL . GetTaskState ( condition ) ;
var _null = new TaskStateMC ( ) ;
dataList . Add ( _null ) ;
var list = dataList . Skip ( 0 ) . Take ( 9999 ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = list . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetTaskExecution ( int start , int limit , string sort , string condition )
{
var dataList = SysTaskDAL . GetTaskExecution ( condition ) ;
var list = dataList . Skip ( start ) . Take ( limit ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = list . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetTaskProgressIndex ( int start , int limit , string sort , string condition )
{
var dataList = SysTaskDAL . GetTaskProgressIndex ( condition ) ;
var list = dataList . Skip ( start ) . Take ( limit ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = list . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult GetTaskProgressIndex_Combox ( string PROP5 , string CIRRENTSTATEIDList )
{
var condition = "PROP5='" + PROP5 + "' and CIRRENTSTATEID in(" + CIRRENTSTATEIDList + ")" ;
var dataList = SysTaskDAL . GetTaskProgressIndex ( condition ) ;
var list = dataList . Skip ( 0 ) . Take ( 9999 ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = list . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult GetExecution ( string KEY )
{
var dataList = SysTaskDAL . GetExecution ( KEY ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
/// <summary>
/// 进行操作 对STATEKEY状态进行EXECUTIONKEY操作
/// </summary>
/// <param name="STATEKEY"></param>
/// <param name="EXECUTIONKEY"></param>
/// <returns></returns>
public ContentResult DoExecution ( string STATEKEY , string EXECUTIONKEY )
{
TaskStateMC data = SysTaskDAL . DoExecution ( STATEKEY , EXECUTIONKEY ) ;
var result = new JsonResponse
{
Success = true ,
Message = "执行成功" ,
Data = null
} ;
if ( data . STATEKEY = = "0000" ) {
result . Success = false ;
result . Message = "没有找到状态值或动作值" ;
}
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , data = data } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult Save1 ( string data )
{
var headList = JsonConvert . Deserialize < List < TaskStateMC > > ( data ) ;
var modb = new ModelObjectRepository ( ) ;
DBResult result = new DBResult ( ) ;
foreach ( var headData in headList )
{
var Ge = BasicDataRefDAL . GetExist ( headData . TableName , "NAME" , headData . NAME , "ID" , headData . ID . ToString ( ) ) ;
if ( Ge > 0 )
{
var jr = new JsonResponse
{
Success = false ,
Message = "名称重复" ,
Data = null
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jr ) } ;
}
}
foreach ( var headData in headList )
{
if ( headData . ID = = 0 )
{
headData . DbOperationType = DbOperationType . DbotIns ;
headData . ModelUIStatus = "I" ;
}
else
{
headData . DbOperationType = DbOperationType . DbotUpd ;
headData . ModelUIStatus = "E" ;
}
result = modb . Save ( headData ) ;
//if(result.)
}
var jsonRespose = new JsonResponse
{
Success = result . Success ,
Message = result . Message ,
Data = null
//Data = GetData(condition)
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult Save2 ( string data )
{
var headList = JsonConvert . Deserialize < List < TaskExecutionMC > > ( data ) ;
var modb = new ModelObjectRepository ( ) ;
DBResult result = new DBResult ( ) ;
foreach ( var headData in headList )
{
var Ge = BasicDataRefDAL . GetExist ( headData . TableName , "DESCRIPTION" , headData . DESCRIPTION , "ID" , headData . ID . ToString ( ) ) ;
if ( Ge > 0 )
{
var jr = new JsonResponse
{
Success = false ,
Message = "说明重复" ,
Data = null
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jr ) } ;
}
}
foreach ( var headData in headList )
{
if ( headData . ID = = 0 )
{
headData . DbOperationType = DbOperationType . DbotIns ;
headData . ModelUIStatus = "I" ;
}
else
{
headData . DbOperationType = DbOperationType . DbotUpd ;
headData . ModelUIStatus = "E" ;
}
result = modb . Save ( headData ) ;
//if(result.)
}
var jsonRespose = new JsonResponse
{
Success = result . Success ,
Message = result . Message ,
Data = null
//Data = GetData(condition)
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult Save3 ( string data )
{
var headList = JsonConvert . Deserialize < List < TaskProgressIndexMC > > ( data ) ;
var modb = new ModelObjectRepository ( ) ;
DBResult result = new DBResult ( ) ;
foreach ( var headData in headList )
{
var Ge = BasicDataRefDAL . GetExist ( headData . TableName , string . Format ( " EXECUTIONID='{0}' and CURRENTSTATEID='{1}' and FINISHSTATEID='{2}' and ID<>{3}" , headData . EXECUTIONID , headData . CURRENTSTATEID , headData . FINISHSTATEID , headData . ID ) ) ;
if ( Ge > 0 )
{
var jr = new JsonResponse
{
Success = false ,
Message = "操作内容完全重复" ,
Data = null
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jr ) } ;
}
}
foreach ( var headData in headList )
{
if ( headData . ID = = 0 )
{
headData . DbOperationType = DbOperationType . DbotIns ;
headData . ModelUIStatus = "I" ;
}
else
{
headData . DbOperationType = DbOperationType . DbotUpd ;
headData . ModelUIStatus = "E" ;
}
result = modb . Save ( headData ) ;
//if(result.)
}
var jsonRespose = new JsonResponse
{
Success = result . Success ,
Message = result . Message ,
Data = null
//Data = GetData(condition)
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult Delete1 ( string data )
{
var headData = JsonConvert . Deserialize < TaskStateMC > ( data ) ;
DBResult result = new DBResult ( ) ;
if ( BasicDataRefDAL . HaveExist ( "Sys_Task_Progress_Index" , string . Format ( " CURRENTSTATEID='{0}' or FINISHSTATEID='{0}' " , headData . ID ) ) )
{
result . Success = false ;
result . Message = "不能删除,任务进度索引已使用该数据" ;
var jsonRespose = new JsonResponse
{
Success = result . Success ,
Message = result . Message
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
else
{
var modb = new ModelObjectDB ( ) ;
result = modb . Delete ( headData ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
public ContentResult Delete2 ( string data )
{
var headData = JsonConvert . Deserialize < TaskExecutionMC > ( data ) ;
DBResult result = new DBResult ( ) ;
if ( BasicDataRefDAL . HaveExist ( "Sys_Task_Progress_Index" , string . Format ( " EXECUTIONID='{0}' " , headData . ID ) ) )
{
var jsonRespose = new JsonResponse
{
Success = false ,
Message = "不能删除,任务进度索引已使用该数据" ,
Data = null
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
else
{
var modb = new ModelObjectDB ( ) ;
result = modb . Delete ( headData ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
public ContentResult Delete3 ( string data )
{
var headData = JsonConvert . Deserialize < TaskProgressIndexMC > ( data ) ;
DBResult result = new DBResult ( ) ;
var modb = new ModelObjectDB ( ) ;
result = modb . Delete ( headData ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
}