예제 #1
0
파일: Form1.cs 프로젝트: GuoZi2942/CarTime
        /// <summary>
        /// 保存至xml文件
        /// </summary>
        /// <param name="ct"></param>
        private void saveToXml(CarTime ct)
        {
            //path = System.IO.Directory.GetCurrentDirectory() + "\\CarTime\\Data\\config.xml";

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(path);

            XmlElement n = xmlDoc.CreateElement("CarTime");

            // n.InnerText = DateTime.Now.ToString("yyyy-MM-dd");
            xmlDoc.SelectSingleNode("config").AppendChild(n);

            //添加子级 遍历类的属性
            System.Reflection.PropertyInfo[] properties =
                ct.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            XmlElement cn = null;

            foreach (System.Reflection.PropertyInfo item in properties)
            {
                cn           = xmlDoc.CreateElement(item.Name);
                cn.InnerText = item.GetValue(ct, null).ToString();
                n.AppendChild(cn);
            }
            //保存数据
            xmlDoc.Save(path);

            MessageBox.Show("上传成功");
        }
예제 #2
0
파일: Form1.cs 프로젝트: GuoZi2942/CarTime
        /// <summary>
        /// 上传结果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Upload_Click(object sender, EventArgs e)
        {
            CarTime ct = new CarTime();

            ct.Mypk     = Guid.NewGuid().ToString();
            ct.Lbstart  = lb_Start.SelectedItem.ToString();
            ct.Lbend    = lb_End.SelectedItem.ToString();
            ct.Dtstart  = this.dateTimePicker1.Value.ToString();
            ct.Dtend    = this.dateTimePicker2.Value.ToString();
            ct.Licheng  = this.textBox1.Text;
            ct.Costtime = this.textBox2.Text;
            ct.Jine     = this.textBox3.Text;
            ct.Demo     = this.textBox8.Text;

            saveToXml(ct);
        }