/// <summary> /// Creates columns for the input channel table. /// </summary> private static DataGridViewColumn[] CreateInCnlTableColumns(ConfigBase configBase) { return(TranslateHeaders("InCnlTable", new DataGridViewColumn[] { NewTextBoxColumn("CnlNum", new ColumnOptions(ColumnKind.PrimaryKey)), NewCheckBoxColumn("Active", new ColumnOptions { DefaultValue = true }), NewTextBoxColumn("Name", new ColumnOptions(ColumnLength.Name)), NewComboBoxColumn("DataTypeID", "Name", configBase.DataTypeTable, true), NewTextBoxColumn("DataLen"), NewComboBoxColumn("CnlTypeID", "Name", configBase.CnlTypeTable, false, false, new ColumnOptions { DefaultValue = CnlTypeID.Measured }), NewComboBoxColumn("ObjNum", "Name", configBase.ObjTable, true), NewComboBoxColumn("DeviceNum", "Name", configBase.DeviceTable, true), NewTextBoxColumn("TagNum"), NewTextBoxColumn("TagCode", new ColumnOptions(ColumnLength.Code)), NewCheckBoxColumn("FormulaEnabled"), NewTextBoxColumn("Formula", new ColumnOptions(ColumnLength.Default)), NewComboBoxColumn("FormatID", "Name", configBase.FormatTable, true), NewComboBoxColumn("QuantityID", "Name", configBase.QuantityTable, true), NewComboBoxColumn("UnitID", "Name", configBase.UnitTable, true), NewComboBoxColumn("LimID", "Name", configBase.LimTable, true), NewTextBoxColumn("ArchiveMask", new ColumnOptions(ColumnKind.BitMask) { DataSource = AppUtils.GetArchiveBits(configBase.ArchiveTable) }), NewButtonColumn("ArchiveMask"), NewTextBoxColumn("EventMask", new ColumnOptions(ColumnKind.BitMask) { DataSource = AppUtils.GetEventBits() }), NewButtonColumn("EventMask") })); }
/// <summary> /// Executes integrity check. /// </summary> public void Execute() { try { string resultFileName = Path.Combine(appData.AppDirs.LogDir, ResultFileName); using (StreamWriter writer = new StreamWriter(resultFileName, false, Encoding.UTF8)) { writer.WriteLine(AppPhrases.IntegrityCheckTitle); writer.WriteLine(new string('-', AppPhrases.IntegrityCheckTitle.Length)); bool hasErrors = false; foreach (IBaseTable baseTable in configBase.AllTables) { writer.Write(baseTable.Title); writer.Write("..."); SortedSet <int> requiredKeys = new SortedSet <int>(); List <int> lostKeys = new List <int>(); foreach (TableRelation relation in baseTable.Dependent) { if (relation.ChildTable.TryGetIndex(relation.ChildColumn, out TableIndex index)) { foreach (int indexKey in index.ItemGroups.Keys) { // if index.AllowNull then 0 means NULL, otherwise 0 is 0 if (indexKey != 0 || !index.AllowNull) { requiredKeys.Add(indexKey); } } } else { throw new ScadaException(AdminPhrases.IndexNotFound); } } foreach (int key in requiredKeys) { if (!baseTable.PkExists(key)) { lostKeys.Add(key); } } if (lostKeys.Count > 0) { hasErrors = true; writer.WriteLine(AppPhrases.TableHasErrors); writer.WriteLine(AppPhrases.LostPrimaryKeys + string.Join(", ", lostKeys)); writer.WriteLine(); } else { writer.WriteLine(AppPhrases.TableCorrect); } } writer.WriteLine(hasErrors ? AppPhrases.BaseHasErrors : AppPhrases.BaseCorrect); } AppUtils.OpenTextFile(resultFileName); } catch (Exception ex) { appData.ProcError(ex, AppPhrases.IntegrityCheckError); } }
/// <summary> /// Generates a channel map. /// </summary> public void Generate() { try { string mapFileName = Path.Combine(appData.AppDirs.LogDir, MapFileName); string indexedColumn = GroupByDevices ? "KPNum" : "ObjNum"; using (StreamWriter writer = new StreamWriter(mapFileName, false, Encoding.UTF8)) { string title = GroupByDevices ? AppPhrases.CnlMapByDevice : AppPhrases.CnlMapByObject; writer.WriteLine(title); writer.WriteLine(new string('-', title.Length)); if (configBase.InCnlTable.TryGetIndex(indexedColumn, out TableIndex index1) && configBase.CtrlCnlTable.TryGetIndex(indexedColumn, out TableIndex index2)) { if (GroupByDevices) { foreach (KP kp in configBase.KPTable.EnumerateItems()) { writer.WriteLine(string.Format(AppPhrases.DeviceCaption, kp.KPNum, kp.Name)); if (IncludeInCnls) { writer.Write(AppPhrases.InCnlsCaption); WriteCnls(writer, index1, kp.KPNum); } if (IncludeOutCnls) { writer.Write(AppPhrases.OutCnlsCaption); WriteCnls(writer, index2, kp.KPNum); } writer.WriteLine(); } writer.WriteLine(AppPhrases.EmptyDevice); } else { foreach (Obj obj in configBase.ObjTable.EnumerateItems()) { writer.WriteLine(string.Format(AppPhrases.ObjectCaption, obj.ObjNum, obj.Name)); if (IncludeInCnls) { writer.Write(AppPhrases.InCnlsCaption); WriteCnls(writer, index1, obj.ObjNum); } if (IncludeOutCnls) { writer.Write(AppPhrases.OutCnlsCaption); WriteCnls(writer, index2, obj.ObjNum); } writer.WriteLine(); } writer.WriteLine(AppPhrases.EmptyObject); } // channels with unspecified device or object if (IncludeInCnls) { writer.Write(AppPhrases.InCnlsCaption); WriteCnls(writer, index1, 0); } if (IncludeOutCnls) { writer.Write(AppPhrases.OutCnlsCaption); WriteCnls(writer, index2, 0); } } else { throw new ScadaException(AdminPhrases.IndexNotFound); } } AppUtils.OpenTextFile(mapFileName); } catch (Exception ex) { appData.ProcError(ex, AppPhrases.GenerateCnlMapError); } }