Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Generating Live data for Chart WebPart

, 30 May 2011 CPOL
This post discusses how to generate the live data for "Chart WebPart for SharePoint 2010
ProspectsBI.zip
ProspectsBI
CallStatusDetails.stp
Prospects.stp
ProspectsBI
ProspectsBI.suo
bin
Debug
ProspectsBI.dll
ProspectsBI.wsp
EventReceiver1
SharePointProjectItem.spdata
Features
Feature1
Feature1.feature
key.snk
Package
Package.package
pkg
pkgobj
Debug
TokenReplaceFolder
ProspectsBI_Feature1
EventReceiver1
Debug
ProspectsBI
ProspectsBI.dll
ProspectsBI_Feature1
EventReceiver1
Properties
ProspectsBI.csproj.user
using System;
using System.Data;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace ProspectsBI.EventReceiver1
{
    /// <summary>
    /// List Item Events
    /// </summary>
      
    public class EventReceiver1 : SPItemEventReceiver
    {
       /// <summary>
       /// An item was added.
       /// </summary>
        SPSite site;
        SPWeb web;
       public override void ItemAdded(SPItemEventProperties properties)
       {
           int NCalledNumbers = retrieveRowCount("Not Called", "NCalled");
           UpdateRecord("Not Called", NCalledNumbers);

           //int NINumbers = retrieveRowCount("Not Interested", "NI");
           //UpdateRecord("Not Interested", NINumbers);

           //int PS = retrieveRowCount("Proposal Sent", "PS");
           //UpdateRecord("Proposal Sent", PS);

           //int PR = retrieveRowCount("Proposal Requested", "PR");
           //UpdateRecord("Proposal Requested", PR);

       }

       /// <summary>
       /// An item was updated.
       /// </summary>
       public override void ItemUpdated(SPItemEventProperties properties)
       {
           int NCalledNumbers = retrieveRowCount("Not Called", "NCalled");
           UpdateRecord("Not Called", NCalledNumbers);

           //int NINumbers = retrieveRowCount("Not Interested", "NI");
           //UpdateRecord("Not Interested", NINumbers);

           //int PS = retrieveRowCount("Proposal Sent", "PS");
           //UpdateRecord("Proposal Sent", PS);

           //int PR = retrieveRowCount("Proposal Requested", "PR");
           //UpdateRecord("Proposal Requested", PR);


       }

       /// <summary>
       /// An item was deleted.
       /// </summary>
       public override void ItemDeleted(SPItemEventProperties properties)
       {
           int NCalledNumbers = retrieveRowCount("Not Called", "NCalled");
           UpdateRecord("Not Called", NCalledNumbers);

           //int NINumbers = retrieveRowCount("Not Interested", "NI");
           //UpdateRecord("Not Interested", NINumbers);

           //int PS = retrieveRowCount("Proposal Sent", "PS");
           //UpdateRecord("Proposal Sent", PS);

           //int PR = retrieveRowCount("Proposal Requested", "PR");
           //UpdateRecord("Proposal Requested", PR);


       }
       public void UpdateRecord(string Column, int rowCount)
       {
           SPList updateList = web.Lists["CallStatusDetails"];
           SPQuery UpdateDetailsSPQ = new SPQuery();
           string updateDetailQry = "<Where><Eq><FieldRef Name='CallStatus'/><Value Type='Text'>" + Column + "</Value></Eq></Where>";
           UpdateDetailsSPQ.Query = updateDetailQry;
           SPListItemCollection col = updateList.GetItems(UpdateDetailsSPQ);
           foreach (SPListItem item in col)
           {
               item["NumberOfCalls"] = rowCount.ToString();
               item.Update();
           }

       }
       public int retrieveRowCount(string Column, string rowName)
       {
           try
           {
               site = new SPSite("http://mosstemp:5000");

               web = site.OpenWeb();
               SPList list = web.Lists["Prospects"];
               SPQuery query = new SPQuery();
               string camlQuery = "<Where><Eq><FieldRef Name='Status'/><Value Type='Choice'>" + Column + "</Value></Eq></Where>";
               query.Query = camlQuery;
               DataTable dt = list.GetItems(query).GetDataTable();


               int a = 0;
               int aSumNCalled = 0;

               foreach (DataRow row in dt.Rows)
               {

                   if (row["Status"].ToString() == Column)
                   {
                       aSumNCalled = aSumNCalled + Convert.ToInt32(row[rowName].ToString());
                       a++;
                   }


               }
               SPList updateList = web.Lists["CallStatusDetails"];
               SPQuery UpdateDetailsSPQ = new SPQuery();
               string updateDetailQry = "<Where><Eq><FieldRef Name='CallStatus'/><Value Type='Text'>" + Column + "</Value></Eq></Where>";
               UpdateDetailsSPQ.Query = updateDetailQry;
               SPListItemCollection col = updateList.GetItems(UpdateDetailsSPQ);
               foreach (SPListItem item in col)
               {
                   item["NumberOfCalls"] = aSumNCalled.ToString();
                   item.Update();
               }

               return aSumNCalled;


           }


           catch (Exception eX)
           {
               throw eX;
           }
           finally
           {
               web.Close();
               web.Dispose();
               site.Close();
               site.Dispose();
           }
       }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150123.1 | Last Updated 30 May 2011
Article Copyright 2011 by SP.Murugesa Pandian
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid