Question

Over the past two years I developed apps for the CF .NET 3.5 to be runned on warehouse's portable device(windows mobile). From the beginning I just jumped into the process and made a lot of mistakes that I'm gradually correcting. What has came out are apps made in this way: a main form to start the whole process which automatically creates a data-form, that will stay alive for the whole time. This data-form will keep all the datas that the user will insert or request from the server. The other forms are basically views of the data with methods to manipulate them.

It works but...am I doing this in the right way? Or maybe am I missing something really fundamental?

Was it helpful?

Solution

So, you created a data form, and you are using it like RAM. You never display the data, you simply store it there to access.

If someone ever has to take over your job (like you leave the company or die), they are going to hate you so bad.

A better technique would be to create a Class that houses all of this data.

The good part is, since you already have a data form, you probably already know how everything is organized!

Now, just use that knowledge of your data to create your class that you can read and write to.

If you have groups of similar items, create other classes that your main class will contain.

If you have several of these similar items, create publically accessible Lists of these items.

Make it as dead simple or as complex as you'd like!

Consider these classes, which are all generic enough to modify however you would need and demonstrate some extras added:

public class DataForm {

  private GroupedItem m_item2;
  public event EventHandler Item2Changed;

  public DataForm() { // this is your constructor
    Item1 = new GroupedItem();
    Item2 = new GroupedItem();
    ItemCollection = new GroupCollectionItems("Group1");
  }

  public float Value1 { get; set; }
  public float Value2 { get; set; }

  public GroupedItem Item1 { get; set; }

  public GroupedItem Item2 {
    get { return m_item2; }
    set {
      if (m_item2 != value) {
        m_item2 = value;
        if (Item2Changed != null) {
          Item2Changed(this, EventArgs.Empty); // notify whoever is listening for the change
        }
      }
    }
  }

  public GroupCollectionItems ItemCollection { get; set; }

}

public class GroupedItem {

  public GroupedItem() { // this is your constructor
  }

  public string Name { get; set; }

  public object Value { get; set; }

}

public class GroupCollectionItem {

  private GroupCollectionItem() { // this is your constructor
  }

  public static GroupCollectionItem Create(string groupName, string itemName, object itemValue) {
    var item = new GroupCollectionItem() {
      Group = groupName,
      Name = itemName,
      Value = itemValue
    };
    return item;
  }

  public string Group { get; private set; }

  public string Name { get; private set; }

  public object Value { get; set; }

}

public class GroupCollectionItems : List<GroupCollectionItem> {

  public GroupCollectionItems(string name) { // this is your constructor
    Name = name;
  }

  public string Name { get; private set; }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top