locked
WPF DataGrid DataTable and MVVP patterns RRS feed

  • Question

  • Hallo

    Hope all are well.

    I've been looking at the design patterns for a WPF application we are busy building, just need some inputs on how and where the best place is to put some of the items.

    Got one screen for instance that got a DataGrid view which will be linked to a DataTable. (Binded). No issue there.

    But there is some logic I'm not sure where the best place is to handle.

    Firstly I've created a class that will only make connections to and from SQL and get the required data back from SQL to a DataTable, 

    DataAccessLayer:

    public DataTable SelectAvailableLocationsByZone(int zone)
            {
                var locations = new DataTable();           
    
                try
                {
                    conn.SqlQuery("Select * from tb_ProdPigeonStatus where where PigeonZone = @Zone and AllocatedToProduction = '0' and PigeonEnabled = '1'");
                    conn.Cmd.Parameters.AddWithValue("Zone", zone);
                    locations = conn.QueryEx();
                }
                catch (Exception e)
                {
                    LogFiles.ExceptionLogger.WriteException(e);
                } 
                return locations;
            }

    Then we got some Modelling to be done on it: (Not sure if this part is required, there is a DataTable will the records as per below headers only).

     public class ActiveWallModel
        {
            private string pigeonLocation;
            public int pigeonZone;
            public bool pigeonActive;
            public bool pigeonAllocated;
            public string orderNrAllocated;           
    
        }

    Data from SQL looks as follow:

    Based on the OrderAllocated I would like the cells in a DataGridView on each cell to be green if there is a value and red if there is no value in the cell. 

    Layout something like this (This was done in Windows Form but moving everything over to WPF.

    WFP New layout: (But need to bind datasource of DataTable and format on DataGrid, not sure if this is to be done on the UI or in a different ViewModel Class, and how to return the formatted datagrid, (DataTable only holds the data).


    labjac

    Tuesday, July 21, 2020 12:41 PM