Example #1
0
 protected void gridviewObjectType_CommandButtonInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCommandButtonEventArgs e)
 {
     if (e.ButtonType == ColumnCommandButtonType.SelectCheckbox)
     {
         //Determine type of object type custom field
         //Get current object type
         var objectId = gridviewObjectType.GetRowValues(e.VisibleIndex, "ObjectTypeId");
         if (objectId != null)
         {
             NAS.DAL.CMS.ObjectDocument.CustomField customField = GetCurrentCustomField(session);
             if (customField == null)
             {
                 return;
             }
             ObjectType objectType = session.GetObjectByKey <ObjectType>((Guid)objectId);
             //Get ObjectTypeCustomField
             CriteriaOperator criteria = CriteriaOperator.And(
                 new BinaryOperator("ObjectTypeId", objectType),
                 new BinaryOperator("CustomFieldId", customField),
                 CriteriaOperator.Or(
                     new BinaryOperator("CustomFieldType", CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER),
                     new BinaryOperator("CustomFieldType", CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER_READONLY),
                     new BinaryOperator("CustomFieldType", CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_READONLY)
                     )
                 );
             ObjectTypeCustomField objectTypeCustomField =
                 session.FindObject <ObjectTypeCustomField>(criteria);
             if (objectTypeCustomField != null)
             {
                 e.Enabled = false;
             }
         }
     }
 }
        public bool CustomFieldEditing_PreTransitionCRUD(string transition)
        {
            switch (transition.ToUpper())
            {
            case "SAVE":
                if (ASPxEdit.ValidateEditorsInContainer(formlayoutGeneralInfo))
                {
                    using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                    {
                        Guid selectedCustomFieldTypeId =
                            Guid.Parse(cbbCustomFieldType.SelectedItem.Value.ToString());
                        CustomFieldType customFieldType =
                            uow.GetObjectByKey <CustomFieldType>(selectedCustomFieldTypeId);
                        //Get eidting CustomField
                        NAS.DAL.CMS.ObjectDocument.CustomField customField =
                            uow.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.CustomField>(CustomFieldId);
                        customField.Name = txtCustomFieldName.Text;
                        customField.CustomFieldTypeId = customFieldType;
                        //Set new Id to session variable
                        CustomFieldId = customField.CustomFieldId;
                        uow.CommitChanges();
                    }
                }
                else
                {
                    return(false);
                }
                break;

            default:
                break;
            }
            return(true);
        }
        public bool CustomFieldCreatingHasNoInitData_PreTransitionCRUD(string transition)
        {
            switch (transition.ToUpper())
            {
            case "ACCEPT":
                if (ASPxEdit.ValidateEditorsInContainer(formlayoutGeneralInfo))
                {
                    using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                    {
                        Guid selectedCustomFieldTypeId =
                            Guid.Parse(cbbCustomFieldType.SelectedItem.Value.ToString());
                        CustomFieldType customFieldType =
                            uow.GetObjectByKey <CustomFieldType>(selectedCustomFieldTypeId);
                        //Create new CustomField
                        NAS.DAL.CMS.ObjectDocument.CustomField customField =
                            new NAS.DAL.CMS.ObjectDocument.CustomField(uow)
                        {
                            CustomFieldId     = Guid.NewGuid(),
                            Name              = txtCustomFieldName.Text,
                            CustomFieldTypeId = customFieldType
                        };
                        //Attach CustomField to ObjectTypeId
                        if (ObjectTypeId != null && !ObjectTypeId.Equals(Guid.Empty))
                        {
                            /*2013-12-12 Khoa.Truong DEL START
                             * Decoupling with the client using this form
                             * //Guid objectTypeId = ((ObjectTypeCustomFieldListing)Parent).ObjectTypeId;
                             * 2013-12-12 Khoa.Truong DEL END*/
                            ObjectType            objectType            = uow.GetObjectByKey <ObjectType>(ObjectTypeId);
                            ObjectTypeCustomField objectTypeCustomField = new ObjectTypeCustomField(uow)
                            {
                                ObjectTypeCustomFieldId = Guid.NewGuid(),
                                CustomFieldId           = customField,
                                ObjectTypeId            = objectType
                            };
                        }
                        //Attach new custom fields for all object of the object type

                        /*These code is replace with lazy updating for custom fields of each object
                         * //ObjectBO objectBO = new ObjectBO();
                         * //objectBO.UpdateCMSObjects(uow, objectTypeId);
                         */

                        uow.CommitChanges();
                    }
                }
                else
                {
                    return(false);
                }
                break;

            default:
                break;
            }
            return(true);
        }
Example #4
0
 private NAS.DAL.CMS.ObjectDocument.CustomField GetCurrentCustomField(Session _session)
 {
     NAS.DAL.CMS.ObjectDocument.CustomField ret = null;
     if (CustomFieldId.Equals(Guid.Empty))
     {
         return(null);
     }
     ret = _session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.CustomField>(CustomFieldId);
     return(ret);
 }
Example #5
0
        protected void gridviewCustomField_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {
            Guid customFieldId = (Guid)e.Keys["CustomFieldId"];

            //Check is system type
            NAS.DAL.CMS.ObjectDocument.CustomField customField =
                session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.CustomField>(customFieldId);
            if (customField.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_READONLY) ||
                customField.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER_READONLY))
            {
                throw new Exception("Không thể xóa trường dữ liệu được tạo ra bởi hệ thống");
            }
        }
Example #6
0
 private void formlayoutCustomFieldAttachment_DataBind()
 {
     if (CustomFieldId != Guid.Empty)
     {
         NAS.DAL.CMS.ObjectDocument.CustomField customField = null;
         customField = GetCurrentCustomField(session);
         if (customField.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER) ||
             customField.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER_READONLY) ||
             customField.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_READONLY))
         {
             lblType.Text = "Hệ thống";
         }
         else
         {
             lblType.Text = "Mặc định";
         }
         //Bind data to form
         dsCustomFieldItem.Criteria = new BinaryOperator("CustomFieldId", CustomFieldId).ToString();
     }
 }
        public bool CustomFieldDataCreating_PreTransitionCRUD(string transition)
        {
            switch (transition.ToUpper())
            {
            case "ACCEPT":
                using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                {
                    //Get creating custom field
                    NAS.DAL.CMS.ObjectDocument.CustomField customField =
                        uow.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.CustomField>(CustomFieldId);
                    //Attach CustomField to ObjectTypeId
                    if (ObjectTypeId != null && !ObjectTypeId.Equals(Guid.Empty))
                    {
                        /*2013-12-12 Khoa.Truong DEL START
                         * Decoupling with the client using this form
                         * //Guid objectTypeId = ((ObjectTypeCustomFieldListing)Parent).ObjectTypeId;
                         * 2013-12-12 Khoa.Truong DEL END*/
                        ObjectType            objectType            = uow.GetObjectByKey <ObjectType>(ObjectTypeId);
                        ObjectTypeCustomField objectTypeCustomField = new ObjectTypeCustomField(uow)
                        {
                            ObjectTypeCustomFieldId = Guid.NewGuid(),
                            CustomFieldId           = customField,
                            ObjectTypeId            = objectType
                        };
                    }

                    /*These code is replace with lazy updating for custom fields of each object
                     * ////Attach new custom fields for all object of the object type
                     * //ObjectBO objectBO = new ObjectBO();
                     * //objectBO.UpdateCMSObjects(uow, objectTypeId);
                     */
                    uow.CommitChanges();
                }
                break;

            default:
                break;
            }
            return(true);
        }
Example #8
0
 protected void gridviewCustomField_CustomButtonInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonEventArgs e)
 {
     if (e.ButtonID.Equals("CustomField_Edit") ||
         e.ButtonID.Equals("CustomField_Delete"))
     {
         var objectId = gridviewCustomField.GetRowValues(e.VisibleIndex, "CustomFieldId");
         if (objectId != null)
         {
             Guid customFieldId = (Guid)gridviewCustomField.GetRowValues(e.VisibleIndex, "CustomFieldId");
             NAS.DAL.CMS.ObjectDocument.CustomField customField =
                 session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.CustomField>(customFieldId);
             if (customField.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_READONLY) ||
                 customField.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER_READONLY) ||
                 customField.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER))
             {
                 e.Visible = DevExpress.Utils.DefaultBoolean.False;
             }
             else
             {
                 e.Visible = DevExpress.Utils.DefaultBoolean.Default;
             }
         }
     }
 }
        protected void cpnCustomFieldEditingForm_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            string[] args       = e.Parameter.Split('|');
            string   command    = args[0];
            bool     isSuccess  = false;
            string   transition = null;

            try
            {
                switch (command)
                {
                case "Create":
                    ClearForm();
                    CustomFieldId    = Guid.NewGuid();
                    GUIContext.State = new CustomFieldCreating(this);
                    transition       = command;
                    isSuccess        = true;
                    break;

                case "Edit":
                    if (args.Length > 1)
                    {
                        CustomFieldId = Guid.Parse(args[1]);
                        //Check is system type
                        NAS.DAL.CMS.ObjectDocument.CustomField customField =
                            session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.CustomField>(CustomFieldId);
                        if (customField.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_READONLY) ||
                            customField.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER_READONLY))
                        {
                            throw new Exception("Không thể chỉnh sửa trường dữ liệu được tạo ra bởi hệ thống");
                        }
                    }
                    else
                    {
                        throw new Exception("CustomFieldId cannot be null");
                    }
                    ClearForm();
                    GUIContext.State = new CustomFieldEditing(this);
                    GUIContext.Request(GetCustomFieldEditingTransition(GetSelectedCustomFieldType().Code), this);
                    transition = command;
                    isSuccess  = true;
                    break;

                case "TabChanged":
                    string editingTransition = null;
                    if (pagCustomFieldEditingForm.ActiveTabIndex == 0)
                    {
                        string customFieldEditingTransition = null;
                        editingTransition = "EDIT_FIELD";
                        //Transit to CustomFieldDataEditing state by transition 'EDIT_FIELD'
                        GUIContext.Request(editingTransition, this);
                        //Then transit to concrete CustomFieldCreating
                        customFieldEditingTransition = GetCustomFieldEditingTransition(GetSelectedCustomFieldType().Code);
                        GUIContext.Request(customFieldEditingTransition, this);
                    }
                    else if (pagCustomFieldEditingForm.ActiveTabIndex == 1)
                    {
                        editingTransition = "EDIT_DATA";
                        GUIContext.Request(editingTransition, this);
                        GUIContext.Request(GetCustomFieldDataEditingTransition(GetSelectedCustomFieldType().Code), this);
                    }
                    transition = editingTransition;
                    txtCustomFieldName.IsValid = true;
                    isSuccess = true;
                    break;

                case "DataTypeChanged":
                    string customFieldTransition = null;
                    customFieldTransition = GetCustomFieldCreatingTransition(GetSelectedCustomFieldType().Code);
                    GUIContext.Request(customFieldTransition, this);
                    transition = customFieldTransition;
                    txtCustomFieldName.IsValid = true;
                    isSuccess = true;
                    break;

                case "Next":
                    string customFieldDataCreatingTransition = null;
                    //Transit to CustomFieldDataCreating state by transition 'NEXT'
                    if (GUIContext.Request(command, this))
                    {
                        //Then transit to concrete CustomFieldDataCreating
                        customFieldDataCreatingTransition = GetCustomFieldDataCreatingTransition(GetSelectedCustomFieldType().Code);
                        GUIContext.Request(customFieldDataCreatingTransition, this);
                    }
                    isSuccess  = true;
                    transition = command;
                    break;

                default:
                    GUIContext.Request(command, this);
                    transition = command;
                    isSuccess  = true;
                    break;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (transition != null)
                {
                    cpnCustomFieldEditingForm.JSProperties.Add("cpCallbackArgs",
                                                               String.Format("{{ \"transition\": \"{0}\", \"success\": {1} }}",
                                                                             transition, isSuccess.ToString().ToLower()));
                }
            }
        }
Example #10
0
        public bool UpdateCustomFieldData(Guid objectCustomFieldId,
                                          IEnumerable <Guid> refIds,
                                          PredefinitionCustomFieldTypeEnum preDefinitionType,
                                          CustomFieldTypeFlag flag)
        {
            bool       ret = false;
            UnitOfWork uow = null;

            try
            {
                uow = XpoHelper.GetNewUnitOfWork();

                ObjectCustomField objectCustomField = uow.GetObjectByKey <ObjectCustomField>(objectCustomFieldId);

                objectCustomField.CustomFieldType = flag.Value;

                uow.FlushChanges();

                NAS.DAL.CMS.ObjectDocument.CustomField customField =
                    objectCustomField.ObjectTypeCustomFieldId.CustomFieldId;

                //Delete all old data
                uow.Delete(objectCustomField.ObjectCustomFieldDatas);
                uow.FlushChanges();
                //Insert new data for object
                if (refIds != null)
                {
                    foreach (var refId in refIds)
                    {
                        PredefinitionData predefinitionData = new PredefinitionData(uow)
                        {
                            CustomFieldId     = customField,
                            PredefinitionType =
                                Enum.GetName(typeof(PredefinitionCustomFieldTypeEnum), preDefinitionType),
                            RefId = refId
                        };
                        //predefinitionData.Save();

                        ObjectCustomFieldData objectCustomFieldData = new ObjectCustomFieldData(uow)
                        {
                            CustomFieldDataId   = predefinitionData,
                            ObjectCustomFieldId = objectCustomField
                        };
                        //objectCustomFieldData.Save();

                        uow.FlushChanges();
                    }
                }

                ICustomFieldDataPreDefinitionDataGetter getter = GetDataGetter(preDefinitionType);
                ObjectBO objectBO = new ObjectBO();
                DynamicObjectListSerializeDataItem dataitem = new DynamicObjectListSerializeDataItem()
                {
                    ObjectCustomFieldId = objectCustomFieldId,
                    CustomFieldName     = customField.Name,
                    CustomFieldData     = getter.GetData(objectCustomFieldId).ToString()
                };
                objectBO.SetDynamicObjectListItem(uow, objectCustomField.ObjectId.ObjectId, dataitem);

                uow.CommitChanges();
                ret = true;
                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }
Example #11
0
        protected void popupCustomFieldAttachment_WindowCallback(object source, DevExpress.Web.ASPxPopupControl.PopupWindowCallbackArgs e)
        {
            try
            {
                string[] args = e.Parameter.Split('|');
                NAS.DAL.CMS.ObjectDocument.CustomField customField = null;
                string command = args[0];
                switch (command)
                {
                    #region AttachTo
                case "AttachTo":
                    //Get CustomField
                    if (args.Length > 1)
                    {
                        CustomFieldId = Guid.Parse(args[1]);
                    }
                    else
                    {
                        throw new Exception("Invalid parameter");
                    }
                    customField = GetCurrentCustomField(session);

                    //Bind data to form
                    formlayoutCustomFieldAttachment_DataBind();

                    /////Set Selection for gridview
                    gridviewObjectType.Selection.UnselectAll();
                    if (customField.ObjectTypeCustomFields != null)
                    {
                        foreach (var objectTypeCustomField in customField.ObjectTypeCustomFields)
                        {
                            gridviewObjectType.Selection
                            .SetSelectionByKey(objectTypeCustomField.ObjectTypeId.ObjectTypeId, true);
                        }
                    }
                    break;
                    #endregion

                    #region Save
                case "Save":
                    using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                    {
                        //Delete all object type custom field which it's type is not master and system
                        customField = GetCurrentCustomField(uow);
                        var userDefinedObjectTypeCustomFields = customField.ObjectTypeCustomFields.Where(r =>
                                                                                                         !r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER) &&
                                                                                                         !r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER_READONLY) &&
                                                                                                         !r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_READONLY)).ToList();
                        uow.Delete(userDefinedObjectTypeCustomFields);
                        //Get selection to save
                        var selectedObjectTypeIds = gridviewObjectType.GetSelectedFieldValues("ObjectTypeId")
                                                    .Select(r => Guid.Parse(r.ToString()));

                        //Update object custom field table
                        foreach (var selectedObjectTypeId in selectedObjectTypeIds)
                        {
                            //Check exist
                            int count = customField.ObjectTypeCustomFields.Where(r =>
                                                                                 r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER) ||
                                                                                 r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_MASTER_READONLY) ||
                                                                                 r.CustomFieldType.Equals(CustomFieldTypeConstant.CUSTOM_FIELD_TYPE_READONLY))
                                        .Count(r => r.ObjectTypeId.ObjectTypeId == selectedObjectTypeId);
                            if (count != 0)
                            {
                                continue;
                            }
                            //get ObjectType
                            ObjectType objectType = uow.GetObjectByKey <ObjectType>(selectedObjectTypeId);
                            //Create new ObjectTypeCustomField
                            ObjectTypeCustomField objectTypeCustomField = new ObjectTypeCustomField(uow)
                            {
                                CustomFieldId = customField,
                                ObjectTypeId  = objectType
                            };
                            objectTypeCustomField.Save();
                        }
                        uow.CommitChanges();
                    }
                    break;
                    #endregion

                default:
                    break;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }