示例#1
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(@"..\..\OrdersList.xml");
                //doc.Load(@"..\..\OrdersList.xml");

                XPathNavigator nav = doc.CreateNavigator();
                nav.MoveToRoot();

                XslCompiledTransform xt = new XslCompiledTransform();
                xt.Load(@"..\..\OrdersList.xslt");

                FileStream    outFileStream = File.OpenWrite(@"..\..\OrdersList.html");
                XmlTextWriter writer        =
                    new XmlTextWriter(outFileStream, System.Text.Encoding.UTF8);
                xt.Transform(nav, null, writer);

                outFileStream.Close();
            }
            catch (XmlException ex)
            {
                ErrorInput form = new ErrorInput("XML Exception:" + ex.ToString());
                form.Show();
            }
            catch (XsltException ex)
            {
                ErrorInput form = new ErrorInput("XSLT Exception:" + ex.ToString());
                form.Show();
            }
        }
示例#2
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         string date     = DateTime.Now.ToString("yyyyMMdd");
         string pattern1 = date + "[0-9]{3}";
         string pattern2 = "[0-9]{11}";
         if (!Regex.IsMatch(textBox3.Text, pattern1))
         {
             var ex0 = new MyException(MyException.exception[0]);
             throw ex0;
         }
         if (!Regex.IsMatch(textBox1.Text, "^[a-zA-Z]+"))
         {
             var ex1 = new MyException(MyException.exception[1]);
             throw ex1;
         }
         if (!Regex.IsMatch(textBox4.Text, pattern2))
         {
             var ex2 = new MyException(MyException.exception[2]);
             throw ex2;
         }
         Order od = new Order(textBox3.Text, textBox1.Text, textBox4.Text);
         if (checkBox3.Checked)
         {
             od.AddDetails(new OrderDetails(1, new Goods("apple", 5.59), int.Parse(numericUpDown3.Text)));
         }
         if (checkBox2.Checked)
         {
             od.AddDetails(new OrderDetails(2, new Goods("eggs", 4.99), int.Parse(numericUpDown2.Text)));
         }
         if (checkBox1.Checked)
         {
             od.AddDetails(new OrderDetails(3, new Goods("milk", 69.9), int.Parse(numericUpDown1.Text)));
         }
         Form1.orders.Add(od);
         textBox2.Text = od.SumReal.ToString("0.00");
     }catch (MyException ex)
     {
         ErrorInput form = new ErrorInput(ex.Message);
         form.Show();
     }
 }