(NET) NET (2013)

Manage site with huge number of page (content, accounting, testing)



In current project I have a challenge - about one thousand pages, at the beginning of work I have 689 pages on right part and I must to increase number of pages during my work. For that page number is use to Visual Studio project explorer is fully impossible, because even searching page in VS Project explorer for opening is a big challenge.

Therefore I have create my own so-called Project Explorer, but enumeration of pages is only one small function of this program. it allow:

Function of this program was expanding in some years and below you can see one of the beginning version of this my program.


1. Database and ORM

This program I have write in combined style - simple ADO.NET and Linq-to-SQL, this is main table to manage pages.


   1:  CREATE TABLE [dbo].[Description](
   2:      [i] [int] IDENTITY(1,1) Not NULL,
   3:      [URL] [nvarchar](250) NULL,
   4:      [RedirectFrom] [nvarchar](250) NULL,
   5:      [H1] [nvarchar](1000) NULL,
   6:      [TXT] [nvarchar](4000) NULL,
   7:      [PageTitle] [nvarchar](250) NULL,
   8:      [PageDescription] [nvarchar](500) NULL,
   9:      [Menu1name] [nvarchar](250) NULL,
  10:      [Menu1order] [nvarchar](250) NULL,
  11:      [Bind1] [nvarchar](250) NULL,
  12:      [Bind2] [nvarchar](250) NULL,
  13:   CONSTRAINT [PK_Description] PRIMARY KEY CLUSTERED 
  14:  (
  15:      [i] ASC
  16:  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  17:  ) ON [PRIMARY]
  18:   
  19:  GO


2. Linq-to-SQL extension with clearing cache

   1:  Module LinqToSqlExtension4
   2:      ''' <summary>
   3:      ''' Return Linq-to-SQL context
   4:      ''' </summary>
   5:      ''' <typeparam name="T"></typeparam>
   6:      ''' <param name="value"></param>
   7:      ''' <param name="ClearCache">True, if need clear cache</param>
   8:      ''' <returns>Linq-to-SQL context</returns>
   9:      <System.Runtime.CompilerServices.Extension()> _
  10:      Public Function GetContext(Of T As System.Data.Linq.DataContext)(ByRef value As T, ByVal ClearCache As Boolean) As T
  11:          If value IsNot Nothing And Not ClearCache Then
  12:              Return value
  13:          Else
  14:              'create new
  15:              Dim ObjConstructors() As Reflection.ConstructorInfo = GetType(T).GetConstructors
  16:              'шукаємо CTOR без параметрів
  17:              For Each One In ObjConstructors
  18:                  If One.GetParameters.Count = 0 Then
  19:                      value = ObjConstructors(0).Invoke(Nothing)
  20:                      Return value
  21:                  End If
  22:              Next
  23:          End If
  24:      End Function
  25:  End Module

3. StringValue class to bind GridView to datasource

   1:  Public Class StringValue
   2:      Private _value As String
   3:      Public Sub New(ByVal s As String)
   4:          _value = s
   5:      End Sub
   6:   
   7:      Public Property Value As String
   8:          Get
   9:              Return _value
  10:          End Get
  11:          Set(ByVal value As String)
  12:              _value = value
  13:          End Set
  14:      End Property
  15:  End Class

4. Extension function to support add new row to GridView

This is my extension for edition GraiView.


   1:  Imports System.Runtime.CompilerServices
   2:   
   3:  Module Extensions4
   4:      <Extension()>
   5:      Sub EditEndRow(Grid As DataGridView)
   6:          Grid.ClearSelection()
   7:          Grid.Rows(Grid.Rows.Count - 1).Selected = True
   8:          Grid.CurrentCell = Grid(0, Grid.Rows.Count - 1)
   9:          Grid.CurrentCell.Selected = True
  10:          Grid.FirstDisplayedScrollingRowIndex = Grid.Rows.Count - 1
  11:          Grid.Focus()
  12:          Grid.BeginEdit(False)
  13:      End Sub
  14:  End Module

5. Main form - editable GridView

This is names of variables in main form.



And this is code related to editable GridView.


   1:  Imports System.ComponentModel
   2:   
   3:  Public Class StartForm
   4:   
   5:      Dim FF As Firefox
   6:      Dim db1 As dbDataContext
   7:      Dim Rows As List(Of Description)
   8:      Public Property DataSource As BindingList(Of StringValue)
   9:      Dim Reg As Registry
  10:      Dim CurRow As List(Of Description)
  11:   
  12:      Private Sub StartForm_Load(sender As Object, e As EventArgs) Handles Me.Load
  13:          Text &= " (" & My.Application.Info.Version.ToString & ")"
  14:          DataGridView_Refresh()
  15:          FF = New Firefox
  16:          Reg = New Registry("BraggartSupport")
  17:      End Sub
  18:   
 ....   
 225:  #Region "DataGridView1"
 226:   
 227:      Sub DataGridView_Refresh()
 228:          db1.GetContext(True)
 229:          Rows = (From X In db1.Descriptions Select X Order By X.URL).ToList
 230:          DataSource = New BindingList(Of StringValue)
 231:          Rows.ForEach(Sub(Y) DataSource.Add(New StringValue(Y.URL)))
 232:          DataGridView1.DataSource = Nothing
 233:          DataGridView1.Rows.Clear()
 234:          DataGridView1.DataSource = DataSource
 235:      End Sub
 236:   
 237:      Private Sub DataGridView1_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) Handles DataGridView1.DataBindingComplete
 238:          For i As Integer = 0 To Rows.Count - 1
 239:              DataGridView1.Rows(i).Cells(0).ToolTipText = Rows(i).i
 240:          Next
 241:      End Sub
 242:   
 243:      Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
 244:          If e.ColumnIndex = 0 Then
 245:              Dim senderGrid = DirectCast(sender, DataGridView)
 246:              Dim CurCell As DataGridViewCell = senderGrid(e.ColumnIndex, e.RowIndex)
 247:              Dim RedStyle = New DataGridViewCellStyle()
 248:              Dim Red As Integer = 200
 249:              RedStyle.BackColor = Color.FromArgb(Red, 255, 255)
 250:              If String.IsNullOrEmpty(CurCell.ToolTipText) Then
 251:                  CurCell.ToolTipText = 0 'new row
 252:                  CurCell.Style = RedStyle
 253:              End If
 254:              Dim CurRow = Rows.Where(Function(X) X.i = CInt(CurCell.ToolTipText)).FirstOrDefault
 255:              If CurRow IsNot Nothing Then
 256:                  If CurRow.URL <> CurCell.Value Then
 257:                      CurCell.Style = RedStyle 'row edited
 258:                  End If
 259:              End If
 260:          End If
 261:      End Sub
 262:   
 263:      Private Sub DataGridView1_RowStateChanged(sender As Object, e As DataGridViewRowStateChangedEventArgs) Handles DataGridView1.RowStateChanged
 264:          GridStatusLabel1.Text = e.StateChanged.ToString.ToLower & "(" & e.Row.Index & ")"
 265:      End Sub
 266:   
 267:      Private Sub DataGridView1_RowEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
 268:          GridStatusLabel2.Text = "rowenter" & "(" & e.RowIndex & ")"
 269:      End Sub
 270:   
 271:      Private Sub DataGridView1_RowLeave(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.RowLeave
 272:          GridStatusLabel1.Text = "rowleave" & "(" & e.RowIndex & ")"
 273:      End Sub
 274:   
 275:      Private Sub SaveToolStripButton_Click(sender As Object, e As EventArgs) Handles SaveToolStripButton.Click
 276:          Dim UpdateTxtResult As New Text.StringBuilder
 277:          Dim InsertTxtResult As New Text.StringBuilder
 278:          For DataSourceRowNum As Integer = 0 To DataSource.Count - 1
 279:              If DataSourceRowNum <= Rows.Count - 1 Then
 280:                  If DataSource(DataSourceRowNum).Value <> Rows(DataSourceRowNum).URL Then
 281:                      UpdateTxtResult.AppendLine(Rows(DataSourceRowNum).URL & "=>" & DataSource(DataSourceRowNum).Value)
 282:                  End If
 283:              End If
 284:              If CInt(DataGridView1.Rows(DataSourceRowNum).Cells(0).ToolTipText = 0) Then
 285:                  If Not String.IsNullOrEmpty(DataSource(DataSourceRowNum).Value) Then
 286:                      InsertTxtResult.AppendLine(DataSource(DataSourceRowNum).Value)
 287:                  End If
 288:              End If
 289:          Next
 290:          Dim UserMessage As String = ""
 291:          If UpdateTxtResult.Length > 0 And InsertTxtResult.Length = 0 Then
 292:              UserMessage = "Update URL ?" & vbCrLf & UpdateTxtResult.ToString
 293:          ElseIf UpdateTxtResult.Length = 0 And InsertTxtResult.Length > 0 Then
 294:              UserMessage = "Add new URL ?" & vbCrLf & InsertTxtResult.ToString
 295:          ElseIf UpdateTxtResult.Length > 0 And InsertTxtResult.Length > 0 Then
 296:              UserMessage = "Update URL ?" & vbCrLf & UpdateTxtResult.ToString & vbCrLf & vbCrLf & "and" & vbCrLf & "Add new URL ?" & vbCrLf & InsertTxtResult.ToString
 297:          ElseIf UpdateTxtResult.Length = 0 And InsertTxtResult.Length = 0 Then
 298:              AutoClosingMessageBox.Show("Nothing URL to save")
 299:              Exit Sub
 300:          End If
 301:          If MessageBox.Show(UserMessage, "Save changing", MessageBoxButtons.YesNo) = DialogResult.Yes Then
 302:              For DataSourceRowNum As Integer = 0 To DataSource.Count - 1
 303:                  If DataSourceRowNum <= Rows.Count - 1 Then
 304:                      If DataSourceRowNum <= Rows.Count - 1 Then
 305:                          If Not String.IsNullOrEmpty(DataSource(DataSourceRowNum).Value) Then
 306:                              Dim CurCell As DataGridViewCell = DataGridView1.Rows(DataSourceRowNum).Cells(0)
 307:                              Dim CurRow = db1.Descriptions.Where(Function(X) X.i = CInt(CurCell.ToolTipText)).FirstOrDefault
 308:                              CurRow.URL = DataGridView1.Rows(DataSourceRowNum).Cells(0).Value
 309:                              db1.SubmitChanges()
 310:                          End If
 311:                      End If
 312:                  End If
 313:                  If CInt(DataGridView1.Rows(DataSourceRowNum).Cells(0).ToolTipText = 0) Then
 314:                      If Not String.IsNullOrEmpty(DataSource(DataSourceRowNum).Value) Then
 315:                          db1.Descriptions.InsertOnSubmit(New Description With {.URL = DataGridView1.Rows(DataSourceRowNum).Cells(0).Value})
 316:                          db1.SubmitChanges()
 317:                      End If
 318:                  End If
 319:              Next
 320:          End If
 321:          DataGridView_Refresh()
 322:      End Sub
 323:   
 324:      Private Sub DataGridView1_SelectionChanged(sender As Object, e As EventArgs) Handles DataGridView1.SelectionChanged
 325:          If DataGridView1.SelectedRows IsNot Nothing Then
 326:              If DataGridView1.SelectedRows.Count > 0 Then
 327:                  StatusLabel.Text = DataGridView1.SelectedRows(0).Cells(0).Value
 328:              Else
 329:                  StatusLabel.Text = ""
 330:              End If
 331:          End If
 332:      End Sub
 333:   
 334:      Private Sub AddToolStripButton_Click(sender As Object, e As EventArgs) Handles AddToolStripButton.Click
 335:          DataSource.Add(New StringValue(""))
 336:          DataGridView1.EditEndRow
 337:          'open for entering new - next event CellFormatting
 338:      End Sub
 339:   
 340:      Private Sub RemoveToolStripButton_Click(sender As Object, e As EventArgs) Handles RemoveToolStripButton.Click
 341:          If DataGridView1.SelectedRows.Count > 0 Then
 342:              Dim CurCell As DataGridViewCell = DataGridView1.Rows(DataGridView1.SelectedRows(0).Index).Cells(0)
 343:              If MessageBox.Show("Delete URL ?" & vbCrLf & CurCell.Value, "Save changing", MessageBoxButtons.YesNo) = DialogResult.Yes Then
 344:                  Dim CurRow = db1.Descriptions.Where(Function(X) X.i = CInt(CurCell.ToolTipText)).FirstOrDefault
 345:                  If CurRow IsNot Nothing Then
 346:                      db1.Descriptions.DeleteOnSubmit(CurRow)
 347:                      db1.SubmitChanges()
 348:                  Else
 349:                      AutoClosingMessageBox.Show(CurCell.Value & vbCrLf & "nothing in database")
 350:                  End If
 351:              End If
 352:          End If
 353:          DataGridView_Refresh()
 354:      End Sub
 355:   
 356:      Private Sub UpToolStripButton_Click(sender As Object, e As EventArgs) Handles UpToolStripButton.Click
 357:          If DataGridView1.SelectedRows IsNot Nothing Then
 358:              If DataGridView1.SelectedRows.Count > 0 Then
 359:                  Dim CurIndex As Integer = DataGridView1.SelectedRows(0).Index
 360:                  If CurIndex > 0 Then
 361:                      DataGridView1.ClearSelection()
 362:                      DataGridView1.Rows(CurIndex - 1).Selected = True
 363:                  End If
 364:              End If
 365:          End If
 366:      End Sub
 367:   
 368:      Private Sub DownToolStripButton_Click(sender As Object, e As EventArgs) Handles DownToolStripButton.Click
 369:          If DataGridView1.SelectedRows IsNot Nothing Then
 370:              If DataGridView1.SelectedRows.Count > 0 Then
 371:                  Dim CurIndex As Integer = DataGridView1.SelectedRows(0).Index
 372:                  If CurIndex < DataGridView1.Rows.Count - 1 Then
 373:                      DataGridView1.ClearSelection()
 374:                      DataGridView1.Rows(CurIndex + 1).Selected = True
 375:                  End If
 376:              End If
 377:          End If
 378:      End Sub
 379:   
 380:   
 381:  #End Region
 ....   

6. Interaction with Visual Studio

I have created simple interaction with Visual Studio by push to clipboard similar command.



7. Interaction with Browser

I interact with browser by this class Small .Net Wrapper Around Firefox

8. Serialize Table to CSV

I use this my old module Serialize Table to CSV

8. SQL procedures to create

In this beginning version I don't use automatically create Web.sitemap and Sitemap.xml, but common template to create both one is look as this:

   1:  ALTER procedure [dbo].[CreateSiteMapForAll]
   2:   
   3:  as
   4:  Create TABLE [dbo].[#SITEMAP](
   5:  [i] [int] IDENTITY(1,1) NOT NULL,
   6:  [TXT] [nvarchar](500) NULL
   7:  ) ON [PRIMARY];
   8:  SET NOCOUNT ON;
   9:   
  10:  insert #SITEMAP (TXT) VALUES ( '<?xml version="1.0" encoding="UTF-8"?>')
  11:  insert #SITEMAP (TXT) VALUES ( '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
  12:  insert #SITEMAP (TXT) select '<url><loc>//www.vb-net.com/' + Page + '</loc></url>' from Topic order by i desc
  13:  insert #SITEMAP (TXT) VALUES ('</urlset>')
  14:   
  15:  select * from #SITEMAP order by i

And this is view of both of its.

10. Function in main form

 ....   
  19:      Private Sub RefreshToolStripButton_Click(sender As Object, e As EventArgs) Handles RefreshToolStripButton.Click
  20:          DataGridView_Refresh()
  21:      End Sub
  22:   
  23:      Function GetDumpFileName() As String
  24:          Dim LocalTmpPath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
  25:          Dim TempAppDirectory As String = IO.Path.Combine(LocalTmpPath, Application.ProductName)
  26:          If Not My.Computer.FileSystem.DirectoryExists(TempAppDirectory) Then
  27:              My.Computer.FileSystem.CreateDirectory(TempAppDirectory)
  28:          End If
  29:          Return IO.Path.Combine(TempAppDirectory, "BraggartSupport.csv")
  30:      End Function
  31:   
  32:      Private Sub DownloadToolStripButton_Click(sender As Object, e As EventArgs) Handles DownloadToolStripButton.Click
  33:          Try
  34:              Dim DumpFileName As String = GetDumpFileName()
  35:              Dim CN As New SqlClient.SqlConnection(My.Settings.BrgUaConnectionString.ToString)
  36:              CN.Open()
  37:              DBDumper.DumpTableToFile(CN, "Description", DumpFileName)
  38:              Process.Start("explorer.exe", DumpFileName)
  39:          Catch ex As Exception
  40:              MsgBox(ex.Message)
  41:          End Try
  42:      End Sub
  43:   
  44:      Private Sub HelpToolStripButton_Click(sender As Object, e As EventArgs) Handles HelpToolStripButton.Click
  45:          Dim X As New HelpForm
  46:          X.ShowDialog()
  47:      End Sub
  48:   
  49:      Private Sub FFopenToolStripButton_Click(sender As Object, e As EventArgs) Handles FFopenToolStripButton.Click
  50:          Dim URL As String
  51:          Dim SiteDomain As String = Reg.GetValue(Of String)("SiteDomain")
  52:          If StatusLabel.Text = "/" Then
  53:              URL = SiteDomain & StatusLabel.Text
  54:          Else
  55:              URL = SiteDomain & StatusLabel.Text & ".aspx"
  56:          End If
  57:          FF.OpenFirefoxInNewTab(URL)
  58:      End Sub
  59:   
  60:      Private Sub FFopenLocalToolStripButton_Click(sender As Object, e As EventArgs) Handles FFopenLocalToolStripButton.Click
  61:          Dim URL As String
  62:          Dim LocalURL As String = Reg.GetValue(Of String)("LocalURL")
  63:          If StatusLabel.Text = "/" Then
  64:              URL = LocalURL & StatusLabel.Text
  65:          Else
  66:              URL = LocalURL & StatusLabel.Text & ".aspx"
  67:          End If
  68:          FF.OpenFirefoxInNewTab(URL)
  69:      End Sub
  70:   
  71:      Private Sub StatusLabel_TextChanged(sender As Object, e As EventArgs) Handles StatusLabel.TextChanged
  72:          If Rows IsNot Nothing Then
  73:              CurRow = (From X In Rows Select X Where X.URL = StatusLabel.Text).ToList
  74:              If CurRow.Count > 0 Then
  75:                  RedirectFromTextBox.Text = CurRow(0).RedirectFrom
  76:                  H1TextBox.Text = CurRow(0).H1
  77:                  TXTTextBox.Text = CurRow(0).TXT
  78:                  PageTitleTextBox.Text = CurRow(0).PageTitle
  79:                  PageDescriptionTextBox.Text = CurRow(0).PageDescription
  80:                  Bind1TextBox.Text = CurRow(0).Bind1
  81:                  Bind2TextBox.Text = CurRow(0).Bind2
  82:                  MenuNameTextBox.Text = CurRow(0).Menu1name
  83:                  MenuOrderNumericUpDown.Text = CurRow(0).Menu1order
  84:                  If PopUpForm_Instance IsNot Nothing Then
  85:                      PopUpForm.SetData(CurRow(0).Menu1name, GetOrderedMenu(), StatusLabel.Text)
  86:                      PopUpForm.Refresh()
  87:                      PopUpForm.BringToFront()
  88:                      PopUpForm.Activate()
  89:                  End If
  90:              End If
  91:          End If
  92:      End Sub
  93:   
  94:      Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
  95:          If StatusLabel.Text.Trim <> "" Then
  96:              Try
  97:                  Dim CurDbRow As List(Of Description) = (From X In db1.Descriptions Select X Where X.URL = StatusLabel.Text).ToList
  98:                  If CurDbRow.Count > 0 Then
  99:                      If Not String.IsNullOrEmpty(RedirectFromTextBox.Text.Trim) Then
 100:                          CurDbRow(0).RedirectFrom = RedirectFromTextBox.Text.Trim
 101:                      Else
 102:                          CurDbRow(0).RedirectFrom = Nothing
 103:                      End If
 104:                      If Not String.IsNullOrEmpty(H1TextBox.Text.Trim) Then
 105:                          CurDbRow(0).H1 = H1TextBox.Text.Trim
 106:                      Else
 107:                          CurDbRow(0).H1 = Nothing
 108:                      End If
 109:                      If Not String.IsNullOrEmpty(TXTTextBox.Text.Trim) Then
 110:                          CurDbRow(0).TXT = TXTTextBox.Text.Trim
 111:                      Else
 112:                          CurDbRow(0).TXT = Nothing
 113:                      End If
 114:                      If Not String.IsNullOrEmpty(PageTitleTextBox.Text.Trim) Then
 115:                          CurDbRow(0).PageTitle = PageTitleTextBox.Text.Trim
 116:                      Else
 117:                          CurDbRow(0).PageTitle = Nothing
 118:                      End If
 119:                      If Not String.IsNullOrEmpty(PageDescriptionTextBox.Text.Trim) Then
 120:                          CurDbRow(0).PageDescription = PageDescriptionTextBox.Text.Trim
 121:                      Else
 122:                          CurDbRow(0).PageDescription = Nothing
 123:                      End If
 124:                      If Not String.IsNullOrEmpty(Bind1TextBox.Text.Trim) Then
 125:                          CurDbRow(0).Bind1 = Bind1TextBox.Text.Trim
 126:                      Else
 127:                          CurDbRow(0).Bind1 = Nothing
 128:                      End If
 129:                      If Not String.IsNullOrEmpty(Bind2TextBox.Text.Trim) Then
 130:                          CurDbRow(0).Bind2 = Bind2TextBox.Text.Trim
 131:                      Else
 132:                          CurDbRow(0).Bind2 = Nothing
 133:                      End If
 134:                      If Not String.IsNullOrEmpty(MenuNameTextBox.Text.Trim) Then
 135:                          CurDbRow(0).Menu1name = MenuNameTextBox.Text.Trim
 136:                      Else
 137:                          CurDbRow(0).Menu1name = Nothing
 138:                      End If
 139:                      If MenuOrderNumericUpDown.Value <> 0 Then
 140:                          CurDbRow(0).Menu1order = MenuOrderNumericUpDown.Value
 141:                      Else
 142:                          CurDbRow(0).Menu1order = Nothing
 143:                      End If
 144:   
 145:                      db1.SubmitChanges()
 146:                      AutoClosingMessageBox.Show("Saved" & vbCrLf & StatusLabel.Text)
 147:                  Else
 148:                      AutoClosingMessageBox.Show("Nothing URL to add data" & vbCrLf & StatusLabel.Text)
 149:                  End If
 150:              Catch ex As Exception
 151:                  MsgBox(ex.Message)
 152:              End Try
 153:          End If
 154:      End Sub
 155:   
 156:      Private Sub SitemapXmlToolStripButton_Click(sender As Object, e As EventArgs) Handles SitemapXmlToolStripButton.Click
 157:          Dim SiteDomain As String = Reg.GetValue(Of String)("SiteDomain")
 158:          Dim URL As String = SiteDomain & "/Sitemap.Xml"
 159:          FF.OpenFirefoxInNewTab(URL)
 160:      End Sub
 161:   
 162:      Private Sub WebSitemapToolStripButton_Click(sender As Object, e As EventArgs) Handles WebSitemapToolStripButton.Click
 163:          Dim SiteDomain As String = Reg.GetValue(Of String)("SiteDomain")
 164:          Dim URL As String = SiteDomain & "/Web.Sitemap"
 165:          FF.OpenFirefoxInNewTab(URL)
 166:      End Sub
 167:   
 168:      Private Sub SetLocalRootToolStripButton_Click(sender As Object, e As EventArgs) Handles SetLocalRootToolStripButton.Click
 169:          Dim X As New SettingForm
 170:          X.ShowDialog()
 171:      End Sub
 172:   
 173:   
 174:      Dim LocalRootFolder As String
 175:      Private Sub OpenWebSitemapToolStripButton_Click(sender As Object, e As EventArgs) Handles OpenWebSitemapToolStripButton.Click
 176:          LocalRootFolder = Reg.GetValue(Of String)("LocalRootFolder")
 177:          Dim Path As String = LocalRootFolder & "\Web.Sitemap"
 178:          Clipboard.SetText("File.OpenFile """ & Path & """")
 179:          AutoClosingMessageBox.Show("Open command in clipboard")
 180:      End Sub
 181:   
 182:      Private Sub OpenSitemapXmlToolStripButton_Click(sender As Object, e As EventArgs) Handles OpenSitemapXmlToolStripButton.Click
 183:          LocalRootFolder = Reg.GetValue(Of String)("LocalRootFolder")
 184:          Dim Path As String = LocalRootFolder & "\Sitemap.Xml"
 185:          Clipboard.SetText("File.OpenFile """ & Path & """")
 186:          AutoClosingMessageBox.Show("Open command in clipboard")
 187:      End Sub
 188:   
 189:      Private Sub OpenInStudoToolStripButton_Click(sender As Object, e As EventArgs) Handles OpenInStudoToolStripButton.Click
 190:          Dim LocalRootFolder As String = Reg.GetValue(Of String)("LocalRootFolder")
 191:          Dim Path As String = LocalRootFolder & StatusLabel.Text.Replace("/", "\") & ".aspx"
 192:          Clipboard.SetText("File.OpenFile """ & Path & """")
 193:          AutoClosingMessageBox.Show("Open command in clipboard")
 194:      End Sub
 195:   
 196:      Dim Pages As List(Of String)
 197:      Dim LocalDomain As String
 198:      Private Sub OpenAlllocallyToolStripButton1_Click(sender As Object, e As EventArgs) Handles OpenAlllocallyToolStripButton1.Click
 199:          LocalRootFolder = Reg.GetValue(Of String)("LocalRootFolder")
 200:          LocalDomain = Reg.GetValue(Of String)("LocalURL")
 201:          Pages = New List(Of String)
 202:          ProcessSiteDir(LocalRootFolder)
 203:          For Each one As String In Pages
 204:              FF.OpenFirefoxInNewTab(one)
 205:          Next
 206:      End Sub
 207:   
 208:      Sub ProcessSiteDir(CurDir As String)
 209:          If Not CurDir.Contains(IO.Path.Combine(LocalRootFolder, "obj")) Then
 210:              Dim Files() As String = IO.Directory.GetFiles(CurDir)
 211:              For Each OneFile As String In Files
 212:                  If OneFile.EndsWith(".aspx") Then
 213:                      Dim URL As String = OneFile.Replace(LocalRootFolder, LocalDomain).Replace("\", "/").ToLower
 214:                      Pages.Add(URL)
 215:                  End If
 216:              Next
 217:              Dim Dirs() As String = IO.Directory.GetDirectories(CurDir)
 218:              For Each OneFir As String In Dirs
 219:                  ProcessSiteDir(OneFir)
 220:              Next
 221:          End If
 222:      End Sub
 223:   
 ....   

11. Popup sticky form.

Main form calling two sticky form, one of them is stick to right down corner of main form and another stick to right side of main form.

This is code of main form to realize sticking.



 ....   
 384:  #Region "Popup"
 385:   
 386:      Dim PopUpForm_Instance As PopUpForm
 387:      Private Sub OpenPopUpButton_Click(sender As Object, e As EventArgs) Handles OpenPopUpButton.Click
 388:          If CurRow IsNot Nothing Then
 389:              If PopUpForm_Instance IsNot Nothing Then
 390:                  PopUpForm.SetData(CurRow(0).Menu1name, GetOrderedMenu(), StatusLabel.Text)
 391:                  PopUpForm_Instance.Show()
 392:              Else
 393:                  PopUpForm_Instance = New PopUpForm
 394:                  PopUpForm_Instance.Owner = Me
 395:                  PopUpForm.SetData(CurRow(0).Menu1name, GetOrderedMenu(), StatusLabel.Text)
 396:                  PopUpForm_Instance.Show()
 397:              End If
 398:          End If
 399:      End Sub
 400:   
 401:      Private Sub StartForm_Move(sender As Object, e As EventArgs) Handles Me.Move
 402:          If PopUpForm_Instance IsNot Nothing Then
 403:              PopUpForm_Instance.PopUpForm_Shown(Nothing, Nothing)
 404:          End If
 405:          If CheckPageForm_Instance IsNot Nothing Then
 406:              CheckPageForm_Instance.CheckPageForm_Shown(Nothing, Nothing)
 407:          End If
 408:      End Sub
 409:   
 410:      Private Sub StartForm_Resize(sender As Object, e As EventArgs) Handles Me.Resize
 411:          If PopUpForm_Instance IsNot Nothing Then
 412:              PopUpForm_Instance.PopUpForm_Shown(Nothing, Nothing)
 413:          End If
 414:          If CheckPageForm_Instance IsNot Nothing Then
 415:              CheckPageForm_Instance.CheckPageForm_Shown(Nothing, Nothing)
 416:          End If
 417:      End Sub
 418:   
 419:      Public Function GetOrderedMenu() As List(Of Description)
 420:          If CurRow IsNot Nothing Then
 421:              Dim Menu1name As String = CurRow(0).Menu1name
 422:              Return db1.Descriptions.Where(Function(S) S.Menu1name = Menu1name).OrderBy(Function(S) S.Menu1order).ToList
 423:          End If
 424:      End Function
 425:   
 426:   
 427:      Dim CheckPageForm_Instance As CheckPageForm
 428:      Private Sub CheckSourcePageToolStripButton_Click(sender As Object, e As EventArgs) Handles CheckSourcePageToolStripButton.Click
 429:          If CheckPageForm_Instance IsNot Nothing Then
 430:              CheckPageForm_Instance.Show()
 431:          Else
 432:              CheckPageForm_Instance = New CheckPageForm
 433:              CheckPageForm_Instance.Owner = Me
 434:              CheckPageForm_Instance.Show()
 435:          End If
 436:      End Sub
 437:   
 438:   
 439:  #End Region
 440:   
 441:  End Class

12. Sticky form with ListView.



   1:  Imports System.ComponentModel
   2:   
   3:  Public Class PopUpForm
   4:   
   5:      Shared Property Title As String
   6:      Shared Property Data As List(Of Description)
   7:      Shared Property Key As String
   8:      Public Sub SetData(TT As String, DT As List(Of Description), KE As String)
   9:          Data = DT
  10:          Title = TT
  11:          Key = KE
  12:      End Sub
  13:   
  14:      Private Sub PopUpForm_Load(sender As Object, e As EventArgs) Handles Me.Load
  15:          Fill()
  16:          Me.BringToFront()
  17:      End Sub
  18:   
  19:      'залипание в прав ниж угол форми-владельца
  20:      Public Sub PopUpForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
  21:          If Owner IsNot Nothing Then
  22:              Dim MeLocation As Point = New Point(Owner.Location.X + Owner.Width - Me.Width, Owner.Location.Y + Owner.Height - Me.Height)
  23:              Me.Location = MeLocation
  24:              MyBase.Show()
  25:          End If
  26:      End Sub
  27:   
  28:      Private Sub PopUpForm_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
  29:          Me.Hide()
  30:          e.Cancel = True
  31:      End Sub
  32:   
  33:      Private Sub PopUpForm_Activated(sender As Object, e As EventArgs) Handles Me.Activated
  34:          Fill()
  35:      End Sub
  36:   
  37:      Public Sub Fill()
  38:          Text = Title
  39:          ListView1.Items.Clear()
  40:          For Each One As Description In Data
  41:              Dim Row() As String = {One.Menu1order, One.H1}
  42:              Dim LV = New ListViewItem(Row)
  43:              If One.URL = Key Then
  44:                  LV.BackColor = Color.LightBlue
  45:              End If
  46:              ListView1.Items.Add(LV)
  47:          Next
  48:      End Sub
  49:   
  50:  End Class

13. Sticky form with GridView.



   1:  Imports System.ComponentModel
   2:   
   3:  Public Class CheckPageForm
   4:  #Region "form control"
   5:   
   6:      Private Sub CheckPageForm_Load(sender As Object, e As EventArgs) Handles Me.Load
   7:          Fill()
   8:      End Sub
   9:   
  10:      'залипание справа
  11:      Public Sub CheckPageForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
  12:          If Owner IsNot Nothing Then
  13:              Dim MeLocation As Point = New Point(Owner.Location.X + Owner.Width - 10, Owner.Location.Y)
  14:              Me.Height = Owner.Height
  15:              Me.Location = MeLocation
  16:              MyBase.Show()
  17:          End If
  18:      End Sub
  19:   
  20:      Private Sub CheckPageForm_Activated(sender As Object, e As EventArgs) Handles Me.Activated
  21:          'show
  22:      End Sub
  23:   
  24:      Private Sub CheckPageForm_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
  25:          Me.Hide()
  26:          e.Cancel = True
  27:      End Sub
  28:   
  29:   
  30:      Private Sub RefreshToolStripButton_Click(sender As Object, e As EventArgs) Handles RefreshToolStripButton.Click
  31:          Fill()
  32:      End Sub
  33:   
  34:  #End Region
  35:   
  36:  #Region "Grid"
  37:   
  38:      Dim Reg As Registry
  39:      Dim SourceRoot As String
  40:      Dim Pages As List(Of String)
  41:      Dim DataSource As BindingList(Of StringValue)
  42:      Dim db1 As dbDataContext
  43:      Dim Rows As List(Of Description)
  44:      Dim OrderedPages As IOrderedEnumerable(Of String)
  45:      Public Sub Fill()
  46:          Reg = New Registry("BraggartSupport")
  47:          Pages = New List(Of String)
  48:          SourceRoot = Reg.GetValue(Of String)("LocalRootFolder")
  49:          db1.GetContext(True)
  50:          Rows = (From X In db1.Descriptions Select X Order By X.URL).ToList
  51:          ProcessSiteDir(SourceRoot)
  52:          ToolStripStatusLabel1.Text = Pages.Count
  53:          OrderedPages = Pages.OrderBy(Of String)(Function(X) X)
  54:          DataSource = New BindingList(Of StringValue)
  55:          OrderedPages.ToList.ForEach(Sub(Y) DataSource.Add(New StringValue(Y)))
  56:          DataGridView1.AutoGenerateColumns = False
  57:          DataGridView1.DataSource = DataSource
  58:      End Sub
  59:   
  60:   
  61:      Public Enum nColumn
  62:          VScommand = 0
  63:          DeleteFiles = 1
  64:          AddToDb = 2
  65:      End Enum
  66:   
  67:      Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
  68:          If e.RowIndex >= 0 Then
  69:              Dim senderGrid = DirectCast(sender, DataGridView)
  70:              Dim CurRow = OrderedPages.ToList(e.RowIndex)
  71:              If TypeOf senderGrid.Columns(e.ColumnIndex) Is DataGridViewImageColumn And e.ColumnIndex = nColumn.VScommand Then
  72:                  Clipboard.SetText("File.OpenFile """ & SourceRoot & CurRow.Replace("/", "\") & """")
  73:                  AutoClosingMessageBox.Show("Open command in clipboard")
  74:              ElseIf TypeOf senderGrid.Columns(e.ColumnIndex) Is DataGridViewImageColumn And e.ColumnIndex = nColumn.AddToDb Then
  75:                  db1.Descriptions.InsertOnSubmit(New Description With {.URL = CurRow.Replace(".aspx", "").ToLower})
  76:                  db1.SubmitChanges()
  77:                  AutoClosingMessageBox.Show(CurRow.Replace(".aspx", "").ToLower & vbCrLf & "Added")
  78:                  Fill()
  79:              ElseIf TypeOf senderGrid.Columns(e.ColumnIndex) Is DataGridViewImageColumn And e.ColumnIndex = nColumn.DeleteFiles Then
  80:                  Try
  81:                      Dim FileName1 = SourceRoot & CurRow.Replace("/", "\")
  82:                      Dim FileName2 = FileName1.Replace(".aspx", ".aspx.cs")
  83:                      Dim FileName3 = FileName1.Replace(".aspx", ".aspx.designer.cs")
  84:                      If MessageBox.Show(FileName1 & vbCrLf & FileName2 & FileName3, "Delete files ?", MessageBoxButtons.YesNo) = DialogResult.Yes Then
  85:                          IO.File.Delete(FileName1)
  86:                          IO.File.Delete(FileName2)
  87:                          IO.File.Delete(FileName3)
  88:                          Fill()
  89:                      End If
  90:                  Catch ex As Exception
  91:                      MsgBox(ex.Message)
  92:                  End Try
  93:              End If
  94:          End If
  95:   
  96:   
  97:   
  98:   
  99:      End Sub
 100:   
 101:  #End Region
 102:   
 103:  #Region "Recurse observe filesystem"
 104:   
 105:      Sub ProcessSiteDir(CurDir As String)
 106:          If Not CurDir.Contains(IO.Path.Combine(SourceRoot, "obj")) Then
 107:              Dim Files() As String = IO.Directory.GetFiles(CurDir)
 108:              For Each OneFile As String In Files
 109:                  If OneFile.EndsWith(".aspx") Or OneFile.EndsWith(".aspx.exclude") Then
 110:                      Dim URL As String = OneFile.Replace(SourceRoot, "").Replace("\", "/").ToLower
 111:                      If Rows.Where(Function(X) X.URL & ".aspx" = URL).ToList.Count = 0 Then
 112:                          Pages.Add(URL)
 113:                      End If
 114:                  End If
 115:              Next
 116:              Dim Dirs() As String = IO.Directory.GetDirectories(CurDir)
 117:              For Each OneFir As String In Dirs
 118:                  ProcessSiteDir(OneFir)
 119:              Next
 120:          End If
 121:      End Sub
 122:   
 123:  #End Region
 124:  End Class

14. Alternate to manual recursion in previous form.

In other part of this program I use another solution.



  71:   
  72:      Sub InitialCollectImageToDB(SiteRoot)
  73:   
  74:          Dim Files = Directory.GetFiles(SiteRoot, "*.*", SearchOption.AllDirectories).
  75:              Where(Function(X) X.EndsWith(".jpg") Or X.EndsWith(".gif") Or X.EndsWith(".png") Or X.EndsWith(".jpeg"))
  76:   
  77:          For Each OneFile In Files
  78:              Dim DirName As String
  79:              Dim FileName As String
  80:              Try
  81:                  Dim RelPath As String = OneFile.Replace(SiteRoot, "")
  82:                  DirName = IO.Path.GetDirectoryName(RelPath)
  83:                  FileName = IO.Path.GetFileName(RelPath)
  84:                  Dim Img As Drawing.Bitmap = New Bitmap(OneFile)
  85:                  Dim CreationTime As Date = IO.File.GetCreationTime(OneFile)
  86:                  Dim LastAccessTime As Date = IO.File.GetLastAccessTime(OneFile)
  87:                  Dim LastWriteTime As Date = IO.File.GetLastWriteTime(OneFile)
  88:                  Dim Exist = (Db1.Images.Where(Function(X) X.Name = FileName And X.Folder = DirName)).FirstOrDefault
  89:                  If Exist Is Nothing Then
  90:                      Db1.Images.InsertOnSubmit(New Image With {.Folder = DirName, .Name = FileName, .X = Img.Width, .Y = Img.Height, .Accessed = LastAccessTime, .Created = CreationTime, .Modified = LastWriteTime})
  91:                  End If
  92:              Catch ex As Exception
  93:                  Db1.Images.InsertOnSubmit(New Image With {.Name = FileName, .Folder = DirName})
  94:                  Console.WriteLine(OneFile & vbCrLf & ex.Message)
  95:              End Try
  96:          Next
  97:   
  98:          Db1.SubmitChanges()
  99:      End Sub

16. Other form.

Other form is not very interesting and I don't publish it.





Comments ( )
Link to this page: //www.vb-net.com/BraggartSupport/Index.htm
< THANKS ME>