Пример #1
0
 public static bool SendUsage()
 {
     try
     {
         //获取使用情况
         List <SeatManage.ClassModel.AMS_AdvertUsage> usageList = SeatManage.Bll.AdvertisementOperation.GetAdvertUsageList();
         //创建使用记录
         List <AMS.Model.AMS_AdvertUsage> modelList = new List <AMS_AdvertUsage>();
         foreach (SeatManage.ClassModel.AMS_AdvertUsage item in usageList)
         {
             AMS.Model.AMS_AdvertUsage model = new AMS.Model.AMS_AdvertUsage();
             model                = AMS.Model.AMS_AdvertUsage.ToModel(item.AdvertUsage);
             model.AdvertNum      = item.AdvertNum;
             model.AdvertType     = (AMS.Model.Enum.AdType)System.Enum.Parse(typeof(AMS.Model.Enum.AdType), item.AdvertType.ToString());
             model.AdvertUsage    = item.AdvertUsage;
             model.LastUpdateTime = item.LastUpdateTime;
             model.SchoolNum      = ServiceSet.SchoolNums;
             if (!AMS.ServiceProxy.AdvertisementOperationService.UpLoadGetAdvertUsage(model))
             {
                 return(false);
             }
         }
         return(true);
     }
     catch
     {
         throw;
     }
 }
Пример #2
0
        /// <summary>
        /// 转换成Xml
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static string ToXml(AMS_AdvertUsage model)
        {
            //TODO:转换成xml结构的算法
            //创建一个xml对象
            XmlDocument xmlDoc = new XmlDocument();
            //创建开头
            XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

            xmlDoc.AppendChild(dec);
            //创建根节点
            XmlElement root = xmlDoc.CreateElement("Root");

            root.SetAttribute("AdvertNum", model.AdvertNum.ToString());
            root.SetAttribute("AdvertType", model.AdvertType.ToString());
            root.SetAttribute("PlayCount", model.PlayCount.ToString());
            root.SetAttribute("WatchCount", model.WatchCount.ToString());
            root.SetAttribute("PrintCount", model.PrintCount.ToString());
            XmlElement SecNode = xmlDoc.CreateElement("AdvertItem");

            foreach (KeyValuePair <string, AdvertisementUsage> item in model.ItemUsage)
            {
                XmlElement ThrNode = xmlDoc.CreateElement("Item");
                ThrNode.SetAttribute("AdvertNum", item.Value.AdvertNum.ToString());
                ThrNode.SetAttribute("PlayCount", item.Value.PlayCount.ToString());
                ThrNode.SetAttribute("WatchCount", item.Value.WatchCount.ToString());
                ThrNode.SetAttribute("PrintCount", item.Value.PrintCount.ToString());
                SecNode.AppendChild(ThrNode);
            }
            //在根节点中添加二级节点
            root.AppendChild(SecNode);
            //添加根节点
            xmlDoc.AppendChild(root);
            return(xmlDoc.OuterXml);
        }
Пример #3
0
        /// <summary>
        /// 转换成Moldel
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static AMS_AdvertUsage ToModel(string xml)
        {
            if (string.IsNullOrEmpty(xml))
            {
                return(null);
            }
            XmlDocument     xmlDoc = new XmlDocument();
            AMS_AdvertUsage model  = new AMS_AdvertUsage();

            try
            {
                xmlDoc.LoadXml(xml);
                //查找根节点
                XmlNode node = xmlDoc.SelectSingleNode("//Root");
                model.AdvertNum  = node.Attributes["AdvertNum"].Value;//列表编号
                model.PlayCount  = int.Parse(node.Attributes["PlayCount"].Value);
                model.WatchCount = int.Parse(node.Attributes["WatchCount"].Value);
                model.PrintCount = int.Parse(node.Attributes["PrintCount"].Value);
                model.AdvertType = (Enum.AdType)System.Enum.Parse(typeof(Enum.AdType), node.Attributes["AdvertType"].Value);
                XmlNodeList nodes = xmlDoc.SelectNodes("//Root/AdvertItem/Item");
                foreach (XmlNode ItemNode in nodes)
                {
                    AdvertisementUsage item = new AdvertisementUsage();
                    item.AdvertNum  = ItemNode.Attributes["AdvertNum"].Value;//列表编号
                    item.PlayCount  = int.Parse(ItemNode.Attributes["PlayCount"].Value);
                    item.WatchCount = int.Parse(ItemNode.Attributes["WatchCount"].Value);
                    item.PrintCount = int.Parse(ItemNode.Attributes["PrintCount"].Value);
                    if (!model.ItemUsage.ContainsKey(item.AdvertNum))
                    {
                        model.ItemUsage.Add(item.AdvertNum, item);
                    }
                }
                return(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }