private void metroButton6_Click(object sender, EventArgs e) { //get the data from texbox p.sPID = int.Parse(sPID.Text); p.sProgramme = sProgramme.Text; bool success = p.Update(p); if (success == true) { //Upload Successfully MessageBox.Show(" Successfully Updated"); } else { //faild to update MessageBox.Show("ERROR "); } DataTable dtp = p.Select(); metroGrid2.DataSource = dtp; Clear2(); }
protected void dgUpdate_Programme(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { Label lblTempID = (Label)e.Item.Cells[0].FindControl("txtID"); TextBox txtTempProgrammeCode = (TextBox)e.Item.Cells[0].FindControl("txtProgrammeID"); DropDownList txtTempFacultyID = (DropDownList)e.Item.Cells[1].FindControl("ddlFacultyName"); TextBox txtTempProgrammeName = (TextBox)e.Item.Cells[2].FindControl("txtProgrammeName"); Regex codeRegex = new Regex(@"[A-Z]{3}$"); Match checkCode = codeRegex.Match(txtTempProgrammeCode.Text); //Validation for programme (No digit allowed and only up to 50 characters) Regex progRegex = new Regex(@"[a-zA-Z() ]{1,50}$"); Match checkProg = progRegex.Match(txtTempProgrammeName.Text); if (lblTempID.Text.Trim() == "" || txtTempProgrammeCode.Text.Trim() == "" || txtTempFacultyID.Text.Trim() == "" || txtTempProgrammeName.Text.Trim() == "") { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Please fill in the programme information first!', 'error')</script>'"); } else if (!checkCode.Success) { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'The programme code must have 3 upppercase characters', 'error')</script>'"); } else if (!checkProg.Success) { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Programme name can only consist characters or ().', 'error')</script>'"); } else { Programme programme = new Programme(); if (programme.Update(lblTempID.Text, txtTempProgrammeCode.Text, txtTempFacultyID.Text, txtTempProgrammeName.Text) == false) { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'This code is existed already, try another programme code!', 'error')</script>'"); } else { ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Updated!', text: 'This " + txtTempProgrammeName.Text + " (" + txtTempProgrammeCode.Text + ") programme is updated successfully', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'cpProgramme.aspx'; }});</script>'"); } } }