Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 20th, 2012  |  syntax: None  |  size: 5.65 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Session dissappears unexpectedly
  2. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click
  3.         If Not stats > 0 Then
  4.             If Session("change") IsNot Nothing Then
  5.                 Dim dc As New DataClassesDataContext
  6.                 Dim getP = From prod In dc.Products _
  7.                            Where prod.ProductID = CInt(Session("change")) _
  8.                            Select prod
  9.  
  10.                 If getP.Any Then
  11.                     If rdbSell.Checked = True Then
  12.                         getP.FirstOrDefault.BuySell = True
  13.                     Else
  14.                         getP.FirstOrDefault.BuySell = False
  15.                     End If
  16.                     If ddlSubSubcat.SelectedValue IsNot String.Empty Then
  17.                         getP.FirstOrDefault.CategoryID = CInt(ddlSubSubcat.SelectedValue)
  18.                     Else
  19.                         getP.FirstOrDefault.CategoryID = CInt(ddlSubCat.SelectedValue)
  20.                     End If
  21.  
  22.                     getP.FirstOrDefault.Content = txtContent.Text.Replace(Environment.NewLine, "<br />")
  23.                     getP.FirstOrDefault.CountyID = CInt(ddlCounty.SelectedValue)
  24.                     getP.FirstOrDefault.E_mail = txtEmail.Text
  25.                     getP.FirstOrDefault.Date = DateTime.Now
  26.                     getP.FirstOrDefault.Active = 0
  27.                     getP.FirstOrDefault.Alias = txtAlias.Text.Replace("'", "''")
  28.                     getP.FirstOrDefault.ShowEmail = 0
  29.                     Dim PreID As Integer = getP.FirstOrDefault.ProductID
  30.                     If chkShowEmail.Checked = True Then
  31.                         getP.FirstOrDefault.ShowEmail = 1
  32.                     Else
  33.                         getP.FirstOrDefault.ShowEmail = 0
  34.                     End If
  35.                     If chkShowPhone.Checked = True Then
  36.                         getP.FirstOrDefault.ShowPhone = 1
  37.                     Else
  38.                         getP.FirstOrDefault.ShowPhone = 0
  39.                     End If
  40.                     getP.FirstOrDefault.Headline = txtHeadline.Text
  41.                     getP.FirstOrDefault.Password = txtPassword.Text
  42.                     getP.FirstOrDefault.Phone = txtPhone.Text
  43.                     getP.FirstOrDefault.Price = txtPrice.Text
  44.  
  45.                     If chkUnknown.Checked = True Then
  46.                         getP.FirstOrDefault.YearModel = String.Empty
  47.                     Else
  48.                         getP.FirstOrDefault.YearModel = ddlYear.SelectedValue
  49.                     End If
  50.  
  51.                     For Each item In libPictures.Items
  52.                         Dim i As String = item.ToString
  53.                         Dim imagecheck = From img In dc.Pictures _
  54.                                          Where img.Name = i And img.ProductID = CInt(Session("change")) _
  55.                                          Select img
  56.  
  57.                         If imagecheck.Any Then
  58.                         Else
  59.                             Dim img As New Picture
  60.                             img.Name = item.ToString
  61.  
  62.                             img.ProductID = CInt(Session("change"))
  63.                             dc.Pictures.InsertOnSubmit(img)
  64.                             dc.SubmitChanges()
  65.                         End If
  66.                     Next
  67.  
  68.                     dc.SubmitChanges()
  69.  
  70.                     Session.Remove("change")
  71.                     Response.Redirect("~/precheck.aspx?id=" + PreID.ToString)
  72.                 End If
  73.             Else
  74.                 Dim dc As New DataClassesDataContext
  75.                 Dim prod As New Product
  76.                 If rdbSell.Checked = True Then
  77.                     prod.BuySell = True
  78.                 Else
  79.                     prod.BuySell = False
  80.                 End If
  81.                 If ddlSubSubcat.DataValueField IsNot String.Empty Then
  82.                     prod.CategoryID = CInt(ddlSubSubcat.SelectedValue)
  83.                 Else
  84.                     prod.CategoryID = CInt(ddlSubCat.SelectedValue)
  85.                 End If
  86.  
  87.                 prod.Content = txtContent.Text.Replace(Environment.NewLine, "<br />")
  88.                 prod.CountyID = CInt(ddlCounty.SelectedValue)
  89.                 prod.E_mail = txtEmail.Text
  90.                 prod.Date = DateTime.Now
  91.                 prod.Active = 0
  92.                 prod.Alias = txtAlias.Text.Replace("'", "''")
  93.                 prod.ShowEmail = 0
  94.                 If chkShowEmail.Checked = True Then
  95.                     prod.ShowEmail = 1
  96.                 Else
  97.                     prod.ShowEmail = 0
  98.                 End If
  99.                 If chkShowPhone.Checked = True Then
  100.                     prod.ShowPhone = 1
  101.                 Else
  102.                     prod.ShowPhone = 0
  103.                 End If
  104.                 prod.Headline = txtHeadline.Text
  105.                 prod.Password = txtPassword.Text
  106.                 prod.Phone = txtPhone.Text
  107.                 prod.Price = txtPrice.Text
  108.  
  109.                 If chkUnknown.Checked = True Then
  110.                     prod.YearModel = String.Empty
  111.                 Else
  112.                     prod.YearModel = ddlYear.SelectedValue
  113.                 End If
  114.  
  115.                 dc.Products.InsertOnSubmit(prod)
  116.                 dc.SubmitChanges()
  117.                 Dim PreID As Integer = prod.ProductID
  118.  
  119.                 For Each item In libPictures.Items
  120.                     Dim img As New Picture
  121.                     img.Name = item.ToString
  122.  
  123.                     img.ProductID = prod.ProductID
  124.                     dc.Pictures.InsertOnSubmit(img)
  125.                     dc.SubmitChanges()
  126.                 Next
  127.                 Session.Remove("change")
  128.                 Response.Redirect("./precheck.aspx?id=" + PreID.ToString, False)
  129.             End If
  130.         End If
  131.         stats = 0
  132.         'Catch ex As Exception
  133.         'End Try
  134.  
  135.     End Sub