Пример #1
0
        /// <summary>
        /// Строим таблицу по модели
        /// </summary>
        public void InitializeControl(object model, int operTypeId = 0)
        {
            tlpPropertyControls.Controls.Clear();
            _operTypeId = operTypeId;
            tlpPropertyControls.RowCount = 1;
            _controlsValues.Clear();
            if (model == null)
            {
                return;
            }

            _modelType = model.GetType();

            foreach (var prop in model.GetType().GetProperties())
            {
                string displayName = null;
                bool   isHidden    = false;

                foreach (var attr in prop.GetCustomAttributes(true))
                {
                    try
                    {
                        Attribute attribute = attr as Attribute;
                        if (((Type)attribute.TypeId) == typeof(OperationAttributeHidden))
                        {
                            isHidden = true;
                            break;
                        }

                        if (((Type)attribute.TypeId) == typeof(OperationAttributeDisplayName))
                        {
                            object operationAttributeDisplayName = attr;
                            displayName = Convert.ToString(operationAttributeDisplayName.GetType().GetProperty("Name").GetValue(operationAttributeDisplayName));
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }

                string rusPropTypeName = ExtTools.GetRussianTypeDisplayValue(prop.PropertyType);

                if (!isHidden)
                {
                    CreateControlRow(prop.Name, prop.PropertyType, rusPropTypeName, displayName, prop.GetValue(model));
                }
            }
        }
Пример #2
0
        private object GetModel()
        {
            try
            {
                object model = Activator.CreateInstance(_modelType);

                foreach (var controlRow in _controlsValues)
                {
                    object value = ExtTools.ConvertStringToType(controlRow.ControlValue.ToString(), controlRow.PropertyType);
                    model.GetType().GetProperty(controlRow.PropertyName).SetValue(model, value);
                }

                return(model);
            }
            catch (Exception ex)
            {
                MLogger.Error(ex.ToString());
                MessageBox.Show(ex.Message, "Ошибка атрибутов", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
Пример #3
0
        private void InitOperationAttributes(int operationId)
        {
            if (operationId == 0)
            {
                operationAttributes1.InitializeControl(null);
                return;
            }

            _viewShedulerStepModel.nameVis = cbOperation.Text;

            string fileName = OperationTools.GetOperationFileNameById(operationId);

            if (string.IsNullOrEmpty(fileName))
            {
                operationAttributes1.InitializeControl(null);
                return;
            }

            Type   attrType     = null;
            string operName     = OperationTools.GetOperationNameEnById(operationId);
            string operFileName = OperationTools.GetOperationFileNameById(operationId);
            string operFileMd5  = OperationTools.GetOperationFileMd5ById(operationId);

            if (!string.IsNullOrEmpty(operName) && !string.IsNullOrEmpty(operFileName) && !string.IsNullOrEmpty(operFileMd5))
            {
                attrType = PluginOperationAdapter.GetPluginOperationAttributesType(
                    operName
                    , operFileName
                    , operFileMd5);
            }

            if (attrType != null)
            {
                IOperationAttributes operationAttributesInstance = (IOperationAttributes)Activator.CreateInstance(attrType);

                //Ищем сохраненные атрибуты
                JObject savedModel = NewtonJson.GetModelFromJson(_viewShedulerStepModel.OperationAttributes) as JObject;
                JToken  token      = null;
                if (savedModel != null && savedModel.HasValues)
                {
                    foreach (var prop in operationAttributesInstance.GetType().GetProperties())
                    {
                        savedModel.TryGetValue(prop.Name, out token);
                        if (token != null)
                        {
                            object propValue = ExtTools.ConvertStringToType(token.ToString(), prop.PropertyType);
                            if (propValue != null)
                            {
                                prop.SetValue(operationAttributesInstance, propValue);
                            }
                        }
                    }
                }

                operationAttributes1.InitializeControl(operationAttributesInstance, operationId);
            }
            else
            {
                operationAttributes1.InitializeControl(null);
            }
        }