public bool ControlDias(string dia) //controlar que no se metan los mismos dias { bool correcto; if (dia.Length == 10) { using (var Context = new MyDbContext()) { if (!moduloInicio.Existe("select FechaFestivo from pyme.festivoes where FechaFestivo='" + dia + "';")) { Festivo NuevoFestivo = new Festivo(); NuevoFestivo.FechaFestivo = dia; Context.Festivos.Add(NuevoFestivo); Context.SaveChanges(); } } correcto = true; } else { MessageBox.Show("error dato " + dia + " dato no cargado", "CUIDADO", MessageBoxButtons.OK); correcto = false; } return(correcto); }
/*================================================================================ * GET FESTIVOS POR AÑO *================================================================================*/ public static ObservableCollection <Festivo> GetFestivosPorAño(int año) { // Creamos la lista y el comando que extrae las líneas. ObservableCollection <Festivo> lista = new ObservableCollection <Festivo>(); using (OleDbConnection conexion = new OleDbConnection(App.Global.CadenaConexion)) { //string comandoSQL = "SELECT * FROM Festivos WHERE Año=? ORDER BY Fecha;"; string comandoSQL = "GetFestivosPorAño"; OleDbCommand comando = new OleDbCommand(comandoSQL, conexion); comando.CommandType = System.Data.CommandType.StoredProcedure; comando.Parameters.AddWithValue("Año", año); OleDbDataReader lector = null; try { conexion.Open(); lector = comando.ExecuteReader(); while (lector.Read()) { Festivo festivo = new Festivo(lector); lista.Add(festivo); festivo.Nuevo = false; festivo.Modificado = false; } } catch (Exception ex) { Utils.VerError("BdFestivos.GetFestivosPorAño", ex); } finally { lector.Close(); } } return(lista); }
public FestivoForm(long oid, Festivo festivo, Form parent) : base(oid, new object[1] { festivo }, true, parent) { InitializeComponent(); }
/*================================================================================ * GET FESTIVOS *================================================================================*/ public static List <Festivo> GetFestivos() { // Creamos la lista y el comando que extrae las líneas. List <Festivo> lista = new List <Festivo>(); using (OleDbConnection conexion = new OleDbConnection(App.Global.CadenaConexion)) { string comandoSQL = "SELECT * FROM Festivos ORDER BY Fecha;"; OleDbCommand comando = new OleDbCommand(comandoSQL, conexion); OleDbDataReader lector = null; try { conexion.Open(); lector = comando.ExecuteReader(); while (lector.Read()) { Festivo festivo = new Festivo(lector); lista.Add(festivo); festivo.Nuevo = false; festivo.Modificado = false; } } catch (Exception ex) { Utils.VerError("BdFestivos.GetFestivosPorMes", ex); } finally { lector.Close(); } } return(lista); }
public FestivoEditForm(Festivo item, Form parent) : base(item, parent) { InitializeComponent(); SetFormData(); _mf_type = ManagerFormType.MFEdit; }
private void DeleteFestivo_BT_Click(object sender, EventArgs e) { if (Festivos_DGW.CurrentRow != null) { Festivo.Delete(ActiveOID); RefreshMainData(); } }
protected override void GetFormSourceData(long oid, object[] parameters) { _entity = (Festivo)parameters[0]; if (_entity == null) { _entity = Festivo.Get(oid, false); _entity.BeginEdit(); } }
/*================================================================================ * GUARDAR FESTIVOS *================================================================================*/ public static void GuardarFestivos(IEnumerable <Festivo> lista) { // Si la lista está vacía, salimos. if (lista == null || lista.Count() == 0) { return; } using (OleDbConnection conexion = new OleDbConnection(App.Global.CadenaConexion)) { //string SQLInsertar = "INSERT INTO Festivos (Año, Fecha) VALUES (?, ?)"; string SQLInsertar = "InsertarFestivo"; //string SQLActualizar = "UPDATE Festivos SET Año=?, Fecha=? WHERE Id=?"; string SQLActualizar = "ActualizarFestivo"; try { conexion.Open(); foreach (Festivo festivo in lista) { if (festivo.Nuevo) { OleDbCommand comando = new OleDbCommand(SQLInsertar, conexion); comando.CommandType = System.Data.CommandType.StoredProcedure; Festivo.ParseToCommand(comando, festivo); comando.ExecuteNonQuery(); festivo.Nuevo = false; festivo.Modificado = false; } else if (festivo.Modificado) { OleDbCommand comando = new OleDbCommand(SQLActualizar, conexion); comando.CommandType = System.Data.CommandType.StoredProcedure; Festivo.ParseToCommand(comando, festivo); comando.ExecuteNonQuery(); festivo.Modificado = false; } } } catch (Exception ex) { Utils.VerError("BdFestivos.GuardarFestivos", ex); } } }
/// <summary> /// Guarda en la bd el objeto actual /// </summary> protected override bool SaveObject() { this.Datos.RaiseListChangedEvents = false; Festivo temp = _entity.Clone(); temp.ApplyEdit(); // do the save try { _entity = temp.Save(); _entity.ApplyEdit(); return(true); } finally { this.Datos.RaiseListChangedEvents = true; } }
protected override void GetFormSourceData(object[] parameters) { _entity = Festivo.New(); _entity.BeginEdit(); }
public FestivoUIForm(Festivo item, Form parent) : base(item.Oid, item, parent) { InitializeComponent(); }
public void Borrar(Festivo festivo) { _listaborrados.Add(festivo); ListaFestivos.Remove(festivo); HayCambios = true; }