/// <summary> /// Insert a MirrorField record into the metaFields table. /// </summary> /// <param name="field">Mirror field.</param> /// <returns>Returns the Id of the last MirrorField added.</returns> public int CreateField(MirrorField field) { try { #region InputValidation if (field == null) { throw new ArgumentNullException("MirrorField"); } #endregion string queryString; if (field.SourceFieldId != 0) { queryString = "insert into metaFields([ViewId], [UniqueId], [ControlFontFamily], [ControlFontStyle], [ControlFontSize], [ControlHeightPercentage], [ControlLeftPositionPercentage], [ControlTopPositionPercentage], [ControlWidthPercentage], [FieldTypeId], [HasTabStop], [Name], [PageId], [PromptFontFamily], [PromptFontStyle], [PromptFontSize], [PromptLeftPositionPercentage], [PromptText], [PromptTopPositionPercentage], [TabIndex], [SourceFieldId]) " + "values (@ViewId, @UniqueId, @ControlFontFamily, @ControlFontStyle, @ControlFontSize, @ControlHeightPercentage, @ControlLeftPositionPercentage, @ControlTopPositionPercentage, @ControlWidthPercentage, @FieldTypeId, @HasTabStop, @Name, @PageId, @PromptFontFamily, @PromptFontStyle, @PromptFontSize, @PromptLeftPositionPercentage, @PromptText, @PromptTopPositionPercentage, @TabIndex, @SourceFieldId)"; } else { queryString = "insert into metaFields([ViewId], [UniqueId], [ControlFontFamily], [ControlFontStyle], [ControlFontSize], [ControlHeightPercentage], [ControlLeftPositionPercentage], [ControlTopPositionPercentage], [ControlWidthPercentage], [FieldTypeId], [HasTabStop], [Name], [PageId], [PromptFontFamily], [PromptFontStyle], [PromptFontSize], [PromptLeftPositionPercentage], [PromptText], [PromptTopPositionPercentage], [TabIndex]) " + "values (@ViewId, @UniqueId, @ControlFontFamily, @ControlFontStyle, @ControlFontSize, @ControlHeightPercentage, @ControlLeftPositionPercentage, @ControlTopPositionPercentage, @ControlWidthPercentage, @FieldTypeId, @HasTabStop, @Name, @PageId, @PromptFontFamily, @PromptFontStyle, @PromptFontSize, @PromptLeftPositionPercentage, @PromptText, @PromptTopPositionPercentage, @TabIndex)"; } Query insertQuery = db.CreateQuery(queryString); insertQuery.Parameters.Add(new QueryParameter("@ViewId", DbType.Int32, field.GetView().Id)); insertQuery.Parameters.Add(new QueryParameter("@UniqueId", DbType.Guid, field.UniqueId)); insertQuery.Parameters.Add(new QueryParameter("@ControlFontFamily", DbType.String, field.ControlFont.Name)); insertQuery.Parameters.Add(new QueryParameter("@ControlFontStyle", DbType.String, field.ControlFont.Style.ToString())); insertQuery.Parameters.Add(new QueryParameter("@ControlFontSize", DbType.Double, field.ControlFont.Size)); insertQuery.Parameters.Add(new QueryParameter("@ControlHeightPercentage", DbType.Double, field.ControlHeightPercentage)); insertQuery.Parameters.Add(new QueryParameter("@ControlLeftPositionPercentage", DbType.Double, field.ControlLeftPositionPercentage)); insertQuery.Parameters.Add(new QueryParameter("@ControlTopPositionPercentage", DbType.Double, field.ControlTopPositionPercentage)); insertQuery.Parameters.Add(new QueryParameter("@ControlWidthPercentage", DbType.Double, field.ControlWidthPercentage)); insertQuery.Parameters.Add(new QueryParameter("@FieldTypeId", DbType.Int32, (int)field.FieldType)); insertQuery.Parameters.Add(new QueryParameter("@HasTabStop", DbType.Boolean, field.HasTabStop)); insertQuery.Parameters.Add(new QueryParameter("@Name", DbType.String, field.Name)); insertQuery.Parameters.Add(new QueryParameter("@PageId", DbType.Int32, field.Page.Id)); insertQuery.Parameters.Add(new QueryParameter("@PromptFontFamily", DbType.String, field.PromptFont.Name)); insertQuery.Parameters.Add(new QueryParameter("@PromptFontStyle", DbType.String, field.PromptFont.Style.ToString())); insertQuery.Parameters.Add(new QueryParameter("@PromptFontSize", DbType.Double, field.PromptFont.Size)); insertQuery.Parameters.Add(new QueryParameter("@PromptLeftPositionPercentage", DbType.Double, field.PromptLeftPositionPercentage)); insertQuery.Parameters.Add(new QueryParameter("@PromptText", DbType.String, field.PromptText)); insertQuery.Parameters.Add(new QueryParameter("@PromptTopPositionPercentage", DbType.Double, field.PromptTopPositionPercentage)); insertQuery.Parameters.Add(new QueryParameter("@TabIndex", DbType.Int32, field.TabIndex)); if (field.SourceFieldId != 0) { insertQuery.Parameters.Add(new QueryParameter("@SourceFieldId", DbType.Int32, field.SourceFieldId)); } db.ExecuteNonQuery(insertQuery); return GetMaxFieldId(field.GetView().Id); } catch (Exception ex) { throw new GeneralException("Could not create field in the database", ex); } finally { } }
/// <summary> /// Update Mirror field. /// </summary> /// <param name="field">Mirror field to update.</param> /// <returns>Id of the updated field.</returns> public void UpdateField(MirrorField field) { try { #region InputValidation if (field == null) { throw new ArgumentNullException("MirrorField"); } #endregion XmlDocument xmlDoc = GetXmlDocument(); XmlNode fieldsNode = GetFieldsNode(GetFieldViewElement(field)); View view = field.GetView(); string fieldId = field.Id.ToString(); XmlNode fieldNode = fieldsNode.SelectSingleNode("//Field[@FieldId= '" + fieldId + "']"); fieldNode.Attributes["Name"].Value = field.Name.ToString(); fieldNode.Attributes["PromptText"].Value = field.PromptText.ToString(); fieldNode.Attributes["ControlFontFamily"].Value = field.ControlFont.FontFamily.Name.ToString(); fieldNode.Attributes["ControlFontStyle"].Value = field.ControlFont.Style.ToString(); fieldNode.Attributes["ControlFontSize"].Value = field.ControlFont.Size.ToString(); fieldNode.Attributes["ControlTopPositionPercentage"].Value = field.ControlTopPositionPercentage.ToString(); fieldNode.Attributes["ControlLeftPositionPercentage"].Value = field.ControlLeftPositionPercentage.ToString(); fieldNode.Attributes["ControlHeightPercentage"].Value = field.ControlHeightPercentage.ToString(); fieldNode.Attributes["ControlWidthPercentage"].Value = field.ControlWidthPercentage.ToString(); fieldNode.Attributes["TabIndex"].Value = field.TabIndex.ToString(); fieldNode.Attributes["HasTabStop"].Value = (bool.Parse(field.HasTabStop.ToString())).ToString(); fieldNode.Attributes["PromptFontFamily"].Value = field.PromptFont.FontFamily.Name.ToString(); fieldNode.Attributes["PromptFontStyle"].Value = field.PromptFont.Style.ToString(); fieldNode.Attributes["PromptFontSize"].Value = field.PromptFont.Size.ToString(); fieldNode.Attributes["PromptScriptName"].Value = field.PromptFont.Name.ToString(); fieldNode.Attributes["PromptTopPositionPercentage"].Value = field.PromptTopPositionPercentage.ToString(); fieldNode.Attributes["PromptLeftPositionPercentage"].Value = field.PromptLeftPositionPercentage.ToString(); fieldNode.Attributes["ControlScriptName"].Value = field.ControlFont.Name.ToString(); //fieldNode.Attributes["ShouldRetainImageSize"].Value = (bool.Parse(field.IsControlResizable.ToString())).ToString(); fieldNode.Attributes["SourceFieldId"].Value = field.SourceFieldId.ToString(); view.Project.Save(); } catch (Exception ex) { throw new GeneralException("Could not update MirrorField in the database", ex); } finally { } }
/// <summary> /// Retrieves data for mirror field from xml metadata /// </summary> /// <param name="field">A mirror field</param> /// <param name="fieldNode">The field node in the Xml metadata file</param> public void GetFieldData(MirrorField field, XmlNode fieldNode) { field.Id = Int32.Parse(fieldNode.Attributes["FieldId"].Value); field.Name = fieldNode.Attributes["Name"].Value; field.PromptText = fieldNode.Attributes["PromptText"].Value; //field.ControlFont = System.Drawing.Font(fieldNode.Attributes["ControlFontFamily"].Value); //field.ControlFont.Style = fieldNode.Attributes["ControlFontStyle"].Value; //field.ControlFont.Size = float.Parse(fieldNode.Attributes["ControlFontSize"].Value); field.ControlTopPositionPercentage = Double.Parse(fieldNode.Attributes["ControlTopPositionPercentage"].Value); field.ControlLeftPositionPercentage = Double.Parse(fieldNode.Attributes["ControlLeftPositionPercentage"].Value); field.ControlHeightPercentage = Double.Parse(fieldNode.Attributes["ControlHeightPercentage"].Value); field.ControlWidthPercentage = Double.Parse(fieldNode.Attributes["ControlWidthPercentage"].Value); field.TabIndex = Int32.Parse(fieldNode.Attributes["TabIndex"].Value); field.HasTabStop = bool.Parse(fieldNode.Attributes["HasTabStop"].Value); //field.PromptFont.FontFamily.Name = fieldNode.Attributes["PromptFontFamily"].Value; //field.PromptFont.Style = fieldNode.Attributes["PromptFontStyle"].Value; //field.PromptFont.Size = fieldNode.Attributes["PromptFontSize"].Value; //field.PromptFont.Name = fieldNode.Attributes["PromptScriptName"].Value; field.PromptTopPositionPercentage = Double.Parse(fieldNode.Attributes["PromptTopPositionPercentage"].Value); field.PromptLeftPositionPercentage = Double.Parse(fieldNode.Attributes["PromptLeftPositionPercentage"].Value); //field.ControlFont.Name = fieldNode.Attributes["ControlScriptName"].Value; //field.IsControlResizable = bool.Parse(fieldNode.Attributes["ShouldRetainImageSize"].Value); field.SourceFieldId = Int32.Parse(fieldNode.Attributes["SourceFieldId"].Value); //field. = fieldNode.Attributes["FieldTypeId"].Value; field.Page = new Page(field.GetView()); //field.Page.Name = field.Page.Id = int.Parse(fieldNode.Attributes["PageId"].Value); }
/// <summary> /// Create Mirror field. /// </summary> /// <param name="field">Mirror field to create.</param> /// <returns>Id of the newly created field.</returns> public int CreateField(MirrorField field) { try { #region InputValidation if (field == null) { throw new ArgumentNullException("MirrorField"); } #endregion XmlDocument xmlDoc = GetXmlDocument(); XmlNode fieldsNode = GetFieldsNode(field.ViewElement); View view = field.GetView(); XmlElement fieldElement = xmlDoc.CreateElement("Field"); XmlAttribute fieldIdAttribute = xmlDoc.CreateAttribute("FieldId"); fieldIdAttribute.Value = view.GetFieldId(field.ViewElement).ToString(); fieldElement.Attributes.Append(fieldIdAttribute); field.Id = Int32.Parse(fieldIdAttribute.Value); XmlAttribute fieldNameAttribute = xmlDoc.CreateAttribute("Name"); fieldNameAttribute.Value = field.Name; fieldElement.Attributes.Append(fieldNameAttribute); XmlAttribute fieldPromptText = xmlDoc.CreateAttribute("PromptText"); fieldPromptText.Value = field.PromptText; fieldElement.Attributes.Append(fieldPromptText); XmlAttribute fieldControlFontFamily = xmlDoc.CreateAttribute("ControlFontFamily"); fieldControlFontFamily.Value = field.ControlFont.FontFamily.Name; fieldElement.Attributes.Append(fieldControlFontFamily); XmlAttribute controlFontStyle = xmlDoc.CreateAttribute("ControlFontStyle"); controlFontStyle.Value = field.ControlFont.Style.ToString(); fieldElement.Attributes.Append(controlFontStyle); XmlAttribute controlFontSize = xmlDoc.CreateAttribute("ControlFontSize"); controlFontSize.Value = field.ControlFont.Size.ToString(); fieldElement.Attributes.Append(controlFontSize); XmlAttribute controlTopPositionPercentage = xmlDoc.CreateAttribute("ControlTopPositionPercentage"); controlTopPositionPercentage.Value = field.ControlTopPositionPercentage.ToString(); fieldElement.Attributes.Append(controlTopPositionPercentage); XmlAttribute controlLeftPositionPercentage = xmlDoc.CreateAttribute("ControlLeftPositionPercentage"); controlLeftPositionPercentage.Value = field.ControlLeftPositionPercentage.ToString(); fieldElement.Attributes.Append(controlLeftPositionPercentage); XmlAttribute controlHeightPercentage = xmlDoc.CreateAttribute("ControlHeightPercentage"); controlHeightPercentage.Value = field.ControlHeightPercentage.ToString(); fieldElement.Attributes.Append(controlHeightPercentage); XmlAttribute controlWidthPercentage = xmlDoc.CreateAttribute("ControlWidthPercentage"); controlWidthPercentage.Value = field.ControlWidthPercentage.ToString(); fieldElement.Attributes.Append(controlWidthPercentage); XmlAttribute tabIndex = xmlDoc.CreateAttribute("TabIndex"); tabIndex.Value = field.TabIndex.ToString(); fieldElement.Attributes.Append(tabIndex); XmlAttribute hasTabStop = xmlDoc.CreateAttribute("HasTabStop"); hasTabStop.Value = (bool.Parse(field.HasTabStop.ToString())).ToString(); fieldElement.Attributes.Append(hasTabStop); XmlAttribute promptFontFamily = xmlDoc.CreateAttribute("PromptFontFamily"); promptFontFamily.Value = field.PromptFont.FontFamily.Name; fieldElement.Attributes.Append(promptFontFamily); XmlAttribute promptFontStyle = xmlDoc.CreateAttribute("PromptFontStyle"); promptFontStyle.Value = field.PromptFont.Style.ToString(); fieldElement.Attributes.Append(promptFontStyle); XmlAttribute promptFontSize = xmlDoc.CreateAttribute("PromptFontSize"); promptFontSize.Value = field.PromptFont.Size.ToString(); fieldElement.Attributes.Append(promptFontSize); XmlAttribute promptScriptName = xmlDoc.CreateAttribute("PromptScriptName"); promptScriptName.Value = field.PromptFont.Name; fieldElement.Attributes.Append(promptScriptName); XmlAttribute promptTopPositionPercentage = xmlDoc.CreateAttribute("PromptTopPositionPercentage"); promptTopPositionPercentage.Value = field.PromptTopPositionPercentage.ToString(); fieldElement.Attributes.Append(promptTopPositionPercentage); XmlAttribute promptLeftPositionPercentage = xmlDoc.CreateAttribute("PromptLeftPositionPercentage"); promptLeftPositionPercentage.Value = field.PromptLeftPositionPercentage.ToString(); fieldElement.Attributes.Append(promptLeftPositionPercentage); XmlAttribute controlScriptName = xmlDoc.CreateAttribute("ControlScriptName"); controlScriptName.Value = field.ControlFont.Name; fieldElement.Attributes.Append(controlScriptName); XmlAttribute shouldRetainImageSize = xmlDoc.CreateAttribute("ShouldRetainImageSize"); //shouldRetainImageSize.Value = (bool.Parse(field.IsControlResizable.ToString())).ToString(); fieldElement.Attributes.Append(shouldRetainImageSize); XmlAttribute sourceFieldId = xmlDoc.CreateAttribute("SourceFieldId"); sourceFieldId.Value = field.SourceFieldId.ToString(); fieldElement.Attributes.Append(sourceFieldId); XmlAttribute fieldTypeId = xmlDoc.CreateAttribute("FieldTypeId"); fieldTypeId.Value = field.FieldType.ToString(); fieldElement.Attributes.Append(fieldTypeId); XmlAttribute pageId = xmlDoc.CreateAttribute("PageId"); pageId.Value = field.Page.Id.ToString(); fieldElement.Attributes.Append(pageId); fieldsNode.AppendChild(fieldElement); view.Project.Save(); return field.Id; } finally { } }
/// <summary> /// Gets the source field name of a mirror field /// </summary> /// <param name="field">A mirror field</param> /// <returns>The source field name</returns> private string GetSourceFieldName(MirrorField field) { // Epi2000 views are alwys stored with prefix. string viewName = "view" + field.GetView().Name; return sourceProject.Metadata.GetSourceFieldName(field.Name, viewName); }
/// <summary> /// Gets the source field id of a mirror field /// </summary> /// <param name="field">A mirror field</param> /// <returns>The source field id</returns> private int GetSourceFieldId(MirrorField field) { string sourceFieldName = GetSourceFieldName(field); return GetFieldIdByName(sourceFieldName, field.GetView()); }