//крч здесь заполнишь все значения сам public static void AddInfoBox(BoxDataResponse boxData) { //Name = boxData.Name; SmartBoxId = boxData.Id; IsOpenedDoor = boxData.IsOpenedBox; Weight = boxData.Weight; Light = boxData.Light; Code = boxData.Code; Temperature = boxData.Temperature; Wetness = boxData.Wetness; BatteryPower = boxData.BatteryPower; BoxState = boxData.BoxState; }
private async void GetInfoAboutBox(string dir_path) { try { ContainerResponse container = new ContainerResponse(); //извлечение данных контейнера из файла //using (FileStream fs = new FileStream(dir_path + "box_data.txt", FileMode.OpenOrCreate)) //{ // container = await System.Text.Json.JsonSerializer.DeserializeAsync<ContainerResponse>(fs); //} //пример чтения данных с файла string file_data_remember; using (FileStream file = new FileStream(dir_path + "box_data.txt", FileMode.Open, FileAccess.Read)) { // преобразуем строку в байты byte[] array = new byte[file.Length]; // считываем данные file.Read(array, 0, array.Length); // декодируем байты в строку file_data_remember = Encoding.Default.GetString(array); file.Close(); } container = JsonConvert.DeserializeObject <ContainerResponse>(file_data_remember); string name = container.Name;//!!!! //if(s_payment.Text == "Оплачено") //{ var myHttpClient = new HttpClient(); var uri = new Uri("http://iot.tmc-centert.ru/api/container/getbox?id=" + container.SmartBoxId); HttpResponseMessage response = await myHttpClient.GetAsync(uri); AuthApiData <BoxDataResponse> o_data = new AuthApiData <BoxDataResponse>(); string s_result; using (HttpContent responseContent = response.Content) { s_result = await responseContent.ReadAsStringAsync(); } o_data = JsonConvert.DeserializeObject <AuthApiData <BoxDataResponse> >(s_result); if (response.StatusCode == HttpStatusCode.OK) { if (o_data.Status == "0") { Toast.MakeText(this, o_data.Message, ToastLength.Long).Show(); BoxDataResponse exported_data = new BoxDataResponse(); exported_data = o_data.ResponseData; StaticBox.AddInfoBox(exported_data); //добавляем инфу о найденном контейнере //container_name.Text = exported_data.Name.ToString(); //container_name.Text = name; s_temperature.Text = exported_data.Temperature; s_light.Text = exported_data.Light.ToString(); s_humidity.Text = exported_data.Wetness; StaticBox.Longitude = exported_data.Longitude; StaticBox.Latitude = exported_data.Latitude; s_longitude.Text = StaticBox.Longitude.ToString(); s_latitude.Text = StaticBox.Latitude.ToString(); //coordinates lat lon s_weight.Text = "100.0"; //progressBar.Progress = 6; Text3.Text = "ПИН-код доступа отобразится после оплаты"; //status_view.Text = "6. Ожидание выгрузки"; if (s_payment.Text == "Оплачено") { s_pin_access_code.Text = (exported_data.Code == null) ? "0000" : "1324";// !!!! } else { s_pin_access_code.Text = "****"; } if (exported_data.IsOpenedDoor.ToString() == "true") { s_lock_unlock_door.Text = "разблокирована"; } else { s_lock_unlock_door.Text = "заблокирована"; } s_cost.Text = "39537.5"; //var boxState = s_open_close_container.Text; //var doorState = s_lock_unlock_door.Text; } else { Toast.MakeText(this, o_data.Message, ToastLength.Long).Show(); } } //else if(s_payment.Text == "Не оплачено") //{ // s_temperature.Text = "****"; // s_light.Text = "****"; // s_humidity.Text = "****"; // s_weight.Text = "****"; // s_pin_access_code.Text = "****"; // s_lock_unlock_door.Text = "****"; // s_cost.Text = "1000"; // container_name.Text = name; // s_latitude.Text = "****"; // s_longitude.Text = "****"; //} } catch (Exception ex) { Toast.MakeText(this, "" + ex.Message, ToastLength.Long).Show(); } }
/// <summary> /// сбор информации о контейнере /// </summary> /// <param name="dir_path"></param> private async void GetInfoAboutBox(string dir_path) { try { ContainerResponse container = new ContainerResponse(); //извлечение данных контейнера из файла //using (FileStream fs = new FileStream(dir_path + "box_data.txt", FileMode.OpenOrCreate)) //{ // container = await System.Text.Json.JsonSerializer.DeserializeAsync<ContainerResponse>(fs); //} //пример чтения данных с файла string file_data_remember; using (FileStream file = new FileStream(dir_path + "box_data.txt", FileMode.Open, FileAccess.Read)) { // преобразуем строку в байты byte[] array = new byte[file.Length]; // считываем данные file.Read(array, 0, array.Length); // декодируем байты в строку file_data_remember = Encoding.Default.GetString(array); file.Close(); } container = JsonConvert.DeserializeObject <ContainerResponse>(file_data_remember); var myHttpClient = new HttpClient(); var uri = new Uri("http://iot.tmc-centert.ru/api/container/getbox?id=" + container.SmartBoxId); HttpResponseMessage response = await myHttpClient.GetAsync(uri); AuthApiData <BoxDataResponse> o_data = new AuthApiData <BoxDataResponse>(); string s_result; using (HttpContent responseContent = response.Content) { s_result = await responseContent.ReadAsStringAsync(); } o_data = JsonConvert.DeserializeObject <AuthApiData <BoxDataResponse> >(s_result);// !!!! if (response.StatusCode == HttpStatusCode.OK) { if (o_data.Status == "0") { Toast.MakeText(this, o_data.Message, ToastLength.Long).Show(); BoxDataResponse exported_data = new BoxDataResponse(); exported_data = o_data.ResponseData; StaticBox.AddInfoBox(exported_data); //добавляем инфу о найденном контейнере container_name.Text = container.Name; s_open_close_container.Text = /*(exported_data.IsOpenedBox == false) ? "закрыт" : "раскрыт";*/ "открыт"; //s_weight.Text = exported_data.Weight.Replace(",","."); s_weight.Text = "100.0"; s_lock_unlock_door.Text = (exported_data.IsOpenedDoor == false) ? "заблокирована" : "разблокирована"; //progressBar.Progress = 6; //status_view.Text = "6. Ожидание выгрузки"; var boxState = s_open_close_container.Text; var doorState = s_lock_unlock_door.Text; if (exported_data.BoxState == ContainerState.onBase) { a_situation = "На складе"; } else if (exported_data.BoxState == ContainerState.onCar) { a_situation = "На автомобиле"; } else if (exported_data.BoxState == ContainerState.onConsignee) { a_situation = "Выгруженным у грузоотправителя"; } else if (exported_data.BoxState == ContainerState.onShipper) { a_situation = "После разгрузки у грузополучателя"; } s_temperature.Text = exported_data.Temperature.Replace(",", "."); s_light.Text = exported_data.Light.ToString(); s_humidity.Text = exported_data.Wetness.Replace(",", "."); s_battery.Text = exported_data.BatteryPower.Replace(",", "."); btn_lock_unlock_door.Text = "Заблокировать/Разблокировать"; s_signal_strength.Text = "Хороший"; } else { Toast.MakeText(this, o_data.Message, ToastLength.Long).Show(); } } } catch (Exception ex) { Toast.MakeText(this, "" + ex.Message, ToastLength.Long).Show(); } }