open System
open System.Windows.Forms
open System.Data
open System.Data.SqlClient
open System.Drawing
let scalfform=new Form(Text="Scalar Functions")
scalfform.BackColor<-Color.Lavender
let ffont=new Font("Arial", 9.75F,FontStyle.Regular, GraphicsUnit.Point)
let constring = @"Data Source=MCNDESKTOP34;Initial Catalog=Employee;User ID=; Password="
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=330,Height=180)
datagrid.DataSource<-dt
let rtrimbtn=new Button(Text="RightTrim()",Top=260,Left=0,Width=100)
let ltrimbtn=new Button(Text="LeftTrim()",Top=300,Left=0,Width=100)
let upperbtn=new Button(Text="UPPER()",Top=340,Left=0,Width=100)
let lowerbtn=new Button(Text="LOWER()",Top=380,Left=0,Width=100)
let substringbtn=new Button(Text="SUBSTRING()",Top=420,Left=0,Width=100)
let convertbtn=new Button(Text="CONVVERT()",Top=460,Left=0,Width=100)
let absbtn=new Button(Text="ABSOLUTE()",Top=500,Left=0,Width=100)
let roundbtn=new Button(Text="ROUND()",Top=540,Left=0,Width=100)
rtrimbtn.BackColor<-Color.Ivory
ltrimbtn.BackColor<-Color.Ivory
upperbtn.BackColor<-Color.Ivory
lowerbtn.BackColor<-Color.Ivory
substringbtn.BackColor<-Color.Ivory
convertbtn.BackColor<-Color.Ivory
absbtn.BackColor<-Color.Ivory
roundbtn.BackColor<-Color.Ivory
scalfform.Controls.Add(datagrid)
let valuertrim=new Label(Top=260,Left=140,Height=20,BorderStyle=BorderStyle.FixedSingle)
let valueltrim=new Label(Top=300,Left=140,Height=20,BorderStyle=BorderStyle.FixedSingle)
let valueupper=new Label(Top=340,Left=140,Height=20,BorderStyle=BorderStyle.FixedSingle)
let valuelower=new Label(Top=380,Left=140,Height=20,BorderStyle=BorderStyle.FixedSingle)
let valuesubstring=new Label(Top=420,Left=140,Height=20,BorderStyle=BorderStyle.FixedSingle)
let valueconvert=new Label(Top=460,Left=140,Height=20,BorderStyle=BorderStyle.FixedSingle)
let valueabs=new Label(Top=500,Left=140,Height=20,BorderStyle=BorderStyle.FixedSingle)
let valueround=new Label(Top=540,Left=140,Height=20,BorderStyle=BorderStyle.FixedSingle)
scalfform.Controls.Add(valuertrim)
scalfform.Controls.Add(valueltrim)
scalfform.Controls.Add(valueupper)
scalfform.Controls.Add(valuelower)
scalfform.Controls.Add(valueconvert)
scalfform.Controls.Add(valuesubstring)
scalfform.Controls.Add(valueabs)
scalfform.Controls.Add(valueround)
scalfform.Controls.Add(convertbtn)
scalfform.Controls.Add(rtrimbtn)
scalfform.Controls.Add(ltrimbtn)
scalfform.Controls.Add(upperbtn)
scalfform.Controls.Add(lowerbtn)
scalfform.Controls.Add(substringbtn)
scalfform.Controls.Add(absbtn)
scalfform.Controls.Add(roundbtn)
//RightTrim FUNCTION
rtrimbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select rtrim('Pravesh ')",con)
com.Connection <- con
valuertrim.Text<-com.ExecuteScalar().ToString()
)
//LeftTrim FUNCTION
ltrimbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select ltrim( ' Amit')",con)
com.Connection <- con
valueltrim.Text<-com.ExecuteScalar().ToString()
)
//UPPER FUNCTION
upperbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select UPPER('Pankaj')",con)
com.Connection <- con
valueupper.Text<-com.ExecuteScalar().ToString()
)
//LOWER FUNCTION
lowerbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select LOWER('Pankaj')",con)
com.Connection <- con
valuelower.Text<-com.ExecuteScalar().ToString()
)
//SUBSTRING FUNCTION
substringbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("select SUBSTRING('Pankaj',3,3)",con)
com.Connection <- con
valuesubstring.Text<-com.ExecuteScalar().ToString()
)
//CONVERT FUNCTION
convertbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select CONVERT(int,30000.89)",con)
com.Connection <- con
valueconvert.Text<-com.ExecuteScalar().ToString()
)
//ABSOLUTE FUNCTION
absbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select ABS(-10)",con)
com.Connection <- con
valueabs.Text<-com.ExecuteScalar().ToString()
)
//ROUND FUNCTION
roundbtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand("Select ROUND(18.5619,3)",con)
com.Connection <- con
valueround.Text<-com.ExecuteScalar().ToString()
)
Application.Run(scalfform)