private void Bind() { DbProviderFactory dbf = DbProviderFactories.GetFactory(); using (IDbConnection con = dbf.CreateConnection()) { string sSQL; // 04/04/2006 Paul. Start with today in ZoneTime and not ServerTime. DateTime dtZONE_NOW = T10n.FromUniversalTime(DateTime.Now.ToUniversalTime()); DateTime dtZONE_TODAY = new DateTime(dtZONE_NOW.Year, dtZONE_NOW.Month, dtZONE_NOW.Day); DateTime dtDATE_START = dtZONE_TODAY; switch (lstTHROUGH.SelectedValue) { case "today": dtDATE_START = dtZONE_TODAY; break; case "tomorrow": dtDATE_START = dtDATE_START.AddDays(1); break; case "this Saturday": dtDATE_START = dtDATE_START.AddDays(DayOfWeek.Saturday - dtDATE_START.DayOfWeek); break; case "next Saturday": dtDATE_START = dtDATE_START.AddDays(DayOfWeek.Saturday - dtDATE_START.DayOfWeek).AddDays(7); break; case "last this_month": dtDATE_START = new DateTime(dtZONE_TODAY.Year, dtZONE_TODAY.Month, DateTime.DaysInMonth(dtZONE_TODAY.Year, dtZONE_TODAY.Month)); break; case "last next_month": dtDATE_START = new DateTime(dtZONE_TODAY.Year, dtZONE_TODAY.Month, DateTime.DaysInMonth(dtZONE_TODAY.Year, dtZONE_TODAY.Month)).AddMonths(1); break; } // 04/04/2006 Paul. Now that we are using ZoneTime, we don't need to convert it to server time when displaying the date. txtTHROUGH.Text = "(" + Sql.ToDateString(dtDATE_START) + ")"; sSQL = "select * " + ControlChars.CrLf + " from vwACTIVITIES_MyList" + ControlChars.CrLf; using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = sSQL; // 11/24/2006 Paul. Use new Security.Filter() function to apply Team and ACL security rules. Security.Filter(cmd, m_sMODULE, "list"); Sql.AppendParameter(cmd, Security.USER_ID, "ASSIGNED_USER_ID", false); cmd.CommandText += " and DATE_START < @DATE_START" + ControlChars.CrLf; cmd.CommandText += " order by DATE_START asc " + ControlChars.CrLf; // 04/04/2006 Paul. DATE_START is not including all records for today. // 04/04/2006 Paul. Instead of using DATE_START <= @DATE_START, change to DATE_START < @DATE_START and increase the start date to tomorrow. // 04/04/2006 Paul. Here we do need to convert it to ServerTime because that is all that the database understands. Sql.AddParameter(cmd, "@DATE_START", T10n.ToServerTime(dtDATE_START.AddDays(1))); if (bDebug) { RegisterClientScriptBlock("vwACTIVITIES_MyList", Sql.ClientScriptBlock(cmd)); } try { using (DbDataAdapter da = dbf.CreateDataAdapter()) { ((IDbDataAdapter)da).SelectCommand = cmd; using (DataTable dt = new DataTable()) { da.Fill(dt); vwMain = dt.DefaultView; grdMain.DataSource = vwMain; if (!IsPostBack) { //grdMain.SortColumn = "DATE_START"; //grdMain.SortOrder = "desc" ; } // 09/15/2005 Paul. We must always bind, otherwise a Dashboard refresh will display the grid with empty rows. grdMain.DataBind(); } } } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); lblError.Text = ex.Message; } } } if (!IsPostBack) { // 06/09/2006 Paul. Remove data binding in the user controls. Binding is required, but only do so in the ASPX pages. //Page.DataBind(); } }
protected void Page_Command(object sender, CommandEventArgs e) { try { sbTrace = new StringBuilder(); if (e.CommandName == "Mailbox.CheckBounce") { EmailUtils.CheckInbound(Application, gID, true); } if (e.CommandName == "Mailbox.CheckMail" || e.CommandName == "Mailbox.CheckBounce") { string sSERVER_URL = Sql.ToString(ViewState["SERVER_URL"]); string sEMAIL_USER = Sql.ToString(ViewState["EMAIL_USER"]); string sEMAIL_PASSWORD = Sql.ToString(ViewState["EMAIL_PASSWORD"]); int nPORT = Sql.ToInteger(ViewState["PORT"]); string sSERVICE = Sql.ToString(ViewState["SERVICE"]); bool bMAILBOX_SSL = Sql.ToBoolean(ViewState["MAILBOX_SSL"]); // 01/08/2008 Paul. Decrypt at the last minute to ensure that an unencrypted password is never sent to the browser. Guid gINBOUND_EMAIL_KEY = Sql.ToGuid(Application["CONFIG.InboundEmailKey"]); Guid gINBOUND_EMAIL_IV = Sql.ToGuid(Application["CONFIG.InboundEmailIV"]); sEMAIL_PASSWORD = Security.DecryptPassword(sEMAIL_PASSWORD, gINBOUND_EMAIL_KEY, gINBOUND_EMAIL_IV); dtMain = new DataTable(); dtMain.Columns.Add("From", typeof(System.String)); dtMain.Columns.Add("Sender", typeof(System.String)); dtMain.Columns.Add("ReplyTo", typeof(System.String)); dtMain.Columns.Add("To", typeof(System.String)); dtMain.Columns.Add("CC", typeof(System.String)); dtMain.Columns.Add("Bcc", typeof(System.String)); dtMain.Columns.Add("Subject", typeof(System.String)); dtMain.Columns.Add("DeliveryDate", typeof(System.DateTime)); dtMain.Columns.Add("Priority", typeof(System.String)); dtMain.Columns.Add("Size", typeof(System.Int32)); dtMain.Columns.Add("ContentID", typeof(System.String)); dtMain.Columns.Add("MessageID", typeof(System.String)); dtMain.Columns.Add("Headers", typeof(System.String)); dtMain.Columns.Add("Body", typeof(System.String)); Pop3.Pop3MimeClient pop = new Pop3.Pop3MimeClient(sSERVER_URL, nPORT, bMAILBOX_SSL, sEMAIL_USER, sEMAIL_PASSWORD); try { pop.Trace += new Pop3.TraceHandler(this.Pop3Trace); pop.ReadTimeout = 60 * 1000; //give pop server 60 seconds to answer pop.Connect(); int nTotalEmails = 0; int mailboxSize = 0; pop.GetMailboxStats(out nTotalEmails, out mailboxSize); List <int> arrEmailIds = new List <int>(); pop.GetEmailIdList(out arrEmailIds); foreach (int i in arrEmailIds) { int nEmailSize = pop.GetEmailSize(i); if (nEmailSize < 1 * 1024 * 1024) { Pop3.RxMailMessage mm = null; #if DEBUG pop.IsCollectRawEmail = true; #endif pop.GetHeaders(i, out mm); if (mm == null) { sbTrace.Append("Email " + i.ToString() + " cannot be displayed." + ControlChars.CrLf); } else { DataRow row = dtMain.NewRow(); dtMain.Rows.Add(row); row["From"] = Server.HtmlEncode(Sql.ToString(mm.From)); row["Sender"] = Server.HtmlEncode(Sql.ToString(mm.Sender)); row["ReplyTo"] = Server.HtmlEncode(Sql.ToString(mm.ReplyTo)); row["To"] = Server.HtmlEncode(Sql.ToString(mm.To)); row["CC"] = Server.HtmlEncode(Sql.ToString(mm.CC)); row["Bcc"] = Server.HtmlEncode(Sql.ToString(mm.Bcc)); row["Subject"] = Server.HtmlEncode(mm.Subject); // 01/23/2008 Paul. DateTime in the email is in universal time. row["DeliveryDate"] = T10n.FromUniversalTime(mm.DeliveryDate); row["Priority"] = mm.Priority.ToString(); row["Size"] = nEmailSize; row["ContentId"] = mm.ContentId; row["MessageId"] = mm.MessageId; row["Headers"] = "<pre>" + Server.HtmlEncode(mm.RawContent) + "</pre>"; //row["Body" ] = mm.Body ; } } } } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); lblError.Text = ex.Message; } finally { pop.Disconnect(); } ViewState["Inbox"] = dtMain; vwMain = new DataView(dtMain); grdMain.DataSource = vwMain; grdMain.DataBind(); } } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); lblError.Text = ex.Message; } finally { #if DEBUG RegisterClientScriptBlock("Pop3Trace", "<script type=\"text/javascript\">sDebugSQL += '" + Sql.EscapeJavaScript(sbTrace.ToString()) + "';</script>"); #endif } }