/// <summary>
        /// 增加一条包含MD5的数据
        /// </summary>
        public bool AddMd5(SeatManage.ClassModel.AMS_PlayListMd5 model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into AMS_PlayList(");
            strSql.Append("Number,CampusNum,PlayList,ReleaseDate,EffectDate,EndDate)");
            strSql.Append(" values (");
            strSql.Append("@Number,@CampusNum,@PlayList,@ReleaseDate,@EffectDate,@EndDate)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Number",      SqlDbType.NVarChar,  50),
                new SqlParameter("@CampusNum",   SqlDbType.NVarChar,  50),
                new SqlParameter("@PlayList",    SqlDbType.Text),
                new SqlParameter("@ReleaseDate", SqlDbType.DateTime),
                new SqlParameter("@EffectDate",  SqlDbType.DateTime),
                new SqlParameter("@EndDate",     SqlDbType.DateTime)
            };
            parameters[0].Value = model.PlayListNo;
            parameters[1].Value = "";
            parameters[2].Value = model.ToXml();
            parameters[3].Value = model.ReleaseDate.Value;
            parameters[4].Value = model.EffectDate;
            parameters[5].Value = model.EndDate;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// 结构转换成XML
        /// </summary>
        /// <param name="playlist">播放列表</param>
        /// <returns></returns>
        public string ToXml(AMS_PlayListMd5 playlist)
        {
            //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("Num", playlist.PlayListNo);
            root.SetAttribute("EffectDate", playlist.EffectDate.ToShortDateString());
            root.SetAttribute("EndDate", playlist.EndDate.ToShortDateString());
            root.SetAttribute("PlayElapsed", playlist.PlayElapsed.ToString());
            //创建二级节点
            XmlElement SecNode = xmlDoc.CreateElement("VideoItems");

            root.AppendChild(SecNode);
            //遍历媒体文件并添加到节点中
            foreach (AMS_VideoMd5Item video in playlist.PlayVideoItems)
            {
                XmlElement ThirdNode = xmlDoc.CreateElement("Video");
                ThirdNode.SetAttribute("name", video.Name);
                ThirdNode.SetAttribute("playtime", video.PlayTime);
                ThirdNode.SetAttribute("source", video.RelativeUrl);
                ThirdNode.SetAttribute("md5value", video.md5Value);
                SecNode.AppendChild(ThirdNode);
                //不重复的视频文件名称
                int i;
                for (i = 0; i < VideoFiles.Count; i++)
                {
                    if (VideoFiles[i].Name == video.Name)
                    {
                        break;
                    }
                }
                if (i >= VideoFiles.Count)
                {
                    VideoFiles.Add(video);
                }
            }
            //在根节点中添加二级节点
            root.AppendChild(SecNode);
            //添加根节点
            xmlDoc.AppendChild(root);
            return(xmlDoc.OuterXml);
        }
        /// <summary>
        /// 更新一条包含MD5的数据
        /// </summary>
        public bool UpdateMd5(SeatManage.ClassModel.AMS_PlayListMd5 model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update AMS_PlayList set ");
            strSql.Append("CampusNum=@CampusNum,");
            strSql.Append("PlayList=@PlayList,");
            strSql.Append("ReleaseDate=@ReleaseDate,");
            strSql.Append("EffectDate=@EffectDate,");
            strSql.Append("EndDate=@EndDate");
            strSql.Append(" where Number=@Number ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CampusNum",   SqlDbType.NVarChar,  50),
                new SqlParameter("@PlayList",    SqlDbType.Text),
                new SqlParameter("@ReleaseDate", SqlDbType.DateTime),
                new SqlParameter("@EffectDate",  SqlDbType.DateTime),
                new SqlParameter("@EndDate",     SqlDbType.DateTime),
                new SqlParameter("@Number",      SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = "";
            parameters[1].Value = model.ToXml();
            if (model.ReleaseDate.HasValue)
            {
                parameters[2].Value = model.ReleaseDate.Value;
            }
            else
            {
                parameters[2].Value = DateTime.Parse("1900-1-1");
            }
            parameters[3].Value = model.EffectDate;
            parameters[4].Value = model.EndDate;
            parameters[5].Value = model.PlayListNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// 播放列表xml 转换成对象
        /// </summary>
        /// <param name="xmlPlayList">xml结构的播放列表</param>
        /// <returns></returns>
        public static AMS_PlayListMd5 Parse(string xmlPlayList)
        {
            AMS_PlayListMd5 plm    = new AMS_PlayListMd5();
            XmlDocument     xmlDoc = new XmlDocument();

            try
            {
                //载入字符串类型的XML
                xmlDoc.LoadXml(xmlPlayList);
                plm = Parse(xmlDoc);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(plm);
        }
示例#5
0
        /// <summary>
        /// 播放列表xml 转换成对象
        /// </summary>
        /// <param name="xmlPlayList">xml结构的播放列表</param>
        /// <returns></returns>
        private static AMS_PlayListMd5 Parse(XmlDocument xmlPlayList)
        {
            AMS_PlayListMd5         plm        = new AMS_PlayListMd5();
            List <AMS_VideoMd5Item> videoFiles = new List <AMS_VideoMd5Item>();
            XmlDocument             xmlDoc     = xmlPlayList;

            try
            {
                //查找根节点
                XmlNode node = xmlDoc.SelectSingleNode("//Root");
                plm.PlayListNo  = node.Attributes["Num"].Value;                        //列表编号
                plm.EffectDate  = DateTime.Parse(node.Attributes["EffectDate"].Value); //生效日期
                plm.PlayElapsed = int.Parse(node.Attributes["PlayElapsed"].Value);
                plm.EndDate     = DateTime.Parse(node.Attributes["EndDate"].Value);
                List <AMS_VideoMd5Item> lists = new List <AMS_VideoMd5Item>();
                XmlNodeList             nodes = xmlDoc.SelectNodes("//Root/VideoItems/Video");
                //遍历找到的视频项
                foreach (XmlNode n in nodes)
                {
                    if ((n.Attributes["md5value"]) == null)
                    {
                        lists.Add(
                            new AMS_VideoMd5Item()
                        {
                            Name        = n.Attributes["name"].Value,
                            PlayTime    = n.Attributes["playtime"].Value,
                            RelativeUrl = n.Attributes["source"].Value,
                            md5Value    = null
                        }
                            );
                    }
                    else
                    {
                        lists.Add(
                            new AMS_VideoMd5Item()
                        {
                            Name        = n.Attributes["name"].Value,
                            PlayTime    = n.Attributes["playtime"].Value,
                            RelativeUrl = n.Attributes["source"].Value,
                            md5Value    = n.Attributes["md5value"].Value
                        }
                            );
                    }
                    //不重复的视频文件名称
                    int i;
                    for (i = 0; i < videoFiles.Count; i++)
                    {
                        if (videoFiles[i].Name == n.Attributes["name"].Value)
                        {
                            break;
                        }
                    }
                    if (i >= videoFiles.Count)
                    {
                        if ((n.Attributes["md5value"]) == null)
                        {
                            videoFiles.Add(new AMS_VideoMd5Item()
                            {
                                Name = n.Attributes["name"].Value, RelativeUrl = n.Attributes["source"].Value, md5Value = null
                            });
                        }
                        else
                        {
                            videoFiles.Add(new AMS_VideoMd5Item()
                            {
                                Name = n.Attributes["name"].Value, RelativeUrl = n.Attributes["source"].Value, md5Value = n.Attributes["md5value"].Value
                            });
                        }
                    }
                }
                plm.VideoFiles         = videoFiles;
                plm.PlayVideoItems     = lists;
                plm.PlayListTimeLength = GetTimeLength(DateTime.Parse(DateTime.Now.ToShortDateString() + " " + lists[0].PlayTime), DateTime.Parse(DateTime.Now.ToShortDateString() + " " + lists[lists.Count - 1].PlayTime));
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(plm);
        }