public bool SaveForm(FormItem item, out string errormessage) { errormessage = ""; if (item == null) { errormessage = "Invalid form."; return(false); } if (String.IsNullOrWhiteSpace(item.Name)) { errormessage = "The form name cannot be blank."; return(false); } SqliteDataReader reader = null; try { this.AddParameter("@name", item.Name); this.AddParameter("@bodyHTML", item.HTML); this.AddParameter("@id", item.ID); if (item.ID > 0) { reader = this.ExecuteReader("SELECT id FROM ReportingForm WHERE id != @id AND name LIKE @name"); if (reader.HasRows) { errormessage = "A reporting form with that name already exists."; return(false); } reader.Close(); this.ExecuteNonQuery("UPDATE ReportingForm SET name = @name, bodyHTML = @bodyHTML WHERE id = @id"); } else { reader = this.ExecuteReader("SELECT id FROM ReportingForm WHERE name LIKE @name"); if (reader.HasRows) { errormessage = "A reporting form with that name already exists."; return(false); } reader.Close(); this.ExecuteNonQuery("INSERT INTO ReportingForm(name, bodyHTML) VALUES(@name, @bodyHTML)"); } return(true); } finally { this.CleanUp(); } }
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; }
public ReportItemBase(int id, string name, string groupName, ConnectionItem connection, FormItem form, TemplateItem template) { this.ID = id; this.Name = name; this.GroupName = groupName; this.ConnectionItem = connection; this.FormItem = form; this.TemplateItem = template; }
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(); } }