Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class Totals : System.Web.UI.Page
- {
- private string DateTruncUnit = "day";
- protected void Page_Load(object sender, EventArgs e)
- {
- if (Request.HttpMethod == "POST")
- Response.Redirect("Totals.aspx");
- if (Request["qDate"]!=null)
- {
- DateSelector.SelectedDate = System.DateTime.Parse(Request["qDate"].ToString());
- }
- else
- {
- DateSelector.DayStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#660000");
- DateSelector.DayStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#efefe7");
- if (DateSelector.SelectedDate <= DateTime.MinValue)
- DateSelector.SelectedDate = DateTime.Today;
- }
- LoadTicker();
- }
- private void LoadTicker()
- {
- DBFunctions DBc = new DBFunctions(Context.User.Identity.Name);
- Npgsql.NpgsqlDataReader DBcTickers = DBc.SelectTickers();
- string TickerPrefix = "";
- string TickerText = "";
- while (DBcTickers.Read())
- {
- TickerText += TickerPrefix+DBcTickers.GetValue(1).ToString();
- TickerPrefix = ConfigurationManager.AppSettings["TickerSeparator"].Replace(" "," ");
- }
- ClientScript.RegisterStartupScript(typeof(Page), "TickerScript", TickerScript(TickerText));
- }
- protected override void OnPreRender(EventArgs e)
- {
- if (Request["PeriodUnit"]!=null)
- this.DateTruncUnit = Request["PeriodUnit"];
- base.OnPreRender(e);
- //Check if Final Totals are supposed to be displayed at Graph by default
- if (Request.UrlReferrer==null ||(Request.UrlReferrer.AbsolutePath.Contains("Totals.aspx") != true && ConfigurationManager.AppSettings["GraphFinalTotalsByDefault"].ToString() == "true"))
- this.chkFinalTotalsOnGraph.Checked = true;
- //Update Chart Image Element according to date selected on the Calendar
- this.ChartIMG.ImageUrl = "Chart.aspx?FinalTotals="+chkFinalTotalsOnGraph.Checked.ToString()+"&TotalsDate=" + DateSelector.SelectedDate.ToLongDateString() + "&PeriodUnit=" + this.DateTruncUnit;
- this.ChartIMG.Attributes.Add("onload", "document.getElementById('ChartIMG').tags=document.getElementById('ChartIMG').src; document.getElementById('ChartIMG').src+='\\u0026width='+(document.body.clientWidth-document.getElementById('LoginInfoTable').offsetWidth-20)+'\\u0026height='+(document.body.clientHeight-document.getElementById('tickerdiv').offsetHeight-15);document.getElementById('ChartIMG').onload=null;");
- //Determine if graph should be displayed in a new window
- if (ConfigurationManager.AppSettings["GraphNewWindow"] == "true")
- {
- if (ConfigurationManager.AppSettings["GraphDisplayTicker"] != "true")
- GraphB.OnClientClick = "window.open('" + Microsoft.JScript.GlobalObject.encodeURI(this.ChartIMG.ImageUrl) + "\\u0026width='+(document.body.clientWidth-44)+'\\u0026height='+(document.body.clientHeight-40),null,'width='+(document.body.clientWidth)+',status=no,left=0,top=0,scrollbars=no,resizable=yes,height='+(document.body.clientHeight)); return false;";
- else
- GraphB.OnClientClick = "window.open('" + Microsoft.JScript.GlobalObject.encodeURI("Totals.aspx?PeriodUnit="+this.DateTruncUnit+"&graphMode=true&qDate=" + DateSelector.SelectedDate.ToShortDateString()) + "',null,'width='+(document.body.clientWidth)+',status=no,left=0,top=0,scrollbars=no,resizable=yes,height='+(document.body.clientHeight)); return false;";
- this.MultiView1.ActiveViewIndex = 1;
- this.GraphB.Text = "Graph";
- GraphB.UseSubmitBehavior = false;
- }
- else
- {
- GraphB.OnClientClick = null;
- ChartIMG.Attributes.Add("onclick", "window.open('" + Microsoft.JScript.GlobalObject.encodeURI(this.ChartIMG.ImageUrl) + "\\u0026width='+(document.body.clientWidth-44)+'\\u0026height='+(document.body.clientHeight-40),null,'width='+(document.body.clientWidth)+',status=no,left=0,top=0,scrollbars=no,resizable=yes,height='+(document.body.clientHeight)); return false;");
- }
- if (Request["graphMode"] != null && Request["graphMode"].ToString() == "true")
- {
- this.MultiView1.ActiveViewIndex = 0;
- LoginInfoTD.Style.Add("display","none");
- }
- chkFinalTotalsOnGraph.Attributes.Add("onclick", "submit();");
- //Check if user should see the Admin button
- if (!Roles.IsUserInRole("Admin"))
- this.AdminB.Visible = false;
- if (!Roles.IsUserInRole("Manager"))
- { FormsAuthentication.SignOut(); Response.Redirect("default.aspx"); }
- //Get user groups
- string adPath = ConfigurationManager.AppSettings["ActiveDirectoryUserGroupsPath"];
- FormsAuth.LdapGroups adAuth = new FormsAuth.LdapGroups(adPath);
- SortedList groups = adAuth.GroupList();
- //Check how to present usernames
- bool userDisplayName=false;
- if (ConfigurationManager.AppSettings["TotalsUsernameDisplayType"].ToString() == "displayname")
- userDisplayName = true;
- //Create DB connection
- DBFunctions DBc = new DBFunctions(Context.User.Identity.Name);
- //Select Periods from DB
- Npgsql.NpgsqlDataReader DBcPeriods = DBc.SelectPeriods(true);
- //Select totals from DB
- Hashtable DBcTotals = DBc.GetCollectionsTotals(DateSelector.SelectedDate.ToLongDateString(),this.DateTruncUnit);
- Hashtable DBcGrandTotalsRecord;
- Hashtable DBcTotalsRows=new Hashtable();
- int PeriodsCount=0;
- foreach (DictionaryEntry userkey in DBcTotals)
- {
- DBcTotalsRows.Add(userkey.Key.ToString(), "");
- }
- //Put Periods to the PeriodsHeaderPlaceholder and get Grand Totals to GrandTotalsPlaceholder
- Literal lGT = new Literal();
- DBcGrandTotalsRecord = (Hashtable)DBcTotals["*"];
- while (DBcPeriods.Read())
- {
- Literal l1 = new Literal();
- l1.Text = "<td class='TdTotalsHeadersCell'>" + DBcPeriods.GetValue(1).ToString() + "</td>";
- PeriodsHeadersPlaceholder.Controls.Add(l1);
- lGT.Text += "<td class='TdGrandTotalsCell'>";
- if (DBcGrandTotalsRecord[DBcPeriods.GetValue(0).ToString()]!=null)
- lGT.Text += DBcGrandTotalsRecord[DBcPeriods.GetValue(0).ToString()];
- else
- lGT.Text += 0;
- lGT.Text += "</td>";
- foreach (DictionaryEntry userkey in DBcTotals)
- {
- Hashtable DBcRecord = (Hashtable)DBcTotals[userkey.Key.ToString()];
- DBcTotalsRows[userkey.Key.ToString()] += "<td class=\"TdTotalsCell\">" + (DBcRecord[DBcPeriods.GetValue(0).ToString()] == null ? "0" : DBcRecord[DBcPeriods.GetValue(0).ToString()].ToString()) + "</td>";
- }
- foreach (DictionaryEntry groupEl in groups)
- {
- SortedList groupUsers = (SortedList)groupEl.Value;
- ArrayList groupTotalPeriods;
- if (groupUsers["*Totals"] == null)
- {
- groupTotalPeriods = new ArrayList();
- groupUsers.Add("*Totals", groupTotalPeriods);
- }
- else
- {
- groupTotalPeriods = (ArrayList) groupUsers["*Totals"];
- }
- foreach (DictionaryEntry groupUserEl in groupUsers)
- {
- Hashtable DBcRecord = (Hashtable)DBcTotals[groupUserEl.Key.ToString()];
- if (DBcTotalsRows[groupUserEl.Key.ToString()] != null)
- {
- if (groupTotalPeriods.Count == PeriodsCount)
- {
- groupTotalPeriods.Add(Int32.Parse(DBcRecord[DBcPeriods.GetValue(0).ToString()] == null ? "0" : DBcRecord[DBcPeriods.GetValue(0).ToString()].ToString()));
- }
- else
- {
- int groupTotalPeriodsVal = (int)groupTotalPeriods[PeriodsCount];
- groupTotalPeriodsVal += Int32.Parse(DBcRecord[DBcPeriods.GetValue(0).ToString()] == null ? "0" : DBcRecord[DBcPeriods.GetValue(0).ToString()].ToString());
- groupTotalPeriods[PeriodsCount] = groupTotalPeriodsVal;
- }
- }
- }
- }
- PeriodsCount++;
- }
- lGT.Text += "<td class='TdGrandTotalsCell'>";
- if (DBcGrandTotalsRecord["-1"].ToString().Length>0 )
- lGT.Text += DBcGrandTotalsRecord["-1"];
- else
- lGT.Text += 0;
- lGT.Text+="</td>";
- GrandTotalsPlaceholder.Controls.Add(lGT);
- Literal lT = new Literal();
- foreach (DictionaryEntry groupEl in groups)
- {
- lT.Text += "<tr><td class=\"TdGroupCell\">"+groupEl.Key.ToString()+"</td><td class=\"TdTotalsCell\" colspan=\""+(PeriodsCount+1)+"\"> </td></tr>";
- SortedList groupUsers = (SortedList)groupEl.Value;
- int GroupFinalTotal = 0;
- foreach (DictionaryEntry groupUserEl in groupUsers)
- {
- if (groupUserEl.Key.ToString() != "*Totals")
- {
- Hashtable DBcRecord = (Hashtable)DBcTotals[groupUserEl.Key.ToString()];
- try
- {
- if (DBcTotalsRows[groupUserEl.Key.ToString()] != null)
- {
- if (DBcRecord["-1"] != null)
- {
- GroupFinalTotal += Int32.Parse(DBcRecord["-1"].ToString());
- if (userDisplayName==true)
- lT.Text += "<tr><td class='TdUserTotalsCell'>" + groupUserEl.Value.ToString() + "</td>" + DBcTotalsRows[groupUserEl.Key.ToString()].ToString() + "<td class=\"TdFinalTotalsCell\">" + DBcRecord["-1"] + "</td></tr>";
- else
- lT.Text += "<tr><td class='TdUserTotalsCell'>" + groupUserEl.Key.ToString() + "</td>" + DBcTotalsRows[groupUserEl.Key.ToString()].ToString() + "<td class=\"TdFinalTotalsCell\">" + DBcRecord["-1"] + "</td></tr>";
- }
- else
- {
- GroupFinalTotal += 0;
- if (userDisplayName == true)
- lT.Text += "<tr><td class='TdUserTotalsCell'>" + groupUserEl.Value.ToString() + "</td>" + DBcTotalsRows[groupUserEl.Key.ToString()].ToString() + "<td class=\"TdFinalTotalsCell\">" + 0 + "</td></tr>";
- else
- lT.Text += "<tr><td class='TdUserTotalsCell'>" + groupUserEl.Key.ToString() + "</td>" + DBcTotalsRows[groupUserEl.Key.ToString()].ToString() + "<td class=\"TdFinalTotalsCell\">" + 0 + "</td></tr>";
- }
- }
- else
- {
- if (userDisplayName == true)
- lT.Text += "<tr><td class='TdUserTotalsCell'>" + groupUserEl.Value.ToString() + "</td>";
- else
- lT.Text += "<tr><td class='TdUserTotalsCell'>" + groupUserEl.Key.ToString() + "</td>";
- for (int i = 0; i < PeriodsCount; i++)
- lT.Text += "<td class=\"TdTotalsCell\">0</td>";
- lT.Text += "<td class=\"TdFinalTotalsCell\">0</td></tr>";
- }
- }
- catch (Exception exc)
- {
- Response.Write(exc);
- }
- }
- }
- lT.Text += "<tr><td class=\"TdGroupTotalsDescriptionCell\">" + groupEl.Key.ToString() + " Totals</td>";
- ArrayList groupTotals = (ArrayList)groupUsers["*Totals"];
- for (int i = 0; i < PeriodsCount;i++ )
- {
- lT.Text += "<td class=\"TdGroupTotalsCell\">";
- try
- {
- lT.Text += groupTotals[i].ToString();
- }
- catch (Exception ex1)
- {
- lT.Text += " <!-- " + ex1.Message.ToString() + " -->";
- }
- lT.Text += "</td>";
- }
- lT.Text += "<td class=\"TdGroupTotalsCell\">"+GroupFinalTotal+"</td></tr><tr><td class=\"TdTotalsCell\" colspan=\""+(PeriodsCount+2)+"\"> </td></tr>";
- }
- TotalsTablePlaceHolder.Controls.Add(lT);
- }
- override protected void OnInit(EventArgs e)
- {
- InitializeComponent();
- base.OnInit(e);
- }
- private void InitializeComponent()
- {
- this.LogoutB.Click += new System.EventHandler(this.LogoutB_Click);
- this.AdminB.Click += new System.EventHandler(this.AdminB_Click);
- this.CollectionsB.Click += new System.EventHandler(this.CollectionsB_Click);
- this.MonthlyReportB.Click += new System.EventHandler(this.MonthlyReportB_Click);
- if (ConfigurationManager.AppSettings["GraphNewWindow"].ToString()!="true")
- this.GraphB.Click += new System.EventHandler(this.GraphB_Click);
- }
- protected void LogoutB_Click(object sender, EventArgs e)
- {
- FormsAuthentication.SignOut();
- Response.Redirect("Totals.aspx");
- FormsAuthentication.RedirectToLoginPage();
- }
- protected void GraphB_Click(object sender, EventArgs e)
- {
- if (this.MultiView1.ActiveViewIndex == 1)
- {
- this.MultiView1.ActiveViewIndex = 0;
- GraphB.Text = "Table";
- }
- else
- {
- this.MultiView1.ActiveViewIndex = 1;
- GraphB.Text = "Graph";
- }
- }
- protected string TickerScript(string content)
- {
- IFormatProvider formatprovider = System.Globalization.CultureInfo.GetCultureInfo("en-US");
- int lowestTimeToRefresh=int.MaxValue;
- int currentRefreshInterval;
- System.TimeSpan RefreshHourCurrentEl;
- if (ConfigurationManager.AppSettings["TotalsRefreshHours"].ToString().Length > 4)
- {
- foreach (string RefreshHour in ConfigurationManager.AppSettings["TotalsRefreshHours"].ToString().Split(';'))
- {
- RefreshHourCurrentEl = System.DateTime.ParseExact(RefreshHour, "HH:mm", formatprovider).Subtract(System.DateTime.Now);
- currentRefreshInterval = (int)RefreshHourCurrentEl.TotalSeconds;
- if (currentRefreshInterval <= 0)
- {
- currentRefreshInterval += 86399;
- }
- if (currentRefreshInterval < lowestTimeToRefresh)
- {
- lowestTimeToRefresh = currentRefreshInterval;
- }
- }
- }
- int tickerRefreshRate = int.MaxValue;
- string _str = "<script>";
- try
- {
- currentRefreshInterval=Int32.Parse(ConfigurationManager.AppSettings["TotalsRefreshRate"].ToString());
- if (currentRefreshInterval > 0 && currentRefreshInterval < lowestTimeToRefresh)
- lowestTimeToRefresh = currentRefreshInterval;
- }
- catch
- {
- }
- try
- {
- tickerRefreshRate = Int32.Parse(ConfigurationManager.AppSettings["TickerRefreshRate"].ToString());
- }
- catch
- {
- }
- _str+="var refreshInterval=setInterval('window.location.reload()'," + lowestTimeToRefresh.ToString() + @"000);";
- _str += "var content='" +content+ @"';
- var aw, mq, tWidth, lefttime;
- var x=setInterval('AJAXtickerLoad()'," + tickerRefreshRate + @"000);
- function AJAXtickerLoad()
- {
- try
- {
- var xmlHttpReq = false;
- var self = this;
- var strURL= 'ticker.aspx';
- // Mozilla/Safari
- if (window.XMLHttpRequest) {
- self.xmlHttpReq = new XMLHttpRequest();
- }
- // IE
- else if (window.ActiveXObject) {
- self.xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP');
- }
- self.xmlHttpReq.open('POST', strURL, true);
- self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- self.xmlHttpReq.onreadystatechange = function() {
- if (self.xmlHttpReq.readyState == 4) {
- if (content!=self.xmlHttpReq.responseText)
- {
- content=self.xmlHttpReq.responseText;
- if (lefttime)
- clearInterval(lefttime);
- startticker();
- }
- }
- }
- self.xmlHttpReq.send('type=all');
- }
- catch (err)
- {
- }
- }
- function startticker()
- {
- if (document.getElementById) {
- tWidth=document.getElementById('tickerdiv').offsetWidth;
- var tHeight=document.getElementById('tickerdiv').offsetHeight;
- var tick = '<div style=\u0022position:relative;width:'+tWidth+';height:'+tHeight+';overflow:hidden;\u0022';
- tick +='><div id=\u0022mq\u0022 style=\u0022position:absolute;left:0px;top:0px;white-space:nowrap;\u0022><\/div><\/div>';
- document.getElementById('tickerdiv').innerHTML = tick; mq = document.getElementById('mq');
- mq.style.left=(parseInt(tWidth)+10)+'px'; mq.innerHTML='<span id=\u0022tx\u0022>'+unescape(content)+'<\/span>';
- aw = document.getElementById('tx').offsetWidth;
- if (content.length>0)
- lefttime=setInterval('scrollticker()',50);
- }
- }
- function scrollticker()
- {
- mq.style.left = parseInt(mq.style.left)-" + ConfigurationManager.AppSettings["TickerSpeed"].ToString() + @"+'px';
- if (parseInt(mq.style.left)<tWidth-aw)
- {
- mq.innerHTML+='<span id=\u0022tx3\u0022>" + ConfigurationManager.AppSettings["TickerSeparator"].Replace(" ", " ") +@"'+unescape(content)+'<\/span>';
- aw+=(document.getElementById('tx').offsetWidth+40);
- }
- }
- startticker();
- </script>";
- return _str;
- }
- protected void MonthlyReportB_Click(object sender, EventArgs e)
- {
- this.DateTruncUnit="month";
- DateSelector.DayStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#efefe7");
- DateSelector.DayStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#000000");
- DateSelector.OtherMonthDayStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#660000");
- DateSelector.VisibleDate = DateSelector.SelectedDate;
- }
- protected void AdminB_Click(object sender, EventArgs e)
- {
- if (Roles.IsUserInRole("Admin")) Response.Redirect("admin.aspx");
- }
- protected void CollectionsB_Click(object sender, EventArgs e)
- {
- Response.Redirect("default.aspx");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement