Example #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            Xamarin.Insights.Initialize(XamarinInsights.ApiKey, this);
            base.OnCreate(savedInstanceState);

            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);
            locMgr = GetSystemService(Context.LocationService) as LocationManager;

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            upPanel       = FindViewById <RelativeLayout> (Resource.Id.maUpPanelRL);
            botPanel      = FindViewById <RelativeLayout> (Resource.Id.maDownPanelRL);
            beforeSignIn  = FindViewById <RelativeLayout> (Resource.Id.sifBeforeSignInRL);
            content       = FindViewById <FrameLayout> (Resource.Id.maContentFL);
            pharamcyTable = FindViewById <TableLayout> (Resource.Id.maPharmacyTable);
            bSignIn       = FindViewById <Button> (Resource.Id.maSignInButton);
            next          = FindViewById <ImageView> (Resource.Id.maNextImage);
            prev          = FindViewById <ImageView> (Resource.Id.maPrevImage);
            pageNum       = FindViewById <TextView> (Resource.Id.maPageText);

            // Up Panel
            upNextBlock        = FindViewById <ImageView> (Resource.Id.maNextBockIV);
            upNextBlock.Click += (object sender, EventArgs e) => {
                if (fragmentNum < 3)
                {
                    fragmentNum++;
                    RefreshContent();
                }
            };
            upPrevBlock        = FindViewById <ImageView> (Resource.Id.maPrevBlockIV);
            upPrevBlock.Click += (object sender, EventArgs e) => {
                if (fragmentNum > 1)
                {
                    fragmentNum--;
                    RefreshContent();
                }
            };
            upInfo          = FindViewById <TextView> (Resource.Id.maInfoText);
            upLogout        = FindViewById <ImageView> (Resource.Id.maLogOut);
            upLogout.Click += (object sender, EventArgs e) => {
                Common.SetCurrentUser(null);
                RefreshMainView();
            };
            upSync        = FindViewById <ImageView> (Resource.Id.maSync);
            upSync.Click += (object sender, EventArgs e) => {
                StartActivity(typeof(SyncActivity));
            };
            upStartAttendance        = FindViewById <Button> (Resource.Id.maStartAttendance);
            upStartAttendance.Click += UpStartAttendance_Click;
            upEndAttendance          = FindViewById <Button> (Resource.Id.maEndAttendance);
            upEndAttendance.Click   += UpEndAttendance_Click;
            upClose        = FindViewById <Button> (Resource.Id.maClose);
            upClose.Click += UpRightB_Click;

            next.Click += (object sender, EventArgs e) => {
                page++;
                if (page == 1)
                {
                    prev.Enabled = false;
                }
                else
                {
                    prev.Enabled = true;
                }
                RefreshPharmacyTable();
            };

            prev.Click += (object sender, EventArgs e) => {
                page--;
                if (page == 1)
                {
                    prev.Enabled = false;
                }
                else
                {
                    prev.Enabled = true;
                }
                RefreshPharmacyTable();
            };

            bSignIn.Click += (object sender, EventArgs e) => {
                //rlBeforeSignIn.Visibility = ViewStates.Gone;
                FragmentTransaction trans        = FragmentManager.BeginTransaction();
                SigninDialog        signinDialog = new SigninDialog(this);
                signinDialog.Show(trans, "dialog fragment");
                signinDialog.SuccessSignedIn += SigninDialog_SuccessSignedIn;

                Log.Info("maSignInButton", "Click");
            };

//			Common.SetCurrentUser (null);
            RefreshMainView();

//			List<Attendance> atts =(List<Attendance>) AttendanceManager.GetAttendances ();
//			foreach (var item in atts) {
//				SyncQueueManager.AddToQueue (item);
//			}
        }
        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);

            user = Common.GetCurrentUser ();

            //return base.OnCreateView (inflater, container, savedInstanceState);

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

            rlBeforeSignIn = rootView.FindViewById<RelativeLayout> (Resource.Id.ifBeforeSignInLayout);
            llAfterSignIn = rootView.FindViewById<LinearLayout> (Resource.Id.ifAfterSignInLayout);

            bSignIn = rootView.FindViewById<Button> (Resource.Id.ifSignInButton);

            bSignIn.Click += (object sender, EventArgs e) => {
                //rlBeforeSignIn.Visibility = ViewStates.Gone;
                FragmentTransaction trans = FragmentManager.BeginTransaction ();
                SigninDialog signinDialog = new SigninDialog (this.Activity);
                //signinDialog.Dialog.SetCanceledOnTouchOutside(true); //Cancelable = true;
                //signinDialog
                signinDialog.Show (trans, "dialog fragment");

            //				Resource.Drawable.

                Log.Info ("ifSignInButton", "Click");
            };

            if (user != null) {
                Log.Info ("InfoFragment", "user IS NOT NULL");

                rlBeforeSignIn.Visibility = ViewStates.Gone;

                Rout rout = new Rout (){Date = DateTime.Now};

                View userCard = inflater.Inflate (Resource.Layout.InfoCard, container, false);
                var ucTitle = userCard.FindViewById<TextView> (Resource.Id.icTitle);
                var ucTable = userCard.FindViewById<TableLayout> (Resource.Id.icInfoTable);

                ucTitle.Text = @"Пользователь";

                ucTable.AddView (GetRow(@"ID", user.id.ToString()));
                ucTable.AddView (GetRow(@"Username", user.username));
                ucTable.AddView (GetRow(@"E-mail", user.email));
                ucTable.AddView (GetRow(@"Password", user.password));

                llAfterSignIn.AddView(userCard);

                View merchantCard = inflater.Inflate (Resource.Layout.InfoCard, container, false);
                var mcTitle = merchantCard.FindViewById<TextView> (Resource.Id.icTitle);
                var mcTable = merchantCard.FindViewById<TableLayout> (Resource.Id.icInfoTable);

                mcTitle.Text = @"Представитель";

                var merchant = Common.GetMerchant (user.username);
                mcTable.AddView (GetRow(@"ID", merchant.id.ToString()));
                mcTable.AddView (GetRow(@"ФИО", merchant.lastName + @" " +merchant.firstName));
                mcTable.AddView (GetRow(@"Телефон", merchant.phone));
                mcTable.AddView (GetRow(@"Менеджер", merchant.manager.ToString()));

                llAfterSignIn.AddView(merchantCard);

                View managerCard = inflater.Inflate (Resource.Layout.InfoCard, container, false);
                var managercTitle = managerCard.FindViewById<TextView> (Resource.Id.icTitle);
                var managercTable = managerCard.FindViewById<TableLayout> (Resource.Id.icInfoTable);

                managercTitle.Text = @"Менеджер";

                var manager = Common.GetManager (user.username);
                managercTable.AddView (GetRow(@"ID", manager.id.ToString()));
                managercTable.AddView (GetRow(@"ФИО", manager.lastName + @" " +manager.firstName));
                managercTable.AddView (GetRow(@"Телефон", manager.phone));
                managercTable.AddView (GetRow(@"Начальник", manager.head.ToString()));

                llAfterSignIn.AddView(managerCard);

                View projectCard = inflater.Inflate (Resource.Layout.InfoCard, container, false);
                var projectcTitle = projectCard.FindViewById<TextView> (Resource.Id.icTitle);
                var projectcTable = projectCard.FindViewById<TableLayout> (Resource.Id.icInfoTable);

                projectcTitle.Text = @"Проект";

                var project = Common.GetProject (user.username);
                projectcTable.AddView (GetRow(@"ID", project.id.ToString()));
                projectcTable.AddView (GetRow(@"Название", project.fullName));
                projectcTable.AddView (GetRow(@"Описание", project.description));
                if (project.drugs != null) {
                    projectcTable.AddView (GetRow (@"Препараты", string.Join (", ", project.drugs)));
                } else {
                    projectcTable.AddView (GetRow (@"Препараты", @""));
                }

                llAfterSignIn.AddView(projectCard);

                View drugsCard = inflater.Inflate (Resource.Layout.InfoCard, container, false);
                var drugscTitle = drugsCard.FindViewById<TextView> (Resource.Id.icTitle);
                var drugscTable = drugsCard.FindViewById<TableLayout> (Resource.Id.icInfoTable);

                drugscTitle.Text = @"Препараты";

                var drugs = Common.GetDrugs (user.username);
                drugscTable.AddView (GetRow(@"ID", @"Наименование"));
                foreach (var drug in drugs) {
                    drugscTable.AddView (GetRow(drug.id.ToString(), drug.fullName));
                }

                llAfterSignIn.AddView(drugsCard);

                View territoryCard = inflater.Inflate (Resource.Layout.InfoCard, container, false);
                var territoryTitle = territoryCard.FindViewById<TextView> (Resource.Id.icTitle);
                var territoryTable = territoryCard.FindViewById<TableLayout> (Resource.Id.icInfoTable);

                territoryTitle.Text = @"Территория";

                var territory = Common.GetTerritory (user.username);
                territoryTable.AddView (GetRow(@"ID", territory.id.ToString()));
                territoryTable.AddView (GetRow(@"Название", territory.name));
                territoryTable.AddView (GetRow(@"Информация", territory.info));
                territoryTable.AddView (GetRow (@"Осн. город", territory.baseCity));
                var pharmacies = PharmacyManager.GetPharmacies ();
                territoryTable.AddView (GetRow (@"Кол-во аптек", pharmacies.Count.ToString()));

                llAfterSignIn.AddView(territoryCard);
            }
            //string [] planets = Resources.GetStringArray (Resource.Array.planets_array);
            //TextView txt = rootView.FindViewById<TextView> (Resource.Id.text);
            //txt.Text = @"Hi!";//planets [this.Arguments.GetInt (POSITION)];

            return rootView;
        }
Example #3
0
        protected override void OnResume()
        {
            base.OnResume();

            //Start Tracking usage in this activit
            Tracking.StartUsage(this);

            var shared = GetSharedPreferences(C_MAIN_PREFS, FileCreationMode.Private);

            string username = shared.GetString(SigninDialog.C_USERNAME, string.Empty);

            if (string.IsNullOrEmpty(username))
            {
                Pharmacies            = new List <Pharmacy>();     //.Take(14).ToList();
                PharmacyTable.Adapter = new PharmacyAdapter(this, Pharmacies);

                var fragmentTransaction = FragmentManager.BeginTransaction();
                var prev = FragmentManager.FindFragmentByTag(SigninDialog.TAG);
                if (prev != null)
                {
                    fragmentTransaction.Remove(prev);
                }
                fragmentTransaction.AddToBackStack(null);

                var signinDialog = new SigninDialog(this);
                signinDialog.Show(fragmentTransaction, SigninDialog.TAG);
                signinDialog.SuccessSignedIn += (caller, arguments) => {
                    //Toast.MakeText(this, @"SuccessSignedIn", ToastLength.Short).Show();
                    RunOnUiThread(() => {
                        OnResume();
                        SDiag.Debug.WriteLine(@"DBPath = {0}", MainDatabase.DBPath);
                    });
                };

                SDiag.Debug.WriteLine(@"username = IsNullOrEmpty");
                return;
            }

            var ft = FragmentManager.BeginTransaction();
            var sd = FragmentManager.FindFragmentByTag(SigninDialog.TAG);

            if (sd != null)
            {
                ft.Remove(sd);
            }
            ft.Commit();

            if (!IsLocationActive() || !IsInternetActive())
            {
                return;
            }

            MainDatabase.Username = username;
            Helper.Username       = username;

            var agentUUID = shared.GetString(SigninDialog.C_AGENT_UUID, string.Empty);

            try {
                var agent = MainDatabase.GetItem <Agent>(agentUUID);
                MainDatabase.AgentUUID = agent.uuid;
                Helper.WeeksInRoute    = agent.weeksInRout;
                Helper.WorkMode        = agent.GetWorkMode();
                Helper.AndroidId       = Helper.GetAndroidId(this);
            } catch (Exception ex) {
                SDiag.Debug.WriteLine(ex.Message);
            }


            var packageInfo = ApplicationContext.PackageManager.GetPackageInfo(ApplicationContext.PackageName, 0);
            var version     = string.Format("Версия: {0} ({1})", packageInfo.VersionName, packageInfo.VersionCode);

            FindViewById <TextView>(Resource.Id.maVersionTV).Text = version;

            var w = new SDiag.Stopwatch();

            w.Restart();
            var currentRouteItems = MainDatabase.GetRouteItems(DateTimeOffset.Now);

            if (currentRouteItems.Count() > 0)
            {
                var nextDate      = DateTimeOffset.Now.AddDays(Helper.WeeksInRoute * 7);
                var date          = new DateTimeOffset(nextDate.Year, nextDate.Month, nextDate.Day, 0, 0, 0, new TimeSpan(0, 0, 0));
                var nextRoutItems = MainDatabase.GetRouteItems(date);

                if (nextRoutItems.Count() == 0)
                {
                    using (var trans = MainDatabase.BeginTransaction()){
                        foreach (var oldItem in currentRouteItems)
                        {
                            var newItem = MainDatabase.Create2 <RouteItem>();
                            newItem.Pharmacy = oldItem.Pharmacy;
                            newItem.Date     = date;
                            newItem.Order    = oldItem.Order;
                        }
                        trans.Commit();
                    }
                }
            }
            w.Stop();
            SDiag.Debug.WriteLine(@"Route: копирование={0}", w.ElapsedMilliseconds);

            w.Restart();
            int count = MainDatabase.GetItems <Attendance>()
                        .Count(att => att.When.LocalDateTime.Date == DateTimeOffset.Now.Date);

            AttendanceCount.Text = string.Format(
                @"РЕЖИМ РАБОТЫ: {0};  СЕГОДНЯ ВИЗИТОВ: {1}", Helper.GetWorkModeDesc(Helper.WorkMode), count
                );
            w.Stop();
            SDiag.Debug.WriteLine(@"OnResume: подсчет визитов={0}", w.ElapsedMilliseconds);

            var  sparseArray = SearchTable.CheckedItemPositions;
            bool hasCheckedItemInSearchTable = false;

            for (var i = 0; i < sparseArray.Size(); i++)
            {
                if (sparseArray.ValueAt(i))
                {
                    hasCheckedItemInSearchTable = true;
                    break;
                }
            }

            if (!hasCheckedItemInSearchTable)
            {
                RecreateAdapter();
            }

            var prefs = GetSharedPreferences(C_MAIN_PREFS, FileCreationMode.Private);
            var uuid  = prefs.GetString(C_SAVED_PHARMACY_UUID, string.Empty);

            if (string.IsNullOrEmpty(uuid))
            {
                return;
            }

            if (SearchItems == null)
            {
                return;
            }

            if (SearchItems.ContainsKey(uuid))
            {
                w.Start();
                var pharmacy = MainDatabase.GetEntity <Pharmacy>(uuid);
                SearchItems[uuid] = new SearchItem(
                    pharmacy.UUID,
                    pharmacy.GetName(),
                    string.IsNullOrEmpty(pharmacy.Subway) ? string.Empty : MainDatabase.GetItem <Subway>(pharmacy.Subway).name,
                    string.IsNullOrEmpty(pharmacy.Region) ? string.Empty : MainDatabase.GetItem <Region>(pharmacy.Region).name,
                    string.IsNullOrEmpty(pharmacy.Brand) ? string.Empty : pharmacy.Brand
                    );
            }
            prefs.Edit().PutString(C_SAVED_PHARMACY_UUID, string.Empty).Commit();
            w.Stop();
            SDiag.Debug.WriteLine(@"Search: обновление={0}", w.ElapsedMilliseconds);
        }