2013-12-10 73 views
0

我需要使用在我的存儲過程切換案例分配的變量,但我總是得到意想不到的結果。請幫助..任何答覆將是一個很大的help.thanks。使用開關案例分配變量

private void CheckMessage() 
     { 
      string chk = null; 
      ShortMessage l = new ShortMessage(); 
      string strCommand = "AT+CMGL=\"ALL\""; 
      objShortMessageCollection = objclsSMS.ReadSMS(this.port, strCommand); 
      foreach (ShortMessage msg in objShortMessageCollection) 
      { 

       l.Message = msg.Message; 
       string[] splt = l.Message.Split('#'); 
       for (int i = 0; i < splt.Length; i++) 
       { 
        string[] parts = splt[i].Split(':'); 
        char prefix = Convert.ToChar(parts[0]); 
        string value = parts[1]; 

        switch (prefix) 
        { 
         case 'T': 
          l.truck = value; 
          break; 
         case 'D': 
          l.driver = value; 
          break; 
         case 'R': 
          l.receiveby = value; 
          break; 
         case 'A': 
          l.arrivedate = value; 
          break; 
         case 'U': 
          l.unloaddate = value; 
          break; 
         case 'N': 
          l.deliverynote = value; 
          break; 
         case 'L': 
          l.deliverydate = value; 
          break; 
         case 'S': 
          l.deliverystatus = value; 
          break; 
         case 'M': 
          l.mac = value; 
          break; 
         case 'C': 
          l.msgcreatedate = value; 
          break; 
        } 

       } 
       chk = l.getINFO(l).Tables[0].Rows[0][0].ToString(); 

       if (chk == "1") 
       { 

        this.AutomaticReply(); 
        this.DeleteToSim(); 
       } 
       else 
       { 

        this.DeleteToSim(); 
       } 

       l = null; 
      } 


     } 
     #endregion 

這裏是我的存儲過程..

ALTER PROCEDURE [dbo].[Message_Check] 
    @truck nvarchar(20), 
    @driver nvarchar(20), 
    @deliverynote int 

AS 
    BEGIN 
     SELECT 1 FROM Truck trk, Driver drv, DeliveryNotes dnt 
          WHERE trk.Plate_Number = @truck 
          AND drv.DRIVER_ID = @driver 
          AND dnt.DNID = @deliverynote 
          AND dnt.Status = 'N' 
    END 
+0

什麼是 「意想不到的結果」 –

回答

0

一種可能性就是你要找的字符不是資本,或者你可能會得到一個前導空格。看看這樣的幫助:

char prefix = parts[0].Trim().ToUpper()[0]; 

如果仍然有問題,編輯您的原職,並添加的ShortMessage類的結構

1

您的查詢會給輸出1 .....總是

SELECT 1 FROM Truck trk, Driver drv, DeliveryNotes dnt 
          WHERE trk.Plate_Number = @truck 
          AND drv.DRIVER_ID = @driver 
          AND dnt.DNID = @deliverynote 
          AND dnt.Status = 'N' 

應該

SELECT Top 1 * FROM Truck trk, Driver drv, DeliveryNotes dnt 
          WHERE trk.Plate_Number = @truck 
          AND drv.DRIVER_ID = @driver 
          AND dnt.DNID = @deliverynote 
          AND dnt.Status = 'N' 
0

請通過檢查是值使用斷點和調試傳遞給存儲過程。 值可能有像「AA BB」的額外空間使用TrimEnd(' ');功能,修剪結束值&請解析正確其數據類型(Int , Double , DateTime etc)。該短信你正在閱讀和利用其他的東西。請檢查電話是Private/Public以便達到其存儲過程的值。

char prefix = Convert.ToChar(parts[0]); 

使用

parts[0]=parts[0].ToUpper(); 
char prefix = Convert.ToChar(parts[0]); 

不斷嘗試...