Beispiel #1
0
        //async void ScanButtonClicked(object sender, EventArgs s) {
        //    var scanPage = new ZXingScannerPage() {
        //        DefaultOverlayTopText = "バーコードを読み取ります",
        //        DefaultOverlayBottomText = "",
        //    };
        //    await Navigation.PushAsync(scanPage);
        //    scanPage.OnScanResult += (result) => {
        //        scanPage.IsScanning = false;
        //        Device.BeginInvokeOnMainThread(async () => {
        //            scanedcode = result.Text;
        //            await Navigation.PopAsync();
        //            //await DisplayAlert("Scan Done!", result.Text, "OK");//これは消して良い
        //            //スキャンして得た情報を使って何かしたい場合
        //            //ここに処理を書く
        //        });
        //    };
        //}

        async void LightScanBtnClicked(object sender, EventArgs s)
        {
            var scanPage = new ZXingScannerPage()
            {
                DefaultOverlayTopText    = "バーコードを読み取ります",
                DefaultOverlayBottomText = "",
            };
            await Navigation.PushAsync(scanPage);

            scanPage.OnScanResult += (result) => {
                scanedcode          = result.Text;
                scanPage.IsScanning = false;
                Device.BeginInvokeOnMainThread(async() => {
                    await Navigation.PopAsync();

                    DependencyService.Get <IMyFormsToast>().Show("LightWeghtTest:" + scanedcode);
                    GetObjects gj     = new GetObjects();
                    string jsonString = await gj.GetItemJsonString(scanedcode);
                    if (jsonString != "null")
                    {
                        SearchedInfo thingInfo = gj.GetItemObjectFromJson(jsonString);
                        //userIdはとりあえず1の人固定
                        int userId = 1;
                        //int itemId = thingInfo[0].Id;
                        int itemId = thingInfo.Id;
                        //個数はとりあえず1個固定
                        int itemNum = 1;

                        //購入品情報を作成
                        Bought_thing bt = new Bought_thing();
                        bt.user_id      = userId;
                        bt.thing_id     = itemId;
                        bt.num          = itemNum;

                        PostJson pj = new PostJson();
                        //Postして購入済みリストに追加、次の購入日を取得
                        Next_buy_date nextBuyDate = await pj.PostBoughtThingInfo(bt);

                        DependencyService.Get <IMyFormsToast>().Show("次の購入日を取得:" + nextBuyDate.next_buy_date);

                        //消耗品リスト作成
                        Bought_expendable be = new Bought_expendable();
                        be.user_id           = userId;
                        be.thing_id          = thingInfo.Id;
                        be.limit             = nextBuyDate.next_buy_date;
                        //Postして消耗品リストに登録
                        Expendables postedEx = await pj.PostExpendablesInfo(be);

                        DependencyService.Get <IMyFormsToast>().Show("消耗品リストに登録しました: " + postedEx.created_at);
                    }
                    else    //json null
                    {
                        DependencyService.Get <IMyFormsToast>().Show("該当の商品情報がありません!");
                    }
                });
            };
        }
Beispiel #2
0
 public BoughtThingConcernPage(SearchedInfo thingInfo, int itemNum, string shopName)
 {
     InitializeComponent();
     //shopNameLabel.Text = shopName;
     itemNumLabel.Text  = itemNum.ToString();
     itemNameLabel.Text = thingInfo.Name;
     this.item          = thingInfo;
     this.itemNum       = itemNum;
     //this.shopName = shopName;
 }
        public CompleteBoughtThingPage(string shopName, SearchedInfo item, Bought_thing bt, Next_buy_date nbd)
        {
            InitializeComponent();
            //shopNameLabel.Text = "店名: " + shopName;
            itemNameLabel.Text    = "商品名: " + item.Name;
            itemNumLabel.Text     = "個数: " + bt.num;
            nextBuyDateLabel.Text = "次の購入予定日: " + nbd.next_buy_date;

            //ここに一定タイマーを仕込む処理を書く
            //CreateNotify();
        }
Beispiel #4
0
 public BoughtThingResultEditPage(string shopName, SearchedInfo thingInfo)
 {
     InitializeComponent();
     //this.shopName = " 選択された店名:" + shopName;
     if (thingInfo.Name != null)
     {
         itemNameLabel.Text = thingInfo.Name;
     }
     //shopNameLabel.Text = shopName;
     //this.shopName = shopName;
     this.thingInfo = thingInfo;
 }
Beispiel #5
0
        async void addScanBtnClicked(object sender, EventArgs s)
        {
            string scanedJancode = "";

            var scanPage = new ZXingScannerPage()
            {
                DefaultOverlayTopText    = "バーコードを読み取ります",
                DefaultOverlayBottomText = "",
            };
            await Navigation.PushAsync(scanPage);

            scanPage.OnScanResult += (result) => {
                scanPage.IsScanning = false;
                Device.BeginInvokeOnMainThread(async() => {
                    scanedJancode = result.Text;
                    await Navigation.PopAsync();

                    //選択した店名をchosenShopNameに入れる
                    string chosenShopName = shopANameLabel.Text;

                    //DependencyService.Get<IMyFormsToast>().Show("Jancode: " + scanedJancode + "で問い合わせ中");

                    //jancodeを元にサーバに商品情報を取得
                    GetObjects go     = new GetObjects();
                    string jsonString = await go.GetItemJsonString(scanedJancode);

                    if (scanedJancode != null)  //jsonの内容をチェック
                    //SearchedInfo thingInfo = new SearchedInfo();
                    {
                        SearchedInfo thingInfo = go.GetItemObjectFromJson(jsonString);

                        //chosenShopName,SearchedInfoを渡す
                        await Navigation.PushAsync(new BoughtThingResultEditPage(chosenShopName, thingInfo), true);
                    }
                    else    //jancode is null
                    {
                        DependencyService.Get <IMyFormsToast>().Show("サーバにデータがありません。商品名を手入力してください");
                        //できればdisplayactionsheetで再スキャンか
                        //入力画面に移行するかを選べるようにする

                        //手入力画面に移行する.手入力ページが未実装なのでコメントアウト
                        //await Navigation.PushAsync(new ManualInputBoughtThingPage(), true);
                    }
                });
            };
        }
Beispiel #6
0
        async void ShowItemNameButtonClicked(object sender, EventArgs s)
        {
            GetObjects gj = new GetObjects();

            string jsonString = await gj.GetItemJsonString(scanedcode);

            if (jsonString != "null")
            {
                SearchedInfo thingInfo = await gj.GetItemInfo(scanedcode);

                DependencyService.Get <IMyFormsToast>().Show("商品名!!" + thingInfo.Name);
            }
            else    //json null
            {
                DependencyService.Get <IMyFormsToast>().Show("該当の商品情報がありません!");
            }
        }
Beispiel #7
0
        public async Task <SearchedInfo> GetItemInfo(string jancode)
        {
            string serverUrl    = ServerInfo.url;
            string searchAPIUrl = "/things/search";
            string reqUrl       = $"{serverUrl}{searchAPIUrl}?jancode={jancode}";

            SearchedInfo      thingInfo = new SearchedInfo();
            WrappedHttpClient whc       = new WrappedHttpClient();

            //Jsonを取得できなかった時の例外のハンドリング
            try {
                string jsonString = await whc.GetStringAsync(reqUrl);

                thingInfo = JsonConvert.DeserializeObject <SearchedInfo>(jsonString);
            } catch (HttpRequestException e) {
                DependencyService.Get <IMyFormsToast>().Show("HttpClient ERROR: " + e.Message);
            }
            return(thingInfo);
        }
Beispiel #8
0
        //Listを取得してセットする処理を書く
        async Task setBoughtList()
        {
            User user   = (User)Application.Current.Properties["user"];
            int  userId = user.id;

            GetObjects go         = new GetObjects();
            string     jsonString = await go.GetExpendablesInfo(userId);

            if (jsonString != "null")
            {
                List <Expendables>          expendablesInfo = go.GetAllItemsObjectFromJson(jsonString);
                Dictionary <string, string> item            = new Dictionary <string, string>();

                for (int n = 0; n < expendablesInfo.Count; n++)
                {
                    item[expendablesInfo[n].name] = "次回購入予定日:" + expendablesInfo[n].limit;
                    //item.Add(expendablesInfo[n].name, expendablesInfo[n].limit);
                    //await DisplayAlert("商品名", expendablesInfo[n].name, "OK");
                    //await DisplayAlert("次回購入予定日", expendablesInfo[n].limit, "OK");
                }


                var cell = new DataTemplate(typeof(ImageCell));
                cell.SetBinding(ImageCell.TextProperty, "Key");
                cell.SetBinding(ImageCell.DetailProperty, "Value");

                var listView = new ListView {
                    IsPullToRefreshEnabled = true,
                    ItemsSource            = item,
                    ItemTemplate           = cell
                };

                var addbutton = new Button {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    Text            = "+",
                    FontSize        = 30,
                    BackgroundColor = Color.Orange,
                    TextColor       = Color.White,
                    Command         = new Command(async() => {
                        string scanedJancode = "";

                        var scanPage = new ZXingScannerPage()
                        {
                            DefaultOverlayTopText    = "バーコードを読み取ります",
                            DefaultOverlayBottomText = "",
                        };
                        await Navigation.PushAsync(scanPage);
                        scanPage.OnScanResult += (result) => {
                            scanPage.IsScanning = false;
                            Device.BeginInvokeOnMainThread(async() => {
                                scanedJancode = result.Text;
                                await Navigation.PopAsync();

                                //選択した店名をchosenShopNameに入れる
                                string chosenShopName = "ShopA";

                                //DependencyService.Get<IMyFormsToast>().Show("Jancode: " + scanedJancode + "で問い合わせ中");

                                //jancodeを元にサーバに商品情報を取得
                                //GetObjects go = new GetObjects();
                                string jsonString2 = await go.GetItemJsonString(scanedJancode);

                                //DependencyService.Get<IMyFormsToast>().Show("Json: " + jsonString2);

                                if (jsonString2 != null)  //jsonの内容をチェック
                                                          //SearchedInfo thingInfo = new SearchedInfo();
                                {
                                    SearchedInfo thingInfo = go.GetItemObjectFromJson(jsonString2);

                                    //chosenShopName,SearchedInfoを渡す
                                    await Navigation.PushAsync(new BoughtThingResultEditPage(chosenShopName, thingInfo), true);
                                }
                                else    //jancode is null
                                {
                                    DependencyService.Get <IMyFormsToast>().Show("サーバにデータがありません");
                                    //DependencyService.Get<IMyFormsToast>().Show("サーバにデータがありません。商品名を手入力してください");
                                    //できればdisplayactionsheetで再スキャンか
                                    //入力画面に移行するかを選べるようにする

                                    //手入力画面に移行する.手入力ページが未実装なのでコメントアウト
                                    //await Navigation.PushAsync(new ManualInputBoughtThingPage(), true);
                                }
                            });
                        };
                    })
                };

                listView.Refreshing += (sender, e) => {
                    setBoughtList();
                    listView.IsRefreshing = false;
                };

                var RefreshList = new Button {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    Text            = "更新",
                    FontSize        = 20,
                    BackgroundColor = Color.Tan,
                    TextColor       = Color.White,
                    Command         = new Command(() => { setBoughtList(); })
                };

                Content = new StackLayout {
                    Padding  = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0), // iOSのみ上部にマージンをとる
                    Children =
                    {
                        new StackLayout {
                            Orientation = StackOrientation.Horizontal,
                            Children    =
                            {
                                RefreshList,
                                addbutton
                            }
                        },
                        listView
                    }
                };

                //foreach (var p in item){
                //     Debug.WriteLine(string.Format("商品名:{0}, 次回購入予定日:{1}", p.Key, p.Value));
                //}
            }
            else //json null
            {
                DependencyService.Get <IMyFormsToast>().Show("商品情報はありません!");
            }
            DependencyService.Get <IMyFormsToast>().Show("リストを更新しました!");
        }
Beispiel #9
0
        //Jsonを受け取ってオブジェクトに変換
        public SearchedInfo GetItemObjectFromJson(string jsonString)
        {
            SearchedInfo thingInfo = JsonConvert.DeserializeObject <SearchedInfo>(jsonString);

            return(thingInfo);
        }
Beispiel #10
0
        //Listを取得してセットする処理を書く
        async Task setBuyList()
        {
            User       user       = (User)Application.Current.Properties["user"];
            int        userId     = user.id;
            GetObjects go         = new GetObjects();
            string     jsonString = await go.GetBuythingInfo(userId);

            List <Buy_thing>            buythingInfo = go.GetbuythingObjectFromJson(jsonString);
            Dictionary <string, string> item         = new Dictionary <string, string>();

            var cell = new DataTemplate(typeof(ImageCell));

            cell.SetBinding(ImageCell.TextProperty, "Key");
            cell.SetBinding(ImageCell.DetailProperty, "Value");

            var listView = new ListView
            {
                IsPullToRefreshEnabled = true,
                ItemsSource            = item,
                ItemTemplate           = cell
            };

            var addbutton = new Button
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "+",
                FontSize        = 30,
                BackgroundColor = Color.OrangeRed,
                TextColor       = Color.White,
                Command         = new Command(async() => {
                    string nextPageResult = await DisplayActionSheet("追加方法を選ぶ", "閉じる", "キャンセル", new string[] { "リストから", "スキャンする" });

                    if (nextPageResult == "リストから")
                    {//リストから選ぶページを表示
                        await Navigation.PushAsync(new ChoiceFromBoughtThingPage(), true);
                    }
                    else if (nextPageResult == "スキャンする")
                    {//スキャンするページを表示
                     //await Navigation.PushAsync(new ScanBuyThingPage(), true);
                     //ZXingのスキャナーを呼ぶ
                        string scanedJancode = "";
                        var scanPage         = new ZXingScannerPage()
                        {
                            DefaultOverlayTopText    = "バーコードを読み取ります",
                            DefaultOverlayBottomText = "",
                        };
                        await Navigation.PushAsync(scanPage);
                        scanPage.OnScanResult += (result) => {
                            //scanPage.OnScanResult += (result) => {
                            scanPage.IsScanning = false;
                            Device.BeginInvokeOnMainThread(async() => {
                                scanedJancode = result.Text;
                                await Navigation.PopAsync();

                                DependencyService.Get <IMyFormsToast>().Show("Jancode: " + scanedJancode + "で問い合わせ中");
                                //GetObjects go = new GetObjects();
                                string json = await go.GetItemJsonString(scanedJancode);

                                if (scanedJancode != null)
                                {//jsonの内容をチェック
                                 //jancodeを元に情報を作成
                                    SearchedInfo thingInfo = go.GetItemObjectFromJson(json);
                                    Bought_thing bt        = new Bought_thing();
                                    User userInfo          = (User)Application.Current.Properties["user"];
                                    bt.user_id             = userInfo.id;
                                    //数は最後に入れてもらうのでとりあえず1を入れる
                                    bt.num      = 1;
                                    bt.thing_id = thingInfo.Id;

                                    //登録に必要な情報を渡す
                                    await Navigation.PushAsync(new ConcernBuyThingPage(bt), true);
                                }
                                else
                                {//jancode is null
                                    DependencyService.Get <IMyFormsToast>().Show("サーバにデータがありません");
                                    //手入力画面に移行する.手入力ページが未実装なのでコメントアウト
                                    //await Navigation.PushAsync(new ManualInputBuyThingPage(), true);
                                }
                            });
                        };
                    }
                    else
                    {//閉じるかキャンセルが押されているので何もしない(留まる)
                        DependencyService.Get <IMyFormsToast>().Show("追加をキャンセルします.");
                    }
                })
            };

            listView.Refreshing += (sender, e) => {
                setBuyList();
                listView.IsRefreshing = false;
            };

            var RefreshList = new Button
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "更新",
                FontSize        = 20,
                BackgroundColor = Color.Tan,
                TextColor       = Color.White,
                Command         = new Command(() => { setBuyList(); })
            };

            for (int n = 0; n < buythingInfo.Count; n++)
            {
                item[buythingInfo[n].name] = buythingInfo[n].alias;
                //item.Add(expendablesInfo[n].name, expendablesInfo[n].limit);
                //await DisplayAlert("商品名", expendablesInfo[n].name, "OK");
                //await DisplayAlert("次回購入予定日", expendablesInfo[n].limit, "OK");
            }

            Content = new StackLayout
            {
                Padding  = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0), // iOSのみ上部にマージンをとる
                Children =
                {
                    new StackLayout {
                        Orientation = StackOrientation.Horizontal,
                        Children    =
                        {
                            RefreshList,
                            addbutton
                        }
                    },
                    listView
                }
            };
            DependencyService.Get <IMyFormsToast>().Show("リストを更新しました!");
        }