public static int Insertar(BE.CopiaDeSeguridad copia) { SqlParameter[] parametros = new SqlParameter[2]; parametros[0] = new SqlParameter("@nombre", copia.Nombre); parametros[1] = new SqlParameter("@fecha", copia.Fecha); return(SqlHelper.getInstance().escribir(Tabla + "_Alta", parametros)); }
private void button1_Click(object sender, EventArgs e) { if (this.ValidarTextbox()) { try { BE.CopiaDeSeguridad copia = new BE.CopiaDeSeguridad(); copia.Nombre = textBox1.Text; copia.Fecha = DateTime.Now; int res = BLL.GestionarCopiaDeSeguridad.Backup(copia); if (res == 0 && File.Exists(copia.Nombre)) { Mensaje("msgBackOk"); cargar(); } else { Mensaje("msgBackNo"); } } catch (Exception ex) { Util.Log.Error(ex.ToString()); Mensaje("msgBackNo"); } } }
private void button2_Click(object sender, EventArgs e) { try { if (listBox1.SelectedItem != null) { BE.CopiaDeSeguridad copia = (BE.CopiaDeSeguridad)listBox1.SelectedItem; if (File.Exists(copia.Nombre)) { BLL.GestionarCopiaDeSeguridad.Restaurar(copia); Mensaje("msgRestoreOk"); BLL.GestionarSesion.getInstance().cerrarSesion(); this.Hide(); this.MdiParent.Hide(); Login form = new Login(); form.ShowDialog(); } else { Mensaje("msgErrorArchivoNoExiste", "msgError"); } } } catch (Exception ex) { Util.Log.Error(ex.ToString()); Mensaje("msgRestoreNo", "msgError"); } }
public static List <BE.CopiaDeSeguridad> Listar() { List <BE.CopiaDeSeguridad> lista = new List <BE.CopiaDeSeguridad>(); DataTable tabla = SqlHelper.getInstance().leer(Tabla + "_Leer", null); foreach (DataRow item in tabla.Rows) { BE.CopiaDeSeguridad obj = new BE.CopiaDeSeguridad(); obj.Nombre = item["nombre"].ToString(); obj.Fecha = DateTime.Parse(item["fecha"].ToString()); lista.Add(obj); } return(lista); }
public static int Backup(BE.CopiaDeSeguridad copia) { int r = 0; try { string back = String.Format("USE [master]; BACKUP DATABASE [{0}] TO DISK='{1}'", db, copia.Nombre); SqlHelper.getInstance().abrir(); r = SqlHelper.getInstance().ejecutarSQL(back, null); SqlHelper.getInstance().cerrar(); } catch (Exception e) { Log.Error("Error al hacer Backup " + e.ToString()); throw; } return(r); }
public static int Restaurar(BE.CopiaDeSeguridad copia) { int r1, r2, r3; try { SqlHelper.getInstance().abrir(); string antes = String.Format("ALTER DATABASE [{0}] SET Single_User WITH Rollback Immediate;", db); r1 = SqlHelper.getInstance().ejecutarSQL(antes, null); string restore = String.Format("USE [master] RESTORE DATABASE [{0}] FROM DISK='{1}' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10", db, copia.Nombre); r2 = SqlHelper.getInstance().ejecutarSQL(restore, null); string despues = String.Format("ALTER DATABASE [{0}] SET Multi_User;", db); r3 = SqlHelper.getInstance().ejecutarSQL(despues, null); SqlHelper.getInstance().cerrar(); } catch (Exception e) { Log.Error("Error al Restaurar " + e.ToString()); throw; } return(r1 + r2 + r3); }