using System;

using System.Data;

using System.Web.UI;

using System.Web.UI.WebControls;

//                                                                .---.  

//                                                               /  .  \ 

//                                                              |\_/|   |    

//          (C)2000 for Colliers Jardine by Riley T. Perry      |   |  /|    

//   .----------------------------------------------------------------' |    

//  /  .-.                                                              |    

// |  /   \                  Admin Custom Controls                      |    

// | |\_.  |                 ~~~~~~~~~~~~~~~~~~~~~                      |    

// |\|  | /|                                                            |     

// | `---' | This a set of custom controls for Various CJ Systems.      |

// |       |                                                            |    

// |       |                                                           /     

// |       |----------------------------------------------------------'

// \       |                                                                                               

//  \     /                                                                                          

//   `---' 

namespace CommonControls

{

      //                                                 ,  ,

      //                                                / \/ \

      //                                              (/ //_ \_

      //     .-._                                      \||  .  \

      //      \  '-._                            _,:__.-"/---\_ \

      // ______/___  '.    .--------------------'~-'--.)__( , )\ \

      //`'--.___  _\  /    |  ColorsControl          ,'    \)|\ `\|

      //     /_.-' _\ \ _:,_  ~~~~~~~~~~~~~                " ||   (

      //   .'__ _.' \'-/,`-~` A list of colors and text      |/

      //       '. ___.> /=,|  boxes with values.             |

      //        / .-'/_ )  '---------------------------------'

      //        )'  ( /(/              Riley_Perry@hotmail.com

      //             \\ "

      //              '=='

      // 

 

      /// <remarks>

      /// A list of colors and text boxes with values.

      /// <seealso cref="Control"/>Inherits from Control</seealso>

      /// <seealso cref="INamingContainer"/>Inherits from INamingContainer</seealso>

      /// </remarks>

     

      public class ColorsControl : Control, INamingContainer

      {

            // Make table a member

 

            Table _table; 

     

            // Declare Constants

 

            const string DSN = "server=GROUPSQL01;uid=xxxx;pwd=xxxx;database=HR";

            const string SPNAME_GET_COLORS = "COMMON_GetColors";

            const string TABLENAME_GET_COLORS = "Colors";

 

            /// <summary>

            /// On initialisation of the control do nothing.

            /// </summary>

            /// <param name="e"></param>

           

            protected override void OnInit(EventArgs e)

            {

            }

 

            /// <summary>

            /// All child controls are created here.

            /// </summary>

           

            protected override void CreateChildControls()

            {

                  // Declare various control elements and data items

 

                  TableRow row;

                  TableCell cell;

                  Label text;

                  DataSet ds;

                 

                  try

                  {

                        // Grab the system colors

 

                        ds = GetColors();

                        DataTable dt = ds.Tables[0];

 

           

                        // Create a table

 

                        _table = new Table();

 

                        _table.Width = System.Web.UI.WebControls.Unit.Percentage(100);

                        _table.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);

                        _table.BorderColor = System.Drawing.Color.FromArgb(255, 232, 232, 232);

                        _table.CellSpacing = 1;

                        _table.CellPadding = 2;

 

                        Controls.Add(_table);

 

                        // Iterate through all rows in the data table

 

                        foreach (DataRow dr in dt.Rows)

                        {

 

                              // Create a row and add it to the table

              

                              row = new TableRow();

                              _table.Rows.Add(row);

 

                              // Create a cell that contains the title of the color

 

                              cell = new TableCell();

                             

                              cell.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);

                              cell.BackColor = System.Drawing.Color.FromArgb(255, 232, 232, 232);

                              cell.BorderColor = System.Drawing.Color.FromArgb(255, 0, 0, 0);

                             

                              row.Cells.Add(cell);

 

                              text = new Label();

                              text.Text = (dr[0].ToString());

                              cell.Controls.Add(text);

 

                              // Create a cell that contains s textbox with that color value

 

                              TextBox textbox;

                              textbox = new TextBox();

                              textbox.Text = dr[1].ToString();

                              textbox.Width = System.Web.UI.WebControls.Unit.Percentage(100);

                             

                              cell = new TableCell();

                              row.Cells.Add(cell);

                             

                              cell.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);

                              cell.BackColor = System.Drawing.Color.FromArgb(255, 204, 204, 204);

                              cell.BorderColor = System.Drawing.Color.FromArgb(255, 0, 0, 0);

                             

                              cell.Controls.Add(textbox);

                        }

                  }

                 

                  catch(System.Exception e)

                  {

 

                        throw e;

                       

                  }

            }

 

            /// <summary>

            /// Gets system colors and their values

            /// </summary>

            /// <returns>A dataset containing colors and their values</returns>

           

            private DataSet GetColors()

            {

 

                  // Declare data set and objects

 

                  DataSet myDataSet;                       

                                                       

                  System.Data.SqlClient.SqlDataAdapter myDataSetCommand;

                 

                  myDataSetCommand = new System.Data.SqlClient.SqlDataAdapter(SPNAME_GET_COLORS, DSN);

                  myDataSet = new DataSet();

 

                  try

                  {

 

                        // Specify the command type as a stored pocedure

 

                        myDataSetCommand.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;

 

                        // Fill the dataset

 

                        myDataSetCommand.Fill(myDataSet, TABLENAME_GET_COLORS);

 

                        // Return the dataset

 

                        return myDataSet;

 

                  }

 

                  catch(System.Exception e)

                  {

 

                        throw e;

                 

                  }

            }

      }

};