DataGridViewDownloadInfoCell.cs :  » Network-Clients » iReaper » IReaper » CourseData » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Network Clients » iReaper 
iReaper » IReaper » CourseData » DataGridViewDownloadInfoCell.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.ComponentModel;
using System.Windows.Forms.VisualStyles;
using IReaper.FileData;

namespace IReaper.CourseData{
    public class DataGridViewDownloadTaskCell : DataGridViewImageCell
    {
        #region static variable and constructor
        static Bitmap pptImage, codeImage, videoImage, qaImage, mp3Image, mp4Image, zuneImage;
        static Bitmap pptLightImage, codeLightImage, videoLightImage,qaLightImage,mp3LightImage, mp4LightImage, zuneLightImage;
        static Bitmap completeImage, emptyImage;
        static Graphics g;

        static DataGridViewDownloadTaskCell()
        {
            //load image
            //orignial
            int length = 0;
            length += 10;

            Image image = (Image)Properties.Resources.ResourceManager.GetObject("PPT_Small");
            pptImage = (Bitmap)image;
            pptImage.MakeTransparent(Color.White);
            length += 20;
            length += 10;
            codeImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("Code_Small");
            codeImage.MakeTransparent(Color.White);
            length += 20;
            length += 10;
            videoImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("Video_Small");
            videoImage.MakeTransparent(Color.White);
            length += 20;
            length += 10;
            qaImage = (Bitmap)Properties.Resources.qa.GetThumbnailImage(20, 20, null, IntPtr.Zero);
            qaImage.MakeTransparent(Color.White);
            length += 20;
            length += 10;
            mp3Image = Properties.Resources.mp3;
            mp3Image.MakeTransparent(Color.White);
            length += 20;
            length += 10;
            mp4Image = Properties.Resources.mp4;
            mp4Image.MakeTransparent(Color.White);
            length += 20;
            length += 10;
            zuneImage = Properties.Resources.Zune;
            zuneImage.MakeTransparent(Color.White);
            length += 20;
            length += 10;
            //light image
            pptLightImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("PPT_Light");
            pptLightImage.MakeTransparent(Color.White);
            codeLightImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("Code_Light");
            codeLightImage.MakeTransparent(Color.White);
            videoLightImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("Video_Light2");
            videoLightImage.MakeTransparent(Color.White);

            qaLightImage = (Bitmap)Properties.Resources.lightqa.GetThumbnailImage(20, 20, null, IntPtr.Zero);
            qaLightImage.MakeTransparent(Color.White);
            mp3LightImage = Properties.Resources.mp3_Gray;
            mp3LightImage.MakeTransparent(Color.White);
            mp4LightImage = Properties.Resources.mp4_Gray;
            mp4LightImage.MakeTransparent(Color.White);
            zuneLightImage = Properties.Resources.Zune_Gray;
            zuneLightImage.MakeTransparent(Color.White);
            //create an empty image
            completeImage = new Bitmap(length, 20, System.Drawing.Imaging.PixelFormat.Format64bppPArgb);
            emptyImage = new Bitmap(length, 20, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
            emptyImage.MakeTransparent(Color.Black);
            //get graphics object from completeImage
            g = Graphics.FromImage(completeImage);
        }
        #endregion

        protected override object GetFormattedValue(object value,
                            int rowIndex, ref DataGridViewCellStyle cellStyle,
                            TypeConverter valueTypeConverter,
                            TypeConverter formattedValueTypeConverter,
                            DataGridViewDataErrorContexts context)
        {
                if (this.DataGridView.Rows.Count < rowIndex)
                { return emptyImage; }
                Course course = null;
                try
                {
                    course = this.DataGridView.Rows[rowIndex].DataBoundItem as Course;
                }
                catch
                {
                    return emptyImage;
                }
                if (course == null)
                {
                    return emptyImage;
                }
                g.Clear(Color.Transparent);
                //draw reminder
                if (!Course.IsNewCourse(course))
                {
                    DrawOldCourse(course);
                }

                return completeImage;
        }

        private void DrawOldCourse(Course course)
        {
            //get thre course
            CourseFileData codeData = course.Code;
            CourseFileData vidoeData = course.Video;
            CourseFileData pptData = course.PPT;
            CourseFileData qaData = course.QA;
            CourseFileData mp3Data = course.MP3;
            CourseFileData mp4Data = course.MP4;
            CourseFileData wmvData = course.WMV;
            
            int offset = 10;
            //draw propimage;
            //draw ppt
            if (pptData == null)
            {
                g.DrawImage(emptyImage, offset, 0);
            }
            else if (pptData.LifetimeStatue == LifetimePosition.DownloadProcessed)
                g.DrawImage(pptImage, offset, 0);
            else
                g.DrawImage(pptLightImage, offset, 0);
            //draw video
            offset += 30;
            if (vidoeData == null)
                g.DrawImage(emptyImage, offset, 0);
            else if (vidoeData.LifetimeStatue == LifetimePosition.DownloadProcessed)
                g.DrawImage(videoImage, offset, 0);
            else
                g.DrawImage(videoLightImage, offset, 0);
            // draw zune
            offset += 30;
            if (wmvData == null)
                g.DrawImage(emptyImage, offset, 0);
            else if (wmvData.LifetimeStatue == LifetimePosition.DownloadProcessed)
                g.DrawImage(zuneImage, offset, 0);
            else
                g.DrawImage(zuneLightImage, offset, 0);
            // draw mp3
            offset += 30;
            if (mp3Data == null)
                g.DrawImage(emptyImage, offset, 0);
            else if (mp3Data.LifetimeStatue == LifetimePosition.DownloadProcessed)
                g.DrawImage(mp3Image, offset, 0);
            else
                g.DrawImage(mp3LightImage, offset, 0);

            // draw mp4
            offset += 30;
            if (mp4Data == null)
                g.DrawImage(emptyImage, offset, 0);
            else if (mp4Data.LifetimeStatue == LifetimePosition.DownloadProcessed)
                g.DrawImage(mp4Image, offset, 0);
            else
                g.DrawImage(mp4LightImage, offset, 0);
            //draw code
            offset += 30;
            if (codeData == null)
                g.DrawImage(emptyImage, offset, 0);
            else if (codeData.LifetimeStatue == LifetimePosition.DownloadProcessed)
                g.DrawImage(codeImage, offset, 0);
            else
                g.DrawImage(codeLightImage, offset, 0);
            //draw qa
            offset += 30;
            if (qaData == null)
                g.DrawImage(emptyImage, offset, 0);
            else if (qaData.LifetimeStatue == LifetimePosition.DownloadProcessed)
                g.DrawImage(qaImage, offset, 0);
            else
                g.DrawImage(qaLightImage, offset, 0);
                
        }

       
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.