读取年份数组中的所有周六周天

第二次写随笔,并不是多么强大的功能,只是帮助自己记录一下一些完成的东西,以便后面使用。

前台按钮打印xml:

 <input type="button" value="生成日期xml" οnclick="AddXML()"/>

 function AddXML() {
            $.ajax({
                type:"POST",
                url:"/XMLManage/CreatXML.aspx?Option=ADDXML",
                data: {},
                success: function() {
                    
                }
            });
        }

后台完成xml的创建和写入:

 public void AddXml()
        {
            XmlDocument xmldoc=new XmlDocument();
            XmlDeclaration xmldec = xmldoc.CreateXmlDeclaration("1.0", "GB2312", null);
            xmldoc.AppendChild(xmldec);
            XmlElement root = xmldoc.CreateElement("非工作日设置");
            xmldoc.AppendChild(root);
            XmlElement node = xmldoc.CreateElement("日期");
            node.SetAttribute("name", "notworkday");
            node.SetAttribute("id", "notworkday");
            List<string> DateList=new List<string>();
            DateList.Add("2015-01-01");
            DateList.Add("2016-01-01");
            DateList.Add("2017-01-01");
            //DateTime dt = DateTime.Parse("2015-01-01");
            for (int i = 0; i < DateList.Count; i++)
            {
                DateTime dt = DateTime.Parse(DateList[i]);
                while (dt.Year == DateTime.Parse(DateList[i].ToString()).Year)
                {
                    if (dt.DayOfWeek == DayOfWeek.Saturday)
                    {
                        var times = dt.Date.ToString("yyyy-MM-dd");
                        XmlElement element = xmldoc.CreateElement("非工作日");
                        element.SetAttribute("name", times);
                        element.SetAttribute("id", times);
                        node.AppendChild(element);
                    }
                    if (dt.DayOfWeek == DayOfWeek.Sunday)
                    {
                        var times = dt.Date.ToString("yyyy-MM-dd");
                        XmlElement element = xmldoc.CreateElement("非工作日");
                        element.SetAttribute("name", times);
                        element.SetAttribute("id", times);
                        node.AppendChild(element);
                    }
                    dt = dt.AddDays(1);
                    
                }
            }
            root.AppendChild(node);
            xmldoc.Save(@"E:\heheheh.xml");
        }

转载于:https://www.cnblogs.com/whm-163/p/5111035.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值