private void ConfigureControls() { ddlUsers.SelectedIndexChanged += ddlUsers_SelectedIndexChanged; ddlUsers.AutoPostBack = true; dtcDate.DateChanged += dtcDate_DateChanged; dtcDate.AutoPostBack = true; dtcDate.OnValueChangeClientScript = "alert('Changed');"; btnSave.Click += btnSave_Click; btnSaveClose.Click += btnSave_Click; var workTypes = TSItem.GetWorkTypes(SPContext.Current.Site.ID); if (workTypes.Count == 0) { phHours.Controls.Add(BuildWorkTypeRow(0, "Work")); } else { foreach (var workType in workTypes) { phHours.Controls.Add(BuildWorkTypeRow(workType.Key, workType.Value)); } } phHours.Controls.Add( new LiteralControl("<tr height='22px'><td style='padding-right:20px;'>Other work this day: </td><td id='tdOther' style='text-align:right;padding-right:3px;' > </td></tr>")); phHours.Controls.Add( new LiteralControl("<tr height='22px'><td id='tdTotalLabel' style='padding-right:20px;'>Total: </td><td id='tdTotal' style='font-weight:bold;text-align:right;padding-right:3px;'> </td></tr>")); RegisterBaseScript(); }
protected override void OnInit(EventArgs e) { act = new EPMLiveCore.Act(Web); activation = act.CheckFeatureLicense(EPMLiveCore.ActFeature.Timesheets); if (activation != 0) { return; } base.OnInit(e); _listId = new Guid(Request.QueryString["ListId"]); _listItemId = int.Parse(Request.QueryString["ItemId"]); ConfigureControls(); if (!IsPostBack) { var web = SPContext.Current.Web; TSItem.PopulateDDLUsers(ddlUsers, web, web.CurrentUser); if (ddlUsers.Items.Count > 1) { pnlUsers.Visible = true; } else { pnlUsers.Visible = false; } } }
private void PopulateExistingHours(TSItem tsItem) { foreach (KeyValuePair <int, TextBox> tb in txtHours) { tb.Value.Text = tsItem == null || !tsItem.Work.ContainsKey(tb.Key) ? "0" : tsItem.Work[tb.Key].ToString(); } if (tsItem != null) { txtNotes.Text = tsItem.Notes; } }
protected void btnSave_Click(object sender, EventArgs e) { var tsItem = new TSItem(_listId, _listItemId, dtcDate.SelectedDate, ddlUsers.SelectedValue, ddlUsers.SelectedItem.Text) { WorkFromInput = txtHours, Notes = txtNotes.Text }; lblStatusMessage.Text = tsItem.Update() ? string.Format("Work hours saved for {0:d}", dtcDate.SelectedDate) + (tsItem.WorkNewHoursValid ? "" : "<br/><em>(The hours are invalid and will need to be adjusted before they can be posted).</em>") : string.Format("Error saving hours for {0:d}", dtcDate.SelectedDate); PopulateExistingHours(tsItem); RegisterDynamicScripts(tsItem); if (((Button)sender).ID == "btnSaveClose") { RegisterScript("saveclose", "<script language=\"javascript\">window.frameElement.commitPopup();</script>"); } }
private void _helper_DomainObjectToGridRow(object sender, EventArgs e) { if ((e as DomainObjectToGridRowEventArgsNew).DomainObject != null) { TSItem obj = (e as DomainObjectToGridRowEventArgsNew).DomainObject as TSItem; DataRow row = DtSource.NewRow(); row["MItemCode1"] = obj.MItemCode; row["MCard1"] = obj.MCard; row["SItemCode1"] = obj.SourceItemCode; row["MSCard1"] = obj.MSourceCard; row["Location1"] = obj.Location; row["LotNO2"] = obj.LotNO; row["VendorCode"] = obj.VendorCode; row["VendorItemCode"] = obj.VendorItemCode; row["DateCode"] = obj.DateCode; row["Reversion"] = obj.Reversion; row["PCBA"] = obj.PCBA; row["BIOS"] = obj.BIOS; row["MEMO"] = obj.MEMO; (e as DomainObjectToGridRowEventArgsNew).GridRow = row; } }
private void PopulateForm() { var tsItem = new TSItem(_listId, _listItemId, dtcDate.SelectedDate, ddlUsers.SelectedValue, ddlUsers.SelectedItem.Text); h2Title.InnerText = tsItem.List.Title + ": " + tsItem.ListItem.Title; if (!tsItem.Authorized) { ErrorMessage("You must be assigned to this item in order to submit hours."); return; } if (!tsItem.IsTSList) { ErrorMessage("This list is not configured for use with timesheets."); return; } if (!tsItem.IsTSChecked) { ErrorMessage("This item has not been allowed in timesheets."); return; } if (tsItem.PeriodId == 0) { ToggleFields(false, "This date does not fall within a valid timesheet period."); return; } if (!tsItem.ValidDay) { ToggleFields(false, tsItem.Date.DayOfWeek + " is not a valid timesheet day."); return; } //Testing: ToggleFields(true, string.Format("List: {0}, Item: {1}", _listId, _listItemId) ); ToggleFields(true, ""); pnlNotes.Visible = tsItem.AllowNotes; PopulateExistingHours(tsItem); RegisterDynamicScripts(tsItem); }
private void _helper_DomainObjectToExportRow(object sender, EventArgs e) { if ((e as DomainObjectToExportRowEventArgsNew).DomainObject != null) { TSItem obj = (e as DomainObjectToExportRowEventArgsNew).DomainObject as TSItem; (e as DomainObjectToExportRowEventArgsNew).ExportRow = new string[] { obj.SourceItemCode, obj.MSourceCard, obj.SourceItemCode, obj.MSourceCard, obj.Location, obj.LotNO, obj.VendorCode, obj.VendorItemCode, obj.DateCode, obj.Reversion, obj.PCBA, obj.BIOS, obj.MEMO }; } }
private void _helper_DomainObjectToGridRow(object sender, EventArgs e) { if ((e as DomainObjectToGridRowEventArgs).DomainObject != null) { TSItem obj = (e as DomainObjectToGridRowEventArgs).DomainObject as TSItem; (e as DomainObjectToGridRowEventArgs).GridRow = new UltraGridRow(new object[] { obj.MItemCode, obj.MCard, obj.SourceItemCode, obj.MSourceCard, obj.Location, obj.LotNO, obj.VendorCode, obj.VendorItemCode, obj.DateCode, obj.Reversion, obj.PCBA, obj.BIOS, obj.MEMO } ); } }
private void RegisterDynamicScripts(TSItem tsItem) { var workAllocated = tsItem.WorkAllocated.ToString(); var javascriptVariables = new StringBuilder(); var i = 0; foreach (var hourId in txtHours) { javascriptVariables.Append($"tb[{i++}] = document.getElementById('{hourId.Value.ClientID}');"); } var blankAnchor = "<img src='_layouts/epmlive/blank.gif' height='1' width='1'>"; var tableHead = "<table border='1' width='240' cellpadding='0' cellspacing='0' class='statustable'><tr class='noborder'>"; var yableBody = $@"</tr></table></td><td id='tdTotal'>"" + workRunningTotal + ""/{workAllocated} hours"; var scriptFormat = @"<script type=text/javascript> var min; var max; var tdTotalLabel; var workExisting; var workUserDayTotal; init(); function init() {{ //window.onbeforeunload=leavePage min = {6}; max = {7}; tdTotalLabel = document.getElementById('tdTotalLabel'); tdTotalLabel.innerHTML = 'Total (must be between ' + min + '-' + max + ') '; calculateExisting(); var tdOther = document.getElementById('tdOther'); tdOther.innerHTML = workUserDayTotal; hoursChanged(); dirty = false; }} function getWorkNew() {{ var tb = new Array(); {0} var workNew = 0; for(i=0; i < tb.length; i++) {{ workNew += Number(tb[i].value) }} return workNew; }} function calculateExisting() {{ var workNew = getWorkNew(); if(workNew == undefined) {{ workExisting = 0; workUserDayTotal = 0; }} else {{ workExisting = {4} - workNew; workUserDayTotal = {8} - workNew; }} }} function hoursChanged() {{ var workNew = getWorkNew(); if(workNew == undefined) return; setpctchart(workNew); dirty = true; }} function setpctchart(workNew) {{ var workRunningTotal = workNew + workExisting; var workUserRunningTotal = workNew + workUserDayTotal; var pct = Math.round( workRunningTotal / {5} * 100 ); if (pct > 100) sTable = ""{2}<td class='noborder' background='/_layouts/epmlive/images/tsstatusred.gif'>{1}</td>{3}""; else if (pct == 100) sTable = ""{2}<td class='noborder' background='/_layouts/epmlive/images/tsstatus.gif'>{1}</td>{3}""; else if (pct == 0) sTable = ""{2}<td class='noborder'>{1}</td>{3}""; else sTable = ""{2}<td class='noborder' background='/_layouts/epmlive/images/tsstatus.gif' width='"" + pct + ""%'>{1}</td><td class='noborder'>{1}</td>{3}""; var tdChart = document.getElementById('tdChart'); tdChart.innerHTML = sTable; var tdTotal = document.getElementById('tdTotal'); tdTotal.innerHTML = workUserRunningTotal; if(workUserRunningTotal > max || workUserRunningTotal < min) {{ tdTotal.className = 'totalHoursException'; }} else {{ tdTotal.className = ''; }} }} function validate(evt) {{ var theEvent = evt || window.event; var key = theEvent.keyCode || theEvent.which; key = String.fromCharCode( key ); var regex = /[0-9]|\./; if( !regex.test(key) ) {{ theEvent.returnValue = false; if (theEvent.preventDefault) theEvent.preventDefault(); }} }} </script>"; var script = string.Format( scriptFormat, javascriptVariables, blankAnchor, tableHead, yableBody, tsItem.WorkDoneListItem, workAllocated, tsItem.Min, tsItem.Max, tsItem.WorkDoneUser); RegisterScript("TSInput", script); }