Пример #1
0
        public ActionResult showTabProps(int id)
        {
            //получим тип узла по id. В соответствии с типом отобразим  нужное представление
            ViewBag.ActiveModules = tagConfigurator.GetConnectedModules();
            int typeProp = tagConfigurator.GetPropType(id);

            switch (typeProp)
            {
            //тег
            case 2:
                ViewBag.OPCservers = tagConfigurator.getOpcServersName();
                var userPropsTag = tagConfigurator.getUserProps(id);
                ViewBag.UserProps = userPropsTag;
                var tagProps = tagConfigurator.getTagProps(id);
                return(PartialView("TagPartial", tagProps));

            case 7:
            case 5:
                var ObjectProps = tagConfigurator.getObjectProps(id);
                //словарь с пользовательскими свойствами
                var userPropsObject = tagConfigurator.getUserProps(id);
                ViewBag.driversName   = filework.getDriversName();
                ViewBag.UserProps     = userPropsObject;
                ViewBag.SelectChannel = tagConfigurator.getChannels();
                return(PartialView("ObjectPartial", ObjectProps));

            //OPC
            case 1:
                var userPropsOPC = tagConfigurator.getUserProps(id);
                ViewBag.UserProps = userPropsOPC;
                var OPCProps = tagConfigurator.getOPCProps(id);
                return(PartialView("OPCPartial", OPCProps));

            //узел без свойства(обычная папка)
            case 21:
                return(PartialView("NoPropsPartial"));

            //PollingGroup
            case 22:
                var PollingGroupProps     = tagConfigurator.getPollingGroupProps(id);
                var userPropsPollingGroup = tagConfigurator.getUserProps(id);
                ViewBag.UserProps = userPropsPollingGroup;
                return(PartialView("PollingGroupPartial", PollingGroupProps));

            //RadioChannel
            case 18:
                var RadioChannelProps     = tagConfigurator.getRadioChannelProps(id);
                var userPropsRadioChannel = tagConfigurator.getUserProps(id);
                ViewBag.UserProps = userPropsRadioChannel;
                return(PartialView("RadioChannelPartial", RadioChannelProps));

            //GPRSChannel
            case 17:
                var GPRSChannelProps     = tagConfigurator.getGPRSChannelProps(id);
                var userPropsGPRSChannel = tagConfigurator.getUserProps(id);
                ViewBag.UserProps = userPropsGPRSChannel;
                return(PartialView("GPRSChannelPartial", GPRSChannelProps));

            //пользовательский узел
            default:
                //получаем 2 типа для передачи.
                //словарь типа динамик
                //получаем стандартные свойства
                NoTypeNodeHelp noTypeNodeProps = tagConfigurator.getNoTypeNodeProps(id);
                //получаем объект, содержащий строковое поле для пользовательских свойств, а также поля Id, Name
                NoTypesProps noTypeNodeIdName = tagConfigurator.getNoTypeNodePropsIdName(id);
                //объект для передачи в частичное представление
                NoTypesPropsHelp model = new NoTypesPropsHelp();

                //получим узлы типа канал(радио, жпрс)
                ViewBag.SelectChannel = tagConfigurator.getChannels();
                //получим узлы типа OPC-сервер
                ViewBag.OPCservers = tagConfigurator.getOpcServersName();
                //строка подключения
                //string ConnString =jstree.getConnectionProp(id);
                int OPCid = jstree.getOPCID();
                noTypeNodeProps.Opc = OPCid;

                model.notypesforSave = noTypeNodeIdName;
                model.notypesModel   = noTypeNodeProps;


                //словарь с пользовательскими свойствами
                var userProps = tagConfigurator.getUserProps(id);
                //словарь со стандартными свойствами
                var standartProps = tagConfigurator.getStandartProps(id);
                ViewBag.StandartProps = standartProps;
                ViewBag.UserProps     = userProps;

                return(PartialView("NoTypeNodePartial", model));
            }
        }
Пример #2
0
        public ActionResult EditNoTypesProps(NoTypesPropsHelp model)
        {
            //проблема с определением типа во вью. Везде видит инт64 как бы не выходит так тонко провалидировать пользовательские свойства
            //json строка с польз свойствами
            string specialProp  = model.notypesforSave.special;
            string forSerialize = "";

            //если есть пользовательске свойства
            if (!string.IsNullOrEmpty(specialProp))
            {
                forSerialize = "{" + specialProp.Remove(0, 1) + "}";
            }

            //собираем сюда возможные ошибки
            List <ErrorUserProp> test = tagConfigurator.checkUserPropsValidity(forSerialize);

            //если польз свойства не валидны
            if (test.Count > 0)
            {
                var callBackString = json.Serialize(test);
                ViewBag.StdPropsValidityError = callBackString;
            }

            var IdForSave = model.notypesforSave.Id;

            if (ModelState.IsValid)
            {
                //даже если модель, включающая стандартные свойства валидна, смотрим есть ли ошибки в польз-х свойствах
                if (test.Count > 0)
                {
                    ViewBag.Notification = 0;
                    //перетираем строку модели в соответствии с ошибками
                }
                else
                {
                    //если валидны и польз и стандратные, то сохраняем
                    tagConfigurator.saveNoTypesProps1(model);
                    ViewBag.Notification = 1;
                }
            }
            else
            {
                ViewBag.Notification = 0;
            }
            ViewBag.ActiveModules = tagConfigurator.GetConnectedModules();
            ViewBag.OPCservers    = tagConfigurator.getOpcServersName();

            //здесь собраны станд свойства,полученные с формы (а не из БД) по результатам изменения пользователем
            //ибо если пользователь исправит  одно из невалидных значений,а другое по результатам исправлений останется невалидным,
            //то при возвращении формы с ошибками снова вернутся старые значения
            //и только когда все валидно произойдет сохранение
            Dictionary <string, dynamic> userProps = new Dictionary <string, dynamic>();

            if (!string.IsNullOrEmpty(specialProp))
            {
                userProps = tagConfigurator.getUserPropsAfterValidate(specialProp);
            }
            //var userProps = tagConfigurator.getUserProps(IdForSave);
            ViewBag.SelectChannel = tagConfigurator.getChannels();
            ViewBag.UserProps     = userProps;
            var standartProps = tagConfigurator.getStandartProps(IdForSave);

            ViewBag.StandartProps = standartProps;
            //если не создать объект класса NoTypeNodeHelp, то при null значении вью дает NullPointerException
            if (model.notypesModel == null)
            {
                var stdProp = new NoTypeNodeHelp();
                model.notypesModel = stdProp;
            }
            return(PartialView("NoTypeNodePartial", model));
            //return PartialView("NoTypeNodePartial");
        }