2025-10-10 14:33:21 +08:00
using System.Collections ;
2024-03-11 23:25:08 +08:00
using System.Collections.Generic ;
2022-09-05 16:36:31 +08:00
using System.Data ;
using System.Data.SqlClient ;
using System.Linq ;
namespace BLL
{
public static class PHTGL_ApproveService
{
public const string ActionPlanReview = "ActionPlanReview" ;
public const string ApproveUserReview = "ApproveUserReview" ;
public const string BidDocumentsReview = "BidDocumentsReview" ;
public const string SetSubReview = "SetSubReview" ;
public const string ContractReview = "ContractReview" ;
public const string ContractReview_Countersign = "ContractReview_Countersign" ;
2024-05-12 20:12:30 +08:00
public const string Invoice_Input = "Invoice_Input" ;
public const string Invoice_Output = "Invoice_Output" ;
2022-09-05 16:36:31 +08:00
public static Model . PHTGL_Approve GetPHTGL_ApproveById ( string ApproveId )
{
return Funs . DB . PHTGL_Approve . FirstOrDefault ( e = > e . ApproveId = = ApproveId ) ;
}
2024-03-11 23:25:08 +08:00
/// <summary>
/// 获取未审批记录
/// </summary>
/// <param name="contractId"></param>
/// <returns></returns>
2022-09-05 16:36:31 +08:00
public static List < Model . PHTGL_Approve > GetPHTGL_ApproveByContractId ( string contractId )
{
var q = ( from x in Funs . DB . PHTGL_Approve where x . ContractId = = contractId & & x . State = = 0 select x ) . ToList ( ) ;
return q ;
}
2025-10-10 14:33:21 +08:00
2022-09-05 16:36:31 +08:00
/// <summary>
///获取当前人员的所有审批信息
/// </summary>
/// <param name="contractId"></param>
/// <param name="approveMan"></param>
/// <returns></returns>
public static List < Model . PHTGL_Approve > GetListPHTGL_ApproveByUserId ( string contractId , string approveMan )
{
var q = ( from x in Funs . DB . PHTGL_Approve where x . ContractId = = contractId & & x . ApproveMan = = approveMan select x ) . ToList ( ) ;
return q ;
}
public static Model . PHTGL_Approve GetPHTGL_ApproveByContractIdandUserId ( string contractId , string UserID )
{
2025-10-10 14:33:21 +08:00
var q = ( from x in Funs . DB . PHTGL_Approve where x . ContractId = = contractId & & x . ApproveMan = = UserID orderby x . ApproveDate descending select x ) . FirstOrDefault ( ) ;
2023-03-10 16:44:23 +08:00
//return Funs.DB.PHTGL_Approve.FirstOrDefault(e => e.ContractId == contractId && e.ApproveMan == UserID );
return q ;
2022-09-05 16:36:31 +08:00
}
public static Model . PHTGL_Approve GetPHTGL_ApproveByContractIdAndType ( string contractId , string approveType )
{
return Funs . DB . PHTGL_Approve . FirstOrDefault ( e = > e . ContractId = = contractId & & e . ApproveType = = approveType ) ;
}
/// <summary>
/// 获取当前人员正在审批的信息
/// </summary>
/// <param name="contractId"></param>
/// <param name="approveMan"></param>
/// <returns></returns>
public static Model . PHTGL_Approve GetPHTGL_ApproveByUserId ( string contractId , string approveMan )
{
return Funs . DB . PHTGL_Approve . FirstOrDefault ( e = > e . ContractId = = contractId & & e . ApproveMan = = approveMan & & e . State = = 0 ) ;
}
/// <summary>
/// 判断当前人员是否是审批相关人员
/// </summary>
/// <param name="contractId"></param>
/// <param name="approveMan"></param>
/// <returns></returns>
public static bool IsApproveMan ( string contractId , string approveMan )
{
bool IsExit = false ;
var q = ( from x in Funs . DB . PHTGL_Approve where x . ContractId = = contractId & & x . ApproveMan = = approveMan select x ) . ToList ( ) ;
if ( q ! = null )
{
IsExit = true ;
}
return IsExit ;
}
/// <summary>
2024-03-11 23:25:08 +08:00
/// 判断当前人员是否正在审批
/// </summary>
/// <param name="contractId"></param>
/// <param name="approveMan"></param>
/// <returns></returns>
public static bool IsApprovingMan ( string contractId , string approveMan )
{
bool IsExit = false ;
2025-10-10 14:33:21 +08:00
var q = ( from x in Funs . DB . PHTGL_Approve where x . ContractId = = contractId & & x . ApproveMan = = approveMan & & x . State = = 0 select x ) . ToList ( ) ;
if ( q . Count > 0 )
2024-03-11 23:25:08 +08:00
{
IsExit = true ;
}
return IsExit ;
}
/// <summary>
2022-09-05 16:36:31 +08:00
/// 添加审批人员记录
/// </summary>
/// <param name="newtable"></param>
public static void AddPHTGL_Approve ( Model . PHTGL_Approve newtable )
{
Model . PHTGL_Approve table = new Model . PHTGL_Approve ( ) ;
table . ApproveId = newtable . ApproveId ;
table . ContractId = newtable . ContractId ;
table . ApproveMan = newtable . ApproveMan ;
table . ApproveDate = newtable . ApproveDate ;
table . State = newtable . State ;
table . IsAgree = newtable . IsAgree ;
table . ApproveIdea = newtable . ApproveIdea ;
table . ApproveType = newtable . ApproveType ;
table . ApproveForm = newtable . ApproveForm ;
table . IsPushOa = newtable . IsPushOa ;
Funs . DB . PHTGL_Approve . InsertOnSubmit ( table ) ;
Funs . DB . SubmitChanges ( ) ;
}
/// <summary>
/// 修改审批人员记录
/// </summary>
/// <param name="newtable"></param>
public static void UpdatePHTGL_Approve ( Model . PHTGL_Approve newtable )
{
Model . PHTGL_Approve table = Funs . DB . PHTGL_Approve . FirstOrDefault ( e = > e . ApproveId = = newtable . ApproveId ) ;
if ( table ! = null )
{
table . ApproveId = newtable . ApproveId ;
table . ContractId = newtable . ContractId ;
table . ApproveMan = newtable . ApproveMan ;
table . ApproveDate = newtable . ApproveDate ;
table . State = newtable . State ;
table . IsAgree = newtable . IsAgree ;
table . ApproveIdea = newtable . ApproveIdea ;
table . ApproveType = newtable . ApproveType ;
table . ApproveForm = newtable . ApproveForm ;
table . IsPushOa = newtable . IsPushOa ;
Funs . DB . SubmitChanges ( ) ;
}
}
/// <summary>
/// 删除记录
/// </summary>
/// <param name="contractId"></param>
public static void DeletePHTGL_ApproveBycontractId ( string contractId )
{
var q = ( from x in Funs . DB . PHTGL_Approve where x . ContractId = = contractId select x ) . ToList ( ) ;
if ( q ! = null )
{
Funs . DB . PHTGL_Approve . DeleteAllOnSubmit ( q ) ;
Funs . DB . SubmitChanges ( ) ;
}
}
/// <summary>
/// 获取未推送oa 的审批记录
/// </summary>
/// <returns></returns>
public static List < Model . PHTGL_Approve > GetApproves_NopushOa ( )
{
2025-10-10 14:33:21 +08:00
var q = ( from x in Funs . DB . PHTGL_Approve where x . IsPushOa = = 0 & & x . ApproveMan ! = "" & & x . State = = 0 select x ) . ToList ( ) ;
2022-09-05 16:36:31 +08:00
return q ;
}
/// <summary>
/// 获取当前审批合同所以人员的最后一次审批记录
/// </summary>
/// <param name="ContractId"></param>
/// <returns></returns>
public static DataTable GetFinalApproveData ( string ContractId )
{
string strSql = @ " select a.ApproveId ,a.ApproveMan, Users.PersonName,
users . SignatureUrl , a . ApproveType , a . ApproveDate , a . ApproveIdea , a . ApproveForm
from PHTGL_Approve a "
+ @" LEFT JOIN dbo.Person_Persons AS Users ON a.ApproveMan=Users.PersonId"
+ @" where not exists (select 1 from PHTGL_Approve b where a.ApproveType=b.ApproveType and a.ContractId=b.ContractId and a.ApproveDate<b.ApproveDate ) and ContractId=@ContractId and a.State=1"
+ @" order by CONVERT(datetime,a.ApproveDate) ASC " ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
listStr . Add ( new SqlParameter ( "@ContractId" , ContractId ) ) ;
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
return tb ;
}
/// <summary>
/// 获取当前审批人在审批流中的审批记录
/// </summary>
/// <param name="ContractId"></param>
/// <param name="ApproveMan"></param>
/// <returns></returns>
public static string GetApproveManIdea ( string ContractId , string ApproveMan , string ApproveType )
{
string AllApproveIdea = "" ;
string strSql = @ " select a.ApproveId ,a.ApproveMan,a.ApproveType,a.ApproveDate ,a.ApproveIdea,a.ApproveForm
from PHTGL_Approve a "
+ @" where ContractId=@ContractId and a.State=1 and a.ApproveMan=@ApproveMan and a.ApproveType=@ApproveType "
+ @" order by CONVERT(datetime,a.ApproveDate) desc " ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
listStr . Add ( new SqlParameter ( "@ContractId" , ContractId ) ) ;
listStr . Add ( new SqlParameter ( "@ApproveMan" , ApproveMan ) ) ;
listStr . Add ( new SqlParameter ( "@ApproveType" , ApproveType ) ) ;
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
foreach ( DataRow dr in tb . Rows )
{
string ApproveIdea = dr [ "ApproveIdea" ] . ToString ( ) . Replace ( "其他会签人员已经拒绝" , "" ) ;
if ( ApproveIdea . Length > 4 )
{
AllApproveIdea + = ApproveIdea ;
}
}
if ( AllApproveIdea = = "" )
{
AllApproveIdea = "同意" ;
}
return AllApproveIdea ;
}
/// <summary>
/// 获取当前审批合同所全部审批记录
/// </summary>
/// <param name="ContractId"></param>
/// <returns></returns>
2024-03-11 23:25:08 +08:00
//public static DataTable GetAllApproveData(string ContractId)
//{
// string strSql = @" select u.PersonName as ApproveMan,
// App.ApproveDate,
// (CASE App.IsAgree WHEN '1' THEN '不同意'
// WHEN '2' THEN '同意' END) AS IsAgree,
// App.ApproveIdea,
// App.ApproveId,
// App.ApproveType
// from PHTGL_Approve as App"
// + @" left join Person_Persons AS U ON U.PersonId = App.ApproveMan WHERE 1=1 and App.IsAgree <>0 and app.ContractId= @ContractId order by convert(datetime ,App.ApproveDate) ";
// List<SqlParameter> listStr = new List<SqlParameter>();
// listStr.Add(new SqlParameter("@ContractId", ContractId));
// SqlParameter[] parameter = listStr.ToArray();
// DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// return tb;
//}
public static IEnumerable GetAllApproveData ( string contractId )
2022-09-05 16:36:31 +08:00
{
2024-03-11 23:25:08 +08:00
var result = ( from x in Funs . DB . PHTGL_Approve
2025-10-10 14:33:21 +08:00
join u in Funs . DB . Person_Persons on x . ApproveMan equals u . PersonId
where x . IsAgree ! = 0 & & x . ContractId = = contractId
orderby x . ApproveDate
2024-03-11 23:25:08 +08:00
select new
2025-10-10 14:33:21 +08:00
{
ApproveMan = u . PersonName ,
x . ApproveDate ,
IsAgree = x . IsAgree = = 1 ? "不同意" : "同意" ,
x . ApproveIdea ,
x . ApproveId ,
x . ApproveType ,
x . ApproveForm
}
2024-03-11 23:25:08 +08:00
2025-10-10 14:33:21 +08:00
) . ToList ( ) ;
2024-03-11 23:25:08 +08:00
return result ;
2022-09-05 16:36:31 +08:00
}
2025-10-10 14:33:21 +08:00
public static IEnumerable GetAllApproveData ( string contractId , string aproveForm )
2024-03-11 23:25:08 +08:00
{
var result = ( from x in Funs . DB . PHTGL_Approve
2025-10-10 14:33:21 +08:00
join u in Funs . DB . Person_Persons on x . ApproveMan equals u . PersonId
where x . IsAgree ! = 0 & & x . ContractId = = contractId
orderby x . ApproveDate
select new
{
ApproveMan = u . PersonName ,
x . ApproveDate ,
IsAgree = x . IsAgree = = 1 ? "不同意" : "同意" ,
x . ApproveIdea ,
x . ApproveId ,
x . ApproveType ,
x . ApproveForm
}
2024-03-11 23:25:08 +08:00
) . ToList ( ) ;
if ( ! string . IsNullOrEmpty ( aproveForm ) )
{
result = result . Where ( x = > x . ApproveForm = = aproveForm ) . ToList ( ) ;
}
2025-10-10 14:33:21 +08:00
2024-03-11 23:25:08 +08:00
return result ;
}
2022-09-05 16:36:31 +08:00
/// <summary>
/// 获取最后拒绝的人员
/// </summary>
/// <param name="ContractId"></param>
/// <returns></returns>
public static DataTable GetRefuseEndMan ( string ContractId )
{
string strSql = @ " select top 1 a.ApproveId ,a.ApproveMan,a.ApproveType,a.ApproveDate ,a.ApproveIdea,a.ApproveForm
from PHTGL_Approve a "
+ @" where ContractId=@ContractId and a.State=1 and a.IsAgree=1"
+ @" order by CONVERT(datetime,a.ApproveDate) desc " ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
listStr . Add ( new SqlParameter ( "@ContractId" , ContractId ) ) ;
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
return tb ;
}
}
}