Esempio n. 1
0
        /// <summary>
        /// По полису определяет к какому МО приписан пациент
        /// </summary>
        /// <param name="policy">Действующий полис пациента</param>
        /// <returns></returns>
        public string GetMoAttached(PolicyInfo policy)
        {
            if (policy.DateEnd.HasValue && policy.DateEnd.Value < DateTime.Now)
            {
                ErrorMessage = "Указанный полис недействителен";
                return(string.Empty);
            }

            try
            {
                string serial = policy.Serial;
                string number = policy.Number;
                string url    = string.Format("http://www.tfomsrb.ru/pp/?srv=p&ser={0}&num={1}", serial, number);

                string result = string.Empty;
                using (WebClient client = new WebClient())
                {
                    byte[] response = client.DownloadData(url);

                    result = Encoding.GetEncoding("windows-1251").GetString(response);
                }

                Regex r     = new Regex("<td>Прикрепление:</td>\n<td>(.*?)</td>");
                var   match = r.Match(result);
                if (match.Success)
                {
                    return(match.Groups[1].Value);
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
            return(string.Empty);
        }
Esempio n. 2
0
        private void GetResults()
        {
            var idResult  = "ResultLabel";
            var result    = _webBrowser.Document.GetElementById(idResult);
            var trResults = result.GetElementsByTagName("tr");

            if (trResults.Count > 0)
            {
                foreach (HtmlElement trResult in trResults)
                {
                    var tds = trResult.GetElementsByTagName("td");
                    if (tds.Count > 0)
                    {
                        var serialNnumber = tds[0].InnerText;
                        var datebeg       = tds[1].InnerText;
                        var dateend       = tds[2].InnerText;
                        var smo           = tds[3].InnerText;

                        if (serialNnumber != null)
                        {
                            serialNnumber = serialNnumber.Trim();
                        }
                        if (datebeg != null)
                        {
                            datebeg = datebeg.Trim();
                        }
                        if (dateend != null)
                        {
                            dateend = dateend.Trim();
                        }
                        if (smo != null)
                        {
                            smo = smo.Trim();
                        }

                        var spaceIndex = serialNnumber.IndexOf(" ", StringComparison.Ordinal);

                        var serial = string.Empty;
                        var number = serialNnumber;
                        if (spaceIndex != -1)
                        {
                            serial = serialNnumber.Substring(0, spaceIndex);
                            number = serialNnumber.Substring(spaceIndex + 1);
                        }

                        var format = "dd.MM.yyyy";
                        var polis  = new PolicyInfo()
                        {
                            Serial  = serial,
                            Number  = number,
                            DateBeg = DateTime.ParseExact(datebeg, format, CultureInfo.InvariantCulture),
                            DateEnd =
                                string.IsNullOrEmpty(dateend)
                                    ? null
                                    : (DateTime?)DateTime.ParseExact(dateend, format, CultureInfo.InvariantCulture),
                            SMO = smo
                        };
                        _polices.Add(polis);
                    }
                }
            }
            else
            {
                var serviceError = result.InnerText;
                if (string.IsNullOrEmpty(serviceError))
                {
                    ErrorMessage = "Не получен ответ от сервиса.";
                }
                else
                {
                    ErrorMessage = serviceError;
                }
            }
        }