Ejemplo n.º 1
0
        //Запись используемых сигналов в SignalsInUse
        private void SaveInUse()
        {
            try
            {
                using (var db = new DaoDb(_projectFile))
                {
                    var old = new SetS();
                    using (var rec = new RecDao(db, "SignalsInUse"))
                    {
                        while (rec.Read())
                        {
                            var code = rec.GetString("FullCode");
                            if ((Signals.ContainsKey(code) && Signals[code].InUse) || HandSignals.ContainsKey(code))
                            {
                                old.Add(code);
                                rec.Put("Del", false);
                            }
                            else
                            {
                                rec.Put("Del", true);
                            }
                        }
                    }
                    db.Execute("DELETE * FROM SignalsInUse WHERE Del=True");
                    var add = new SetS();
                    var use = from s in SignalsList where s.InUse select s;
                    SignalsInUseCount = use.Count();
                    foreach (var s in use)
                    {
                        if (!old.Contains(s.FullCode))
                        {
                            add.Add(s.FullCode);
                        }
                        if (s.InUseSource)
                        {
                            UsedProviders.Add(s.SourceName);
                        }
                        if (s.InUseReceiver)
                        {
                            UsedProviders.Add(s.ReceiverName);
                        }
                    }
                    if (HandSignals.Count > 0 && HandInputSource != null)
                    {
                        UsedProviders.Add(HandInputSource);
                    }
                    foreach (var hand in HandSignals.Values)
                    {
                        if (!old.Contains(hand.FullCode))
                        {
                            add.Add(hand.FullCode);
                        }
                    }

                    using (var rec = new RecDao(db, "SignalsInUse"))
                    {
                        while (rec.Read())
                        {
                            var    s   = rec.GetString("FullCode");
                            Signal sig = Signals.ContainsKey(s) ? Signals[s] : HandSignals[s];
                            sig.ToRecordset(rec, false);
                        }
                        foreach (var s in add.Keys)
                        {
                            Signal sig = Signals.ContainsKey(s) ? Signals[s] : HandSignals[s];
                            sig.ToRecordset(rec, true);
                        }
                    }
                    using (var rec = new RecDao(db, "GraficsList"))
                        while (rec.Read())
                        {
                            rec.Put("UsedUnits", UsingParamsString(Grafics[rec.GetString("Code")].UsingParams));
                        }
                }
            }
            catch (Exception ex)
            {
                AddError("Ошибка сохранения сигналов или графиков", ex);
            }
        }