Compile function Copy_WM_IN_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given WM_IN record to the MSSQL database.
	
	History
	-------
	05/09/2012    KRF   Original Programmer
\*****************************************************************************/

$insert WM_IN_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(40)
MatParse Record into Rec
					    
// List of key names and their values
Keys  = "WO_NO"       :@VM:SQL_Format(Field(Key, "*", 1), "INT"):@FM
Keys := "PROC_STEP_NO":@VM:SQL_Format(Field(Key, "*", 2), "INT"):@FM
Keys := "IN_CASS_NO"  :@VM:SQL_Format(Field(Key, "*", 3), "INT")

// List of data fields and their values
DataFields  = "LPD_PRECLEAN"     :@VM:SQL_Format(Rec(WM_IN_LPD_PRECLEAN$),      "INT"):@FM
DataFields := "LPD_POST_PRECLEAN":@VM:SQL_Format(Rec(WM_IN_LPD_POST_PRECLEAN$), "INT"):@FM
DataFields := "PRE_PITS"         :@VM:SQL_Format(Rec(WM_IN_PRE_PITS$),          "INT"):@FM
DataFields := "PRE_MOUNDS"       :@VM:SQL_Format(Rec(WM_IN_PRE_MOUNDS$),        "INT"):@FM
DataFields := "PRE_SCRATCHES"    :@VM:SQL_Format(Rec(WM_IN_PRE_SCRATCHES$),     "INT"):@FM
DataFields := "PRE_SCRATCH_LEN"  :@VM:SQL_Format(Rec(WM_IN_PRE_SCRATCH_LEN$),   "INT"):@FM
DataFields := "PRE_SPOTS"        :@VM:SQL_Format(Rec(WM_IN_PRE_SPOTS$),         "INT"):@FM
DataFields := "PRE_FOV"          :@VM:SQL_Format(Rec(WM_IN_PRE_FOV$),           "INT"):@FM
DataFields := "PRE_BL_DEFECTS"   :@VM:SQL_Format(Rec(WM_IN_PRE_BL_DEFECTS$),    "INT"):@FM
DataFields := "HOLD_ORG"         :@VM:SQL_Format(Rec(WM_IN_HOLD_ORG$),          "BIT"):@FM
DataFields := "HOT_LOT"          :@VM:SQL_Format(Rec(WM_IN_HOT_LOT$),           "BIT"):@FM
DataFields := "VOID"             :@VM:SQL_Format(Rec(WM_IN_VOID$),              "BIT")

// Write the data to the SQL database
Ans = SQL_Write(Connection, "WM_IN", Keys, DataFields)

//-------------------------------------------------------------------------------------------------
// Multi-valued Fields

// WM_IN_SLOT_NO
If Ans EQ "" AND (Rec(WM_IN_SLOT_NO$) NE "" OR Rec(WM_IN_RDS_NO$) NE "" OR Rec(WM_IN_POCKET_NO$) NE "" OR Rec(WM_IN_ZONE$) NE "" OR Rec(WM_IN_SLOT_MET_NO$) NE "" OR Rec(WM_IN_SLOT_NCR$) NE "") then
    
    // List of data fields and their values
    MvFields  = "SLOT_NO"        :@FM:SQL_Format(Rec(WM_IN_SLOT_NO$),     "INT"):@RM
    MvFields := "RDS_NO"         :@FM:SQL_Format(Rec(WM_IN_RDS_NO$),      "STR"):@RM
    MvFields := "RDS_CURR_STATUS":@FM:SQL_Format({RDS_CURR_STATUS},       "STR"):@RM
    MvFields := "POCKET_NO"      :@FM:SQL_Format(Rec(WM_IN_POCKET_NO$),   "STR"):@RM
    MvFields := "ZONE"           :@FM:SQL_Format(Rec(WM_IN_ZONE$),        "STR"):@RM
    MvFields := "SLOT_MET_NO"    :@FM:SQL_Format(Rec(WM_IN_SLOT_MET_NO$), "STR"):@RM
    MvFields := "SLOT_NCR"       :@FM:SQL_Format(Rec(WM_IN_SLOT_NCR$),    "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WM_IN_SLOT_NO", Keys, MvFields);
    
end

// WM_IN_SIG_BLOCK
If Ans EQ "" AND (Rec(WM_IN_PRE_CODE$) NE "" OR Rec(WM_IN_PRE_BOAT_ID$) NE "" OR Rec(WM_IN_PRE_SRD_NO$) NE "" OR Rec(WM_IN_PRE_EPI_SIG$) NE "" OR Rec(WM_IN_PRE_EPI_SIG_DTM$) NE "") then
    
    // List of data fields and their values
    MvFields  = "PRE_CODE"        :@FM:SQL_Format(Rec(WM_IN_PRE_CODE$),        "STR"):@RM
    MvFields := "PRE_BOAT_ID"     :@FM:SQL_Format(Rec(WM_IN_PRE_BOAT_ID$),     "STR"):@RM
    MvFields := "PRE_SRD_NO"      :@FM:SQL_Format(Rec(WM_IN_PRE_SRD_NO$),      "INT"):@RM
    MvFields := "PRE_EPI_SIG"     :@FM:SQL_Format(Rec(WM_IN_PRE_EPI_SIG$),     "STR"):@RM
    MvFields := "PRE_EPI_SIG_NAME":@FM:SQL_Format({PRE_EPI_SIG_NAME},          "STR"):@RM
    MvFields := "PRE_EPI_SIG_DTM" :@FM:SQL_Format(Rec(WM_IN_PRE_EPI_SIG_DTM$), "DATETIME")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WM_IN_SIG_BLOCK", Keys, MvFields);
    
end

// WM_IN_HOLD_HISTORY
If Ans EQ "" AND (Rec(WM_IN_HOLD_START_DTM_ORG$) NE "" OR Rec(WM_IN_HOLD_START_USER_ORG$) NE "" OR Rec(WM_IN_HOLD_START_REASON_ORG$) NE "" OR Rec(WM_IN_HOLD_STOP_DTM_ORG$) NE "" OR Rec(WM_IN_HOLD_STOP_USER_ORG$) NE "" OR Rec(WM_IN_HOLD_STOP_REASON_ORG$) NE "") then
    
    // List of data fields and their values
    MvFields  = "HOLD_START_DTM"   :@FM:SQL_Format({HOLD_START_DTM},    "DATETIME"):@RM
    MvFields := "HOLD_START_USER"  :@FM:SQL_Format({HOLD_START_USER},   "STR"):@RM
    MvFields := "HOLD_START_REASON":@FM:SQL_Format({HOLD_START_REASON}, "STR"):@RM
    MvFields := "HOLD_STOP_DTM"    :@FM:SQL_Format({HOLD_STOP_DTM},     "DATETIME"):@RM
    MvFields := "HOLD_STOP_USER"   :@FM:SQL_Format({HOLD_STOP_USER},    "STR"):@RM
    MvFields := "HOLD_STOP_REASON" :@FM:SQL_Format({HOLD_STOP_REASON},  "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WM_IN_HOLD_HISTORY", Keys, MvFields);
    
end


// WM_IN Comments
If Ans EQ "" AND Rec(37) NE "" then
    MvFields  = "EPP_COMMENT_DATE":@FM:SQL_Format(Rec(37), "DATETIME"):@RM
    MvFields := "EPP_COMMENT_USER":@FM:SQL_Format(Rec(38), "STR"):@RM
    MvFields := "EPP_COMMENT_NOTE":@FM:SQL_Format(Rec(39), "STR")
    Ans       = SQL_Write_MV(Connection, "WM_IN_COMMENT", Keys, MvFields);
end

Return Ans


