Example #1
0
        protected override ApplyResult ProcessApplyItem(ref object obj, out string errormessage, out string successmessage, out bool edited)
        {
            errormessage   = "";
            successmessage = "";
            edited         = false;
            string action   = this.Request.Form.action.Value.ToLower();
            int    objectID = -1;

            if (this.Request.Form.objectID != null)
            {
                objectID = int.Parse(this.Request.Form.objectID.Value.ToString());
            }

            string html = this.Request.Form.HTML.Value;

            FormItem item = new FormItem(objectID,
                                         this.Request.Form.Name.Value,
                                         html);

            obj = item;



            switch (action)
            {
            case BaseWebModule.PostSave:

                List <SWBaseTag> tags = SWBaseTag.GetTags(html, SWBaseTag.BaseTagTypes.Form);
                foreach (SWBaseTag t1 in tags)
                {
                    foreach (SWBaseTag t2 in tags)
                    {
                        if (!t1.Equals(t2) &&
                            t1.Name.Equals(t2.Name))
                        {
                            errormessage = String.Format("There are one or more tags with the same name {0}.", t1.Name);
                            return(ApplyResult.Message);
                        }
                    }
                }

                bool result = false;
                result = new DBContent().SaveForm(item, out errormessage);
                edited = item.ID > 0;

                if (result)
                {
                    return(ApplyResult.Save);
                }
                break;

            case BaseWebModule.PostCancel:
                return(ApplyResult.Cancel);
            }
            return(ApplyResult.Message);
        }
Example #2
0
        private string ProcessTag(SWBaseTag tag, DBContent.TagValueItemTypes htmlType, out string errormessage)
        {
            errormessage = "";
            if (tag == null)
            {
                return("");
            }

            switch (tag.TagType)
            {
            case SWInputTextTag.Type:
                return(this.ProcessInputTextTag(tag as SWInputTextTag, htmlType, out errormessage));

            case SWInputDateTag.Type:
            case SWInputTimeTag.Type:
                return(this.ProcessInputDateTimeTag(tag as SWBaseInputDateTimeTag, htmlType, out errormessage));

            case SWDateTag.Type:
                return(DateTime.Now.ToString());

            case SWVarTag.Type:
                return(this.ProcessVarTag(tag as SWVarTag, htmlType, out errormessage));

            case SWQueryTag.Type:
                return(this.ProcessQueryTag(tag as SWQueryTag, out errormessage));

            case SWSelectTag.Type:
                return(this.ProcessSelectTag(tag as SWSelectTag, htmlType, out errormessage));

                /*   case SWInputDateTag.Type:
                 *     switch (htmlType)
                 *     {
                 *         case DBContent.TagValueItemTypes.Form:
                 *             return this.ProcessInputDateTag(foundTag as SWInputDateTag, out errormessage);
                 *         case DBContent.TagValueItemTypes.Template:
                 *             return foundTag.Value;
                 *     }
                 *     break;*/
            }

            return("");
        }
Example #3
0
        private void CreateHTML(out string errormessage,
                                ref string html,
                                DBContent.TagValueItemTypes htmlType)
        {
            errormessage = "";
            if (String.IsNullOrWhiteSpace(html))
            {
                return;
            }

            int startIndex = -1;
            int endIndex   = -1;

            while ((startIndex = html.IndexOf(SWBaseTag.TagStart.ToLower(), endIndex + 1, StringComparison.CurrentCultureIgnoreCase)) >= 0)
            {
                endIndex = html.IndexOf(SWBaseTag.TagEnd.ToLower(), startIndex);
                int tempStart = html.IndexOf(SWBaseTag.TagStart.ToLower());
                if (tempStart > endIndex)
                {
                    continue;
                }

                string xmlTag = html.Substring(startIndex, endIndex - startIndex + 1);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmlTag.ToLower());
                XmlNode newNode = doc.DocumentElement;

                SWBaseTag    tag      = null;
                XmlAttribute typeAttr = newNode.Attributes[SWBaseTag.TypeAttribute];
                if (typeAttr != null)
                {
                    tag = SWBaseTag.GetTag(typeAttr.Value);
                }

                if (tag == null)
                {
                    continue;
                }

                XmlAttribute nameAttr = newNode.Attributes[SWBaseTag.NameAttribute];
                if (nameAttr != null)
                {
                    tag.Name = nameAttr.Value;
                }

                string newHTML = this.ProcessTag(tag, htmlType, out errormessage);
                if (newHTML == null)
                {
                    newHTML = "";
                }
                int s = newHTML.Length;
                if (!String.IsNullOrWhiteSpace(errormessage))
                {
                    html = null;
                    return;
                }

                html = html.Substring(0, startIndex) +
                       newHTML +
                       html.Substring(endIndex + 1, html.Length - endIndex - 1);
                int takeaway = endIndex - startIndex + 1;
                startIndex += newHTML.Length - takeaway;
                endIndex   += newHTML.Length - takeaway;
            }
        }
Example #4
0
        public ReportItemBase GetReport(int id,
                                        out string errormessage)
        {
            errormessage = "";
            ConnectionItem   connection   = null;
            FormItem         form         = null;
            TemplateItem     template     = null;
            List <SWBaseTag> formTags     = new List <SWBaseTag>();
            List <SWBaseTag> templateTags = new List <SWBaseTag>();

            try
            {
                string sql = "SELECT fk_connection, fk_template, fk_form, [Report].name, [ReportGroup].name FROM [Report]";
                sql += " LEFT JOIN [ReportGroup] ON [ReportGroup].id = [Report].fk_group";
                sql += " WHERE [Report].ID = " + id;

                _reader = this.ExecuteReader(sql);

                int    connectionID = -1;
                int    formID       = -1;
                int    templateID   = -1;
                string reportName   = "";
                string groupName    = "";

                if (!_reader.HasRows)
                {
                    _reader.Close();
                    errormessage = "Invalid report.";
                    return(null);
                }

                while (_reader.Read())
                {
                    connectionID = int.Parse(_reader[0].ToString());
                    templateID   = int.Parse(_reader[1].ToString());

                    if (_reader[2] != DBNull.Value)
                    {
                        formID = int.Parse(_reader[2].ToString());
                    }
                    reportName = _reader[3].ToString();
                    groupName  = _reader[4].ToString();
                    break;
                }
                _reader.Close();

                connection = new DBContent().GetConnection(connectionID);
                if (connection == null)
                {
                    errormessage = "Invalid connection.";
                    return(null);
                }

                form = new DBContent().GetForm(formID);

                template = new DBContent().GetTemplate(templateID);
                if (template == null)
                {
                    errormessage = "Invalid template.";
                    return(null);
                }

                sql     = "SELECT [TagValue].itemType, [Tag].type, [TagValue].name, [TagValue].value FROM [Tag]";
                sql    += " INNER JOIN [TagValue] ON [TagValue].fk_tag = [Tag].id";
                sql    += " WHERE [TagValue].fk_report = " + id;
                _reader = this.ExecuteReader(sql);
                while (_reader.Read())
                {
                    int itemType = 0;
                    if (!int.TryParse(_reader[0].ToString(), out itemType))
                    {
                        continue;
                    }

                    string type  = _reader[1].ToString().ToLower();
                    string name  = _reader[2].ToString().ToLower();
                    string value = _reader[3].ToString();

                    SWBaseTag tag = SWBaseTag.GetTag(type);
                    tag.Name  = name;
                    tag.Value = value;
                    if (tag == null)
                    {
                        continue;
                    }
                    switch (itemType)
                    {
                    case (int)DBContent.TagValueItemTypes.Form:
                        if (tag.BaseTagType == SWBaseTag.BaseTagTypes.Form ||
                            tag.BaseTagType == SWBaseTag.BaseTagTypes.Both)
                        {
                            formTags.Add(tag);
                        }
                        break;

                    case (int)DBContent.TagValueItemTypes.Template:
                        if (tag.BaseTagType == SWBaseTag.BaseTagTypes.Template ||
                            tag.BaseTagType == SWBaseTag.BaseTagTypes.Both)
                        {
                            templateTags.Add(tag);
                        }
                        break;

                    default:
                        continue;
                    }
                }

                ReportItemBase item = new ReportItemBase(id, reportName, groupName, connection, form, template);
                foreach (SWBaseTag dbtag in formTags)
                {
                    foreach (SWBaseTag itemTag in item.FormTags)
                    {
                        if (dbtag.Name.Equals(itemTag.Name) &&
                            dbtag.BaseTagType.Equals(itemTag.BaseTagType) &&
                            dbtag.TagType.Equals(itemTag.TagType))
                        {
                            itemTag.Value = dbtag.Value;
                            break;
                        }
                    }
                }

                foreach (SWBaseTag dbtag in templateTags)
                {
                    foreach (SWBaseTag itemTag in item.TemplateTags)
                    {
                        if (dbtag.Name.Equals(itemTag.Name) &&
                            dbtag.BaseTagType.Equals(itemTag.BaseTagType) &&
                            dbtag.TagType.Equals(itemTag.TagType))
                        {
                            itemTag.Value = dbtag.Value;
                            break;
                        }
                    }
                }
                return(item);
            }
            finally
            {
                this.CleanUp();
            }
        }
Example #5
0
        protected override ApplyResult ProcessApplyItem(ref object obj, out string errormessage, out string successmessage, out bool edited)
        {
            string action = "";

            if (this.Request.Form.action != null)
            {
                action = this.Request.Form.action.Value.ToLower();
            }
            errormessage   = "";
            successmessage = "";
            edited         = false;
            switch (action)
            {
            case "cancel":
                return(ApplyResult.Cancel);
            }

            this.Context.ViewBag.TemplateConst = ReportModule.Template;
            this.Context.ViewBag.FormConst     = ReportModule.Form;

            int id = -1;

            if (this.Request.Form.objectID != null)
            {
                int.TryParse(this.Request.Form.objectID.Value.ToString(), out id);
            }

            string name  = this.Request.Form.Name.Value;
            string group = this.Request.Form.GroupName.Value;

            ConnectionItem connection = null;

            if (this.Request.Form.Connection != null)
            {
                connection = new DBContent().GetConnection(int.Parse(this.Request.Form.Connection.Value));
            }

            FormItem form = null;
            int      formID;

            if (int.TryParse(this.Request.Form.Form, out formID))
            {
                form = new DBContent().GetForm(formID);
            }

            TemplateItem template   = null;
            int          templateID = -1;

            if (int.TryParse(this.Request.Form.Template, out templateID))
            {
                template = new DBContent().GetTemplate(templateID);
            }

            obj = new CreateReportItem(new ReportItemBase(id,
                                                          name,
                                                          group,
                                                          connection,
                                                          form,
                                                          template));

            foreach (KeyValuePair <string, object> kvp in (this.Request.Form as Nancy.DynamicDictionary).ToDictionary())
            {
                string[] split = kvp.Key.Split('.');
                if (split.Count() <= 1)
                {
                    continue;
                }

                SWBaseTag tag = null;
                switch (split[0])
                {
                case ReportModule.Form:
                    tag = (obj as CreateReportItem).ReportItem.FormTags.Where(x => x.Name.Equals(split[1])).FirstOrDefault();
                    if (tag != null)
                    {
                        tag.Value = kvp.Value.ToString();
                    }
                    break;

                case ReportModule.Template:
                    tag = (obj as CreateReportItem).ReportItem.TemplateTags.Where(x => x.Name.Equals(split[1])).FirstOrDefault();
                    if (tag != null)
                    {
                        tag.Value = kvp.Value.ToString();
                    }
                    break;
                }
            }

            switch (action)
            {
            case "save":
                bool result = new DBContent().SaveReport((obj as CreateReportItem).ReportItem, out errormessage);
                if (result)
                {
                    edited = (obj as CreateReportItem).ID > 0;
                    return(ApplyResult.Save);
                }
                else
                {
                    return(ApplyResult.Message);
                }

            default:
                return(ApplyResult.Message);
            }
        }