2012-10-29 83 views
0

我得到EDI文件如下所示,我需要處理它,並且我需要維護主鍵,外鍵也。EDI文件沒有任何第三方工具

TH*4.2*857463*01**20091015*1045*P**~~IS*7564*ACME 
PHARMACY~PHA*1234567890~PAT*MA*06*987544****SMITH*JOHN****1234 MAIN 
ST**SOMEWHERE*MA*54356**19500101*M*01*01*INDIA**BURGER~ 

這裏列的分隔符是*,如果沒有提供任何值,它們也會放*。

我需要從

TH*4.2*857463*01**20091015*1045*P**~~ 

存儲字段爲1個表中,由分隔條件字段。

因此,這將是

 
th01  th02  th03  th04 th05   th06  th07  th08 th09   th10 
TH   4.2  857163  01  *(no value) 20091015 1045  p  * (novalue) ~~ 

爲* 7564 * ACME藥學到另一臺,依此類推。

,因爲我不能有XML文件

任何幫助,我無法使用第三方工具?

好的。

這裏是我的vb.net代碼

公共枚舉段 TH PHA PAT IS1 結束枚舉

Dim arrLine As String() 
Dim segmentcode As String 
Dim counter As Integer 
Dim linenumber As Integer = 1 
Dim segmenetsequence As Hashtable = New Hashtable() 
Dim setid As Guid = Guid.NewGuid() 






Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) 

    arrLine = Row.LineText.Split("*"c) 

    segmentcode = SegmentValue(arrLine, 0) 
    Row.LineNumber = linenumber 


    Row.Setid = setid 

    counter = arrLine.Length 
    linenumber += 1 

    Select Case (segmentcode.ToUpper()) 

     Case Segments.TH.ToString.ToUpper() 
      Row.TH01 = SegmentValue(arrLine, 1) 
      Row.TH02 = SegmentValue(arrLine, 2) 
      Row.TH03 = Convert.ToInt32(SegmentValue(arrLine, 3)) 
      Row.TH04 = SegmentValue(arrLine, 4) 
      Row.TH05 = Convert.ToDateTime(SegmentValue(arrLine, 5)) 
      Row.TH06 = SegmentValue(arrLine, 6) 
      Row.TH07 = SegmentValue(arrLine, 7) 
      Row.TH08 = Convert.ToInt32(SegmentValue(arrLine, 8)) 
      Row.TH09 = SegmentValue(arrLine, 9) 

     Case Segments.IS1.ToString.ToUpper() 
      Row.IS01 = SegmentValue(arrLine, 1) 
      Row.IS02 = SegmentValue(arrLine, 2) 
      Row.IS03 = SegmentValue(arrLine, 3) 

     Case Segments.PHA.ToString.ToUpper() 

      Row.PHA01 = SegmentValue(arrLine, 1) 
      Row.PHA02 = SegmentValue(arrLine, 2) 
      Row.PHA03 = SegmentValue(arrLine, 3) 
      Row.PHA04 = SegmentValue(arrLine, 4) 
      Row.PHA05 = SegmentValue(arrLine, 5) 
      Row.PHA06 = SegmentValue(arrLine, 6) 
      Row.PHA07 = SegmentValue(arrLine, 7) 
      Row.PHA08 = SegmentValue(arrLine, 8) 
      Row.PHA09 = SegmentValue(arrLine, 9) 
      Row.PHA10 = SegmentValue(arrLine, 10) 
      Row.PHA11 = SegmentValue(arrLine, 11) 
      Row.PHA12 = SegmentValue(arrLine, 12) 


     Case Segments.PAT.ToString.ToUpper() 

      Row.PAT01 = SegmentValue(arrLine, 1) 
      Row.PAT02 = SegmentValue(arrLine, 2) 
      Row.PAT03 = SegmentValue(arrLine, 3) 
      Row.PAT04 = SegmentValue(arrLine, 4) 
      Row.PAT05 = Convert.ToInt32(SegmentValue(arrLine, 5)) 
      Row.PAT06 = SegmentValue(arrLine, 6) 
      Row.PAT07 = SegmentValue(arrLine, 7) 
      Row.PAT08 = SegmentValue(arrLine, 8) 
      Row.PAT09 = SegmentValue(arrLine, 9) 
      Row.PAT10 = SegmentValue(arrLine, 10) 
      Row.PAT11 = SegmentValue(arrLine, 11) 
      Row.PAT12 = SegmentValue(arrLine, 12) 
      Row.PAT13 = SegmentValue(arrLine, 13) 
      Row.PAT14 = SegmentValue(arrLine, 14) 
      Row.PAT15 = SegmentValue(arrLine, 15) 
      Row.PAT16 = SegmentValue(arrLine, 16) 
      Row.PAT17 = SegmentValue(arrLine, 17) 
      Row.PAT18 = Convert.ToDateTime(SegmentValue(arrLine, 18)) 
      Row.PAT19 = SegmentValue(arrLine, 19) 
      Row.PAT20 = Convert.ToInt32(SegmentValue(arrLine, 20)) 
      Row.PAT21 = Convert.ToInt32(SegmentValue(arrLine, 21)) 
      Row.PAT22 = SegmentValue(arrLine, 22) 
      Row.PAT23 = SegmentValue(arrLine, 23) 
      Row.PAT24 = SegmentValue(arrLine, 24) 




    End Select 



End Sub 

Public Function SegmentValue(ByRef LineArray As String(), ByVal Counter As Integer) As String 
    Throw New NotImplementedException 

    If LineArray.Length > Counter Then 
     Return LineArray(Counter).ToString().Trim() 

    End If 
    Return String.Empty 

End Function 

末級

+4

「有幫助嗎?」是你在整篇文章中提出的唯一問題,這不是一個可以回答的問題。請編輯您的問題,先將其改進爲可回答的問題,然後再添加一些代碼格式以使其更具可讀性。 –

+0

我需要的方法來處理這個文件,而無需使用任何第三方工具 – user1783579

+1

那麼你有什麼嘗試?解析文件非常簡單;您只需抓住每對分隔符('*')之間的部分,並在到達'〜'時停止每個「行」(分段)。 NCPDP EDI藥店索賠文件是最簡單的解析文件之一,但您在此處未展示任何努力。而且你需要**編輯**你的問題來實際詢問一個問題,正如我之前要求你做的那樣。 –

回答

0

從廣義上來講,我是這樣看在使用腳本組件作爲源。它會爲文件可能包含的每個「事物」輸出集合。在你的例子中,你有Output 0有足夠的列來描述上面的th行。然後,您將有一個Output 1集合,該集合描述IS數據集。您還需要考慮任何密鑰,可能在源組件中生成替代密鑰以跟蹤數據。

一旦您定義了集合中的所有列,那麼在C#/ VB.NET中編寫解析邏輯就很簡單了。一旦解析完畢,您只需將值分配到這些集合中即可。

Output0Buffer.AddRow(); 
    // use this to assign a value 
    Output0Buffer.MyColumn = parsedValue; 
    // Use this for handling a null value 
    Output0Buffer.MyColumn_IsNull = true; 

現在你可以運行包和分析的數據流向下流。

這聽起來像你有外鍵被滿足和代理值生成。如果是這樣,我會將大部分(如果不是全部)數據寫入各種登臺表中,然後通過重複查詢通過鏈接到數據流任務的執行SQL任務進行驗證和回填數據。

需要更多的細節?編輯你的問題,並提供一些你自己。我們很樂意提供建議和指導,但我們不在您的立方體中,並且不瞭解您的需求。

+0

我正在使用源組件作爲trnasform,並且我正在通過eachand每個stage.but我的腳本組件只是運行indefinetly。 – user1783579

+0

這裏是我的源代碼 – user1783579

+0

我如何在這裏上傳文件或圖片 – user1783579

相關問題