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(); }
public void execute(SPSite site, string data) { DataTable dtItems = null; int userid = 0; WebAppId = site.WebApplication.Id; using (SqlConnection cn = CreateConnection()) { try { cn.Open(); try { WorkList = site.RootWeb.Lists["My Work"]; } catch { } XmlDocument docTimesheet = new XmlDocument(); docTimesheet.LoadXml(data); using (SqlCommand cmd = new SqlCommand("SELECT dbo.TSUSER.USER_ID FROM dbo.TSUSER INNER JOIN dbo.TSTIMESHEET ON dbo.TSUSER.TSUSERUID = dbo.TSTIMESHEET.TSUSER_UID WHERE TS_UID=@tsuid", cn)) { cmd.Parameters.AddWithValue("@tsuid", base.TSUID); using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.Read()) { userid = dr.GetInt32(0); } } } //bool SaveAndSubmit = false; //try //{ // SaveAndSubmit = bool.Parse(docTimesheet.FirstChild.Attributes["SaveAndSubmit"].Value); //} //catch { } bool liveHours = false; bool.TryParse(EPMLiveCore.CoreFunctions.getConfigSetting(site.RootWeb, "EPMLiveTSLiveHours"), out liveHours); if (userid != 0) { SPUser user = TimesheetAPI.GetUser(site.RootWeb, userid.ToString()); if (user.ID != userid) { bErrors = true; sErrors = "You do not have access to edit that timesheet."; } else { using (SqlCommand cmd1 = new SqlCommand("update TSQUEUE set percentcomplete=1 where TSQUEUE_ID=@QueueUid", cn)) { cmd1.Parameters.AddWithValue("@queueuid", QueueUid); cmd1.ExecuteNonQuery(); } TimesheetSettings settings = new TimesheetSettings(site.RootWeb); DataSet dsItems = new DataSet(); SPUser editUser = site.RootWeb.AllUsers.GetByID(base.userid); using (var cache = SaveDataJobExecuteCache.InitializeCache(site)) { using (SqlCommand cmd2 = new SqlCommand("SELECT * FROM TSITEM WHERE TS_UID=@tsuid", cn)) { cmd2.Parameters.AddWithValue("@tsuid", base.TSUID); using (SqlDataAdapter da = new SqlDataAdapter(cmd2)) { da.Fill(dsItems); dtItems = dsItems.Tables[0]; XmlNodeList ndItems = docTimesheet.FirstChild.SelectNodes("Item"); float percent = 0; float count = 0; float total = ndItems.Count; using (SqlCommand cmd3 = new SqlCommand("update TSQUEUE set percentcomplete=2 where TSQUEUE_ID=@QueueUid", cn)) { cmd3.Parameters.AddWithValue("@queueuid", QueueUid); cmd3.ExecuteNonQuery(); } string preloadErrors; var preloadHasErrors = cache.PreloadListItems(ndItems.Cast <XmlNode>().Select(i => new SaveDataJobExecuteCache.ListItemInfo { WebId = iGetAttribute(i, "WebID"), ListId = iGetAttribute(i, "ListID"), ListItemId = iGetAttribute(i, "ItemID") }), out preloadErrors); if (preloadHasErrors) { bErrors = true; sErrors += preloadErrors; } foreach (XmlNode ndItem in ndItems) { string worktype = ""; try { worktype = ndItem.Attributes["WorkTypeField"].Value; } catch { } ProcessItemRow(ndItem, dtItems, cn, site, settings, liveHours, worktype == settings.NonWorkList); count++; float pct = count / total * 98; if (pct >= percent + 10) { using (SqlCommand cmd4 = new SqlCommand("update TSQUEUE set percentcomplete=@pct where TSQUEUE_ID=@QueueUid", cn)) { cmd4.Parameters.AddWithValue("@queueuid", QueueUid); cmd4.Parameters.AddWithValue("@pct", pct); cmd4.ExecuteNonQuery(); } percent = pct; } } } } if (liveHours) { sErrors += processProjectWork(cn, TSUID.ToString(), site, true, false); } } } } else { bErrors = true; sErrors = "Timesheet does not exist"; } } catch (Exception ex) { bErrors = true; sErrors = "Error: " + ex.ToString(); } finally { if (dtItems != null) { dtItems.Dispose(); } if (site != null) { site.Dispose(); } data = null; } } }
protected override void RenderWebPart(HtmlTextWriter output) { tb.AddTimer(); if (SPContext.Current.ViewContext.View != null) { foreach (System.Web.UI.WebControls.WebParts.WebPart wp in WebPartManager.WebParts) { try { if (wp.ToString() == "Microsoft.SharePoint.WebPartPages.XsltListViewWebPart" || wp.ToString() == "Microsoft.SharePoint.WebPartPages.ListViewWebPart") { wp.Visible = false; } } catch { } } } if (activation != 0) { output.Write(act.translateStatus(activation)); return; } if (!bHasPeriods) { output.WriteLine("There are no periods setup for this TimeSheet. Please contact your system administrator"); return; } output.WriteLine(@"<style> .GMBodyRight { border-right: 1px solid #DDD!important; } .GMBodyRight .GMCell { border-left: 1px solid #DDD!important; border-bottom: 1px solid #DDD!important; overflow: visible; } .GMCellHeader, .GMCellHeaderPanel, .GMCell, .GMCellPanel { border-bottom: 1px solid #DDD!important; } .Totals { font-weight: bold; } .GMFootRight { border-left: 2px solid #ccc } .GMFootRight .GMCell { border-left: 1px solid #DDD!important; border-bottom: 1px solid #DDD!important; } .HideCol0StopWatch { background-position: 0px center !important; } .TSBold { font-weight: bold !important; } .GMPx0xx { background: none; opacity: 1; } #ddlFilterControl .caret {display:none;} </style>"); string sUserId = ""; if (!string.IsNullOrEmpty(Page.Request["Delegate"])) { SPUser user = TimesheetAPI.GetUser(SPContext.Current.Web, Page.Request["Delegate"]); sUserId = user.ID.ToString(); } bCanEditViews = SPContext.Current.Web.DoesUserHavePermissions(SPBasePermissions.ManageWeb); string url = SPContext.Current.Web.Url; if (url == "/") { url = ""; } string curUrl = Page.Request.RawUrl.ToString(); if (curUrl.Contains("?")) { curUrl = curUrl.Substring(0, curUrl.IndexOf("?") + 1); } foreach (string key in Page.Request.QueryString.AllKeys) { if (key.ToString().ToLower() != "newperiod" && key.ToString().ToLower() != "delegate") { curUrl += key + "=" + Page.Request.QueryString[key] + "&"; } } int counter = 0; bool IsDefaultAvailable = false; foreach (KeyValuePair <string, Dictionary <string, string> > key in views.Views) { try { if (key.Value["Default"].ToLower() == "true") { sCurrentView = key.Key; sCurrentViewId = "V" + counter; IsDefaultAvailable = true; } } catch { } counter++; } if (!IsDefaultAvailable) { counter = 0; foreach (KeyValuePair <string, Dictionary <string, string> > key in views.Views) { try { sCurrentView = key.Key; sCurrentViewId = "V" + counter; } catch { } counter++; } } curUrl = curUrl.Trim('&').Trim('?'); System.Globalization.CultureInfo cInfo = new System.Globalization.CultureInfo(1033); IFormatProvider culture = new System.Globalization.CultureInfo(cInfo.Name, true); System.Globalization.CultureInfo nInfo = new System.Globalization.CultureInfo(SPContext.Current.Web.Locale.LCID); output.WriteLine(@"<script language=""javascript""> var TSObject" + sFullGridId + @" = new Object(); TSObject" + sFullGridId + @".canSave = true; TSObject" + sFullGridId + @".id = '" + sFullGridId + @"'; TSObject" + sFullGridId + @".Periods = '" + sPeriodList + @"'; TSObject" + sFullGridId + @".PeriodName = '" + sPeriodName + @"'; TSObject" + sFullGridId + @".PeriodId = " + sPeriodId + @"; TSObject" + sFullGridId + @".UserId = '" + sUserId + @"'; TSObject" + sFullGridId + @".DecimalSeparator='" + nInfo.NumberFormat.NumberDecimalSeparator + @"'; TSObject" + sFullGridId + @".GroupSeparator='" + nInfo.NumberFormat.NumberGroupSeparator + @"'; TSObject" + sFullGridId + @".IsCurPeriod = " + bIsCurrentTimesheetPeriod.ToString().ToLower() + @"; TSObject" + sFullGridId + @".CurPeriodId = " + iCurPeriodId + @"; TSObject" + sFullGridId + @".CurPeriodName = '" + sCurPeriodName + @"'; TSObject" + sFullGridId + @".PreviousPeriod = " + iPreviousPeriod + @"; TSObject" + sFullGridId + @".NextPeriod = " + iNextPeriod + @"; TSObject" + sFullGridId + @".TSURL = '" + curUrl + @"'; TSObject" + sFullGridId + @".Status = '" + sStatus + @"'; TSObject" + sFullGridId + @".Locked = " + bTsLocked.ToString().ToLower() + @"; TSObject" + sFullGridId + @".DisableApprovals = " + settings.DisableApprovals.ToString().ToLower() + @"; TSObject" + sFullGridId + @".Delegates = '" + sDelegates.Replace("'", @"`") + @"'; TSObject" + sFullGridId + @".DelegateId = '" + Page.Request["Delegate"] + @"'; TSObject" + sFullGridId + @".Views = " + views.ToJSON() + @"; TSObject" + sFullGridId + @".CurrentView = '" + sCurrentView + @"'; TSObject" + sFullGridId + @".Qualifier = '" + Qualifier + @"'; TSObject" + sFullGridId + @".CurrentViewId = '" + sCurrentViewId + @"'; TSObject" + sFullGridId + @".CanEditViews = " + bCanEditViews.ToString().ToLower() + @"; TSColType = " + TSColType + @"; TSNotes = " + TSNotes + @"; TSTypeObject = " + TSTypeObject + @"; TSCols = " + TSCols + @"; TSDCols = " + TSDCols + @"; siteId = '" + SPContext.Current.Web.ID + @"'; siteUrl = '" + url + @"'; siteColUrl = '" + (SPContext.Current.Site.ServerRelativeUrl == "/" ? "" : SPContext.Current.Site.ServerRelativeUrl) + @"'; periodId = '" + sPeriodId + @"'; GridType = '" + GridType + @"'; curServerDate = (new Date()).getTime() - (new Date('" + DateTime.Now.ToString("MMMM dd, yyyy H:mm:ss", culture) + @"')).getTime(); TGSetEvent('OnRenderFinish', 'TS" + sFullGridId + @"', TSRenderFinish); TGSetEvent('OnReady', 'TS" + sFullGridId + @"', TSReady); TGSetEvent('OnLoaded', 'TS" + sFullGridId + @"', TSOnLoaded); </script> "); //output.WriteLine(@"<div align=""center"" id=""TSLoader" + sFullGridId + @""" width=""100%""><img style=""vertical-align:middle;"" src=""/_layouts/images/gears_anv4.gif""/> Loading Items...</div>"); StringBuilder sb = new StringBuilder("<select class=\"form-control\" onchange=\"changePeriodCommand('" + curUrl + "',this,'" + Page.Request["Delegate"] + "')\">"); var arrPeriods = sPeriodList.Split(','); for (var i = 0; i < arrPeriods.Length; i++) { var arrPeriod = arrPeriods[i].Split('|'); if (arrPeriod[1] != sPeriodName) { sb.Append("<option value=" + arrPeriod[0] + ">" + arrPeriod[1] + "</option>"); } else { sb.Append("<option value=" + arrPeriod[0] + " selected>" + arrPeriod[1] + "</option>"); } } sb.Append("</select>"); var str = new HtmlString(sb.ToString()); if (GridType == 0) { output.WriteLine(@" <div id=""tsnav"" style=""display:none""> <nav class=""navbar navbar-default navbar-static"" role=""navigation""> <div> <div class=""collapse navbar-collapse""> <ul class=""nav navbar-nav"" class=""ts-nav-list""> <li class=""nav-btn nav-text-wrapper"" style=""float:left;padding-right:20px;padding: 0px""> <div class=""nav-label"">Status:</div> <div class=""text"" id=""mytimesheetstatus"">" + sStatus + @"</div> </li> <li class=""nav-btn nav-text-wrapper"" style=""padding: 0px; float:left""> <div class=""nav-label"">Current Period: </div>"); if (iPreviousPeriod != 0) { output.WriteLine(@" <span class=""icon-arrow-left-17 icon"" onclick=""javascript:previousPeriodCommand('" + curUrl + "','" + iPreviousPeriod + "','" + Page.Request["Delegate"] + @"')""></span> "); } else { output.WriteLine(@" <span class=""icon-arrow-left-17 icon disabled""></span> "); } output.WriteLine(@"<div class=""nav-select"">" + str.ToHtmlString() + @" </div>"); if (iNextPeriod != 0) { output.WriteLine(@" <span class=""icon-arrow-right-17 icon"" onclick=""javascript:nextPeriodCommand('" + curUrl + "','" + iNextPeriod + "','" + Page.Request["Delegate"] + @"')""></span> "); } else { output.WriteLine(@" <span class=""icon-arrow-right-17 icon disabled""></span> "); } output.WriteLine(@"</li> </ul> </div> </div> </nav> </div>"); output.Write("<div style=\"height:300px;width:100%;overflow:hidden;display:inline-block\" id=\"gridouter\">"); output.WriteLine("<div style=\"width:100%;height:100%\">"); output.WriteLine(@"<treegrid Data_Url=""" + url + @"/_vti_bin/WorkEngine.asmx"" Data_Timeout=""0"" Data_Method=""Soap"" Data_Function=""Execute"" Data_Namespace=""workengine.com"" Data_Param_Function=""timesheet_GetTimesheetGrid"" Data_Param_Dataxml=""" + sDataParam + @""" Layout_Url=""" + url + @"/_vti_bin/WorkEngine.asmx"" Layout_Timeout=""0"" Layout_Method=""Soap"" Layout_Function=""Execute"" Layout_Namespace=""workengine.com"" Layout_Param_Function=""timesheet_GetTimesheetGridLayout"" Layout_Param_Dataxml=""" + sLayoutParam + @""" Check_Url=""" + url + @"/_vti_bin/WorkEngine.asmx"" Check_Timeout=""0"" Check_Method=""Soap"" Check_Function=""Execute"" Check_Namespace=""workengine.com"" Check_Param_Function=""timesheet_GetTimesheetUpdates"" Check_Param_Dataxml=""" + sLayoutParam + @""" Check_Interval=""0"" Check_Repeat=""0"" Upload_Url=""" + url + @"/_layouts/epmlive/savemytimesheet.aspx" + (Page.Request["Delegate"] != null? "?Delegate=" + Page.Request["Delegate"]:"") + @""" Upload_Type=""Body,Cfg"" Upload_Flags=""AllCols,Accepted"" Debug="""" SuppressMessage=""3""></treegrid>"); output.WriteLine("</div>"); output.WriteLine("</div>"); } else if (GridType == 1) { RenderApprovalToolbar(output); output.WriteLine(@" <div id=""tsnav"" style=""display:none""> <nav class=""navbar navbar-default navbar-static"" role=""navigation""> <div> <div class=""collapse navbar-collapse""> <ul class=""nav navbar-nav"" style=""list-style-type: none;padding-top: 10px; margin:0px;padding: 0px; ""> <li class=""nav-btn nav-text-wrapper"" style=""float:left;padding: 0px; ""> <div class=""nav-label"">Current Period: </div>"); if (iPreviousPeriod != 0) { output.WriteLine(@" <span class=""icon-arrow-left-17 icon"" onclick=""javascript:previousPeriodCommand('" + curUrl + "','" + iPreviousPeriod + "','" + Page.Request["Delegate"] + @"')""></span> "); } else { output.WriteLine(@" <span class=""icon-arrow-left-17 icon disabled""></span> "); } output.WriteLine(@"<div class=""nav-select"">" + str.ToHtmlString() + @" </div>"); if (iNextPeriod != 0) { output.WriteLine(@" <span class=""icon-arrow-right-17 icon"" onclick=""javascript:nextPeriodCommand('" + curUrl + "','" + iNextPeriod + "','" + Page.Request["Delegate"] + @"')""></span> "); } else { output.WriteLine(@" <span class=""icon-arrow-right-17 icon disabled""></span> "); } output.WriteLine(@"</li> </ul> </div> </div> </nav> </div>"); output.Write("<div style=\"height:300px;width:100%;overflow:hidden;display:inline-block\" id=\"gridouter\">"); output.WriteLine("<div style=\"width:100%;height:100%\">"); output.WriteLine(@"<treegrid Data_Url=""" + url + @"/_vti_bin/WorkEngine.asmx"" Data_Timeout=""0"" Data_Method=""Soap"" Data_Function=""Execute"" Data_Namespace=""workengine.com"" Data_Param_Function=""timesheet_GetTimesheetApprovalsGrid"" Data_Param_Dataxml=""" + sDataParam + @""" Layout_Url=""" + url + @"/_vti_bin/WorkEngine.asmx"" Layout_Timeout=""0"" Layout_Method=""Soap"" Layout_Function=""Execute"" Layout_Namespace=""workengine.com"" Layout_Param_Function=""timesheet_GetTimesheetGridLayout"" Layout_Param_Dataxml=""" + sLayoutParam + @""" Page_Url=""" + url + @"/_layouts/15/epmlive/timesheetapprovalpage.aspx?Period=" + sPeriodId + @""" SuppressMessage=""3"" ></treegrid>"); output.WriteLine("</div>"); output.WriteLine("</div>"); } output.WriteLine(@"<div align=""center"" id=""divMessage" + sFullGridId + @""" width=""100%"" class=""dialog""><img style=""vertical-align:middle;"" src=""/_layouts/images/gears_anv4.gif""/> <span id=""spnMessage" + sFullGridId + @""">Saving Timesheet...</span></div>"); output.Write("<div id='NotesDiv' style='z-index:999;position: absolute; margin-left: 65px; display:none; width:150px;height:110px;border: 1px solid #666;background-color:#FFFFFF;cursor:pointer' onClick='stopProp(event);'><textarea id='txtNotes' style='z-index:999;width:140px;height:60px;border:0px;margin-bottom:5px;resize: none; outline: 0;' onkeyup='stopProp(event);' onclick='stopProp(event);' onkeypress='stopProp(event);'"); if (bTsLocked) { output.Write(" disabled='disabled'"); } output.Write("></textarea><br><input type=\"button\" value=\"OK\" onCLick=\"SaveNotes(event);stopProp(event);\" style=\"float:right\"></div>"); output.WriteLine(@"<div id=""viewNameDiv"" style=""display:none;width:200;padding:10px""> View Name:<br /> <input type=""text"" class=""ms-input"" name=""viewname"" id=""viewname""/><br /><br /> <div><input type=""checkbox"" name=""chkViewDefault"" id=""chkViewDefault"" /> Default View </div><br /><br /> <input type=""button"" value=""OK"" onclick=""validate()"" class=""ms-ButtonHeightWidth"" style=""width:100px"" target=""_self"" /> <input type=""button"" value=""Cancel"" onclick=""SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 'Cancel clicked'); return false;"" class=""ms-ButtonHeightWidth"" style=""width:100px"" target=""_self"" /> </div>"); output.WriteLine(@"<script language=""javascript"">"); output.WriteLine("function LoadTSGrid" + sFullGridId + "(){ LoadTSGrid('" + sFullGridId + "');}"); output.WriteLine("SP.SOD.executeOrDelayUntilScriptLoaded(LoadTSGrid" + sFullGridId + ", 'EPMLive.js');"); output.WriteLine("initmb();"); output.WriteLine("function clickTab(){"); output.WriteLine("SelectRibbonTab('Ribbon.MyTimesheetTab', true);"); //output.WriteLine("var wp = document.getElementById('MSOZoneCell_WebPart" + this.Qualifier + "');"); //output.WriteLine("fireEvent(wp, 'mouseup');"); output.WriteLine("}"); output.WriteLine("function validate(){"); output.WriteLine("if(document.getElementById('viewname').value.replace(/^\\s+|\\s+$/, '') == ''){"); output.WriteLine("alert('Please enter a view name - view names cannot be blank.')"); output.WriteLine("return false;"); output.WriteLine("}"); output.WriteLine("else{"); output.WriteLine("SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, document.getElementById('viewname').value + '|' + document.getElementById('chkViewDefault').checked); return false;"); output.WriteLine("}"); output.WriteLine("}"); //output.Write("SP.SOD.executeOrDelayUntilScriptLoaded(clickTab, \"MyTimesheetContextualTabPageComponent.js\");"); output.WriteLine(@"var viewNameDiv = document.getElementById(""viewNameDiv"");"); output.WriteLine("</script>"); tb.StopTimer(); tb.WriteTimers(output); }
protected void Page_Load(object sender, EventArgs e) { XmlDocument doc = new XmlDocument(); doc.LoadXml(System.Web.HttpUtility.HtmlDecode(Request["Data"])); string sPeriodId = doc.FirstChild.SelectSingleNode("//Cfg").Attributes["PeriodId"].Value; string tsuid = doc.FirstChild.SelectSingleNode("//Cfg").Attributes["TimesheetUID"].Value; bool submit = false; try { submit = bool.Parse(doc.FirstChild.SelectSingleNode("//Cfg").Attributes["SaveAndSubmit"].Value); } catch { } TimesheetSettings settings = new TimesheetSettings(SPContext.Current.Web); XmlNodeList ndListItems = doc.FirstChild.SelectNodes("//B/I"); XmlDocument docTimesheet = new XmlDocument(); int userId = SPContext.Current.Web.CurrentUser.ID; if (!string.IsNullOrEmpty(Page.Request["Delegate"])) { SPUser user = TimesheetAPI.GetUser(SPContext.Current.Web, Page.Request["Delegate"]); userId = user.ID; } docTimesheet.LoadXml("<Timesheet TSUID=\"" + tsuid + "\" Editable=\"0\" SaveAndSubmit=\"" + submit.ToString() + "\" TimesheetOwnerID=\"" + userId + "\"/>"); try { docTimesheet.FirstChild.Attributes["Editable"].Value = doc.FirstChild.SelectSingleNode("//Cfg").Attributes["GridEditable"].Value; } catch { } SqlConnection cn = null; SPSecurity.RunWithElevatedPrivileges(delegate() { cn = new SqlConnection(EPMLiveCore.CoreFunctions.getConnectionString(SPContext.Current.Web.Site.WebApplication.Id)); cn.Open(); }); SqlCommand cmd = new SqlCommand("SELECT * FROM TSTYPE where SITE_UID=@siteid", cn); cmd.Parameters.AddWithValue("@siteid", SPContext.Current.Site.ID); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); DataTable dtTypes = ds.Tables[0]; bool bTypes = false; if (dtTypes.Rows.Count > 0) { bTypes = true; } ArrayList arrPeriodDates = TimesheetAPI.GetPeriodDaysArray(cn, settings, SPContext.Current.Web, sPeriodId); Hashtable arrPeriodDateCols = new Hashtable(); foreach (DateTime dt in arrPeriodDates) { arrPeriodDateCols.Add("P" + dt.Ticks, dt.ToString("s")); if (bTypes) { arrPeriodDateCols.Add("TSP" + dt.Ticks, dt.ToString("s")); } } cn.Close(); foreach (XmlNode nd in ndListItems) { XmlNode ndRow = docTimesheet.CreateNode(XmlNodeType.Element, "Item", docTimesheet.NamespaceURI); XmlNode ndRowHours = docTimesheet.CreateNode(XmlNodeType.Element, "Hours", docTimesheet.NamespaceURI); ndRow.AppendChild(ndRowHours); foreach (XmlAttribute attr in nd.Attributes) { if (arrPeriodDateCols.Contains(attr.Name)) { if (bTypes) { if (attr.Name.StartsWith("TS")) { JavaScriptSerializer a = new JavaScriptSerializer(); object o = a.DeserializeObject(attr.Value); System.Collections.Generic.Dictionary <string, object> oo = (System.Collections.Generic.Dictionary <string, object>)o; XmlNode ndDate = docTimesheet.CreateNode(XmlNodeType.Element, "Date", docTimesheet.NamespaceURI); XmlAttribute attr1 = docTimesheet.CreateAttribute("Value"); attr1.Value = arrPeriodDateCols[attr.Name].ToString(); ndDate.Attributes.Append(attr1); foreach (DataRow dr in dtTypes.Rows) { try { XmlNode ndTime = docTimesheet.CreateNode(XmlNodeType.Element, "Time", docTimesheet.NamespaceURI); attr1 = docTimesheet.CreateAttribute("Hours"); attr1.Value = oo["T" + dr["TSTYPE_ID"].ToString()].ToString(); ndTime.Attributes.Append(attr1); attr1 = docTimesheet.CreateAttribute("Type"); attr1.Value = dr["TSTYPE_ID"].ToString(); ndTime.Attributes.Append(attr1); ndDate.AppendChild(ndTime); } catch { } } if (settings.AllowNotes) { string notes = ""; try { notes = oo["Notes"].ToString(); } catch { } if (notes != "") { XmlNode ndNotes = docTimesheet.CreateNode(XmlNodeType.Element, "Notes", docTimesheet.NamespaceURI); ndNotes.InnerText = notes; ndDate.AppendChild(ndNotes); } } ndRowHours.AppendChild(ndDate); } } else { XmlNode ndDate = docTimesheet.CreateNode(XmlNodeType.Element, "Date", docTimesheet.NamespaceURI); XmlAttribute attr1 = docTimesheet.CreateAttribute("Value"); attr1.Value = arrPeriodDateCols[attr.Name].ToString(); ndDate.Attributes.Append(attr1); XmlNode ndTime = docTimesheet.CreateNode(XmlNodeType.Element, "Time", docTimesheet.NamespaceURI); ndDate.AppendChild(ndTime); attr1 = docTimesheet.CreateAttribute("Hours"); attr1.Value = attr.Value; ndTime.Attributes.Append(attr1); if (settings.AllowNotes) { string notes = nd.Attributes["TS" + attr.Name].Value; if (notes != "") { XmlNode ndNotes = docTimesheet.CreateNode(XmlNodeType.Element, "Notes", docTimesheet.NamespaceURI); ndNotes.InnerText = notes; ndDate.AppendChild(ndNotes); } } ndRowHours.AppendChild(ndDate); } } else { XmlAttribute attr1 = docTimesheet.CreateAttribute(attr.Name); attr1.Value = attr.Value; ndRow.Attributes.Append(attr1); } } docTimesheet.FirstChild.AppendChild(ndRow); } XmlDocument docRes = new XmlDocument(); docRes.LoadXml(TimesheetAPI.SaveTimesheet(docTimesheet.OuterXml, SPContext.Current.Web)); if (docRes.FirstChild.Attributes["Status"].Value == "0") { data = "<Grid><IO Result='" + docRes.FirstChild.Attributes["Status"].Value + "'/></Grid>"; } else { data = "<Grid><IO Result='" + docRes.FirstChild.Attributes["Status"].Value + "' Message='" + docRes.FirstChild.InnerText + "'/></Grid>"; } }