protected void btnSubmit_Click(object sender, EventArgs e) { //Creating the object of BAL RecordBAL rBAL=new RecordBAL(); int recordStatus = 0; //int employeeid = 109; // int employeeid = 0; string firstname = txtName.Text.ToString(); string lastname=txtSurname.Text.ToString(); DateTime dateofbirth = Convert.ToDateTime( txtDoB.Text.ToString()); // int Age=Convert.ToInt32( txtAge.Text); DateTime hiredate = Convert.ToDateTime( txtDateHire.Text.ToString()); string email = txtEmail.Text.ToString(); string phonenumber = txtPhone.Text.ToString(); // int UserID=Convert.ToInt32(txtPhone.Text); try{ recordStatus = rBAL.InsertRecord_BAL(firstname, lastname, dateofbirth,dateofbirth, email, phonenumber); lblInfo.Text = "New Record Inserted Successfully."; if(recordStatus > 0) lblInfo.Text = "New Record Inserted Successfully."; txtName.Text = ""; txtSurname.Text = ""; txtDoB.Text = ""; txtDateHire.Text = ""; txtEmail.Text = ""; txtPhone.Text = ""; } catch (Exception ex) { lblInfo.Text = ex.Message.ToString(); } finally { rBAL = null; } }
protected void GridView1_RowCommand2(object sender, GridViewCommandEventArgs e) { RecordBAL rBA = new RecordBAL(); if (e.CommandName == "EditRow") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; GridView1.EditIndex = rowIndex; BindGridViewShowRecords(); } else if (e.CommandName == "DeleteRow") { try { rBA.DeleteEmployee(Convert.ToInt32(e.CommandArgument)); BindGridViewShowRecords(); } catch (Exception ex) { lblInfo.Text = ex.Message.ToString(); } } else if (e.CommandName == "CancelUpdate") { GridView1.EditIndex = -1; BindGridViewShowRecords(); } else if (e.CommandName == "UpdateRow") { try { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; int employeeid = Convert.ToInt32(e.CommandArgument); string firstname = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox1")).Text; string lastname = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox2")).Text; string email = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox3")).Text; Int32 phonenumber = Convert.ToInt32(((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox4")).Text); rBA.UpdateRecord_BAL(employeeid, firstname, lastname, email, phonenumber); GridView1.EditIndex = -1; BindGridViewShowRecords(); } catch (Exception ex) { lblInfo.Text = ex.Message.ToString(); } } }
private DataTable GridShowRecordsDataSource() { //Creating object of BAL RecordBAL rBAL = new RecordBAL(); DataTable dTable = new DataTable(); try { //Getting the DataSource for GridView from BAL Using BAL object dTable = rBAL.RetrieveRecords(); } catch (Exception ex) { lblInfo.Text = ex.Message.ToString(); } finally { rBAL = null; } return dTable; }