protected void gvRutina_RowDeleting(object sender, GridViewDeleteEventArgs e) { Log.WriteOnLog("entro a funcion eliminar"); try { using (SqlConnection sqlCon = new SqlConnection(connectionString)) { sqlCon.Open(); string query = "DELETE FROM T_Rutina WHERE PK_IR_Cod = @id"; SqlCommand sqlCmd = new SqlCommand(query, sqlCon); sqlCmd.Parameters.AddWithValue("@id", Convert.ToInt32(gvRutina.DataKeys[e.RowIndex].Value.ToString())); sqlCmd.ExecuteNonQuery(); PopulateGridview(); ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "showNotification", "showNotification('bg-green', '" + "Rutina eliminada" + "', 'bottom', 'center', null, null);", true); //lblSuccessMessage.Text = "Rutina eliminada con exito"; lblErrorMessage.Text = ""; UPGridview.Update(); } } catch (Exception ex) { lblSuccessMessage.Text = ""; Log.WriteOnLog("Error al borrar" + ex.Message); } }
protected void gvRutina_RowUpdating(object sender, GridViewUpdateEventArgs e) { Log.WriteOnLog("entro a funcion Actualizar"); try { using (SqlConnection sqlCon = new SqlConnection(connectionString)) { sqlCon.Open(); string query = "UPDATE T_Rutina SET DR_FechaRutina=@Fecharutina,VR_DescripcionE=@descripcion,FK_ITR_Cod=@fkitrcod,VR_Duracion=@duracion,IR_Repeticion=@repetic WHERE PK_IR_Cod = @id"; SqlCommand sqlCmd = new SqlCommand(query, sqlCon); sqlCmd.Parameters.AddWithValue("@Fecharutina", DateTime.Parse((gvRutina.Rows[e.RowIndex].FindControl("txtfechaRutina") as TextBox).Text.Trim())); sqlCmd.Parameters.AddWithValue("@descripcion", (gvRutina.Rows[e.RowIndex].FindControl("txtdescripcion") as TextBox).Text.Trim()); sqlCmd.Parameters.AddWithValue("@fkitrcod", (gvRutina.Rows[e.RowIndex].FindControl("txtFK_ITR_Cod") as TextBox).Text.Trim()); sqlCmd.Parameters.AddWithValue("@duracion", (gvRutina.Rows[e.RowIndex].FindControl("txtduracion") as TextBox).Text.Trim()); sqlCmd.Parameters.AddWithValue("@repetic", (gvRutina.Rows[e.RowIndex].FindControl("txtrepeticion") as TextBox).Text.Trim()); sqlCmd.Parameters.AddWithValue("@id", Convert.ToInt32(gvRutina.DataKeys[e.RowIndex].Value.ToString())); sqlCmd.ExecuteNonQuery(); gvRutina.EditIndex = -1; UPGridview.Update(); PopulateGridview(); UPGridview.Update(); ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "showNotification", "showNotification('bg-green', '" + "Actualizacion exitosa" + "', 'bottom', 'center', null, null);", true); //lblSuccessMessage.Text = "Rutina Actualizada con exito."; lblErrorMessage.Text = ""; } } catch (Exception ex) { lblSuccessMessage.Text = ""; Log.WriteOnLog("Error en el actualizar : " + ex.Message); } }
protected void gvRutina_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName.Equals("AddNew")) { Log.WriteOnLog("entro a funcion add new"); using (SqlConnection sqlCon = new SqlConnection(connectionString)) { sqlCon.Open(); string query = "INSERT INTO T_Rutina (DR_FechaRutina,DR_FechaRegistro,VR_DescripcionE,FK_ITR_Cod,VR_Duracion,IR_Repeticion) VALUES (@Fecharutina,GETDATE(),@descripcion,@fkitrcod,@duracion,@repetic)"; SqlCommand sqlCmd = new SqlCommand(query, sqlCon); sqlCmd.Parameters.AddWithValue("@Fecharutina", DateTime.Parse((gvRutina.FooterRow.FindControl("txtfechaRutinaFooter") as TextBox).Text.Trim())); sqlCmd.Parameters.AddWithValue("@descripcion", (gvRutina.FooterRow.FindControl("txtdescripcionFooter") as TextBox).Text.Trim()); sqlCmd.Parameters.AddWithValue("@fkitrcod", (gvRutina.FooterRow.FindControl("txtFK_ITR_CodFooter") as TextBox).Text.Trim()); sqlCmd.Parameters.AddWithValue("@duracion", (gvRutina.FooterRow.FindControl("txtduracionFooter") as TextBox).Text.Trim()); sqlCmd.Parameters.AddWithValue("@repetic", (gvRutina.FooterRow.FindControl("txtrepeticionFooter") as TextBox).Text.Trim()); sqlCmd.ExecuteNonQuery(); PopulateGridview(); ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "showNotification", "showNotification('bg-green', '" + "Registro exitoso" + "', 'bottom', 'center', null, null);", true); //lblSuccessMessage.Text = "Registro de rutina con exito."; //var textbox = gvRutina.FindControl("txtFK_ITR_CodFooter"); lblErrorMessage.Text = ""; UPGridview.Update(); DateTime FechaSel = Convert.ToDateTime(Session["PrimerDia"]); string fecha = FechaSel.ToString("yyyy-MM-dd'T'HH':'mm':'ss"); DateTime date = DateTime.Now; (gvRutina.FooterRow.FindControl("txtfechaRutinaFooter") as TextBox).Text = fecha; (gvRutina.FooterRow.FindControl("txtfecharegistroFooter") as TextBox).Text = date.ToShortDateString(); (gvRutina.FooterRow.FindControl("txtFK_ITR_CodFooter") as TextBox).Text = "1"; } } } catch (Exception ex) { lblSuccessMessage.Text = ""; lblErrorMessage.Text = ex.Message; Log.WriteOnLog("error en add new: " + ex.Message); } }
protected void gvRutina_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { gvRutina.EditIndex = -1; PopulateGridview(); UPGridview.Update(); }
protected void gvRutina_RowEditing(object sender, GridViewEditEventArgs e) { gvRutina.EditIndex = e.NewEditIndex; PopulateGridview(); UPGridview.Update(); }