//Este metodo carga la lista de Entidades y a su vez llama a cargarAcreditacionesEnEntidades para llenar //la lista de Acreditaciones. public void cargarListaEntidades() { lisEntidades.DataSource = null; lisEntidades.Items.Clear(); if (listEnt.Count <= 0) { con.Connect(); dsEntidades = con.fillDs("SELECT * FROM ENTIDADES", "ENTIDADES"); if (dsEntidades.Tables[0].Rows.Count > 0) { foreach (DataRow dr in dsEntidades.Tables[0].Rows) { Entidad ent = new Entidad(); ent.pCp = Convert.ToInt32(dr["cp"]); ent.pCuit = Convert.ToString(dr["cuit"]); ent.pDireccion = Convert.ToString(dr["direccion"]); ent.pEmail = Convert.ToString(dr["email"]); ent.pId_departamento = Convert.ToInt32(dr["id_departamento"]); ent.pId_localidad = Convert.ToInt32(dr["id_localidad"]); ent.pId_provincia = Convert.ToInt32(dr["id_provincia"]); ent.pNombre = Convert.ToString(dr["nombre"]); ent.pTel = Convert.ToString(dr["tel"]); listEnt.Add(ent); } foreach (Entidad ent in listEnt) { lisEntidades.Items.Add(ent); } lisEntidades.DisplayMember = "pNombre"; cargarAcreditacionesEnEntidades(listEnt); cargarCamposDesdeLista(0); cargarProvincias(); cargarDepartamentos(listEnt[0].pId_provincia.ToString()); cargarCiudades(listEnt[0].pId_departamento.ToString()); seleccionarProvincia(listEnt[0].pId_provincia.ToString()); selecctionarDepartamento(listEnt[0].pId_departamento.ToString()); seleccionarLocalidad(listEnt[0].pId_localidad.ToString()); } } }
public bool removerEntidad(Entidad ent) { string cuit = ent.pCuit; lisEntidades.Items.Remove(ent); listEnt.Remove(ent); con.modifyData("DELETE FROM ENTIDADES WHERE cuit = '" + cuit + "';"); return true; }
public bool actualizarEntidad() { bool estadoOk = false; Entidad ent = new Entidad(); String errores = ""; if (String.IsNullOrEmpty(txtNombre.Text)) { errores += "- Debe completar el nombre de la empresa \n"; estadoOk = false; } else { estadoOk = true; } if (String.IsNullOrEmpty(txtCuit.Text) || txtCuit.TextLength < 13) { errores += "- Debe indicar un CUIT en el formato correcto \n"; estadoOk = false; } else { estadoOk = true; } if (estadoOk) { ent.pNombre = txtNombre.Text; if (!String.IsNullOrEmpty(txtCp.Text)) ent.pCp = Convert.ToInt32(txtCp.Text); ent.pCuit = txtCuit.Text; ent.pDireccion = txtDireccion.Text; ent.pEmail = txtEmail.Text; ent.pTel = txtTel.Text; ent.pId_provincia = Convert.ToInt32(cboProvincia.SelectedValue); ent.pId_departamento = Convert.ToInt32(cboDepartamento.SelectedValue); ent.pId_localidad = Convert.ToInt32(cboCiudad.SelectedValue); if (txtCuit.Enabled) { con.modifyData("INSERT INTO ENTIDADES VALUES('" + ent.pCuit + "','" + ent.pNombre + "'," + ent.pId_provincia + "," + ent.pId_departamento + "," + ent.pId_localidad + ",'" + ent.pTel + "','" + ent.pCp + "','" + ent.pEmail + "','" + ent.pDireccion + "');"); if (lisAcreditaciones.Items.Count > 0) { ent.pAcreditaciones = new List<Acreditacion>(); DataSet ds = new DataSet(); int maxAcr = 0; con.Connect(); ds = con.fillDs("SELECT * FROM ACREDITACIONES;", "ALL_ACREDITACIONES"); foreach (DataRow dr in ds.Tables[0].Rows) { int current = Convert.ToInt32(dr["id_acreditacion"].ToString()); if (current > maxAcr) maxAcr = current; } for (int i = 0; i < lisAcreditaciones.Items.Count; i++) { maxAcr++; Acreditacion acr = new Acreditacion(); acr = (Acreditacion)lisAcreditaciones.Items[i]; acr.pIdAcreditacion = Convert.ToString(maxAcr); ent.pAcreditaciones.Add(acr); Console.WriteLine("INSERT INTO ACREDITACIONES VALUES ('" + acr.pIdAcreditacion + "','" + acr.pIdEmpresa + "','" + acr.pPathAcreditacion + "');"); con.modifyData("INSERT INTO ACREDITACIONES VALUES ('" + acr.pIdAcreditacion + "','" + acr.pIdEmpresa + "','" + acr.pPathAcreditacion + "');"); } } listEnt.Add(ent); lisEntidades.Items.Add(ent); return true; } else { int i = lisEntidades.SelectedIndex; listEnt[i].pNombre = txtNombre.Text; listEnt[i].pCp = Convert.ToInt32(txtCp.Text); listEnt[i].pCuit = txtCuit.Text; listEnt[i].pDireccion = txtDireccion.Text; listEnt[i].pEmail = txtEmail.Text; listEnt[i].pTel = txtTel.Text; listEnt[i].pId_provincia = Convert.ToInt32(cboProvincia.SelectedValue); listEnt[i].pId_departamento = Convert.ToInt32(cboDepartamento.SelectedValue); listEnt[i].pId_localidad = Convert.ToInt32(cboCiudad.SelectedValue); con.modifyData("UPDATE ENTIDADES SET nombre='" + listEnt[i].pNombre + "'," + "id_provincia=" + listEnt[i].pId_provincia + ", " + "id_departamento=" + listEnt[i].pId_departamento + ", " + "id_localidad=" + listEnt[i].pId_localidad + ", " + "tel='" + listEnt[i].pTel + "'," + "cp='" + listEnt[i].pCp + "'," + "email='" + listEnt[i].pEmail + "'," + "direccion='" + listEnt[i].pDireccion + "' WHERE cuit = '" + listEnt[i].pCuit + "';"); Console.WriteLine("UPDATE ENTIDADES SET nombre='" + listEnt[i].pNombre + "'," + "id_provincia=" + listEnt[i].pId_provincia + ", " + "id_departamento=" + listEnt[i].pId_departamento + ", " + "id_localidad=" + listEnt[i].pId_localidad + ", " + "tel='" + listEnt[i].pTel + "'," + "cp='" + listEnt[i].pCp + "'," + "email='" + listEnt[i].pEmail + "'," + "direccion='" + listEnt[i].pDireccion + "' WHERE cuit = '" + listEnt[i].pCuit + "';"); if (lisAcreditaciones.Items.Count > 0) { listEnt[i].pAcreditaciones = new List<Acreditacion>(); DataSet ds = new DataSet(); int maxAcr = 0; con.Connect(); ds = con.fillDs("SELECT * FROM ACREDITACIONES;", "ALL_ACREDITACIONES"); foreach (DataRow dr in ds.Tables[0].Rows) { int current = Convert.ToInt32(dr["id_acreditacion"].ToString()); if (current > maxAcr) maxAcr = current; } for (int j = 0; j < lisAcreditaciones.Items.Count; j++) { maxAcr++; Acreditacion acr = new Acreditacion(); acr = (Acreditacion)lisAcreditaciones.Items[i]; if (!listEnt[i].pAcreditaciones.Contains(acr)) { listEnt[i].pAcreditaciones.Add(acr); } } } lisEntidades.DataSource = listEnt; return true; } } MessageBox.Show(errores, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; }