public JsonResult GetByControlPointIdGrid(int ControlPointID, [DataSourceRequest] DataSourceRequest request)
        {
            IEnumerable <SelectListItem> slcontrolPointId = CreateDropDownControlPointId();

            ViewBag.DropDownValuesControlPointId = slcontrolPointId;

            // if (ControlPointID != null && ControlPointID!=0)
            // {
            ManagementNomenclaturesSoapClient client = new ManagementNomenclaturesSoapClient();

            client.Endpoint.EndpointBehaviors.Add(new MessageBehavior("_system", "SYS"));

            var all = client.GetConfigurationId(Convert.ToInt32(ControlPointID));

            if (all == null)
            {
                return(Json(new List <IndexViewModels>().ToDataSourceResult(request)));
            }

            IEnumerable <IndexViewModels> allTotalizers = all.Select(b => new IndexViewModels
            {
                TotalizerTag     = b.TotalizerTag,
                ControlPointID   = Convert.ToInt32(b.ControlPointID),
                FlowDirection    = Convert.ToInt32(b.FlowDirection),
                ControlerCode    = Convert.ToInt32(b.ControlerCode),
                PositionNumber   = Convert.ToInt32(b.PositionNumber),
                ControlPointName = b.ControlPointName,
                EngineeringUnit  = b.EngineeringUnit,
                ProductCode      = b.ProductCode
            }).ToList();

            return(Json(all.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
            //}
            // return Json(new List<IndexViewModels>().ToDataSourceResult(request));
        }
        public ActionResult Create(AddTotalizerTagViewModel tag)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    CacheNomAdministration.SoapServices.SoapProxy.ControlPointView addtag = new SoapServices.SoapProxy.ControlPointView()
                    {
                        ControlPointName = tag.ControlPointName,
                        EngineeringUnit  = tag.EngineeringUnit,
                        ProductCode      = tag.ProductCode,
                        TotalizerTag     = tag.TotalizerTag,
                        ControlPointID   = tag.ControlPointID,
                        FlowDirection    = tag.FlowDirection,
                        ControlerCode    = tag.ControlerCode
                    };

                    ManagementNomenclaturesSoapClient client = new ManagementNomenclaturesSoapClient();
                    client.Endpoint.EndpointBehaviors.Add(new MessageBehavior("_system", "SYS"));
                    client.AddRecord(addtag);

                    //ако има грешки от Caheto, Тук да ги прехвана

                    IEnumerable <SelectListItem> slunit           = CreateDropDownUnits(); ViewBag.EngineeringUnit = slunit;
                    IEnumerable <SelectListItem> slflowdirection  = CreateDropDownFlowDirection(); ViewBag.DropDownValuesFlowDirection = slflowdirection;
                    IEnumerable <SelectListItem> slcontrolercode  = CreateDropDownFlowDirection(); ViewBag.DropDownValuesControlerCode = slcontrolercode;
                    IEnumerable <SelectListItem> slcontrolPointId = CreateDropDownControlPointId(); ViewBag.DropDownValuesControlPointId = slcontrolPointId;

                    ModelState.Clear();
                    return(View());
                }
                else
                {
                    IEnumerable <SelectListItem> slunit           = CreateDropDownUnits(); ViewBag.EngineeringUnit = slunit;
                    IEnumerable <SelectListItem> slflowdirection  = CreateDropDownFlowDirection(); ViewBag.DropDownValuesFlowDirection = slflowdirection;
                    IEnumerable <SelectListItem> slcontrolercode  = CreateDropDownFlowDirection(); ViewBag.DropDownValuesControlerCode = slcontrolercode;
                    IEnumerable <SelectListItem> slcontrolPointId = CreateDropDownControlPointId(); ViewBag.DropDownValuesControlPointId = slcontrolPointId;

                    TempData["ResultMessage"] = new ResultOfAction()
                    {
                        Type = ResultType.Error, Message = "Hеправилно въведени входни данни във формата !!!!",
                    };
                    return(View());
                }
            }
            catch
            {
                IEnumerable <SelectListItem> slunit           = CreateDropDownUnits(); ViewBag.EngineeringUnit = slunit;
                IEnumerable <SelectListItem> slflowdirection  = CreateDropDownFlowDirection(); ViewBag.DropDownValuesFlowDirection = slflowdirection;
                IEnumerable <SelectListItem> slcontrolercode  = CreateDropDownFlowDirection(); ViewBag.DropDownValuesControlerCode = slcontrolercode;
                IEnumerable <SelectListItem> slcontrolPointId = CreateDropDownControlPointId(); ViewBag.DropDownValuesControlPointId = slcontrolPointId;

                ModelState.Clear();
                TempData["ResultMessage"] = new ResultOfAction()
                {
                    Type = ResultType.Error, Message = "Възникна грешка при добавянето на таталайзер тага !!!",
                };
                return(View());
            }
        }
        public ActionResult VerifyControlPointName(int controlPointId, string controlPointName)
        {
            if (controlPointName != null)
            {
                bool result = false;
                if (controlPointId == 0)
                {
                    return(Json(false, JsonRequestBehavior.AllowGet));
                }
                try
                {
                    ManagementNomenclaturesSoapClient client = new ManagementNomenclaturesSoapClient();
                    client.Endpoint.EndpointBehaviors.Add(new MessageBehavior("_system", "SYS"));
                    result = client.IsValidControlPointName(Convert.ToInt64(controlPointId), controlPointName);
                }
                catch
                {
                    // TODO : gre6ka
                }

                if (!result)
                {
                    return(Json(false, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(true, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(data: null));
        }
        public bool VerifyProductCodeBool(string productCode)
        {
            if (productCode != null)
            {
                bool result = false;
                try
                {
                    ManagementNomenclaturesSoapClient client = new ManagementNomenclaturesSoapClient();
                    client.Endpoint.EndpointBehaviors.Add(new MessageBehavior("_system", "SYS"));
                    result = client.IsValidProduct(productCode);
                }
                catch
                {
                    // TODO : gre6ka
                }

                string suggestedName = String.Format(CultureInfo.InvariantCulture, "Въведете валиден код на продукта !");

                if (!result)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
        private void TotalizatorDestroy(IndexViewModels totalizator)
        {
            ManagementNomenclaturesSoapClient client = new ManagementNomenclaturesSoapClient();

            client.Endpoint.EndpointBehaviors.Add(new MessageBehavior("_system", "SYS"));
            client.DeleteRecordTag(totalizator.TotalizerTag, Convert.ToInt32(totalizator.ControlPointID), Convert.ToInt32(totalizator.FlowDirection),
                                   Convert.ToInt32(totalizator.ControlerCode), Convert.ToInt32(totalizator.PositionNumber));
        }
        static void Main(string[] args)
        {
            Console.BufferWidth = 500;
            ManagementNomenclaturesSoapClient client = new ManagementNomenclaturesSoapClient();

            client.Endpoint.EndpointBehaviors.Add(new MessageBehavior("_system", "SYS"));

            var configuration = client.GetConfiguration();

            foreach (var tag in configuration.OrderBy(x => x.TotalizerTag).ThenBy(x => x.ControlPointID))
            {
                Console.WriteLine($"{nameof(tag.TotalizerTag), 15}: {tag.TotalizerTag, 30} | {nameof(tag.ControlPointID), 20}: {tag.ControlPointID, 20} | {nameof(tag.ControlerCode), 20}: {tag.ControlerCode, 20} | {nameof(tag.ControlPointName), 20}: {tag.ControlPointName, 20} ");
            }
        }
        public static IEnumerable <SelectListItem> CreateDropDownControlPointId()
        {
            ManagementNomenclaturesSoapClient client = new ManagementNomenclaturesSoapClient();

            client.Endpoint.EndpointBehaviors.Add(new MessageBehavior("_system", "SYS"));

            var list = new List <SelectListItem>();
            var arrayOfControlPointId = client.GetIdControlPoint();

            for (int i = 0; i < arrayOfControlPointId.Count; i++)
            {
                list.Add(new SelectListItem
                {
                    Value = arrayOfControlPointId[i].MeasuringPointId.ToString(),
                    Text  = arrayOfControlPointId[i].MeasuringPointId.ToString()
                });
            }
            return(list);
        }
        public ActionResult GetAll([DataSourceRequest] DataSourceRequest request)
        {
            ManagementNomenclaturesSoapClient client = new ManagementNomenclaturesSoapClient();

            client.Endpoint.EndpointBehaviors.Add(new MessageBehavior("_system", "SYS"));

            IEnumerable <IndexViewModels> allTotalizers = client.GetConfiguration().Select(b => new IndexViewModels
            {
                TotalizerTag     = b.TotalizerTag,
                ControlPointID   = Convert.ToInt32(b.ControlPointID),
                FlowDirection    = Convert.ToInt32(b.FlowDirection),
                ControlerCode    = Convert.ToInt32(b.ControlerCode),
                PositionNumber   = Convert.ToInt32(b.PositionNumber),
                ControlPointName = b.ControlPointName,
                EngineeringUnit  = b.EngineeringUnit,
                ProductCode      = b.ProductCode
            }).ToList();

            return(Json(allTotalizers.ToDataSourceResult(request)));
        }
        // [HttpPost]
        public ActionResult VerifyProductCode(string productCode)
        {
            if (productCode != null)
            {
                bool      result    = false;
                Stopwatch stopWatch = new Stopwatch();
                try
                {
                    ManagementNomenclaturesSoapClient client = new ManagementNomenclaturesSoapClient();
                    client.Endpoint.EndpointBehaviors.Add(new MessageBehavior("_system", "SYS"));

                    stopWatch.Start();
                    result = client.IsValidProduct(productCode);
                    stopWatch.Stop();

                    TimeSpan ts          = stopWatch.Elapsed;
                    string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
                }
                catch
                {
                    // TODO : gre6ka
                }

                string suggestedName = String.Format(CultureInfo.InvariantCulture, "Въведете валиден код на продукта !");

                if (!result)
                {
                    return(Json(suggestedName, JsonRequestBehavior.AllowGet));
                }                                                             // false - gre6kata se vizualizira
                else
                {
                    return(Json(true, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json(true, JsonRequestBehavior.AllowGet));
        }