示例#1
0
        /// <summary>
        /// if the textblock doesn't exist, create it with the default value supplied
        /// </summary>
        /// <param name="sectionName"></param>
        /// <param name="defaultBodyText"></param>
        /// <param name="isPlainText"></param>
        protected void init(string sectionName, string defaultTitle, string defaultBodyText, bool isPlainText)
        {
            this.SectionCode = sectionName;
            DataBlock db = new DataBlock();

            db.OpenDB();

            if (Web.Request["droptextblocks"] != null && Util.IsBewebOffice)
            {
                db.execute("delete from TextBlock where SectionCode='" + Fmt.SqlString(sectionName) + "'");
            }

            DataBlock rs = db.execute("select * from TextBlock where SectionCode='" + Fmt.SqlString(sectionName) + "'");

            if (rs.eof())
            {
                //autocreate empty textblock
                if (defaultTitle != null)
                {
                    db.execute("insert into TextBlock(sectioncode,title,bodytexthtml,isbodyplaintext,isurlavailable,istitleavailable,ispictureavailable)values('" + Fmt.SqlString(sectionName) + "','" + Fmt.SqlString(defaultTitle) + "','" + Fmt.SqlString(defaultBodyText) + "'," + Fmt.SqlBoolean(isPlainText) + ",0,1,0)");
                }
                else
                {
                    db.execute("insert into TextBlock(sectioncode,bodytexthtml,isbodyplaintext,isurlavailable,istitleavailable,ispictureavailable)values('" + Fmt.SqlString(sectionName) + "','" + Fmt.SqlString(defaultBodyText) + "'," + Fmt.SqlBoolean(isPlainText) + ",0,0,0)");
                }
                rs.close();                //close previous rs

                //reopen newly created block
                rs = db.open("select * from TextBlock where SectionCode='" + Fmt.SqlString(sectionName) + "'");
            }

            _ID       = rs.GetValueInt("TextBlockID");
            RawBody   = rs.GetValue("BodyTextHTML");
            _BodyText = Fmt.FmtText(RawBody);
            // todo: add fmttext back (abstract?)
            _BodyTextHTML = RawBody;            //currCMA.FmtHtmlText();
            _Title        = rs.GetValue("Title");
            if (!rs.FieldExists("SubTitle"))
            {
                new Sql("alter table textblock add SubTitle nvarchar(250);");
            }
            else
            {
                SubTitle = rs.GetValue("SubTitle");
            }
            if (rs.GetValueIsTrue("IsPictureAvailable"))
            {
                if (rs.GetValue("Picture").IsNotBlank())
                {
                    _Picture = Util.GetAttachmentVPath() + rs.GetValue("Picture");
                    if (rs.FieldExists("PictureCaption"))
                    {
                        _PictureCaption = rs.GetValue("PictureCaption");
                    }
                    if (rs.FieldExists("PictureWidth"))
                    {
                        _PictureWidth  = rs.GetValue("PictureWidth").ToInt(0);
                        _PictureHeight = rs.GetValue("PictureHeight").ToInt(0);
                    }
                }
            }
            _URL        = rs.GetValue("URL");
            _URLCaption = rs.GetValue("URLCaption");
            //}else
            //{
            //	//bugger
            //	//throw new Exception("not found sectionName[" + sectionName + "]count[" + rs.RecordCount+ "]");
            //	rs.execute("insert into textblock(sectioncode)values()")
            //}
            rs.close();
            db.CloseDB();
        }