17-09-12, 02:07 PM
مثال بسيط جدا
الاكواد
صفحة الماستر بيج
رمز برمجي:
الصفحة المحمية وهي هنا default2.aspx
رمز برمجي:
صفحة الدخول Login.aspx
رمز برمجي:
صفحة اضافة عضوية جديدة addme.aspx
رمز برمجي:
صفحة الخروج Logout.aspx
رمز برمجي:
الاكواد
صفحة الماستر بيج
رمز برمجي:
كود :
Imports System.Data.OleDb
Imports System.Web.SessionState
Partial Class MasterPage
Inherits System.Web.UI.MasterPage
Dim constr As String = "provider=microsoft.ace.oledb.12.0 ; data source=|datadirectory|\db.accdb"
Dim con As New OleDbConnection(constr)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("name") = "" Then
l.Text = "اهلا وسهلا بك يازائر كم يسعدنا تسجيلك معنا"
HyperLink5.Visible = False
HyperLink4.Visible = True
HyperLink3.Visible = True
Else
HyperLink3.Visible = False
HyperLink4.Visible = False
HyperLink5.Visible = True
l.Text = "اهلا بعودتك يا :" & Session("name")
End If
End Sub
End Class
الصفحة المحمية وهي هنا default2.aspx
رمز برمجي:
كود :
Imports System.Data.OleDb
Imports System.Web.SessionState
Partial Class Default2
Inherits System.Web.UI.Page
Dim constr As String = "provider=microsoft.ace.oledb.12.0 ; data source=|datadirectory|\db.accdb"
Dim con As New OleDbConnection(constr)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Title = "معرض الصور"
If Session("name") = "" Then
Response.Redirect("~\login.aspx")
End If
Label1.Text = "اهلا وسهلا بك يا :" & Session("name")
End Sub
End Class
رمز برمجي:
كود :
Imports System.Data.OleDb
Imports System.Web.SessionState
Partial Class Default3
Inherits System.Web.UI.Page
Dim constr As String = "provider=microsoft.ace.oledb.12.0 ; data source=|datadirectory|\db.accdb"
Dim con As New OleDbConnection(constr)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Title = "تسجيل الدخول"
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text.Trim = "" Or TextBox2.Text.Trim = "" Then
l.Text = "فضلا عبيء الحقول بقيم مقبولة!"
l.ForeColor = Drawing.Color.Red
l.Font.Bold = True
Else
Dim cm As New OleDbCommand("select * from tb where tname='" & TextBox1.Text & "'and tpass='" & Val(TextBox2.Text) & "'", con)
If con.State = Data.ConnectionState.Open Then con.Close()
con.Open()
Dim dr As Data.OleDb.OleDbDataReader = cm.ExecuteReader
If dr.Read Then
Session("name") = TextBox1.Text
Response.Redirect("~\default.aspx")
Else
l.Text = "عفوا يوجد خطا اما باسم المستخدم او كلمة المرور"
l.ForeColor = Drawing.Color.Red
End If
If con.State = Data.ConnectionState.Open Then con.Close()
End If
End Sub
End Class
رمز برمجي:
كود :
Imports System.Data.OleDb
Imports System.Web.SessionState
Imports System.Data
Partial Class addme
Inherits System.Web.UI.Page
Dim constr As String = "provider=microsoft.ace.oledb.12.0 ; data source=|datadirectory|\db.accdb"
Dim con As New OleDbConnection(constr)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Title = "تسجيل جديد"
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text.Trim = "" Or TextBox2.Text.Trim = "" Then
l.Text = "فضلا عبيء الحقول بقيم مقبولة!"
l.ForeColor = Drawing.Color.Red
l.Font.Bold = True
Else
Dim ds As New DataSet
Dim da As New OleDbDataAdapter("select * from tb", con)
Dim cm As New OleDbCommandBuilder(da)
da.Fill(ds, "tb")
Dim dr As DataRow = ds.Tables("tb").NewRow
dr.Item("tname") = TextBox1.Text
dr.Item("tpass") = TextBox2.Text
ds.Tables("tb").Rows.Add(dr)
da.Update(ds, "tb")
Response.Redirect("~\default.aspx")
End If
End Sub
End Class
رمز برمجي:
كود :
Imports System.Web.SessionState
Partial Class Default3
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session("name") = ""
Response.Redirect("~\default.aspx")
End Sub
End Class