protected override void CreateChildControls()
        {
            tb.AddTimer();
            act        = new EPMLiveCore.Act(SPContext.Current.Web);
            activation = act.CheckFeatureLicense(EPMLiveCore.ActFeature.Timesheets);

            if (activation != 0)
            {
                return;
            }

            if (SPContext.Current.ViewContext.View != null)
            {
                try
                {
                    typeof(ListTitleViewSelectorMenu).GetField("m_wpSingleInit", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(Page.FindControl("ctl00$PlaceHolderPageTitleInTitleArea$ctl01$ctl00").Controls[1], true);
                }
                catch { }
                try
                {
                    typeof(ListTitleViewSelectorMenu).GetField("m_wpSingle", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(Page.FindControl("ctl00$PlaceHolderPageTitleInTitleArea$ctl01$ctl00").Controls[1], true);
                }
                catch { }
            }

            try
            {
                sPeriodId = Page.Request["NewPeriod"].ToString();
            }
            catch { }
            try
            {
                sUserId = Page.Request["Delegate"].ToString();
            }
            catch { }

            ///

            SPWeb web = SPContext.Current.Web;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                settings = new TimesheetSettings(web);

                SqlConnection cn = new SqlConnection(EPMLiveCore.CoreFunctions.getConnectionString(web.Site.WebApplication.Id));
                cn.Open();

                SqlCommand cmd  = new SqlCommand("spTSGetPeriodsForSite", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@siteid", web.Site.ID);

                DataSet ds = new DataSet();

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);

                DataTable dtPeriods = ds.Tables[0];

                DataRow[] drCur = dtPeriods.Select("CurPeriod='1'");
                if (drCur.Length > 0)
                {
                    iCurPeriodId   = int.Parse(drCur[0]["period_id"].ToString());
                    sCurPeriodName = ((DateTime)drCur[0]["period_start"]).ToShortDateString() + " - " + ((DateTime)drCur[0]["period_end"]).ToShortDateString();
                }
                if (dtPeriods.Rows.Count > 0)
                {
                    if (sPeriodId == "")
                    {
                        DataRow[] dr = dtPeriods.Select("CurPeriod='1'");
                        if (dr.Length > 0)
                        {
                            sPeriodId   = dr[0]["period_id"].ToString();
                            sPeriodName = ((DateTime)dr[0]["period_start"]).ToShortDateString() + " - " + ((DateTime)dr[0]["period_end"]).ToShortDateString();
                            bIsCurrentTimesheetPeriod = true;
                        }
                        else
                        {
                            sPeriodId   = dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_id"].ToString();
                            sPeriodName = ((DateTime)dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_start"]).ToShortDateString() + " - " + ((DateTime)dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_end"]).ToShortDateString();
                        }
                    }
                    else
                    {
                        DataRow[] dr = ds.Tables[0].Select("period_id='" + sPeriodId + "'");
                        if (dr.Length > 0)
                        {
                            sPeriodName = ((DateTime)dr[0]["period_start"]).ToShortDateString() + " - " + ((DateTime)dr[0]["period_end"]).ToShortDateString();
                            try
                            {
                                if (dr[0]["curPeriod"].ToString() == "1")
                                {
                                    bIsCurrentTimesheetPeriod = true;
                                }
                            }
                            catch { }
                        }
                        else
                        {
                            DataRow[] dr2 = ds.Tables[0].Select("CurPeriod='1'");
                            if (dr2.Length > 0)
                            {
                                sPeriodId   = dr2[0]["period_id"].ToString();
                                sPeriodName = ((DateTime)dr2[0]["period_start"]).ToShortDateString() + " - " + ((DateTime)dr2[0]["period_end"]).ToShortDateString();
                                bIsCurrentTimesheetPeriod = true;
                            }
                            else
                            {
                                sPeriodId   = dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_id"].ToString();
                                sPeriodName = ((DateTime)dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_start"]).ToShortDateString() + " - " + ((DateTime)dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_end"]).ToShortDateString();
                            }
                        }
                    }

                    string itmpprev = "";
                    bool bNext      = false;

                    foreach (DataRow dr in dtPeriods.Rows)
                    {
                        sPeriodList += "," + dr["period_id"].ToString() + "|" + ((DateTime)dr["period_start"]).ToShortDateString() + " - " + ((DateTime)dr["period_end"]).ToShortDateString();

                        if (bNext)
                        {
                            bNext = false;

                            iNextPeriod = int.Parse(dr["period_id"].ToString());
                        }

                        if (dr["period_id"].ToString() == sPeriodId)
                        {
                            if (itmpprev != "")
                            {
                                iPreviousPeriod = int.Parse(itmpprev);
                            }
                            bNext = true;
                        }

                        itmpprev = dr["period_id"].ToString();
                    }

                    sPeriodList = sPeriodList.Trim(',');

                    TSNotes = settings.AllowNotes.ToString().ToLower();


                    cmd = new SqlCommand("SELECT TSTYPE_ID, TSTYPE_NAME FROM TSTYPE where SITE_UID=@siteid", cn);
                    cmd.Parameters.AddWithValue("@siteid", web.Site.ID);

                    SqlDataReader drTypes = cmd.ExecuteReader();
                    while (drTypes.Read())
                    {
                        int id = drTypes.GetInt32(0);

                        TSColType = 2;

                        TSTypeObject += ",T" + id + ": '" + drTypes.GetString(1) + "'";
                    }
                    drTypes.Close();


                    TSTypeObject = "{" + TSTypeObject.Trim(',') + "}";

                    ArrayList arrPeriods = TimesheetAPI.GetPeriodDaysArray(cn, settings, web, sPeriodId);

                    foreach (DateTime dtStart in arrPeriods)
                    {
                        TSCols += "\"P" + dtStart.Ticks + "\": true,";
                    }

                    foreach (DateTime dtStart in arrPeriods)
                    {
                        TSDCols += "\"P" + dtStart.Ticks + "\": \"" + settings.DayDef.Split('|')[(int)dtStart.DayOfWeek * 3 + 1] + "|" + settings.DayDef.Split('|')[(int)dtStart.DayOfWeek * 3 + 2] + "\",";
                    }

                    TSCols  = "{" + TSCols.Trim(',') + "}";
                    TSDCols = "{" + TSDCols.Trim(',') + "}";

                    if (GridType == 0)
                    {
                        SPUser user = TimesheetAPI.GetUser(web, sUserId);

                        cmd = new SqlCommand("SELECT submitted, approval_status, locked FROM TSTIMESHEET where SITE_UID=@siteid and period_id=@period and username=@username", cn);
                        cmd.Parameters.AddWithValue("@siteid", web.Site.ID);
                        cmd.Parameters.AddWithValue("@period", sPeriodId);
                        cmd.Parameters.AddWithValue("@username", user.LoginName);

                        SqlDataReader drTS = cmd.ExecuteReader();
                        if (drTS.Read())
                        {
                            //Locked
                            if (drTS.GetBoolean(2))
                            {
                                bTsLocked = true;
                            }

                            //Submitted
                            if (drTS.GetBoolean(0))
                            {
                                if (drTS.GetInt32(1) == 1)
                                {
                                    sStatus = "Approved";
                                    if (!settings.DisableApprovals)
                                    {
                                        bTsLocked = true;
                                    }
                                }
                                else if (drTS.GetInt32(1) == 2)
                                {
                                    sStatus = "Rejected";
                                }
                                else
                                {
                                    sStatus = "Submitted";
                                }
                            }
                        }
                        drTS.Close();
                    }
                    else
                    {
                        bTsLocked = true;
                    }


                    cn.Close();

                    bHasPeriods = true;
                }
            });



            sDataParam   = "<Param GridId=\"" + sFullGridId + "\" Period=\"" + sPeriodId + "\" UserId=\"" + sUserId + "\"/>";
            sLayoutParam = "<Param GridId=\"" + sFullGridId + "\" Period=\"" + sPeriodId + "\" UserId=\"" + sUserId + "\" Editable=\"" + iEditable + "\" GridType=\"" + GridType + "\"/>";

            sDataParam   = System.Web.HttpUtility.HtmlEncode(System.Web.HttpUtility.HtmlEncode(sDataParam));
            sLayoutParam = System.Web.HttpUtility.HtmlEncode(System.Web.HttpUtility.HtmlEncode(sLayoutParam));
            ///


            DataTable dtTsDelegates = EPMLiveCore.API.APITeam.GetResourcePool("<Resources FilterField=\"TimesheetDelegates\" FilterFieldValue=\"" + web.CurrentUser.Name + "\" ><Columns>SimpleColumns</Columns></Resources>", web);

            foreach (DataRow dr in dtTsDelegates.Rows)
            {
                if (sUserId == dr["SPID"].ToString())
                {
                    sCurrentDelegate = dr["Title"].ToString();
                }

                sDelegates += dr["SPID"].ToString() + "|" + dr["Title"].ToString() + "^";
            }

            sDelegates = sDelegates.Trim('^');

            string serviceUrl = ((SPContext.Current.Web.ServerRelativeUrl == "/")
                                     ? ""
                                     : SPContext.Current.Web.ServerRelativeUrl) + "/_vti_bin/Workengine.asmx";

            ScriptManager scriptManager = ScriptManager.GetCurrent(Page);

            if (scriptManager != null)
            {
                scriptManager.Services.Add(new ServiceReference(serviceUrl));
            }
            else
            {
                scriptManager = new ScriptManager();
                scriptManager.Services.Add(new ServiceReference(serviceUrl));

                Page.Form.Controls.Add(scriptManager);
            }

            views = TimesheetAPI.GetViews(web);

            tb.StopTimer();
        }