After looking at the BaseDALObject and tracing its usage, I’ve come to the conclusion that at the moment, it is too intertwined to refactor. I will leave it as is with its simple code cleanup and try a different angle.
So I decided to run the application. And kaboom! No go. So I think I will just start from the top down.
Wow, I completely forgot that back in the day we didn’t have the awesomeness of partial classes. So my main form has a bunch of generated controls etc from the designer. So I am going to create a new MainForm and let VS do its magic joo joo. And actually since I have to create a new form anyway, I am going to create a WPF application.
Step 1 – Create a new WPF project called RMS
Step 2 – Move all the WinForm controls over
When I tried to compile after fixing some minor issues. I got this error message
The issue is my MainForm still has a ‘main’ method. The new WPF application project has the main method in the App.xaml.cs
Remove this and we should be good to go.
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new MainForm());
- }
The project already has a MainWindow and it is opened up by the application on startup. How do I know? I can just look at the App.xaml and the StartupUri.
So now time to start moving over the actual code and controls for the MainForm.
Menu
File > Quit
Manage Data > Manage Datasets, Manage Other Data
Analysis > Analyze Rate Schedules
To recreate this in WPF we simply do:
- <Menu>
- <MenuItem Header="File">
- <MenuItem Header="Quit" />
- </MenuItem>
- <MenuItem Header="Manage Data">
- <MenuItem Header="Manage Datasets" />
- <MenuItem Header="Manage Other Data" />
- </MenuItem>
- <MenuItem Header="Analysis">
- <MenuItem Header="Analyze Rate Schedules" />
- </MenuItem>
- </Menu>
Change layout controls
- Panel leftPanel = new Panel();
- leftPanel.AutoScroll = true;
- leftPanel.Width = 350;
- leftPanel.Dock = DockStyle.Left;
- Splitter splitterCtrl = new Splitter();
- splitterCtrl.Dock = DockStyle.Left;
- splitterCtrl.MinExtra = 200;
- splitterCtrl.MinSize = 200;
- Panel mainPanel = new Panel();
- mainPanel.AutoScroll = true;
- mainPanel.Dock = DockStyle.Fill;
- Controls.AddRange(new Control[] {mainPanel, splitterCtrl, leftPanel});
Based on the naming of the controls and my recollection. I had a left side and a main panel. And looks like a splitter between the two panels. In WPF we can do this all within a grid control.
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto" />
- <RowDefinition />
- </Grid.RowDefinitions>
- <Grid.ColumnDefinitions>
- <ColumnDefinition />
- <ColumnDefinition />
- <ColumnDefinition />
- </Grid.ColumnDefinitions>
- <StackPanel x:Name="leftPanel"
- Grid.Row="1"
- Grid.Column="0"
- Width="350"
- MinWidth="200"
- />
- <GridSplitter Grid.Row="1"
- Grid.Column="1" />
- <StackPanel x:Name="mainPanel"
- Grid.Row="1"
- Grid.Column="2" />
Now time to swap out change the code where some other controls are added to the panels.
- Contract_Control contractsCtrl = new Contract_Control(rmsController);
- contractsCtrl.Dock = DockStyle.Fill;
- leftPanel.Controls.Add(contractsCtrl);
- RateSchedule_Control rateScheduleCtrl = new RateSchedule_Control(rmsController);
- rateScheduleCtrl.Dock = DockStyle.Fill;
- mainPanel.Controls.Add(rateScheduleCtrl);
We just need to wrap up the form controls in WindowsFormsHost controls and add them to the stackpanels.
- var contractsCtrl = new Contract_Control(rmsController);
- contractsCtrl.Dock = DockStyle.Fill;
- var host = new WindowsFormsHost();
- host.Child = contractsCtrl;
- leftPanel.Children.Add(host);
- var rateScheduleCtrl = new RateSchedule_Control(rmsController);
- rateScheduleCtrl.Dock = DockStyle.Fill;
- var host2 = new WindowsFormsHost();
- host2.Child = rateScheduleCtrl;
- leftPanel.Children.Add(host2);
Now I can compile. But when I run, I blow up. Looks like I need to take a look at the RMS Controller. But that can wait for another day.