Exemplo n.º 1
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);
        }
 /// <summary>
 /// 更新使用情况
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static string UpdateAdvertUsage(SeatManage.ClassModel.AMS_AdvertUsage model)
 {
     IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
     try
     {
         return(seatService.UpdateAdvertUsage(model));
     }
     catch (FaultException ex)
     {
         SeatManageComm.WriteLog.Write("更新广告状态失败:" + ex.Message);
         return(ex.Message);
     }
     finally
     {
         ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
         try
         {
             if (ICommObjectService.State == CommunicationState.Faulted)
             {
                 ICommObjectService.Abort();
             }
             else
             {
                 ICommObjectService.Close();
             }
         }
         catch
         {
             ICommObjectService.Abort();
         }
     }
 }
 /// <summary>
 /// 更新使用情况
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static string UpdateAdvertUsage(SeatManage.ClassModel.AMS_AdvertUsage model)
 {
     IWCFService.ISeatManageService seatService = new WcfServiceForSeatManage.SeatManageDateService();
     try
     {
         return(seatService.UpdateAdvertUsage(model));
     }
     catch (FaultException ex)
     {
         SeatManageComm.WriteLog.Write("更新广告状态失败:" + ex.Message);
         return(ex.Message);
     }
 }
Exemplo n.º 4
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 = (SeatManage.EnumType.AdType)System.Enum.Parse(typeof(SeatManage.EnumType.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;
            }
        }