コード例 #1
0
        public async void StoreAll()
        {
            ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
            if (connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
            {
                busyindicator.IsActive = true;
                //await LoadInAppPurchaseProxyFileAsync();
                try
                {
                    var client = new Windows.Web.Http.HttpClient();
                    string urlPath = "http://mhndt.com/newsstand/renungan-harian/callback/allWinItems";
                    var values = new List<KeyValuePair<string, string>>
                    {
                        //new KeyValuePair<string, string>("hal", "1"),
                        //new KeyValuePair<string, string>("limit","300")
                    };

                    var response = await client.PostAsync(new Uri(urlPath), new Windows.Web.Http.HttpFormUrlEncodedContent(values));
                    response.EnsureSuccessStatusCode();

                    if (!response.IsSuccessStatusCode)
                    {
                        RequestException();
                    }

                    string jsonText = await response.Content.ReadAsStringAsync();
                    JsonObject jsonObject = JsonObject.Parse(jsonText);
                    JsonArray jsonData1 = jsonObject["data"].GetArray();

                    foreach (JsonValue groupValue in jsonData1)
                    {
                        JsonObject groupObject = groupValue.GetObject();
                        string bundleName = "";
                        string pathFile = "";

                        string nid = groupObject["sku"].GetString();
                        string title = groupObject["judul"].GetString();
                        string deskripsi = groupObject["deskripsi"].GetString();
                        string tanggal = groupObject["tgl"].GetString();
                        string tipe = groupObject["tipe"].GetString();
                        string namaTipe = groupObject["nama_tipe"].GetString();
                        string gratis = groupObject["gratis"].GetString();
                        string dataFile = groupObject["nfile"].GetString();
                        string harga = groupObject["hrg"].GetString();
                        var bundleObj = groupObject["bundle"];

                        BukuAudio file = new BukuAudio();

                        file.BundleName = new List<string>();
                        file.BundlePath = new List<string>();
                        if (bundleObj.ValueType == JsonValueType.Array)
                        {
                            JsonArray bundle = bundleObj.GetArray();
                            foreach (JsonValue groupValue1 in bundle)
                            {
                                JsonObject groupObject1 = groupValue1.GetObject();

                                bundleName = groupObject1["bundle_file"].GetString();
                                pathFile = groupObject1["path_file"].GetString();

                                file.BundleName.Add(bundleName);
                                file.Tipe = tipe;
                                if (file.Tipe == "0")
                                {
                                    file.BundlePath.Add(pathFile + bundleName + ".pdf");
                                    //file.BundlePath = pathFile + bundleName + ".pdf";
                                }
                                else if (file.Tipe == "1")
                                {
                                    file.BundlePath.Add(pathFile + bundleName);
                                    //file.BundlePath = pathFile + bundleName;
                                }
                            }
                        }

                        file.SKU = nid;
                        file.Judul = title;
                        file.Deskripsi = deskripsi;

                        string[] formats = { "d MMMM yyyy" };
                        var dateTime = DateTime.ParseExact(tanggal, formats, new CultureInfo("id-ID"), DateTimeStyles.None);

                        Int64 n = Int64.Parse(dateTime.ToString("yyyyMMdd"));
                        file.Tanggal = n.ToString();
                        int tgl = Int32.Parse(file.Tanggal);
                        //file.Tipe = tipe;
                        file.NamaTipe = "Tipe: " + namaTipe;
                        file.Gratis = gratis;
                        file.File = "http://mhndt.com/newsstand/rh/item/" + dataFile;
                        file.Cover = "http://mhndt.com/newsstand/rh/item/" + dataFile + ".jpg";

                        if (licenseInformation.ProductLicenses[file.SKU].IsActive)
                        {
                            file.Harga = "Purchased";
                        }
                        else
                        {
                            if (file.Gratis == "1")
                            {
                                file.Harga = "Free";
                            }
                            else
                            {
                                file.Harga = harga;
                            }
                        }

                        if (bundleObj.ValueType == JsonValueType.Array && tgl >= 20150301
                            || file.Judul == "Renungan Harian Tahunan VII"
                            || file.Judul == "Edisi Tahunan VI" || file.Judul == "RH Anak Volume 01 : Yesus Sahabatku")
                        {
                            datasource.Add(file);
                        }
                    }

                    if (jsonData1.Count > 0)
                    {
                        itemGridView.ItemsSource = datasource;
                    }
                    else
                    {
                        MessageDialog messageDialog;
                        messageDialog = new MessageDialog("Data kosong", "Buku atau Audio Tidak tersedia");
                        messageDialog.Commands.Add(new UICommand("Tutup", (command) =>
                        {
                            this.Frame.Navigate(typeof(MainPage));
                        }));
                        await messageDialog.ShowAsync();
                    }
                }
                catch (HttpRequestException ex)
                {
                    RequestException();
                    busyindicator.IsActive = false;
                }
            }
            else
            {
                ConnectionException();
                busyindicator.IsActive = false;
            }
        }
コード例 #2
0
 private void ItemView_ItemClick(object sender, ItemClickEventArgs e)
 {
     ProductDetail.IsOpen = true;
     itemDetail = e.ClickedItem as BukuAudio;
     //Debug.WriteLine("id:" + e.ClickedItem);
     DetailCover.Source = new BitmapImage(new Uri(itemDetail.Cover, UriKind.Absolute));
     DetailJudul.Text = itemDetail.Judul;
     DetailDeskripsi.Text = itemDetail.Deskripsi;
     DetailSKU.Text = itemDetail.SKU;
     DetailHarga.Text = itemDetail.Harga;
     DetailFree.Text = itemDetail.Gratis;
     DetailTipe.Text = itemDetail.Tipe;
     DetailNamaTipe.Text = itemDetail.NamaTipe;
     DetailBundleName.Text = itemDetail.BundleName == null ? "null" : itemDetail.BundleName.FirstOrDefault();
     DetailPathFile.Text = itemDetail.BundlePath == null ? "null" : itemDetail.BundlePath.FirstOrDefault();
 }