Example #1
0
        /// <summary>
        /// Converts the tag data to string.
        /// </summary>
        protected override string ConvertTagDataToStr(int signal, SrezTableLight.CnlData tagData)
        {
            if (tagData.Stat > 0)
            {
                switch (tagTypes[signal - 1])
                {
                case TagType.String:
                    return(ScadaUtils.DecodeAscii(tagData.Val));

                case TagType.DateTime:
                    return(ScadaUtils.DecodeDateTime(tagData.Val).ToLocalizedString());
                }
            }

            return(base.ConvertTagDataToStr(signal, tagData));
        }
Example #2
0
        /// <summary>
        /// Converts the tag data to string.
        /// </summary>
        protected override string ConvertTagDataToStr(KPTag kpTag, SrezTableLight.CnlData tagData)
        {
            if (tagData.Stat > 0 && kpTag.Aux is TagType tagType)
            {
                switch (tagType)
                {
                case TagType.String:
                    return(ScadaUtils.DecodeAscii(tagData.Val));

                case TagType.DateTime:
                    return(ScadaUtils.DecodeDateTime(tagData.Val).ToLocalizedString());
                }
            }

            return(base.ConvertTagDataToStr(kpTag, tagData));
        }
Example #3
0
 /// <summary>
 /// Преобразовать данные тега КП в строку
 /// </summary>
 protected override string ConvertTagDataToStr(int signal, SrezTableLight.CnlData tagData)
 {
     if (tagData.Stat > 0)
     {
         if (signal == 1)
         {
             return(tagData.Val > 0 ?
                    (Localization.UseRussian ? "Есть" : "Yes") :
                    (Localization.UseRussian ? "Нет" : "No"));
         }
         else if (signal == 2)
         {
             return(((int)tagData.Val).ToString());
         }
         // TEST -------------------
         else if (signal == 3)
         {
             return(ScadaUtils.DecodeAscii(tagData.Val).ToString());
         }
         // TEST -------------------
     }
     return(base.ConvertTagDataToStr(signal, tagData));
 }
Example #4
0
        /// <summary>
        /// Format input channel value
        /// </summary>
        public void FormatCnlVal(double val, int stat, InCnlProps cnlProps, string decSep, string grSep,
                                 out string text, out string textWithUnit, out bool textIsNumber, bool throwOnError = false)
        {
            bool cnlPropsIsNull = cnlProps == null;

            try {
                if (stat <= 0)
                {
                    text         = textWithUnit = EmptyVal;
                    textIsNumber = false;
                }
                else
                {
                    text         = textWithUnit = NoVal;
                    textIsNumber = false;

                    int formatID   = cnlPropsIsNull ? 0 : cnlProps.FormatID;
                    int unitArrLen = cnlPropsIsNull || cnlProps.UnitArr == null ? 0 : cnlProps.UnitArr.Length;

                    if (cnlPropsIsNull || cnlProps.ShowNumber)
                    {
                        // getting dimension
                        string unit = unitArrLen > 0 ? " " + cnlProps.UnitArr[0] : "";

                        // number format definition
                        NumberFormatInfo nfi;
                        bool             sepDefined = !(decSep == null && grSep == null);

                        if (cnlPropsIsNull || sepDefined)
                        {
                            nfi = sepDefined ? CreateFormatInfo(DefDecDig, decSep, grSep) : defNfi;
                        }
                        else if (cnlProps.FormatInfo == null)
                        {
                            nfi = cnlProps.FormatInfo = CreateFormatInfo(cnlProps.DecDigits, decSep, grSep);
                        }
                        else
                        {
                            nfi = cnlProps.FormatInfo;
                        }

                        // value formatting
                        text         = val.ToString("N", nfi);
                        textWithUnit = text + unit;
                        textIsNumber = true;
                    }
                    else if (formatID == BaseValues.Formats.EnumText)
                    {
                        if (unitArrLen > 0)
                        {
                            var unitInd = (int)val;
                            if (unitInd < 0)
                            {
                                unitInd = 0;
                            }
                            else if (unitInd >= unitArrLen)
                            {
                                unitInd = unitArrLen - 1;
                            }
                            text = textWithUnit = cnlProps.UnitArr[unitInd];
                        }
                    }
                    else if (formatID == BaseValues.Formats.AsciiText)
                    {
                        text = textWithUnit = ScadaUtils.DecodeAscii(val);
                    }
                    else if (formatID == BaseValues.Formats.UnicodeText)
                    {
                        text = textWithUnit = ScadaUtils.DecodeUnicode(val);
                    }
                    else if (formatID == BaseValues.Formats.DateTime)
                    {
                        text = textWithUnit = ScadaUtils.DecodeDateTime(val).ToLocalizedString();
                    }
                    else if (formatID == BaseValues.Formats.Date)
                    {
                        text = textWithUnit = ScadaUtils.DecodeDateTime(val).ToLocalizedDateString();
                    }
                    else if (formatID == BaseValues.Formats.Time)
                    {
                        text = textWithUnit = ScadaUtils.DecodeDateTime(val).ToLocalizedTimeString();
                    }
                }
            } catch (Exception ex) {
                if (throwOnError)
                {
                    string cnlNumStr = cnlPropsIsNull ? "?" : cnlProps.CnlNum.ToString();
                    throw new ScadaException($"Error formatting value of input channel {cnlNumStr}", ex);
                }

                text         = textWithUnit = FrmtErrVal;
                textIsNumber = false;
            }
        }
Example #5
0
        /// <summary>
        /// Форматировать значение входного канала
        /// </summary>
        public void FormatCnlVal(double val, int stat, InCnlProps cnlProps, string decSep, string grSep,
                                 out string text, out string textWithUnit, out bool textIsNumber, bool throwOnError = false)
        {
            bool cnlPropsIsNull = cnlProps == null;

            try
            {
                if (stat <= 0)
                {
                    text         = textWithUnit = EmptyVal;
                    textIsNumber = false;
                }
                else
                {
                    text         = textWithUnit = NoVal;
                    textIsNumber = false;

                    int formatID   = cnlPropsIsNull ? 0 : cnlProps.FormatID;
                    int unitArrLen = cnlPropsIsNull || cnlProps.UnitArr == null ? 0 : cnlProps.UnitArr.Length;

                    if (cnlPropsIsNull || cnlProps.ShowNumber)
                    {
                        string unit = unitArrLen > 0 ? " " + cnlProps.UnitArr[0] : "";

                        nfi.NumberDecimalDigits    = cnlPropsIsNull ? DefDecDig : cnlProps.DecDigits;
                        nfi.NumberDecimalSeparator = decSep == null ? defDecSep : decSep;
                        nfi.NumberGroupSeparator   = grSep == null ? defGrSep : grSep;

                        text         = val.ToString("N", nfi);
                        textWithUnit = text + unit;
                        textIsNumber = true;
                    }
                    else if (formatID == BaseValues.Formats.EnumText)
                    {
                        if (unitArrLen > 0)
                        {
                            int unitInd = (int)val;
                            if (unitInd < 0)
                            {
                                unitInd = 0;
                            }
                            else if (unitInd >= unitArrLen)
                            {
                                unitInd = unitArrLen - 1;
                            }
                            text = textWithUnit = cnlProps.UnitArr[unitInd];
                        }
                    }
                    else if (formatID == BaseValues.Formats.AsciiText)
                    {
                        text = textWithUnit = ScadaUtils.DecodeAscii(val);
                    }
                    else if (formatID == BaseValues.Formats.UnicodeText)
                    {
                        text = textWithUnit = ScadaUtils.DecodeUnicode(val);
                    }
                    else if (formatID == BaseValues.Formats.DateTime)
                    {
                        text = textWithUnit = ScadaUtils.DecodeDateTime(val).ToLocalizedString();
                    }
                    else if (formatID == BaseValues.Formats.Date)
                    {
                        text = textWithUnit = ScadaUtils.DecodeDateTime(val).ToLocalizedDateString();
                    }
                    else if (formatID == BaseValues.Formats.Time)
                    {
                        text = textWithUnit = ScadaUtils.DecodeDateTime(val).ToLocalizedTimeString();
                    }
                }
            }
            catch (Exception ex)
            {
                if (throwOnError)
                {
                    string cnlNumStr = cnlPropsIsNull ? "?" : cnlProps.CnlNum.ToString();
                    throw new ScadaException(string.Format(Localization.UseRussian ?
                                                           "Ошибка при форматировании значения входного канала {0}" :
                                                           "Error formatting value of input channel {0}", cnlNumStr), ex);
                }
                else
                {
                    text         = textWithUnit = FrmtErrVal;
                    textIsNumber = false;
                }
            }
        }
Example #6
0
        /// <summary>
        /// Форматировать значение входного канала
        /// </summary>
        public void FormatCnlVal(double val, int stat, InCnlProps cnlProps, string decSep, string grSep,
                                 out string text, out string textWithUnit, out bool textIsNumber, bool throwOnError = false)
        {
            bool cnlPropsIsNull = cnlProps == null;

            try
            {
                if (stat <= 0)
                {
                    text         = textWithUnit = EmptyVal;
                    textIsNumber = false;
                }
                else
                {
                    text         = textWithUnit = NoVal;
                    textIsNumber = false;

                    int formatID   = cnlPropsIsNull ? 0 : cnlProps.FormatID;
                    int unitArrLen = cnlPropsIsNull || cnlProps.UnitArr == null ? 0 : cnlProps.UnitArr.Length;

                    if (cnlPropsIsNull || cnlProps.ShowNumber)
                    {
                        // получение размерности
                        string unit = unitArrLen > 0 ? " " + cnlProps.UnitArr[0] : "";

                        // определение формата числа
                        NumberFormatInfo nfi;
                        bool             sepDefined = !(decSep == null && grSep == null);

                        if (cnlPropsIsNull)
                        {
                            nfi = sepDefined ?
                                  CreateFormatInfo(DefDecDig, decSep, grSep) :
                                  defNfi;
                        }
                        else if (sepDefined)
                        {
                            nfi = CreateFormatInfo(cnlProps.DecDigits, decSep, grSep);
                        }
                        else if (cnlProps.FormatInfo == null)
                        {
                            nfi = cnlProps.FormatInfo = CreateFormatInfo(cnlProps.DecDigits, decSep, grSep);
                        }
                        else
                        {
                            nfi = cnlProps.FormatInfo;
                        }

                        // форматирование значения
                        text         = val.ToString("N", nfi);
                        textWithUnit = text + unit;
                        textIsNumber = true;
                    }
                    else if (formatID == BaseValues.Formats.EnumText)
                    {
                        if (unitArrLen > 0)
                        {
                            int unitInd = (int)val;
                            if (unitInd < 0)
                            {
                                unitInd = 0;
                            }
                            else if (unitInd >= unitArrLen)
                            {
                                unitInd = unitArrLen - 1;
                            }
                            text = textWithUnit = cnlProps.UnitArr[unitInd];
                        }
                    }
                    else if (formatID == BaseValues.Formats.AsciiText)
                    {
                        text = textWithUnit = ScadaUtils.DecodeAscii(val);
                    }
                    else if (formatID == BaseValues.Formats.UnicodeText)
                    {
                        text = textWithUnit = ScadaUtils.DecodeUnicode(val);
                    }
                    else if (formatID == BaseValues.Formats.DateTime)
                    {
                        text = textWithUnit = ScadaUtils.DecodeDateTime(val).ToLocalizedString();
                    }
                    else if (formatID == BaseValues.Formats.Date)
                    {
                        text = textWithUnit = ScadaUtils.DecodeDateTime(val).ToLocalizedDateString();
                    }
                    else if (formatID == BaseValues.Formats.Time)
                    {
                        text = textWithUnit = ScadaUtils.DecodeDateTime(val).ToLocalizedTimeString();
                    }
                }
            }
            catch (Exception ex)
            {
                if (throwOnError)
                {
                    string cnlNumStr = cnlPropsIsNull ? "?" : cnlProps.CnlNum.ToString();
                    throw new ScadaException(string.Format(Localization.UseRussian ?
                                                           "Ошибка при форматировании значения входного канала {0}" :
                                                           "Error formatting value of input channel {0}", cnlNumStr), ex);
                }
                else
                {
                    text         = textWithUnit = FrmtErrVal;
                    textIsNumber = false;
                }
            }
        }