コード例 #1
0
ファイル: Query.cs プロジェクト: sean-scott/inventory
        public async static Task <bool> Update(Item item)
        {
            using (var client = new HttpClient())
            {
                var values = new Dictionary <string, string>
                {
                    { "id", item.ID.ToString() },
                    { "barcode", item.Barcode },
                    { "imageFileName", item.ImageFilename },
                    { "name", item.Name },
                    { "datePurchased", item.DatePurchased.ToString("yyyy-MM-dd") },
                    { "quantity", item.Quantity.ToString() },
                    { "value", item.Value.ToString() },
                    { "location", item.Location },
                    { "category", item.Category },
                    { "notes", item.Notes }
                };

                var content  = new MyFormUrlEncodedContent(values);
                var response = await client.PostAsync("http://192.168.1.133/inventory/updateItem.php", content);

                var responseString = await response.Content.ReadAsStringAsync();

                bool b = responseString == "\\1";

                return(b);
            }
        }
コード例 #2
0
ファイル: Query.cs プロジェクト: sean-scott/inventory
        public async static Task <bool> AddItemAsProduct(JObject product)
        {
            string   dateString = (string)product["datePurchased"];
            DateTime datePurchased;


            if (string.IsNullOrEmpty(dateString))
            {
                datePurchased = new DateTime(1, 1, 1);
            }
            else
            {
                datePurchased = DateTime.Parse(dateString);

                if (datePurchased.Year == 1)
                {
                    datePurchased = DateTime.Today;
                }
            }

            using (var client = new HttpClient())
            {
                var values = new Dictionary <string, string>
                {
                    { "hid", Core.HouseID.ToString() },
                    { "barcode", (string)product["barcode"] },
                    { "imageFileName", null },
                    { "name", (string)product["name"] },
                    { "datePurchased", datePurchased.ToString("yyyy-MM-dd") },
                    { "quantity", (string)product["quantity"] },
                    { "value", (string)product["value"] },
                    { "location", (string)product["location"] },
                    { "category", (string)product["category"] },
                    { "notes", (string)product["notes"] }
                };

                var content = new MyFormUrlEncodedContent(values);

                var response = await client.PostAsync("http://192.168.1.133/inventory/addItem.php", content);

                var responseString = await response.Content.ReadAsStringAsync();

                bool b = responseString == "1";

                return(b);
            }
        }
コード例 #3
0
ファイル: Query.cs プロジェクト: sean-scott/inventory
        public async static Task UploadImage(string filename, byte[] imageData)
        {
            using (var client = new HttpClient())
            {
                var values = new Dictionary <string, string>
                {
                    { "filename", filename },
                    { "imageData", Convert.ToBase64String(imageData) }
                };

                var content = new MyFormUrlEncodedContent(values);

                var response = await client.PostAsync("http://192.168.1.133/inventory/uploadImage.php", content);

                var responseString = await response.Content.ReadAsStringAsync();
            }
        }
コード例 #4
0
ファイル: Query.cs プロジェクト: sean-scott/inventory
        public async static Task <byte[]> GetImage(string filename)
        {
            using (var client = new HttpClient())
            {
                var values = new Dictionary <string, string>
                {
                    { "filename", filename }
                };

                var content = new MyFormUrlEncodedContent(values);

                var response = await client.PostAsync("http://192.168.1.133/inventory/getImage.php", content);

                var bytes = await response.Content.ReadAsByteArrayAsync();

                return(bytes);
            }
        }
コード例 #5
0
ファイル: Query.cs プロジェクト: sean-scott/inventory
        public async static Task <bool> DeleteItem(int id)
        {
            using (var client = new HttpClient())
            {
                var values = new Dictionary <string, string>
                {
                    { "id", id.ToString() }
                };

                var content  = new MyFormUrlEncodedContent(values);
                var response = await client.PostAsync("http://192.168.1.133/inventory/deleteItem.php", content);

                var responseString = await response.Content.ReadAsStringAsync();

                bool b = responseString == "1";

                return(b);
            }
        }
コード例 #6
0
    private static byte[] GetContentByteArray(IEnumerable <KeyValuePair <string, string> > nameValueCollection)
    {
        if (nameValueCollection == null)
        {
            throw new ArgumentNullException("nameValueCollection");
        }
        StringBuilder stringBuilder = new StringBuilder();

        foreach (KeyValuePair <string, string> current in nameValueCollection)
        {
            if (stringBuilder.Length > 0)
            {
                stringBuilder.Append('&');
            }

            stringBuilder.Append(MyFormUrlEncodedContent.Encode(current.Key));
            stringBuilder.Append('=');
            stringBuilder.Append(MyFormUrlEncodedContent.Encode(current.Value));
        }
        return(Encoding.Default.GetBytes(stringBuilder.ToString()));
    }
コード例 #7
0
ファイル: Query.cs プロジェクト: sean-scott/inventory
 public MyFormUrlEncodedContent(IEnumerable <KeyValuePair <string, string> > nameValueCollection)
     : base(MyFormUrlEncodedContent.GetContentByteArray(nameValueCollection))
 {
     base.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
 }