patterncsharpMinor
Creating and Editing a UtilityMeter
Viewed 0 times
creatingutilitymeterandediting
Problem
I have some functionality that allows the user to create a
A
Once a
This is the caller:
Create:
Edit:
```
internal void EditMeterButton_Click(Meter _meter)
{
if (_meter == null)
return;
var premise = _meter.Premise;
var createMeterWindow = new CreateMeterWindow(_meter);
if (createMeterWindow.ShowDialog() == true)
{
var meter = createMeterWindow.CreateMeterViewModel.Met
Meter, which counts your gas, water, and electricity usage.A
Meter has one or more Counter objects, which keeps track of your usage for a certain date via CounterReading.Once a
Meter is created, you can edit it by adding a new Reading.This is the caller:
Create:
internal void CreateUtilityTransferButton_Click(Premise selectedPremise)
{
var printUtilitiesWindow = new TransferUtilitiesWindow();
if (selectedPremise != null)
printUtilitiesWindow.TransferUtilitiesWindowViewModel.SelectedTransferPremise = selectedPremise;
if (printUtilitiesWindow.ShowDialog() == true)
{
PdfFiller filler = new PdfFiller();
var documentType = printUtilitiesWindow.TransferUtilitiesWindowViewModel.DocumentType;
try
{
switch (documentType)
{
case UtilityDocumentType.Transfer:
filler.Fill(printUtilitiesWindow.TransferUtilitiesWindowViewModel.Transfer);
break;
case UtilityDocumentType.Connection:
filler.Fill(printUtilitiesWindow.TransferUtilitiesWindowViewModel.Connection);
break;
case UtilityDocumentType.Water:
filler.Fill(printUtilitiesWindow.TransferUtilitiesWindowViewModel.Water);
break;
default:
throw new ArgumentException("Verkeerd documenttype gekozen");
}
}
catch (ArgumentException e)
{
var popup = new ErrorMessage(e);
popup.ShowDialog();
}
}
}Edit:
```
internal void EditMeterButton_Click(Meter _meter)
{
if (_meter == null)
return;
var premise = _meter.Premise;
var createMeterWindow = new CreateMeterWindow(_meter);
if (createMeterWindow.ShowDialog() == true)
{
var meter = createMeterWindow.CreateMeterViewModel.Met
Solution
Here're my comments:
-
You shouldn't mix conventions like in this method declaration:
Lot's of people use the underscore
-
You shouldn't name a method like it was an event handler but it isn't:
Name it accordingly to what it does like
-
You should name methods firing events with the
instead of
-
Try to keep one style when naming fields:
it would be better to apply camelCase naming to the first variable:
-
You shouldn't mix conventions like in this method declaration:
internal void EditMeterButton_Click(Meter _meter)Lot's of people use the underscore
_ for private fields and it's confusing when used with a parameter name-
You shouldn't name a method like it was an event handler but it isn't:
internal void ComboBox_SelectionChanged()Name it accordingly to what it does like
UpdateMeters or something (it's just an example, I cannot deduce exactly what it's purpose)-
You should name methods firing events with the
On-prefix:public void OnNotifyPropertyChanged(String info)instead of
public void NotifyPropertyChanged(String info)-
Try to keep one style when naming fields:
private CounterReading _NewReading;
private bool _isEdit = false;it would be better to apply camelCase naming to the first variable:
private CounterReading _newReading;Code Snippets
internal void EditMeterButton_Click(Meter _meter)internal void ComboBox_SelectionChanged()public void OnNotifyPropertyChanged(String info)public void NotifyPropertyChanged(String info)private CounterReading _NewReading;
private bool _isEdit = false;Context
StackExchange Code Review Q#101091, answer score: 4
Revisions (0)
No revisions yet.