// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DATOS ENTIDAD a FORM private void loadDataToForm() { // carga comunidades y provincias bindingSourceComunidades.DataSource = DBAccess.ComunidadesORM.SelectAllEntidades(); bindingSourceProvincias.DataSource = ((CCAA)comboBoxComunidad.SelectedItem).PROVINCIAS.ToList(); AsociationDataes entidad = null; // Lee Archivo JSON desde servidor var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://api.eevapp.es/api/UPDATAS"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "GET"; var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); try { StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()); string result = (String)streamReader.ReadToEnd(); JObject jsonentidad = JObject.Parse(result); entidad = jsonentidad.ToObject <AsociationDataes>(); } catch (Exception ex) { Debug.Write(ex.ToString()); } // Asigna datos a formulario textBoxNombre.Text = entidad.m_Nombre; textBoxCIF.Text = entidad.m_CIF; textBoxTelefono.Text = entidad.m_Telefono; textBoxDireccion.Text = entidad.m_Direccion; textBoxCiudad.Text = entidad.m_Ciudad; textBoxCodigoPostal.Text = entidad.m_CodigoPostal; comboBoxComunidad.SelectedValue = entidad.m_IdComunidad; comboBoxProvincia.SelectedValue = entidad.m_IdProvincia; textBoxEmail.Text = entidad.m_Email; textBoxWeb.Text = entidad.m_Web; textBoxRGPD.Text = entidad.m_RGPD; isModified = false; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GetUPCONFIG // // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FILE WRITING -> public void SavingJsonFile(string filename, AsociationDataes entidad) { if (entidad != null) { JObject jsonentidad = (JObject)JToken.FromObject(entidad); StreamWriter fichero = File.CreateText(FILE_PATH + filename + ".json"); JsonTextWriter jsonwriter = new JsonTextWriter(fichero); jsonentidad.WriteTo(jsonwriter); jsonwriter.Close(); } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GetUPCONFIG // // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FILE READING -> public AsociationDataes ReadingJsonFile(string filename) { JObject jsonentidad = null; AsociationDataes entidad = null; if (File.Exists(FILE_PATH + filename + ".json")) { // Lee Archivo JSON jsonentidad = JObject.Parse(File.ReadAllText(FILE_PATH + filename + ".json")); entidad = jsonentidad.ToObject <AsociationDataes>(); } return(entidad); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DATOS FORM a ENTIDAD private AsociationDataes asignDataFormToEntity() { AsociationDataes entidad = new AsociationDataes(); entidad.m_Nombre = textBoxNombre.Text; entidad.m_CIF = textBoxCIF.Text; entidad.m_Telefono = textBoxTelefono.Text; entidad.m_Direccion = textBoxDireccion.Text; entidad.m_Ciudad = textBoxCiudad.Text; entidad.m_CodigoPostal = textBoxCodigoPostal.Text; entidad.m_IdComunidad = ((CCAA)comboBoxComunidad.SelectedItem).id; entidad.m_IdProvincia = ((PROVINCIAS)comboBoxProvincia.SelectedItem).id; entidad.m_Email = textBoxEmail.Text; entidad.m_Web = textBoxWeb.Text; entidad.m_RGPD = textBoxRGPD.Text; entidad.m_UserModif = Publica.usuario; DateTime nowmismo = DateTime.Now; entidad.m_LastModif = new int[] { nowmismo.Year, nowmismo.Month, nowmismo.Day, nowmismo.Hour, nowmismo.Minute, nowmismo.Second }; return(entidad); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ALMACENAR DATOS ENTIDAD private void almacenarDatosEntidad() { AsociationDataes entidad = asignDataFormToEntity(); if (entidad != null) { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://api.eevapp.es/api/UPDATAS"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = WebRequestMethods.Http.Post; try { JObject jsonentidad = (JObject)JToken.FromObject(entidad); StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()); streamWriter.Write(jsonentidad); streamWriter.Close(); var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); MessageBox.Show("Datos almacenados correctamente...", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } isModified = false; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FILE READING // // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PostUPCONFIG -> public void PostUPCONFIG(AsociationDataes _entity) { SavingJsonFile("datas", _entity); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GetUPCONFIG -> public AsociationDataes GetUPCONFIG() { AsociationDataes retu = ReadingJsonFile("datas"); return(retu); }