How To Make An Admin Panel To Controll Every Controller In My App.

Amr_Ali 136 Reputation points
2020-12-14T10:13:05.207+00:00

Hi all,
This question is strange, i think that . But i had to ask it before.....
Anyway , My clients asked me to fix some code in my apps. for example (I have to make a date changeable not fixed" In some Forms i made the datetimepicker takes the today date only and can't change to insure that the process done in the current date of Bill creation" But the client change his mind and want me to change this scenario to set the datetimepicker changeable to any date he want)
this so good and i can change it to whatever he wants .
But the question here is
Why do i have to make build to my app. every time and uninstall my app. from his machine and then install it again after any new changes to my app. ???
How can i make a Form (say for example "Admin Panel") to enable me to make any changes in the run time without need to uninstall the app. from the client machine ?
Can i use XML file to perform this mission and how ?
I want every controller in my app. obeying to this strategy .....
Any suggestions ............................

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,725 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,421 Reputation points
    2020-12-17T11:12:43.84+00:00

    @Amr_Ali

    How can i add a new controls in the form1 and where can i write any methods or functions ??

    I'm sure it's possible to some extent but in 20 years of coding never had the need for this and would think this would need to run off some dynamic script. Although not an answer the following can give you a clue to the complexities you will face.

    1 person found this answer helpful.

5 additional answers

Sort by: Most helpful
  1. Karen Payne MVP 35,421 Reputation points
    2020-12-17T15:55:49.147+00:00

    @Amr_Ali

    Full source

    Note CheckBoxes don't have Text set because I didn't set it but you can, that's what happens when I'm pressed for time, sorry.

    49225-a1.png

    Revised FormOperations

    Imports System.IO  
    Imports Newtonsoft.Json  
      
    Public Class FormOperations  
      
        Public Shared Container As New List(Of ControlContainer)  
        Public Shared Property FileName() As String  
      
        Public Shared ReadOnly Property HasControls() As Boolean  
            Get  
                Return Container.Count > 0  
            End Get  
        End Property  
        Public Shared ReadOnly Property FileExists() As Boolean  
            Get  
                Return File.Exists(FileName)  
            End Get  
        End Property  
        Public Shared Sub SerializeToFile()  
            If HasControls Then  
                Dim output As String = JsonConvert.SerializeObject(Container, Formatting.Indented)  
                File.WriteAllText(FileName, output)  
            End If  
        End Sub  
        Public Shared Function DeserializeFromFile() As Boolean  
            If FileExists Then  
                Dim json = File.ReadAllText(FileName)  
                Container = JsonConvert.DeserializeObject(Of List(Of ControlContainer))(json)  
                Return True  
            Else  
                Return False  
            End If  
        End Function  
        Public Shared Sub Collect(sender As Form)  
      
            Container.Clear()  
      
            Dim itemList As New List(Of ControlContainer)  
      
            sender.ButtonList.ForEach(Sub(button)  
                                          itemList.Add(New ControlContainer() With {  
                                            .Type = GetType(Button),  
                                            .Text = button.Text,  
                                            .Anchor = button.Anchor,  
                                            .Location = button.Location,  
                                            .TabIndex = button.TabIndex,  
                                            .Name = button.Name,  
                                            .FormName = sender.Name  
                                }  
                             )  
                                      End Sub)  
      
            sender.CheckBoxList.ForEach(Sub(checkBox)  
                                            itemList.Add(New ControlContainer() With {  
                                                .Type = GetType(CheckBox),  
                                                .Anchor = checkBox.Anchor,  
                                                .Location = checkBox.Location,  
                                                .TabIndex = checkBox.TabIndex,  
                                                .Name = checkBox.Name,  
                                                .Checked = checkBox.Checked,  
                                                .FormName = sender.Name  
                                }  
                             )  
                                        End Sub)  
      
            Dim buttons = itemList.Where(Function(item) item.Type Is GetType(Button)).ToList()  
            Dim checkBoxes = itemList.Where(Function(item) item.Type Is GetType(CheckBox)).ToList()  
      
            Container.AddRange(buttons)  
            Container.AddRange(checkBoxes)  
        End Sub  
      
        Public Shared Function GetByForm(sender As String) As List(Of ControlContainer)  
            If HasControls Then  
                Return Container.Where(Function(item) item.FormName = sender).ToList()  
            Else  
                Return Nothing  
            End If  
      
        End Function  
      
      
    End Class  
    

    Revised form code

    Public Class Form1  
        Private Sub CollectButton_Click(sender As Object, e As EventArgs) Handles CollectButton.Click  
            FormOperations.Collect(Me)  
        End Sub  
      
        Private Sub GetByFormnName_Click(sender As Object, e As EventArgs) Handles GetByFormNameButton.Click  
      
            Dim controls = FormOperations.GetByForm(Name)  
      
            If controls IsNot Nothing Then  
                MessageBox.Show(controls.Count.ToString())  
            Else  
                MessageBox.Show("No controls located")  
            End If  
      
      
        End Sub  
        Private Sub SerializeButton_Click(sender As Object, e As EventArgs) Handles SerializeButton.Click  
      
            FormOperations.SerializeToFile()  
      
        End Sub  
      
        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown  
      
            FormOperations.FileName = "Forms.json"  
      
        End Sub  
        Private Sub DeserializeFromFile_Click(sender As Object, e As EventArgs) Handles DeserializeFromFileButton.Click  
      
            If FormOperations.DeserializeFromFile() Then  
                For Each controlContainer As ControlContainer In FormOperations.Container  
                    Debug.WriteLine($"{controlContainer.FormName}.{controlContainer.Name} is {controlContainer.Type}")  
                Next  
            End If  
      
        End Sub  
    End Class  
    

    JSON

    [  
      {  
        "FormName": "Form1",  
        "Text": "Button3",  
        "Location": "108, 28",  
        "Name": "Button3",  
        "Size": "0, 0",  
        "Anchor": 5,  
        "TabIndex": 5,  
        "Type": "System.Windows.Forms.Button, System.Windows.Forms, Version=5.0.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",  
        "Checked": false  
      },  
      {  
        "FormName": "Form1",  
        "Text": "Button2",  
        "Location": "27, 76",  
        "Name": "Button2",  
        "Size": "0, 0",  
        "Anchor": 9,  
        "TabIndex": 1,  
        "Type": "System.Windows.Forms.Button, System.Windows.Forms, Version=5.0.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",  
        "Checked": false  
      },  
      {  
        "FormName": "Form1",  
        "Text": "Button1",  
        "Location": "27, 31",  
        "Name": "Button1",  
        "Size": "0, 0",  
        "Anchor": 5,  
        "TabIndex": 0,  
        "Type": "System.Windows.Forms.Button, System.Windows.Forms, Version=5.0.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",  
        "Checked": false  
      },  
      {  
        "FormName": "Form1",  
        "Text": null,  
        "Location": "18, 191",  
        "Name": "CheckBox2",  
        "Size": "0, 0",  
        "Anchor": 5,  
        "TabIndex": 4,  
        "Type": "System.Windows.Forms.CheckBox, System.Windows.Forms, Version=5.0.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",  
        "Checked": false  
      },  
      {  
        "FormName": "Form1",  
        "Text": null,  
        "Location": "19, 158",  
        "Name": "CheckBox1",  
        "Size": "0, 0",  
        "Anchor": 5,  
        "TabIndex": 3,  
        "Type": "System.Windows.Forms.CheckBox, System.Windows.Forms, Version=5.0.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",  
        "Checked": false  
      }  
    ]  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.