-1

I need to implement this approach - two kinds of data sent as one set of parameters in a single Type - so that one type will hold those two parameters. That way I will be able to pass that Type to be processed by some method.

the first data item is:

  • Columns to be displayed , named: displayed

the second data item:

  • A copy (or only a portion) of that Columns displayed, as it has the same source, only these columns will not be displayed... in other words, Columns to omit, so I've named it: omitted

both are of a type Columns that I named - SelectedColumns

public class SelectedcColoumns
{
    public enum renederingMode
    {
        Displayed,
        omitted
    }
    public class omitted
    {

    }
    public class displayed
    {
    }
}

As the request for that SetOfColumns to be displayed is done by choosing table-name. So the Column class as data to be displayed varies based on the user choice the available source For SelectedColumns to choose from, is as shown below:

public class tableNames
{
   public static readonly string tblCustomers = "tblCustomers";
   public static readonly string tblProducts = "tblProducts";
}

public class TblColumns
{
    public class tblCustomers
    {
        public const string custID = "custID",
                            Name = "Name",
                            Phone = "Phone";
                            Email = "Email";
  
    }
    public class tblProducts 
    {
        public const string PrudctID = "PrudctID ",
                            PrudctName = "PrudctID",
                            PrudctCategory = "PrudctCategory";
    }
    ...etc'

}

When the user selects a set of tables Columns ... from any table user could, in this example.. choose either Customers or Products columns (e.g. SelectedColumns - is tblCustomers Columns), I then need to have another list, of those that the user selected to omit (not to display) from all of available table Columns.

Say the user chose to have Table Customers as a table. He chose to omit tblCustomers.custID + tblCustomer.Email because he only needs the name and phone to be displayed.

The problem I've encountered is while having these parameters in my reach (table name + columns to omit), How could I send it to process (passing it as One Parameter)? So that is why I've created a dedicated class, to hold this Type as sent parameter: all columns + omitted Columns in one piece.

This is where I am currently stuck; I need to know how to use it to build / construct the parameter out of user selection.

public class SelectedColoumns
{
    public enum renederingMode
    {
        Displayed,
        omitted
    }
        public class omitted
        {
           List<string> omitCols_ListStr = new List<string>();
        }
       
        public class displayed
        {
           List<string> dispCols_ListStr = new List<string>();
        }
}

In this part, I retrieve list of Columns through reflection as the supplier of data, via the following method:

Get any Nested Class-Fields, As List<string>, By a nested class-name and it's parent - Type.

public static List<string> anyNestedClassFiledsAsListByType<ClassToReturnOneOfitsNested_Fields>(string NetedClassName)
 {
                var RetNestedClassFildsListValues = typeof(ClassToReturnOneOFitsNested).GetNestedTypes()
                    .First(t => String.Compare(t.Name, NetedClassName, true) == 0).GetFields(BindingFlags.Public | BindingFlags.Static)
                    .Where(f => f.FieldType == typeof(string)).Select(f => (string)f.GetValue(null)).ToList();
                return RetNestedClassFildsListValues;
            }

so to produce this I could use the method above Like that

var TableColumns_ALL = 
anyNestedClassFldsAsListByType<TblColumns>(tableNames.tblCustomers);

My question is related to the class that needs to send TableColumns_ALL + the selected Columns to omit to be then processed by renderSelectedTable() below.

So it's even more basic than the complexity of reflection, but still some how i do not know the popper way to construct, the SelectedColumns class, so it will accommodate and format the structure of this new data type that will be sent as a parameter the method is something like this.

public void renderSelectedTable(SelectedColoumns CurrentUserSelectedCols)
{
    StringBuilder NwTRLoopSB = new StringBuilder();

    string curRowStyle= string.Empty,
           nwLine = Environment.NewLine + "\t\t\t",
           BaseTemplateTD = string.Empty;

    NwTRLoopSB.Append(
            string.Format(
                "<table id='tbl_Settings' cellspacing='0' border='1'><tr id='TR_headers'{0}>{1}",
                curRowStyle,
                nwLine
                )._Dhtml_DoubleQoutes()
        );
    foreach (var Item in SelectedListStr.Select((Val, counter) => new { Value = Val, Index = counter }))
    {
            curRowStyle = Lsts.DynamicStyle_Generator(Item.Index);

            if(Lsts.ExcludeColumns(Item.Value, OmittedCols))
            {
                BaseTemplateTD = string.Format("<td>{0}</td>{1}", Item.Value, nwLine)._Dhtml_DoubleQoutes();
                NwTRLoopSB.Append(BaseTemplateTD);
            }    
      
    }///ENd TR cells generator Section

    NwTRLoopSB.Append("</tr></table>");
    return NwTRLoopSB.ToString();

}
TylerH
  • 20,799
  • 66
  • 75
  • 101
LoneXcoder
  • 2,121
  • 6
  • 38
  • 76

2 Answers2

1

I would approach it this way:

public class Column{
    public string Name { get; set; }
    public bool Visible { get; set; }
}

public class Grid{
    public List<Column> Columns { get; set; }
}

So the I could easily define my full table with either visible or ommited columns. In the OP's example:

public class SelectedColumns
{
    //instead of the enum you would have boolean in the column type "Visible" (whether is shown or not)
    public enum renederingMode
    {
        Displayed,
        omitted
    }
    // instead of both these you would have a List o Column types that have a name AND a boolean, so you have your List<string> and a boolean to indicate whether it is visible or ommited. Well at least that's how I understood it.
    public class ommited
    {

    }
    public class displayed
    {
    }
}
povilasp
  • 2,386
  • 1
  • 22
  • 36
  • little more please , will give you extra 10' on that one (: implementing or what esle is missing from this approach so i could really learn while we're throwing some jokes .. thanks mate – LoneXcoder Dec 19 '12 at 20:33
  • you did understand correctly, i need to send `List` + `List` or you could put it this way `List` + (-`List`), a new word i have learnd recently (: i will try to omit few lines of text out of my question next time (; – LoneXcoder Dec 19 '12 at 20:59
0

so.. first.. a design note: Given a list of columns.. you will either display a column, or not display a column.. there are no other options where visibility is concerned. So you really only need to pass in a single list of EITHER the columns to display, OR the columns to omit - but NOT both.

If you choose to make that modification then you can simply pass in a single List<string>

If you choose to keep your current design then you will need a class with two properties:

public class SelectedColumns {
    public List<string> displayed { get; set; }
    public List<string> omitted { get; set; }
}
Sam Axe
  • 33,313
  • 9
  • 55
  • 89
  • thanks for the answer, as you could see i am some times missing the obvious when pushing my self to come with new ideas . it does work with single passed List of Columns but i have made it sorted with another list within the method itself , i wanted it to be cleaned up to be a proper code so i could take an example from a professional developers . – LoneXcoder Dec 19 '12 at 20:19
  • by the way what is TLDR (: – LoneXcoder Dec 19 '12 at 20:21
  • you are quick Povilasp !! i have looked it up in google took you 23 secs to say that – LoneXcoder Dec 19 '12 at 20:22
  • I was writing an answer down bellow and already knew what it means - probably because I get that a lot :D – povilasp Dec 19 '12 at 20:25
  • I might as well use your approach... as I am not cleared out of the stage of how to process the UI request from user to be automatically processed on line for next stage , as it is for UI project that makes a kind of my own version of GridView in which it's settings is made via a Webforms approach instead of visual studio , so you could DIY your report no .net knowledge required – LoneXcoder Dec 19 '12 at 21:34
  • http://stackoverflow.com/questions/13908695/how-to-save-style-css-values-for-later-use-then-reload-those-values-back – LoneXcoder Dec 19 '12 at 21:40