//Importing Namespaces
open System
open System.Windows.Forms
open System.Drawing
open System.Data.SqlClient
open System.Data
// Creating Form & User Controls
let MyForm = new Form(Height =400, Width = 500)
// Labels
let lblId = new Label(Top =20 ,Left=0, Height =30, Width = 120)
let lblafdelete = new Label(Top =100 ,Left=30, Height =20, Width = 80)
let lblbafdelete = new Label(Top =100 , Left=420, Height =20, Width = 120)
// TextBoxes
let txtID = new TextBox(Top =20, Left =120,BorderStyle=BorderStyle.FixedSingle)
lblId.Text <- " Enter Customer ID:"
lblafdelete.Text <- "After Delete"
lblbafdelete.Text <- "Before/After Delete"
let btnTable1 = new Button(Top =120, Left =30, Height =20, Width =90)
let btnTable2 = new Button(Top =120, Left =420, Height =20, Width =90)
let btnsearch = new Button(Top =20, Left =250, Height =20, Width =80)
btnTable1.Text <- "FirstTable"
btnTable2.Text <- "SecondTable"
btnsearch.Text <- "Delete"
//Adding Controls to Form
MyForm.Controls.Add(lblId)
MyForm.Controls.Add(lblafdelete)
MyForm.Controls.Add(lblbafdelete)
MyForm.Controls.Add(txtID)
MyForm.Controls.Add(btnTable1)
MyForm.Controls.Add(btnTable2)
MyForm.Controls.Add(btnsearch)
//Database Connectivity
let constr = @"Data Source=MCNDESKTOP34;Initial Catalog=DemoTriggers; User Id=sa; Password=mcn@123"
let con = new SqlConnection(constr)
let com1 = new SqlCommand()
btnsearch.Click.Add(fun _->
con.Close()
com1.Connection <- con
con.Open()
com1.CommandType <- CommandType.StoredProcedure
com1.CommandText <- "DeleteData" //DeleteData is a stored procedure
com1.Parameters.AddWithValue("@cid",txtID.Text) |> ignore
com1.ExecuteNonQuery()|> ignore
con.Close()
MessageBox.Show("After Delete Trigger Fired on Firsttable")|>ignore
txtID.Clear()
txtID.Focus() |>ignore
)
btnTable1.Click.Add(fun _ ->
let adapter = new SqlDataAdapter("select * from FirstTable",con)
let ds = new DataSet()
adapter.Fill(ds) |>ignore
let gridview = new DataGridView(Top=150,Width=420, Height=150)
MyForm.Controls.Add(gridview)
gridview.DataSource <- ds.Tables.[0]
)
btnTable2.Click.Add(fun _ ->
let adapter = new SqlDataAdapter("select * from SecondTable",con)
let dt = new DataTable()
adapter.Fill(dt) |>ignore
let gridview = new DataGridView(Top=150,Left=420,Width=400,Height=150)
MyForm.Controls.Add(gridview)
gridview.DataSource <- dt
)
Application.Run(MyForm)