示例#1
0
 public void Add(RateEntityGroup group)
 {
     if (!this.groups.Contains(group))
     {
         this.groups.Add(group);
     }
 }
示例#2
0
        protected override string GenerateXML(DataSet ds)
        {
            Dictionary <string, Dictionary <decimal, decimal> > rateDic = new Dictionary <string, Dictionary <decimal, decimal> >();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                DataRow row = ds.Tables[0].Rows[i];
                if (row[0] == DBNull.Value)
                {
                    continue;
                }

                string[] header      = new string[] { "AU", "GB-1", "GB-2", "GB-3", "GB-4" };
                int[]    validColumn = new int[] { 22, 24, 25, 26, 27 };

                for (int j = 0; j < header.Length; j++)
                {
                    string zone = header[j];
                    if (!rateDic.ContainsKey(zone))
                    {
                        rateDic.Add(zone, new Dictionary <decimal, decimal>());
                    }
                    int columnNumber = validColumn[j];
                    if (row[columnNumber] != DBNull.Value)
                    {
                        decimal weight = Math.Round(Convert.ToDecimal(row[0]), 2, MidpointRounding.AwayFromZero);
                        decimal rate   = Convert.ToDecimal(row[columnNumber]);
                        rateDic[zone].Add(weight, rate);
                    }
                }
            }

            RateEntityGroups groups = new RateEntityGroups {
                Name = this.CurrentProcessFileName
            };

            foreach (string key in rateDic.Keys)
            {
                RateEntityGroup group = new RateEntityGroup {
                    Zone = key
                };
                foreach (KeyValuePair <decimal, decimal> kv in rateDic[key])
                {
                    group.Add(new RateEntiy {
                        Zone = key, Weight = kv.Key, Price = kv.Value
                    });
                }
                groups.Add(group);
            }
            return(groups.ToString());
        }