public int EditConjunto(Conjuntos c) { int res = 0; if (c != null) { //SE CREA UN DATATABLE COMUN Y SE ASIGNA //EL RESULTADO DE UNA CONSULTA LINQ //CON EL ID DE LA FILA DataTable dt = cta.GetData(). Where(x => x.Id == c.id).CopyToDataTable <conjuntosRow>(); //SE CREA UN DATATABLE TIPO DE LA TABLA conjuntosDataTable cdt = new conjuntosDataTable(); //SE COMBINA LOS DATATABLES PARA FACILITAR EL MANEJO cdt.Merge(dt); //SE CREA UN DATAROW DEL TIPO DE LA TABLA EwoDatabaseDataSet.conjuntosRow conRow = cdt.FindById(c.id); //SE ASIGNAN LOS VALORES MODIFICADOS conRow.nombre = c.nombre; conRow.image_path = c.image_path; conRow.id_sistema = c.id_sistema; //SE EJECUTA LA ACTUALIZACIÓN res = cta.Update(conRow); } return(res); }
private void metroButton1_Click(object sender, EventArgs e) { if (txtNombre.Text.Trim().Length > 0 && imagen1.Length > 0) { con_.nombre = txtNombre.Text.Trim(); con_.image_path = Path.GetFileName(imagen1); con_.image = pbImg1.Image; con_.id_sistema = (int)cboSistema.SelectedValue; if (cboSmp.SelectedIndex > -1) { con_.id_smp = (int)cboSmp.SelectedValue; } conjunto = new Conjuntos(); conjunto = con_; DialogResult = DialogResult.OK; } else { MessageBox.Show("Todos los campos son requeridos!"); } }
public int AddConjunto(Conjuntos c) { int res = 0; if (c != null) { res = cta.Insert(c.nombre, c.image_path, c.id_sistema); } return(res); }
public int DeleteConjunto(Conjuntos c) { int res = 0; if (c.id > 0) { //SE EJECUTA LA ACTUALIZACIÓN res = cta.Delete(c.id, c.id_sistema); } return(res); }
public int EditConjunto(Conjuntos con) { conjuntos conje; int regs = 0; try { //1. Get row from DB using (var context = new MttoAppEntities()) { conje = context.conjuntos.Where(s => s.Id == con.id).FirstOrDefault(); } //2. change data in disconnected mode (out of ctx scope) if (conje != null) { conje.nombre = con.nombre; conje.image_path = con.image_path; conje.id_sistema = con.id_sistema; conje.id_smp = con.id_smp; } //save modified entity using new Context using (var context = new MttoAppEntities()) { //3. Mark entity as modified context.Entry(conje).State = System.Data.Entity.EntityState.Modified; //4. call SaveChanges regs = context.SaveChanges(); } } catch (Exception e) { MessageBox.Show("Excepción al editar conjunto: " + e.ToString(), "Atención", MessageBoxButton.OK, MessageBoxImage.Error); } return(regs); }
public int DeleteConjunto(Conjuntos con) { conjuntos cond; int regs = 0; try { //1. Get row from DB using (var context = new MttoAppEntities()) { cond = context.conjuntos.Where(s => s.Id == con.id).FirstOrDefault(); } //save modified entity using new Context using (var context = new MttoAppEntities()) { //3. Mark entity as deleted context.Entry(cond).State = System.Data.Entity.EntityState.Deleted; //4. call SaveChanges regs = context.SaveChanges(); if (regs > 0) { //BORRAR IMAGEN File.Delete(Global.DIRECTORIO_IMAGENES + @"\" + cond.image_path); } } //BORRAR COMPONENTES DEL CONJUNTO DeleteComponentesByConjunto(con.id); } catch (Exception e) { MessageBox.Show("Excepción al eliminar conjunto: " + e.ToString(), "Atención", MessageBoxButton.OK, MessageBoxImage.Error); } return(regs); }
public int EditSmpComponents(Conjuntos cnt) { int regs = 0; try { //1. Get row from DB using (var context = new MttoAppEntities()) { var come = context.componentes.Where(s => s.id_conjunto == cnt.id).ToList(); come.ForEach(x => x.id_smp = cnt.id_smp); //context.Entry(come).State = System.Data.Entity.EntityState.Modified; regs = context.SaveChanges(); } } catch (Exception e) { MessageBox.Show("Excepción al asignar SMP a todos los componentes: " + e.ToString(), "Atención", MessageBoxButton.OK, MessageBoxImage.Error); } return(regs); }
public int AddConjunto(Conjuntos con) { int regs = 0; try { using (var context = new MttoAppEntities()) { context.conjuntos.Add(new conjuntos() { id_sistema = con.id_sistema, nombre = con.nombre, image_path = con.image_path, id_smp = con.id_smp }); regs = context.SaveChanges(); } } catch (Exception e) { MessageBox.Show("Excepción al agregar conjunto: " + e.ToString(), "Atención", MessageBoxButton.OK, MessageBoxImage.Error); } return(regs); }
private void lvConjuntos_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { if (lvConjuntos.SelectedItems.Count == 1) { try { Conjuntos conjunto_selected = (Conjuntos)lvConjuntos.SelectedItems[0].Tag as Conjuntos; conjunto = conjunto_selected.nombre; SetName(); setDetails(Global.DIRECTORIO_IMAGENES + @"\" + conjunto_selected.image_path, conjunto_selected.nombre, tipos.Conjunto); tlpDetalles.Visible = true; } catch (Exception EX) { MessageBox.Show("error: " + EX.ToString()); } } else { tlpDetalles.Visible = false; } }
public NuevoConjunto(Sistemas s, Conjuntos c) { InitializeComponent(); cboSistema.DataSource = daoML.GetSystems(s.id_machine); sistema = s; if (c != null) { con_ = c; txtNombre.Text = c.nombre; imagen1 = c.image_path; FileStream stream = new FileStream(Util.Global.DIRECTORIO_IMAGENES + @"\" + c.image_path, FileMode.Open, FileAccess.Read); pbImg1.Image = Image.FromStream(stream); stream.Close(); cboSistema.SelectedValue = c.id_sistema; } if (s != null) { cboSistema.SelectedValue = sistema.id; } }
private void lvOpciones_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { if (lvOpciones.SelectedItems.Count == 1) { ListViewItem lviOptionSeleted = lvOpciones.SelectedItems[0]; Acciones_list opSel = (Acciones_list)lviOptionSeleted.Tag; switch (opSel) { case Acciones_list.AgregarMay: switch (type_selected) { //MAQUINAS case 0: CreateFormModalMachines(opSel, null); break; //SISTEMAS case 1: CreateFormModalSystem(opSel, null, null); break; //CONJUNTOS case 2: ListViewItem lv_edit_co = lvConjuntos.SelectedItems[0]; Conjuntos con = (Conjuntos)lv_edit_co.Tag; CreateFormModalConjuntos(opSel, listSubSytems.Where(x => x.id == con.id_sistema).First(), null); break; default: break; } break; case Acciones_list.AgregarMen: switch (type_selected) { //MAQUINA case 0: ListViewItem lvi = lvMaquinas.SelectedItems[0]; Machines m = (Machines)lvi.Tag; CreateFormModalSystem(opSel, m, null); break; //SISTEMA case 1: ListViewItem lvi_sis = lvSistemas.SelectedItems[0]; Sistemas sis = (Sistemas)lvi_sis.Tag; CreateFormModalConjuntos(opSel, sis, null); break; case 2: //var compWin = new CalendarioPMBiBlio.Calendar(); //ElementHost.EnableModelessKeyboardInterop(compWin); //compWin.Show(); ListViewItem lvi_s = lvConjuntos.SelectedItems[0]; Conjuntos cc = (Conjuntos)lvi_s.Tag; Util.Global.conjunto = cc; CalendarioPm cpm = new CalendarioPm(); cpm.ShowDialog(); cpm.Dispose(); cpm = null; GC.Collect(); break; default: break; } break; case Acciones_list.Editar: switch (type_selected) { case 0: ListViewItem lvi = lvMaquinas.SelectedItems[0]; Machines m = (Machines)lvi.Tag; CreateFormModalMachines(opSel, m); break; case 1: ListViewItem lv = lvSistemas.SelectedItems[0]; Sistemas sis = (Sistemas)lv.Tag; CreateFormModalSystem(opSel, null, sis); break; //CONJUNTOS case 2: ListViewItem lv_edit_co = lvConjuntos.SelectedItems[0]; Conjuntos con = (Conjuntos)lv_edit_co.Tag; CreateFormModalConjuntos(opSel, listSubSytems.Where(x => x.id == con.id_sistema).First(), con); break; default: break; } break; case Acciones_list.Eliminar: switch (type_selected) { //MAQUINA case 0: ListViewItem lvi = lvMaquinas.SelectedItems[0]; Machines m = (Machines)lvi.Tag; CreateFormModalMachines(opSel, m); break; case 1: ListViewItem lv = lvSistemas.SelectedItems[0]; Sistemas sis_del = (Sistemas)lv.Tag; CreateFormModalSystem(opSel, null, sis_del); break; //CONJUNTOS case 2: ListViewItem lv_eli = lvConjuntos.SelectedItems[0]; Conjuntos con_del = (Conjuntos)lv_eli.Tag; CreateFormModalConjuntos(opSel, listSubSytems.Where(x => x.id == con_del.id_sistema).First(), con_del); break; default: break; } break; default: break; } } }
private void CreateFormModalConjuntos(Acciones_list al, Sistemas sis, Conjuntos con) { if (al == Acciones_list.Eliminar) { //if (listConjuntos.Count > 0) //{ // MessageBox.Show("No se puede eliminar, hay conjuntos que dependen de este sistema !", "Error eliminando sistema", MessageBoxButtons.OK, MessageBoxIcon.Error); //} //else //{ DialogResult res = MessageBox.Show("Esto eliminará este conjunto y todos sus componentes, desea eliminar realmente " + con.nombre + " ?" , "Eliminar conjunto", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { daoML.DeleteConjunto(con); if (!bgLoadConjuntos.IsBusy) { splash.Show(); bgLoadConjuntos.RunWorkerAsync(1); } } //} } else { //INHABILITAR PANTALLA PRINCIPAL Enabled = false; //VENTANA QUE SERVIRÁ DE SOMBRA DEL MODAL Shadow mod = new Shadow(); //LA SOMBRA TOMARÁ EL MISMO TAMAÑO DE LA VENTANA PRINCIPAL mod.Size = Size; //MOSTRAR LA VENTANA DE SOMBRA mod.Show(); //LA SOMBRA TENDRÁ LA MISMA UBICACIÓN EN LA PANTALLA QUE LA VENTANA PRINCIPAL mod.Location = Location; //CREAR NUEVO ELEMENTO if (al == Acciones_list.AgregarMay || al == Acciones_list.Editar || al == Acciones_list.AgregarMen) { NuevoConjunto nvC; if (al == Acciones_list.AgregarMen) { nvC = new NuevoConjunto(sis, con); } if (al == Acciones_list.AgregarMay) { nvC = new NuevoConjunto(sis, null); } else { nvC = new NuevoConjunto(sis, con); } //INICIALIZAR EVENTO DE CIERRE DE FORMULARIO PARA CONTROLARLO DESDE LA PANTALLA PADRE nvC.FormClosed += (s, e) => { mod.Close(); Enabled = true; };//HABILITAR VENTANA PRINCIPAL APENAS SE CIERRE //LA POSICIÓN PRINCIPAL SERÁ FIJADA POR LA UBICACIÓN MANUAL nvC.StartPosition = FormStartPosition.CenterScreen; //CALCULAR POSICIÓN DE ACUERDO AL TAMAÑO DE LA VENTANA PRINCIPAL //nvS.Location = //new System.Drawing.Point(mod.Left + (mod.Width - nvS.Width) / 2, // mod.Top + (mod.Height - nvS.Height) / 2); //TAMAÑO MAS PEQUEÑO nvC.Size = new System.Drawing.Size(548, 516); //MOSTRAR MODAL SOBRE EL FORMULARIO DE SOMBRA nvC.ShowDialog(); //CUANDO SE CIERRE EL MODAL, MOSTRAR LA VENTANA PRINCIPAL this.BringToFront(); if (al == Acciones_list.AgregarMen || al == Acciones_list.AgregarMay) { if (nvC.DialogResult == DialogResult.OK) { //OBTENER EL OBJETO CON INFORMACIÓN Y AGREGARLO A LA BASE DE DATOS daoML.AddConjunto(nvC.conjunto); //MODIFICAR EL SMP EN TODOS LOS COMPONENTES daoML.EditSmpComponents(nvC.conjunto); } } else { if (nvC.DialogResult == DialogResult.OK) { //OBTENER EL OBJETO CON INFORMACIÓN Y EDITARLO EN LA BASE DE DATOS daoML.EditConjunto(nvC.conjunto); //MODIFICAR EL SMP EN TODOS LOS COMPONENTES daoML.EditSmpComponents(nvC.conjunto); } //tlpSistemas.Visible = false; } nvC.Dispose(); tlpDetalles.Visible = false; if (!bgLoad.IsBusy) { splash.Show(); bgLoad.RunWorkerAsync(); } } } }