c# - Multiple Linq.Tables in method -


i've created little bit of code adds data linq.tables (dc.gtmd_financials) usercontrol. every entry in database shows new usercontrol.

but use code in method reuse throughout application. problem each time call method use different table database (so gtmd_financials changes)

i can't seem figure out , appreciate form of or example.

        int locationcontrol = 78;         dataclasses1datacontext dc = new dataclasses1datacontext();          dc.gtmd_financials.tolist().foreach(x =>         {             kpientrys uc = new kpientrys();         // usercontrol              uc.kpi = x.kpi;                         // add data properties             uc.status = x.status.tostring();             uc.goal = x.goal.tostring();             uc.currently = x.currently.tostring();             bool checkaction = x.showaction == true ? uc.showaction = true : uc.showaction = false;             bool checkstats = x.showstats == true ? uc.showstats = true : uc.showstats = false;             bool checkstatus = x.status < x.statussignal ? uc.statusgood = true : uc.statusgood = false;              uc.location = new point(21, locationcontrol);             this.controls.add(uc);                  // add control form              locationcontrol = locationcontrol + 34;         }         );  

if unclear please let me know. in advance help.

edit:

i can't seem working got. able edit method little bit replys got:

    int locationcontrol = 78;     dataclasses1datacontext dc = new dataclasses1datacontext();      public list<control> loadkpis(table<gtmd_financial> dbtable)     {         var controls = new list<control>();                      dbtable.tolist().foreach(x =>         {             kpientrys uc = new kpientrys();              uc.kpi = x.kpi;             uc.status = x.status.tostring();             uc.goal = x.goal.tostring();             uc.currently = x.currently.tostring();             uc.showaction = (bool)x.showaction;             uc.showstats = (bool)x.showstats;             uc.statusgood = x.status < x.statussignal;             uc.location = new point(21, locationcontrol);              controls.add(uc);              locationcontrol = locationcontrol + 34;         }         );         return controls;     } 

so let me rephrase question: how can change class when call method: loadkpis(table<gtmd_financial> dbtable? gtmd_finacial changes.

write interface defines properties want use, , implement on business entities want use.

public interface imyreusableinterface {     string kpi { get; set; }     string status { get; set; }     // etc... }  public partial gtmd_financials: imyreusableinterface { } 

now can write reusable method accepts list of objects implement interface.

public list<control> myreusablemethod (list<imyreusableinterface> data) {     int locationcontrol = 78;     var controls = new list<control>();      foreach (var x in data) {         kpientrys uc = new kpientrys();         // usercontrol          uc.kpi = x.kpi;                         // add data properties         uc.status = x.status.tostring();         uc.goal = x.goal.tostring();         uc.currently = x.currently.tostring();         // i've simplefied boolean checks.         uc.showaction = x.showaction;         uc.showstats = x.showstats;         uc.statusgood = x.status < x.statussignal;         uc.location = new point(21, locationcontrol);          controls.add(uc);                  // add control form          locationcontrol = locationcontrol + 34;     }      return controls; } 

and use it:

dataclasses1datacontext dc = new dataclasses1datacontext(); this.controls.addrange(     myreusablemethod(         dc.gtmd_financials             .cast<imyreusableinterface>()             .tolist()     ) ); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -