Thursday, 28 September 2017

Dbms Application # 15 (how to find fees Defaulter in recrods/Table Alteration/Removing anamolies)

All important Query



select * from sys.tables
select * from fees

delete from fees where fee_id=2

select * from STUDENT_STATUS


select s.std_id,sa.SA_ID,f.fee_id,s.std_name,sa.sa_year,f.dayx+'/'+f.monthx as PaidDate,f.fee_amount from student s inner join STUDENT_STATUS sa on s.std_id=sa.SA_ST_ID inner join fees f on sa.SA_ID=f.SA_FK_ID where sa.sa_year='2017'


select count(fee_id) from fees where fee_fk_st_id=2 and monthx='9'

delete from STUDENT_STATUS where SA_ID=3


alter table fees
drop column fee_date

modified Storeprocedure

USE [schoolm]
GO
/****** Object:  StoredProcedure [dbo].[insert_tblfees]    Script Date: 9/28/2017 12:03:43 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[insert_tblfees]
(
@fee_amount float ,
@dayx nvarchar(2),
@monthx nvarchar(2),
@fee_fk_st_id int,
@SA_FK_ID INT  

)
as

begin

insert into fees(fee_amount,dayx,monthx,fee_fk_st_id,SA_FK_ID)
values(@fee_amount,@dayx,@monthx,@fee_fk_st_id,@SA_FK_ID)


end

Modified Fees insertion method


        public void insert_FEES(student_status sa,string id)
        {
            SqlConnection conn = new SqlConnection(connstring);
            try
            {
                SqlCommand cmd = new SqlCommand("insert_tblfees", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@fee_amount", SqlDbType.Float).Value = sa.class_fees;
                cmd.Parameters.Add("@dayx", SqlDbType.NVarChar).Value = System.DateTime.Now.Day.ToString();
                cmd.Parameters.Add("@monthx", SqlDbType.NVarChar).Value = System.DateTime.Now.Month.ToString();
                cmd.Parameters.Add("@fee_fk_st_id", SqlDbType.Int).Value =id ;
                cmd.Parameters.Add("@SA_FK_ID", SqlDbType.Int).Value = sa.status_student_id;




                conn.Open();
                cmd.ExecuteNonQuery();


                MessageBox.Show("DATA record has been inserted successfully.....");

            }
            catch (Exception)
            {
                MessageBox.Show("data is not inserted !!!");

            }

            finally
            {
                conn.Close();
            }


        } //method end...........


Fees Submission events code:

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

namespace WindowsFormsApplication4
{
    public partial class feessubmission : Form
    {
        viewclass vc = new viewclass();
        string q;
        private string connstring = ConfigurationManager.ConnectionStrings["TESTDB"].ConnectionString;
        public feessubmission()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection(connstring);
            string sql = "select s.std_id,s.std_name,sa.SA_ID,SA_Class_id,sa.sa_year,c.classname,c.fees  from student s inner join STUDENT_STATUS sa  on sa.SA_ST_ID=s.std_id inner join classes c on c.class_id=sa.SA_Class_id where sa.sa_year='"+System.DateTime.Now.Year+"' and s.std_id="+textBox1.Text;

            try
            {
                label2.Text = " ";
                label3.Text = " ";
                label4.Text = " ";
                label5.Text = " ";

                connection.Open();
                SqlCommand cmd = new SqlCommand(sql, connection);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    label2.Text =reader.GetValue(1).ToString();
                    label3.Text = reader.GetValue(5).ToString();
                    label4.Text =reader.GetValue(6).ToString();
                    label5.Text =  reader.GetValue(2).ToString();

                    
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("No RECORDS WERE FOUND!");
            }


            returnclass rc = new returnclass();
            string pathquerry = rc.scalarReturn("select img_path from student_img where img_fk=" + textBox1.Text);
            if (pathquerry == " ")
            {
                pictureBox1.Image = Image.FromFile(@"C:\Users\salman\documents\visual studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Resources\profile.jpg");
            }
            else
            {
                pictureBox1.Image = Image.FromFile(pathquerry);
            }

            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

          string s=  rc.scalarReturn("select count(fee_id) from fees where fee_fk_st_id="+textBox1.Text+" and monthx='"+System.DateTime.Now.Month.ToString()+"'");
          if (s.Equals("0"))
          {
              button2.Enabled = true;

              label10.Text = "Unpaid!";
              label10.ForeColor = System.Drawing.Color.Red;
          }
          else
          {
              label10.Text = "paid!";
              button2.Enabled = false;
              label10.ForeColor = System.Drawing.Color.Green;

          }




        }

        private void button2_Click(object sender, EventArgs e)
        {
            student_status sa = new student_status();
            sa.status_student_id =Convert.ToInt32( label5.Text);
            sa.class_fees = label4.Text;
            sa.class_name = label3.Text;

            insert i = new insert();
            i.insert_FEES(sa, textBox1.Text);
            q = "select s.std_id,sa.SA_ID,f.fee_id,s.std_name,sa.sa_year,f.dayx+'/'+f.monthx as PaidDate,f.fee_amount from student s inner join STUDENT_STATUS sa on s.std_id=sa.SA_ST_ID inner join fees f on sa.SA_ID=f.SA_FK_ID where sa.sa_year='" + System.DateTime.Now.Year.ToString() + "'";
            dataGridView1.DataSource = vc.showrecord(q);

        }

        private void feessubmission_Load(object sender, EventArgs e)
        {
            q = "select s.std_id,sa.SA_ID,f.fee_id,s.std_name,sa.sa_year,f.dayx+'/'+f.monthx as PaidDate,f.fee_amount from student s inner join STUDENT_STATUS sa on s.std_id=sa.SA_ST_ID inner join fees f on sa.SA_ID=f.SA_FK_ID where sa.sa_year='"+System.DateTime.Now.Year.ToString()+"'";
            dataGridView1.DataSource = vc.showrecord(q);
        }
    }
}

Tuesday, 26 September 2017

How to use Video Control in html-5

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Video and audion controls</title>
<style>
body
{
margin:0 auto;
padding:0px;
background-color:#F00;

}
#wrapper
{
width:80%;
margin:0 auto;
height:900px;
background-color:#FFF;
border:1px solid black;

}
header
{
width:100%;
height:100px;
 background-color:#CCC;
 margin-bottom:100px;


}


</style>


</head>

<body>

<div id="wrapper">
<header>

<DIV style="WIDTH:300PX;HEIGHT:100%;">
<img style="width:200px;height:100%" src="img/you.png"/>
</DIV>

 </header>


<div style="WIDTH:100%;HEIGHT:500px; margin:0 auto;  border:1px solid black ">


<video controls style="width:100%;height:100%">

<source src="video/carvideo.mp4" type="video/mp4" >
 </video>

</div>


<div style="WIDTH:100%;HEIGHT:auto; margin:0 auto;  border:1px solid black ">
<video controls style="width:25%;height:200px">

<source src="video/carvideo.mp4" type="video/mp4">
 </video>

<video controls style="width:24%;height:200px">

<source src="video/carvideo.mp4" type="video/mp4">
 </video>

<video controls style="width:24%;height:200px">

<source src="video/carvideo.mp4" type="video/mp4">
 </video>
<video controls style="width:24%;height:200px">

<source src="video/carvideo.mp4" type="video/mp4">
 </video>


</div>



</div>



</body>
</html>

Quiz Application# 1 (Databse Design)

create table admin_athu
(
ad_id int primary key identity  ,
ad_user nvarchar(20) not null,
ad_password nvarchar(20) not null

)

create table student_record
(
std_id int primary key identity  ,
std_name nvarchar(20) not null,
std_batchcode nvarchar(20) not null,
std_password nvarchar(20) not null,
std_ad_id int foreign key references admin_athu(ad_id )
)


create table exams
(
ex_id int primary key identity  ,
exam_name nvarchar(20) not null
)

create table questions
(
q_id int primary key identity,
q_title   nvarchar(max) not null,
q_opa nvarchar(200) not null,
q_opb nvarchar(200) not null,
q_opc nvarchar(200) not null,
q_opd nvarchar(200) not null,
q_opcorrect nvarchar(200) not null,
q_addeddate nvarchar(20) not null,
q_fk_ad int foreign key references admin_athu(ad_id ),
q_fk_ex int foreign key references exams(ex_id)
)

Sunday, 24 September 2017

How to create Attractive Forms in html-5 using some Css code

Copy and paste the code in your html file:


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Forms </title>

<style>
body
{ margin:0 auto;
padding:0px;
background-color:#99C;
background-image:url(img/1.jpg);
background-size:cover;
}

form
{
margin:0 auto;
width:350px;
height:600px;
background-color:#F6F;
margin-top:100px;
border-radius:50px 20px 50px 20px;
color:#93F;
border:8px   inset #90F;
font-style:italic;
font-weight:bold;
opacity:0.6;

background-image:url(img/2.jpg);
}
TD{
padding:20PX;}

</style>



</head>

<body>

<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>


</body>
</html>


How to export From sql records to data Grid view

Database to Data Grid view:


            string connectionString = null; //connection string
            string sql = null; //query from db

            connectionString = "Data Source=LAB6-168;Initial Catalog=schoolm;User ID=sa;Password=aptech";
            SqlConnection cnn = new SqlConnection(connectionString); //con object
            cnn.Open(); //coneection open form db
            sql = "SELECT * FROM student"; //query
            SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn); //reads all records from db
            DataSet ds = new DataSet();
            dscmd.Fill(ds);

            dataGridView1.DataSource = ds.Tables[0];

How to export database table in excel file (From SQL TO EXCEL)

Button event Code:

  SqlConnection cnn;
            string connectionString = null;
            string sql = null;
            string data = null;
            int i = 0;
            int j = 0;

            Microsoft.Office.Interop.Excel.Application xlApp;
            Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlApp = new Microsoft.Office.Interop.Excel.Application();
            xlWorkBook = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            connectionString = "Data Source=LAB6-168;Initial Catalog=schoolm;User             ID=sa;Password=aptech";
            cnn = new SqlConnection(connectionString);
            cnn.Open();
            sql = "SELECT * FROM student";
            SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
            DataSet ds = new DataSet();
            dscmd.Fill(ds);

            for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
            {
                for (j = 0; j <= ds.Tables[0].Columns.Count - 1; j++)
                {
                    data = ds.Tables[0].Rows[i].ItemArray[j].ToString();
                    xlWorkSheet.Cells[i + 1, j + 1] = data;
                }
            }

            xlWorkBook.SaveAs(@"C:\Users\salman\Desktop\csharp-Excel6.xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();

            releaseObject(xlWorkSheet);
            releaseObject(xlWorkBook);
            releaseObject(xlApp);

            MessageBox.Show("Excel file created , you can find the file c:\\csharp.net-informations.xls");

Release Method outside button event :

private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        }


Saturday, 23 September 2017

database application in urdu/hindi part 13 (FETCHING RECORD FROM MULTIPLE TABLES,Fees Submission Form)

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

namespace WindowsFormsApplication4
{
    public partial class feessubmission : Form
    {
        private string connstring = ConfigurationManager.ConnectionStrings["TESTDB"].ConnectionString;
        public feessubmission()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection(connstring);
            string sql = "select s.std_id,s.std_name,sa.SA_ID,SA_Class_id,sa.sa_year,c.classname,c.fees  from student s inner join STUDENT_STATUS sa  on sa.SA_ST_ID=s.std_id inner join classes c on c.class_id=sa.SA_Class_id where sa.sa_year='"+System.DateTime.Now.Year+"' and s.std_id="+textBox1.Text;

            try
            {
                label2.Text = " ";
                label3.Text = " ";
                label4.Text = " ";
                label5.Text = " ";

                connection.Open();
                SqlCommand cmd = new SqlCommand(sql, connection);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    label2.Text ="Name: "+reader.GetValue(1).ToString();
                    label3.Text ="Class: "+ reader.GetValue(5).ToString();
                    label4.Text ="fees: "+ reader.GetValue(6).ToString();
                    label5.Text = "Status id: "+reader.GetValue(2).ToString();

                   
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("No RECORDS WERE FOUND!");
            }


            returnclass rc = new returnclass();
            string pathquerry = rc.scalarReturn("select img_path from student_img where img_fk=" + textBox1.Text);
            if (pathquerry == " ")
            {
                pictureBox1.Image = Image.FromFile(@"C:\Users\salman\documents\visual studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Resources\profile.jpg");
            }
            else
            {
                pictureBox1.Image = Image.FromFile(pathquerry);
            }

            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;







        }

        private void button2_Click(object sender, EventArgs e)
        {
            student_status sa = new student_status();
            sa.status_student_id =Convert.ToInt32( label5.Text);
            sa.class_fees = label4.Text;
            sa.class_name = label3.Text;

            insert i = new insert();
            i.insert_FEES(sa, textBox1.Text);


        }
    }
}

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 ...