I have a VERY simple windows form that the user uses to manage "Stores".
Each store has a name and number, and is kept in a corresponding DB table.
The form has a listbox of stores, an add button that creates a new store, a delete button, and an edit button.
Beside those I have text boxes for the name and number, and save/cancel buttons.
When the user chooses a store from the list box, and clicks 'edit', the textboxes become populated and save/cancel become active. When the user clicks 'add', I create a new Store, add it to the listbox, activate the textboxes and save/cancel buttons, then commit it to the database when the user clicks 'save', or discards it when the user clicks 'cancel'.
Right now, my event system looks like this (in psuedo-code. It's just shorter that way.)
add->click:
store = new Store()
listbox.add(store)
populateAndEdit(store)
delete->click:
store = listbox.selectedItem
db.deleteOnSubmit(store)
listbox.remove(store)
db.submit()
edit->click:
populateAndEdit(listbox.selectedItem)
save->click:
parseAndSave(listbox.selectedItem)
db.submit()
disableTexts()
cancel->click:
disableTexts()
The problem is in how I determine if we are inserting a new Store, or updating an existing one.
The obvious solution to me would be to make it a "modal" process - that is, when I click edit, I go into edit mode, and the save button does things differently than if I were in add mode.
I know I could make this more MVC-like, but I don't really think this simple form merits the added complexity. I'm not very experienced with winforms, so I'm not sure if I even have the right idea for how to tackle this.
Is there a better way to do this? I would like to keep it simple, but usable.