Esempio n. 1
0
        private GetPlantResponse GetPlants()
        {
            GetPlantResponse plants = new GetPlantResponse();

            try
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri("http://localhost:9000/");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.Add("EO-Header", wnd.User + " : " + wnd.Pwd);

                HttpResponseMessage httpResponse =
                    client.GetAsync("api/Login/GetPlants").Result;
                if (httpResponse.IsSuccessStatusCode)
                {
                    Stream       streamData = httpResponse.Content.ReadAsStreamAsync().Result;
                    StreamReader strReader  = new StreamReader(streamData);
                    string       strData    = strReader.ReadToEnd();
                    strReader.Close();
                    plants = JsonConvert.DeserializeObject <GetPlantResponse>(strData);
                }
                else
                {
                    MessageBox.Show("There was an error retreiving plants");
                }
            }
            catch (Exception ex)
            {
            }

            return(plants);
        }
Esempio n. 2
0
        public GetPlantResponse GetPlantsByType(long plantTypeId)
        {
            GetPlantResponse plants = new GetPlantResponse();

            try
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(((App)App.Current).LAN_Address);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.Add("EO-Header", User + " : " + Pwd);

                HttpResponseMessage httpResponse =
                    client.GetAsync("api/Login/GetPlantsByType?plantTypeId=" + plantTypeId).Result;
                if (httpResponse.IsSuccessStatusCode)
                {
                    Stream       streamData = httpResponse.Content.ReadAsStreamAsync().Result;
                    StreamReader strReader  = new StreamReader(streamData);
                    string       strData    = strReader.ReadToEnd();
                    strReader.Close();
                    plants = JsonConvert.DeserializeObject <GetPlantResponse>(strData);
                }
                else
                {
                    MessageBox.Show("There was an error retreiving plants");
                }
            }
            catch (Exception ex)
            {
                Exception ex2 = new Exception("Admin - GetPlantsByType", ex);
                ((App)App.Current).LogError(ex2.Message, "plantTypeId = " + plantTypeId.ToString());
            }

            return(plants);
        }
Esempio n. 3
0
        public async Task <GetPlantResponse> GetPlantsByType(long typeId)
        {
            GenericGetRequest request  = new GenericGetRequest("GetPlantsByType", "plantTypeId", typeId);
            GetPlantResponse  response = await GetRequest <GetPlantResponse>(request);

            return(response);
        }
Esempio n. 4
0
        public async Task <GetPlantResponse> GetPlants()
        {
            GenericGetRequest request  = new GenericGetRequest("GetPlants", String.Empty, 0);
            GetPlantResponse  response = await GetRequest <GetPlantResponse>(request);

            return(response);
        }
Esempio n. 5
0
        public void ShowPlants(GetPlantResponse response)
        {
            plants = response.PlantInventoryList;

            foreach (PlantInventoryDTO p in plants)
            {
                list3.Add(p);
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                plantListView.ItemsSource = list3;

                PlantName.SelectedIndexChanged += PlantName_SelectedIndexChanged;
            });
        }
Esempio n. 6
0
        public PlantPage()
        {
            InitializeComponent();

            plantTypes = GetPlantTypes();

            ObservableCollection <KeyValuePair <long, string> > list1 = new ObservableCollection <KeyValuePair <long, string> >();

            foreach (PlantTypeDTO code in plantTypes)
            {
                list1.Add(new KeyValuePair <long, string>(code.PlantTypeId, code.PlantTypeName));
            }

            this.PlantTypes.ItemsSource = list1;

            //plant names combo is populated after a selection from plant type combo

            serviceCodes = GetServiceCodes();

            ObservableCollection <KeyValuePair <long, string> > list2 = new ObservableCollection <KeyValuePair <long, string> >();

            foreach (ServiceCodeDTO code in serviceCodes)
            {
                list2.Add(new KeyValuePair <long, string>(code.ServiceCodeId, code.ServiceCode + "($ " + code.Price.ToString() + ")"));
            }

            GetPlantResponse p = GetPlants();

            plantList = p.PlantInventoryList;

            foreach (PlantInventoryDTO pDTO in plantList)
            {
                plants.Add(pDTO.Plant);
            }

            foreach (PlantInventoryDTO plant in plantList)
            {
                list3.Add(plant);
            }

            this.PlantInventoryListView.ItemsSource = list3;
        }
Esempio n. 7
0
        private void ShowSelectedPlantTypes(GetPlantResponse response, long selectedValue)
        {
            plants = response.PlantInventoryList;

            ObservableCollection <KeyValuePair <long, string> > list2 = new ObservableCollection <KeyValuePair <long, string> >();

            ObservableCollection <PlantInventoryDTO> pDTO = new ObservableCollection <PlantInventoryDTO>();

            foreach (PlantInventoryDTO p in plants.Where(a => a.Plant.PlantTypeId == selectedValue))
            {
                list2.Add(new KeyValuePair <long, string>(p.Plant.PlantId, p.Plant.PlantName));

                pDTO.Add(p);
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                PlantName.ItemsSource = list2;

                plantListView.ItemsSource = pDTO;
            });
        }
        private void PlantsByTypeLoaded(ObservableCollection <ArrangementInventoryFilteredItem> list1, string name, string size, GetPlantResponse response)
        {
            plants = response.PlantInventoryList;

            List <PlantInventoryDTO> filtered = new List <PlantInventoryDTO>();

            filtered.AddRange(plants);

            if (!String.IsNullOrEmpty(name))
            {
                filtered = plants.Where(a => a.Plant.PlantName.Contains(name)).ToList();
            }

            if (!String.IsNullOrEmpty(size))
            {
                filtered = plants.Where(a => a.Plant.PlantSize.Equals(size)).ToList();
            }

            foreach (PlantInventoryDTO p in filtered)
            {
                list1.Add(new ArrangementInventoryFilteredItem()
                {
                    Id              = p.Inventory.InventoryId,
                    Type            = p.Inventory.InventoryName,
                    InventoryTypeId = p.Inventory.InventoryTypeId,
                    Name            = p.Plant.PlantName,
                    Size            = p.Plant.PlantSize,
                    ServiceCodeId   = p.Inventory.ServiceCodeId,
                    ServiceCode     = p.Inventory.ServiceCodeName,
                    ImageId         = p.ImageId
                });
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                ArrangementInventoryList.ItemsSource = list1;
            });
        }
Esempio n. 9
0
        public void AddPlant()
        {
            long image_id = 0;

            try
            {
                List <string> errorMsgs = new List <string>();

                KeyValuePair <long, string> p = (KeyValuePair <long, string>) this.PlantNames.SelectedValue;

                long   plantNameId            = p.Key;
                String plantName              = p.Value;
                long   selectedPlantTypeIndex = ((KeyValuePair <long, string>) this.PlantTypes.SelectedValue).Key;
                //long selectedServiceCode = ((KeyValuePair<long, string>)this.ServiceCodes.SelectedValue).Key;

                if (String.IsNullOrEmpty(plantName))
                {
                    errorMsgs.Add("You must enter a plant name.");
                }

                if (selectedPlantTypeIndex == 0)
                {
                    errorMsgs.Add("You must select a plant type.");
                }

                //if(selectedServiceCode == 0)
                //{
                //    errorMsgs.Add("You must select a service code.");
                //}

                if (fileStreamContent == null)
                {
                    MessageBoxResult msgBoxResult = MessageBox.Show("Do you want to add an image?");

                    if (msgBoxResult == MessageBoxResult.Yes)
                    {
                        return;
                    }
                }

                if (errorMsgs.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string msg in errorMsgs)
                    {
                        sb.AppendLine(msg);
                    }

                    MessageBox.Show(sb.ToString());
                    return;
                }

                AddPlantRequest addPlantRequest = new AddPlantRequest();

                //save image if the user has selected one
                if (fileStreamContent != null)
                {
                    var url = "http://localhost:9000/api/Login/UploadPlantImage";
                    fileStreamContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
                    {
                        Name = "file", FileName = fileName
                    };
                    fileStreamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
                    using (var client1 = new HttpClient())
                    {
                        using (var formData = new MultipartFormDataContent())
                        {
                            client1.DefaultRequestHeaders.Add("EO-Header", wnd.User + " : " + wnd.Pwd);

                            formData.Add(fileStreamContent);
                            var    response   = client1.PostAsync(url, formData).Result;
                            string strImageId = response.Content.ReadAsStringAsync().Result;

                            Int64.TryParse(strImageId, out image_id);
                        }
                    }
                }

                PlantDTO pDTO = new PlantDTO();
                pDTO.PlantName        = plantName;
                pDTO.PlantTypeId      = selectedPlantTypeIndex;
                addPlantRequest.Plant = pDTO;

                InventoryDTO iDTO = new InventoryDTO();
                iDTO.InventoryName   = plantName;
                iDTO.InventoryTypeId = 1; //"Plants"
                //iDTO.ServiceCodeId = selectedServiceCode;

                addPlantRequest.Plant     = pDTO;
                addPlantRequest.Inventory = iDTO;
                if (image_id > 0)
                {
                    addPlantRequest.ImageId = image_id;
                }

                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(((App)App.Current).LAN_Address);
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.Add("EO-Header", wnd.User + " : " + wnd.Pwd);

                string jsonData = JsonConvert.SerializeObject(addPlantRequest);
                var    content  = new StringContent(jsonData, Encoding.UTF8, "application/json");
                HttpResponseMessage httpResponse = client.PostAsync("api/Login/AddPlant", content).Result;
                if (httpResponse.IsSuccessStatusCode)
                {
                    Stream       streamData = httpResponse.Content.ReadAsStreamAsync().Result;
                    StreamReader strReader  = new StreamReader(streamData);
                    string       strData    = strReader.ReadToEnd();
                    strReader.Close();
                    GetPlantResponse apiResponse = JsonConvert.DeserializeObject <GetPlantResponse>(strData);

                    if (apiResponse.Messages.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (KeyValuePair <string, List <string> > messages in apiResponse.Messages)
                        {
                            foreach (string msg in messages.Value)
                            {
                                sb.AppendLine(msg);
                            }
                        }

                        MessageBox.Show(sb.ToString());
                    }
                    else
                    {
                        list3.Add(apiResponse.PlantInventoryList.First());
                        this.PlantInventoryListView.ItemsSource = null;
                        this.PlantInventoryListView.ItemsSource = list3;
                    }
                }
                else
                {
                    MessageBox.Show("Error adding plant");
                }

                fileStreamContent = null;
            }
            catch (Exception ex)
            {
            }
        }