Beispiel #1
0
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GetUPCONFIG //
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FILE WRITING ->
 public void SavingJsonFile(string filename, DeviceAppDataes 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();
     }
 }
Beispiel #2
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GetUPCONFIG //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FILE READING ->
        public DeviceAppDataes ReadingJsonFile(string filename)
        {
            JObject         jsonentidad = null;
            DeviceAppDataes entidad     = null;

            if (File.Exists(FILE_PATH + filename + ".json"))
            {
                // Lee Archivo JSON
                jsonentidad = JObject.Parse(File.ReadAllText(FILE_PATH + filename + ".json"));
                entidad     = jsonentidad.ToObject <DeviceAppDataes>();
            }
            return(entidad);
        }
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ALMACENAR DATOS ENTIDAD
        private void almacenarDatosEntidad()
        {
            DeviceAppDataes entidad = asignDataFormToEntity();

            if (entidad != null)
            {
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://api.eevapp.es/api/UPCONFIG");
                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;
        }
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DATOS ENTIDAD a FORM
        private void loadDataToForm()
        {
            DeviceAppDataes entidad = null;
            // Lee Archivo JSON desde servidor
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://api.eevapp.es/api/UPCONFIG");

            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 <DeviceAppDataes>();
            }
            catch (Exception ex) { Debug.Write(ex.ToString()); }
            // Asigna datos a formulario
            if (entidad != null)
            {
                if (entidad.m_GPS == 1)
                {
                    checkBoxGPS.Checked = true;
                }
            }
            if (entidad != null)
            {
                if (entidad.m_Sound == 1)
                {
                    checkBoxSound.Checked = true;
                }
            }
            if (entidad != null)
            {
                comboBoxLang.SelectedIndex = (int)entidad.m_Lang;
            }
            if (entidad != null)
            {
                textBoxUpdate.Text = entidad.m_Update.ToString();
            }
            else
            {
                textBoxUpdate.Text = "12";
            }
            if (entidad != null)
            {
                if (entidad.m_LongAlertAct == 1)
                {
                    checkBoxLongAlertAct.Checked = true;
                }
            }
            if (entidad != null)
            {
                textBoxLongAlert.Text = entidad.m_LongAlert.ToString();
            }
            else
            {
                textBoxLongAlert.Text = "24";
            }
            if (entidad != null)
            {
                if (entidad.m_ShortAlertAct == 1)
                {
                    checkBoxShortAlertAct.Checked = true;
                }
            }
            if (entidad != null)
            {
                textBoxShortAlert.Text = entidad.m_ShortAlert.ToString();
            }
            else
            {
                textBoxShortAlert.Text = "2";
            }
            if (entidad != null)
            {
                textBoxAlertFromHH.Text = entidad.m_AlertFromHH.ToString();
            }
            else
            {
                textBoxAlertFromHH.Text = "10";
            }
            if (entidad != null)
            {
                textBoxAlertFromMM.Text = entidad.m_AlertFromMM.ToString();
            }
            else
            {
                textBoxAlertFromMM.Text = "00";
            }
            if (entidad != null)
            {
                textBoxAlertToHH.Text = entidad.m_AlertToHH.ToString();
            }
            else
            {
                textBoxAlertToHH.Text = "20";
            }
            if (entidad != null)
            {
                textBoxAlertToMM.Text = entidad.m_AlertToMM.ToString();
            }
            else
            {
                textBoxAlertToMM.Text = "00";
            }
            isModified = false;
        }
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DATOS FORM a ENTIDAD
        private DeviceAppDataes asignDataFormToEntity()
        {
            DeviceAppDataes entidad = new DeviceAppDataes();

            if (entidad != null && esEntero(textBoxUpdate, 1, 72))
            {
                entidad.m_Update = int.Parse(textBoxUpdate.Text);
            }
            else
            {
                entidad = null;
            }
            if (entidad != null && esEntero(textBoxLongAlert, 24, 72))
            {
                entidad.m_LongAlert = int.Parse(textBoxLongAlert.Text);
            }
            else
            {
                entidad = null;
            }
            if (entidad != null && esEntero(textBoxShortAlert, 0, 23))
            {
                entidad.m_ShortAlert = int.Parse(textBoxShortAlert.Text);
            }
            else
            {
                entidad = null;
            }
            if (entidad != null && esEntero(textBoxAlertFromHH, 0, 23))
            {
                entidad.m_AlertFromHH = int.Parse(textBoxAlertFromHH.Text);
            }
            else
            {
                entidad = null;
            }
            if (entidad != null && esEntero(textBoxAlertFromMM, 0, 59))
            {
                entidad.m_AlertFromMM = int.Parse(textBoxAlertFromMM.Text);
            }
            else
            {
                entidad = null;
            }
            if (entidad != null && esEntero(textBoxAlertToHH, 0, 23))
            {
                entidad.m_AlertToHH = int.Parse(textBoxAlertToHH.Text);
            }
            else
            {
                entidad = null;
            }
            if (entidad != null && esEntero(textBoxAlertToMM, 0, 59))
            {
                entidad.m_AlertToMM = int.Parse(textBoxAlertToMM.Text);
            }
            else
            {
                entidad = null;
            }
            if (entidad != null)
            {
                if (checkBoxGPS.Checked == true)
                {
                    entidad.m_GPS = 1;
                }
                else
                {
                    entidad.m_GPS = 0;
                }
                if (checkBoxSound.Checked == true)
                {
                    entidad.m_Sound = 1;
                }
                else
                {
                    entidad.m_Sound = 0;
                }
                entidad.m_Lang = (int)comboBoxLang.SelectedIndex;
                if (checkBoxLongAlertAct.Checked == true)
                {
                    entidad.m_LongAlertAct = 1;
                }
                else
                {
                    entidad.m_LongAlertAct = 0;
                }
                if (checkBoxShortAlertAct.Checked == true)
                {
                    entidad.m_ShortAlertAct = 1;
                }
                else
                {
                    entidad.m_ShortAlertAct = 0;
                }
            }
            return(entidad);
        }
Beispiel #6
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FILE READING //


        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PostUPCONFIG ->
        public void PostUPCONFIG(DeviceAppDataes _entity)
        {
            SavingJsonFile("config", _entity);
        }
Beispiel #7
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GetUPCONFIG ->
        public DeviceAppDataes GetUPCONFIG()
        {
            DeviceAppDataes retu = ReadingJsonFile("config");

            return(retu);
        }