private void SentAccindentSignelToApi() { ConnectToApi connectToApi = new ConnectToApi(); bool connection = connectToApi.CheckConnectionOfVikSite(); if (mCity.Text.Trim().Length > 0 && mAddress.Text.Trim().Length > 0 && mDescription.Text.Trim().Length > 0 && mPhoneNumber.Text.Trim().Length > 0 && mFullName.Text.Trim().Length > 0) { #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); PostAccidentToDB(stream); } else { Stream stream = null; PostAccidentToDB(stream); } //else //{ // PostAccidentToDBwithoutImage(); //} } else { RunOnUiThread(() => RefreshProgressDialogAndToastWhenThereIsNoInternet()); } } else { progress.Dismiss(); Looper.Prepare(); //Toast.MakeText(this, "Попълнете полетата", ToastLength.Long); RunOnUiThread(() => { UpdateError(); }); } }
private void CheckIfThereisAnewMessageFromApi(ConnectToApi connectToApi) { EncrypConnection encryp = new EncrypConnection(); string crypFinalPass = encryp.Encrypt(); //// get message from preferences GrudMessageFromPreferemces grudMessage = new GrudMessageFromPreferemces(); int lastMessageId = grudMessage.GetMessageFromPreferencesInPhone().MessageID; //realno !!!!!!!!!!!!! string messageUrl = ConnectToApi.urlAPI + "api/msg/"; ///testovo // string messageUrl = ConnectToApi.wtf + "api/msg/"; string finalUrl = messageUrl + crypFinalPass + "/" + lastMessageId; var messageFromApiAsJsonString = connectToApi.FetchApiDataAsync(finalUrl); // check api response if (messageFromApiAsJsonString != null) { Message newMessage = new Message(); newMessage = connectToApi.GetMessageFromApi(messageFromApiAsJsonString); if (newMessage.MessageID > lastMessageId) { grudMessage.SaveMessageInPhone(newMessage); // SaveMessageInPhone(newMessage); int messagesCount = newMessage.Messages.Count; if (messagesCount > 0) { SentNotificationWithoutSubscribe(newMessage); } } } }
private void SentAccindentSignelToApi() { ConnectToApi connectToApi = new ConnectToApi(); bool connection = connectToApi.CheckConnectionOfVikSite(); if (mCity.Text.Trim().Length > 0 && mAddress.Text.Trim().Length > 0 && mDescription.Text.Trim().Length > 0 && mPhoneNumber.Text.Trim().Length > 0 && mFullName.Text.Trim().Length > 0) { if (connection == true) { // sent with a pic if (mSaveImageUri != null) { Stream stream = ContentResolver.OpenInputStream(mSaveImageUri); PostAccidentToDB(stream); } // sent without a pic else { Stream stream = null; PostAccidentToDB(stream); } } else { RunOnUiThread(() => RefreshProgressDialogAndToastWhenThereIsNoInternet()); } } else { progress.Dismiss(); Looper.Prepare(); RunOnUiThread(() => { UpdateError(); }); } }
// when there is no customers in phone private void AddOneCustomer(ISharedPreferences pref, ref string billNumber, ref string egn) { EncrypConnection encryp = new EncrypConnection(); string crypFinalPass = encryp.Encrypt(); ConnectToApi connectToApi = new ConnectToApi(); // to use RefreshErrorAndProgresBarWhenSuccsesfullyAddACustomer string localParamBillNumber = billNumber; //check the connection bool connection = connectToApi.CheckConnectionOfVikSite(); // check if connection is ok if (connection == true) { // test api url // string realUrl = ConnectToApi.urlAPI + "api/abonats/" + crypFinalPass + "/" + billNumber + "/" + egn; ////real api url string realUrl = ConnectToApi.urlAPI + "api/abonats/" + crypFinalPass + "/" + billNumber + "/" + egn + "/" + ConnectToApi.updateByAddCutomerButton + "/"; var jsonResponse = connectToApi.FetchApiDataAsync(realUrl); //check the api if (jsonResponse == null) { RunOnUiThread(() => { RefreshErrorAndProgressBarWhenCanNotConnectToApi(); }); return; } // check is billNumber correct and get and save customer in phone else if (jsonResponse != null) { Customer newCustomer = connectToApi.GetCustomerFromApi(jsonResponse); mIsExist = newCustomer.IsExisting; // check in vikSite is there a customer with this billNumber(is billNumber correct) if (mIsExist == false) { RunOnUiThread(() => { RefreshErrorAndProgressBarWhenEgnOrBillNumberIsNotCorrect(); }); } else if (newCustomer != null && mIsExist == true) { mCustomers.Add(newCustomer); // convert the list to json var listOfCustomersAsJson = JsonConvert.SerializeObject(this.mCustomers); ISharedPreferencesEditor editor = pref.Edit(); bool isAddedAnewCustomer = true; bool isAlreadyBeenUpdated = false; string isAddedAnewCustomerAsString = JsonConvert.SerializeObject(isAddedAnewCustomer); string isAlreadyBeenUpdatedAsString = JsonConvert.SerializeObject(isAlreadyBeenUpdated); // set the value to Customers key editor.PutString("Customers", listOfCustomersAsJson); editor.PutString("isAddedAnewCustomer", isAddedAnewCustomerAsString); editor.PutString("isAlredyBeenUpdated", isAlreadyBeenUpdatedAsString); // 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; } }
private void UpdateCustomers(List <Customer> mCustomers, ISharedPreferences pref) { ConnectToApi connectToApi = new ConnectToApi(); bool connection = connectToApi.CheckConnectionOfVikSite(); if (connection == true) { EncrypConnection encryp = new EncrypConnection(); string crypFinalPass = encryp.Encrypt(); //// get from preferences GrudMessageFromPreferemces grudMessage = new GrudMessageFromPreferemces(); int lastMessageId = grudMessage.GetMessageFromPreferencesInPhone().MessageID; //realno !!!!!!!!!!!!!! string messageUrl = ConnectToApi.urlAPI + "api/msg/"; ///teest // string messageUrl = "http://192.168.2.222/VIKWebApi/api/msg/"; string finalUrl = messageUrl + crypFinalPass + "/" + lastMessageId; var messageFromApiAsJsonString = connectToApi.FetchApiDataAsync(finalUrl); if (messageFromApiAsJsonString != null) { Message newMessage = new Message(); newMessage = connectToApi.GetMessageFromApi(messageFromApiAsJsonString); if (newMessage.MessageID > lastMessageId) { grudMessage.SaveMessageInPhone(newMessage); int messagesCount = newMessage.Messages.Count; if (messagesCount > 0) { SentNotificationWithoutSubscribe(newMessage); // myNotification.SentNotificationWithoutSubscribe(newMessage); } } } int testNullResponse = 0; foreach (var item in mCustomers) { mTempFetchCollection.Add(item); } foreach (var customer in mCustomers) { bool isReceiveNotifyNewInvoiceCheck = false; bool isReceiveNotifyInvoiceOverdueCheck = false; bool isReciveNotifyReadingCheck = false; isReceiveNotifyNewInvoiceCheck = customer.NotifyNewInvoice; isReceiveNotifyInvoiceOverdueCheck = customer.NotifyInvoiceOverdue; isReciveNotifyReadingCheck = customer.NotifyReading; string billNumber = customer.Nomer.ToString(); string egn = customer.EGN.ToString(); string realUrl = "http://192.168.2.222/VIKWebApi/" + "api/abonats/" + crypFinalPass + "/" + billNumber + "/" + egn + "/" + ConnectToApi.updateByButtonRefresh + "/" + isReceiveNotifyNewInvoiceCheck + "/" + isReceiveNotifyInvoiceOverdueCheck + "/" + isReciveNotifyReadingCheck + "/"; mTempFetchCollection.Remove(customer); // if(isAnyNotifycationCheck == true) // { //CREATE test URL string url = "http://192.168.2.222/VIKWebApi/"; /// !!!!!!!!!!!!!!!!!!!!!!!! //string realUrl = ConnectToApi.urlAPI + "api/abonats/" + crypFinalPass + "/" // + billNumber + "/" + egn + "/" + ConnectToApi.updateByButtonRefresh + "/"; // // + isReceiveNotifyNewInvoiceToday + "/" + isReceiveNotifyInvoiceOverdueToday + "/" + isReciveNotifyReadingToday + "/"; // var jsonResponse = connectToApi.FetchApiDataAsync(realUrl); string jsonResponse = string.Empty; if (testNullResponse >= 1) { jsonResponse = null; } else { jsonResponse = connectToApi.FetchApiDataAsync(realUrl); } //check the api if (jsonResponse == null) { RunOnUiThread(() => RefreshProgressDialogAndToastWhenNoConnectioToApi()); // mAllUpdateCustomerFromApi.AddRange(mTempFetchCollection); mAllUpdateCustomerFromApi.Add(customer); // return; } // check in vikSite is there a customer with this billNumber (is billNumber correct) else if (jsonResponse == "[]") { RefreshProgressDialogAndToastWhenInputIsNotValid(); mAllUpdateCustomerFromApi.Add(customer); // return; } // check is billNumber correct and get and save customer in phone else if (jsonResponse != null) { // var jsonArray = JArray.Parse(jsonResponse); // Customer newCustomer = connectToApi.GetCustomerFromApi(jsonResponse); Customer updateCutomerButNoNotify = connectToApi.GetCustomerFromApi(jsonResponse); if (updateCutomerButNoNotify != null && updateCutomerButNoNotify.IsExisting == true) // (newCustomer != null && newCustomer.IsExisting == true) { updateCutomerButNoNotify.NotifyNewInvoice = customer.NotifyNewInvoice; updateCutomerButNoNotify.NotifyInvoiceOverdue = customer.NotifyInvoiceOverdue; updateCutomerButNoNotify.NotifyReading = customer.NotifyReading; mAllUpdateCustomerFromApi.Add(updateCutomerButNoNotify); ////////////updateCutomerButNoNotify testNullResponse++; //mTempFetchCollection.Remove(customer); // SaveUpdatesInPhone(pref, mDate.Text.ToString(), mHour.Text.ToString()); } else { RunOnUiThread(() => { RefreshProgressDialogAndToastWhenNoConnectioToApi(); }); return; } } // } } #region setting the updating date string updateHour; string updateDate; GetUpdateDateAndHour(out updateHour, out updateDate); #endregion RunOnUiThread(() => { GetFinalUpdateDateHour(); }); SelectWhichCustomersTobeNotified(countНotifyReadingustomers, countНotifyInvoiceOverdueCustomers, countNewНotifyNewInvoiceCustomers, mAllUpdateCustomerFromApi); //mCustomerFromApiToNotifyToday SaveUpdatesInPhone(pref, mDate.Text.ToString(), mHour.Text.ToString()); //MyNotification myNotification = new MyNotification(this); //myNotification.SentNotificationForOverdue(mCountНotifyInvoiceOverdueCustomers); SentNoficationForNewInovoice(countNewНotifyNewInvoiceCustomers); SentNotificationForOverdue(countНotifyInvoiceOverdueCustomers); SentNotificationForReading(countНotifyReadingustomers); var intent = new Intent(this, typeof(MainActivity)); StartActivity(intent); } else { Looper.Prepare(); RunOnUiThread(() => RefreshProgresDialogAndToastWhenThereIsNoConnection()); return; } }
private void AllJobsDoneInService() { CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("bg-BG"); mCountНotifyReadingustomers = new List <Customer>(); mCountНotifyInvoiceOverdueCustomers = new List <Customer>(); mCountNewНotifyNewInvoiceCustomers = new List <Customer>(); mCustomerFromApiToNotifyToday = new List <Customer>(); // get customers mCustomers = GetCustomersFromPreferences(); ConnectToApi connectToApi = new ConnectToApi(); bool connection = connectToApi.CheckConnectionOfVikSite(); if (connection == true) { CheckIfThereisAnewMessageFromApi(connectToApi); foreach (var item in mCustomers) { mTempFetchCollection.Add(item); } foreach (var customer in mCustomers) { bool isReceiveNotifyNewInvoiceCheck = false; bool isReceiveNotifyInvoiceOverdueCheck = false; bool isReciveNotifyReadingCheck = false; isReceiveNotifyNewInvoiceCheck = customer.NotifyNewInvoice; isReceiveNotifyInvoiceOverdueCheck = customer.NotifyInvoiceOverdue; isReciveNotifyReadingCheck = customer.NotifyReading; EncrypConnection encryp = new EncrypConnection(); string crypFinalPass = encryp.Encrypt(); string billNumber = customer.Nomer; string egn = customer.EGN; string realUrl = ConnectToApi.urlAPI + "api/abonats/" + crypFinalPass + "/" + billNumber + "/" + egn + "/" + ConnectToApi.updateByAutoService + "/" + isReceiveNotifyNewInvoiceCheck + "/" + isReceiveNotifyInvoiceOverdueCheck + "/" + isReciveNotifyReadingCheck + "/"; //string realUrl = "http://192.168.2.222/VIKWebApi/" + "api/abonats/" // + crypFinalPass + "/" + billNumber + "/" + egn + "/" + ConnectToApi.updateByButtonRefresh + "/" // + isReceiveNotifyNewInvoiceCheck + "/" + isReceiveNotifyInvoiceOverdueCheck + "/" + isReciveNotifyReadingCheck + "/"; var jsonResponse = connectToApi.FetchApiDataAsync(realUrl); //FetchApiDataAsync(realUrl); mTempFetchCollection.Remove(customer); //check the api if (jsonResponse == null) { mAllUpdateCustomerFromApi.Add(customer); } // check in vikSite is there a customer with this billNumber (is billNumber correct) else if (jsonResponse == "[]") { mAllUpdateCustomerFromApi.Add(customer); } // check if billNumber is correct and get and save customer in phone else if (jsonResponse != null) { Customer updateCutomerButNoNotify = connectToApi.GetCustomerFromApi(jsonResponse); if (updateCutomerButNoNotify != null && updateCutomerButNoNotify.IsExisting == true) { updateCutomerButNoNotify.NotifyNewInvoice = customer.NotifyNewInvoice; updateCutomerButNoNotify.NotifyInvoiceOverdue = customer.NotifyInvoiceOverdue; updateCutomerButNoNotify.NotifyReading = customer.NotifyReading; mAllUpdateCustomerFromApi.Add(updateCutomerButNoNotify); } else { mAllUpdateCustomerFromApi.Add(customer); } } } SelectWhichCustomersTobeNotified(mCountНotifyReadingustomers, mCountНotifyInvoiceOverdueCustomers, mCountNewНotifyNewInvoiceCustomers, mAllUpdateCustomerFromApi); // mCustomerFromApiToNotifyToday SaveCustomersFromApiInPhone(); SentNotificationForOverdue(mCountНotifyInvoiceOverdueCustomers); SentNoficationForNewInovoice(mCountNewНotifyNewInvoiceCustomers); SentNotificationForReading(mCountНotifyReadingustomers); } }
private void AllJobsDoneInService() { CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("bg-BG"); mCountНotifyReadingustomers = new List <Customer>(); mCountНotifyInvoiceOverdueCustomers = new List <Customer>(); mCountNewНotifyNewInvoiceCustomers = new List <Customer>(); mCustomerFromApiToNotifyToday = new List <Customer>(); // get customers mCustomers = GetCustomersFromPreferences(); ConnectToApi connectToApi = new ConnectToApi(); bool connection = connectToApi.CheckConnectionOfVikSite(); // if (mCustomers.Count > 0) // { if (connection == true) { CheckIfThereisAnewMessageFromApi(connectToApi); foreach (var customer in mCustomers) { bool isReceiveNotifyNewInvoiceCheck = false; bool isReceiveNotifyInvoiceOverdueCheck = false; bool isReciveNotifyReadingCheck = false; isReceiveNotifyNewInvoiceCheck = customer.NotifyNewInvoice; isReceiveNotifyInvoiceOverdueCheck = customer.NotifyInvoiceOverdue; isReciveNotifyReadingCheck = customer.NotifyReading; EncrypConnection encryp = new EncrypConnection(); string crypFinalPass = encryp.Encrypt(); // check if connection is ok // if (isAnyNotifycationCheck == true) // { string billNumber = customer.Nomer; string egn = customer.EGN; //CREATE URL // string url = "http://192.168.2.222/VIKWebApi/"; /// !!!!!!!!!!!!!!!!!!!!! here //string realUrl = ConnectToApi.urlAPI + "api/abonats/" + crypFinalPass + "/" + billNumber + "/" + egn; //string realUrl = ConnectToApi.urlAPI + "api/abonats/" + crypFinalPass + "/" + billNumber + "/" + egn + "/" // + ConnectToApi.updateByAutoService + "/" // + isReceiveNotifyNewInvoiceCheck + "/" + isReceiveNotifyInvoiceOverdueCheck + "/" + isReciveNotifyReadingCheck + "/"; string realUrl = "http://192.168.2.222/VIKWebApi/" + "api/abonats/" + crypFinalPass + "/" + billNumber + "/" + egn + "/" + ConnectToApi.updateByButtonRefresh + "/" + isReceiveNotifyNewInvoiceCheck + "/" + isReceiveNotifyInvoiceOverdueCheck + "/" + isReciveNotifyReadingCheck + "/"; var jsonResponse = connectToApi.FetchApiDataAsync(realUrl); //FetchApiDataAsync(realUrl); //check the api if (jsonResponse == null) { return; } // check in vikSite is there a customer with this billNumber (is billNumber correct) else if (jsonResponse == "[]") { return; //// } // check if billNumber is correct and get and save customer in phone else if (jsonResponse != null) { Customer updateCutomerButNoNotify = connectToApi.GetCustomerFromApi(jsonResponse); if (updateCutomerButNoNotify != null && updateCutomerButNoNotify.IsExisting == true) // (newCustomer != null && newCustomer.IsExisting == true) { updateCutomerButNoNotify.NotifyNewInvoice = customer.NotifyNewInvoice; updateCutomerButNoNotify.NotifyInvoiceOverdue = customer.NotifyInvoiceOverdue; updateCutomerButNoNotify.NotifyReading = customer.NotifyReading; mAllUpdateCustomerFromApi.Add(updateCutomerButNoNotify); } else { return; } } //string format = "HH"; //string currentTime = DateTime.Now.ToString(format); //int currentTimeAsInt = Convert.ToInt32(currentTime); // if(currentTimeAsInt == 17) // { SelectWhichCustomersTobeNotified(mCountНotifyReadingustomers, mCountНotifyInvoiceOverdueCustomers, mCountNewНotifyNewInvoiceCustomers, mAllUpdateCustomerFromApi); // mCustomerFromApiToNotifyToday SaveCustomersFromApiInPhone(); //Looper.Prepare(); //MyNotification myNotification = new MyNotification(this); //myNotification.SentNotificationForOverdue(mCountНotifyInvoiceOverdueCustomers); //if() SentNotificationForOverdue(mCountНotifyInvoiceOverdueCustomers); SentNoficationForNewInovoice(mCountNewНotifyNewInvoiceCustomers); SentNotificationForReading(mCountНotifyReadingustomers); // SaveCustomersFromApiInPhone(); // } //else //{ // SelectWhichCustomersTobeNotified(mCountНotifyReadingustomers, mCountНotifyInvoiceOverdueCustomers, mCountNewНotifyNewInvoiceCustomers, mCustomerFromApiToNotifyToday); // // SaveCustomersFromApiInPhone(); // foreach (var customer in mCustomerFromApiToNotifyToday) // { // if(customer.NotifyNewInvoice == true && customer.ReceiveNotifyNewInvoiceToday && customer.DidGetNewInoviceToday == false) // { // SentNoficationForNewInovoice(mCountNewНotifyNewInvoiceCustomers); // } // else if(customer.NotifyInvoiceOverdue == true && customer.ReceiveNotifyInvoiceOverdueToday == true && customer.DidGetOverdueToday == false) // { // SentNotificationForOverdue(mCountНotifyInvoiceOverdueCustomers); // } // else if(customer.NotifyReading == true && customer.ReciveNotifyReadingToday == true && customer.DidGetReadingToday == false) // { // SentNotificationForReading(mCountНotifyReadingustomers); // } // } // // SaveCustomersFromApiInPhone(); //} } //else //{ // return; //// //} // } } }