ارجو منكم مساعدتي في فهم وشرح ال code
Imports System.IO.Path
Partial Class Add_Identity_App
Inherits System.Web.UI.Page
Dim mycon As New SqlConnection(ConfigurationManager.ConnectionStrings("civil").ConnectionString)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim img_path As String = ""
If Not FileUpload1.PostedFile Is Nothing And FileUpload1.PostedFile.ContentLength > 0 Then
Dim Filename As String = GetFileName(FileUpload1.PostedFile.FileName)
Dim SaveLocation As String = Server.MapPath("~\personal_img") & "\" & Filename
img_path = "~\personal_img\" & Filename
FileUpload1.PostedFile.SaveAs(SaveLocation)
End If
Dim sqlcom As New SqlCommand("INSERT INTO Identity_App VALUES " _
& "(@App_no, @nid, @f_name, @s_name, @t_name, @l_name, @Birth_place, @Birth_date, @Gender," _
& "@Religion, @Mother_name, @Civil_registration, @Country, @city, @Brigade, @Zone, @Village," _
& "@Photo, @App_date, NULL, 1)", mycon)
With sqlcom.Parameters
.AddWithValue("@App_no", HDFappNo.Value)
.AddWithValue("@nid", txtNID.Text)
.AddWithValue("@f_name", txtFname.Text)
.AddWithValue("@s_name", txtSname.Text)
.AddWithValue("@t_name", txtTname.Text)
.AddWithValue("@l_name", txtLname.Text)
.AddWithValue("@Birth_place", txtBirthPlace.Text)
.AddWithValue("@Birth_date", RDPDob.SelectedDate)
.AddWithValue("@Gender", drpGender.SelectedItem.Text)
.AddWithValue("@Religion", DrpReligion.SelectedItem.Text)
.AddWithValue("@Mother_name", txtMothrerName.Text)
.AddWithValue("@Civil_registration", txtCivil_registration.Text)
.AddWithValue("@Country", txtCountry.Text)
.AddWithValue("@city", txtCity.Text)
.AddWithValue("@Brigade", txtBrigade.Text)
.AddWithValue("@Zone", txtZone.Text)
.AddWithValue("@Village", txtVillage.Text)
.AddWithValue("@Photo", img_path)
.AddWithValue("@App_date", Now.Date)
End With
mycon.Open()
Dim eff As Integer = sqlcom.ExecuteNonQuery
mycon.Close()
If eff > 0 Then
lblresult.Text = "تـم إضـافـة الـطـلب بنجاح"
txtBirthPlace.Text = Nothing
txtBrigade.Text = Nothing
txtCity.Text = Nothing
txtCivil_registration.Text = Nothing
txtCountry.Text = Nothing
txtFileName.Text = Nothing
txtFname.Text = Nothing
txtSname.Text = Nothing
txtTname.Text = Nothing
txtLname.Text = Nothing
txtMothrerName.Text = Nothing
txtNID.Text = Nothing
txtVillage.Text = Nothing
txtZone.Text = Nothing
End If
get_app_no()
Catch ex As Exception
End Try
End Sub
Sub get_app_no()
Dim sqlcom As New SqlCommand("select isnull(max(app_no),0) + 1 from Identity_App ", mycon)
mycon.Open()
HDFappNo.Value = sqlcom.ExecuteScalar
mycon.Close()
End Sub
Sub Del_Prev_Attach()
Dim sqlcom As New SqlCommand("Delete from attachments where app_no=@app_no and app_type=1", mycon)
sqlcom.Parameters.AddWithValue("@app_no", HDFappNo.Value)
mycon.Open()
sqlcom.ExecuteNonQuery()
mycon.Close()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.IsPostBack = False Then
get_app_no()
Del_Prev_Attach()
End If
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim file_path As String = ""
If Not FileUpload1.PostedFile Is Nothing And FileUpload2.PostedFile.ContentLength > 0 Then
Dim Filename As String = GetFileName(FileUpload2.PostedFile.FileName)
Dim SaveLocation As String = Server.MapPath("~\Attachment") & "\" & Filename
file_path = "~\Attachment\" & Filename
FileUpload1.PostedFile.SaveAs(SaveLocation)
End If
Dim sqlcom As New SqlCommand("insert into Attachments values(@file_name,@file,@app_no,1)", mycon)
sqlcom.Parameters.AddWithValue("@file_name", txtFileName.Text)
sqlcom.Parameters.AddWithValue("@file", file_path)
sqlcom.Parameters.AddWithValue("@app_no", HDFappNo.Value)
mycon.Open()
Dim eff As Integer = sqlcom.ExecuteNonQuery
mycon.Close()
If eff > 0 Then
txtFileName.Text = Nothing
GridView1.DataBind()
End If
Catch ex As Exception
lblresult.Text = ex.Message
End Try
End Sub
End Class