c# - How to create report in windows Form using Report Viewe with an object Data Sourcer -


i'm using visual studio 2013 , widows form , want generate reports report viewer i'm new on topic. class wich must used object datasource

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace windowsformsapplication3 { public class result {     public string epc     {         get;         set;     }     public int nombreesseyage     {         get;         set;     }     public double dureeessay     {         get;         set;     }     public string marque     {         get;         set;     }     public string nom     {         get;         set;     }     public string couleur     {         get;         set;     }     string taille     {         get;         set;     }      public    result(string epc1, int nombreesseyage1, double dureeessay1,       string marque1, string nom1, string couleur1, string taille1) {     epc = epc1;     nombreesseyage = nombreesseyage1;     dureeessay = dureeessay1;     marque = marque1;     nom = nom1;     couleur = couleur1;     taille = taille1; } } } 

then data database , added code calculate 2 fields of classe result nombreessayage et dureeessay. code below:

namespace windowsformsapplication3 { public partial class form5 : form {     public form5()     {         initializecomponent();     }      private void button1_click(object sender, eventargs e)     {         sqlconnection cn; sqlcommand cmd; cn = new sqlconnection(@"data source=desktop-odcfvr1\sqlexpress;initial catalog=rfid;integrated security=true"); cn.open(); cmd = new sqlcommand("select  hab_essaye_epc, hab_essaye_time, article_marque, article_nom, article_couleur,article_taille  habits_essayes, habits hab_essaye_epc = article_epc , article_nom '%'+ @nom + '%'  , hab_essaye_epc not in (select hab_vendu_epc habits_vendus)", cn); cmd.parameters.add("@nom", sqldbtype.varchar, 30).value = textbox1.text; sqldataadapter da = new sqldataadapter(cmd); datatable datatable = new datatable(); // query database , return result datatable da.fill(datatable); string epcmoinun = ""; \\initialization of variables list<result> resultats = new list<result>(); datetime timemoinun = new datetime(); double dureeessayage = 0; int nombreessay = 0; string marquem = ""; string couleurm = ""; string nomm = ""; string taillem = ""; foreach (datarow row in datatable.rows) {     string epclocal = row["hab_essaye_epc"].tostring();     datetime timelocal = (datetime)row["hab_essaye_time"];     string marquel = row["article_marque"].tostring();     string couleurl = row["article_couleur"].tostring();     string noml = row["article_nom"].tostring();     string taillel = row["article_taille"].tostring();     if (timemoinun == null)     {         epcmoinun = epclocal;         nombreessay++;         timemoinun = timelocal;         marquem = marquel;         nomm = noml;         couleurm = couleurl;         taillem = taillel;     }     else     {         if (epcmoinun.equals(epclocal))         {             marquem = marquel;             nomm = noml;             couleurm = couleurl;             taillem = taillel;             var diff = (timelocal - timemoinun).totalminutes;             if (diff <= 2)             {                 dureeessayage = dureeessayage + diff;             }             else             {                 nombreessay++;             }              timemoinun = timelocal;         }         else         {             result rr = new result(epcmoinun, nombreessay, dureeessayage, marquem, nomm, couleurm, taillem);             resultats.add(rr);             epcmoinun = epclocal;             timemoinun = timelocal;             dureeessayage = 0;             nombreessay = 1;             marquem = marquel;             nomm = noml;             couleurm = couleurl;             taillem = taillel;         }     }     } result rr2 = new result(epcmoinun, nombreessay, dureeessayage, marquem, nomm, couleurm, taillem); resultats.add(rr2); chart1.datasource = resultats; chart2.datasource = resultats; chart1.series[0].isvalueshownaslabel = true; chart2.series[0].isvalueshownaslabel = true; chart1.chartareas[0].axisx.majorgrid.linewidth = 0; chart1.chartareas[0].axisy.majorgrid.linewidth = 0;  chart2.chartareas[0].axisx.majorgrid.linewidth = 0; chart2.chartareas[0].axisy.majorgrid.linewidth = 0;     foreach (result tt in resultats)     {         chart1.series[0].xvaluemember = "epc";         chart1.series[0].yvaluemembers = "nombreesseyage";         chart1.databind();         chart2.series[0].xvaluemember = "epc";         chart2.series[0].yvaluemembers = "dureeessay";         chart2.databind();         cn.close();         da.dispose();       }     }     }     } 

i added reportviwer project , selected result datasource. inserted chart. want set datasource "binding" , don't know how it.

can me? :)


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -