open System
open System.Windows.Forms
open System.Data
open System.Data.SqlClient
open System.Drawing
let aggfform=new Form(Text="Aggrigate Functions")
aggfform.BackColor<-Color.DarkGray
let ffont=new Font("Arial", 9.75F,FontStyle.Regular, GraphicsUnit.Point)
let constring = @"Data Source=MCNDESKTOP34;Initial Catalog=Employee;User ID=sa; Password=mcn@123"
let adap=new SqlDataAdapter("select * from EmployeeSalary",constring)
let dt=new DataTable()
adap.Fill(dt) |>ignore
let datagrid=new DataGridView(Top=20,Left=40,Width=440,Height=200)
datagrid.DataSource<-dt
let maxbtn=new Button(Text="MAX SALARY",Top=240,Left=0,Width=100)
let minbtn=new Button(Text="MIN SALARY",Top=280,Left=0,Width=100)
let countbtn=new Button(Text="COUNT EMPLOYEES",Top=320,Left=0,Width=120)
let sumbtn=new Button(Text="SUM OF SALARIES",Top=360,Left=0,Width=120)
let avgbtn=new Button(Text="AVG OF SALARIES",Top=400,Left=0,Width=120)
let getdatebtn=new Button(Text="GETDATE",Top=440,Left=0,Width=100)
maxbtn.BackColor<-Color.Ivory
minbtn.BackColor<-Color.Ivory
countbtn.BackColor<-Color.Ivory
sumbtn.BackColor<-Color.Ivory
avgbtn.BackColor<-Color.Ivory
getdatebtn.BackColor<-Color.Ivory
aggfform.Controls.Add(datagrid)
let valuemax=new Label(Top=240,Left=140,Height=30,BorderStyle=BorderStyle.FixedSingle)
let valuemin=new Label(Top=280,Left=140,Height=30,BorderStyle=BorderStyle.FixedSingle)
let valuecount=new Label(Top=320,Left=140,Height=30,BorderStyle=BorderStyle.FixedSingle)
let valuesum=new Label(Top=360,Left=140,Height=30,BorderStyle=BorderStyle.FixedSingle)
let valueavg=new Label(Top=400,Left=140,Height=30,BorderStyle=BorderStyle.FixedSingle)
let valuegetdate=new Label(Top=440,Left=140,Height=30,BorderStyle=BorderStyle.FixedSingle)
aggfform.Controls.Add(valuemax)
aggfform.Controls.Add(valuemin)
aggfform.Controls.Add(valuecount)
aggfform.Controls.Add(valuesum)
aggfform.Controls.Add(valueavg)
aggfform.Controls.Add(valuegetdate)
aggfform.Controls.Add(maxbtn)
aggfform.Controls.Add(minbtn)
aggfform.Controls.Add(countbtn)
aggfform.Controls.Add(sumbtn)
aggfform.Controls.Add(avgbtn)
aggfform.Controls.Add(getdatebtn)
//MAX FUNCTION
maxbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select max(Salary) from EmployeeSalary",con)
com.Connection <- con
valuemax.Text<-com.ExecuteScalar().ToString()
)
//MIN FUCTION
minbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select min(Salary) from EmployeeSalary",con)
com.Connection <- con
valuemin.Text<-com.ExecuteScalar().ToString()
)
//COUNT FUNCTION
countbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select Count(Salary) from EmployeeSalary",con)
com.Connection <- con
valuecount.Text<-com.ExecuteScalar().ToString()
)
//SUM FUNCTION
sumbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select Sum(Salary) from EmployeeSalary",con)
com.Connection <- con
valuesum.Text<-com.ExecuteScalar().ToString()
)
//AVG FUNCTION
avgbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select avg(Salary) from EmployeeSalary",con)
com.Connection <- con
valueavg.Text<-com.ExecuteScalar().ToString()
)
//GETDATE FUNCTION
getdatebtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select getdate()",con)
com.Connection <- con
valuegetdate.Text<-com.ExecuteScalar().ToString()
)
Application.Run(aggfform)