2022-09-05 16:36:31 +08:00
using FineUIPro ;
2023-11-29 18:02:03 +08:00
2022-09-05 16:36:31 +08:00
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.SqlClient ;
using System.Linq ;
using System.Text ;
namespace BLL
{
2022-11-01 17:11:30 +08:00
2022-09-05 16:36:31 +08:00
public static class HJGL_PackagingmanageService
{
2022-11-01 17:11:30 +08:00
public class PackagingManageItem
{
public string PackagingManageId { get ; set ; }
public string PackagingCode { get ; set ; }
public string ProjectId { get ; set ; }
public string ProjectName { get ; set ; }
public string ContactName { get ; set ; }
public string ContactPhone { get ; set ; }
public string StackingPosition { get ; set ; }
public int? State { get ; set ; }
public string ReceiveMan { get ; set ; }
public string ReceiveDate { get ; set ; }
public string PlanStartDate { get ; set ; }
2024-01-22 10:35:43 +08:00
public string Code { get ; set ; }
2024-09-28 16:59:44 +08:00
public string TrainNumber { get ; set ; }
2022-11-01 17:11:30 +08:00
}
2022-09-05 16:36:31 +08:00
public static Model . SGGLDB db = Funs . DB ;
/// <summary>
/// 未到场
/// </summary>
public static int state_0 = 0 ;
/// <summary>
/// 已发货
/// </summary>
public static int state_1 = 1 ;
/// <summary>
/// 已到场
/// </summary>
public static int state_2 = 2 ;
public static ListItem [ ] GetState ( )
{
ListItem [ ] list = new ListItem [ 3 ] ;
2023-12-19 09:00:47 +08:00
list [ 0 ] = new ListItem ( "预出库" , state_0 . ToString ( ) ) ;
2022-09-05 16:36:31 +08:00
list [ 1 ] = new ListItem ( "已出库" , state_1 . ToString ( ) ) ;
list [ 2 ] = new ListItem ( "已到场" , state_2 . ToString ( ) ) ;
return list ;
}
#region 获 取 列 表
/// <summary>
/// 记录数
/// </summary>
public static int count
{
get ;
set ;
}
/// 获取分页列表
/// </summary>
/// <param name="PageIndex">页码</param>
/// <param name="PageSize">每页数量</param>
/// <returns></returns>
public static IEnumerable getListData ( string name , Grid Grid1 )
{
IQueryable < Model . HJGL_PackagingManage > q1 = ( from x in db . HJGL_PackagingManage
join y in db . HJGL_Pipeline_Component on x . PipelineComponentId equals y . PipelineComponentId
join z in db . HJGL_Pipeline on y . PipelineId equals z . PipelineId
2023-11-29 18:02:03 +08:00
select x
2022-09-05 16:36:31 +08:00
) ;
if ( ! string . IsNullOrEmpty ( name ) )
{
q1 = q1 . Where ( e = > e . PackagingManageId . Contains ( name ) ) ;
}
count = q1 . Count ( ) ;
if ( count = = 0 )
{
return null ;
}
q1 = SortConditionHelper . SortingAndPaging ( q1 , Grid1 . SortField , Grid1 . SortDirection , Grid1 . PageIndex , Grid1 . PageSize ) ;
return from x in q1
select new
{
x . PackagingManageId ,
x . PackagingCode ,
x . ProjectId ,
x . PipelineComponentId ,
x . StackingPosition ,
x . State ,
x . ContactName ,
x . ContactPhone ,
x . Remark ,
2024-09-28 16:59:44 +08:00
x . TrainNumber
2022-09-05 16:36:31 +08:00
} ;
}
#endregion
public static Model . HJGL_PackagingManage GetHJGL_PackagingManageById ( string PackagingManageId )
{
2023-10-10 19:13:59 +08:00
using ( Model . SGGLDB db = new Model . SGGLDB ( Funs . ConnString ) )
{
return db . HJGL_PackagingManage . FirstOrDefault ( x = > x . PackagingManageId = = PackagingManageId ) ;
}
2022-09-05 16:36:31 +08:00
}
2022-11-01 17:11:30 +08:00
public static string GetMinPlanStartDate ( string PackagingManageId )
{
string PlanStartDate = "" ;
DataTable tb = BLL . HJGL_PackagingmanageService . GetPackagingDetailById ( PackagingManageId ) ;
2024-10-17 00:01:35 +08:00
if ( tb = = null | | tb . Rows . Count = = 0 )
{
return PlanStartDate ;
}
2022-11-01 17:11:30 +08:00
var dtTable = tb . AsEnumerable ( ) . OrderBy ( o = > o [ "PlanStartDate" ] ) . CopyToDataTable ( ) ;
if ( dtTable . Rows ! = null & & dtTable . Rows . Count > 0 )
{
PlanStartDate = dtTable . Rows [ 0 ] [ "PlanStartDate" ] . ToString ( ) ;
}
return PlanStartDate ;
}
2024-03-29 17:21:00 +08:00
public static List < PackagingManageItem > GetPackagingManageList ( string projectId , string PackagingCode , int pageIndex , int pageSize )
2022-11-01 17:11:30 +08:00
{
using ( Model . SGGLDB db = new Model . SGGLDB ( Funs . ConnString ) )
{
var q = ( from x in db . HJGL_PackagingManage
join n in db . Base_Project on x . ProjectId equals n . ProjectId
join m in db . Person_Persons on x . ReceiveMan equals m . PersonId into tt
from t in tt . DefaultIfEmpty ( )
where x . ProjectId = = projectId
2023-11-29 18:02:03 +08:00
& & ( string . IsNullOrEmpty ( PackagingCode ) | | x . PackagingCode . Contains ( PackagingCode ) )
2022-11-01 17:11:30 +08:00
select new PackagingManageItem
{
PackagingManageId = x . PackagingManageId ,
PackagingCode = x . PackagingCode ,
ProjectName = n . ProjectName ,
ContactName = x . ContactName ,
ContactPhone = x . ContactPhone ,
StackingPosition = x . StackingPosition ,
State = x . State ,
ReceiveMan = t . PersonName ,
2023-11-29 18:02:03 +08:00
ReceiveDate = x . ReceiveDate . HasValue ? string . Format ( "{0:g}" , x . ReceiveDate ) : "" ,
2022-11-01 17:11:30 +08:00
PlanStartDate = GetMinPlanStartDate ( x . PackagingManageId ) ,
2024-09-28 16:59:44 +08:00
TrainNumber = x . TrainNumber ,
2024-01-22 10:35:43 +08:00
Code = x . PackagingCode . Substring ( 0 , x . PackagingCode . LastIndexOf ( "-" ) ) . Substring ( x . PackagingCode . Substring ( 0 , x . PackagingCode . LastIndexOf ( "-" ) ) . LastIndexOf ( "-" ) + 1 ) ,
2022-11-01 17:11:30 +08:00
} ) . Distinct ( ) ;
2024-03-29 17:21:00 +08:00
return q . OrderByDescending ( x = > x . Code ) . Skip ( pageIndex * pageSize ) . Take ( pageSize ) . ToList ( ) ;
2022-11-01 17:11:30 +08:00
}
}
2022-09-05 16:36:31 +08:00
/// <summary>
/// 形成出库单
/// </summary>
/// <param name="PackagingManageId"></param>
public static void PutOutOrder ( string PackagingManageId )
{
2023-11-29 18:02:03 +08:00
var model = GetHJGL_PackagingManageById ( PackagingManageId ) ;
if ( model . State = = state_0 )
2022-09-05 16:36:31 +08:00
{
model . State = state_1 ;
UpdateHJGL_PackagingManage ( model ) ;
}
}
/// <summary>
/// 根据主键获取装箱明细
/// </summary>
/// <param name="PackagingManageId"></param>
/// <returns></returns>
public static DataTable GetPackagingDetailById ( string PackagingManageId )
{
DataTable tb = new DataTable ( ) ;
var model = GetHJGL_PackagingManageById ( PackagingManageId ) ;
2023-11-29 18:02:03 +08:00
if ( ! string . IsNullOrEmpty ( model . PipelineComponentId ) )
2022-09-05 16:36:31 +08:00
{
var PipelineComponentIds = model . PipelineComponentId . Split ( ',' ) ;
2023-12-14 10:35:55 +08:00
string strSql = @"select com.PipelineComponentId, com.PipelineComponentCode,isnull(pipe.PlanStartDate,getdate()) as PlanStartDate,unitwork.UnitWorkName,'1' as num ,'个' as CU
2022-09-05 16:36:31 +08:00
from HJGL_Pipeline_Component com
left join HJGL_Pipeline pipe on com.PipelineId=pipe.PipelineId
left join WBS_UnitWork unitwork on pipe.UnitWorkId=unitwork.UnitWorkId
" ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
strSql + = string . Format ( "where com.PipelineComponentId in ( {0}) " , "'" + string . Join ( "','" , PipelineComponentIds ) + "'" ) ;
2023-12-04 17:27:07 +08:00
strSql + = " order by com.PipelineComponentCode" ;
2022-09-05 16:36:31 +08:00
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
2023-11-29 18:02:03 +08:00
}
2022-09-05 16:36:31 +08:00
return tb ;
}
/// <summary>
/// 根据项目号获取包装编号历史记录
/// </summary>
/// <param name="projectid"></param>
/// <returns></returns>
2023-11-29 18:02:03 +08:00
public static List < string > GetPackagingCode ( string projectid )
2022-09-05 16:36:31 +08:00
{
Model . SGGLDB db = Funs . DB ;
var q = ( from x in db . HJGL_PackagingManage
where x . ProjectId . Contains ( projectid )
select x . PackagingCode ) . Distinct ( ) . ToList ( ) ;
return q ;
}
/// <summary>
/// 新增实体
/// </summary>
/// <param name="newtable"></param>
public static void AddHJGL_PackagingManage ( Model . HJGL_PackagingManage newtable )
{
Model . HJGL_PackagingManage table = new Model . HJGL_PackagingManage
{
PackagingManageId = newtable . PackagingManageId ,
PackagingCode = newtable . PackagingCode ,
ProjectId = newtable . ProjectId ,
PipelineComponentId = newtable . PipelineComponentId ,
StackingPosition = newtable . StackingPosition ,
State = newtable . State ,
ContactName = newtable . ContactName ,
ContactPhone = newtable . ContactPhone ,
Remark = newtable . Remark ,
2022-10-15 15:40:49 +08:00
ReceiveDate = newtable . ReceiveDate ,
ReceiveMan = newtable . ReceiveMan ,
2024-09-28 16:59:44 +08:00
TrainNumber = newtable . TrainNumber
2022-09-05 16:36:31 +08:00
} ;
db . HJGL_PackagingManage . InsertOnSubmit ( table ) ;
db . SubmitChanges ( ) ;
}
public static void UpdateHJGL_PackagingManage ( Model . HJGL_PackagingManage newtable )
{
Model . HJGL_PackagingManage table = db . HJGL_PackagingManage . FirstOrDefault ( x = > x . PackagingManageId = = newtable . PackagingManageId ) ;
if ( table ! = null )
{
table . PackagingManageId = newtable . PackagingManageId ;
table . PackagingCode = newtable . PackagingCode ;
table . ProjectId = newtable . ProjectId ;
table . PipelineComponentId = newtable . PipelineComponentId ;
table . StackingPosition = newtable . StackingPosition ;
table . State = newtable . State ;
table . ContactName = newtable . ContactName ;
table . ContactPhone = newtable . ContactPhone ;
table . Remark = newtable . Remark ;
2023-11-29 18:02:03 +08:00
table . ReceiveMan = newtable . ReceiveMan ;
table . ReceiveDate = newtable . ReceiveDate ;
2024-09-28 16:59:44 +08:00
table . TrainNumber = newtable . TrainNumber ;
2022-09-05 16:36:31 +08:00
db . SubmitChanges ( ) ;
}
}
public static void DeleteHJGL_PackagingManageById ( string PackagingManageId )
{
Model . HJGL_PackagingManage table = db . HJGL_PackagingManage . FirstOrDefault ( x = > x . PackagingManageId = = PackagingManageId ) ;
if ( table ! = null )
{
db . HJGL_PackagingManage . DeleteOnSubmit ( table ) ;
db . SubmitChanges ( ) ;
}
}
/// <summary>
/// 管线下拉框
/// </summary>
/// <param name="dropName">下拉框名字</param>
/// <param name="isShowPlease">是否显示请选择</param>
public static void InitPipelineDownList ( FineUIPro . DropDownList dropName , string projectid , bool isShowPlease )
{
dropName . DataValueField = "string" ;
dropName . DataTextField = "string" ;
dropName . DataSource = GetPackagingCode ( projectid ) ;
dropName . DataBind ( ) ;
if ( isShowPlease )
{
Funs . FineUIPleaseSelect ( dropName ) ;
}
}
}
}