public List <cMaestrosCabeceraDesktop> CargarLista() { List <cMaestrosCabeceraDesktop> result = new List <cMaestrosCabeceraDesktop>(); try { svcMOM.MasterOfMasterSvcClient svc = new svcMOM.MasterOfMasterSvcClient(); var lista = svc.ConsultarMaestroCabecera(-1, "", null, "0001-01-01", "9999-12-31"); foreach (MasterOfMasterModels.cMaestrosCabecera MC in lista) { cMaestrosCabeceraDesktop datos = new cMaestrosCabeceraDesktop(); datos.descripcion = MC.descripcion; datos.idMaestroCabecera = MC.idMaestroCabecera; datos.idUsuarioActualiza = MC.idUsuarioActualiza; datos.idUsuarioCreador = MC.idUsuarioCreador; datos.indActivo = MC.indActivo; datos.fechaCreacion = MC.fechaCreacion.ToShortDateString(); datos.fechaOcurrencia = MC.fechaOcurrencia.ToShortDateString(); result.Add(datos); } } catch (Exception Ex) { Console.WriteLine(Ex.Message); Log.Error(Ex.Message); } return(result); }
private void btnGuardar_Click(object sender, RoutedEventArgs e) { string messageBoxText = "¿Está seguro de crear éste maestro avanzado?"; string caption = "Crear maestro avanzado"; MessageBoxButton button = MessageBoxButton.YesNo; MessageBoxImage icon = MessageBoxImage.Information; MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon); svcMOM.MasterOfMasterSvcClient svc = new svcMOM.MasterOfMasterSvcClient(); bool flag = ComprobarNombreColumna(txtbNombreTabla.Text); string mensaje = ""; var listaMA = svc.ListarMAestrosAvanzados(); int countMA = 0; if (flag) { switch (result) { case MessageBoxResult.Yes: int ClavesPrimarias = 0; try { if ((Regex.IsMatch(txtCNombre.Text, @"^[A-Z][0-9a-zA-Z_]+$"))) { mensaje = "El nombre del maestro avanzado no es válido "; } else { if (txtbNombreTabla.Text == "") { MessageBox.Show("Ingrese nombre del maestro avanzado", "Alerta"); } else { if (lista.Count < 2) { mensaje = "Los maestros avanzados deben tener como mínimo dos columnas"; } else { if (chkPN.IsChecked.Value == true && chkPK.IsChecked.Value == true) { mensaje += "La clave primaria no puede permitir valores nulos \n"; } else { if ((chkPK.IsChecked.Value == true) && !(cbTD.Text == "bigint" || cbTD.Text == "int")) { mensaje += "La clave primaria solo puede ser Int o BigInt \n"; } else { // validaciones PK foreach (var item in lista) { if (item.PK) { ClavesPrimarias++; if (!(item.TypeData == "bigint" || item.TypeData == "int")) { mensaje = "La clave primaria solo puede ser de tipo BigInt o Int"; break; } if (item.PN) { mensaje = "La clave primaria no puede permitir valores nulos"; } } } if (ClavesPrimarias == 0) { mensaje = "Debe asignar una clave primaria \n"; } else { if (ClavesPrimarias > 1) { mensaje += "Solo se puede tener una clave primaria, tiene: " + ClavesPrimarias + "\n"; } } } } } } } // fin validaciones pk if (mensaje == "" && ClavesPrimarias == 1 && txtbNombreTabla.Text != "") { Tabla datos = new Tabla(); datos.NombreTabla = txtbNombreTabla.Text; datos.Atributo = ""; foreach (var item in listaMA) { if (item.NombreTabla == datos.NombreTabla) { countMA++; } } if (countMA > 0) { MessageBox.Show("Ya existe un maestro avanzado con este nombre", "Alerta"); } else { foreach (var item in lista) { datos.Atributo += item.NomColumn + " " + item.TypeData; if (!item.PN) { datos.Atributo += " Not Null "; } if (item.PK) { datos.Atributo += " PRIMARY KEY IDENTITY(1,1) "; } if (item != lista[lista.Count - 1]) { datos.Atributo += " , "; } } this.Cursor = Cursors.Wait; do { e.Handled = true; mensaje = svc.CrearTabla(datos); this.Cursor = Cursors.Arrow; } while (this.Cursor.ToString() == "Wait"); pw.CargarMenus(); if (!mensaje.Contains("Error")) { limpiarCampos(); } MessageBox.Show(mensaje, "Información"); } } else { MessageBox.Show(mensaje, "Alerta"); } } catch (Exception Ex) { Log.Error(Ex.Message); Console.WriteLine(Ex.Message); } break; case MessageBoxResult.No: break; default: break; } } else { MessageBox.Show("El nombre del maestro avanzado no es válido", "Alerta"); } }