11.01.2010

OMG Dependencies–new direction time

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

image

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.

  1.         /// <summary>
  2.         /// The main entry point for the application.
  3.         /// </summary>
  4.         [STAThread]
  5.         static void Main()
  6.         {
  7.             Application.Run(new MainForm());
  8.         }

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.

image

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:

  1.         <Menu>
  2.             <MenuItem Header="File">
  3.                 <MenuItem Header="Quit" />
  4.             </MenuItem>
  5.             <MenuItem Header="Manage Data">
  6.                 <MenuItem Header="Manage Datasets" />
  7.                 <MenuItem Header="Manage Other Data" />
  8.             </MenuItem>
  9.             <MenuItem Header="Analysis">
  10.                 <MenuItem Header="Analyze Rate Schedules" />
  11.             </MenuItem>
  12.         </Menu>

Change layout controls

  1.             Panel leftPanel = new Panel();
  2.             leftPanel.AutoScroll = true;
  3.             leftPanel.Width = 350;
  4.             leftPanel.Dock = DockStyle.Left;
  5.  
  6.             Splitter splitterCtrl = new Splitter();
  7.             splitterCtrl.Dock = DockStyle.Left;
  8.             splitterCtrl.MinExtra = 200;
  9.             splitterCtrl.MinSize = 200;
  10.  
  11.             Panel mainPanel = new Panel();
  12.             mainPanel.AutoScroll = true;
  13.             mainPanel.Dock = DockStyle.Fill;
  14.  
  15.             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.

  1.     <Grid>
  2.         <Grid.RowDefinitions>
  3.             <RowDefinition Height="Auto" />
  4.             <RowDefinition />
  5.         </Grid.RowDefinitions>
  6.         <Grid.ColumnDefinitions>
  7.             <ColumnDefinition />
  8.             <ColumnDefinition />
  9.             <ColumnDefinition />
  10.         </Grid.ColumnDefinitions>
  1.         <StackPanel x:Name="leftPanel"
  2.                     Grid.Row="1"
  3.                     Grid.Column="0"
  4.                     Width="350"
  5.                     MinWidth="200"
  6.                     />
  7.         <GridSplitter Grid.Row="1"
  8.                       Grid.Column="1" />
  9.         <StackPanel x:Name="mainPanel"
  10.                     Grid.Row="1"
  11.                     Grid.Column="2" />

Now time to swap out change the code where some other controls are added to the panels.

  1.             Contract_Control contractsCtrl = new Contract_Control(rmsController);
  2.             contractsCtrl.Dock = DockStyle.Fill;
  3.             leftPanel.Controls.Add(contractsCtrl);
  4.  
  5.             RateSchedule_Control rateScheduleCtrl = new RateSchedule_Control(rmsController);
  6.             rateScheduleCtrl.Dock = DockStyle.Fill;
  7.             mainPanel.Controls.Add(rateScheduleCtrl);

We just need to wrap up the form controls in WindowsFormsHost controls and add them to the stackpanels.

  1.             var contractsCtrl = new Contract_Control(rmsController);
  2.             contractsCtrl.Dock = DockStyle.Fill;
  3.             var host = new WindowsFormsHost();
  4.             host.Child = contractsCtrl;
  5.             leftPanel.Children.Add(host);
  6.  
  7.             var rateScheduleCtrl = new RateSchedule_Control(rmsController);
  8.             rateScheduleCtrl.Dock = DockStyle.Fill;
  9.             var host2 = new WindowsFormsHost();
  10.             host2.Child = rateScheduleCtrl;
  11.             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.

0 comments:

Post a Comment