@ -33,6 +33,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
private readonly ESUNContext _ esun_context ;
private readonly IConfiguration _ config ;
private readonly string _ PTDContext ;
private string SFISDbContext = "SFIS.." ;
/// <summary>
///
@ -43,6 +44,11 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
_ config = new ConfigurationBuilder ( ) . SetBasePath ( Environment . CurrentDirectory ) . AddJsonFile ( "appsettings.json" ) . Build ( ) ;
_ context = context ;
_ PTDContext = _ config . GetConnectionString ( "PTDContext" ) ;
if ( _ PTDContext . IndexOf ( "SFIS_PTD_T" ) > 0 )
{
SFISDbContext = "SFIS_T.." ;
}
}
/// <summary>
@ -803,13 +809,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
WriteTraceLog ( "query wip_kp rows qty:" + dtKp . Rows . Count ) ;
}
/ *
string sql = @" select c.wip_no as WipNo,b.barcode_no as BarcodeNo,b.extra_barcode_no as ExtraBarcodeNo,d.model_no as ModelNO,d.item_no as ItemNO" ;
sql = sql + " from jhames.barcode_info b,jhames.wip_info c,jhames.wip_att d" ;
sql = sql + " where b.wip_id = c.wip_id and c.wip_no = d.wip_no" ;
sql = sql + " and c.wip_no = '" + wipNO + "'" ;
* /
string sql = @" select c.wip_no as WipNo,b.barcode_no as BarcodeNo,b.extra_barcode_no as ExtraBarcodeNo,e.station_name as StationName,b.box_no as BoxNo,d.model_no as ModelNO,d.item_no as ItemNO" ;
sql = sql + " from jhames.barcode_info b,jhames.wip_barcode c,jhames.wip_att d,jhames.stations e" ;
sql = sql + " where b.barcode_no between c.start_no and c.end_no and c.wip_no = d.wip_no and b.station_id = e.station_id" ;
@ -915,55 +914,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
if ( kp_no . StartsWith ( "MB" ) & & ! kp_no . StartsWith ( "MB_MAC" ) )
{
/ *
WriteTraceLog ( "query mac by mb trace 001" ) ;
ESUNContext _ esun_context = new ESUNContext ( ) ;
WriteTraceLog ( "query mac by mb trace 002" ) ;
//读取MAC
DbConnection esun_conn = _ esun_context . Database . GetDbConnection ( ) ;
WriteTraceLog ( "query mac by mb trace 003" ) ;
if ( esun_conn . State ! = ConnectionState . Open )
{
await esun_conn . OpenAsync ( ) ;
}
WriteTraceLog ( "query mac by mb trace 004" ) ;
* /
bool createMacCol = true ;
//part_no = "91000237320038";
/ *
string mac_sql = string . Format ( @ "select distinct a.工單編號 as mo_id,e.客戶工單編號 as customer_moid,a.工單序號 as product_sn,
case substring ( f . avalue_kp_typeid , 1 , 3 ) when ' MAC ' then isnull ( z . item_prefix , ' ' ) + b . SUB_ITEM_SN else b . SUB_ITEM_SN end as part_barcode ,
f . avalue_kp_typeid as class , c . material_id , d . r_stn as routeid , ' ' as workerid , rtrim ( g . sn_date ) + ' ' + rtrim ( g . sn_time ) as create_date
from or_sn_story a
left join sub_item_db b on a . 工 單 編 號 = b . or_sn and a . 工 單 序 號 = b . or_sal
left join jh_sub_item c on a . 工 單 編 號 = c . mo_id and b . class = c . part_typeid
left join jh_sub_item_prefix z on c . mo_id = z . mo_id
left join or_sub_db d on a . 工 單 編 號 = d . or_sn and b . class = d . class
join or_list e on a . 工 單 編 號 = e . 工 單 編 號 and e . [ 客 戶 ] = ' EV '
left join jh_sub_item_mapping f on b . class = f . eversun_kp_typeid
join jh_sn_list g on a . 工 單 序 號 = g . sn
where g . sn_result = ' OK '
AND a . 工 單 序 號 = ' { 0 } '
AND c . material_id LIKE ' MAC % ' ", part_no);
* /
/ *
string mac_sql = string . Format ( @ "SELECT B.[ProductSN], B.[PartBarcode], B.[MFID], B.[MOID], B.[PartTypeID], B.[MaterialID], B.[IsActive]
FROM [ SFIS ] . [ dbo ] . [ ZPDKeyPart ] B WHERE B . [ IsActive ] = 1 AND B . [ ProductSN ] = ( SELECT A . [ PartBarcode ] FROM [ SFIS ] . [ dbo ] . [ ZPDKeyPart ] A WHERE A . [ IsActive ] = 1 AND A . [ PartTypeID ] = ' MAC ' AND A . [ PartBarcode ] = ' { 0 } ' ) ", part_no);
WriteTraceLog ( "query mac by mb sql:" + mac_sql ) ;
* /
bool findFlag = false ;
string mac_sql = string . Format ( "select partbarcode from jhames.c_sfis_keyparts where productsn = '{0}' and parttypeid='MAC'" , part_no ) ;
@ -1043,7 +995,11 @@ FROM [SFIS].[dbo].[ZPDKeyPart] B WHERE B.[IsActive] = 1 AND B.[ProductSN] = (S
//从barcode_item读取结转数据
if ( ! findFlag )
{
string mac_sql2 = string . Format ( "select a.part_no from jhames.barcode_item a,jhames.barcode_info b where a.barcode_id = b.barcode_id and b.barcode_no = '{0}' and item_no like 'MAC%'" , part_no ) ;
string mac_sql2 = string . Format ( "select a.part_no from jhames.barcode_item a,jhames.barcode_info b " +
" where a.barcode_id = b.barcode_id " +
" and b.barcode_no = '{0}' " +
" and item_no like 'MAC%' " +
" order by a.ITEM_NO, a.PART_NO " , part_no ) ;
using ( var esun_cmd = conn . CreateCommand ( ) )
{
@ -1096,7 +1052,6 @@ FROM [SFIS].[dbo].[ZPDKeyPart] B WHERE B.[IsActive] = 1 AND B.[ProductSN] = (S
string mac = "" ;
for ( int m = 0 ; m < esun_table . Rows . Count ; m + + )
{
//mac = esun_table.Rows[m]["part_barcode"].ToString().Trim();
mac = esun_table . Rows [ m ] [ "PART_NO" ] . ToString ( ) . Trim ( ) ;
if ( dtItem . Rows . Count = = 1 )
{
@ -2145,7 +2100,9 @@ FROM [SFIS].[dbo].[ZPDKeyPart] B WHERE B.[IsActive] = 1 AND B.[ProductSN] = (S
lineDesc = q3 . LineDesc ,
unitName = q4 . UnitName ,
wipType = q1 . WipType ,
factoryNo = q1 . WerksNO
factoryNo = q1 . WerksNO ,
startDate = q1 . StartDate ,
fqcClearDate = q1 . FQCClearDate
} ;
@ -2208,27 +2165,7 @@ FROM [SFIS].[dbo].[ZPDKeyPart] B WHERE B.[IsActive] = 1 AND B.[ProductSN] = (S
q = q . Skip ( ( page - 1 ) * limit ) . Take ( limit ) ;
}
var qq = await q . ToListAsync ( ) ;
// 塞入開工日
foreach ( var item in qq )
{
var workDate = _ context . WipStations . Where ( w = > w . WipID = = item . wipID )
. OrderBy ( s = > s . CreateDate )
. FirstOrDefault ( ) ;
item . workDate = workDate = = null ? "" : workDate . CreateDate . ToString ( "yyyy/MM/dd" ) ;
}
// 塞檢驗完成日期
foreach ( var item in qq )
{
var fqcDate = _ context . FqcResultMasters . Where ( w = > w . WipNo = = item . wipNo & & w . QaResult ! = "A" )
. OrderByDescending ( s = > s . EndTime )
. FirstOrDefault ( ) ;
item . fqcDate = fqcDate = = null ? "" : fqcDate . EndTime . ToString ( "yyyy/MM/dd" ) ;
}
result . Data = qq ;
result . Data = await q . ToListAsync ( ) ;
if ( result = = null )
{
@ -2991,7 +2928,7 @@ FROM [SFIS].[dbo].[ZPDKeyPart] B WHERE B.[IsActive] = 1 AND B.[ProductSN] = (S
}
string strSQL = $ @ "select DNNO,DNLineNO,ProductID,ShipQty,ShipCustomerID,SoldCustomerID,ExpectShipDate ,
CurrentShipDate
from SFIS_PTD . dbo . ZDNDetail where DNNO = ' { dnNo } ' ";
from ZDNDetail where DNNO = ' { dnNo } ' ";
if ( ! string . IsNullOrEmpty ( lineNo ) )
{
strSQL + = $@"And DNLineNO ='{lineNo}'" ;
@ -3065,7 +3002,7 @@ FROM [SFIS].[dbo].[ZPDKeyPart] B WHERE B.[IsActive] = 1 AND B.[ProductSN] = (S
}
string strSQL = $ @ "select RecordNumber as DN單號,MOID as WipNo,ProductID as ItemNO,SerialNumber as ExtraBarcodeNo,'' as BarcodeNo,
RecordDate as StartDate
from SFIS_PTD . dbo . ZProductTrans where RecordNumber = ' { dnNo } ' and RCLineNO = ' { lineNo } '
from ZProductTrans where RecordNumber = ' { dnNo } ' and RCLineNO = ' { lineNo } '
order by SerialNumber ";
DataTable dtZProductTrans = new DataTable ( ) ;
using ( var cmd = connPTD . CreateCommand ( ) )
@ -3467,6 +3404,9 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
string customer = data . Customer ;
string strDNNo = data . TableData [ 0 ] . DnNo ;
string dnLineNo = data . TableData [ 0 ] . LineNo ;
int shipQty = data . TableData [ 0 ] . ShipQty ;
string productID = data . TableData [ 0 ] . Material ;
var pdtMail = await new PTD . PTDController ( ) . GetCustomerItemMailGroup ( customer ) ;
if ( pdtMail . Any ( a = > a . StatusNo ! = "S" ) )
@ -3482,7 +3422,10 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
worksheet . Cells [ 1 , 1 ] . Value = "DN單號" ;
worksheet . Cells [ 1 , 2 ] . Value = "LineNo" ;
worksheet . Cells [ 1 , 3 ] . Value = "Material(料號)" ;
worksheet . Cells [ 1 , 4 ] . Value = "SN" ;
worksheet . Cells [ 1 , 4 ] . Value = "出貨數量" ;
worksheet . Cells [ 1 , 5 ] . Value = "SN" ;
worksheet . Cells [ 1 , 6 ] . Value = "StartDate" ;
worksheet . Cells [ 1 , 7 ] . Value = "工單號碼" ;
worksheet . Row ( 1 ) . Style . Font . Bold = true ;
int i = 0 ;
@ -3492,19 +3435,50 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
worksheet . Cells [ i + 2 , 1 ] . Value = SNData . DnNo ;
worksheet . Cells [ i + 2 , 2 ] . Value = SNData . LineNo ;
worksheet . Cells [ i + 2 , 3 ] . Value = SNData . Material ;
worksheet . Cells [ i + 2 , 4 ] . Value = SNData . Sn ;
worksheet . Cells [ i + 2 , 4 ] . Value = SNData . ShipQty ;
worksheet . Cells [ i + 2 , 5 ] . Value = SNData . Sn ;
worksheet . Cells [ i + 2 , 6 ] . Value = SNData . StartDate ;
worksheet . Cells [ i + 2 , 7 ] . Value = SNData . CurrentMOID ;
i + + ;
}
// 自動調整欄寬
worksheet . Cells [ worksheet . Dimension . Address ] . AutoFitColumns ( ) ;
fileContents = package . GetAsByteArray ( ) ;
// 寫入實體 Excel 檔案
}
var firstItem = pdtMail . FirstOrDefault ( ) ;
string toMail = firstItem . MailGroup ;
string Subject = $"[AMES系統通知] 出貨單號:" + strDNNo ;
string emailBody = "" ;
string Subject = firstItem . CustomerName + "_" + strDNNo ;
string emailBody = $ @ "
< html >
< body >
< p > Dear Team , < / p >
< p > Please find the details below : < / p >
< table border = '1' style = ' border - collapse : collapse ; width : 1 0 0 % ; ' >
< thead style = ' background - color : # 0 0 0 0F F ; color : # FFFFFF ; text - align : left ; ' >
< tr >
< th style = ' padding : 8 px ; ' > DNLineNO < / th >
< th style = ' padding : 8 px ; ' > ProductID < / th >
< th style = ' padding : 8 px ; ' > ShipQty < / th >
< th style = ' padding : 8 px ; ' > SerialNumber ? < / th >
< / tr >
< / thead >
< tbody >
< tr >
< td style = ' padding : 8 px ; ' > { dnLineNo } < / td >
< td style = ' padding : 8 px ; ' > { productID } < / td >
< td style = ' padding : 8 px ; ' > { shipQty } < / td >
< td style = ' padding : 8 px ; ' > Yes < / td >
< / tr >
< / tbody >
< / table >
< / body >
< / html > ";
//string filePath = $"D:\\Alex\\EXCEL\\{strDNNo}.xlsx";
//System.IO.File.WriteAllBytes(filePath, fileContents);
await new MailController ( _ context , _ config ) . PostMailByByteFile ( Subject , emailBody , "" , toMail , false , fileContents : fileContents , fileName : $"{strDNNo}.xlsx" ) ;
}
}
@ -3565,7 +3539,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
salesOrderNumber = dnDetail . FirstOrDefault ( ) . OrderNo ;
sOLineNO = dnDetail . FirstOrDefault ( ) . OrderLineNO ;
eRP_CustomerID = dnDetail . FirstOrDefault ( ) . Ship CustomerID ;
eRP_CustomerID = dnDetail . FirstOrDefault ( ) . Sold CustomerID ;
}
}
@ -3573,7 +3547,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
strMaterial = SNData . Material ;
string strLatest ;
//確認此出貨序號是否有ZHistoryKeyDefine
strSQL = $@"select Seed FROM [SFIS_PTD].[dbo].[ ZHistoryKeyDefine] where serialnumber ='{SNData.Sn}'" ;
strSQL = $@"select Seed FROM ZHistoryKeyDefine where serialnumber ='{SNData.Sn}'" ;
using ( var cmd = connPTD . CreateCommand ( ) )
{
cmd . CommandText = strSQL ;
@ -3585,12 +3559,12 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
int nIdx = seed + 1 ;
strLatest = SNData . Sn + nIdx . ToString ( ) . PadLeft ( 4 , '0' ) ; //組成HistoryID
//HistoryKeyDefine
strSQL = @ $ "UPDATE [SFIS_PTD].[dbo].[ ZHistoryKeyDefine]
SET [ Seed ] = { nIdx } where [ SerialNumber ] = ' { SNData . Sn } ' ";
strSQL = @ $ "UPDATE ZHistoryKeyDefine
SET Seed = { nIdx } where SerialNumber = ' { SNData . Sn } ' ";
Console . WriteLine ( strSQL ) ;
colSQL . Add ( strSQL ) ;
//ZSNInfo
strSQL = @ $ "Update SFIS_PTD.. ZSNInfo SET LatestHistoryID='{strLatest}',RecordTypeID='{strRecordType}',
strSQL = @ $ "Update ZSNInfo SET LatestHistoryID='{strLatest}',RecordTypeID='{strRecordType}',
CurrentProductID = ' { SNData . Material } '
where SerialNumber = ' { SNData . Sn } ' ";
Console . WriteLine ( strSQL ) ;
@ -3600,15 +3574,15 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
strLatest = SNData . Sn + 1. ToString ( ) . PadLeft ( 4 , '0' ) ; //組成HistoryID
//ZHistoryKeyDefine
strSQL = @ $ "INSERT INTO [SFIS_PTD].[dbo].[ZHistoryKeyDefine] ([SerialNumber],[Seed] )
strSQL = @ $ "INSERT INTO ZHistoryKeyDefine (SerialNumber, Seed )
VALUES ( ' { SNData . Sn } ' , 1 ) ";
Console . WriteLine ( strSQL ) ;
colSQL . Add ( strSQL ) ;
//ZSNInfo
strSQL = @ $ "INSERT INTO [SFIS_PTD].[dbo].[ZSNInfo] ([SerialNumber],[CurrentProductID],[OriginalProductID] ,
[LocationID] , [ LatestHistoryID ] , [ RecordTypeID ] ,
[OwnerPlantID] , [ OwnerCompanyID ] , [ CreatePlantID ] , [ CreateCompanyID ] ,
[ModifyDate] ) VALUES
strSQL = @ $ "INSERT INTO ZSNInfo (SerialNumber, CurrentProductID, OriginalProductID ,
LocationID , LatestHistoryID , RecordTypeID ,
OwnerPlantID , OwnerCompanyID , CreatePlantID , CreateCompanyID ,
ModifyDate ) VALUES
( ' { SNData . Sn } ',' { SNData . Material } ',' { SNData . Material } ' ,
' { strLocation } ',' { strLatest } ',' { strRecordType } ' ,
' { strWorkCenter } ',' { strRbu } ',' { strWorkCenter } ',' { strRbu } ' ,
@ -3617,13 +3591,13 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
colSQL . Add ( strSQL ) ;
}
//ZProductTrans
strSQL = $ @ "INSERT INTO [SFIS_PTD].[dbo].[ ZProductTrans]
( [ HistoryID ] , [ SerialNumber ] , [ RecordTypeID ] , [ RecordNumber ] , [ RCLineNO ] , [ RecordDate ] ,
[ProductID] , [ IsChangeID ] , [ LocationID ] , [ EmplID ] , [ IsDelete ] ,
[OwnerPlantID] , [ OwnerCompanyID ] , [ CreatePlantID ] , [ CreateCompanyID ] ,
[CreatorID] , [ CreateDate ] , [ ModifierID ] , [ ModifyDate ] ,
[chkflag] , [ IsBranchCoReceived ] , [ MOID ] ,
[SalesOrderNumber] , [ SOLineNO ] , [ ERP_CustomerID ] ) VALUES
strSQL = $ @ "INSERT INTO ZProductTrans
( HistoryID , SerialNumber , RecordTypeID , RecordNumber , RCLineNO , RecordDate ,
ProductID , IsChangeID , LocationID , EmplID , IsDelete ,
OwnerPlantID , OwnerCompanyID , CreatePlantID , CreateCompanyID ,
CreatorID , CreateDate , ModifierID , ModifyDate ,
chkflag , IsBranchCoReceived , MOID ,
SalesOrderNumber , SOLineNO , ERP_CustomerID ) VALUES
( ' { strLatest } ',' { SNData . Sn } ',' { strRecordType } ',' { SNData . DnNo } ',' { SNData . LineNo } ',' { strRecordDate } ' ,
' { SNData . Material } ' , 0 , ' { strLocation } ',' { strEmpId } ' , 0 ,
' { strWorkCenter } ',' { strRbu } ',' { strWorkCenter } ',' { strRbu } ' ,
@ -3700,9 +3674,9 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
//查剩餘數
string strSQL = $ @ "select ShipQty -
( SELECT count ( 1 )
FROM [ SFIS_PTD ] . [ dbo ] . [ ZWHPickListDetail ]
FROM ZWHPickListDetail
where RecordNumber = DNNO and RCLineNO = DNLineNO ) as surplusQty
from [ SFIS_PTD ] . [ dbo ] . ZDNDetail where DNNO = ' { recordNumber } ' and DNLineNO = ' { lineNo } ' ";
from ZDNDetail where DNNO = ' { recordNumber } ' and DNLineNO = ' { lineNo } ' ";
using ( var cmd = connPTD . CreateCommand ( ) )
{
cmd . CommandText = strSQL ;
@ -3747,8 +3721,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
//用ZProductTrans最新RecordType 檢查PTDFlowRules邏輯
bool bolChkFlow = false ;
string strSQL = $ @ "Select [ FormID] FROM [SFIS_PTD].[dbo].[ PTDFlowRules]
where [ ToID ] = ' { recordType } ' ";
string strSQL = $ @ "Select FormID FROM PTDFlowRules
where ToID = ' { recordType } ' ";
DataTable dtPTDFlowRules = new DataTable ( ) ;
using ( var cmd = connPTD . CreateCommand ( ) )
{
@ -3763,9 +3737,9 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
}
strSQL = @ $ "Select [ RecordTypeID] FROM [SFIS_PTD].[dbo].[ ZProductTrans]
where [ SerialNumber ] = ' { serialNumber } '
Order by [ RecordDate ] Desc ";
strSQL = @ $ "Select RecordTypeID FROM ZProductTrans
where SerialNumber = ' { serialNumber } '
Order by RecordDate Desc ";
using ( var cmd = connPTD . CreateCommand ( ) )
{
cmd . CommandText = strSQL ;
@ -3825,9 +3799,9 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
// //查剩餘數
// string strSQL = $@"select ShipQty -
// (SELECT count(1)
// FROM [SFIS_PTD].[dbo].[ ZWHPickListDetail]
// FROM ZWHPickListDetail
// where RecordNumber =DNNO and RCLineNO =DNLineNO and TaskStatus ='Picked') as surplusQty
// from [SFIS_PTD].[dbo]. ZDNDetail where DNNO ='{recordNumber}' and DNLineNO ='{lineNo}'";
// from ZDNDetail where DNNO ='{recordNumber}' and DNLineNO ='{lineNo}'";
// using (var cmd = connPTD.CreateCommand())
// {
// cmd.CommandText = strSQL;
@ -3869,7 +3843,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
// }
// //用ZProductTrans最新RecordType 檢查PTDFlowRules邏輯
// bool bolChkFlow = false;
// string strSQL = $@"Select [FormID] FROM [SFIS_PTD].[dbo].[ PTDFlowRules]
// string strSQL = $@"Select [FormID] FROM PTDFlowRules
// where [ToID] ='{recordType}'";
// DataTable dtPTDFlowRules = new DataTable();
// using (var cmd = connPTD.CreateCommand())
@ -3885,7 +3859,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
// }
// }
// strSQL = @$"Select [RecordTypeID] FROM [SFIS_PTD].[dbo].[ ZProductTrans]
// strSQL = @$"Select [RecordTypeID] FROM ZProductTrans
// where [SerialNumber] ='{serialNumber}'
// Order by [RecordDate] Desc";
// using (var cmd = connPTD.CreateCommand())
@ -3936,8 +3910,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
try
{
string strSQL = $ @ "select a.RecordTypeID,(select distinct TypeName from SFIS_PTD.dbo. RecordTypeInfo where ID = a.RecordTypeID ) as TypeName
from SFIS_PTD . dbo . ZProductTrans a group by a . RecordTypeID ";
string strSQL = $ @ "select a.RecordTypeID,(select distinct TypeName from RecordTypeInfo where ID = a.RecordTypeID ) as TypeName
from ZProductTrans a group by a . RecordTypeID ";
DataTable dtRecordTypes = new DataTable ( ) ;
using ( var cmd = connPTD . CreateCommand ( ) )
{
@ -3999,7 +3973,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
SWITCHOFFSET ( CONVERT ( datetimeoffset ,
a . RecordDate ) ,
DATENAME ( TzOffset , SYSDATETIMEOFFSET ( ) ) ) ) as RecordDate
FROM SFIS_PTD . dbo . ZProductTrans a where 1 = 1 ";
FROM ZProductTrans a where 1 = 1 ";
if ( recordType ! = null & & recordType ! = "" & & recordType ! = "全部" )
{
strSQL + = $" And a.RecordTypeID ='{recordType}'" ;
@ -4113,7 +4087,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
a . SerialNumber ' SN ' , a . ProductID , a . LocationID ' Location ' ,
a . EmplID as empID , a . CreateDate , a . ExtNotes , a . RecordDate ,
a . SalesOrderNumber AS soNumber , a . SOLineNO AS soLineNo , a . ERP_CustomerID ' Customer '
FROM SFIS_PTD . dbo . ZProductTrans a where 1 = 1 ";
FROM ZProductTrans a where 1 = 1 ";
if ( recordType ! = null & & recordType ! = "" & & recordType ! = "全部" )
{
@ -4239,7 +4213,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
try
{
string strSQL = $@"Select top 1 SoldCustomerID 'Customer' from SFIS_PTD.dbo. ZDNDetail where DNNo ='{recordNumber}'" ;
string strSQL = $@"Select top 1 SoldCustomerID 'Customer' from ZDNDetail where DNNo ='{recordNumber}'" ;
string strCustomer = "" ;
using ( var cmd = connPTD . CreateCommand ( ) )
@ -4287,7 +4261,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
try
{
string strSQL = $@"select * from SFIS_PTD.dbo. RecordTypeInfo" ;
string strSQL = $@"select * from RecordTypeInfo" ;
DataTable dtRecordTypeInfo = new DataTable ( ) ;
using ( var cmd = connPTD . CreateCommand ( ) )
@ -4346,7 +4320,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
try
{
string strSQL = $@"select * from SFIS_PTD.dbo. RecordTypeInfo Where SEQ ='{id}'" ;
string strSQL = $@"select * from RecordTypeInfo Where SEQ ='{id}'" ;
DataTable dtRecordTypeInfo = new DataTable ( ) ;
using ( var cmd = connPTD . CreateCommand ( ) )
@ -4407,7 +4381,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
try
{
string strSQL = $ @ "INSERT INTO SFIS_PTD.dbo. RecordTypeInfo (ID, RBU, TypeName, TypeDesc, Source, PrefixCode, Length,Status)
string strSQL = $ @ "INSERT INTO RecordTypeInfo (ID, RBU, TypeName, TypeDesc, Source, PrefixCode, Length,Status)
VALUES ( ' { RecordTypeInfo . ID } ',' { RecordTypeInfo . RBU } ' , ' { RecordTypeInfo . TypeName } ' , ' { RecordTypeInfo . TypeDesc } ' ,
' { RecordTypeInfo . Source } ' , ' { RecordTypeInfo . PrefixCode } ' , { RecordTypeInfo . Length }
, ' { RecordTypeInfo . Status } ' ) ";
@ -4458,7 +4432,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
try
{
string strSQL = $ @ "UPDATE SFIS_PTD.dbo. RecordTypeInfo
string strSQL = $ @ "UPDATE RecordTypeInfo
SET RBU = ' { RecordTypeInfo . RBU } ' ,
ID = ' { RecordTypeInfo . ID } ' ,
TypeName = ' { RecordTypeInfo . TypeName } ' ,
@ -4507,7 +4481,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
try
{
string strSQL = $ @ "DELETE FROM SFIS_PTD.dbo. RecordTypeInfo
string strSQL = $ @ "DELETE FROM RecordTypeInfo
WHERE SEQ = ' { id } ' ";
using ( var cmd = connPTD . CreateCommand ( ) )
@ -4551,7 +4525,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
try
{
string strSQL = $@"select * from SFIS_PTD.dbo. CustomerItemMailGroup" ;
string strSQL = $@"select * from CustomerItemMailGroup" ;
DataTable dtCustomerItemMailGroup = new DataTable ( ) ;
using ( var cmd = connPTD . CreateCommand ( ) )
{
@ -4604,7 +4578,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
try
{
string strSQL = $@"select * from SFIS_PTD.dbo. CustomerItemMailGroup Where 1=1" ;
string strSQL = $@"select * from CustomerItemMailGroup Where 1=1" ;
if ( id ! = null & & id ! = "" )
{
strSQL + = $@" And CustomerCode ='{id}'" ;
@ -4662,7 +4636,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
try
{
string strSQL = $ @ "INSERT INTO SFIS_PTD.dbo.[CustomerItemMailGroup] ([ItemNumber],[CustomerCode],[MailGroup],[StatusNo] )
string strSQL = $ @ "INSERT INTO CustomerItemMailGroup (ItemNumber, CustomerCode, MailGroup, StatusNo )
VALUES ( ' { CustomerItemMailGroup . ItemNumber } ',' { CustomerItemMailGroup . CustomerCode } ' ,
' { CustomerItemMailGroup . MailGroup } ' , ' { CustomerItemMailGroup . StatusNo } ' ) ";
using ( var cmd = connPTD . CreateCommand ( ) )
@ -4711,7 +4685,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
try
{
string strSQL = $ @ "UPDATE SFIS_PTD.dbo. CustomerItemMailGroup
string strSQL = $ @ "UPDATE CustomerItemMailGroup
SET ItemNumber = ' { CustomerItemMailGroup . ItemNumber } ' ,
MailGroup = ' { CustomerItemMailGroup . MailGroup } '
WHERE CustomerCode = ' { id } ' ";
@ -4754,7 +4728,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
try
{
string strSQL = $ @ "UPDATE SFIS_PTD.dbo. CustomerItemMailGroup
string strSQL = $ @ "UPDATE CustomerItemMailGroup
SET StatusNo =
CASE
WHEN StatusNo = 'A' THEN 'S'
@ -4954,8 +4928,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
//用ZProductTrans最新RecordType 檢查PTDFlowRules邏輯
bool bolChkFlow = false ;
strSQL = $ @ "Select [ FormID] FROM [SFIS_PTD].[dbo].[ PTDFlowRules]
where [ ToID ] = ' { Data . RecordTypeID } ' ";
strSQL = $ @ "Select FormID FROM PTDFlowRules
where ToID = ' { Data . RecordTypeID } ' ";
DataTable dtPTDFlowRules = new DataTable ( ) ;
using ( var cmd = connPTD . CreateCommand ( ) )
{
@ -4970,9 +4944,9 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
}
strSQL = @ $ "Select [ RecordTypeID] FROM [SFIS_PTD].[dbo].[ ZProductTrans]
where [ SerialNumber ] = ' { Data . ShipmentSN } '
Order by [ RecordDate ] Desc ";
strSQL = @ $ "Select RecordTypeID FROM ZProductTrans
where SerialNumber = ' { Data . ShipmentSN } '
Order by RecordDate Desc ";
using ( var cmd = connPTD . CreateCommand ( ) )
{
cmd . CommandText = strSQL ;
@ -5047,8 +5021,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
try
{
string strSQL = $ @ "DELETE FROM SFIS_PTD.dbo.[ ZWHPickListDetail]
WHERE [ TaskStatus ] = ' Picked ' And [ ShipmentSN ] = ' { sn } ' ";
string strSQL = $ @ "DELETE FROM ZWHPickListDetail
WHERE TaskStatus = ' Picked ' And ShipmentSN = ' { sn } ' ";
using ( var cmd = connPTD . CreateCommand ( ) )
{
cmd . CommandText = strSQL ;
@ -5089,8 +5063,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
try
{
string strSQL = $ @ "DELETE FROM SFIS_PTD.dbo.[ ZWHPickListDetail]
WHERE [ TaskStatus ] = ' Picked ' And [ RecordNumber ] = ' { recordNo } ' AND [ RCLineNO ] = ' { lineNo } ' ";
string strSQL = $ @ "DELETE FROM ZWHPickListDetail
WHERE TaskStatus = ' Picked ' And RecordNumber = ' { recordNo } ' AND RCLineNO = ' { lineNo } ' ";
using ( var cmd = connPTD . CreateCommand ( ) )
{
cmd . CommandText = strSQL ;
@ -5240,15 +5214,28 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
salesOrderNumber = dnDetail . FirstOrDefault ( ) . OrderNo ;
sOLineNO = dnDetail . FirstOrDefault ( ) . OrderLineNO ;
eRP_CustomerID = dnDetail . FirstOrDefault ( ) . Ship CustomerID ;
eRP_CustomerID = dnDetail . FirstOrDefault ( ) . Sold CustomerID ;
}
}
var mailDataItem = new List < SNDataModel > ( ) ;
//ZWHPickListDetail查SN資訊
strSQL = $ @ "Select * FROM [SFIS_PTD].[dbo].[ZWHPickListDetail]
where RecordNumber = ' { SNData . dnno } ' and RCLineNO = ' { SNData . dnLineNO } ' and ProductID = ' { SNData . productID } ' ";
strSQL = $ @ " SELECT
ShipmentSN ,
StartDate ,
ExpectStartDate ,
a . ProductID ,
b . CurrentMOID
FROM ZWHPickListDetail a - - 安 勤 備 貨
LEFT JOIN { SFISDbContext } ZProductSN b
ON a . ShipmentSN = b . CurrentShipmentSN
LEFT JOIN { SFISDbContext } ZMO c
ON b . CurrentMOID = c . MOID
WHERE
RecordNumber = ' { SNData . dnno } '
AND RCLineNO = ' { SNData . dnLineNO } '
AND a . ProductID = ' { SNData . productID } ' ";
var q = await ptdConnection . QueryAsync < dynamic > ( strSQL ) ;
@ -5256,7 +5243,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
string strLatest ;
//確認此出貨序號是否有ZHistoryKeyDefine
strSQL = $@"select Seed FROM [SFIS_PTD].[dbo].[ ZHistoryKeyDefine] where serialnumber ='{row.ShipmentSN}'" ;
strSQL = $@"select Seed FROM ZHistoryKeyDefine where serialnumber ='{row.ShipmentSN}'" ;
var q1 = await ptdConnection . QueryAsync < dynamic > ( strSQL ) ;
@ -5266,11 +5253,11 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
int nIdx = seed + 1 ;
strLatest = row . ShipmentSN + nIdx . ToString ( ) . PadLeft ( 4 , '0' ) ; //組成HistoryID
//HistoryKeyDefine
strSQL = @ $ "UPDATE [SFIS_PTD].[dbo].[ ZHistoryKeyDefine]
SET [ Seed ] = { nIdx } where [ SerialNumber ] = ' { row . ShipmentSN } ' ";
strSQL = @ $ "UPDATE ZHistoryKeyDefine
SET Seed = { nIdx } where SerialNumber = ' { row . ShipmentSN } ' ";
colSQL . Add ( strSQL ) ;
//ZSNInfo
strSQL = @ $ "Update [SFIS_PTD].[dbo].[ ZSNInfo] SET LatestHistoryID='{strLatest}',RecordTypeID='{strRecordType}',
strSQL = @ $ "Update ZSNInfo SET LatestHistoryID='{strLatest}',RecordTypeID='{strRecordType}',
CurrentProductID = ' { row . ProductID } '
where SerialNumber = ' { row . ShipmentSN } ' ";
colSQL . Add ( strSQL ) ;
@ -5279,14 +5266,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
strLatest = row . ShipmentSN + 1. ToString ( ) . PadLeft ( 4 , '0' ) ; //組成HistoryID
//ZHistoryKeyDefine
strSQL = @ $ "INSERT INTO [SFIS_PTD].[dbo].[ZHistoryKeyDefine] ([SerialNumber],[Seed] )
strSQL = @ $ "INSERT INTO ZHistoryKeyDefine (SerialNumber, Seed )
VALUES ( ' { row . ShipmentSN } ' , 1 ) ";
colSQL . Add ( strSQL ) ;
//ZSNInfo
strSQL = @ $ "INSERT INTO [SFIS_PTD].[dbo].[ZSNInfo] ([SerialNumber],[CurrentProductID],[OriginalProductID] ,
[LocationID] , [ LatestHistoryID ] , [ RecordTypeID ] ,
[OwnerPlantID] , [ OwnerCompanyID ] , [ CreatePlantID ] , [ CreateCompanyID ] ,
[ModifyDate] ) VALUES
strSQL = @ $ "INSERT INTO ZSNInfo (SerialNumber, CurrentProductID, OriginalProductID ,
LocationID , LatestHistoryID , RecordTypeID ,
OwnerPlantID , OwnerCompanyID , CreatePlantID , CreateCompanyID ,
ModifyDate ) VALUES
( ' { row . ShipmentSN } ',' { row . ProductID } ',' { row . ProductID } ' ,
' 9 0 0 0 ',' { strLatest } ',' { strRecordType } ' ,
' { strWorkCenter } ',' { strRbu } ',' { strWorkCenter } ',' { strRbu } ' ,
@ -5294,13 +5281,13 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
colSQL . Add ( strSQL ) ;
}
//ZProductTrans
strSQL = $ @ "INSERT INTO [SFIS_PTD].[dbo].[ ZProductTrans]
( [ HistoryID ] , [ SerialNumber ] , [ RecordTypeID ] , [ RecordNumber ] , [ RCLineNO ] , [ RecordDate ] ,
[ProductID] , [ IsChangeID ] , [ LocationID ] , [ EmplID ] , [ IsDelete ] ,
[OwnerPlantID] , [ OwnerCompanyID ] , [ CreatePlantID ] , [ CreateCompanyID ] ,
[CreatorID] , [ CreateDate ] , [ ModifierID ] , [ ModifyDate ] ,
[chkflag] , [ IsBranchCoReceived ] , [ MOID ] ,
[SalesOrderNumber] , [ SOLineNO ] , [ ERP_CustomerID ] ) VALUES
strSQL = $ @ "INSERT INTO ZProductTrans
( HistoryID , SerialNumber , RecordTypeID , RecordNumber , RCLineNO , RecordDate ,
ProductID , IsChangeID , LocationID , EmplID , IsDelete ,
OwnerPlantID , OwnerCompanyID , CreatePlantID , CreateCompanyID ,
CreatorID , CreateDate , ModifierID , ModifyDate ,
chkflag , IsBranchCoReceived , MOID ,
SalesOrderNumber , SOLineNO , ERP_CustomerID ) VALUES
( ' { strLatest } ',' { row . ShipmentSN } ',' { strRecordType } ',' { SNData . dnno } ',' { SNData . dnLineNO } ',' { strRecordDate } ' ,
' { SNData . productID } ' , 0 , ' 9 0 0 0 ',' { strEmpId } ' , 0 ,
' { strWorkCenter } ',' { strRbu } ',' { strWorkCenter } ',' { strRbu } ' ,
@ -5313,10 +5300,13 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
DnNo = SNData . dnno ,
LineNo = SNData . dnLineNO ,
Material = SNData . productID ,
Sn = row . ShipmentSN
ShipQty = SNData . shipQty ,
Sn = row . ShipmentSN ,
StartDate = row . StartDate ? ? row . ExpectStartDate , //StartDate(實際開工日),ExpectStartDate(預計開工日)
CurrentMOID = row . CurrentMOID
} ) ;
}
strSQL = $ @ "Update [SFIS_PTD].[dbo].[ZWHPickListDetail] set TaskStatus ='Recorded'
strSQL = $ @ "Update ZWHPickListDetail set TaskStatus ='Recorded'
where RecordNumber = ' { SNData . dnno } ' and RCLineNO = ' { SNData . dnLineNO } ' ";
colSQL . Add ( strSQL ) ;
@ -5397,7 +5387,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
foreach ( PTD007TableDataModel SNData in Data . TableData )
{
//ZWHPickListDetail查SN資訊
strSQL = $ @ "Select * FROM [SFIS_PTD].[dbo].[ ZWHPickListDetail]
strSQL = $ @ "Select * FROM ZWHPickListDetail
where RecordNumber = ' { SNData . dnno } ' and RCLineNO = ' { SNData . dnLineNO } ' ";
DataTable dtSNData = new DataTable ( ) ;
using ( var cmd = connPTD . CreateCommand ( ) )
@ -5416,7 +5406,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
string strLatest ;
//確認此出貨序號是否有ZHistoryKeyDefine
strSQL = $@"select Seed FROM [SFIS_PTD].[dbo].[ ZHistoryKeyDefine] where serialnumber ='{row[" ShipmentSN "]}'" ;
strSQL = $@"select Seed FROM ZHistoryKeyDefine where serialnumber ='{row[" ShipmentSN "]}'" ;
using ( var cmd = connPTD . CreateCommand ( ) )
{
cmd . CommandText = strSQL ;
@ -5428,11 +5418,11 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
int nIdx = seed + 1 ;
strLatest = row [ "ShipmentSN" ] . ToString ( ) + nIdx . ToString ( ) . PadLeft ( 4 , '0' ) ; //組成HistoryID
//HistoryKeyDefine
strSQL = @ $ "UPDATE [SFIS_PTD].[dbo].[ ZHistoryKeyDefine]
SET [ Seed ] = { nIdx } where [ SerialNumber ] = ' { row [ "ShipmentSN" ] } ' ";
strSQL = @ $ "UPDATE ZHistoryKeyDefine
SET Seed = { nIdx } where SerialNumber = ' { row [ "ShipmentSN" ] } ' ";
colSQL . Add ( strSQL ) ;
//ZSNInfo
strSQL = @ $ "Update [SFIS_PTD].[dbo].[ ZSNInfo] SET LatestHistoryID='{strLatest}',RecordTypeID='{strRecordType}',
//ZSNInfoF
strSQL = @ $ "Update ZSNInfo SET LatestHistoryID='{strLatest}',RecordTypeID='{strRecordType}',
CurrentProductID = ' { row [ "ProductID" ] } '
where SerialNumber = ' { row [ "ShipmentSN" ] } ' ";
colSQL . Add ( strSQL ) ;
@ -5441,14 +5431,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
strLatest = row [ "ShipmentSN" ] . ToString ( ) + 1. ToString ( ) . PadLeft ( 4 , '0' ) ; //組成HistoryID
//ZHistoryKeyDefine
strSQL = @ $ "INSERT INTO [SFIS_PTD].[dbo].[ZHistoryKeyDefine] ([SerialNumber],[Seed] )
strSQL = @ $ "INSERT INTO ZHistoryKeyDefine (SerialNumber, Seed )
VALUES ( ' { row [ "ShipmentSN" ] } ' , 1 ) ";
colSQL . Add ( strSQL ) ;
//ZSNInfo
strSQL = @ $ "INSERT INTO [SFIS_PTD].[dbo].[ZSNInfo] ([SerialNumber],[CurrentProductID],[OriginalProductID] ,
[LocationID] , [ LatestHistoryID ] , [ RecordTypeID ] ,
[OwnerPlantID] , [ OwnerCompanyID ] , [ CreatePlantID ] , [ CreateCompanyID ] ,
[ModifyDate] ) VALUES
strSQL = @ $ "INSERT INTO ZSNInfo (SerialNumber, CurrentProductID, OriginalProductID ,
LocationID , LatestHistoryID , RecordTypeID ,
OwnerPlantID , OwnerCompanyID , CreatePlantID , CreateCompanyID ,
ModifyDate ) VALUES
( ' { row [ "ShipmentSN" ] } ',' { row [ "ProductID" ] } ',' { row [ "ProductID" ] } ' ,
' 9 0 0 0 ',' { strLatest } ',' { strRecordType } ' ,
' { strWorkCenter } ',' { strRbu } ',' { strWorkCenter } ',' { strRbu } ' ,
@ -5456,12 +5446,12 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
colSQL . Add ( strSQL ) ;
}
//ZProductTrans
strSQL = $ @ "INSERT INTO [SFIS_PTD].[dbo].[ ZProductTrans]
( [ HistoryID ] , [ SerialNumber ] , [ RecordTypeID ] , [ RecordNumber ] , [ RCLineNO ] , [ RecordDate ] ,
[ProductID] , [ IsChangeID ] , [ LocationID ] , [ EmplID ] , [ IsDelete ] ,
[OwnerPlantID] , [ OwnerCompanyID ] , [ CreatePlantID ] , [ CreateCompanyID ] ,
[CreatorID] , [ CreateDate ] , [ ModifierID ] , [ ModifyDate ] ,
[chkflag] , [ IsBranchCoReceived ] , [ MOID ] ) VALUES
strSQL = $ @ "INSERT INTO ZProductTrans
( HistoryID , SerialNumber , RecordTypeID , RecordNumber , RCLineNO , RecordDate ,
ProductID , IsChangeID , LocationID , EmplID , IsDelete ,
OwnerPlantID , OwnerCompanyID , [ CreatePlantID , CreateCompanyID ,
CreatorID , CreateDate , ModifierID , ModifyDate ,
chkflag , IsBranchCoReceived , MOID ) VALUES
( ' { strLatest } ',' { row [ "ShipmentSN" ] } ',' { strRecordType } ',' { SNData . dnno } ',' { SNData . dnLineNO } ',' { strRecordDate } ' ,
' { SNData . productID } ' , 0 , ' 9 0 0 0 ',' { SNData . soldCustomerID . ToString ( ) } ' , 0 ,
' { strWorkCenter } ',' { strRbu } ',' { strWorkCenter } ',' { strRbu } ' ,
@ -5470,7 +5460,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
}
}
}
strSQL = $ @ "Update [SFIS_PTD].[dbo].[ ZWHPickListDetail] set TaskStatus ='Recorded'
strSQL = $ @ "Update ZWHPickListDetail set TaskStatus ='Recorded'
where RecordNumber = ' { SNData . dnno } ' and RCLineNO = ' { SNData . dnLineNO } ' ";
colSQL . Add ( strSQL ) ;
}
@ -5556,14 +5546,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
EmplID AS SoldCustomerID ,
count ( * ) as Qty ,
OwnerPlantID
FROM SFIS_PTD . dbo . ZProductTrans
FROM ZProductTrans
WHERE ERP_CustomerID IN ( { string . Join ( ", " , erpCustomerId . ConvertAll ( id = > $"N'{id}'" ) ) } )
AND RecordNumber = @RecordNumber
AND IsBranchCoReceived = 0
AND RecordTypeID in ( N ' 6 0 1 ' , N ' 6 3 3 ' , N ' 6 0 1D B ' )
GROUP BY RecordNumber , RCLineNO , ProductID , OwnerPlantID , EmplID
) A
LEFT JOIN SFIS_PTD . dbo . ZDNDetail B on A . DNNO = B . DNNO AND A . DNLineNO = B . DNLineNO
LEFT JOIN ZDNDetail B on A . DNNO = B . DNNO AND A . DNLineNO = B . DNLineNO
ORDER BY A . DNNO , A . DNLineNO ";
DynamicParameters p = new DynamicParameters ( ) ;
@ -5634,7 +5624,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
var mailDataItem = new List < SNDataModel > ( ) ;
//ZProductTrans
strSQL = $ @ " SELECT * FROM SFIS_PTD.dbo. ZProductTrans
strSQL = $ @ " SELECT * FROM ZProductTrans
WHERE ERP_CustomerID IN ( { string . Join ( ", " , erpCustomerId . ConvertAll ( id = > $"N'{id}'" ) ) } )
AND IsBranchCoReceived = 0
AND RecordTypeID in ( N ' 6 0 1 ' , N ' 6 3 3 ' , N ' 6 0 1D B ' )
@ -5647,7 +5637,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
string strLatest ;
//確認此出貨序號是否有ZHistoryKeyDefine
strSQL = $@"select Seed FROM [SFIS_PTD].[dbo].[ ZHistoryKeyDefine] where serialnumber ='{row.SerialNumber}'" ;
strSQL = $@"select Seed FROM ZHistoryKeyDefine where serialnumber ='{row.SerialNumber}'" ;
var q1 = await ptdConnection . QueryAsync < dynamic > ( strSQL ) ;
if ( q1 . Any ( ) )
@ -5656,11 +5646,11 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
int nIdx = seed + 1 ;
strLatest = row . SerialNumber + nIdx . ToString ( ) . PadLeft ( 4 , '0' ) ; //組成HistoryID
//HistoryKeyDefine
strSQL = @ $ "UPDATE [SFIS_PTD].[dbo].[ ZHistoryKeyDefine]
SET [ Seed ] = { nIdx } where [ SerialNumber ] = ' { row . SerialNumber } ' ";
strSQL = @ $ "UPDATE ZHistoryKeyDefine
SET Seed = { nIdx } where SerialNumber = ' { row . SerialNumber } ' ";
colSQL . Add ( strSQL ) ;
//ZSNInfo
strSQL = @ $ "Update [SFIS_PTD].[dbo].[ ZSNInfo] SET LatestHistoryID='{strLatest}',RecordTypeID='{strRecordType}',
strSQL = @ $ "Update ZSNInfo SET LatestHistoryID='{strLatest}',RecordTypeID='{strRecordType}',
CurrentProductID = ' { row . ProductID } '
where SerialNumber = ' { row . SerialNumber } ' ";
colSQL . Add ( strSQL ) ;
@ -5669,14 +5659,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
strLatest = row . SerialNumber + 1. ToString ( ) . PadLeft ( 4 , '0' ) ; //組成HistoryID
//ZHistoryKeyDefine
strSQL = @ $ "INSERT INTO [SFIS_PTD].[dbo].[ZHistoryKeyDefine] ([SerialNumber],[Seed] )
strSQL = @ $ "INSERT INTO ZHistoryKeyDefine (SerialNumber, Seed )
VALUES ( ' { row . SerialNumber } ' , 1 ) ";
colSQL . Add ( strSQL ) ;
//ZSNInfo
strSQL = @ $ "INSERT INTO [SFIS_PTD].[dbo].[ZSNInfo] ([SerialNumber],[CurrentProductID],[OriginalProductID] ,
[LocationID] , [ LatestHistoryID ] , [ RecordTypeID ] ,
[OwnerPlantID] , [ OwnerCompanyID ] , [ CreatePlantID ] , [ CreateCompanyID ] ,
[ModifyDate] ) VALUES
strSQL = @ $ "INSERT INTO ZSNInfo (SerialNumber, CurrentProductID, OriginalProductID ,
LocationID , LatestHistoryID , RecordTypeID ,
OwnerPlantID , OwnerCompanyID , CreatePlantID , CreateCompanyID ,
ModifyDate ) VALUES
( ' { row . SerialNumber } ',' { row . ProductID } ',' { row . ProductID } ' ,
' 9 0 0 0 ',' { strLatest } ',' { strRecordType } ' ,
' { strWorkCenter } ',' { strRbu } ',' { strWorkCenter } ',' { strRbu } ' ,
@ -5684,12 +5674,12 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
colSQL . Add ( strSQL ) ;
}
//ZProductTrans
strSQL = $ @ "INSERT INTO [SFIS_PTD].[dbo].[ ZProductTrans]
( [ HistoryID ] , [ SerialNumber ] , [ RecordTypeID ] , [ RecordNumber ] , [ RCLineNO ] , [ RecordDate ] ,
[ProductID] , [ IsChangeID ] , [ LocationID ] , [ EmplID ] , [ IsDelete ] ,
[OwnerPlantID] , [ OwnerCompanyID ] , [ CreatePlantID ] , [ CreateCompanyID ] ,
[CreatorID] , [ CreateDate ] , [ ModifierID ] , [ ModifyDate ] ,
[chkflag] , [ IsBranchCoReceived ] , [ MOID ] ) VALUES
strSQL = $ @ "INSERT INTO ZProductTrans
( HistoryID , SerialNumber , RecordTypeID , RecordNumber , RCLineNO , RecordDate ,
ProductID , IsChangeID , LocationID , EmplID , IsDelete ,
OwnerPlantID , OwnerCompanyID , CreatePlantID , CreateCompanyID ,
CreatorID , CreateDate , ModifierID , ModifyDate ,
chkflag , IsBranchCoReceived , MOID ) VALUES
( ' { strLatest } ',' { row . SerialNumber } ',' { strRecordType } ',' { SNData . dnno } ',' { SNData . dnLineNO } ',' { strRecordDate } ' ,
' { SNData . productID } ' , 0 , ' 9 0 0 0 ',' { SNData . soldCustomerID . ToString ( ) } ' , 0 ,
' { strWorkCenter } ',' { strRbu } ',' { strWorkCenter } ',' { strRbu } ' ,
@ -5704,7 +5694,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
Sn = row . SerialNumber
} ) ;
}
strSQL = $ @ " Update SFIS_PTD.dbo. ZProductTrans set IsBranchCoReceived ='1'
strSQL = $ @ " Update ZProductTrans set IsBranchCoReceived ='1'
WHERE ERP_CustomerID IN ( { string . Join ( ", " , erpCustomerId . ConvertAll ( id = > $"N'{id}'" ) ) } )
AND IsBranchCoReceived = 0
AND RecordTypeID in ( N ' 6 0 1 ' , N ' 6 3 3 ' , N ' 6 0 1D B ' )
@ -5766,7 +5756,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
string strSQL = $ @ "SELECT RecordTypeID,RecordNumber,RCLineNO 'LineNo',
SerialNumber ' SN ' , ProductID , CreateDate
FROM SFIS_PTD . dbo . ZProductTrans where RecordNumber = ' { recordNumber } ' And RCLineNO = ' { lineNo } '
FROM ZProductTrans where RecordNumber = ' { recordNumber } ' And RCLineNO = ' { lineNo } '
And ProductID = ' { materialNo } ' ";
if ( shippingSN ! = null & & shippingSN ! = "" )
{
@ -5853,7 +5843,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
if ( Data . type = = 0 ) //還原
{
//SQL Server 2012後才能使用
//strSQL = $"Select HistoryID,RecordTypeID,ModifyDate from [SFIS_PTD].[dbo].[ ZProductTrans] " +
//strSQL = $"Select HistoryID,RecordTypeID,ModifyDate from ZProductTrans " +
// $"where [SerialNumber] = '{SNData.sn}' " +
// $"Order by HistoryID desc offset 1 row fetch next 1 rows only ";
@ -5863,8 +5853,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
RecordTypeID ,
ModifyDate ,
ROW_NUMBER ( ) OVER ( ORDER BY HistoryID DESC ) AS RowNum
FROM [ SFIS_PTD ] . [ dbo ] . [ ZProductTrans ]
WHERE [ SerialNumber ] = ' { SNData . sn } '
FROM ZProductTrans
WHERE SerialNumber = ' { SNData . sn } '
)
SELECT
HistoryID ,
@ -5880,21 +5870,21 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{
if ( reader . Read ( ) )
{
strSQL = $"Update [SFIS_PTD].[dbo].[ ZSNInfo] set RecordTypeID ='{reader[" RecordTypeID "]}',ModifyDate ='{reader[" ModifyDate "]}',LatestHistoryID ='{reader[" HistoryID "]}' " +
strSQL = $"Update ZSNInfo set RecordTypeID ='{reader[" RecordTypeID "]}',ModifyDate ='{reader[" ModifyDate "]}',LatestHistoryID ='{reader[" HistoryID "]}' " +
$"where SerialNumber ='{SNData.sn}'" ;
colSQL . Add ( strSQL ) ;
int seed = int . Parse ( reader [ "HistoryID" ] . ToString ( ) . Substring ( reader [ "HistoryID" ] . ToString ( ) . Length - 4 ) ) ;
strSQL = @ $ "UPDATE [SFIS_PTD].[dbo].[ ZHistoryKeyDefine]
SET [ Seed ] = { seed } where [ SerialNumber ] = ' { SNData . sn } ' ";
strSQL = @ $ "UPDATE ZHistoryKeyDefine
SET Seed = { seed } where SerialNumber = ' { SNData . sn } ' ";
colSQL . Add ( strSQL ) ;
}
else
{
strSQL = $"Delete [SFIS_PTD].[dbo].[ ZSNInfo] where SerialNumber ='{SNData.sn}'" ;
strSQL = $"Delete ZSNInfo where SerialNumber ='{SNData.sn}'" ;
colSQL . Add ( strSQL ) ;
strSQL = $"Delete [SFIS_PTD].[dbo].[ ZHistoryKeyDefine] where SerialNumber ='{SNData.sn}'" ;
strSQL = $"Delete ZHistoryKeyDefine where SerialNumber ='{SNData.sn}'" ;
colSQL . Add ( strSQL ) ;
}
}
@ -5906,13 +5896,13 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
throw new Exception ( SNData . recordTypeID + "狀態不能刪除!" ) ;
}
strSQL = $"Delete [SFIS_PTD].[dbo].[ ZProductTrans] " +
strSQL = $"Delete ZProductTrans " +
$"where [SerialNumber] = '{SNData.sn}' " +
$"and RecordNumber = '{SNData.recordNumber}' and RCLineNO ='{SNData.lineNo}' " +
$"and ProductID ='{SNData.productID}'" ;
colSQL . Add ( strSQL ) ;
strSQL = $ @ "Delete [SFIS_PTD].[dbo].[ ZWHPickListDetail]
strSQL = $ @ "Delete ZWHPickListDetail
where InputSN = ' { SNData . sn } '
and RecordNumber = ' { SNData . recordNumber } '
and RCLineNO = ' { SNData . lineNo } ' ";