Exemplo n.º 1
0
        /// <summary>
        /// Create LastSaveTime field.
        /// </summary>
        /// <param name="field">LastSaveTime field to create.</param>
        /// <returns>Id of the newly created field.</returns>
        public int CreateField(LastSaveTimeField field)
        {
            try
            {
                #region InputValidation
                if (field == null)
                {
                    throw new ArgumentNullException("LastSaveTimeField");
                }
                #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
            {
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Insert a FirstSaveTimeField record into the metaFields table.
        /// </summary>
        /// <param name="field">LastSaveTime field.</param>
        /// <returns>Returns the Id of the lastSaveTime Field added.</returns>
        public int CreateField(LastSaveTimeField field)
        {
            try
            {
                #region InputValidation
                if (field == null)
                {
                    throw new ArgumentNullException("LastSaveTimeField");
                }
                #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("Unable to get LastSaveTime field from the database", ex);
            }
            finally
            {

            }
        }