예제 #1
0
        public Form3()
        {
            InitializeComponent();
            //counter =  counter.ReadFromFile();
            //string str ;
            //str = counter.ReadTextFile();
            //counter = counter.ConvertToCounter(str);
            buttonClose.Enabled   = false;
            buttonProceed.Enabled = false;
            jlist.LoadXmlFile("Joke.xml");
            arrayList         = jlist.JokeList();
            jokeText          = ReturnJooke(arrayList);
            Text              = "Показ шутки " + jokeText.Name;
            richTextBox1.Text = jokeText.Text;

            //foreach (JokeText jt in jokeText.JokeTextArL)
            //{
            //    richTextBox1.Text = jt.Text;
            //    Thread.Sleep(5000);
            //}
            //for (int i = 0; i < jokeText.JokeTextArL.Count; i++)
            //{
            //    int k = random.Next(jokeText.JokeTextArL.Count);
            //    JokeText jokeText in jokeText.JokeTextArL[k];

            //    jokeText.JokeTextArL.RemoveAt(k);
            //}
        }
예제 #2
0
        public Form3()
        {
            InitializeComponent();
            //counter =  counter.ReadFromFile();
            //string str ;
            //str = counter.ReadTextFile();
            //counter = counter.ConvertToCounter(str);
            buttonClose.Enabled = false;
            buttonProceed.Enabled = false;
            jlist.LoadXmlFile("Joke.xml");
            arrayList = jlist.JokeList();
            jokeText = ReturnJooke(arrayList);
            Text = "Показ шутки " + jokeText.Name;
            richTextBox1.Text = jokeText.Text;

            //foreach (JokeText jt in jokeText.JokeTextArL)
            //{
            //    richTextBox1.Text = jt.Text;
            //    Thread.Sleep(5000);
            //}   
            //for (int i = 0; i < jokeText.JokeTextArL.Count; i++)
            //{
            //    int k = random.Next(jokeText.JokeTextArL.Count);
            //    JokeText jokeText in jokeText.JokeTextArL[k];
              
            //    jokeText.JokeTextArL.RemoveAt(k);
            //}
        }
예제 #3
0
        private void Write()
        {
            //FileStream fileStream = new FileStream("Joke.xml",FileMode.Open,FileAccess.Write);

            //XmlSerializer serializer = new XmlSerializer(typeof(JokeList));
            //TextWriter textWriter = new StreamWriter("Joke.xml");
            //serializer.Serialize(textWriter, myList);
            //textWriter.Close();
            XmlTextWriter writer = null;

            try
            {
                writer            = new XmlTextWriter("joke.xml", System.Text.Encoding.Default);
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement("Jokes");
                for (int i = 0; i < jokeText.JokeTextArL.Count; i++)
                {
                    JokeText joke = new JokeText();
                    joke = (JokeText)jokeText.JokeTextArL[i];
                    writer.WriteStartElement("Joke");
                    writer.WriteElementString("Title", joke.Name);
                    writer.WriteElementString("Content", joke.Text);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
예제 #4
0
        private void показатьШуткуToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _joke.JokeTextArL = _jl.JokeList();
            ArrayList arrayList = new ArrayList();

            arrayList = _jl.JokeList();
            if (arrayList.Count != 0)
            {
                //for (int i = 0; i < arrayList.Count; i++)
                //{
                int k = _rand.Next(arrayList.Count);
                _joke = (JokeText)arrayList[k];
                DialogResult dialogResult = MessageBox.Show(_joke.Text, _joke.Name,
                                                            MessageBoxButtons.YesNo, MessageBoxIcon.None);
                if (dialogResult == DialogResult.Yes)
                {
                    _counter.Yes++;
                    _counter.WriteToFile(_counter);
                }
                else
                {
                    _counter.No++;
                    _counter.WriteToFile(_counter);
                }
                arrayList.RemoveAt(k);
                //}
            }
            else
            {
                MessageBox.Show("Вы все просмотрели", "Шутки закончились",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #5
0
 private JokeText ReturnJooke(ArrayList arrayList)
 {
     JokeText jok = new JokeText();
     //for (int i = 0; i < arrayList.Count; i++)
     //{
         int k = random.Next(arrayList.Count);
         jok = (JokeText) arrayList[k];
         arrayList.RemoveAt(k);
     //    break;
     //}
     return jok;
 }
예제 #6
0
        private JokeText ReturnJooke(ArrayList arrayList)
        {
            JokeText jok = new JokeText();
            //for (int i = 0; i < arrayList.Count; i++)
            //{
            int k = random.Next(arrayList.Count);

            jok = (JokeText)arrayList[k];
            arrayList.RemoveAt(k);
            //    break;
            //}
            return(jok);
        }
예제 #7
0
 private void buttonProceed_Click(object sender, EventArgs e)
 {
     buttonYes.Enabled = true;
     buttonNo.Enabled  = true;
     if (arrayList.Count != 0)
     {
         jokeText          = ReturnJooke(arrayList);
         Text              = "Показ шутки " + jokeText.Name;
         richTextBox1.Text = jokeText.Text;
     }
     else
     {
         Text = "Показ шутки " + "Шутки закончились";
         richTextBox1.Text   = "Вы все просмотрели";
         buttonClose.Enabled = true;
         buttonYes.Enabled   = false;
         buttonNo.Enabled    = false;
     }
     buttonProceed.Enabled = false;
 }
예제 #8
0
        public void LoadXmlFile(string nameFile)
        {
            XElement list = XElement.Load(nameFile);

            IEnumerable<XElement> title =
                from element in list
                    .Elements("Joke")
                    .Elements("Title")
                select element;

            IEnumerable<XElement> content =
                from element in list
                    .Elements("Joke")
                    .Elements("Content")
                select element;

            for (int i = 0; i < title.Count(); i++)
            {
                JokeText jokeText = new JokeText(title.ElementAt(i).Value,content.ElementAt(i).Value);
                jokeList.Add(jokeText);
            }
        }
예제 #9
0
        public void LoadXmlFile(string nameFile)
        {
            XElement list = XElement.Load(nameFile);

            IEnumerable <XElement> title =
                from element in list
                .Elements("Joke")
                .Elements("Title")
                select element;

            IEnumerable <XElement> content =
                from element in list
                .Elements("Joke")
                .Elements("Content")
                select element;

            for (int i = 0; i < title.Count(); i++)
            {
                JokeText jokeText = new JokeText(title.ElementAt(i).Value, content.ElementAt(i).Value);
                jokeList.Add(jokeText);
            }
        }
예제 #10
0
 private void buttonProceed_Click(object sender, EventArgs e)
 {
     buttonYes.Enabled = true;
     buttonNo.Enabled = true;
    if(arrayList.Count != 0)
    {
        jokeText = ReturnJooke(arrayList);
        Text = "Показ шутки " + jokeText.Name;
        richTextBox1.Text = jokeText.Text;
    }
    else
    {
        Text = "Показ шутки " + "Шутки закончились";
        richTextBox1.Text = "Вы все просмотрели";
        buttonClose.Enabled = true;
        buttonYes.Enabled = false;
        buttonNo.Enabled = false;
    }
    buttonProceed.Enabled = false;
 }
예제 #11
0
 private void показатьШуткуToolStripMenuItem_Click(object sender, EventArgs e)
 {
    
     _joke.JokeTextArL = _jl.JokeList();
     ArrayList arrayList = new ArrayList();
     arrayList = _jl.JokeList();
     if (arrayList.Count != 0)
     {
         //for (int i = 0; i < arrayList.Count; i++)
         //{
             int k = _rand.Next(arrayList.Count);
             _joke = (JokeText) arrayList[k];
             DialogResult dialogResult = MessageBox.Show(_joke.Text, _joke.Name,
                                                         MessageBoxButtons.YesNo, MessageBoxIcon.None);
             if (dialogResult == DialogResult.Yes)
             {
                 _counter.Yes++;
                 _counter.WriteToFile(_counter);
             }
             else
             {
                 _counter.No++;
                 _counter.WriteToFile(_counter);
             }
             arrayList.RemoveAt(k);
         //}
     }
     else
     {
         MessageBox.Show("Вы все просмотрели", "Шутки закончились",
             MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
    
 }