예제 #1
0
        /// <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
            {

            }
        }
예제 #2
0
        /// <summary>
        /// Gets all the fields in a view
        /// </summary>
        /// <param name="view">A view object</param>
        /// <returns>A collection of fields</returns>
        public virtual FieldCollectionMaster GetFields(View view)
        {
            FieldCollectionMaster fields = new FieldCollectionMaster();
            try
            {
                DataTable table = GetFieldsAsDataTable(view);
                foreach (DataRow row in table.Rows)
                {
                    MetaFieldType fieldTypeId = (MetaFieldType)row[ColumnNames.FIELD_TYPE_ID];
                    Field field = null;
                    switch (fieldTypeId)
                    {
                        case MetaFieldType.Text:
                            field = new SingleLineTextField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.LabelTitle:
                            field = new LabelField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.TextUppercase:
                            field = new UpperCaseTextField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Multiline:
                            field = new MultilineTextField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Number:
                            field = new NumberField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.PhoneNumber:
                            field = new PhoneNumberField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Date:
                            field = new DateField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Time:
                            field = new TimeField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.DateTime:
                            field = new DateTimeField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Checkbox:
                            field = new CheckBoxField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.YesNo:
                            field = new YesNoField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Option:
                            field = new OptionField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.CommandButton:
                            field = new CommandButtonField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Image:
                            field = new ImageField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Mirror:
                            field = new MirrorField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Grid:
                            field = new GridField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Group:
                            field = new GroupField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.GUID:
                            field = new GUIDField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.LegalValues:
                            field = new DDLFieldOfLegalValues(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Codes:
                            field = new DDLFieldOfCodes(view);
                            ((DDLFieldOfCodes)field).LoadFromRow(row);  //zack
                            break;
                        case MetaFieldType.List:
                            field = new DDListField(view);
                            ((DDListField)field).LoadFromRow(row);
                            break;
                        case MetaFieldType.CommentLegal:
                            field = new DDLFieldOfCommentLegal(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.Relate:
                            field = new RelatedViewField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.RecStatus:
                            field = new RecStatusField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.UniqueKey:
                            field = new UniqueKeyField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.ForeignKey:
                            field = new ForeignKeyField(view);
                            field.LoadFromRow(row);
                            break;
                        case MetaFieldType.GlobalRecordId:
                            field = new GlobalRecordIdField(view);
                            field.LoadFromRow(row);
                            break;
                        default:
                            throw new ApplicationException("Invalid Field Type");
                    }
                    // Note: This check ideally shouldn't be necessary, but Epi 3.5.1 and previous versions actually do allow duplicate field names for group fields.
                    if (fields.Contains(field))
                    {
                        Logger.Log(DateTime.Now + ":  " + string.Format("The {0} field with name \"{1}\" already exists in {2}. This field has not been imported.", field.GetType().ToString(), field.Name, view.Name));
                    }
                    else
                    {
                        fields.Add(field);
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return (fields);
        }
예제 #3
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);
            }
        }
예제 #4
0
 /// <summary>
 /// Retrieves data for rec status field from xml metadata.
 /// </summary>
 /// <param name="field">A rec status field.</param>
 /// <param name="fieldNode">XML node for rec status field.</param>
 public void GetFieldData(RecStatusField field, XmlNode fieldNode)
 {
 }
예제 #5
0
        /// <summary>
        /// Fills the listbox with controls to be searched for
        /// </summary>
        private void BuildControlsList()
        {
            lbxSearchFields.Items.Clear();

            if (view.Pages.Count > 0)
            {
                foreach (Page page in view.Pages)
                {
                    foreach (Epi.Fields.Field field in page.Fields)
                    {
                         if (!(field is UniqueKeyField) && !(field is RecStatusField) && !(field is MirrorField) && !(field is RelatedViewField) && !(field is LabelField) && !(field is GridField) && !(field is GroupField) && !(field is CommandButtonField))
                           {
                            if (field is IPatternable)
                            {
                                lbxSearchFields.Items.Add(new SearchListBoxItem(field.Name.ToString(), field.Id, field.FieldType.ToString(), ((IPatternable)field).Pattern, string.Empty));
                            }
                            else
                            {
                                lbxSearchFields.Items.Add(new SearchListBoxItem(field.Name.ToString(), field.Id, field.FieldType.ToString(), string.Empty, string.Empty));
                            }
                        }
                    }
                 }
                //--Ei-139
                RecStatusField recstatus = new RecStatusField(view);
                lbxSearchFields.Items.Add(new SearchListBoxItem(recstatus.Name.ToString(), recstatus.Id, recstatus.FieldType.ToString(), string.Empty, string.Empty));
                GlobalRecordIdField globalfld = new GlobalRecordIdField(view);
                lbxSearchFields.Items.Add(new SearchListBoxItem(globalfld.Name.ToString(), globalfld.Id, globalfld.FieldType.ToString(), string.Empty, string.Empty));
                FirstSaveTimeField firstsavetime = new FirstSaveTimeField(view);
                lbxSearchFields.Items.Add(new SearchListBoxItem(firstsavetime.Name.ToString(), firstsavetime.Id, firstsavetime.FieldType.ToString(), string.Empty, string.Empty));
                LastSaveTimeField lastsavetime = new LastSaveTimeField(view);
                lbxSearchFields.Items.Add(new SearchListBoxItem(lastsavetime.Name.ToString(), lastsavetime.Id, lastsavetime.FieldType.ToString(), string.Empty, string.Empty));
                //--
              }
        }
예제 #6
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();
        }
예제 #7
0
        /// <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
            {
            }
        }
예제 #8
0
        /// <summary>
        /// Gets all the fields in a view
        /// </summary>
        /// <param name="view">the view object</param>
        /// <returns>A collection of fields</returns>
        public virtual FieldCollectionMaster GetFields(View view)
        {
            try
            {
                FieldCollectionMaster fields = new FieldCollectionMaster();

                //DataTable table = GetFieldsAsDataTable(view);
                //foreach (DataRow row in table.Rows)
                //{
                //    MetaFieldType fieldTypeId = (MetaFieldType)row[ColumnNames.FIELD_TYPE_ID];
                //    Field field = null;

                XmlNode fieldsNode = view.ViewElement.SelectSingleNode("Fields");
                foreach (XmlNode fieldNode in fieldsNode.ChildNodes)
                {
                    //MetaFieldType fieldTypeId = (MetaFieldType)(int.Parse(fieldNode.Attributes["FieldTypeId"].Value.ToString()));
                    MetaFieldType fieldTypeId = (MetaFieldType)Enum.Parse(typeof(MetaFieldType), fieldNode.Attributes["FieldTypeId"].Value.ToString());

                    Field field = null;
                    switch (fieldTypeId)
                    {
                        case MetaFieldType.Text:
                            field = new SingleLineTextField(view, fieldNode);
                            break;
                        case MetaFieldType.LabelTitle:
                            field = new LabelField(view, fieldNode);
                            break;
                        case MetaFieldType.TextUppercase:
                            field = new UpperCaseTextField(view, fieldNode);
                            break;
                        case MetaFieldType.Multiline:
                            field = new MultilineTextField(view, fieldNode);
                            break;
                        case MetaFieldType.Number:
                            field = new NumberField(view, fieldNode);
                            break;
                        case MetaFieldType.PhoneNumber:
                            field = new PhoneNumberField(view, fieldNode);
                            break;
                        case MetaFieldType.Date:
                            field = new DateField(view, fieldNode);
                            break;
                        case MetaFieldType.Time:
                            field = new TimeField(view, fieldNode);
                            break;
                        case MetaFieldType.DateTime:
                            field = new DateTimeField(view, fieldNode);
                            break;
                        case MetaFieldType.Checkbox:
                            field = new CheckBoxField(view, fieldNode);
                            break;
                        case MetaFieldType.YesNo:
                            field = new YesNoField(view, fieldNode);
                            break;
                        case MetaFieldType.Option:
                            field = new OptionField(view, fieldNode);
                            break;
                        case MetaFieldType.CommandButton:
                            field = new CommandButtonField(view, fieldNode);
                            break;
                        case MetaFieldType.Image:
                            field = new ImageField(view, fieldNode);
                            break;
                        case MetaFieldType.Mirror:
                            field = new MirrorField(view, fieldNode);
                            break;
                        case MetaFieldType.Grid:
                            field = new GridField(view, fieldNode);
                            break;
                        case MetaFieldType.LegalValues:
                            field = new DDLFieldOfLegalValues(view, fieldNode);
                            break;
                        case MetaFieldType.Codes:
                            field = new DDLFieldOfCodes(view, fieldNode);
                            break;
                        case MetaFieldType.List:
                            field = new DDListField(view, fieldNode);
                            break;
                        case MetaFieldType.CommentLegal:
                            field = new DDLFieldOfCommentLegal(view, fieldNode);
                            break;
                        case MetaFieldType.Relate:
                            field = new RelatedViewField(view, fieldNode);
                            break;
                        case MetaFieldType.RecStatus:
                            field = new RecStatusField(view);
                            break;
                        case MetaFieldType.UniqueKey:
                            field = new UniqueKeyField(view);
                            break;
                        case MetaFieldType.ForeignKey:
                            field = new ForeignKeyField(view);
                            break;
                        default:
                            throw new GeneralException("Invalid Field Type");
                    }
                    //field.LoadFromRow(row);
                    fields.Add(field);
                }
                return (fields);
            }
            finally
            {
            }
        }