Esempio n. 1
0
        private void SlowMethod()
        {
//			Thread.Sleep (5000);
//
//							if (mAnimation.HasEnded) {
//				activity.RunOnUiThread(() => Toast.MakeText(context, @"Animation End", ToastLength.Short).Show());
//							} else {
//				activity.RunOnUiThread(() =>Toast.MakeText(context, @"Animation NOT End", ToastLength.Short).Show());
//							}

            //user.username = @"Zvezdova957";
            //user.password = @"624590701";

            user.username = tvUsername.Text;
            user.password = tvPassword.Text;

            bool isAuth = false;

            if (true)
            {
                isAuth = onlineAuth(user.username, user.password);
            }
            else
            {
                isAuth = offlineAuth(user.username, user.password);
            }

            if (isAuth)
            {
                //Toast.MakeText(context, @"Authentificated", ToastLength.Short).Show())

                WriteInfo(@"Обновление внутренних данных", 2000);
                try {
                    Common.SetCurrentUser(user);
                    PharmacyManager.Refresh();
                    AttendanceManager.Refresh();
                    AttendancePhotoManager.Refresh();
                    AttendanceResultManager.Refresh();
                    SyncQueueManager.Refresh();
                } catch (Exception ex) {
                    Log.Error(@"Login", ex.Message);
                    WriteDanger(@"ОШИБКА! ВХОД НЕ ВЫПОЛНЕН", 3000);
                    return;
                }
                WriteSuccess(@"ВХОД ВЫПОЛНЕН УСПЕШНО", 3000);
                Dismiss();
                OnSuccessSignedIn(EventArgs.Empty);
//				MessageBox.Show();
            }
            else
            {
                activity.RunOnUiThread(() => Toast.MakeText(context, @"NOT Authentificated", ToastLength.Short).Show());
                WriteDanger(@"ОШИБКА! ВХОД НЕ ВЫПОЛНЕН", 3000);
//				activity.RunOnUiThread (() => bSignUp.Visibility = ViewStates.Visible);
//				MessageBox.Show(@"NOT Authentificated");
            }

            //RunOnUiThread (() => textview.Text = "Method Complete");
        }
Esempio n. 2
0
 public override void OnPause()
 {
     base.OnPause();
     if (Common.GetIsAttendanceRun(user.username))
     {
         AttendancePhotoManager.SetCurrentAttendancePhotos(newAttendancePhotos);
     }
 }
Esempio n. 3
0
 void UpRightB_Click(object sender, EventArgs e)
 {
     FragmentManager.BeginTransaction().Remove(fragment).Commit();
     AttendanceManager.SetCurrentAttendance(null);
     AttendanceResultManager.SetCurrentAttendanceResults(null);
     AttendancePhotoManager.SetCurrentAttendancePhotos(null);
     RefreshMainView();
 }
Esempio n. 4
0
        void UpEndAttendance_Click(object sender, EventArgs e)
        {
            isVisitStart = false;
            Common.SetIsAttendanceRun(user.username, isVisitStart);
            locMgr.RemoveUpdates(this);

            // SAVE
            upPrevBlock.Visibility = ViewStates.Gone;
            upNextBlock.Visibility = ViewStates.Gone;
            FragmentManager.BeginTransaction().Remove(fragment).Commit();
            fragmentNum = 1;

            Attendance newAttendance = AttendanceManager.GetCurrentAttendance();
            List <AttendanceResult> newAttendanceResults = AttendanceResultManager.GetCurrentAttendanceResults();
            List <AttendancePhoto>  newAttendancePhotos  = AttendancePhotoManager.GetCurrentAttendancePhotos();
//			List<AttendanceGPSPoint> newAttendanceGPSPoints = AttendanceGPSPointManager.GetCurrentAttendanceGPSPoints ();
            int attID = AttendanceManager.SaveAttendance(newAttendance);

            if (newAttendanceResults != null)
            {
                AttendanceResultManager.SaveNewAttendanceResults(attID, newAttendanceResults);
            }
            if (newAttendancePhotos != null)
            {
                AttendancePhotoManager.SaveNewAttendancePhotos(attID, newAttendancePhotos);
            }
            if (attendanceGPSPoints != null)
            {
                AttendanceGPSPointManager.SaveNewAttendanceGPSPoints(attID, attendanceGPSPoints);
            }
            //Correct Pharmacy
            Pharmacy pharmacy = PharmacyManager.GetPharmacy(selectedPharmacyID);

            pharmacy.prev = DateTime.Now;
            pharmacy.next = DateTimeFormatInfo.CurrentInfo.Calendar.AddWeeks(pharmacy.prev, 2);
            PharmacyManager.SavePharmacy(pharmacy);

            //Clear
            AttendanceManager.SetCurrentAttendance(null);
            AttendanceResultManager.SetCurrentAttendanceResults(null);
            AttendancePhotoManager.SetCurrentAttendancePhotos(null);

            RefreshMainView();
        }
Esempio n. 5
0
        public override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (resultCode == Result.Ok)
            {
                // Make it available in the gallery
//				Intent mediaScanIntent = new Intent (Intent.ActionMediaScannerScanFile);
//				Android.Net.Uri contentUri = Android.Net.Uri.FromFile (file);
//				mediaScanIntent.SetData (contentUri);
//
//				Activity.SendBroadcast (mediaScanIntent);
//
                AttendancePhoto attPhoto = new AttendancePhoto()
                {
                    photoPath = file.ToString(),
                    stamp     = DateTime.Now,
                    subType   = currentPhotoSubTypes[spnPhotoSubTypes.SelectedItemPosition].id
                };

                //Latitude and Longitude
                ExifInterface exif     = new ExifInterface(attPhoto.photoPath);
                float[]       lat_long = new float[2];
                if (exif.GetLatLong(lat_long))
                {
                    attPhoto.latitude  = lat_long [0];
                    attPhoto.longitude = lat_long [1];
                }

                newAttendancePhotos.Add(attPhoto);
                AttendancePhotoManager.SetCurrentAttendancePhotos(newAttendancePhotos);

                RefreshPhotoList();
            }

            // Dispose of the Java side bitmap.
            GC.Collect();
        }
Esempio n. 6
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            // return inflater.Inflate(Resource.Layout.YourFragment, container, false);
            layoutInflater = inflater;

            base.OnCreateView(inflater, container, savedInstanceState);

            View rootView = inflater.Inflate(Resource.Layout.PhotoAddFragment, container, false);

            user = Common.GetCurrentUser();

            photoTypes     = Common.GetPhotoTypes(user.username);
            photoTypesDict = new Dictionary <int, PhotoType> ();
            foreach (var item in photoTypes)
            {
                photoTypesDict.Add(item.id, item);
            }
            photoSubTypes     = Common.GetPhotoSubTypes(user.username);
            photoSubTypesDict = new Dictionary <int, PhotoSubType> ();
            foreach (var item in photoSubTypes)
            {
                photoSubTypesDict.Add(item.id, item);
            }

            newAttendancePhotos = AttendancePhotoManager.GetCurrentAttendancePhotos();
            if ((newAttendancePhotos == null) || (newAttendancePhotos.Count == 0))
            {
                newAttendancePhotos = new List <AttendancePhoto> ();
            }

            llPhotoList = rootView.FindViewById <LinearLayout> (Resource.Id.pafAddedPhotoLL);
            RefreshPhotoList();

            spnPhotoTypes = rootView.FindViewById <Spinner> (Resource.Id.pafPhotoTypeSpinner);
            ArrayAdapter adapter = new ArrayAdapter(Activity, Android.Resource.Layout.SimpleSpinnerItem, (string [])(from item in photoTypes select item.name).ToArray());

            adapter.SetDropDownViewResource(Resource.Layout.SpinnerItem);
            spnPhotoTypes.Adapter = adapter;

            spnPhotoTypes.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => {
                int photoTypesID = photoTypes [e.Position].id;

                currentPhotoSubTypes = (List <PhotoSubType>)(from item in photoSubTypes where item.type == photoTypesID select item).ToList();
                ArrayAdapter adapterPST = new ArrayAdapter(Activity, Android.Resource.Layout.SimpleSpinnerItem, (string [])(from item in currentPhotoSubTypes select item.name).ToArray());
                adapterPST.SetDropDownViewResource(Resource.Layout.SpinnerItem);
                spnPhotoSubTypes.Adapter = adapterPST;
            };

            spnPhotoSubTypes = rootView.FindViewById <Spinner> (Resource.Id.pafPhotoSubTypeSpinner);

            btnAddPhoto        = rootView.FindViewById <Button> (Resource.Id.pafAddPhotoButton);
            btnAddPhoto.Click += (object sender, EventArgs e) => {
                if (Common.CreateDirForPhotos(user))
                {
                    string type = photoTypes[spnPhotoTypes.SelectedItemPosition].name;
                    type = Transliteration.Front(type, TransliterationType.Gost).Substring(0, Math.Min(5, type.Length)).ToUpper();
                    string subtype = currentPhotoSubTypes[spnPhotoSubTypes.SelectedItemPosition].name;
                    subtype = Transliteration.Front(subtype, TransliterationType.Gost).Substring(0, Math.Min(5, subtype.Length)).ToUpper();
                    string stamp = DateTime.Now.ToString(@"yyyyMMddHHmmsszz");
                    file = new Java.IO.File(Common.GetDirForPhotos(user), String.Format("PHOTO_{0}_{1}_{2}.jpg", type, subtype, stamp));
                    Intent intent = new Intent(MediaStore.ActionImageCapture);
                    intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(file));
                    StartActivityForResult(intent, 0);
                }
            };

            return(rootView);
        }
Esempio n. 7
0
        void RefreshContent()
        {
            llSyncItems.RemoveAllViews();
            queue = (List <SyncQueue>)SyncQueueManager.GetSyncQueue(selectedDate);
            foreach (var q in queue)
            {
                View view = LayoutInflater.Inflate(Resource.Layout.SyncFragmentItem, null);

                RelativeLayout rl = view.FindViewById <RelativeLayout> (Resource.Id.sfiRelativeLayout);
                ImageView      iv = view.FindViewById <ImageView> (Resource.Id.sfiStatusImage);

                TextView type = view.FindViewById <TextView> (Resource.Id.sfiTypeInfoText);
                TextView loc  = view.FindViewById <TextView> (Resource.Id.sfiLocationText);

                try {
                    if (q.isSync)
                    {
                        rl.SetBackgroundColor(Android.Graphics.Color.LightGreen);
                        iv.SetImageResource(Resource.Drawable.ic_check_circle_white_36dp);
                        type.SetTextAppearance(this, Resource.Style.text_success);
                        loc.SetTextAppearance(this, Resource.Style.text_success_small);
                    }
                    else
                    {
                        rl.SetBackgroundColor(Android.Graphics.Color.LightPink);
                        iv.SetImageResource(Resource.Drawable.ic_highlight_off_white_36dp);
                        type.SetTextAppearance(this, Resource.Style.text_danger);
                        loc.SetTextAppearance(this, Resource.Style.text_danger_small);
                    }

                    Attendance att   = null;
                    Pharmacy   pharm = null;
                    switch (q.type)
                    {
                    case SyncQueueType.sqtAttendance:
                        att       = AttendanceManager.GetAttendance(q.itemID);
                        pharm     = PharmacyManager.GetPharmacy(att.pharmacy);
                        type.Text = string.Format(@"Тип: Посещение аптеки {0} за дату {1}", pharm.fullName, att.date.ToString(@"d"));
                        loc.Text  = string.Format(@"Размещение: {0}", q.fileLocation);
                        break;

                    case SyncQueueType.sqtAttendanceResult:
                        AttendanceResult attRes = AttendanceResultManager.GetAttendanceResult(q.itemID);
                        att       = AttendanceManager.GetAttendance(attRes.attendance);
                        pharm     = PharmacyManager.GetPharmacy(att.pharmacy);
                        type.Text = string.Format(@"Тип: Значение по препарату в посещение аптеки {0} за дату {1}", pharm.fullName, att.date.ToString(@"d"));
                        loc.Text  = string.Format(@"Размещение: {0}", q.fileLocation);
                        break;

                    case SyncQueueType.sqtAttendanceGPSPoint:
                        AttendanceGPSPoint attGPS = AttendanceGPSPointManager.GetAttendanceGPSPoint(q.itemID);
                        att       = AttendanceManager.GetAttendance(attGPS.attendance);
                        pharm     = PharmacyManager.GetPharmacy(att.pharmacy);
                        type.Text = string.Format(@"Тип: GPS значение в посещение аптеки {0} за дату {1} - lat:{2}, lon:{3}", pharm.fullName, att.date.ToString(@"d"), attGPS.latitude, attGPS.longitude);
                        loc.Text  = string.Format(@"Размещение: {0}", q.fileLocation);
                        break;

                    case SyncQueueType.sqtAttendancePhoto:
                        AttendancePhoto attPho = AttendancePhotoManager.GetAttendancePhoto(q.itemID);
                        type.Text = string.Format(@"Фото: {0}", attPho.photoPath);
                        loc.Text  = q.fileLocation;
                        break;

                    default:
                        type.Text = @"Неизвестный тип файла";
                        type.SetTextColor(Android.Graphics.Color.DarkRed);
                        break;
                    }
                } catch (Exception ex) {
                    type.Text = @"Error:";
                    loc.Text  = ex.Message;
                }

                llSyncItems.AddView(view);
            }
        }
Esempio n. 8
0
        void UpLoadAttendances()
        {
            string cookieName  = string.Empty;
            string cookieValue = string.Empty;
            var    user        = Common.GetCurrentUser();

            var login = new RestClient(Settings.URLs.Host);

            //login.Authenticator = new SimpleAuthenticator("identifier", "*****@*****.**", "password", "q1234567");
            login.Authenticator   = new SimpleAuthenticator(@"identifier", user.username, @"password", user.password);
            login.CookieContainer = new CookieContainer();

            var  request  = new RestRequest(@"auth/local", Method.POST);
            var  response = login.Execute <User>(request);
            User userRes  = response.Data;

            if (userRes == null)
            {
                RunOnUiThread(() => progressDialog.SetMessage(@"Не удалось пройти аутентификацию!"));
                return;
            }

            cookieName  = response.Cookies[0].Name;
            cookieValue = response.Cookies[0].Value;

            var queueToUpload = (List <SyncQueue>)SyncQueueManager.GetSyncQueue(selectedDate);

            foreach (var q in queueToUpload)
            {
                try {
                    if ((q.type == SyncQueueType.sqtAttendance) && (!q.isSync))
                    {
                        var client = new RestClient(Settings.URLs.Host);

                        Attendance oldAttendance = SyncQueueManager.GetAttendace(q.fileLocation);
                        RunOnUiThread(() => progressDialog.SetMessage(string.Format(@"Загрузка посещения с id:{0}", oldAttendance.id)));
                        request = new RestRequest(@"Attendance/", Method.POST);
                        request.AddCookie(cookieName, cookieValue);
                        request.RequestFormat = DataFormat.Json;
                        request.JsonSerializer.ContentType = @"application/json; charset=utf-8";
                        //request.AddBody(oldAttendance);
                        request.AddParameter(@"application/json; charset=utf-8", oldAttendance.ToJSON(), ParameterType.RequestBody);
                        var respAttendance = client.Execute <Attendance>(request);

                        Attendance newAttendance = respAttendance.Data;
                        //					Thread.Sleep (500);

                        switch (respAttendance.StatusCode)
                        {
                        case HttpStatusCode.OK:
                        case HttpStatusCode.Created:
                            if (AttendanceResultManager.CreateItemsForSync(oldAttendance, newAttendance) &&
                                AttendancePhotoManager.CreateItemsForSync(oldAttendance, newAttendance) &&
                                AttendanceGPSPointManager.CreateItemsForSync(oldAttendance, newAttendance)
                                )
                            {
                                q.isSync = true;
                                SyncQueueManager.SaveSyncQueue(q, false);
                                RunOnUiThread(() => {
                                    progressDialog.SetMessage(string.Format(@"Посещение с id:{0} ЗАГРУЖЕНО!", oldAttendance.id));
                                    //								RefreshContent ();
                                });
                            }
                            else
                            {
                                RunOnUiThread(() => {
                                    progressDialog.SetMessage(string.Format(@"Не удалось скорректировать данные для посещения с id:{0} ОШИБКА!", oldAttendance.id));
                                    //								RefreshContent ();
                                });
                            }
                            continue;

                        default:
                            //						Thread.Sleep (500);
                            RunOnUiThread(() => progressDialog.SetMessage(@"Не удалось загрузить посещение!"));
                            //						Thread.Sleep (1500);
                            break;
                        }
                    }
                } catch (Exception ex) {
                    RunOnUiThread(() => progressDialog.SetMessage(@"Error : " + ex.Message));
                    //						Thread.Sleep (1500);
                    break;
                }
            }
        }