الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

هدية: كلاس للتعامل مع الراميترات مع الكود و الشرح

مغلق
بدأه ابوأنس في 14 أغسطس 2005 · 1 رد · 634 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله

هذا كلاس بسيط يساعدك على بناء البراميترات في الروابط بسهولة فإذا كنت تريد إضافة باراميتر الى الرابط عادة تقوم بالتالي:

Dim url as string ="http://www.arabteam2000.com"
url+="?ParameterName1=" + ParameterValue1
url+="&ParameterName2="+ ParameterValue2
  .
  .
  .
url+="&ParameterNameN="+ ParameterValueN

Response.Redirct(url)

هذه الاضافة فقط واذا أردت أن تحذف أو تعدل فأدعو الله أن يعينك

أما الآن فما عليك سوى أن

Dim urlParmObj as new UrlParameters("http://www.arabteam2000")
With urlParmObj
     .AddParameter("ParameterName1", ParameterValue1)  'إضافة
     .AddParameter("ParameterName1", ParameterValue1)   'إضافة
     .
     .
     .
     .AddParameter("ParameterNameN", ParameterValueN)   'إضافة

     .UpdateParameter("upw", "upw", "1")    'تعديل
     .RemoveParameter("upw")  'حذف
     
      Response.Redirct( .url ) 'Redirecting
End With

بكل سهولة والكود موجود والمثال مرفق وأي سؤال أنا حاضر ان شاء الله

Public Class UrlParamerters
    Public Sub New(ByVal Url_Address As String)
        'throwing a fromat Exception if the url Address is Empty
        If Url_Address.Trim = "" Then
            Throw New FormatException("Empty Url Address")
            Exit Sub
        End If
        'adding a "?" for accepting new parameters
        Url_Address = Url_Address.ToLower() + "?"
        _Url = Url_Address
    End Sub
    'to set and get the Url after adding the parameters to it
    Private _Url As String
    Public Property Url() As String
        Get
            Return _Url
        End Get
        Set(ByVal Value As String)
            Url = Value
        End Set
    End Property
    'to add a parameter to the url address
    Public Sub AddParameter(ByVal Key As String, ByVal value As String)

        If _Url.IndexOf("?") = _Url.Length - 1 Then
            'if it is the first parameter
            _Url += Key + "=" + value
        Else
            'if there are parameters
            _Url += "&" + Key + "=" + value
        End If
    End Sub
    Public Sub RemoveParameter(ByVal Key As String)
        Key = Key.ToLower()
        _Url = _Url.ToLower()
        'finding the key index in the url address
        Dim KeyIndex As Integer = _Url.IndexOf(Key)
        Dim DeleteEndIndex As Integer
        'if the key not found then exit sub
        If KeyIndex = -1 Then Exit Sub
        'finding  the & to know where we will stop deleting 
        DeleteEndIndex = _Url.IndexOf("&", KeyIndex)
        'if the & not found it mean that the key is the last key
        ' in the url address
        If DeleteEndIndex = -1 Then
            DeleteEndIndex = _Url.Length
            KeyIndex -= 1
        Else
            'we added 1 to take out the &
            DeleteEndIndex += 1
        End If
        'removing the old key
        _Url = _Url.Remove(KeyIndex, DeleteEndIndex - KeyIndex)
    End Sub
    Public Sub UpdateParameter(ByVal OldKey As String, ByVal NewKey As String, ByVal value As String)
        RemoveParameter(OldKey)
        AddParameter(NewKey, value)
    End Sub
End Class

UrlParamerters.rar

#2

مشكور اخوي على هذا الكلاس ، وفعلاً راح يختصر شغل كثير

هذا الموضوع مغلق.

مواضيع مشابهة