|  | 
	                
  
    |  |  
    | 
        
        จะแปลงโค้ดชุดนี้จาก VB.NET เป็น C# รบกวนผู้รู้ช่วยหน่อยค่ะ ด่วนมากค่ะ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | คือว่าจะให้ระบบที่พัฒนาขึ้นมาสามารถส่ง sms ได้ค่ะ ก็เลยสมัครpacketกับเว็บไซต์หนึ่ง แล้วได้ตัวอย่างโค้ดAPIที่เป็น .NETมาแบบนี้ค่ะ
 ตอนนี้ก็พยายามแปลงเป็นC#อยู่ แต่กลัวจะเสร็จไม่ทัน เพราะไม่เคยเขียนVB เลย
 ส่วนC# ก็เพิ่งหัดเล่นค่ะ รบกวนผู้รู้แนะนำด้วยค่ะ ด่วนมากค่ะ ต้องเสร็จภายในวันนี้
 
 ขอบคุณมากค่ะ
 Code (VB.NET)
 
 Imports System.IO	
Imports System.Net
Imports System.Net.WebRequest
Imports System.Net.WebResponse
Private Function SendSMS_txtLocal(ByVal Test As Boolean, _
ByVal iFrom As String, _
ByVal Message As String, _
ByVal SendTo As String, _
ByVal URL As String) As String
Const TransportURL As String = "http://www.inanosms.com/API_NANO_NAME_V2.ASP"
Const TransportUserName As String = "Register Username"
Const TransportPassword As String = "mypassword"
Const SMode As String = "E" ' ภาษาที่ใช้ส่ง
Dim strPost As String
strPost = "Username=" + TransportUserName _
+ "&Password=" + TransportPassword _
+ "&Text=" + Message _
+ "&Sname=" + iFrom _
+ "&SMSMode=" + SMode _
+ "&Phonenumber=" + SendTo
Dim request As WebRequest = WebRequest.Create(TransportURL)
request.Method = "POST"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(strPost) ' Create POST
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
' Get the response.
Dim response As WebResponse = request.GetResponse()
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
' Clean up the streams.
reader.Close()
dataStream.Close()
response.Close()
' Return result to calling function
If responseFromServer.Length > 0 Then
Return responseFromServer
Else
Return CType(response, HttpWebResponse).StatusDescription
End If
End Function
 
 
 
 Tag : .NET, Web (ASP.NET), VB.NET, C#
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2011-03-24 12:08:05 | By :
                          inoi | View :
                          1910 | Reply :
                          10 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (C#) 
 private string SendSMS_txtLocal(bool Test, string iFrom, string Message, string SendTo, string URL)
{
	const string TransportURL = "http://www.inanosms.com/API_NANO_NAME_V2.ASP";
	const string TransportUserName = "Register Username";
	const string TransportPassword = "mypassword";
	const string SMode = "E";
	// ภาษาที่ใช้ส่ง
	string strPost = null;
	strPost = "Username=" + TransportUserName + "&Password=" + TransportPassword + "&Text=" + Message + "&Sname=" + iFrom + "&SMSMode=" + SMode + "&Phonenumber=" + SendTo;
	WebRequest request = WebRequest.Create(TransportURL);
	request.Method = "POST";
	byte[] byteArray = Encoding.UTF8.GetBytes(strPost);
	// Create POST
	request.ContentType = "application/x-www-form-urlencoded";
	request.ContentLength = byteArray.Length;
	Stream dataStream = request.GetRequestStream();
	dataStream.Write(byteArray, 0, byteArray.Length);
	dataStream.Close();
	// Get the response.
	WebResponse response = request.GetResponse();
	dataStream = response.GetResponseStream();
	StreamReader reader = new StreamReader(dataStream);
	string responseFromServer = reader.ReadToEnd();
	// Clean up the streams.
	reader.Close();
	dataStream.Close();
	response.Close();
	// Return result to calling function
	if (responseFromServer.Length > 0) {
		return responseFromServer;
	} else {
		return ((HttpWebResponse)response).StatusDescription;
	}
}
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-03-24 12:57:25 | By :
                            webmaster |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ขอบคุณมากค่ะ 
 แต่ว่ามัน error ตรงบรรทัดนี้ค่ะ
 Code (C#)
 
 byte[] byteArray = Encoding.UTF8.GetBytes(strPost);
 
 ตรง Encoding ค่ะ ไม่ทาบว่าหนูต้องทำอะไรเพิ่มเติมหรือเปล่าค่ะ
 
  
 
 ขอบคุณค่ะ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-03-24 13:29:08 | By :
                            inoi |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (C#) 
 byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(strPost);
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-03-24 13:56:56 | By :
                            สาวเอ๋อ เอ๋อเหรอ เอ๋อมากมาย |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | พอดี Convert ผ่านโปรแกรมครับ  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-03-24 14:27:30 | By :
                            webmaster |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ขอบคุณค่ะ ขอบคุณพี่ทั้งสองคนมากๆๆค่ะ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-03-24 15:17:54 | By :
                            inoi |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | DialogResultWindows.Forms.DialogResult.Yes 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-09-21 21:40:18 | By :
                            เเปลงเปน C# จะเปนยังไงค่ะ |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ถ้าจะเเปลงเป็น c# จะเป็นอะไรค่ะ  Windows.Forms.DialogResult.Yes 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-09-21 21:41:56 | By :
                            kukkai |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ช่วยแปลงโค้ด vb เป็น C# หน่อยได้ไหมค่ะ 
 โค้ด VB ค่ะ
 
 
 Dim newID As Integer = CInt(dr.Item("oid"))
 newID += 1
 txtid.Text = "PF" & newID.ToString("00000")
 cbtype.Focus()
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-10-30 22:21:22 | By :
                            maya |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (C#) 
 int newID = Convert.ToInt32(dr.Item("oid"));
newID += 1;
txtid.Text = "PF" + newID.ToString("00000");
cbtype.Focus();
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-10-30 22:43:23 | By :
                            mr.win |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |