private static string FormatOctetMATHF(PropertyTypeEnum exportPropertyType, TypeOfOctet octetType, ExportPropertyGeneral property)
        {
            double Num;
            string propertyValue = null;
            double value         = 0;



            if (property != null)
            {
                propertyValue = property.Value;
                value         = double.Parse(propertyValue);
                if (exportPropertyType == PropertyTypeEnum.PhysicalModulusOfElasticity)
                {
                    value = value * 1000;
                }
            }
            string emptyOctet = EMPTYOCTET;

            if (exportPropertyType != PropertyTypeEnum.PhysicalPoissonCoefficient)
            {
                emptyOctet = FillEmptySpace(0, octetType, 8);
            }


            return(propertyValue != null && double.TryParse(propertyValue, out Num) ? FillEmptySpace(value, octetType, 8) : emptyOctet);
        }
예제 #2
0
        /// <summary>
        /// Fills the octet with values according to if value is double, int, or value which lenght is bigger then 8 characters.
        /// Also we must consider value align in octet.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static String FillOctet(double value, TypeOfOctet type, TMPropertyTypeEnum exportType)
        {
            string formatedValue = "";

            switch (exportType)
            {
            case TMPropertyTypeEnum.None:
                break;

            case TMPropertyTypeEnum.PhysicalModulusOfElasticity:
                formatedValue = (String.Format(CultureInfo.InvariantCulture, "{0:0.###E+0}", value * 1000000)).Replace("E", "");
                formatedValue = formatedValue.PadRight(8);
                break;

            case TMPropertyTypeEnum.PhysicalPoissonCoefficient:
                formatedValue = value.ToString().PadRight(8);
                break;

            case TMPropertyTypeEnum.PhysicalDensity:
                formatedValue = value.ToString().PadRight(8);
                break;

            case TMPropertyTypeEnum.PhysicalMeanCoeffThermalExpansion:
                formatedValue = (String.Format(CultureInfo.InvariantCulture, "{0:0.###E+0}", value / 1000000)).Replace("E", "");
                formatedValue = formatedValue.PadRight(8);
                break;

            default:
                break;
            }
            return(formatedValue);
        }
        /// <summary>
        /// Formats the octet.
        /// </summary>
        /// <param name="export">The export.</param>
        /// <param name="exportType">Type of the export.</param>
        /// <returns></returns>
        private static string FormatOctet(ExportPropertyGeneral property, TypeOfOctet octetType)
        {
            double Num;
            string propertyValue = null;

            if (property != null)
            {
                propertyValue = property.Value;
            }
            return(propertyValue != null && double.TryParse(propertyValue, out Num) ? FillOctet(double.Parse(propertyValue), octetType) : EMPTYOCTET);
        }
        /// <summary>
        /// Fills the octet with values according to if value is double, int, or value which lenght is bigger then 8 characters.
        /// Also we must consider value align in octet.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static String FillOctet(double value, TypeOfOctet type)
        {
            string stringValue  = value.ToString();
            int    stringLength = stringValue.Length;
            int    freeSpaces   = Octet - stringValue.Length;

            if (stringLength > Octet)
            {
                if (stringValue.Split('.').Count() > 1 && stringValue.Split('.')[1] != null)
                {
                    int    beforeComma = stringValue.Split('.')[0].Count();
                    int    afterComma  = stringValue.Split('.')[1].Count();
                    string returnValue = Math.Round(value, Octet - beforeComma - 1).ToString();
                    if (returnValue.Length == 8)
                    {
                        return(returnValue);
                    }
                    freeSpaces = Octet - returnValue.Length;
                    return(AddEmptySpaces(returnValue, freeSpaces, type));
                }
                else
                {
                    stringValue = stringValue.Substring(0, 1) + ".0+" + (stringValue.Length - 1).ToString();
                    freeSpaces  = Octet - stringValue.Length;
                    return(AddEmptySpaces(stringValue, freeSpaces, type));
                    // return stringValue + ".0";
                }
            }
            if (stringValue.IndexOf(".") > -1 && stringValue.Split('.')[1] != null)
            {
                return(AddEmptySpaces(stringValue, freeSpaces, type));
            }
            if (stringValue.Length > Octet - 2)
            {
                stringValue = "1.0+" + (stringValue.Length - 1).ToString();
                freeSpaces  = Octet - stringValue.Length;
                return(AddEmptySpaces(stringValue, freeSpaces, type));
            }
            else
            {
                stringValue = stringValue + ".0";
                freeSpaces  = freeSpaces - 2;
                return(AddEmptySpaces(stringValue, freeSpaces, type));
            }
        }
 /// <summary>
 /// Adds the empty spaces according to type Of octet.
 /// </summary>
 /// <param name="stringValue">The string value.</param>
 /// <param name="freeSpaces">The free spaces.</param>
 /// <param name="type">The type.</param>
 /// <returns></returns>
 private static string AddEmptySpaces(string stringValue, int freeSpaces, TypeOfOctet type)
 {
     if (type == TypeOfOctet.Left)
     {
         for (int i = 0; i < freeSpaces; i++)
         {
             stringValue = stringValue + " ";
         }
     }
     else
     {
         for (int i = 0; i < freeSpaces; i++)
         {
             stringValue = " " + stringValue;
         }
     }
     return(stringValue);
 }
예제 #6
0
        /// <summary>
        /// Formats the octet.
        /// </summary>
        /// <param name="export">The export.</param>
        /// <param name="exportType">Type of the export.</param>
        /// <returns></returns>
        private static string FormatOctet(IList <ExportPropertyGeneral> properties, TMPropertyTypeEnum exportType, TypeOfOctet octetType)
        {
            double Num;
            string propertyValue           = null;
            ExportPropertyGeneral property = (from u in properties where u.Type == exportType select u).FirstOrDefault();

            if (property != null)
            {
                propertyValue = property.Value;
                return(propertyValue != null && double.TryParse(propertyValue, out Num) ? FillOctet(double.Parse(propertyValue), octetType, exportType) : EMPTYOCTET);
            }
            else
            {
                return(ZERO);
            }
        }