Ejemplo n.º 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("該当の商品情報がありません!");
                    }
                });
            };
        }
Ejemplo n.º 2
0
    public override StartCommandResult OnStartCommand(Android.Content.Intent intent, StartCommandFlags flags, int startId)
    {
        Android.Util.Log.Debug("BackgroundService", "Started BackgroundService");
        Task.Run(async() => {
            while (true)
            {
                await Task.Delay(10000);
                // 開発用。ずっとサーバにアクセスし続けるので一旦何もしないようにする
                // continue;

                DateTime dt = DateTime.Now;
                // 毎日AM9:00のみ一度実行
                if (dt.Hour != 9 && dt.Minute != 0 && dt.Second != 0)
                {
                    // continue;
                }
                string today = dt.ToString("yyyy-MM-dd");

                var bundle = new Bundle();
                global::Xamarin.Forms.Forms.Init(this, bundle);

                // PCLのクラス実行
                madaarumk2.GetObjects go = new madaarumk2.GetObjects();
                int userId = intent.GetIntExtra("userid", 0);
                if (userId == 0)
                {
                    continue;
                }
                string jsonString = await go.GetExpendablesInfo(userId);
                if (jsonString == "null")
                {
                    continue;
                }
                List <madaarumk2.Expendables> expInfo = go.GetAllItemsObjectFromJson(jsonString);
                Dictionary <string, string> item      = new Dictionary <string, string>();

                for (int n = 0; n < expInfo.Count; n++)
                {
                    if (expInfo[n].limit != today)
                    {
                        continue;
                    }
                    // TODO: aliasを使うようにする(要Expendablesクラスの拡張)
                    madaarumk2.BackgroundNotification.Main(expInfo[n].name);
                }
            }
        });

        return(StartCommandResult.Sticky);
    }
Ejemplo n.º 3
0
        //リストに表示する情報を取得してくる
        async Task setList()
        {
            User userInfo = (User)Application.Current.Properties["user"];
            int  user_id  = userInfo.id;

            GetObjects go = new GetObjects();

            BuyThingList = await go.GetBuyThingObjects(user_id);

            for (int i = 0; i < BuyThingList.Count; i++)
            {
                ItemNameList.Add(BuyThingList[i].name);
            }
            itemListView.ItemsSource = ItemNameList;
        }
Ejemplo n.º 4
0
        //for debug
        async void ShowJancodeButtonClicked(object sender, EventArgs s)
        {
            GetObjects gj = new GetObjects();

            if (scanedcode != "0")
            {
                string jsonString = await gj.GetItemJsonString(scanedcode);

                DependencyService.Get <IMyFormsToast>().Show(jsonString);
            }
            else    //Not Scaned
            {
                DependencyService.Get <IMyFormsToast>().Show("Jancodeがスキャンされていません");
            }
        }
Ejemplo n.º 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);
                    }
                });
            };
        }
Ejemplo n.º 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("該当の商品情報がありません!");
            }
        }
Ejemplo n.º 7
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("リストを更新しました!");
        }
Ejemplo n.º 8
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("リストを更新しました!");
        }