Friday, 22 February 2013

CREATING OF CALCULATOR IN C# .NET


CODE OF CALCULATOR



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 calcuatoerqwe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "1";
            }
            button19.ForeColor = Color.Blue;
            button19.BackColor = Color.Yellow;
          
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "2";
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "3";
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "4";
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "5";
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "6";
            }
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "7";
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "8";
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "9";
            }
        }

        private void button17_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {

                textBox1.Text = textBox1.Text + "0";
            }
        }

        private void button18_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + ".";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //textBox1.Clear();
            textBox1.Text = "";
        }
        double a, b, c;
        int aa;
        private void button12_Click(object sender, EventArgs e)
        {
            a = Convert.ToDouble(textBox1.Text);
            textBox1.Clear();
            aa = 1;
        }

        private void button13_Click(object sender, EventArgs e)
        {
            a = Convert.ToDouble(textBox1.Text);
            textBox1.Clear();
            aa = 2;
        }

        private void button14_Click(object sender, EventArgs e)
        {

            a = Convert.ToDouble(textBox1.Text);
            textBox1.Clear();
            aa = 3;

        }

        private void button15_Click(object sender, EventArgs e)
        {

            a = Convert.ToDouble(textBox1.Text);
            textBox1.Clear();
            aa = 4;
        }

        private void button16_Click(object sender, EventArgs e)
        {
            b = Convert.ToDouble(textBox1.Text);
            textBox1.Clear();

            switch (aa)
            {
                case 1:
                    {
                        c = a + b;
                        textBox1.Text = c.ToString();
                        break;
                    }
                case 2:
                    {
                        c = a - b;
                        textBox1.Text = c.ToString();
                        break;
                    }
                case 3:
                    {
                        c = a * b;
                        textBox1.Text = c.ToString();
                        break;
                    }
                case 4:
                    {
                        c = a / b;
                        textBox1.Text = c.ToString();
                        break;

                    }
            }
        }
  …./// back space

        private void button2_Click(object sender, EventArgs e)
        {
            int a = textBox1.Text.Length;
            string s = textBox1.Text;
            textBox1.Clear();
            for (int i = 0; i < a - 1; i++)
            {
                textBox1.Text = textBox1.Text + s[i].ToString();
            }
        }

        private void button19_Click(object sender, EventArgs e)
        {
            textBox1.ReadOnly = false;
        }

        private void button20_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox1.ReadOnly = true;
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(!char.IsDigit(e.KeyChar))
            {
                e.Handled=true;
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void button21_Click(object sender, EventArgs e)
        {
            a = Convert.ToDouble(textBox1.Text);
            textBox1.Text = Math.Sqrt(a).ToString();
        }

        private void button19_MouseHover(object sender, EventArgs e)
        {
            button19.Text = "please click me";
        }

        private void button19_MouseLeave(object sender, EventArgs e)
        {
            button19.Text = "on";
        }
    }
}



  string s = textBox1.Text;
            int aa = textBox1.Text.Length;
            textBox2.Clear();
            for (int a = aa-1; a >=0; a--)
            {
                textBox2.Text = textBox2.Text + (s[a].ToString());
            }

            if (textBox1.Text == textBox2.Text)
            {
                MessageBox.Show("no. is palindrom");
            }
            else
            {
                MessageBox.Show("no. is not palindrom");
            }

// decimal to binary

  int b, c;
        string j = "";
        string p = "";
        private void button1_Click(object sender, EventArgs e)
        {
            int a = Convert.ToInt32(textBox1.Text);
            while (a > 0)
            {
                b = a % 2;
                c = a / 2;
                a = c;
                j += b.ToString();
               // a--;
            }
            int l = j.Length;
            for(int i=l-1;i>=0;i--)
            {

                p += j[i].ToString();
            }
            textBox2.Text = p.ToString();
          
        }
//Binary to decimal

        private void button2_Click(object sender, EventArgs e)
        {
            double p=0;
            int l = textBox2.Text.Length;
            string s=textBox2.Text;
            for (int i = 0; i < l; i++)
            {
                p += Convert.ToDouble(s[i].ToString()) * Math.Pow(2, Convert.ToDouble(l - (i + 1)));
            }
            textBox3.Text = p.ToString();
        }
    }
}





DATA TYPES OF C# DOT NET


                            
MEMORY ALLOCATION ON COMPILE TIME                               MEMORY ALLOCATION ON RUN TIME
IF FOLLOWS THE STACK (LIFO) TO GIVE MEMORY                       IT FOLLOW HEAP (FIFO)

MEMORY IS NOT PROVIDED TO VARIABLE IT IS PROVIDED TO THE DATA TYPES


                    VALUE TYPE


Predefined C# value types
        
        
        
       short:
        
        Holds 16-bit signed integers. The smallest possible value for a short variable is -32,768; the largest possible value is 32,767.
        
       ushort:
        
        Holds 16-bit unsigned integers. The u in ushort stands for unsigned. The smallest possible value of an ushort variable is 0; the largest possible value is 65,535.
        
       int:
        
       Holds 32-bit signed integers. The smallest possible value of an int variable is -2,147,483,648; the largest possible value is 2,147,483,647.
        

**
       uint:
        
       Holds 32-bit unsigned integers. The u in uint stands for unsigned. The smallest possible value of a uint variable is 0; the largest possible value is 4,294,967,295.
      
*       long:
*        
*        Holds 64-bit signed integers. The smallest possible value of a long variable is -9,223,372,036,854,775,808; the largest possible value is 9,223,372,036,854,775,807.
*        
*       ulong:
*        
*        Holds 64-bit unsigned integers. The u in ulong stands for unsigned. The smallest possible value of a ulong variable is 0; the largest possible value is 18,446,744,073,709,551,615.
*        
*       char:
*        Holds 16-bit Unicode characters. The smallest possible value of a char variable is the Unicode character whose value is 0; the largest possible value is the Unicode character whose value is 65,535.
*        
*       float:
*        
*        Holds a 32-bit signed floating-point value. The smallest possible value of a float type is approximately 1.5 times 10 to the 45th power; the largest possible value is approximately 3.4 times 10 to the 38th power.
*        
*       double:
*        
*        Holds a 64-bit signed floating-point value. The smallest possible value of a double is approximately 5 times 10 to the 324th; the largest possible value is approximately 1.7 times 10 to the 308th.
*        
*        
*       bool:
*        
*       Holds one of two possible values, true or false. The use of the bool type is one of the areas in which C# breaks from its C and C++ heritage. In C and C++, the integer value 0 was synonymous with false, and any nonzero value was synonymous with true. In C#, however, the types are not synonymous. You cannot convert an integer variable into an equivalent bool value. If you want to work with a variable that needs to represent a true or false condition, use a bool variable and not an int variable.


                                       REFERENCE TYPE



*       string:
*        
*       Represents a string of Unicode characters. It allows easy manipulation and assignment of strings. Strings are immutable, meaning that once it is created it can't be modified. So when you try to modify a string, such as concatenating it with another string, a new string object is actually created to hold the new resulting string.
*        
*       object:
*        
*       Represents a general purpose type. In C#, all predefined and user-defined types inherit from the object type or System.Object class.


                        USER DEFINED
1.              CLASS
2.              INTERFACE
3.              DELEGATE


VIDEO PAY ON HTML PAGE

VIDEO PAY ON HTML PAGE.......................................................


<html>
 HTML5 CODING

<title>my vidio</title>
<body>

<video width="320" height="240" controls="controls">
  <source src="E:/HINDI VIDEO SONGS/Tip-Tip-Barsa-Pani.mp4" type="video/mp4" />
  <source src="E:/HINDI VIDEO SONGS/Tip-Tip-Barsa-Pani.ogg" type="video/ogg" />
  Your browser does not support the video tag.
</video>

</body>
</html>

ASP.NET CODING


<object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" id="player" width="320" height="260">


<param name="showcontrols" value="true" />
       

<object type="video/x-ms-wmv" data="Tip-Tip-Barsa-Pani.mp4" width="320" height="260">

<param name="src" value="Tip-Tip-Barsa-Pani.mp4" />

<param name="autostart" value="true" />

<param name="controller" value="true" />

</object>

CONVERT TIME TO WORD

Method of Converting Time to Word...................................


private static readonly string[] fuzzyHours = new string[]
        {
        "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Forteen", "FIFTEEN",
        "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty", "Twenty-One", "Twenty-Two", "Twenty-Three"
        };

..........................................................

public static string TimeToWords(DateTime time)
        {
           
                string result;
                int minutes = time.Minute;
                int hours = time.Hour;
                if (minutes != 0)
                    result = fuzzyHours[hours] + " " + NumberToWords(minutes);
                else
                    result = fuzzyHours[hours] + ((hours != 0) ? " O'Clock" : string.Empty);

                if (hours >= 0 && hours < 12)
                    return result + " am";

                if (hours >= 12)
                    result = result + " pm";

                return result;
           
        }
        public static string NumberToWords(Int32 number)
        {
                if (number == 0)
                    return "zero";

                if (number < 0)
                    return "minus " + NumberToWords(Math.Abs(number));

                string words = "";

                if (number > 0)
                {
                    if (words != "")
                        words += " ";

                    var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
                    var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty" };

                    if (number < 20)
                        words += unitsMap[number];
                    else
                    {
                        words += tensMap[number / 10];
                        if ((number % 10) > 0)
                            words += "-" + unitsMap[number % 10];
                    }
                }


                return words;
           
        }

CONVERT A NUMBER TO WORD

Convert Number To Word.....................................................


 public static string NumberToWords(Int64 number)
        {
                if (number == 0)
                    return "zero";

                if (number < 0)
                    return "minus " + NumberToWords(Math.Abs(number));

                string words = "";

                if ((number / 10000000) > 0)
                {
                    words += NumberToWords(number / 10000000) + " crore ";
                    number %= 10000000;
                }
                if ((number / 100000) > 0)
                {
                    words += NumberToWords(number / 100000) + " lakh ";
                    number %= 100000;
                }

                if ((number / 1000) > 0)
                {
                    words += NumberToWords(number / 1000) + " thousand ";
                    number %= 1000;
                }

                if ((number / 100) > 0)
                {
                    words += NumberToWords(number / 100) + " hundred ";
                    number %= 100;
                }

                if (number > 0)
                {
                    if (words != "")
                        words += " ";

                    var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
                    var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };

                    if (number < 20)
                        words += unitsMap[number];
                    else
                    {
                        words += tensMap[number / 10];
                        if ((number % 10) > 0)
                            words += "-" + unitsMap[number % 10];
                    }
                }

                return words;
           
        }

IMAGE DELETE FROM WEBSITE FOLDER


SqlCommand cmd1 = new SqlCommand("select image from audit where image=@image", con);
        SqlCommand cmd = new SqlCommand("delete from audit where image=@image", con);
        cmd.Parameters.Add("@image", SqlDbType.VarChar).Value = (GridView1.DataKeys[e.RowIndex].Value);
        cmd1.Parameters.Add("@image", SqlDbType.VarChar).Value = (GridView1.DataKeys[e.RowIndex].Value);
       
       
     

     
        con.Open();
       
       
        SqlDataReader dr= cmd1.ExecuteReader();
        dr.Read();
        string s =Server.MapPath(dr[0].ToString());
       
        if (File.Exists(s))
        {
            System.IO.File.Delete(s);
            Response.Write("Deleted");
        }
       
        dr.Close();
        cmd.ExecuteNonQuery();
        con.Close();
        bind();