Ejemplo n.º 1
0
        private async Task <bool> InitReportsGroupAsync()
        {
            string paramGetGroupsList = "callerUID=INIT_ID_1&instance=_level1.scene.spContentHolder8.PANEL_RP_TREE.spContentHolder0.RP_TREE.spContentHolder&RP_PUBLIC=1&__const=TYPE=RP_TYPE&datablock=RP_TYPE&action=GET";
            var    list = new List <Model.EmcosReportType>();

            try
            {
                string url  = @"{0}scripts/reports.asp";
                string data = await ServiceHelper.ExecuteFunctionAsync(ServiceHelper.MakeRequestAsync, url, paramGetGroupsList, true, (answer) => ServiceHelper.DecodeAnswer(answer));

                //string data = "&RP_TYPE_ID_0=72&RP_TYPE_NAME_0=DWRES Отчеты&TYPE_0=RP_TYPE&RP_PUBLIC_0=1&RP_TYPE_ID_1=42&RP_TYPE_NAME_1=Балансы подстанций&TYPE_1=RP_TYPE&RP_PUBLIC_1=1&RP_TYPE_ID_2=2&RP_TYPE_NAME_2=Волковысские сети&TYPE_2=RP_TYPE&RP_PUBLIC_2=1&RP_TYPE_ID_3=22&RP_TYPE_NAME_3=Выработка&TYPE_3=RP_TYPE&RP_PUBLIC_3=1&RP_TYPE_ID_4=7&RP_TYPE_NAME_4=Отчеты ТЭЦ-2&TYPE_4=RP_TYPE&RP_PUBLIC_4=1&RP_TYPE_ID_5=32&RP_TYPE_NAME_5=Отчётные формы&TYPE_5=RP_TYPE&RP_PUBLIC_5=1&RP_TYPE_ID_6=17&RP_TYPE_NAME_6=Перетоки&TYPE_6=RP_TYPE&RP_PUBLIC_6=1&RP_TYPE_ID_7=67&RP_TYPE_NAME_7=Промышленные предприятия&TYPE_7=RP_TYPE&RP_PUBLIC_7=1&RP_TYPE_ID_8=27&RP_TYPE_NAME_8=Структура дерева&TYPE_8=RP_TYPE&RP_PUBLIC_8=1&RP_TYPE_ID_9=47&RP_TYPE_NAME_9=Тест&TYPE_9=RP_TYPE&RP_PUBLIC_9=1&RP_TYPE_ID_10=37&RP_TYPE_NAME_10=Утвержденные&TYPE_10=RP_TYPE&RP_PUBLIC_10=1&result=0&recordCount=11";

                if (data.Contains("result=0") == false)
                {
                    return(false);
                }

                var records = Utils.ParseRecords(data);
                if (records == null)
                {
                    return(false);
                }

                foreach (var nvc in records)
                {
                    if (nvc.Get("TYPE") == Model.EmcosReportType.TYPE)
                    {
                        Model.EmcosReportType element = new Model.EmcosReportType();
                        for (int i = 0; i < nvc.Count; i++)
                        {
                            #region  азбор полей
                            int intValue = 0;
                            switch (nvc.GetKey(i))
                            {
                            case "RP_TYPE_ID":
                                int.TryParse(nvc[i], out intValue);
                                element.RP_TYPE_ID = intValue;
                                break;

                            case "RP_TYPE_NAME":
                                element.RP_TYPE_NAME = nvc[i];
                                break;

                            case "RP_PUBLIC":
                                element.RP_PUBLIC = nvc[i] == "1";
                                break;
                            }
                            #endregion
                        }
                        list.Add(element);
                    }
                }
            }
            catch
            {
                return(false);
            }
            ReportsGroupList = list;
            return(true);
        }
Ejemplo n.º 2
0
        private async Task <bool> InitReportsAsync()
        {
            int groupID = Properties.Settings.Default.SelectedReportsGroupId;

            var list = new List <Model.EmcosReport>();

            try
            {
                string paramGetReports = string.Format("callerUID=INIT_ID_1/RP_TYPE_ID_{0}&instance=_level1.scene.spContentHolder6.PANEL_RP_TREE.spContentHolder0.RP_TREE.spContentHolder&RP_PUBLIC=1&RP_TYPE_ID={0}&__const=TYPE=RP&datablock=RP&action=GET",
                                                       groupID);

                string url  = @"{0}scripts/reports.asp";
                string data = await ServiceHelper.ExecuteFunctionAsync(ServiceHelper.MakeRequestAsync, url, paramGetReports, true, (answer) => ServiceHelper.DecodeAnswer(answer));

                //string data = "&RP_ID_0=679&RP_TYPE_ID_0=72&RP_NAME_0=Выборка точек по группе&RP_PUBLIC_0=1&RP_DESCRIPTION_0=&RPF_ID_0=1&RP_LOG_ENABLED_0=0&USER_NAME_0=System user EMCOS&TYPE_0=RP&RP_ID_1=675&RP_TYPE_ID_1=72&RP_NAME_1=Для расчета балансов ПС до 35кВ&RP_PUBLIC_1=1&RP_DESCRIPTION_1=&RPF_ID_1=2&RP_LOG_ENABLED_1=0&USER_NAME_1=Щелухин Д.Д.&TYPE_1=RP&RP_ID_2=698&RP_TYPE_ID_2=72&RP_NAME_2=Для расчета балансов ПС 35-770кВ&RP_PUBLIC_2=1&RP_DESCRIPTION_2=&RPF_ID_2=2&RP_LOG_ENABLED_2=1&USER_NAME_2=System user EMCOS&TYPE_2=RP&result=0&recordCount=3";
                if (data.Contains("result=0") == false)
                {
                    return(false);
                }

                var records = Utils.ParseRecords(data);
                if (records == null)
                {
                    return(false);
                }

                foreach (var nvc in records)
                {
                    if (nvc.Get("TYPE") == Model.EmcosReport.TYPE)
                    {
                        Model.EmcosReport element = new Model.EmcosReport();
                        for (int i = 0; i < nvc.Count; i++)
                        {
                            #region  азбор полей
                            int intValue = 0;
                            switch (nvc.GetKey(i))
                            {
                            case "RP_ID":
                                int.TryParse(nvc[i], out intValue);
                                element.RP_ID = intValue;
                                break;

                            case "RP_TYPE_ID":
                                int.TryParse(nvc[i], out intValue);
                                element.RP_TYPE_ID = intValue;
                                break;

                            case "RP_NAME":
                                element.RP_NAME = nvc[i];
                                break;

                            case "RP_PUBLIC":
                                element.RP_PUBLIC = nvc[i] == "1";
                                break;

                            case "RP_DESCRIPTION":
                                element.RP_DESCRIPTION = nvc[i];
                                break;

                            case "RPF_ID":
                                int.TryParse(nvc[i], out intValue);
                                element.RPF_ID = intValue;
                                break;

                            case "RP_LOG_ENABLED":
                                element.RP_LOG_ENABLED = nvc[i] == "1";
                                break;

                            case "USER_NAME":
                                element.USER_NAME = nvc[i];
                                break;
                            }
                            #endregion
                        }
                        list.Add(element);
                    }
                }
            }
            catch
            {
                return(false);
            }
            ReportsList = list;

            /*var selected = Properties.Settings.Default.SelectedReport;
             * Model.EmcosReport r = App.Base64StringToObject<Model.EmcosReport>(selected);
             * if (r != null)
             *  cmbReports.SelectedItem = list.Where(i => i.RP_ID == r.RP_ID).FirstOrDefault();*/
            return(true);
        }
Ejemplo n.º 3
0
        private void PrepareReport(ListPointWithResult point)
        {
            int    groupId = point.Id;
            string param   = String.Format("__invoker=undefined&RP_ID={0}&RP_NAME={1}&errorDispatch=false&dataBlock=PARAMETERS&action=GET",
                                           _selectedReport.RP_ID, _selectedReport.RP_NAME);
            string url    = @"{0}scripts/reports.asp";
            string answer = ServiceHelper.ExecuteFunctionAsync(ServiceHelper.MakeRequestAsync, url, param, true, (p) => ServiceHelper.DecodeAnswer(p)).Result;

            if (String.IsNullOrEmpty(answer) == false && answer.Contains("result=0"))
            {
                var records = Utils.ParseRecords(answer);
                if (records == null)
                {
                    System.Diagnostics.Debugger.Break();
                }

                List <RPQ> rpqs = new List <RPQ>(records.Count);
                foreach (var nvc in records)
                {
                    if (nvc.Get("COLUMN_NAME") != "GR_ID")
                    {
                        _window.ShowDialogError(Strings.InvalidReport);
                        return;
                    }
                    RPQ rpq = new RPQ();
                    for (int i = 0; i < nvc.Count; i++)
                    {
                        #region  азбор полей

                        switch (nvc.GetKey(i))
                        {
                        case "RPQ_ID":
                            rpq.RPQ_ID = nvc[i];
                            break;

                        case "RPQ_NAME":
                            rpq.RPQ_NAME = nvc[i];
                            break;

                        case "TABLE_NAME":
                            rpq.TABLE_NAME = nvc[i];
                            break;

                        case "RPQF_ID":
                            rpq.RPQF_ID = nvc[i];
                            break;

                        case "RPQO_ID":
                            rpq.RPQO_ID = nvc[i];
                            break;

                        case "RPQO_CODE":
                            rpq.RPQO_CODE = nvc[i];
                            break;

                        case "RPQF_VALUE":
                            rpq.RPQF_VALUE = nvc[i];
                            break;

                        case "FIELD_DESC":
                            rpq.FIELD_DESC = nvc[i];
                            break;

                        case "RPQF_ALLOW_EMPTY_VALUES":
                            rpq.RPQF_ALLOW_EMPTY_VALUES = nvc[i];
                            break;

                        case "DATA_TYPE":
                            rpq.DATA_TYPE = nvc[i];
                            break;
                        }

                        #endregion  азбор полей
                    }
                    rpqs.Add(rpq);
                }
                param = String.Format("__invoker=undefined&RP_ID={0}&RP_NAME={1}&errorDispatch=false&dataBlock=PREPARED_RP&action=GET",
                                      _selectedReport.RP_ID, _selectedReport.RP_NAME);
                url    = @"{0}scripts/reports.asp";
                answer = ServiceHelper.ExecuteFunctionAsync(ServiceHelper.MakeRequestAsync, url, param, true, (p) => ServiceHelper.DecodeAnswer(p)).Result;

                if (String.IsNullOrEmpty(answer) == false && answer.Contains("result=0"))
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < rpqs.Count; i++)
                    {
                        RPQ rpq = rpqs[i];
                        sb.AppendFormat("RPQF_{0}={1}&DATA_TYPE_0_{2}={3}&RPQF_VALUE_0_{2}={1}&COLUMN_NAME_0_{2}={4}&RPQO_ID_0_{2}={5}&RPQF_ID_0_{2}={0}&",
                                        rpq.RPQF_ID,     //0
                                        groupId,         //1
                                        i,               //2
                                        rpq.DATA_TYPE,   //3
                                        rpq.COLUMN_NAME, //4
                                        rpq.RPQO_ID      //5
                                        );
                    }
                    sb.AppendFormat("RPQ_NAME_0={0}&RPQ_ID_0={1}&RPQF_COUNT_0={2}&RPQ_COUNT=1&export_to_html=0&RP_ID={3}&action=SHOW_REPORT",
                                    rpqs[0].RPQ_NAME,
                                    rpqs[0].RPQ_ID,
                                    rpqs.Count,
                                    _selectedReport.RP_ID);

                    url    = @"{0}scripts/ReportGenerator.asp";
                    answer = ServiceHelper.MakeRequestAsync(url, sb.ToString()).Result;

                    if (ServiceHelper.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        // получение имени файла

                        /*
                         * <HTML>
                         * <HEAD>
                         * <META HTTP-EQUIV=Refresh CONTENT="0;URL=../\\reports\2016\12\30\Для расчета балансов ПС до 35кВ_2016_12_30_113404_1.txt">
                         * </HEAD>
                         * </HTML>
                         */
                        Match  KeywordMatch = Regex.Match(answer, "<meta HTTP-EQUIV=Refresh content=\"([^<]*)\">", RegexOptions.IgnoreCase | RegexOptions.Multiline);
                        string metaKeywords = KeywordMatch.Groups[1].Value;
                        string file         = metaKeywords.Substring(8).Replace("../", "").Replace("\\", "/");

                        var client = new WebClient();

                        if (file.EndsWith(".txt"))
                        {
                            point.ResultValue = client.DownloadString(ServiceHelper.SiteAddress + file);
                            point.ResultType  = "txt";
                        }
                        else
                        if (file.EndsWith(".xls"))
                        {
                            point.ResultValue = client.DownloadData(ServiceHelper.SiteAddress + file);
                            point.ResultType  = "xls";
                        }
                        else
                        {
                            point.ResultValue = client.DownloadString(ServiceHelper.SiteAddress + file);
                            point.ResultType  = "unknown";
                        }
                    }
                }
            }
        }