Exemple #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("該当の商品情報がありません!");
                    }
                });
            };
        }
Exemple #2
0
        public async Task <Expendables> GetExpendablesObject(int user_id)
        {
            string serverUrl    = ServerInfo.url;
            string searchAPIUrl = "/expendables.json";
            string reqUrl       = $"{serverUrl}{searchAPIUrl}?user_id={user_id}";

            WrappedHttpClient whc        = new WrappedHttpClient();
            string            jsonString = await whc.GetStringAsync(reqUrl);

            Expendables expendables = JsonConvert.DeserializeObject <Expendables>(jsonString);

            return(expendables);
        }
Exemple #3
0
        //Expendables情報をpost後、その情報をもう一度返す
        //返り値のExpendablesは使い道ないので捨てて良い
        //なら返り値要らないのでは
        public async Task <Expendables> PostExpendablesInfo(Bought_expendable be)
        {
            string serverUrl = ServerInfo.url;
            string APIUrl    = "/expendables.json";
            string reqUrl    = $"{serverUrl}{APIUrl}";

            string jsonString = JsonConvert.SerializeObject(be);

            //HttpClient hc = new HttpClient();
            WrappedHttpClient whc = new WrappedHttpClient();

            var content = new StringContent(jsonString, Encoding.UTF8, "application/json");
            //HttpResponseMessage response = await hc.PostAsync(reqUrl, content);
            HttpResponseMessage response = await whc.PostAsync(reqUrl, content);


            //result string => ""
            //resut無いのに必要?
            string result = await response.Content.ReadAsStringAsync();

            Expendables ex = JsonConvert.DeserializeObject <Expendables>(result);

            return(ex);
        }
Exemple #4
0
        async void OkBtnClicked(object sender, EventArgs s)
        {
            //サーバーに登録情報を送る
            //購入品情報を作成
            //userIdはLoginが実装でき次第書き換える
            //userIdはとりあえず固定

            User user   = (User)Application.Current.Properties["user"];
            int  userId = user.id;

            Bought_thing bt = new Bought_thing();

            //書き換える
            bt.user_id  = userId;
            bt.thing_id = item.Id;
            bt.num      = itemNum;

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

            //1990-01-01だった場合
            //nextBuyDate.next_buy_dateはstring型なのでDateTimeに変換する
            DateTime defaultDT     = new DateTime(1990, 1, 1);
            DateTime inputDateTime = defaultDT;
            DateTime nextBuyDT;
            DateTime nextBuyDTymd;
            string   sendDTstring = nextBuyDate.next_buy_date;

            //DateTime inputDate;

            //defaultDTでプロパティを初期化
            Application.Current.Properties["inputDateTime"] = inputDateTime;


            if (DateTime.TryParse(nextBuyDate.next_buy_date, out nextBuyDT))
            {
                nextBuyDTymd = new DateTime(nextBuyDT.Year, nextBuyDT.Month, nextBuyDT.Day);

                if (nextBuyDTymd.CompareTo(defaultDT) == 0)  //サーバから帰ってきた日付が1990-01-01
                //入力してもらう
                {
                    await Navigation.PushAsync(new DateTimeInputPage(), true);

                    inputDateTime = (DateTime)Application.Current.Properties["inputDateTime"];
                    //DependencyService.Get<IMyFormsToast>().Show("入力した日付: " + inputDateTime.ToString());


                    if (inputDateTime.CompareTo(defaultDT) == 0)  //1990-01-01なので入力してくれてない
                    {
                        DependencyService.Get <IMyFormsToast>().Show("もう一度日付入力してください");
                        return;
                    }
                    else
                    {
                        sendDTstring = inputDateTime.ToString("yyyy-MM-dd");
                    }
                }//1990-01-01ではないので通常通り続ける


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

                //消耗品リスト作成
                Bought_expendable be = new Bought_expendable();
                //書き換える
                be.user_id  = userId;
                be.thing_id = item.Id;
                be.limit    = sendDTstring;

                //Todo:消す
                DependencyService.Get <IMyFormsToast>().Show("次のlimitの日付: " + inputDateTime.ToString("yyyy-MM-dd"));

                //be.limit = nextBuyDate.next_buy_date;
                //Postして消耗品リストに登録
                Expendables postedEx = await pj.PostExpendablesInfo(be);

                //DependencyService.Get<IMyFormsToast>().Show("消耗品リストに登録しました: " + postedEx.created_at);

                //登録完了したので完了したことを伝えるページに遷移
                //shopName(店名)、item.Name(商品名)、bt(bt.numで個数)、nextBuyDate(limit)
                //Page cbtPage = new CompleteBoughtThingPage(shopName, item, bt, nextBuyDate);
                //await Navigation.PushAsync(cbtPage, true);
                await Navigation.PushAsync(new CompleteBoughtThingPage(shopName, item, bt, nextBuyDate), true);
            }
            else  //帰ってきた日付が変換できないエラー
            {
                DependencyService.Get <IMyFormsToast>().Show("帰ってきた日付を変換できません:" + nextBuyDate.next_buy_date);
                //Todo:BoughtListPageに戻る処理
                //Navigation.RemovePage();
            }
        }