Click here to Skip to main content
15,896,727 members
Articles / Multimedia / GDI+

Internal Supply Chain, Visibility via 200 plus 3D Chart Reports - Part II

Rate me:
Please Sign up or sign in to vote.
5.00/5 (15 votes)
8 Oct 2009CPOL4 min read 53.8K   5.3K   46  
This article focuses on internal supply chain management systems visibility via chart reports, and provides assessment apparatus to manage and monitor activities spawned during business processes, hence paves the way for timely and precise business decisions.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Security.Permissions;
using System.Threading;
using System.Drawing.Drawing2D;
using System.Diagnostics;
using System.Collections;


namespace ISCMS.Control
{
    public class Bars : Hasan.CustomLabel
    {

        int perspective_ID; 
       
        public int Perspective_ID 
        {
            get { return perspective_ID; }
            set { perspective_ID = value; }
        }

        int option_ID; 
        public int Option_ID
        {
            get { return option_ID; }
            set { option_ID = value; }
        }

        bool is_Event;
        public bool Is_Event
        {
            get { return is_Event; }
            set { is_Event = value; }
        }


        int iD;
        private System.Windows.Forms.Timer TimerBar;
    
        public int ID
        {
            get { return iD; }
            set { iD = value; }
        }

        string tag;
        public string Tag
        {
            get { return tag; }
            set { tag = value; }
        }

        public Bars()
            : base()
        {
            this.SetStyle(ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
            InitializeComponent();
        }


        #region Private Instance Variables

        //private DialogResult m_DialogResult;
        private bool m_IsDefault;

        //private int m_CornerRadius = 8;
        
        //private ContentAlignment m_ImageAlign = ContentAlignment.MiddleCenter;
        //private ContentAlignment m_TextAlign = ContentAlignment.MiddleCenter;
        //private ImageList m_ImageList;
        //private int m_ImageIndex = -1;

        //private bool keyPressed;
        private Rectangle contentRect;
        public float m_ValuePerPixel = 0.5F; 
        public float m_ValueDifference;
        
        public static bool Is_HoverEnable = true;

        #endregion


        private Hasan.CBalloonBase aForm = new Hasan.CBalloonBase();
        private IContainer components;
        public Hasan.CBalloonBase aFormConcreate = null;
        public static string m_Start_Date = "";

        public void NotifyDefault(bool value)
        {
            if (m_IsDefault != value)
                m_IsDefault = value;
            this.Invalidate();
        }


        #region Properties

       



        //DefaultSize
        protected override System.Drawing.Size DefaultSize
        {
            get { return new Size(75, 23); }
        }


        //IsDefault
        [Browsable(false)]
        public bool IsDefault
        {
            get { return m_IsDefault; }
        }


        #endregion

        #region Overriden Methods

       


        protected override void OnMouseClick(MouseEventArgs e)
        {

            float m_X = e.X;
            
            //System.Drawing.Point po = this.FindForm().PointToClient(System.Windows.Forms.Control.MousePosition);
            System.Drawing.Point poi = this.FindForm().PointToClient(System.Windows.Forms.Control.MousePosition);
            Bar barStruct;


            switch (perspective_ID)
            {
                case 0:
                    MessageBox.Show("Currently material does not have\n click functionality is only available at work in progress");
                    //Hasan.CMessageBox.ShowBox("Currently material does not have\n click functionality is only available at work in progress", (int)Hasan.CMessageBox.Type.Exclamation);
                    //Hasan.CMessageBoxSmall.ShowBox("Currently material does not have\n click functionality is only available at work in progress", (int)Hasan.CMessageBox.Type.Exclamation, 100,100);
                    return;

                case 2:
                    MessageBox.Show("Currently goods does not have\n click functionality is only available at work in progress");
                    //Hasan.CMessageBox.ShowBox("Currently goods does not have\n click functionality is only available at work in progress", (int)Hasan.CMessageBox.Type.Exclamation);
                    //Hasan.CMessageBoxSmall.ShowBox("Currently goods does not have\n click functionality is only available at work in progress", (int)Hasan.CMessageBox.Type.Exclamation, 100, 100);
                    return;
            }

           
            
            for (int i = 0; i < barArrayList.Count; i++)
            {
                barStruct = (Bar)barArrayList[i];
                if (m_X >= barStruct.initial_Point && m_X <= barStruct.final_Point)
                {
                    # region

                    
                    if (!Is_HoverEnable)
                        return;
                    if (aForm != null)
                        aForm.Dispose();
                    if (aFormConcreate != null)
                        aFormConcreate.Dispose();


                    if (barStruct.color == Color.DimGray)
                    {
                        Hasan.CMessageBoxSmall.ShowBox("Job is in its final phase \n no further trasition is possilbe", (int)Hasan.CMessageBox.Type.Exclamation, Location.X, Location.Y);
                        return;
                    }



                    if (perspective_ID == 1 && barStruct.Is_Final_Job_Status && barStruct.color != Color.DimGray)
                        Control.JobStatusBalloon.ShowBox(barStruct, poi, (MainForm)this.FindForm());
                    else
                    {
                        Hasan.CMessageBoxSmall.ShowBox("Dormant phase and cannot be altered", (int)Hasan.CMessageBox.Type.Exclamation, Location.X, Location.Y);
                        return;
                    }

                    #endregion
                }
            }
            base.OnMouseClick(e);
        }

        protected override bool ProcessMnemonic(char charCode)
        {
            if (IsMnemonic(charCode, this.Text))
            {
                base.OnClick(EventArgs.Empty);
                return true;
            }
            return base.ProcessMnemonic(charCode);
        }

        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);
            this.Invalidate();
        }

        protected override void OnMouseHover(EventArgs e)
        {
            //MessageBox.Show( "HOOVER" );
            base.OnMouseHover(e);
            //Bar_MouseMove(new object(), new MouseEventArgs(MouseButtons.Middle,1,0,0,1));
            this.Invalidate();
        }


        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseHover(e);
            Bar_MouseLeave(new object(), new EventArgs());
            this.Invalidate();
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
           
            Bar_MouseMove(new object(), e);
         //   Bar_MouseLeave(new object(), new EventArgs());
            //base.OnMouseLeave(
            this.Invalidate();
        }

        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            base.OnMouseDoubleClick(e);
            Bar_MouseLeave(new object(), new EventArgs());
            OnMouseClick(e);
        }

        public struct Bar
        {
            public float initial_Point, final_Point;
            public System.Drawing.Color color;
            public string date;
            public int ID;
            public string Status;
            public string Comments;
            public bool Is_Final_Job_Status;
            public int Job_Transaction_ID;
        }
      
        // identifing current bar context 
        bool IdentifyBarContext(System.Windows.Forms.Control cont)
        {
            
            switch (perspective_ID)
            {
                // Raw material current bar context 
                case 0:
                    if (option_ID == 0)
                        filter = " Goods_ID =" + iD;
                    if (option_ID == 1)
                        filter = " Date =  #" + cont.Text + "#";
                    rows = MainForm.data.Tables["GoodsCurrent"].Select(filter); 
                    break;

                // Work in progress current bar context
                case 1:
                    filter = " Job_ID = " + iD;
                    rows = MainForm.data.Tables["JobByDate"].Select(filter); 
                    break;

                // Finished goods current bar context
                case 2:
                    if (option_ID == 0)
                        filter = " Goods_ID =" + iD;
                    if (option_ID == 1)
                        filter = " Date =  #" + cont.Text + "#";
                    rows = MainForm.data.Tables["GoodsCurrent"].Select(filter); 
                    break;
            }
            return true;
        }

        void GenerateCurrentContextBarResutset(System.Windows.Forms.Control cont)
        {
               // Generate current bars resultsets
                switch (perspective_ID)
                {
                    // Generate raw material resultsets
                    case 0:
                        switch (option_ID)
                        {
                            // Generate raw material resultsets by date
                            case 0:
                                #region Generate non Event raw material resultsets by date
                                if (!is_Event)
                                {
                                
                                    if (rows.Length == 0)
                                    {
                                        DataAccess.Access ac = new ISCMS.DataAccess.Access();
                                        rows = ac.RawMaterialSingleCurrent( iD
                                           , this.Parent.Controls.Find("Date", true)[0].Text).Tables[0].Select();
                                    }

                                    barArray = new Bar[5];
                                    barArray[0].initial_Point = 0;
                                    barArray[0].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    // Incomming current
                                    if (((Convert.ToInt32(rows[0]["Incomming_Current"])) - temp) > 3)
                                    {

                                        barArray[0].final_Point =     
                                            (Convert.ToInt32(rows[0]["Incomming_Current"]) 
                                          //  - Convert.ToInt32(rows[0]["Outgoing_Finished"]) 
                                          //  - Convert.ToInt32(rows[0]["Outgoing_Expected"]) 
                                            - Convert.ToInt32(rows[0]["Outgoing_Waste"] )
                                            - Convert.ToInt32(rows[0]["Outgoing_InProcess"]) 
                                            - temp )* m_ValuePerPixel ;
                                        barArray[0].color = Color.Green;
                                        if( barArray[0].final_Point > 1 )
                                            barArrayList.Add(barArray[0]);
                                    }
                                    else
                                    {
                                        barArray[0].final_Point = 0;
                                    }

                                    // Incomming Expected
                                    barArray[1].initial_Point = barArray[0].final_Point++;
                                    barArray[1].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    if (((Convert.ToInt32(rows[0]["Incomming_Expected"])) - temp) > 3)
                                    {
                                        barArray[1].final_Point = barArray[1].initial_Point 
                                            + ((Convert.ToInt32(rows[0]["Incomming_Expected"]) 
                                            - temp) * m_ValuePerPixel);
                                        barArray[1].color = Color.Orange;
                                        if (barArray[1].final_Point > 1)
                                        barArrayList.Add(barArray[1]);
                                    }
                                    else
                                    {
                                        barArray[1].final_Point = barArray[1].initial_Point;
                                    }

                                    // Outgoing Expected
                                    barArray[2].initial_Point = barArray[1].final_Point++;
                                    barArray[2].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    if (((Convert.ToInt32(rows[0]["Outgoing_Expected"])) - temp) > 3)
                                    {

                                        barArray[2].final_Point = barArray[2].initial_Point 
                                            + ((Convert.ToInt32(rows[0]["Outgoing_Expected"]) 
                                            - temp) * m_ValuePerPixel);
                                        barArray[2].color = Color.DarkBlue;
                                        if (barArray[2].final_Point > 1)
                                        barArrayList.Add(barArray[2]);
                                    }
                                    else
                                    {
                                        barArray[2].final_Point = barArray[2].initial_Point;
                                    }

                                    // Outgoing In-Process
                                    //barArray[3].initial_Point = barArray[2].final_Point++;
                                    //barArray[3].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    //if (((Convert.ToInt32(rows[0]["Outgoing_InProcess"])) - temp) > 3)
                                    //{
                                    //    barArray[3].final_Point =  barArray[3].initial_Point 
                                    //        + (Convert.ToInt32(rows[0]["Outgoing_InProcess"]) 
                                    //        - temp) * m_ValuePerPixel;;
                                    //    barArray[3].color = Color.Yellow;
                                    //    if (barArray[3].final_Point > 1)
                                    //    {
                                    //        barArrayList.Add(barArray[3]);
                                    //    }
                                    //}
                                }
                                #endregion

                                #region  Generate Event raw material resultsets by date
                                if (is_Event)
                                {

                                    barArray = new Bar[rows.Length];
                                    float temp_Initial_Point = 0;
                                    for (int i = 0; i < rows.Length; i++)
                                    {
                                        barArray[i].final_Point =  temp_Initial_Point + (Convert.ToInt32(rows[i]["Unit"]) - temp )  * m_ValuePerPixel;;;
                                        barArray[i].initial_Point = temp_Initial_Point - temp;
                                        temp_Initial_Point = barArray[i].final_Point + temp;// temp_Initial_Point + Convert.ToInt32(rows[0]["Unit"]);
                                        barArray[i].ID = Convert.ToInt32(rows[i]["Transaction_ID"]);

                                        // Incomming Expected
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 2)
                                        {
                                            barArray[i].color = Color.Orange;
                                        }

                                        // Incomming Current
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 1)
                                        {
                                            barArray[i].color = Color.Green;
                                        }

                                        // outgoing Expected 
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) ==2  )
                                        {
                                            barArray[i].color = Color.DarkBlue;
                                        }

                                        // outgoing In-Process
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 3)
                                        {
                                            barArray[i].color = Color.Yellow;
                                        }

                                        // Outgoing Finished
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 5)
                                        {
                                            barArray[i].color = Color.Black;
                                        }

                                        // Outgoing Waste
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 6)
                                        {
                                            barArray[i].color = Color.Red;
                                        }

                                        if (barArray[i].final_Point > 1)
                                        barArrayList.Add(barArray[i]);
                                    }
     
                                 
                                }
                                #endregion
                                break;
                            // Generate raw material resultsets by range
                            case 1:
                                #region Generate non Event raw material resultsets by range
                                if (!is_Event)
                                {
                                    if (rows.Length == 0)
                                    {
                                        DataAccess.Access ac = new ISCMS.DataAccess.Access();
                                        rows = ac.RawMaterialSingleCurrent(iD
                                                                    , this.Parent.Controls.Find("Tag", true)[0].Text).Tables[0].Select();
                                    }


                                    barArray = new Bar[5];
                                    barArray[0].initial_Point = 0;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    barArray[0].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    // Incomming current
                                    if (((Convert.ToInt32(rows[0]["Incomming_Current"])) - temp) > 3)
                                    {
                                        barArray[0].final_Point = ((Convert.ToInt32(rows[0]["Incomming_Current"]) 
                                          //  - Convert.ToInt32(rows[0]["Outgoing_Finished"]) 
                                          //  - Convert.ToInt32(rows[0]["Outgoing_Expected"]) 
                                            - Convert.ToInt32(rows[0]["Outgoing_Waste"] )
                                            - Convert.ToInt32(rows[0]["Outgoing_InProcess"])
                                            ) - temp) * m_ValuePerPixel;
                                        barArray[0].color = Color.Green;
                                        if (barArray[0].final_Point > 1)
                                        barArrayList.Add(barArray[0]);
                                    }
                                    else
                                    {
                                        barArray[0].final_Point = 0;
                                    }

                                    // Incomming Expected
                                    barArray[1].initial_Point = barArray[0].final_Point++;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    barArray[1].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    if (((Convert.ToInt32(rows[0]["Incomming_Expected"])) - temp) > 3)
                                    {
                                        barArray[1].final_Point = barArray[1].initial_Point + ( Convert.ToInt32(rows[0]["Incomming_Expected"]) - temp ) * m_ValuePerPixel; 
                                        barArray[1].color = Color.Orange;
                                        if (barArray[1].final_Point > 1)
                                        barArrayList.Add(barArray[1]);
                                    }
                                    else
                                    {
                                        barArray[1].final_Point = barArray[1].initial_Point;
                                    }

                                    // Outgoing Expected
                                    barArray[2].initial_Point = barArray[1].final_Point++;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    barArray[2].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    if (((Convert.ToInt32(rows[0]["Outgoing_Expected"])) - temp) > 3)
                                    {
                                        barArray[2].final_Point = barArray[2].initial_Point + ( Convert.ToInt32(rows[0]["Outgoing_Expected"]) - temp )* m_ValuePerPixel; ;
                                        barArray[2].color = Color.DarkBlue;
                                        if (barArray[2].final_Point > 1)
                                        barArrayList.Add(barArray[2]);
                                    }
                                    else
                                    {
                                        barArray[2].final_Point = barArray[2].initial_Point;
                                    }

                                    //// Outgoing In-Process
                                    //barArray[3].initial_Point = barArray[2].final_Point++;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    //barArray[3].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    //if (((Convert.ToInt32(rows[0]["Outgoing_InProcess"])) - temp) > 3)
                                    //{
                                    //    barArray[3].final_Point = barArray[3].initial_Point + ( Convert.ToInt32(rows[0]["Outgoing_InProcess"]) - temp ) * m_ValuePerPixel ;;
                                    //    barArray[3].color = Color.Yellow;
                                    //    if (barArray[3].final_Point > 1)
                                    //    barArrayList.Add(barArray[3]);
                                    //}
                                }
                                #endregion

                                #region Generate Event raw material resultsets by range
                                if (is_Event)
                                {


                                    barArray = new Bar[rows.Length];
                                    float temp_Initial_Point = 0;
                                    for (int i = 0; i < rows.Length; i++)
                                    {
                                        barArray[i].final_Point = temp_Initial_Point + ( Convert.ToInt32(rows[i]["Unit"]) - temp ) * m_ValuePerPixel ;;
                                        barArray[i].initial_Point = temp_Initial_Point - temp;
                                        temp_Initial_Point = barArray[i].final_Point + temp;// temp_Initial_Point + Convert.ToInt32(rows[0]["Unit"]);
                                        barArray[i].ID = Convert.ToInt32(rows[i]["Transaction_ID"]);


                                        // Incomming Expected Fullfilled
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 7)
                                        {
                                            // barArray[i].color =// Color.Green;
                                        }

                                        // Incomming Expected
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 2)
                                        {
                                            barArray[i].color = Color.Orange;
                                        }

                                        // Incomming Current
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 1)
                                        {
                                            barArray[i].color = Color.Green;
                                        }

                                        // outgoing Expected 
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 2)
                                        {
                                            barArray[i].color = Color.DarkBlue;
                                        }

                                        // outgoing Expected Fullfilled
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 7)
                                        {
                                            // barArray[i].color = //Color.Green;
                                        }

                                        // outgoing In-Process
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 3)
                                        {
                                            barArray[i].color = Color.Yellow;
                                        }

                                        // Outgoing Finished
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 5)
                                        {
                                            barArray[i].color = Color.Black;
                                        }

                                        // Outgoing Waste
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 6)
                                        {
                                            barArray[i].color = Color.Red;
                                        }


                                        if (barArray[i].final_Point > 1)
                                        barArrayList.Add(barArray[i]);
                                    }


                                }
                                #endregion
                                break;
                        }
                        break;
                    // Generate job resultsets
                    case 1:
                        switch (option_ID)
                        {
                            // Generate job resultsets by date
                            case 0:
                                #region Generate job resultsets by date
                                TimeSpan ts = new TimeSpan();
                                ts = DateTime.Parse(rows[0]["Start_Date_Time"].ToString()) - DateTime.Parse(Bars.m_Start_Date);
                                Bar[] barArrayFirst = new Bar[1];
                                barArrayFirst[0].initial_Point = (ts.Days + 1) * (100 * m_ValuePerPixel) + (ts.Hours * Convert.ToSingle(2.5 * m_ValuePerPixel)); // Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                ts = DateTime.Parse(rows[0]["End_Date_Time"].ToString()) - DateTime.Parse(Bars.m_Start_Date);
                                barArrayFirst[0].final_Point = (ts.Days + 1) * (100 * m_ValuePerPixel) + (ts.Hours * Convert.ToSingle(2.5 * m_ValuePerPixel)); ;
                                barArrayFirst[0].ID = Convert.ToInt32(rows[0]["Job_ID"]);
                                barArrayFirst[0].Job_Transaction_ID = 0;
                                barArrayFirst[0].Is_Final_Job_Status = true;

                                // Expected
                                if (Convert.ToInt32(rows[0]["Status_ID"]) == 2)
                                {
                                    cont.BackColor = Color.Orange;
                                    cont.ForeColor = Color.Black;
                                    barArrayFirst[0].color = Color.DarkBlue;
                                }

                                // In-Progress
                                if (Convert.ToInt32(rows[0]["Status_ID"]) == 3)
                                {
                                    cont.BackColor = Color.Green;
                                    cont.ForeColor = Color.White;
                                    barArrayFirst[0].color = Color.Black;
                                }

                                // Finished
                                if (Convert.ToInt32(rows[0]["Status_ID"]) == 5)
                                {
                                    cont.BackColor = Color.Yellow;
                                    cont.ForeColor = Color.Black;
                                    barArrayFirst[0].color = Color.DimGray;
                                }

                                // Waste
                                if (Convert.ToInt32(rows[0]["Status_ID"]) == 6)
                                {
                                    cont.BackColor = Color.Red;
                                    cont.ForeColor = Color.White;
                                    barArrayFirst[0].color = Color.Red;
                                }

                                if (barArrayFirst[0].final_Point > 1)
                                    barArrayList.Add(barArrayFirst[0]);

                                rows = MainForm.data.Tables["Job_TransactionByDate"].Select( "Job_ID = " + rows[0]["Job_ID"].ToString() );
                                barArray = new Bar[rows.Length];
                                 for (int i = 0; i < rows.Length; i++)
                                 {

                                     ts = DateTime.Parse(rows[i]["Start_Date_Time"].ToString()) - DateTime.Parse(Bars.m_Start_Date);

                                     barArray[i].initial_Point = ( (ts.Days + 1) * (100 * m_ValuePerPixel)) + (ts.Hours * Convert.ToSingle(2.5 * m_ValuePerPixel)); ;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                     ts = DateTime.Parse(rows[i]["End_Date_Time"].ToString()) - DateTime.Parse(Bars.m_Start_Date);
                                     barArray[i].final_Point = ((ts.Days + 1) * (100 * m_ValuePerPixel)) + (ts.Hours * Convert.ToSingle(2.5 * m_ValuePerPixel));
                                     barArray[i].ID = Convert.ToInt32(rows[i]["Job_ID"]);
                                     barArray[i].Job_Transaction_ID = Convert.ToInt32(rows[i]["Job_Transaction_ID"]);
                                     barArray[i].Is_Final_Job_Status = false;
                                     
                                     // Expected
                                     if (Convert.ToInt32(rows[i]["Status_ID"]) == 2)
                                     {
                                         barArray[i].color = Color.DarkBlue;
                                     }

                                     // In-Progress
                                     if (Convert.ToInt32(rows[i]["Status_ID"]) == 3)
                                     {
                                         barArray[i].color = Color.Black;
                                     }

                                     // Finished
                                     if (Convert.ToInt32(rows[i]["Status_ID"]) == 5)
                                     {
                                         barArray[i].color = Color.DimGray;
                                     }

                                     // Waste
                                     if (Convert.ToInt32(rows[i]["Status_ID"]) == 6)
                                     {
                                         barArray[i].color = Color.Red;
                                     }

                                     if (barArray[i].final_Point > 1)
                                         barArrayList.Add(barArray[i]);
                                 }
                                #endregion
                                 break;
                            // Generate job resultsets by range
                            case 1:
                                #region Generate job resultsets by range

                                ts = new TimeSpan();


                                ts = DateTime.Parse(rows[0]["Start_Date_Time"].ToString()) - DateTime.Parse(Bars.m_Start_Date);
                                
                                barArrayFirst = new Bar[1];
                                barArrayFirst[0].initial_Point = ( ts.Days + 1 ) * (100 * m_ValuePerPixel) + (ts.Hours * Convert.ToSingle(2.5 * m_ValuePerPixel)); // Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                ts = DateTime.Parse(rows[0]["End_Date_Time"].ToString()) - DateTime.Parse(Bars.m_Start_Date);
                                barArrayFirst[0].final_Point = ( ts.Days + 1 ) * (100 * m_ValuePerPixel) + (ts.Hours * Convert.ToSingle(2.5 * m_ValuePerPixel)); ;
                                barArrayFirst[0].ID = Convert.ToInt32(rows[0]["Job_ID"]);
                                barArrayFirst[0].Job_Transaction_ID = 0;
                                barArrayFirst[0].Is_Final_Job_Status = true;
                                // Expected
                                if (Convert.ToInt32(rows[0]["Status_ID"]) == 2)
                                {
                                    cont.BackColor = Color.Orange;
                                    cont.ForeColor = Color.Black;
                                    barArrayFirst[0].color = Color.DarkBlue;
                                }

                                // In-Progress
                                if (Convert.ToInt32(rows[0]["Status_ID"]) == 3)
                                {
                                    cont.BackColor = Color.Green;
                                    cont.ForeColor = Color.White;
                                    barArrayFirst[0].color = Color.Black;
                                }

                                // Finished
                                if (Convert.ToInt32(rows[0]["Status_ID"]) == 5)
                                {
                                    cont.BackColor = Color.Yellow;
                                    cont.ForeColor = Color.Black;
                                    barArrayFirst[0].color = Color.DimGray;
                                }

                                // Waste
                                if (Convert.ToInt32(rows[0]["Status_ID"]) == 6)
                                {
                                    cont.BackColor = Color.Red;
                                    cont.ForeColor = Color.White;
                                    barArrayFirst[0].color = Color.Red;
                                }


                                if ((   barArrayFirst[0].final_Point - barArrayFirst[0].initial_Point  ) > 2) //  barArrayFirst[0].final_Point > 2)
                                    barArrayList.Add(barArrayFirst[0]);

                                rows = MainForm.data.Tables["Job_TransactionByDate"].Select("Job_ID = " + rows[0]["Job_ID"].ToString());

                                barArray = new Bar[rows.Length];
                                for (int i = 0; i < rows.Length; i++)
                                {

                                    ts = DateTime.Parse(rows[i]["Start_Date_Time"].ToString()) - DateTime.Parse(Bars.m_Start_Date);

                                    barArray[i].initial_Point = ( ( ts.Days + 1 ) * (100 * m_ValuePerPixel)) + (ts.Hours * Convert.ToSingle(2.5 * m_ValuePerPixel)); ;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    ts = DateTime.Parse(rows[i]["End_Date_Time"].ToString()) - DateTime.Parse(Bars.m_Start_Date);
                                    barArray[i].final_Point = ( ( ts.Days + 1 ) * (100 * m_ValuePerPixel)) + (ts.Hours * Convert.ToSingle(2.5 * m_ValuePerPixel));
                                    barArray[i].ID = Convert.ToInt32(rows[i]["Job_ID"]);
                                    barArray[i].Job_Transaction_ID = Convert.ToInt32(rows[i]["Job_Transaction_ID"]);
                                    barArray[i].Is_Final_Job_Status = false;



                                    // Expected
                                    if (Convert.ToInt32(rows[i]["Status_ID"]) == 2)
                                    {
                                        barArray[i].color = Color.DarkBlue;
                                    }

                                    // In-Progress
                                    if (Convert.ToInt32(rows[i]["Status_ID"]) == 3)
                                    {
                                        barArray[i].color = Color.Black;
                                    }

                                    // Finished
                                    if (Convert.ToInt32(rows[i]["Status_ID"]) == 4)
                                    {
                                        barArray[i].color = Color.DimGray;
                                    }

                                    // Waste
                                    if (Convert.ToInt32(rows[i]["Status_ID"]) == 6)
                                    {
                                        barArray[i].color = Color.Red;
                                    }

                                    if ( (  barArray[i].final_Point - barArray[i].initial_Point ) > 2 )
                                        barArrayList.Add(barArray[i]);
                                }
                                #endregion
                                break;
                        }
                        break;
                    // Generate finished goods resultsets
                    case 2:
                        switch (option_ID)
                        {
                            // Generate finished goods resultsets by date
                            case 0:
                                #region Generate non Event finished goods resultsets by date
                                if (!is_Event)
                                {

                                    if (rows.Length == 0)
                                    {
                                        DataAccess.Access ac = new ISCMS.DataAccess.Access();
                                        rows = ac.RawMaterialSingleCurrent(iD
                                                                    , this.Parent.Controls.Find("Date", true)[0].Text).Tables[0].Select();
                                    }


                                    barArray = new Bar[5];
                                    barArray[0].initial_Point = 0;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    barArray[0].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    // Incomming current
                                    if (((Convert.ToInt32(rows[0]["Incomming_Current"])) - temp) > 3)
                                    {

                                        barArray[0].final_Point = ((Convert.ToInt32(rows[0]["Incomming_Current"]) + Convert.ToInt32(rows[0]["Incomming_Sold"]) - Convert.ToInt32(rows[0]["Outgoing_InProcess"]) 
                                            //- Convert.ToInt32(rows[0]["Outgoing_Expected"]) 
                                            - Convert.ToInt32(rows[0]["Outgoing_Sold"]) 
                                            - Convert.ToInt32(rows[0]["Outgoing_Waste"])) - temp) * m_ValuePerPixel; 
                                        barArray[0].color = Color.Green;
                                        if (barArray[0].final_Point > 1)
                                        barArrayList.Add(barArray[0]);
                                    }
                                    else
                                    {
                                        barArray[0].final_Point = 0;
                                    }

                                    // Incomming Expected
                                    barArray[1].initial_Point = barArray[0].final_Point++;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    barArray[1].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    if (((Convert.ToInt32(rows[0]["Incomming_Expected"])) - temp) > 3)
                                    {
                                        barArray[1].final_Point = barArray[1].initial_Point + (Convert.ToInt32(rows[0]["Incomming_Expected"]) - temp) * m_ValuePerPixel; 
                                        barArray[1].color = Color.Orange;
                                        if (barArray[1].final_Point > 1)
                                        barArrayList.Add(barArray[1]);
                                    }
                                    else
                                    {
                                        barArray[1].final_Point = barArray[1].initial_Point;
                                    }

                                    // Outgoing Expected
                                    barArray[2].initial_Point = barArray[1].final_Point++;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    barArray[2].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    if (((Convert.ToInt32(rows[0]["Outgoing_Expected"])) - temp) > 3)
                                    {

                                        barArray[2].final_Point = barArray[2].initial_Point + (Convert.ToInt32(rows[0]["Outgoing_Expected"]) - temp) * m_ValuePerPixel; ;
                                        barArray[2].color = Color.DimGray;
                                        if (barArray[2].final_Point > 1)
                                        barArrayList.Add(barArray[2]);
                                    }
                                    else
                                    {
                                        barArray[2].final_Point = barArray[2].initial_Point;
                                    }

                                    // Incomming In-Process
                                    barArray[3].initial_Point = barArray[2].final_Point++;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    barArray[3].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    if (((Convert.ToInt32(rows[0]["Incomming_InProcess"])) - temp) > 3)
                                    {
                                        barArray[3].final_Point = barArray[3].initial_Point + (Convert.ToInt32(rows[0]["Incomming_InProcess"]) - temp) * m_ValuePerPixel; ;
                                        barArray[3].color = Color.Yellow;
                                        if (barArray[3].final_Point > 1)
                                        barArrayList.Add(barArray[3]);
                                    }
                                }
                                #endregion

                                #region  Generate Event finished goods resultsets by date
                                if (is_Event)
                                {

                                    barArray = new Bar[rows.Length];
                                    float temp_Initial_Point = 0;
                                    for (int i = 0; i < rows.Length; i++)
                                    {
                                        barArray[i].final_Point =  temp_Initial_Point + (Convert.ToInt32(rows[i]["Unit"]) - temp ) * m_ValuePerPixel;;
                                        barArray[i].initial_Point = temp_Initial_Point - temp;
                                        temp_Initial_Point = barArray[i].final_Point + temp;// temp_Initial_Point + Convert.ToInt32(rows[0]["Unit"]);
                                        barArray[i].ID = Convert.ToInt32(rows[i]["Transaction_ID"]);
                                        // Incomming Expected Fullfilled
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 7)
                                        {
                                            // barArray[i].color =// Color.Green;
                                        }

                                        // Incomming Expected
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 2)
                                        {
                                            barArray[i].color = Color.Orange;
                                        }

                                        // Incomming In-Process
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 3)
                                        {
                                            barArray[i].color = Color.Yellow;
                                        }

                                        // Incomming Current
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 1)
                                        {
                                            barArray[i].color = Color.Green;
                                        }

                                        // Incomming Sold
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 4)
                                        {
                                            barArray[i].color = Color.DarkBlue;
                                        }

                                        // outgoing Expected 
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 2)
                                        {
                                            barArray[i].color = Color.DimGray;
                                        }

                                        // outgoing Expected Fullfilled
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 7)
                                        {
                                            // barArray[i].color = //Color.Green;
                                        }

                                        // outgoing In-Process
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 3)
                                        {
                                            barArray[i].color = Color.Yellow;
                                        }

                                        // outgoing Sold
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 4)
                                        {
                                            barArray[i].color = Color.DarkBlue;
                                        }

                                        // Outgoing Finished
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 5)
                                        {
                                            barArray[i].color = Color.Green;
                                        }

                                        // Outgoing Waste
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 6)
                                        {
                                            barArray[i].color = Color.Red;
                                        }


                                        if (barArray[i].final_Point > 1)
                                        barArrayList.Add(barArray[i]);
                                    }


                                }
                                #endregion
                                break;
                            // Generate finished goods resultsets by range
                            case 1:
                                #region Generate non Event raw material resultsets by range
                                if (!is_Event)
                                {
                                    if (rows.Length == 0)
                                    {
                                        DataAccess.Access ac = new ISCMS.DataAccess.Access();
                                        rows = ac.RawMaterialSingleCurrent( iD
                                                                    , this.Parent.Controls.Find("Tag", true)[0].Text).Tables[0].Select();
                                    }


                                    barArray = new Bar[5];
                                    barArray[0].initial_Point = 0;
                                    barArray[0].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    // Incomming current
                                    if (((Convert.ToInt32(rows[0]["Incomming_Current"])) - temp) > 3)
                                    {
                                        barArray[0].final_Point = ((Convert.ToInt32(rows[0]["Incomming_Current"]) + Convert.ToInt32(rows[0]["Incomming_Sold"]) 
                                            - Convert.ToInt32(rows[0]["Outgoing_InProcess"]) 
                                            - Convert.ToInt32(rows[0]["Outgoing_Sold"]) 
                                            //- Convert.ToInt32(rows[0]["Outgoing_Expected"]) 
                                            - Convert.ToInt32(rows[0]["Outgoing_Waste"])) - temp) * m_ValuePerPixel; ;
                                        barArray[0].color = Color.Green;
                                        
                                        if( barArray[0].final_Point > 2 )
                                            barArrayList.Add(barArray[0]);
                                    }
                                    else
                                    {
                                        barArray[0].final_Point = 0;
                                    }

                                    // Incomming Expected
                                    barArray[1].initial_Point = barArray[0].final_Point++;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    barArray[1].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    if (((Convert.ToInt32(rows[0]["Incomming_Expected"])) - temp) > 3)
                                    {
                                        barArray[1].final_Point = barArray[1].initial_Point + (Convert.ToInt32(rows[0]["Incomming_Expected"]) - temp) * m_ValuePerPixel; ;
                                        barArray[1].color = Color.Orange;
                                        barArrayList.Add(barArray[1]);
                                    }
                                    else
                                    {
                                        barArray[1].final_Point = barArray[1].initial_Point;
                                    }

                                    // Outgoing Expected
                                    barArray[2].initial_Point = barArray[1].final_Point++;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    barArray[2].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    if (((Convert.ToInt32(rows[0]["Outgoing_Expected"])) - temp) > 3)
                                    {

                                        barArray[2].final_Point = barArray[2].initial_Point + (Convert.ToInt32(rows[0]["Outgoing_Expected"]) - temp) * m_ValuePerPixel; ;
                                        barArray[2].color = Color.DimGray;

                                        barArrayList.Add(barArray[2]);
                                    }
                                    else
                                    {
                                        barArray[2].final_Point = barArray[2].initial_Point;
                                    }

                                    // Incomming In-Process
                                    barArray[3].initial_Point = barArray[2].final_Point++;// Convert.ToInt32(rows[i]["Incomming_Current"]) * m_ValuePerPixel - temp;
                                    barArray[3].ID = Convert.ToInt32(rows[0]["Goods_ID"]);
                                    if (((Convert.ToInt32(rows[0]["Incomming_InProcess"])) - temp) > 3)
                                    {
                                        barArray[3].final_Point = barArray[3].initial_Point + (Convert.ToInt32(rows[0]["Incomming_InProcess"]) - temp) * m_ValuePerPixel; ;
                                        barArray[3].color = Color.Yellow;
                                        barArrayList.Add(barArray[3]);
                                    }
                                }
                                #endregion

                                #region  Generate  Event raw material resultsets by range
                                if (is_Event)
                                {


                                    barArray = new Bar[rows.Length];
                                    float temp_Initial_Point = 0;
                                    for (int i = 0; i < rows.Length; i++)
                                    {
                                        barArray[i].final_Point =  temp_Initial_Point + ( Convert.ToInt32(rows[i]["Unit"]) - temp )  * m_ValuePerPixel;;
                                        barArray[i].initial_Point = temp_Initial_Point - temp;
                                        temp_Initial_Point = barArray[i].final_Point + temp;// temp_Initial_Point + Convert.ToInt32(rows[0]["Unit"]);
                                        barArray[i].ID = Convert.ToInt32(rows[i]["Transaction_ID"]);

                                        // Incomming Expected Fullfilled
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 7)
                                        {
                                            // barArray[i].color =// Color.Green;
                                        }

                                        // Incomming Expected
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 2)
                                        {
                                            barArray[i].color = Color.Orange;
                                        }

                                        // Incomming Current
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 1)
                                        {
                                            barArray[i].color = Color.Green;
                                        }

                                        // Incomming In-Process
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 3)
                                        {
                                            barArray[i].color = Color.Yellow;
                                        }

                                        // Incomming Sold
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 1 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 4)
                                        {
                                            barArray[i].color = Color.DarkBlue;
                                        }

                                        // outgoing Expected 
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 2)
                                        {
                                            barArray[i].color = Color.DimGray;
                                        }

                                        // outgoing Expected Fullfilled
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 7)
                                        {
                                            // barArray[i].color = //Color.Green;
                                        }

                                        // outgoing In-Process
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 3)
                                        {
                                            barArray[i].color = Color.Yellow;
                                        }

                                        // Outgoing Finished
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 5)
                                        {
                                            barArray[i].color = Color.Green;
                                        }

                                        // Outgoing Waste
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 6)
                                        {
                                            barArray[i].color = Color.Red;
                                        }

                                        // Sold
                                        if (Convert.ToInt32(rows[i]["Transaction_Type_ID"]) == 2 && Convert.ToInt32(rows[i]["Transaction_Status_ID"]) == 4)
                                        {
                                            barArray[i].color = Color.RoyalBlue;
                                        }



                                        barArrayList.Add(barArray[i]);
                                    }


                                }
                                #endregion
                                break;
                        }
                        break;
                }

           

        }

        void GenerateBars(PaintEventArgs pevent)
        {
            int generatedBarCount = 0;
            System.Drawing.Drawing2D.GraphicsPath path = new GraphicsPath();
            Pen drawingPen = new Pen(Color.Gray);
            Bar barStruct;
            Color shadeColor, fillColor;
            // defines magnitude of concern bar
            int bar = 0;
            Rectangle r = new Rectangle();

            int i = 0;
            int COUNTER = 0;
            //for ( i = 0; generatedBarCount < barArrayList.Count; i++)
            while (generatedBarCount < barArrayList.Count)
            {
                if (generatedBarCount >= barArrayList.Count)
                    goto Finish1;

                barStruct = (Bar)barArrayList[generatedBarCount];
                fillColor = barStruct.color;
                shadeColor = barStruct.color;
                bar = Convert.ToInt32(barStruct.final_Point) - Convert.ToInt32(barStruct.initial_Point);
                r = new Rectangle(0, 0, bar, 18);
                r.X = Convert.ToInt32(barStruct.initial_Point);
                r.Y += 4;
                i = i + bar;


                path = new GraphicsPath();
                path.AddRectangle(r);
                PathGradientBrush brush = new PathGradientBrush(path);
                brush.WrapMode = WrapMode.TileFlipX;
                brush.SurroundColors = new Color[] { shadeColor };
                brush.CenterColor = Color.White;

                //Draw the bar Background
                pevent.Graphics.FillPath(brush, path);

                //...and border
                pevent.Graphics.DrawPath(drawingPen, path);
                generatedBarCount++;
                brush.Dispose();
                i++;
               
            }

        Finish1:
            drawingPen.Dispose();
            path.Dispose();
        }

        string filter = "";
        Bar[] barArray;
        ArrayList barArrayList;
        float temp = 0;
        private static Mutex mut = new Mutex();
        System.Data.DataRow[] rows;


        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            mut.WaitOne();
            pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            Rectangle translateRect = this.Bounds;
            PaintEventArgs pe = new PaintEventArgs(pevent.Graphics, translateRect);
            this.InvokePaintBackground(this.Parent, pe);
           
            // calibrate scale on the bar
            MakeScale(pevent);
            // contains all bargrid's bar data
            barArrayList = new ArrayList();
            
           
            // user to shift scale initial reference point
            temp = (m_ValueDifference * 100) * m_ValuePerPixel;
          
            if ( MainForm.data != null)
            {
                System.Windows.Forms.Control cont = this.Parent.Controls.Find("Tag", true)[0];
                cont.BackColor = System.Drawing.SystemColors.Control;
                cont.ForeColor = Color.Black;

                if (!IdentifyBarContext(cont))
                    return;
                GenerateCurrentContextBarResutset(cont);
            }
            else
                // data is not initialized abort no need to go further
                return;  

            GenerateBars(pevent); 
            mut.ReleaseMutex();
        }



        
        private Single fontBoundY1;
        private Single fontBoundY2;

        // Calibrated bar frame
        protected void MakeScale(PaintEventArgs pe)
        {
            FindFontBounds();
            Bitmap Bitmap= new Bitmap(Width, Height, pe.Graphics);
            Graphics ggr = Graphics.FromImage(Bitmap);
            ggr.FillRectangle(new SolidBrush(System.Drawing.Color.Transparent), ClientRectangle);
            ggr.SmoothingMode = SmoothingMode.HighQuality;
            ggr.PixelOffsetMode = PixelOffsetMode.HighQuality;
            GraphicsPath gp = new GraphicsPath();
            ggr.SetClip(ClientRectangle);

            String valueText = "";
            SizeF boundingBox;
            Int32 counter1 = 0;
            Int32 scaleValueUnit = 0;
            Int32 scaleTemValueUnit = 0;
            Int32 scaleUnit = 0;

            while (scaleUnit <= 720)
            {
                ggr.DrawLine(new Pen(System.Drawing.Color.Gray, 2),
               (Single)scaleValueUnit,
               (Single)0,
               (Single)scaleValueUnit,
               (Single)35);
                valueText = "";
                boundingBox = ggr.MeasureString(valueText, Font, -1, StringFormat.GenericTypographic);
                scaleUnit++;
                scaleTemValueUnit = Convert.ToInt32(scaleTemValueUnit + (m_ValuePerPixel * 10));// scaleTemMinUnit + 5;
                scaleValueUnit = Convert.ToInt32(scaleValueUnit + (100 * m_ValuePerPixel));
                counter1++;
            }

            pe.Graphics.DrawImageUnscaled(Bitmap, 0, 0);
            pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            pe.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
        }

        #region helper
        private void FindFontBounds()
        {
            //find upper and lower bounds for numeric characters
            Int32 c1;
            Int32 c2;
            Boolean boundfound;
            Bitmap b;
            Graphics g;
            SolidBrush backBrush = new SolidBrush(Color.White);
            SolidBrush foreBrush = new SolidBrush(Color.Black);
            SizeF boundingBox;

            b = new Bitmap(5, 5);
            g = Graphics.FromImage(b);
            boundingBox = g.MeasureString("0123456789", Font, -1, StringFormat.GenericTypographic);
            b = new Bitmap((Int32)(boundingBox.Width), (Int32)(boundingBox.Height));
            g = Graphics.FromImage(b);
            g.FillRectangle(backBrush, 0.0F, 0.0F, boundingBox.Width, boundingBox.Height);
            g.DrawString("0123456789", Font, foreBrush, 0.0F, 0.0F, StringFormat.GenericTypographic);

            fontBoundY1 = 0;
            fontBoundY2 = 0;
            c1 = 0;
            boundfound = false;
            while ((c1 < b.Height) && (!boundfound))
            {
                c2 = 0;
                while ((c2 < b.Width) && (!boundfound))
                {
                    if (b.GetPixel(c2, c1) != backBrush.Color)
                    {
                        fontBoundY1 = c1;
                        boundfound = true;
                    }
                    c2++;
                }
                c1++;
            }

            c1 = b.Height - 1;
            boundfound = false;
            while ((0 < c1) && (!boundfound))
            {
                c2 = 0;
                while ((c2 < b.Width) && (!boundfound))
                {
                    if (b.GetPixel(c2, c1) != backBrush.Color)
                    {
                        fontBoundY2 = c1;
                        boundfound = true;
                    }
                    c2++;
                }
                c1--;
            }
        }
        #endregion

        protected override void OnPaint(PaintEventArgs e)
        {
            DrawImage(e.Graphics);
            DrawText(e.Graphics);
            DrawFocus(e.Graphics);
            base.OnPaint(e);
        }

        protected override void OnParentBackColorChanged(EventArgs e)
        {
            base.OnParentBackColorChanged(e);
            this.Invalidate();
        }


        protected override void OnParentBackgroundImageChanged(EventArgs e)
        {
            base.OnParentBackgroundImageChanged(e);
            this.Invalidate();
        }


        #endregion

        #region Internal Draw Methods

        private void DrawImage(Graphics g)
        {
            if (this.ImageList == null || this.ImageIndex == -1)
                return;
            if (this.ImageIndex < 0 || this.ImageIndex >= this.ImageList.Images.Count)
                return;

            Image _Image = this.ImageList.Images[this.ImageIndex];

            Point pt = Point.Empty;

            switch (this.ImageAlign)
            {
                case ContentAlignment.TopLeft:
                    pt.X = contentRect.Left;
                    pt.Y = contentRect.Top;
                    break;

                case ContentAlignment.TopCenter:
                    pt.X = (Width - _Image.Width) / 2;
                    pt.Y = contentRect.Top;
                    break;

                case ContentAlignment.TopRight:
                    pt.X = contentRect.Right - _Image.Width;
                    pt.Y = contentRect.Top;
                    break;

                case ContentAlignment.MiddleLeft:
                    pt.X = contentRect.Left;
                    pt.Y = (Height - _Image.Height) / 2;
                    break;

                case ContentAlignment.MiddleCenter:
                    pt.X = (Width - _Image.Width) / 2;
                    pt.Y = (Height - _Image.Height) / 2;
                    break;

                case ContentAlignment.MiddleRight:
                    pt.X = contentRect.Right - _Image.Width;
                    pt.Y = (Height - _Image.Height) / 2;
                    break;

                case ContentAlignment.BottomLeft:
                    pt.X = contentRect.Left;
                    pt.Y = contentRect.Bottom - _Image.Height;
                    break;

                case ContentAlignment.BottomCenter:
                    pt.X = (Width - _Image.Width) / 2;
                    pt.Y = contentRect.Bottom - _Image.Height;
                    break;

                case ContentAlignment.BottomRight:
                    pt.X = contentRect.Right - _Image.Width;
                    pt.Y = contentRect.Bottom - _Image.Height;
                    break;
            }

            //if (this.ButtonState == CustomLabelState.Pressed)
            //    pt.Offset(1, 1);

            if (this.Enabled)
                this.ImageList.Draw(g, pt, this.ImageIndex);
            else
                ControlPaint.DrawImageDisabled(g, _Image, pt.X, pt.Y, this.BackColor);

        }


        private void DrawText(Graphics g)
        {
            SolidBrush TextBrush = new SolidBrush(this.ForeColor);

            RectangleF R = (RectangleF)contentRect;

            if (!this.Enabled)
                TextBrush.Color = SystemColors.GrayText;

            StringFormat sf = new StringFormat(StringFormatFlags.NoWrap | StringFormatFlags.NoClip);

            if (ShowKeyboardCues)
                sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
            else
                sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide;

            switch (this.TextAlign)
            {
                case ContentAlignment.TopLeft:
                    sf.Alignment = StringAlignment.Near;
                    sf.LineAlignment = StringAlignment.Near;
                    break;

                case ContentAlignment.TopCenter:
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Near;
                    break;

                case ContentAlignment.TopRight:
                    sf.Alignment = StringAlignment.Far;
                    sf.LineAlignment = StringAlignment.Near;
                    break;

                case ContentAlignment.MiddleLeft:
                    sf.Alignment = StringAlignment.Near;
                    sf.LineAlignment = StringAlignment.Center;
                    break;

                case ContentAlignment.MiddleCenter:
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Center;
                    break;

                case ContentAlignment.MiddleRight:
                    sf.Alignment = StringAlignment.Far;
                    sf.LineAlignment = StringAlignment.Center;
                    break;

                case ContentAlignment.BottomLeft:
                    sf.Alignment = StringAlignment.Near;
                    sf.LineAlignment = StringAlignment.Far;
                    break;

                case ContentAlignment.BottomCenter:
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Far;
                    break;

                case ContentAlignment.BottomRight:
                    sf.Alignment = StringAlignment.Far;
                    sf.LineAlignment = StringAlignment.Far;
                    break;
            }

            //if (this.ButtonState == CustomLabelState.Pressed)
            //    R.Offset(1, 1);

            if (this.Enabled)
                g.DrawString(this.Text, this.Font, TextBrush, R, sf);
            else
                ControlPaint.DrawStringDisabled(g, this.Text, this.Font, this.BackColor, R, sf);

        }


        private void DrawFocus(Graphics g)
        {
            Rectangle r = contentRect;
            r.Inflate(1, 1);
            if (this.Focused && this.ShowFocusCues && this.TabStop)
                ControlPaint.DrawFocusRectangle(g, r, this.ForeColor, this.BackColor);
        }


        #endregion

        #region Helper Methods

       

        //The ControlPaint Class has methods to Lighten and Darken Colors, but they return a Solid Color.
        //The Following 2 methods return a modified color with original Alpha.
      

        private Color LightenColor(Color colorIn, int percent)
        {
            //This method returns White if you lighten by 100%

            if (percent < 0 || percent > 100)
                throw new ArgumentOutOfRangeException("percent");

            int a, r, g, b;

            a = colorIn.A;
            r = colorIn.R + (int)(((255f - colorIn.R) / 100f) * percent);
            g = colorIn.G + (int)(((255f - colorIn.G) / 100f) * percent);
            b = colorIn.B + (int)(((255f - colorIn.B) / 100f) * percent);

            return Color.FromArgb(a, r, g, b);
        }


        #endregion

        
       


        #region Custom TypeEditor for RoundCorners property

        [PermissionSetAttribute(SecurityAction.LinkDemand, Unrestricted = true)]
        [PermissionSetAttribute(SecurityAction.InheritanceDemand, Unrestricted = true)]
        public class RoundCornersEditor : UITypeEditor
        {
            public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
            {
                return UITypeEditorEditStyle.DropDown;
            }

         
        }

        #endregion

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.TimerBar = new System.Windows.Forms.Timer(this.components);
            this.SuspendLayout();
            // 
            // TimerBar
            // 
            this.TimerBar.Enabled = false;
            this.TimerBar.Interval = 1000;
            this.TimerBar.Tick += new System.EventHandler(this.Timer_Tick);
            // 
            // Bars
            // 
            this.BackColor = System.Drawing.SystemColors.Desktop;
            this.MouseLeave += new System.EventHandler(this.Bar_MouseLeave);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Bar_MouseMove);
            this.ResumeLayout(false);

        }
        

        public void Bar_MouseLeave(object sender, EventArgs e)
        {
            if (aForm != null)
                aForm.Close();
            //_Is_Mouse_Hoover = true;
        }

        System.Drawing.Point poLast = new Point(0, 0);

        static Thread m_WorkerThread;
        string lastTime = "1/1/2008";
        bool _Is_Mouse_Hoover = false;

        int counter = 0;
        private void Bar_MouseMove(object sender, MouseEventArgs e)
        {
            // bar array is not initialzie 
            if (barArrayList == null)
                return;

            // balloon dialog is not allowed to be open on hover
            if (!Is_HoverEnable)
                return;

            System.Drawing.Point po;

            _sameBaloonTimes = 0;
            counter++;
            //try
            //{
            //    if( m_WorkerThread.IsAlive )
            //        ;
            //      //  m_WorkerThread.Suspend();
            //}
            //catch { }
            //m_WorkerThread = new Thread(new ThreadStart(setBaloon));
            //m_WorkerThread.Start();

            //return;
           


            if (!_Is_Mouse_Hoover)
            {
                TimerBar.Stop();
                TimerBar.Enabled = false;
                TimerBar = new System.Windows.Forms.Timer();
                this.TimerBar.Enabled = true;
                this.TimerBar.Interval = 500;
                this.TimerBar.Tick += new System.EventHandler(this.Timer_Tick);
                po = this.FindForm().PointToClient(System.Windows.Forms.Control.MousePosition);
                poLast = po;
                TimerBar.Start();
                
                return;
            }
            _Is_Mouse_Hoover = false;
            //TimerBar.Enabled = true;
         
            // base ballon dialog is not null then dispose it
            po = this.FindForm().PointToClient(System.Windows.Forms.Control.MousePosition);
            System.Drawing.Point po2 = this.PointToClient(System.Windows.Forms.Control.MousePosition);

            //if (po.X == poLast.X && po.Y == poLast.Y)
            //    return;
            //MessageBox.Show(" x=" + po.X.ToString() + "," + poLast.X.ToString() + "     y=" + po.Y.ToString() + "," + poLast.Y.ToString());
         
            poLast = po;

          

            TimeSpan ts = DateTime.Now - DateTime.Parse(lastTime);
            lastTime = DateTime.Now.ToLongDateString();// ts.Seconds;

            //if (ts.Seconds < 1)
           //     return;


            //if (aForm != null)
            //    aForm.Close();


            
            float m_X = po2.X; 
            Bar barStruct;
            
            int DisplayShift = Convert.ToInt32(temp / m_ValuePerPixel * 0.5);

            #region Traversing current bar
            for (int i = 0; i < barArrayList.Count; i++)
            {
                barStruct = (Bar)barArrayList[i];

                // mouse is over generated bar
                if (m_X >= barStruct.initial_Point && m_X <= barStruct.final_Point)
                {

                    // Raw material balloon
                    if (perspective_ID == 0)
                    {
                        // Raw material non Event balloon dialog
                        if (!is_Event)
                        {
                            aForm = new GoodsBalloon(filter, this, barStruct.color, rows);
                        }
                        // Raw material Event balloon dialog
                        else
                        {
                            aForm = new ActivityBalloon(barStruct.ID, barStruct.color);
                        }
                    }


                    // Job ballloon dialog
                    if (perspective_ID == 1)
                    {
                        aForm = new JobBalloon(barStruct.ID, barStruct.Job_Transaction_ID, barStruct.Is_Final_Job_Status, barStruct.color);
                    }

                    // Finished Goods ballloon
                    if (perspective_ID == 2)
                    {
                        // Finished Goods non Event balloon dialog
                        if (!is_Event)
                        {
                            aForm = new GoodsBalloon(filter, this, barStruct.color, rows);
                        }
                        // Finished Goods Event balloon dialog
                        else
                        {
                            aForm = new ActivityBalloon(barStruct.ID, barStruct.color);
                        }
                    }

                    // Displaying selected balloon dialog 
                    aForm.setBalloonPosition(this.FindForm(), po);
                    aForm.Show();
                    poBaloonLast = po;
                    this.Focus();
                    return;
                }
            }
            #endregion
          

            // mouse is not on generated bar
            string tag = "";
            string name = "";

            switch (perspective_ID)
            {
                case 0:
                    tag = "Raw Material";
                    name = this.Parent.Controls.Find("Tag", true)[0].Text;
                    break;
                case 1:
                    tag = "Job ID";
                    name = this.Parent.Controls.Find("Tag", true)[0].Text;
                    break;
                case 2:
                    tag = "Finished Goods";
                    name = this.Parent.Controls.Find("Tag", true)[0].Text;
                    break;
            }
            try
            {
                aForm = new VacantBalloon(tag, name);
                aForm.setBalloonPosition(this.FindForm(), po);
                aForm.Show();
                poBaloonLast = po;
            }
            catch
            {
                aForm = null;
            }
            this.Focus();
        }


        System.Drawing.Point poBaloonLast = new Point(0, 0);
        int _sameBaloonTimes = 0;

        System.Drawing.Point po;
        System.Drawing.Point po2; 
        void setBaloon()
        {
            try
            {
               po  = this.FindForm().PointToClient(System.Windows.Forms.Control.MousePosition);
               po2 = this.PointToClient(System.Windows.Forms.Control.MousePosition);
            }
            catch
            { return; }

            if (po.X == poLast.X && po.Y == poLast.Y)
            {

            }
            else
                return;
            TimerBar.Enabled = false;
            //if (aForm.Location.X == po.X && aForm.Location.Y == po.Y )
            //    return;

            if (po.X == poBaloonLast.X && po.Y == poBaloonLast.Y)
            {
                _sameBaloonTimes++; 
            }

            if (_sameBaloonTimes > 0)
                return;
            
            ////MessageBox.Show(poBaloonLast.X.ToString() + "__" + poBaloonLast.Y.ToString() +
            //    "------" + po.X.ToString() + "___" + po.Y.ToString()); 

            poLast = po;


            
            //// base ballon dialog is not null then dispose it
            if (aForm != null)
                aForm.Close();




            float m_X = po2.X;
            Bar barStruct;

            int DisplayShift = Convert.ToInt32(temp / m_ValuePerPixel * 0.5);

            #region Traversing current bar
            for (int i = 0; i < barArrayList.Count; i++)
            {
                barStruct = (Bar)barArrayList[i];

                // mouse is over generated bar
                if (m_X >= barStruct.initial_Point && m_X <= barStruct.final_Point)
                {

                    // Raw material balloon
                    if (perspective_ID == 0)
                    {
                        // Raw material non Event balloon dialog
                        if (!is_Event)
                        {
                            aForm = new GoodsBalloon(filter, this, barStruct.color, rows);
                        }
                        // Raw material Event balloon dialog
                        else
                        {
                            aForm = new ActivityBalloon(barStruct.ID, barStruct.color);
                        }
                    }


                    // Job ballloon dialog
                    if (perspective_ID == 1)
                    {
                        aForm = new JobBalloon(barStruct.ID, barStruct.Job_Transaction_ID, barStruct.Is_Final_Job_Status, barStruct.color);
                    }

                    // Finished Goods ballloon
                    if (perspective_ID == 2)
                    {
                        // Finished Goods non Event balloon dialog
                        if (!is_Event)
                        {
                            aForm = new GoodsBalloon(filter, this, barStruct.color, rows);
                        }
                        // Finished Goods Event balloon dialog
                        else
                        {
                            aForm = new ActivityBalloon(barStruct.ID, barStruct.color);
                        }
                    }

                    // Displaying selected balloon dialog 
                    aForm.setBalloonPosition(this.FindForm(), po);
                    aForm.Show();
                    poBaloonLast = po;
                    this.Focus();
                    return;
                }
            }
            #endregion


            // mouse is not on generated bar
            string tag = "";
            string name = "";

            switch (perspective_ID)
            {
                case 0:
                    tag = "Raw Material";
                    name = this.Parent.Controls.Find("Tag", true)[0].Text;
                    break;
                case 1:
                    tag = "Job ID";
                    name = this.Parent.Controls.Find("Tag", true)[0].Text;
                    break;
                case 2:
                    tag = "Finished Goods";
                    name = this.Parent.Controls.Find("Tag", true)[0].Text;
                    break;
            }
            //try
            {
                aForm = new VacantBalloon(tag, name + "__" + _sameBaloonTimes.ToString() + "__" + counter.ToString());
                aForm.setBalloonPosition(this.FindForm(), po);
                poBaloonLast = po;
                aForm.Show();
            }
        //    catch
            {
          //      aForm = null;
            }
            this.Focus();
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            //MessageBox.Show("timer");
            setBaloon();
            _Is_Mouse_Hoover = false;
        }







    }

}

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)


Written By
Software Developer
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
This is a Organisation

33 members

Comments and Discussions