Пример #1
0
        private void SentAccindentSignelToApi()
        {
            ConnectToApi connectToApi = new ConnectToApi();

            bool connection = connectToApi.CheckConnectionOfVikSite();

            if (mCity.Text.Trim().Length > 3 &&
                mAddress.Text.Trim().Length > 3 &&
                mDescription.Text.Trim().Length > 3 &&
                mPhoneNumber.Text.Trim().Length > 3)
            {
                #region old stuff
                //// casting imageview to bitmap
                //Android.Graphics.Drawables.BitmapDrawable bd =
                //    (Android.Graphics.Drawables.BitmapDrawable)pic.Drawable;

                //Android.Graphics.Bitmap bitmap = bd.Bitmap;

                //using (var stream = new MemoryStream())
                //{
                //    bitmap.Compress(Bitmap.CompressFormat.Jpeg, 0, stream);
                //    PostItem(stream);
                //}
                #endregion
                if (connection == true)
                {
                    if (mSaveImageUri != null)
                    {
                        Stream stream = ContentResolver.OpenInputStream(mSaveImageUri);

                        PostAccidentToDBwithImage(stream);
                    }
                    else
                    {
                        PostAccidentToDBwithoutImage();
                    }
                }
                else
                {
                    RunOnUiThread(() => RefreshProgressDialogAndToastWhenThereIsNoInternet());
                }
            }
            else
            {
                progress.Dismiss();

                Looper.Prepare();
                //Toast.MakeText(this, "Попълнете полетата", ToastLength.Long);

                RunOnUiThread(() => { UpdateError(); });
            }
        }
Пример #2
0
        // when there is no customers in phone
        private void AddOneCustomer(ISharedPreferences pref, ref string billNumber, ref string egn)
        {
            ConnectToApi connectToApi = new ConnectToApi();

            string localParamBillNumber = billNumber;   // to use RefreshErrorAndProgresBarWhenSuccsesfullyAddACustomer

            //check the connection
            bool connection = connectToApi.CheckConnectionOfVikSite();

            // check if connection is ok
            if (connection == true)
            {
                //CREATE URL
                string url = "http://192.168.2.222/VIKWebApi/";

                string realUrl = url + "api/abonats/" + billNumber + "/" + egn;

                var jsonResponse = connectToApi.FetchApiDataAsync(realUrl);

                //check the api
                if (jsonResponse == null)
                {
                    RunOnUiThread(() =>
                    {
                        RefreshErrorAndProgressBarWhenCanNotConnectToApi();
                    });

                    return;
                }
                // check in vikSite is there a customer with this billNumber (is billNumber correct)
                else if (jsonResponse == "[]")
                {
                    RunOnUiThread(() =>
                    {
                        RefreshErrorAndProgressBarWhenEgnOrBillNumberIsNotCorrect();
                    });
                }

                // check is billNumber correct and get and save customer in phone
                else if (jsonResponse != null)
                {
                    Customer newCustomer = connectToApi.GetCustomerFromApi(jsonResponse);

                    if (newCustomer != null)
                    {
                        mCustomers.Add(newCustomer);

                        // convert the list to json
                        var listOfCustomersAsJson = JsonConvert.SerializeObject(this.mCustomers);

                        ISharedPreferencesEditor editor = pref.Edit();

                        // set the value to Customers key
                        editor.PutString("Customers", listOfCustomersAsJson);

                        // commit the changes
                        editor.Commit();

                        RunOnUiThread(() =>
                        {
                            RefreshErrorAndProgresBarWhenSuccsesfullyAddACustomer(localParamBillNumber);
                        });

                        var intent = new Intent(this, typeof(MainActivity));
                        StartActivity(intent);
                    }
                    else
                    {
                        RunOnUiThread(() =>
                        {
                            RefreshErrorAndProgressBarWhenCanNotConnectToApi();
                        });
                    }
                }
            }

            // check if connection is not ok
            else
            {
                RunOnUiThread(() => RefreshProgressDialogAndToastWhenThereIsNoConnection());

                return;   // nqma6e return
            }
        }