Tuesday, 17 October 2017

How to make KBC game in C# (part-2/5)

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.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace kbc
{
    public partial class QUIZ : Form
    {

        int[] x = new int[15];
        int p = 0;
        string ansfromdb, ansselect;
        returnclass rc = new returnclass();
        int score = 0,qid;
        private string connstring = ConfigurationManager.ConnectionStrings["kbc"].ConnectionString;

        public QUIZ()
        {
            InitializeComponent();
        }

        private void QUIZ_Load(object sender, EventArgs e)
        {
           // label2.Text = startgame.NAME;

            Random r = new Random();
           qid= r.Next(3, 17);
           x[p] = qid;
       

            displayquestion(qid);
         






        }

        private void label3_Click(object sender, EventArgs e)
        {
       
          ansselect = label3.Text;
          if (ansselect.Equals(ansfromdb))
          {
              MessageBox.Show("correct ans!");
              qid++;
              displayquestion(qid);
          l1:
              Random r = new Random();
              int s = r.Next(1, 17);

           bool c= search(x, s);

           if (c==true)
           {
               goto l1;
           }
           else
           {

               p++;
               qid = s;
               x[p] = qid;
               displayquestion(qid);

           }








          }

          else
          {
              MessageBox.Show("game over");


          }





        }

        private void label4_Click(object sender, EventArgs e)
        {
            ansselect = label4.Text;
            if (ansselect.Equals(ansfromdb))
            {
                MessageBox.Show("correct ans!");
                qid++;
                displayquestion(qid);
            l1:
                Random r = new Random();
                int s = r.Next(1, 17);

                bool c = search(x, s);

                if (c == true)
                {
                    goto l1;
                }
                else
                {

                    p++;
                    qid = s;
                    x[p] = qid;
                    displayquestion(qid);

                }








            }

            else
            {
                MessageBox.Show("game over");


            }

        }

        private void label5_Click(object sender, EventArgs e)
        {
            ansselect = label5.Text;
            if (ansselect.Equals(ansfromdb))
            {
                MessageBox.Show("correct ans!");
                qid++;
                displayquestion(qid);
            l1:
                Random r = new Random();
                int s = r.Next(1, 17);

                bool c = search(x, s);

                if (c == true)
                {
                    goto l1;
                }
                else
                {

                    p++;
                    qid = s;
                    x[p] = qid;
                    displayquestion(qid);

                }








            }

            else
            {
                MessageBox.Show("game over");


            }

        }

        private void label6_Click(object sender, EventArgs e)
        {
            ansselect = label6.Text;
            if (ansselect.Equals(ansfromdb))
            {
                MessageBox.Show("correct ans!");
                qid++;
                displayquestion(qid);
            l1:
                Random r = new Random();
                int s = r.Next(1, 17);

                bool c = search(x, s);

                if (c == true)
                {
                    goto l1;
                }
                else
                {

                    p++;
                    qid = s;
                    x[p] = qid;
                    displayquestion(qid);

                }








            }

            else
            {
                MessageBox.Show("game over");


            }



        }


        public void displayquestion(int q_id)
        {

            string sql = "select q_question,q_opA,q_opB,q_opC,q_opD,q_opcORRECT from questions where q_id=" + q_id;
            SqlConnection connection = new SqlConnection(connstring);
            try
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand(sql, connection);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    label1.Text = reader.GetValue(0).ToString(); //question
                    label3.Text = reader.GetValue(1).ToString(); //opa
                    label4.Text = reader.GetValue(2).ToString();//opb
                    label5.Text = reader.GetValue(3).ToString();//opc
                    label6.Text = reader.GetValue(4).ToString();//opd
                    ansfromdb = reader.GetValue(5).ToString();//correct option.........

                }
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Errro 202");
            }
       
       
       
       
       
        } //method ends....................


        public static bool search(int[] x, int s)
        {
            bool c = false;
            for (int i = 0; i < x.Length; i++)
            {
                if (s == x[i])
                {

                    c = true;
                    break;
                }

            }

            return c;


        } //function of searching.....................




    }
}

Saturday, 14 October 2017

how to change progress bar color

public NewProgressBar()
    {
        this.SetStyle(ControlStyles.UserPaint, true);
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        Rectangle rec = e.ClipRectangle;

        rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4;
        if(ProgressBarRenderer.IsSupported)
           ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle);
        rec.Height = rec.Height - 4;
        e.Graphics.FillRectangle(Brushes.Red, 2, 2, rec.Width, rec.Height);
    }

Friday, 13 October 2017

How to make simple and easy Services page of a E-Commerce website in 15 minutes

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>About Us</title>
<link href="../css/style.css" rel="stylesheet"  type="text/css"/>

<style>

 table td p
{ font-family:"Comic Sans MS", cursive;
}

td
{
padding:20px;
}
td:hover
{ background-color:rgb(255,190,0);
border:2px solid rgb(255,190,0);
color:white;
}



 </style>

</head>

<body>

<div id="warpper">

<header>

<div style="width:50%;height:200px;float:left">

<img src="../img/logo.png" style="width:250px;height:190px;">



 </div>
<div style="width:50%;height:200px;float:left">
<img src="../img/logo2.png" style="width:250px;height:190px;">

</div>


 </header>

<nav>
<ul>

<li> <a href="../index.html">HOME </a> </li>

<li> <a href="service.html">SERVICE </a> </li>

<li> <a href="about us.html">ABOUT </a> </li>

<li> <a href="contact.html">CONTACT</a> </li>

<li> <a href="gallery.html">GALLERY</a> </li>


</ul>


</nav>



<section style="min-height:500px;margin:0">

<div style="background-color:rgb(2,173,193);width:100%;height:70px; margin:0;">
<br>
<h1 style=" color:white;margin-top:0px; margin-left:20px;"> Services |
<span style="font-size:16px" >
Take A Look What We love To  Do </span>
</h1>


 </div>


<table ">

<tr>
<td>
<img src="../img/html-5-icon.png" style="width:100px;height:100px; margin-left:120px"/>

<h3 style="text-align:center">Latest Technology</h3>
<p style="text-align:center">
Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.
</p>
</td>



<td>
<img src="../img/activity_grid21600.png" style="width:100px;height:100px; margin-left:120px"/>

<h3 style="text-align:center">Latest Technology</h3>
<p style="text-align:center">
Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.
</p>
</td>



<td>
<img src="../img/Document-icon.png" style="width:100px;height:100px; margin-left:120px"/>

<h3 style="text-align:center">Latest Technology</h3>
<p style="text-align:center">
Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.
</p>
</td>


</tr>







<tr>
<td>
<img src="../img/iPhone-White-Apple-icon.png" style="width:100px;height:100px; margin-left:120px"/>

<h3 style="text-align:center">Latest Technology</h3>
<p style="text-align:center">
Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.
</p>
</td>



<td>
<img src="../img/wheels-icon.png" style="width:100px;height:100px; margin-left:120px"/>

<h3 style="text-align:center">Latest Technology</h3>
<p style="text-align:center">
Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.
</p>
</td>



<td>
<img src="../img/Eye-icon.png" style="width:100px;height:100px; margin-left:120px"/>

<h3 style="text-align:center">Latest Technology</h3>
<p style="text-align:center">
Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.
</p>
</td>


</tr>




</table>

 </section>


<footer>
<br>


<p style="text-align:center; ">Made by : Salmanmasood </p>
</footer>




</div>


</body>
</html>

Thursday, 12 October 2017

Progress Bar in C#

  private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            int sum = 0;
            for (int i = 1; i <= 100; i++)
            {
                Thread.Sleep(100);
                sum = sum + i;
                // Calling ReportProgress() method raises ProgressChanged event
                // To this method pass the percentage of processing that is complete
                backgroundWorker1.ReportProgress(i);
                if (i == 100)
                {
                   
               
                    e.Cancel = true;
                    // Reset progress percentage to ZERO and return
                    backgroundWorker1.ReportProgress(100);
                 
                    return;

               
                 
                }

                // Check if the cancellation is requested
                if (backgroundWorker1.CancellationPending)
                {
                    // Set Cancel property of DoWorkEventArgs object to true
                    e.Cancel = true;
                    // Reset progress percentage to ZERO and return
                    backgroundWorker1.ReportProgress(0);
                    return;
                }
            }
        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
            label1.Text = e.ProgressPercentage.ToString() + "%";

        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                label1.Text = "Processing cancelled";
                f.Show();


            }
            else if (e.Error != null)
            {
                label1.Text = e.Error.Message;
            }
            else
            {
                label1.Text = e.Result.ToString();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if (!backgroundWorker1.IsBusy)
            {
                // This method will start the execution asynchronously in the background
                backgroundWorker1.RunWorkerAsync();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!backgroundWorker1.IsBusy)
            {
                // This method will start the execution asynchronously in the background
                backgroundWorker1.RunWorkerAsync();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (backgroundWorker1.IsBusy)
            {
                // Cancel the asynchronous operation if still in progress
                backgroundWorker1.CancelAsync();
            }
        }

one to many relationship in sql

create table department ( dept_id int identity primary key, dept_name nvarchar(20) not null ) insert into department values('CS') insert into department values('MATHS') insert into department values('PHYSICS') insert into department values('CHEMISTRY') insert into department values('GEOLOGY') SELECT * FROM department create table TEACHERS ( T_id int identity primary key, T_name nvarchar(20) not null ) INSERT INTO TEACHERS VALUES('SALMAN') INSERT INTO TEACHERS VALUES('ALI') INSERT INTO TEACHERS VALUES('AHSAN') INSERT INTO TEACHERS VALUES('AHMED') INSERT INTO TEACHERS VALUES('BILAL') INSERT INTO TEACHERS VALUES('ZOHAIB') INSERT INTO TEACHERS VALUES('SANA') INSERT INTO TEACHERS VALUES('KHALID') INSERT INTO TEACHERS VALUES('KHIZRA') INSERT INTO TEACHERS VALUES('SAMI') INSERT INTO TEACHERS VALUES('UZAIR') INSERT INTO TEACHERS VALUES('RAZA') INSERT INTO TEACHERS VALUES('YASIR') SELECT * FROM TEACHERS CREATE TABLE T_D_RECROD ( S_ID INT IDENTITY PRIMARY KEY, FK_T INT unique FOREIGN KEY REFERENCES TEACHERS(T_id), FK_d INT FOREIGN KEY REFERENCES department(dept_id) ) insert into T_D_RECROD values(1,1) insert into T_D_RECROD values(3,1) insert into T_D_RECROD values(5,1) insert into T_D_RECROD values(7,1) insert into T_D_RECROD values(9,1) insert into T_D_RECROD values(11,1) insert into T_D_RECROD values(2,3) insert into T_D_RECROD values(4,4) insert into T_D_RECROD values(6,2) insert into T_D_RECROD values(8,3) insert into T_D_RECROD values(12,1) select t.T_id,t.T_name,d.dept_id,d.dept_name from T_D_RECROD r inner join TEACHERS t on t.T_id=r.FK_T inner join department d on d.dept_id=r.FK_d

Wednesday, 11 October 2017

Gallery page and linking other pages

Html code:





<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>About Us</title>
<link href="../css/style.css" rel="stylesheet"  type="text/css"/>

<style>

img:hover
{ border:2px solid red;
opacity:0.4;


}

</style>
</head>

<body>

<div id="warpper">

<header>

<div style="width:50%;height:200px;float:left">

<img src="../img/logo.png" style="width:250px;height:190px;">



 </div>
<div style="width:50%;height:200px;float:left">
<img src="../img/logo2.png" style="width:250px;height:190px;">

</div>


 </header>

<nav>
<ul>

<li> <a href="../index.html">HOME </a> </li>

<li> <a href="service.html">SERVICE </a> </li>

<li> <a href="about us.html">ABOUT </a> </li>

<li> <a href="contact.html">CONTACT</a> </li>

<li> <a href="gallery.html">GALLERY</a> </li>


</ul>


</nav>



<section style=" height:auto">


<div style="width:90%;background-color:#FFF; margin:0 auto;margin-top:20px;">
<a href="../img/g1.jpg" target="new">
<img src="../img/g1.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>

</a>


<img src="../img/g2.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g3.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g4.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g5.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>

<br><br>


<img src="../img/g6.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g7.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g8.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g9.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g10.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>

<br><br>

<img src="../img/g1.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g2.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g3.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g4.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g5.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>

<br><br>


<img src="../img/g6.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g7.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g8.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g9.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>
<img src="../img/g10.jpg" width="200px" height="200px" style=" border-radius:20px 50px 20px 50px; box-shadow:5px 5px 5px 5px #0033FF"/>







</div>









 </section>

<br><br>
<footer>
<br>


<p style="text-align:center;">Made by : Salmanmasood </p>
</footer>




</div>


</body>
</html>

Contact Us form in html and styling navigation bar

html  code:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>About Us</title>
<link href="../css/style.css" rel="stylesheet"  type="text/css"/> 



<script
src="http://maps.googleapis.com/maps/api/js">
</script>
<script>
function initialize() {
  var mapProp = {
    center:new google.maps.LatLng(24.9273208  , 67.0330662),
    zoom:15,
    mapTypeId:google.maps.MapTypeId.ROADMAP
  };
  var map=new google.maps.Map(document.getElementById("maps"), mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />







<style>

#maps
{ background-color:#666;
width:70%;
height:500px;
float:left;
}
#forms
{background-color:#093;
width:30%;
height:500px;
float:left;
color:#fff;
}

form
{

width: 100%;
height:100%;
background-color:rgb(2,173,193);
font-style:italic;
font-weight:bold;


}
TD{
 padding:20PX;}








 </style>


</head>

<body>

<div id="warpper"> 

<header>

<div style="width:50%;height:200px;float:left">

<img src="../img/logo.png" style="width:250px;height:190px;">



 </div>
<div style="width:50%;height:200px;float:left"> 
<img src="../img/logo2.png" style="width:250px;height:190px;">

</div>


 </header>

<nav> 
<ul> 

<li> <a href="../index.html">HOME </a> </li>

<li> <a href="service.html">SERVICE </a> </li>

<li> <a href="about us.html">ABOUT </a> </li>

<li> <a href="contact.html">CONTACT</a> </li>

<li> <a href="gallery.html">GALLERY</a> </li>


</ul>


</nav>



<section style="min-height:500px;background-color:red">

<div id="forms">


<form>
<br>
<br>

<table>

<tr> 
<td> User Name: </td>

<td>
<input type="text" size="15"  required="required" maxlength="10"/>

 </td>
 </tr>

<tr> 
<td> Password: </td>
<td> <input type="password" size="15"  required="required"/>  </td>
 </tr>


<tr> 
<td> Gender: </td>
<td>
<input type="radio"value="male" name="gender"/>Male <input type="radio" value="Female" name="gender"/>Female
 </td>

 </tr>


<tr>

<td>Education </td>
<td>
<input type="checkbox"  name="EDU" value="SSC"/>SSC
<input type="checkbox"  name="EDU" value="HSC"/>HSC
<input type="checkbox"  name="EDU" value="GRADUATION"/>GRAD
   </td>

</tr>




<TR>

<TD> City: </TD>
<TD>
<select>
<option value="khi">Karachi</option>
<option value="lhr">Lahore</option>
<option value="isb">Islamabad</option>
<option value="MUL">Multan </option>

</select>

</TD>

</TR>

<tr>

<td>Upload Resume: </td>
<td> <input type="file"/>  </td>

</tr>


<tr>

<td> </td>
<td><button> Submit!</button> </td>

</tr>


</table>



</form>




 </div>

<div id="maps">

<iframe width="450px" height="450px" src="https://www.google.com/maps/place/Aptech+Computer+Education+North+Karachi+Center/@24.9787237,67.0596737,17z/data=!3m1!4b1!4m5!3m4!1s0x3eb340e584b891c3:0x29b2cbc198ba2dbd!8m2!3d24.9787237!4d67.0618624"> </iframe> 




 </div>



 </section>


<footer> 
<br>


<p style="text-align:center; ">Made by : Salmanmasood </p>
</footer>




</div>


</body>
</html>

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...