Example #1
0
        public static Models.TextBlock GetPlain(string sectionCode, string defaultTextHtml = null, string defaultTitle = null)
        {
            CheckForDrop(sectionCode);
            var tb = All.Filter(textBlock => textBlock.SectionCode == sectionCode).FirstOrDefault();

            if (tb == null)
            {
                // add it to the database
                tb             = new Models.TextBlock();
                tb.SectionCode = sectionCode;
                if (defaultTitle != null)
                {
                    tb.IsTitleAvailable = true;
                    tb.Title            = defaultTitle;
                }
                else
                {
                    tb.IsTitleAvailable = false;
                }
                tb.IsBodyPlainText    = true;
                tb.IsUrlAvailable     = false;
                tb.IsPictureAvailable = false;
                tb.BodyTextHtml       = defaultTextHtml ?? Fmt.SplitTitleCase(sectionCode) + " content goes here";
                tb.Save();
                All.Add(tb);
            }
            return(tb);
        }
Example #2
0
        /// <summary>
        /// Override this if you want to add breadcrumb
        /// </summary>
        public virtual void InitBread()
        {
            if (IsAdminSection)
            {
                if (IncludeHome)
                {
                    AddBreadcrumb(0, "Home");
                    SetBreadcrumb(0, "Home", Web.Root);
                }
                AddBreadcrumb(1, "Admin");
                SetBreadcrumb(1, "Admin", DefaultUrl);
                if (HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"].ToLower().Contains("admin/edit") || Web.PageFileName.ToLower().Contains("edit.aspx"))
                {
                    //lost during edit, assume level 3, create level 2
#if MVC
                    var tableName = HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"].Substring(0, HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"].ToLower().IndexOf("admin/edit/"));
                    tableName = tableName.Substring(tableName.LastIndexOf("/") + 1);
#else
                    var tableName = Web.PageFileName.Substring(0, Web.PageFileName.ToLower().IndexOf("edit.aspx"));
#endif
                    var newlabel = Fmt.SplitTitleCase(tableName).Plural();
                    AddBreadcrumb(2, newlabel);
#if MVC
                    SetBreadcrumb(2, newlabel, Web.ResolveUrl("~/admin/") + tableName + "Admin/");
#else
                    SetBreadcrumb(2, newlabel, Web.ResolveUrl("~/admin/") + tableName + "List.aspx");
#endif
                }
            }
            else
            {
                AddBreadcrumb(0, "Home");
                SetBreadcrumb(0, "Home", DefaultUrl);
            }
        }
Example #3
0
        public static Page LoadOrCreatePageCode(System.String pageCodeValue)
        {
            Page page = PageCache.GetByPageCode(pageCodeValue);

            if (page == null || page.IsNewRecord)
            {
                page = new Page()
                {
                    PageCode        = pageCodeValue,
                    TemplateCode    = "special",
                    DateAdded       = DateTime.Now,
                    PublishDate     = DateTime.Now,
                    Title           = Fmt.SplitTitleCase(pageCodeValue),
                    BodyTextHtml    = "Copy to be written for [" + pageCodeValue + "]<br>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat. Ut wisis enim ad minim veniam, quis nostrud exerci tution ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis te feugifacilisi. Duis autem dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto.",
                    RevisionStatus  = "Live",
                    PageIsALink     = false,
                    ShowInMainNav   = false,
                    ShowInFooterNav = false,
                    SortPosition    = 999
                };
                page.Save();
                PageCache.Rebuild();
            }

            return(page);
        }
Example #4
0
        public static void ExportToExcel(Sql sql, string filename)
        {
            StringBuilder allData = new StringBuilder();

            var reader = sql.GetReader();

            if (!reader.HasRows)
            {
                allData.AppendLine("No records");
            }
            else
            {
                // write field titles
                string str = "";
                for (int scan = 0; scan < reader.VisibleFieldCount; scan++)
                {
                    str += "\t" + Fmt.SplitTitleCase(reader.GetName(scan));
                }
                allData.AppendLine(str.Trim());

                foreach (DbDataRecord row in reader)
                {
                    // write field values
                    str = "";
                    for (int scan = 0; scan < reader.VisibleFieldCount; scan++)
                    {
                        string val      = "";
                        var    datatype = reader.GetDataTypeName(scan).ToLower();
                        if (datatype == "datetime")
                        {
                            if (row[scan].ToString().IsNotBlank())
                            {
                                val = Fmt.DateTime((DateTime)row[scan]);
                            }
                        }
                        else if (datatype == "bit")
                        {
                            if (row[scan].ToString().IsNotBlank())
                            {
                                val = Fmt.YesNo(("" + row[scan]).ToLower());
                            }
                        }
                        else
                        {
                            val = row[scan].ToString();
                        }
                        str += "\t" + TsvCleanup(val);
                    }
                    allData.AppendLine(str.Trim());
                }
            }
            reader.Close();
            reader.Dispose();
            ExportToExcel(allData.ToString(), filename);
        }
Example #5
0
        /// <summary>
        /// Sortable column header in a list/grid
        /// </summary>
        public static string ColSort(string fieldName, string title, string currentSortField, bool isDescending)
        {
            if (title == null)
            {
                title = Fmt.SplitTitleCase(fieldName);
                if (title.StartsWith("Is "))
                {
                    title = title.Substring(3);
                }
            }

            if (fieldName == "SortPosition")
            {
                isDescending = false;
            }

            HtmlTag html = new HtmlTag("a");

            html.Add("href", "javascript:ColSortBy(" + fieldName.JsEnquote() + ")");
            html.Add("title", "sort by " + title.JsEnquote() + "");
            string css = "colhead colsort";

            if (currentSortField == fieldName)
            {
                css += " selected";
                if (isDescending)
                {
                    css += " descending";
                }
                else
                {
                    css += " ascending";
                }
            }
            html.Add("class", css);

            html.SetInnerHtml(title);
            return(html.ToString());
        }
Example #6
0
 /// Loads a plain text or HTML textblock with the given code from the database.
 /// If the textblock doenst exist, create it with the default value of '[textblockname] content goes here'.
 /// If isPlainText=false then it is HTML.
 public TextBlock(string sectionName, bool isPlainText)
 {
     //init(sectionName,null,"auto-created section named ["+sectionName+"]");
     init(sectionName, null, Fmt.SplitTitleCase(sectionName) + " " + (isPlainText?"text":"content") + " goes here", isPlainText);
 }
Example #7
0
 /// <summary>
 /// Loads an HTML textblock with the given textblockname from the database.
 /// if the textblock doenst exist, create it with the default value of '[textblockname] content goes here'.
 /// </summary>
 /// <param name="sectionName"></param>
 public TextBlock(string sectionName)
 {
     //init(sectionName,null,"auto-created section named ["+sectionName+"]");
     init(sectionName, null, Fmt.SplitTitleCase(sectionName) + " content goes here", false);
 }
Example #8
0
        // note that T must be a class that can be "newed" because one of the otherwise options is "new"
        public T Execute <T>() where T : class, new()
        {
            string typeDescription = Fmt.SplitTitleCase(typeof(T).Name);
            // the next line wasn't being used - it caused a call to "Request" which isn't available all the time (eg AppStart)
            //string detailedMessage = "Resource type: " + typeDescription + "\nURL: " + Web.FullRawUrl + "\nTime: " + DateTime.Now + "\n";
            string message = typeDescription + " not found: " + Web.LocalUrl;

            if (actionType == OtherwiseAction.Null)
            {
                return(null);
            }
            else if (actionType == OtherwiseAction.New)
            {
                return(new T());
            }
            else if (actionType == OtherwiseAction.NotFound)
            {
                //TODO: MN 20140407 Web.Redirect("~/CantBeRouted?incomingUrl=" + Web.LocalUrl.UrlEncode());
                Error.PageNotFound("Resource not found. " + message);
                return(null);
                //throw new BadUrlException(message);
            }
            else if (actionType == OtherwiseAction.ProgrammingError)
            {
                throw new ProgrammingErrorException(message);
            }
            else if (actionType == OtherwiseAction.AdminError)
            {
                throw new AdminErrorException(message);
            }
            else if (actionType == OtherwiseAction.NullButNotifyProgrammer)
            {
                new ElectronicMail()
                {
                    ToAddress = SendEMail.EmailAboutError, Subject = Util.GetSiteName() + " Website Non-fatal Error Notification", BodyHtml = "Please address the following non-fatal issue with the website:<br>" + message + "<br>" + Logging.GetDiagnosticsDumpHtml()
                }.Send(false);
                //SendEMail.SimpleSendHtmlEmail(SendEMail.EmailAboutError, Util.GetSiteName() + " Website Non-fatal Error Notification", "Please address the following non-fatal issue with the website:\n" + message+Logging.GetDiagnosticsDumpHtml());
                return(null);
            }
            else if (actionType == OtherwiseAction.NullButNotifyAdmin)
            {
                new ElectronicMail()
                {
                    ToAddress = SendEMail.EmailAboutError, Subject = Util.GetSiteName() + " Website Problem Notification", BodyHtml = "Please address the following issue with the website:<br>" + message
                }.Send(false);
                //SendEMail.SimpleSendEmail(SendEMail.EmailToAddress, Util.GetSiteName() + " Website Problem Notification", "Please address the following issue with the website:\n" + message);
                return(null);
            }
            else
            {
                // eat own dog food
                throw new ProgrammingErrorException("Otherwise: Invalid otherwise case");
            }
            //if (actionType == OtherwiseAction.NotFound) {
            //  throw new HttpException(404, "Resource Not Found: "+typeDescription);
            //} else if (actionType == OtherwiseAction.Error) {
            //  throw new Exception("Resource Not Found: "+typeDescription);
            //} else if (actionType == OtherwiseAction.GoReturnPage) {
            //  Web.InfoMessage = "Cannot find  "+typeDescription+".";
            //  Web.Redirect(Savvy.Breadcrumbs.Current.GetReturnPage());
            //}
        }