Esempio n. 1
0
        /// <summary>
        /// Creates a view in a specified project
        /// </summary>
        /// <old-param name="isrelatedview">Whether or not this view is a related (child) view</old-param>
        /// <old-param name="viewname">Name of the view</old-param>
        public void InsertView(View view)
        {
            #region Input Validation
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }
            #endregion Input Validation

            try
            {
                Query insertQuery = db.CreateQuery("insert into metaViews([Name], [IsRelatedView], [CheckCode], [Width], [Height], [Orientation], [LabelAlign] ) values (@Name, @IsRelatedView, @CheckCode, @Width, @Height, @Orientation, @LabelAlign)");
                insertQuery.Parameters.Add(new QueryParameter("@Name", DbType.String, view.Name));
                insertQuery.Parameters.Add(new QueryParameter("@IsRelatedView", DbType.Boolean, view.IsRelatedView));
                insertQuery.Parameters.Add(new QueryParameter("@CheckCode", DbType.String, view.CheckCode));
                insertQuery.Parameters.Add(new QueryParameter("@Width", DbType.Int32, view.PageWidth));
                insertQuery.Parameters.Add(new QueryParameter("@Height", DbType.Int32, view.PageHeight));
                insertQuery.Parameters.Add(new QueryParameter("@Orientation", DbType.String, view.PageOrientation));
                insertQuery.Parameters.Add(new QueryParameter("@LabelAlign", DbType.String, view.PageLabelAlign));
                db.ExecuteNonQuery(insertQuery);
                view.Id = this.GetMaxViewId();

                RecStatusField recStatusField = new RecStatusField(view);
                UniqueKeyField uniqueKeyField = new UniqueKeyField(view);
                GlobalRecordIdField globalRecordIdField = new GlobalRecordIdField(view);
                uniqueKeyField.SaveToDb();
                recStatusField.SaveToDb();
                globalRecordIdField.SaveToDb();
                if (view.IsRelatedView)
                {
                    ForeignKeyField foreignKeyField = new ForeignKeyField(view);
                    foreignKeyField.SaveToDb();
                }
            }
            catch (Exception ex)
            {
                throw new GeneralException("Could not create view in the database", ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new view in XML metadata
        /// </summary>
        /// <param name="view">View to be inserted in metadata</param>        
        public void InsertView(View view)
        {
            XmlDocument xmlDoc = GetXmlDocument();
            XmlNode viewsNode = GetViewsNode();
            XmlElement viewElement = xmlDoc.CreateElement("View");
            viewsNode.AppendChild(viewElement);
            view.ViewElement = viewElement;
            XmlAttribute viewId = xmlDoc.CreateAttribute("ViewId");
            viewId.Value = GetMaxViewId().ToString();
            view.Id = int.Parse(viewId.Value);
            viewElement.Attributes.Append(viewId);
            XmlAttribute viewNameAttribute = xmlDoc.CreateAttribute("Name");
            viewNameAttribute.Value = view.Name;
            viewElement.Attributes.Append(viewNameAttribute);
            XmlAttribute isRelatedView = xmlDoc.CreateAttribute("IsRelatedView");
            isRelatedView.Value = view.IsRelatedView.ToString();
            viewElement.Attributes.Append(isRelatedView);
            viewElement.AppendChild(xmlDoc.CreateElement("CheckCodeBefore"));
            viewElement.AppendChild(xmlDoc.CreateElement("CheckCodeAfter"));
            viewElement.AppendChild(xmlDoc.CreateElement("RecordCheckCodeBefore"));
            viewElement.AppendChild(xmlDoc.CreateElement("RecordCheckCodeAfter"));
            viewElement.AppendChild(xmlDoc.CreateElement("CheckCodeVariableDefinitions"));
            viewElement.AppendChild(xmlDoc.CreateElement("Pages"));
            viewElement.AppendChild(xmlDoc.CreateElement("Fields"));

            //Insert system fields .. RecStatus and UniqueKey
            RecStatusField recStatusField = new RecStatusField(view, viewElement);
            UniqueKeyField uniqueKeyField = new UniqueKeyField(view, viewElement);
            recStatusField.SaveToDb();
            uniqueKeyField.SaveToDb();
            if (view.IsRelatedView)
            {
                ForeignKeyField foreignKeyField = new ForeignKeyField(view, viewElement);
                foreignKeyField.SaveToDb();
            }
            Save();
        }