Friday, 21 February 2014

TIC TAC TOE

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int count = 1;


        private void btnall(object sender, EventArgs e)
        {
            Button b = (Button)sender;
           
           b.Text= (count % 2 == 0) ? "O" : "X";
         
           // if (count % 2 == 0)
           //{
           //    //b.BackColor = Color.Red;
           //    b.ForeColor = Color.Red;
             
           //}
           //else
           //{
           //    b.BackColor = Color.Blue;
           //}
           b.Enabled = false;
           count++;
            check();
        }


        void check()
        {
            if (button1.Text == button2.Text && button2.Text == button3.Text && button1.Text != "")
            {
                result(button1.Text);
            }
             if (button1.Text == button4.Text && button4.Text == button7.Text && button1.Text != "")
            {
                result(button1.Text);
            }
             if (button4.Text == button5.Text && button5.Text == button6.Text && button4.Text != "")
            {
                result(button4.Text);
            }
             if (button7.Text == button8.Text && button8.Text == button9.Text && button7.Text != "")
            {
                result(button7.Text);
            }
             if (button2.Text == button5.Text && button5.Text == button8.Text && button2.Text != "")
            {
                result(button2.Text);
            }
             if (button3.Text == button6.Text && button6.Text == button9.Text && button3.Text != "")
            {
                result(button3.Text);
            }
             if (button1.Text == button5.Text && button5.Text == button9.Text && button1.Text != "")
            {
                result(button1.Text);
            }
             if (button3.Text == button5.Text && button5.Text == button7.Text && button3.Text != "")
            {
                result(button3.Text);
            }

        }
        void result( string txt)
        {
            if (txt=="O")
            {
                MessageBox.Show("Second Player Win");
            }
            else
            {
                MessageBox.Show("First Player Win");
            }
           
        }

        private void button10_Click(object sender, EventArgs e)
        {
             reset();
        }
     
        void reset()
        {
            foreach (Button b in this.Controls)
            {
                b.Text = "";
                b.Enabled = true;
                b.BackColor = Control.DefaultBackColor;
                button10.Text = "Reset";
                button11.Text = "Play Again";

            }
            count = 1;
        }

        private void button11_Click(object sender, EventArgs e)
        {
           
            if (MessageBox.Show("Are You Want To Play Again!"," "  , MessageBoxButtons.YesNo) == DialogResult.Yes)

           
            {

                reset();
            }
            else
            {
                Form1 frm = new Form1();
                frm.Focus();

            }
        }



        }
   
}


Tuesday, 11 February 2014

Example Of Array With Sturctue

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public int index;
        public int ch,temp=0;
       
        public Form1()
        {
            InitializeComponent();
        }
       public struct Student
        {
            public int sno;
            public string fname;
            public string lname;
            public DateTime dob;
        }
         Student [] arr=new Student[1];

        private void btnSave_Click(object sender, EventArgs e)
        {
             //Student[] arr = new Student[1];  
            arr[index].sno = Convert.ToInt32(textBox1.Text);
            arr[index].fname = textBox2.Text;
            arr[index].lname = textBox3.Text;
            arr[index].dob = Convert.ToDateTime(textBox4.Text);
            index++;
            Array.Resize(ref arr,index+1);
            textclear();

        }

        private void textclear()
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";


        }

       

        private void btnLast_Click(object sender, EventArgs e)
        {
           // Student[] arr = new Student[1];
            textBox1.Text = arr[index-1].sno.ToString();
            textBox2.Text = arr[index-1].fname;
            textBox3.Text = arr[index-1].lname;
            textBox4.Text = arr[index-1].dob.ToShortDateString();
            temp = index;
        }

        private void btnFirst_Click(object sender, EventArgs e)
        {
            //Student[] arr = new Student[1];
            textBox1.Text = arr[0].sno.ToString();
            textBox2.Text = arr[0].fname;
            textBox3.Text = arr[0].lname;
            textBox4.Text = arr[0].dob.ToShortDateString();
            temp = 0;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            textclear();

        }

        private void btnCLose_Click(object sender, EventArgs e)
        {
            Form.ActiveForm.Close();

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            int i;

           
            //For this right click on project add refrence click on .net and select microsoft visual basic
           int sear= Convert.ToInt32(Microsoft.VisualBasic.Interaction.InputBox("Enter The Sno.To Be Searched"));
       
                for(i=0;i<=arr.Length-1;i++)
                {
                    if(arr[i].sno==sear)
                    {
                        //break;
                        textBox1.Text = arr[i].sno.ToString();
                        textBox2.Text = arr[i].fname;
                        textBox3.Text = arr[i].lname;
                        textBox4.Text = arr[i].dob.ToShortDateString();
                        ch = i;
                        return;

                    }
                   
                }
                MessageBox.Show ("Id Not Found");



           


        }

     

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
           


            arr[ch].sno = Convert.ToInt32(textBox1.Text);
             arr[ch].fname=textBox2.Text ;
             arr[ch].lname=textBox3.Text ;
             arr[ch].dob = Convert.ToDateTime(textBox4.Text);

        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            int i;
           

            //For this right click on project add refrence click on .net and select microsoft visual basic
            int sear = Convert.ToInt32(Microsoft.VisualBasic.Interaction.InputBox("Enter The Sno.To Be Deleted"));

            for (i = 0; i < index; i++)
            {
                if (arr[i].sno == sear)
                {
                    for (int j = i; j <index; j++)
                    {
                        arr[j] = arr[j+1];
                        index--;
                        Array.Resize(ref arr, index + 1);


                       
                    }
                }
            }
           
         




        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (temp < index-1)
            {
                temp++;
                textBox1.Text = arr[temp].sno.ToString();
                textBox2.Text = arr[temp].fname;
                textBox3.Text = arr[temp].lname;
                textBox4.Text=arr[temp].dob.ToShortDateString();
            }
        }

        private void btnPre_Click(object sender, EventArgs e)
        {
            if (temp > 0)
            {
                temp--;
                textBox1.Text = arr[temp].sno.ToString();
                textBox2.Text = arr[temp].fname;
                textBox3.Text = arr[temp].lname;
                textBox4.Text = arr[temp].dob.ToShortDateString();
            }

        }

       


       

       
    }
 
   


}

Friday, 7 February 2014

PHP: "How To Show Images From Database using GET in PHP Without PHP"

<!-- HTML CODE BEIGNS -->

<html>
<head>
<title> Image Showing </title>
</head>
<body>
<a href="ShowImage.php?id=1">IMG1</a>
<a href="ShowImage.php?id=2">IMG2</a>
<a href="ShowImage.php?id=3">IMG3</a>
</body>
</html>

<!-- HTML CODE ENDS -->
------------------------------------------------------------------------------------------------------------
<!-- PHP CODE BEGINS -->

<?php
$id=$_GET[id];
$con=mysqli_connect("localhost","root","","images");
if(mysqli_connect_errno())
{
echo "Failed To Connect"." ".mysqli_connect_errno();
}
$sql="SELECT * FROM Table1 WHERE Id=".$id; // in single qoutes(' ')  string types  values only 
$rs=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($rs))
{
$check=$row[img_name];
}
 
echo "<img src='$check'>";

?>

<!-- PHP CODE ENDS -->