Пример #1
0
        /// <summary>
        /// Given a sql statement where the first column is the data field and the secodn is the description, draw a set of option tags (call this within a select tag)
        /// </summary>
        /// <param name="cma">Savvy Page containing database connection to work with</param>
        /// <param name="sql">SQL statement where the first column is the data field and the secodn is the description</param>
        /// <param name="selectedValue">value to select if in the list</param>
        /// <returns></returns>

        public static string WriteDropDownOptions(string sql, string selectedValue)
        {
            string   result = "";
            DataView rs;
            string   value       = "";
            string   description = "";

            selectedValue = selectedValue + "";                         // convert to string

            DataBlock dataObject = new DataBlock(BewebData.GetConnectionString());

            dataObject.OpenDB();
            rs = dataObject.CreateDataSource(sql);

            for (int scan = 0; scan < dataObject.RecordCount; scan++)
            {
                value       = dataObject.GetValue(scan, 0) + "";                                        // convert to string
                description = dataObject.GetValue(scan, 1);
                result     += "<option value=\"" + value + "\"";
                if (value == selectedValue)
                {
                    result += " selected";
                }
                result += ">" + description + "</option>" + VB.crlf;
            }
            dataObject.CloseDB();
            return(result);
        }
Пример #2
0
        /// <summary>
        /// if the HelpText doesn't exist, create it with the default value supplied
        /// </summary>
        /// <param name="helpTextCode"></param>
        /// <param name="defaultTitle"></param>
        /// <param name="defaultBodyText"></param>
        protected void init(string helpTextCode, string defaultTitle, string defaultBodyText)
        {
            this.HelpTextCode = helpTextCode;
            DataBlock db = new DataBlock();

            db.OpenDB();

            if (Web.Request["dropHelpTexts"] != null && Util.IsBewebOffice)
            {
                db.execute("delete from HelpText where HelpTextCode='" + Fmt.SqlString(helpTextCode) + "'");
            }

            DataBlock rs = db.execute("select * from HelpText where HelpTextCode='" + Fmt.SqlString(helpTextCode) + "'");

            if (rs.eof())
            {
                defaultTitle = (defaultTitle.IsBlank()) ? helpTextCode + " Help" : defaultTitle;
                //autocreate empty HelpText
                db.execute("insert into HelpText(HelpTextCode,title,bodytexthtml,dateadded)values('" + Fmt.SqlString(helpTextCode) + "','" + Fmt.SqlString(defaultTitle) + "','" + Fmt.SqlString(defaultBodyText) + "', " + Fmt.SqlDate(DateTime.Now) + ")");
                rs.close();                //close previous rs
                //reopen newly created block
                rs = db.open("select * from HelpText where HelpTextCode='" + Fmt.SqlString(helpTextCode) + "'");
            }

            _ID           = rs.GetValueInt("HelpTextID");
            _BodyTextHTML = rs.GetValue("BodyTextHTML");
            _Title        = rs.GetValue("Title");
            rs.close();
            db.CloseDB();
        }
Пример #3
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();
        }