Tuesday, June 24, 2014

C# Learning Web Links

http://www.tutorialspoint.com/csharp/
http://www.learncs.org/
http://www.microsoftvirtualacademy.com/training-courses/c-fundamentals-for-absolute-beginners
http://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners
*****
http://www.homeandlearn.co.uk/csharp/csharp.html
http://www.csharp-station.com/
http://visualcsharptutorials.com/tutorials
https://www.udemy.com/learn-c-sharp-programming-in-ten-easy-steps/
http://www.csharp411.com/category/c/
http://www.learnvisualstudio.net/
http://www.learnvisualstudio.net/free/c-training/
*****
http://www.functionx.com/csharp/
http://www.freewebs.com/campelmxna/tutorials.htm
http://www.codeproject.com/?cat=3
http://msdn.microsoft.com/en-us/library/618ayhy6.aspx

Final Review (CSI-156)



Read and Find number of alphabets

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace Reading_txt_and_cs_files
{
    public partial class Form1 : Form
    {
        List<string> methodNames = new List<string>();

        public Form1()
        {
            InitializeComponent();
        }

        private void btnReadFromFile_Click(object sender, EventArgs e)
        {
            //create an open file dialog
            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Filter = "txt files (*.txt)|*.txt|(*.cs)|*.cs";
            //display it
            DialogResult dr = fdlg.ShowDialog();
            if (dr == DialogResult.OK)
            {
                //get the selected file and display in the
                //textbox (txtFilePath)
                txtFilePath.Text = fdlg.FileName;
            }
        }

        private void btnReadFile_Click(object sender, EventArgs e)
        {
            StreamReader sr = null;
            try
            {
                //1. Open file for reading
                sr = File.OpenText(txtFilePath.Text);

                //2. Read it
                richTextBox1.Clear();
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    richTextBox1.AppendText(line + "\n");
                    string output = CountAllChars(line);
                    richTextBox2.AppendText(output);
                }
            }
            catch (ArgumentException ae)
            {
                MessageBox.Show(ae.Message);
            }
            catch (IOException ioe)
            {
                MessageBox.Show(ioe.Message);
            }
            finally
            {
                //3. close
                if (sr != null)
                    sr.Close();
            }
        }

        static string CountAllChars(string s)
        {
            if (s == null) return null;
            if (s == "") return "";
            s = s.ToLower();
            char[] chars = s.ToCharArray();
            Array.Sort(chars);
            StringBuilder sb = new StringBuilder();
            int count = 0;
            for (int i = 0; i < chars.Length; i++)
            {
                if (chars[i] < 'a' || chars[i] > 'z') continue;
                if (sb.Length == 0)
                {
                    sb = sb.Append(chars[i]);
                    count = 1;
                }
                else if (chars[i] == chars[i - 1])
                {
                    count++;
                }
                else
                {
                    sb = sb.Append(count.ToString());
                    sb = sb.Append("\n" + chars[i]);
                    count = 1;
                }
            }
            sb = sb.Append(count.ToString());
            return sb.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            richTextBox2.Clear();
            int ifcounter = 0;
            int forcounter = 0;
            StreamReader sr = null;
            try
            {
                sr = File.OpenText(txtFilePath.Text);
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    richTextBox2.AppendText(line);
                    foreach (string c in line.Split())
                    {
                        if (c.Contains("if"))
                        {
                            if (true)
                            {
                                ifcounter++;
                            }
                        }
                        if (c.Contains("for"))
                        {
                            forcounter++;
                        }
                    }
                }
                richTextBox1.AppendText("Total if statement: " + ifcounter );
                richTextBox1.AppendText("\n" + "Total for loop " + forcounter );
               
            }
            catch (ArgumentException ae)
            {
                MessageBox.Show(ae.Message);
            }
            catch (IOException ioe)
            {
                MessageBox.Show(ioe.Message);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
        }

    }
}
//======================LAB ASSIGNMENT FOR MONDAY 6/16/14===========
//Write code to read a text file (.txt, .cs, or .java)
//and determine the number of occurrences of each character
//in the alphabet.
//Write code to read a .cs file and determine the number of for loops and if statements it has.
//forums.asp.net/t/1318256.aspx?Find+no+of+occurrence+of+each+character+in+a+string
//forums.asp.net/t/1608521.aspx?How+to+read+all+function+method+names+from+cs+file

Friday, June 6, 2014

Drawing Line with Class


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing; // Add to draw
using System.Threading.Tasks;

Thursday, June 5, 2014

Drawing Rectangular with Mouse


namespace Zau_DrawRectWithMouse
{
    public partial class Form1 : Form
    {
        Bitmap bmap;
        Graphics g;

Using Color Dialog


namespace MouseEvents
{
    public partial class Form1 : Form
    {
        Bitmap bmap;
        Graphics g;
        Point pOne;

Wednesday, June 4, 2014

Draw Line Between Two Points with Mouse


namespace Zau_DrawLine_Btn_Two_Point_wMouse
{
    public partial class Form1 : Form
    {
        Bitmap bmap;

Mouse Event & Draw Line


namespace MouseEvents
{
    public partial class Form1 : Form
    {
        Bitmap bmap;
        Graphics g;

Tuesday, June 3, 2014

Plotting



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Drawing.Drawing2D; //to use matrix