Esempio n. 1
0
        /// <summary>
        /// 根据配置文件中formate的属性字符串获得对应的Format对象
        /// </summary>
        /// <param name="formatAttri">配置文件中formate的属性字符串</param>
        /// <returns>Format对象</returns>
        private static Format GetFormat(String formatAttri)
        {
            Format result = new Format();

            if (String.IsNullOrEmpty(formatAttri))
            {
                return(result);
            }

            String[] formats = formatAttri.Split(',');
            if (formats.Length == 0)
            {
                return(result);
            }

            foreach (String eachFormat in formats)
            {
                String[] subFormats = eachFormat.Split(':');

                if (subFormats.Length < 2)
                {
                    LogUtilities.LogMessage(eachFormat + " is incorrect format String!");
                    continue;
                }

                String formatFlag     = subFormats[0];
                String formatConetent = subFormats[1];

                switch (formatFlag)
                {
                case "Z":
                {
                    // Sample: Z:Now:E 和 Z:this:H
                    //  Z开头-如果某个字段是0显示横杠/空,
                    // 例Z:Now:E表示如果Now值是0,显示String.Empty;
                    // 例Z:this:H表示如果该字段的值是0,显示横杠
                    CompareTarget CompareTarget; FieldIndex comparedIndex = FieldIndex.Market;
                    if (subFormats[1].Equals("this", StringComparison.CurrentCultureIgnoreCase))
                    {
                        CompareTarget = CompareTarget.This;
                    }
                    else
                    {
                        CompareTarget = CompareTarget.SpecialFieldIndex;
                        comparedIndex = (FieldIndex)Enum.Parse(typeof(FieldIndex), formatConetent, true);
                    }

                    ZeroTypeFlag ZeroTypeFlag = (ZeroTypeFlag)Enum.Parse(typeof(ZeroTypeFlag), subFormats[2]);
                    result.ZeroRule = new ZeroRule(CompareTarget, comparedIndex, ZeroTypeFlag);
                }
                break;

                case "A":
                case "C":
                case "M":
                case "D":
                {
                    // Sample:  A:100:F2
                    // A:100:F2   A开头表示加,加100,保留两位小数
                    // C:100:F2   C开头表示减,减100,保留两位小数
                    // M:100:F2   M开头表示乘,乘100,保留两位小数
                    // D:100:F2   D开头表示除,除100,保留两位小数

                    if (result.CalculateRules == null)
                    {
                        result.CalculateRules = new List <CalculateRule>(1);
                    }

                    CalMethod calMethod = (CalMethod)Enum.Parse(typeof(CalMethod), subFormats[0]);
                    float     zoomNum;
                    if (float.TryParse(subFormats[1], out zoomNum))
                    {
                        result.CalculateRules.Add(new CalculateRule(calMethod, zoomNum, subFormats[2]));
                    }
                }
                break;



                case "N":
                    result.NRule = new NRule(formatConetent);
                    break;

                case "P":
                    result.PRule = new PRule(formatConetent);
                    break;

                case "Q":
                    result.QRule = new QRule(formatConetent);
                    break;

                case "S":
                    result.SRule = new SRule(formatConetent);
                    break;

                default:
                    break;
                }
            }

            return(result);
        }
Esempio n. 2
0
 /// <summary>
 /// 判零规则的构造函数
 /// </summary>
 /// <param name="compareTarget">比较类型</param>
 /// <param name="comparedIndex"></param>
 /// <param name="zeroTypeFlag"></param>
 public ZeroRule(CompareTarget compareTarget, FieldIndex comparedIndex, ZeroTypeFlag zeroTypeFlag)
 {
     this.CompareTarget = compareTarget;
     this.ZeroTypeFlag  = zeroTypeFlag;
     this.ComparedIndex = comparedIndex;
 }