/// <summary> /// Insert a RecStatusField record into the metaFields table. /// </summary> /// <param name="field">RecStatus field.</param> /// <returns>Returns the Id of the last RecStatusField added.</returns> public int CreateField(RecStatusField field) { try { #region InputValidation if (field == null) { throw new ArgumentNullException("RecStatusField"); } #endregion Query insertQuery = db.CreateQuery("insert into metaFields([DataTableName], [ViewId], [FieldTypeId], [Name]) " + "values (@DataTableName, @ViewId, @FieldTypeId, @Name)"); insertQuery.Parameters.Add(new QueryParameter("@DataTableName", DbType.String, field.TableName)); insertQuery.Parameters.Add(new QueryParameter("@ViewId", DbType.Int32, field.GetView().Id)); insertQuery.Parameters.Add(new QueryParameter("@FieldTypeId", DbType.Int32, (int)field.FieldType)); insertQuery.Parameters.Add(new QueryParameter("@Name", DbType.String, field.Name)); db.ExecuteNonQuery(insertQuery); return GetMaxFieldId(field.GetView().Id); } catch (Exception ex) { throw new GeneralException("Could not create RecStatus field in the database", ex); } finally { } }
/// <summary> /// Create Record Status field. /// </summary> /// <param name="field">Record Status field to create.</param> /// <returns>Id of the newly created field.</returns> public int CreateField(RecStatusField field) { try { #region InputValidation if (field == null) { throw new ArgumentNullException("RecStatusField"); } #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 fieldTypeId = xmlDoc.CreateAttribute("FieldTypeId"); fieldTypeId.Value = field.FieldType.ToString(); fieldElement.Attributes.Append(fieldTypeId); XmlAttribute fieldNameAttribute = xmlDoc.CreateAttribute("Name"); fieldNameAttribute.Value = field.Name; fieldElement.Attributes.Append(fieldNameAttribute); XmlAttribute fieldViewId = xmlDoc.CreateAttribute("ViewId"); fieldViewId.Value = view.Id.ToString(); fieldElement.Attributes.Append(fieldViewId); XmlAttribute dataTableName = xmlDoc.CreateAttribute("DataTableName"); dataTableName.Value = field.TableName; fieldElement.Attributes.Append(dataTableName); fieldsNode.AppendChild(fieldElement); view.Project.Save(); return field.Id; } finally { } }