Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Tuesday, October 30, 2012

Binding Image along with Count of Tasks Real Time Task in SharePoint 2007 and SharePoint 2010



using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Security;

namespace CHSample.CHSample
{
    [ToolboxItemAttribute(false)]
    public class CHSample : WebPart
    {
        int strTaskCompleted;
        int StrTaskInProgress;
        int strTaskNotStarted;
        int strtaskDeferred;
        int strWaitingOnSomeoneElse;
        string strTaskCompletedImage=SPContext.Current.Web.Url+"/Shared Documents/Completed.JPG";
        string strTaskInProgressImage = SPContext.Current.Web.Url + "/Shared Documents/In Progress.JPG";
        string strTaskNotStartedImage = SPContext.Current.Web.Url + "/Shared Documents/Not Started.JPG";
        string strTaskDeferredImage = SPContext.Current.Web.Url + "/Shared Documents/Deferred.JPG";
        string strWaitingOnSomeoneElseImage = SPContext.Current.Web.Url + "/Shared Documents/Waiting on Soimeonle else.JPG";
        string strError = string.Empty;
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(strError);
            try
            {
                        
                writer.Write("<Table>");
                //Completed Status
                writer.Write("<Tr>");
                writer.Write("<Td>");
                writer.Write("<img src='"+strTaskCompletedImage+"' Title='Completed' border='0' width='25' height='25' />");
                writer.Write("</Td>");
                writer.Write("<Td>");
                writer.Write(strTaskCompleted);
                writer.Write("</Td>");
                writer.Write("</Tr>");
                //In Progress Status
                writer.Write("<Tr>");
                writer.Write("<Td>");
                writer.Write("<img src='" + strTaskInProgressImage + "' Title='In Progress' border='0' width='25' height='25' />");
                writer.Write("</Td>");
                writer.Write("<Td>");
                writer.Write(StrTaskInProgress);
                writer.Write("</Td>");
                writer.Write("</Tr>");
                //Deferred Status
                writer.Write("<Tr>");
                writer.Write("<Td>");
                writer.Write("<img src='" + strTaskDeferredImage + "' Title='Deferred' border='0' width='25' height='25' />");
                writer.Write("</Td>");
                writer.Write("<Td>");
                writer.Write(strtaskDeferred);
                writer.Write("</Td>");
                writer.Write("</Tr>");
                //Waiting on some one else Status
                writer.Write("<Tr>");
                writer.Write("<Td>");
                writer.Write("<img src='" + strWaitingOnSomeoneElseImage + "' Title='Waiting on someone else' border='0' width='25' height='25' />");
                writer.Write("</Td>");
                writer.Write("<Td>");
                writer.Write(strWaitingOnSomeoneElse);
                writer.Write("</Td>");
                writer.Write("</Tr>");
                //Not Started Status
                writer.Write("<Tr>");
                writer.Write("<Td>");
                writer.Write("<img src='" + strTaskNotStartedImage + "' Title='Not Started' border='0' width='25' height='25' />");
                writer.Write("</Td>");
                writer.Write("<Td>");
                writer.Write(strTaskNotStarted);
                writer.Write("</Td>");
                writer.Write("</Tr>");
                writer.Write("</Table>");
            }
            catch (Exception ex)
            {

                writer.Write(ex.ToString());
            }
        }
        protected override void CreateChildControls()
        {
            try
            {
                getData("Completed");
                getData("In Progress");
                getData("Not Started");
                getData("Deferred");
                getData("Waiting on someone else");
            }
            catch (Exception ex)
            {

                strError += ex.ToString();
            }
        }

        public void getData(string strStatus)
        {
            try
            {
                SPWeb currentWeb = SPContext.Current.Web;
            SPList lst = currentWeb.Lists["Tasks"];
            SPQuery sQuery = new SPQuery();
            sQuery.Query = "<Where><Eq><FieldRef Name='Status' /><Value Type='Choice'>" + strStatus + "</Value></Eq></Where>";
            SPListItemCollection myColl = lst.GetItems(sQuery);
            if (myColl.Count > 0)
            {
                if (strStatus == "Completed")
                {
                    strTaskCompleted = myColl.Count;
                }
                if (strStatus == "Not Started")
                {
                    strTaskNotStarted = myColl.Count;
                }
                if (strStatus == "Deferred")
                {
                    strtaskDeferred = myColl.Count;
                }
                if (strStatus == "In Progress")
                {
                    StrTaskInProgress = myColl.Count;
                }
                if (strStatus == "Waiting on someone else")
                {
                    strWaitingOnSomeoneElse = myColl.Count;
                }
            }
            else
            {
                if (strStatus == "Completed")
                {
                    strTaskCompleted = 0;
                }
                if (strStatus == "Not Started")
                {
                    strTaskNotStarted = 0;
                }
                if (strStatus == "Deferred")
                {
                    strtaskDeferred = 0;
                }
                if (strStatus == "In Progress")
                {
                    StrTaskInProgress = 0;
                }
                if (strStatus == "Waiting on someone else")
                {
                    strWaitingOnSomeoneElse = 0;
                }
            }
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
    }
}

No comments:

Post a Comment