Esempio n. 1
0
        private void CheckIfThereisAnewMessageFromApi(ConnectToApi connectToApi)
        {
            EncryptConnection encryp = new EncryptConnection();


            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 AddOneCustomer()
        {
            if (mBillNumber.ToString().Trim().Length > 3 && mEgn.ToString().Trim().Length > 9)
            {
                EncryptConnection encryp = new EncryptConnection();

                string crypFinalPass = encryp.Encrypt();

                ConnectToApi connectToApi = new ConnectToApi();

                string localParamBillNumber = mBillNumber.ToString();   // to use RefreshErrorAndProgresBarWhenSuccsesfullyAddACustomer

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

                // check if connection is ok
                if (connection == true)
                {
                    string realUrl =
                        ConnectToApi.urlAPI + "api/abonats/" + crypFinalPass + "/" + mBillNumber.ToString() + "/" + mEgn.ToString();

                    var jsonResponse = connectToApi.FetchApiDataAsync(realUrl);

                    //check the api
                    if (jsonResponse == null)
                    {
                        InvokeOnMainThread(() =>
                        {
                            Error.Hidden = false;
                            Error.Text   = "Грешка при извличане на данните";
                        });

                        return;
                    }
                    // check in vikSite is there a customer with this billNumber (is billNumber correct)
                    else if (jsonResponse == "[]")
                    {
                        InvokeOnMainThread(() =>
                        {
                            Error.Hidden = false;
                            Error.Text   = "Несъщесвуващ абонат";
                        });
                    }

                    // 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();

                            bool isAddedAnewCustomer  = true;
                            bool isAlreadyBeenUpdated = false;

                            string isAddedAnewCustomerAsString  = JsonConvert.SerializeObject(isAddedAnewCustomer);
                            string isAlreadyBeenUpdatedAsString = JsonConvert.SerializeObject(isAlreadyBeenUpdated);


                            File.WriteAllText(mFilename, listOfCustomersAsJson);

                            ViewController mainScreeen = this.Storyboard.InstantiateViewController("ViewController") as ViewController;
                            if (mainScreeen != null)
                            {
                                this.NavigationController.PushViewController(mainScreeen, true);
                                //  mainScreeen.EmployeesTableView.re
                            }



                            //RunOnUiThread(() =>
                            //{
                            //    RefreshErrorAndProgresBarWhenSuccsesfullyAddACustomer(localParamBillNumber);
                            //});
                        }
                        else
                        {
                            //    RunOnUiThread(() =>
                            //    {
                            //        RefreshErrorAndProgressBarWhenCanNotConnectToApi();
                            //    });
                        }
                    }
                }
                // check if connection is not ok
                else
                {
                    InvokeOnMainThread(() =>
                    {
                        Error.Hidden = false;
                        Error.Text   = "Проверете интернет връзката";
                    });

                    return;   // nqma6e return
                }
            }
            else
            {
                InvokeOnMainThread(() =>
                {
                    Error.Hidden = false;
                    Error.Text   = "Некоректни данни";
                });
            }
        }
Esempio n. 3
0
        private void AllJobDoneInService()
        {
            mCustomers = new List <Customer>();
            mAllUpdateCustomerFromApi = new List <Customer>();
            mTempFetchCollection      = new List <Customer>();

            GetCustomersFromPreferences();


            ConnectToApi connectToApi = new ConnectToApi();

            bool connection = connectToApi.CheckConnectionOfVikSite();

            // if (mCustomers.Count > 0)
            //  {
            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;


                    EncryptConnection encryp = new EncryptConnection();

                    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.updateByAutoService + "/"
                    //   + isReceiveNotifyNewInvoiceCheck + "/" + isReceiveNotifyInvoiceOverdueCheck + "/" + isReciveNotifyReadingCheck + "/";

                    var jsonResponse = connectToApi.FetchApiDataAsync(realUrl); //FetchApiDataAsync(realUrl);

                    mTempFetchCollection.Remove(customer);

                    //check the api
                    if (jsonResponse == null)
                    {
                        mAllUpdateCustomerFromApi.Add(customer);
                        //return;
                    }
                    // check in vikSite is there a customer with this billNumber (is billNumber correct)
                    else if (jsonResponse == "[]")
                    {
                        mAllUpdateCustomerFromApi.Add(customer);
                        //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
                        {
                            mAllUpdateCustomerFromApi.Add(customer);
                        }
                    }
                }


                SelectWhichCustomersTobeNotified(mCountНotifyReadingustomers, mCountНotifyInvoiceOverdueCustomers, mCountNewНotifyNewInvoiceCustomers, mAllUpdateCustomerFromApi); // mCustomerFromApiToNotifyToday

                //SaveCustomersFromApiInPhone();


                SaveUpdatesInPhone();

                //Looper.Prepare();

                //MyNotification myNotification = new MyNotification(this);

                //myNotification.SentNotificationForOverdue(mCountНotifyInvoiceOverdueCustomers);


                SentNotificationForOverdue(mCountНotifyInvoiceOverdueCustomers);

                SentNoficationForNewInovoice(mCountNewНotifyNewInvoiceCustomers);

                SentNotificationForReading(mCountНotifyReadingustomers);
            }


            //ViewController vc = new ViewController();

            //vc.ViewDidLoad();

            //Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime);
        }
Esempio n. 4
0
        private void AddOneCustomer()
        {
            if (mBillNumber.ToString().Trim().Length > 3 && mEgn.ToString().Trim().Length > 9)
            {
                EncryptConnection encryp = new EncryptConnection();

                string crypFinalPass = encryp.Encrypt();

                ConnectToApi connectToApi = new ConnectToApi();

                string localParamBillNumber = mBillNumber.ToString();   // to use RefreshErrorAndProgresBarWhenSuccsesfullyAddACustomer

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

                //bool connection = false;

                // check if connection is ok
                if (connection == true)
                {
                    // BTProgressHUD.ShowContinuousProgress("Добавяне на абонат ...", ProgressHUD.MaskType.Black);

                    string realUrl = ConnectToApi.urlAPI + "api/abonats/" + crypFinalPass
                                     + "/" + mBillNumber.ToString() + "/" + mEgn.ToString() + "/" + ConnectToApi.updateByAddCutomerButton + "/";

                    var jsonResponse = connectToApi.FetchApiDataAsync(realUrl);

                    //string jsonResponse = null;

                    //check the api
                    if (jsonResponse == null)
                    {
                        InvokeOnMainThread(() =>
                        {
                            Error.Hidden = false;
                            Error.Text   = "Грешка при извличане на данните";

                            BTProgressHUD.Dismiss();
                        });

                        //return;
                    }
                    // check in vikSite is there a customer with this billNumber (is billNumber correct)
                    else if (jsonResponse == "[]")
                    {
                        InvokeOnMainThread(() =>
                        {
                            Error.Hidden = false;
                            Error.Text   = "Несъщесвуващ абонат";

                            BTProgressHUD.Dismiss();
                        });
                    }

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

                        if (newCustomer != null && newCustomer.IsExisting == 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);

                            DateTime updateHourAndDate = DateTime.Now;

                            string DateFormatt = "HH:mm";
                            string format      = "dd.MM.yyyy";

                            string shortReportDatetHour = updateHourAndDate.ToString(DateFormatt);


                            var updateHour = updateHourAndDate.ToString(DateFormatt);   // + " часа, ";
                            var updateDate = updateHourAndDate.ToString(format);

                            File.WriteAllText(mFilename, listOfCustomersAsJson);
                            File.WriteAllText(mHourFileName, updateHour);
                            File.WriteAllText(mDateFileName, updateDate);

                            InvokeOnMainThread(() =>
                            {
                                BTProgressHUD.Dismiss();

                                ViewController mainScreeen = this.Storyboard.InstantiateViewController("ViewController") as ViewController;
                                mainScreeen.mToastText     = "абонат";

                                if (mainScreeen != null)
                                {
                                    this.NavigationController.PushViewController(mainScreeen, true);
                                }
                            });
                        }
                        else
                        {
                            InvokeOnMainThread(() =>
                            {
                                //RefreshErrorAndProgressBarWhenCanNotConnectToApi();

                                Error.Hidden = false;
                                Error.Text   = "Несъщесвуващ абонат";   ////////////////////////////////////

                                BTProgressHUD.Dismiss();
                            });
                        }
                    }
                }
                // check if connection is not ok
                else
                {
                    InvokeOnMainThread(() =>
                    {
                        Error.Hidden = false;
                        Error.Text   = "Проверете интернет връзката";

                        BTProgressHUD.Dismiss();
                    });

                    // return;   // nqma6e return
                }
            }
            else
            {
                InvokeOnMainThread(() =>
                {
                    Error.Hidden = false;
                    Error.Text   = "Некоректни данни";

                    BTProgressHUD.Dismiss();
                });
            }
        }