public static void EventsHandler(BaseEvent evt, Logger l)
        {
            if (evt is BlowingEvent) {
                var be = evt as BlowingEvent;
                Keeper.SetBlowingStatus(be.BlowingFlag == 1);
            } else

            if (evt is FlexEvent) {
                var fxe = evt as FlexEvent;
                if (fxe.Operation.StartsWith("UDP.OffGasAnalysisEvent")) {
                    var fxh = new FlexHelper(fxe);

                    var co = fxh.GetDbl("CO");
                    var co2 = fxh.GetDbl("CO2");

                    SetGasAnalysis(co, co2);
                } else

                if (fxe.Operation.StartsWith("OPC.WatchdogsFromL1"))
                {
                    var fxh = new FlexHelper(fxe);
                    var wd1 = fxh.GetInt("WDPLC1");
                    var wd2 = fxh.GetInt("WDPLC2");
                    var wd3 = fxh.GetInt("WDPLC3");
                    var wd01 = fxh.GetInt("WDPLC01");

                    SetWatchdogReceive(wd1, wd2, wd3, wd01);
                }
            }
        }
        public void OnEvent(BaseEvent evt)
        {
            using (var l = new Logger("Listener")) {
                if (evt is FlexEvent) {
                    var fxe = evt as FlexEvent;
                    if (fxe.Operation.StartsWith("SQL.Corrections")) {
                        var fex = new FlexHelper(fxe);
                        if (fex.GetStr(MainWindow.ArgCommandName) == "GetScheme") {
                            if (fex.GetStr(MainWindow.ArgErrorCodeName) == "S_OK") {
                                var itemLst = (List<int>) fex.GetComplexArg("ITEM", typeof (List<int>));
                                var cminLst = (List<double>) fex.GetComplexArg("CMIN", typeof (List<double>));
                                var cmaxLst = (List<double>) fex.GetComplexArg("CMAX", typeof (List<double>));
                                var oxygenLst = (List<double>) fex.GetComplexArg("OXYGEN", typeof (List<double>));
                                var heatinLst = (List<double>) fex.GetComplexArg("HEATING", typeof (List<double>));
                                Pointer.PMainWindow.Dispatcher.Invoke(new Action(delegate() {
                                                                                     Pointer.PMainWindow.TableData = new List<TableRow>();
                                                                                     Pointer.PMainWindow.StandartTableData = new List<TableRow>();
                                                                                     for (int i = 0; i < fex.GetInt(MainWindow.ArgCountName); i++) {
                                                                                         var tr = new TableRow();
                                                                                         tr.Item = itemLst[i];
                                                                                         tr.CMin = cminLst[i];
                                                                                         tr.CMax = cmaxLst[i];
                                                                                         tr.Oxygen = oxygenLst[i];
                                                                                         tr.Heating = heatinLst[i];

                                                                                         Pointer.PMainWindow.StandartTableData.Add(new TableRow(tr));

                                                                                         tr.Item = i;
                                                                                         Pointer.PMainWindow.TableData.Add(new TableRow(tr));

                                                                                     }
                                                                                     Pointer.PMainWindow.dgScheme.ItemsSource =Pointer.PMainWindow.TableData;
                                                                                     Pointer.PMainWindow.dgScheme.Items.Refresh();
                                                                                     Pointer.PMainWindow.btnSave.IsEnabled = true;
                                                                                     Pointer.PMainWindow.LogWrite("Scheme loaded");
                                                                                 }));
                            }
                            else {
                                Pointer.PMainWindow.Dispatcher.Invoke(new Action(delegate() {
                                                                                     Pointer.PMainWindow.LogWrite(fex.GetStr(MainWindow.ArgErrorStringName));
                                                                                 }));
                            }
                        }

                        if (fex.GetStr(MainWindow.ArgCommandName) == "InsertSchemeRow") {
                            if (fex.GetStr(MainWindow.ArgErrorCodeName) == "S_OK") {
                                Pointer.PMainWindow.Dispatcher.Invoke(new Action(delegate() {
                                                                                     Pointer.PMainWindow.TableChangeCounter--;
                                                                                     if (Pointer.PMainWindow.TableChangeCounter == 0) {
                                                                                         Pointer.PMainWindow.ReqScheme(Pointer.PMainWindow.CurrentSchema);
                                                                                         Pointer.PMainWindow.LogWrite("Save complete");
                                                                                     }
                                                                                 }));
                            }
                            else {
                                Pointer.PMainWindow.Dispatcher.Invoke(new Action(delegate() {
                                                                                     Pointer.PMainWindow.LogWrite("Scheme save error");
                                                                                 }));
                            }
                        }
                        if (fex.GetStr(MainWindow.ArgCommandName) == "UpdateSchemeRow")
                        {
                            if (fex.GetStr(MainWindow.ArgErrorCodeName) == "S_OK")
                            {
                                Pointer.PMainWindow.Dispatcher.Invoke(new Action(delegate()
                                {
                                    Pointer.PMainWindow.TableChangeCounter--;
                                    if (Pointer.PMainWindow.TableChangeCounter == 0)
                                    {
                                        Pointer.PMainWindow.ReqScheme(Pointer.PMainWindow.CurrentSchema);
                                        Pointer.PMainWindow.LogWrite("Save complete");
                                    }
                                }));
                            }
                            else
                            {
                                Pointer.PMainWindow.Dispatcher.Invoke(new Action(delegate()
                                {
                                    Pointer.PMainWindow.LogWrite("Scheme Update error");
                                }));
                            }
                        }

                        if (fex.GetStr(MainWindow.ArgCommandName) == "DeleteSchemeRow")
                        {
                            if (fex.GetStr(MainWindow.ArgErrorCodeName) == "S_OK")
                            {
                                Pointer.PMainWindow.Dispatcher.Invoke(new Action(delegate()
                                {
                                    Pointer.PMainWindow.TableChangeCounter--;
                                    if (Pointer.PMainWindow.TableChangeCounter == 0)
                                    {
                                        Pointer.PMainWindow.ReqScheme(Pointer.PMainWindow.CurrentSchema);
                                        Pointer.PMainWindow.LogWrite("Save complete");
                                    }
                                }));
                            }
                            else
                            {
                                Pointer.PMainWindow.Dispatcher.Invoke(new Action(delegate()
                                {
                                    Pointer.PMainWindow.LogWrite("Scheme Delete error");
                                }));
                            }
                        }
                    }
                }
            }
        }
        public static CSVTableParser LoadMatrixTFromFlex(List<ColumnPath> description, FlexHelper fex)
        {
            var matrixT = new CSVTableParser();
            matrixT.Description = description;

            var cminLst = (List<double>)fex.GetComplexArg("CMIN", typeof(List<double>));
            var cmaxLst = (List<double>)fex.GetComplexArg("CMAX", typeof(List<double>));
            var oxygenLst = (List<double>)fex.GetComplexArg("OXYGEN", typeof(List<double>));
            var heatinLst = (List<double>)fex.GetComplexArg("HEATING", typeof(List<double>));

            for (int i = 0; i < fex.GetInt(Implements.DBFlex.ArgCountName); i++) {
                var row = matrixT.ColumnCreator();
                row.Cell["CMin"] = cminLst[i];
                row.Cell["CMax"] = cmaxLst[i];
                row.Cell["OxygenOnHeating"] = oxygenLst[i];
                row.Cell["Heating"] = heatinLst[i];
                matrixT.Rows.Add(row);
            }

            return matrixT;
        }