예제 #1
1
        private void button_update_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count == 0) return;

            TreeNode node = treeView1.SelectedNode;

            try
            {
                switch (node.Level)
                {
                    case 0:
                        DateTime startDate = DateTime.Parse(dataGridView1.Rows[0].Cells[0].Value.ToString());
                        DateTime endDate = DateTime.Parse(dataGridView1.Rows[0].Cells[1].Value.ToString());
                        if (startDate.Date >= endDate.Date)
                        {
                            MessageBox.Show("起始日期须早于终止日期!请检查输入!", "日期校验异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        DateSheet dt = new DateSheet();
                        dt.startDate = startDate;
                        dt.endDate = endDate;
                        dt.Mon = (bool)dataGridView1.Rows[0].Cells[2].Value;
                        dt.Tue = (bool)dataGridView1.Rows[0].Cells[3].Value;
                        dt.Wed = (bool)dataGridView1.Rows[0].Cells[4].Value;
                        dt.Thu = (bool)dataGridView1.Rows[0].Cells[5].Value;
                        dt.Fri = (bool)dataGridView1.Rows[0].Cells[6].Value;
                        dt.Sat = (bool)dataGridView1.Rows[0].Cells[7].Value;
                        dt.Sun = (bool)dataGridView1.Rows[0].Cells[8].Value;
                        dt.timesheets = config.datesheets[node.Index].timesheets;
                        config.datesheets[node.Index] = dt;
                        cur_node.Text = "日期: " + dt.startDate.ToShortDateString() + " 至 " + dt.endDate.ToShortDateString();
                        break;

                    case 1:
                        DateTime startTime = DateTime.Parse(dataGridView1.Rows[0].Cells[0].Value.ToString());
                        DateTime endTime = DateTime.Parse(dataGridView1.Rows[0].Cells[1].Value.ToString());
                        if (startTime.TimeOfDay >= endTime.TimeOfDay)
                        {
                            MessageBox.Show("起始时间须早于终止时间!请检查输入!", "时间校验异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        TimeSheet ts = new TimeSheet();
                        ts.startTime = startTime;
                        ts.endTime = endTime;
                        ts.mode = dataGridView1.Rows[0].Cells[2].Value.ToString() == "随机播放" ? PlayMode.random : PlayMode.sequencial;
                        ts.contents = config.datesheets[node.Parent.Index].timesheets[node.Index].contents;
                        config.datesheets[node.Parent.Index].timesheets[node.Index] = ts;
                        cur_node.Text = "时间: " + ts.startTime.ToLongTimeString() + " 至 " + ts.endTime.ToLongTimeString() + ", 播放模式: " + ts.mode;
                        break;

                    case 2:
                        Content ct = new Content();
                        if (dataGridView1.Rows[0].Cells[0].Value.ToString().Equals("dir")) ct.type = ContentType.dir;
                        if (dataGridView1.Rows[0].Cells[0].Value.ToString().Equals("powerpoint")) ct.type = ContentType.powerpoint;
                        if (dataGridView1.Rows[0].Cells[0].Value.ToString().Equals("video")) ct.type = ContentType.video;
                        ct.duration = int.Parse(dataGridView1.Rows[0].Cells[1].Value.ToString());
                        ct.file = dataGridView1.Rows[0].Cells[2].Value.ToString();
                        config.datesheets[node.Parent.Parent.Index].timesheets[node.Parent.Index].contents[node.Index] = ct;
                        cur_node.Text = "文件: 类型:" + ct.type.ToString() + ", 停留: " + ct.duration.ToString() + ", 名称: " + ct.file;
                        break;

                    default:
                        break;
                }
                label_update_ok.Text = "保存成功!";
                label_update_ok.ForeColor = Color.Black;
            }
            catch
            {
                label_update_ok.Text = "修改失败!请检查输入!";
                label_update_ok.ForeColor = Color.Red;
            }

            label_update_ok.Visible = true;
        }
예제 #2
0
파일: XML.cs 프로젝트: solunar66/AdPlayer
        /// <summary>
        /// 读取播放配置
        /// </summary>
        /// <returns></returns>
        public bool ReadPlayConfig(ref Config config, bool expendDir, ref string error)
        {
            error = string.Empty;

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);

                XmlNode system = doc.SelectSingleNode("system");

                XmlNode screen = system.SelectSingleNode("screen");
                config.scr = int.Parse(screen.Attributes["index"].Value);

                XmlNode idle = system.SelectSingleNode("idle");
                config.idle = new Content();
                string idletype = idle.Attributes["type"].Value;
                if (idletype.Equals("video")) { config.idle.type = ContentType.video; }
                if (idletype.Equals("powerpoint")) { config.idle.type = ContentType.powerpoint; }
                config.idle.file = idle.Attributes["src"].Value;
                config.idle.duration = int.Parse(idle.Attributes["duration"].Value);

                XmlNode sleep = system.SelectSingleNode("sleep");
                config.sleep = new Sleep();
                config.sleep.timespan.startTime = DateTime.Parse(sleep.Attributes["starttime"].Value);
                config.sleep.timespan.endTime = DateTime.Parse(sleep.Attributes["endtime"].Value);
                config.sleep.enable = sleep.Attributes["enable"].Value == "0" ? false : true;

                XmlNode notice = system.SelectSingleNode("notice");
                config.notice.bold = notice.Attributes["bold"].Value == "0" ? false : true;
                config.notice.color = Color.FromName(notice.Attributes["color"].Value);
                config.notice.bgcolor = Color.FromName(notice.Attributes["bgcolor"].Value);
                config.notice.font = notice.Attributes["fontname"].Value;
                config.notice.size = int.Parse(notice.Attributes["size"].Value);
                config.notice.interval = int.Parse(notice.Attributes["speed"].Value);

                XmlNode intermedia = system.SelectSingleNode("intermedia");
                config.intermedia.enable = intermedia.Attributes["enable"].Value == "0" ? false : true;
                config.intermedia.limit = int.Parse(intermedia.Attributes["limit"].Value);
                config.intermedia.duration = int.Parse(intermedia.Attributes["duration"].Value);
                if(config.intermedia.contents == null) config.intermedia.contents = new List<Content>();
                /*DirectoryInfo d = new DirectoryInfo(intermedia.Attributes["root"].Value);
                if (d.Exists)
                {
                    foreach (FileInfo file in d.GetFiles())
                    {
                        Content content = new Content();
                        if (file.Extension.Contains("ppt")) { content.type = ContentType.powerpoint; }
                        else { content.type = ContentType.video; }
                        content.duration = config.intermedia.duration;
                        content.file = file.FullName;
                        config.intermedia.contents.Add(content);
                    }
                }*/

                XmlNode syscfg = system.SelectSingleNode("syscfg");
                config.syscfg.sysDuration = syscfg.Attributes["sysduration"].Value == "0" ? false : true;
                config.syscfg.duration = int.Parse(syscfg.Attributes["duration"].Value);

                XmlNodeList root = system.SelectNodes("period");
                config.datesheets = new List<DateSheet>();
                foreach (XmlNode period in root)
                {
                    DateSheet datesheets = new DateSheet();

                    datesheets.startDate = DateTime.Parse(period.Attributes["startdate"].Value);
                    datesheets.endDate = DateTime.Parse(period.Attributes["enddate"].Value + " 23:59:59");

                    datesheets.Mon = period.Attributes["mon"].Value.Equals("1") ? true : false;
                    datesheets.Tue = period.Attributes["tue"].Value.Equals("1") ? true : false;
                    datesheets.Wed = period.Attributes["wed"].Value.Equals("1") ? true : false;
                    datesheets.Thu = period.Attributes["thu"].Value.Equals("1") ? true : false;
                    datesheets.Fri = period.Attributes["fri"].Value.Equals("1") ? true : false;
                    datesheets.Sat = period.Attributes["sat"].Value.Equals("1") ? true : false;
                    datesheets.Sun = period.Attributes["sun"].Value.Equals("1") ? true : false;
                    datesheets.timesheets = new List<TimeSheet>();

                    XmlNodeList timelist = period.ChildNodes;
                    foreach (XmlNode timewindow in timelist)
                    {
                        TimeSheet timesheets = new TimeSheet();
                        timesheets.startTime = DateTime.Parse(timewindow.Attributes["starttime"].Value);
                        timesheets.endTime = DateTime.Parse(timewindow.Attributes["endtime"].Value);
                        string mode = timewindow.Attributes["mode"].Value;
                        if (mode.Equals("sequencial")) { timesheets.mode = PlayMode.sequencial; }
                        if (mode.Equals("random")) { timesheets.mode = PlayMode.random; }
                        timesheets.contents = new List<Content>();

                        XmlNodeList itemlist = timewindow.ChildNodes;
                        foreach (XmlNode item in timewindow)
                        {
                            string type = item.Attributes["type"].Value;
                            if (type.Equals("dir") && expendDir)
                            {
                                DirectoryInfo dir = new DirectoryInfo(item.Attributes["src"].Value);
                                foreach (FileInfo file in dir.GetFiles())
                                {
                                    Content content = new Content();
                                    if (file.Extension.Contains("ppt")) { content.type = ContentType.powerpoint; }
                                    else { content.type = ContentType.video; }
                                    content.duration = int.Parse(item.Attributes["duration"].Value);
                                    content.file = file.FullName;
                                    timesheets.contents.Add(content);
                                }
                            }
                            else
                            {
                                Content content = new Content();
                                content.duration = int.Parse(item.Attributes["duration"].Value);
                                content.file = item.Attributes["src"].Value;
                                if (type.Equals("dir")) { content.type = ContentType.dir; }
                                if (type.Equals("video")) { content.type = ContentType.video; }
                                if (type.Equals("powerpoint")) { content.type = ContentType.powerpoint; }
                                timesheets.contents.Add(content);
                            }
                        }
                        datesheets.timesheets.Add(timesheets);
                    }
                    config.datesheets.Add(datesheets);
                }

                LogXML("log file read successfully: \"" + path + "\"");

                return true;
            }
            catch (Exception e)
            {
                LogXML(e.Message);
                error = e.Message;
                return false;
            }
        }