Пример #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            // Create your application here
            SetContentView(Resource.Layout.Route);

            FindViewById <Button>(Resource.Id.raCloseB).Click += (s, e) => {
                MainDatabase.Dispose();
                Finish();
            };

            PharmacyTable            = FindViewById <ListView>(Resource.Id.raPharmacyTable);
            PharmacyTable.ItemClick += (sender, e) => {
                var ll      = (ListView)sender;
                var adapter = (RoutePharmacyAdapter)ll.Adapter;
                adapter.SwitchVisibility(e.Position);

                var row = LayoutInflater.Inflate(Resource.Layout.RouteItem, RouteTable, false);
                row.SetTag(Resource.String.Position, e.Position);

                RouteSearchItem item;
                if (string.IsNullOrEmpty(SearchEditor.Text))
                {
                    item = RouteSearchItems[e.Position];
                }
                else
                {
                    item = SearchedItems[e.Position];
                }

                //TODO: rename vars
                using (var trans = MainDatabase.BeginTransaction()){
                    var newRouteItem = MainDatabase.Create2 <RouteItem>();
                    newRouteItem.Pharmacy = item.UUID;
                    newRouteItem.Order    = RouteTable.ChildCount;
                    newRouteItem.Date     = SelectedDate;
                    trans.Commit();
                    row.SetTag(Resource.String.RouteItemUUID, newRouteItem.UUID);
                }
                row.SetTag(Resource.String.PharmacyUUID, item.UUID);

                row.FindViewById <TextView>(Resource.Id.riPharmacyTV).Text = item.Name;
                row.SetTag(Resource.String.RouteItemOrder, RouteTable.ChildCount);
                row.FindViewById <TextView>(Resource.Id.riOrderTV).Text = (RouteTable.ChildCount + 1).ToString();

                row.FindViewById <ImageView>(Resource.Id.riDeleteIV).Click += RowDelete_Click;
                row.LongClick += Row_LongClick;
                row.Drag      += Row_Drag;

                RouteTable.AddView(row);
            };

            RouteSearchItemsSource = new List <RouteSearchItem>();
            var pharmacies = MainDatabase.GetItems <Pharmacy>();

            foreach (var item in pharmacies)
            {
                RouteSearchItemsSource.Add(
                    new RouteSearchItem(
                        item.UUID,
                        string.IsNullOrEmpty(item.GetName()) ? string.Empty : item.GetName(),
                        string.IsNullOrEmpty(item.Subway) ? string.Empty : MainDatabase.GetItem <Subway>(item.Subway).name,
                        string.IsNullOrEmpty(item.Region) ? string.Empty : MainDatabase.GetItem <Region>(item.Region).name,
                        string.IsNullOrEmpty(item.Brand) ? string.Empty : item.Brand,
                        string.IsNullOrEmpty(item.Address) ? string.Empty : item.Address
                        )
                    );
            }
            SearchedItems  = new List <RouteSearchItem>();
            SearchSwitcher = FindViewById <ViewSwitcher>(Resource.Id.raSearchVS);
            SearchSwitcher.SetInAnimation(this, Android.Resource.Animation.SlideInLeft);
            SearchSwitcher.SetOutAnimation(this, Android.Resource.Animation.SlideOutRight);

            SearchImage        = FindViewById <ImageView>(Resource.Id.raSearchIV);
            SearchImage.Click += (sender, e) => {
                if (CurrentFocus != null)
                {
                    var imm = (InputMethodManager)GetSystemService(InputMethodService);
                    imm.HideSoftInputFromWindow(CurrentFocus.WindowToken, HideSoftInputFlags.None);
                }

                SearchSwitcher.ShowNext();
            };

            SearchEditor = FindViewById <EditText>(Resource.Id.raSearchET);

            SearchEditor.AfterTextChanged += (sender, e) => {
                var text = e.Editable.ToString();

                if (string.IsNullOrEmpty(text))
                {
                    foreach (var item in RouteSearchItems)
                    {
                        item.Match = string.Empty;
                    }
                    PharmacyTable.Adapter = new RoutePharmacyAdapter(this, RouteSearchItems);
                    return;
                }

                var w = new SDiag.Stopwatch();
                w.Start();
                SearchedItems = new List <RouteSearchItem>();
                var matchFormat = @"Совпадение: {0}";
                var culture     = CultureInfo.GetCultureInfo("ru-RU");
                // 2 поиск
                foreach (var item in RouteSearchItems)
                {
                    if (item.IsVisible)
                    {
                        //item.Subway = null;
                        if (culture.CompareInfo.IndexOf(item.Subway, text, CompareOptions.IgnoreCase) >= 0)
                        {
                            item.Match = string.Format(matchFormat, @"метро=" + item.Subway);
                            SearchedItems.Add(item);
                            //if (SearchedItems.Count > C_ITEMS_IN_RESULT) break;
                            continue;
                        }

                        if (culture.CompareInfo.IndexOf(item.Region, text, CompareOptions.IgnoreCase) >= 0)
                        {
                            item.Match = string.Format(matchFormat, @"район=" + item.Region);
                            SearchedItems.Add(item);
                            //if (SearchedItems.Count > C_ITEMS_IN_RESULT) break;
                            continue;
                        }

                        if (culture.CompareInfo.IndexOf(item.Brand, text, CompareOptions.IgnoreCase) >= 0)
                        {
                            item.Match = string.Format(matchFormat, @"бренд=" + item.Brand);
                            SearchedItems.Add(item);
                            //if (SearchedItems.Count > C_ITEMS_IN_RESULT) break;
                            continue;
                        }

                        if (culture.CompareInfo.IndexOf(item.Address, text, CompareOptions.IgnoreCase) >= 0)
                        {
                            item.Match = string.Format(matchFormat, @"адрес");
                            SearchedItems.Add(item);
                            //if (SearchedItems.Count > C_ITEMS_IN_RESULT) break;
                            continue;
                        }
                    }
                }
                w.Stop();
                SDiag.Debug.WriteLine(@"Search: поиск={0}", w.ElapsedMilliseconds);

                PharmacyTable.Adapter = new RoutePharmacyAdapter(this, SearchedItems);
            };

            RouteTable = FindViewById <LinearLayout>(Resource.Id.raRouteTable);

            FindViewById <Button>(Resource.Id.raSelectDateB).Click += (sender, e) => {
                DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime date) {
                    SDiag.Debug.WriteLine("DatePicker:{0}", date.ToLongDateString());
                    SDiag.Debug.WriteLine("DatePicker:{0}", new DateTimeOffset(date));
                    SelectedDate = new DateTimeOffset(date, new TimeSpan(0, 0, 0));;
                    RefreshTables();
                });
                frag.Show(FragmentManager, DatePickerFragment.TAG);
            };

            Info      = FindViewById <TextView>(Resource.Id.raInfoTV);
            Info.Text = string.Format(@"Период планирования: {0} недели ({1} дней)", Helper.WeeksInRoute, Helper.WeeksInRoute * 5);

            var switcher = FindViewById <ViewSwitcher>(Resource.Id.raSwitchViewVS);

            FindViewById <ImageView>(Resource.Id.raSwitchIV).Click += (sender, e) => {
                SDiag.Debug.WriteLine(@"switcher:{0}; Resource{1}", switcher.CurrentView.Id, Resource.Id.raContainerVP);
                if (switcher.CurrentView.Id != Resource.Id.raContainerVP)
                {
                    Info.Text = string.Format(
                        @"Период планирования: {0} недели ({1} дней). Номер недели: {2}",
                        Helper.WeeksInRoute, Helper.WeeksInRoute * 5, 1
                        );
                    var pager = FindViewById <ViewPager>(Resource.Id.raContainerVP);
                    pager.AddOnPageChangeListener(this);
                    pager.Adapter = new RoutePagerAdapter(SupportFragmentManager);
                }
                else
                {
                    Info.Text = string.Format(@"Период планирования: {0} недели ({1} дней)", Helper.WeeksInRoute, Helper.WeeksInRoute * 5);
                }
                switcher.ShowNext();
            };
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            // Create your application here
            SetContentView(Resource.Layout.Profile);

            FindViewById <Button>(Resource.Id.paCloseB).Click += (sender, e) => {
                Finish();
            };

            FindViewById <Button>(Resource.Id.paExitAppB).Click += (sender, e) => {
                int count = 0;

                count += MainDatabase.CountItemsToSync <Attendance>();
                count += MainDatabase.CountItemsToSync <CompetitorData>();
                count += MainDatabase.CountItemsToSync <ContractData>();
                count += MainDatabase.CountItemsToSync <CoterieData>();
                count += MainDatabase.CountItemsToSync <DistributionData>();
                count += MainDatabase.CountItemsToSync <Pharmacy>();
                count += MainDatabase.CountItemsToSync <Employee>();

                count += MainDatabase.CountItemsToSync <GPSData>();

                count += MainDatabase.CountItemsToSync <Hospital>();
                count += MainDatabase.CountItemsToSync <HospitalData>();

                //var monthFinanceDatas = MainDatabase.GetItemsToSync<FinanceDataByMonth>();
                //var quarterFinanceDatas = MainDatabase.GetItemsToSync<FinanceDataByQuarter>();
                //var monthSaleDatas = MainDatabase.GetItemsToSync<SaleDataByMonth>();
                //var quarterSaleDatas = MainDatabase.GetItemsToSync<SaleDataByQuarter>();

                count += MainDatabase.CountItemsToSync <MessageData>();

                count += MainDatabase.CountItemsToSync <PresentationData>();
                count += MainDatabase.CountItemsToSync <PromotionData>();
                count += MainDatabase.CountItemsToSync <ResumeData>();
                count += MainDatabase.CountItemsToSync <RouteItem>();

                count += MainDatabase.CountItemsToSync <RouteItem>();

                count += MainDatabase.CountItemsToSync <PhotoData>();

                if (count > 0)
                {
                    new AlertDialog.Builder(this)
                    .SetTitle(Resource.String.warning_caption)
                    .SetMessage("Перед выходом необходимо синхронизировать все данные!!!")
                    .SetCancelable(true)
                    .SetPositiveButton("OK", (caller, arguments) => {
                        if (caller is Dialog)
                        {
                            (caller as Dialog).Dismiss();
                        }
                    })
                    .Show();
                }
                else
                {
                    GetSharedPreferences(MainActivity.C_MAIN_PREFS, FileCreationMode.Private)
                    .Edit()
                    .PutString(SigninDialog.C_USERNAME, string.Empty)
                    .Commit();
                    MainDatabase.Dispose();
                    Finish();
                }
            };

            Content = FindViewById <LinearLayout>(Resource.Id.paAttendanceByWeekLL);
            Table   = FindViewById <ListView>(Resource.Id.paAttendanceByWeekTable);

            int weeksCount = 14;

            Dates = new DateTimeOffset[weeksCount];
            var header = (LinearLayout)LayoutInflater.Inflate(Resource.Layout.AttendanceByWeekTableHeader, Table, false);

            (header.GetChildAt(0) as TextView).Text = @"Недели";
            for (int w = 0; w < weeksCount; w++)
            {
                Dates[w] = DateTimeOffset.UtcNow.AddDays(-7 * (weeksCount - 1 - w));
                var hView = header.GetChildAt(w + 1);
                if (hView is TextView)
                {
                    (hView as TextView).Text = Helper.GetIso8601WeekOfYear(Dates[w].UtcDateTime.Date).ToString();
                }
            }
            Content.AddView(header, 1);

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

            FindViewById <TextView>(Resource.Id.paUsernameTV).Text = shared.GetString(SigninDialog.C_USERNAME, string.Empty);

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

            try {
                var agent = MainDatabase.GetItem <Agent>(agentUUID);
                FindViewById <TextView>(Resource.Id.paShortNameTV).Text = agent.shortName;
            } catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            SearchSwitcher = FindViewById <ViewSwitcher>(Resource.Id.paSearchVS);
            SearchSwitcher.SetInAnimation(this, Android.Resource.Animation.SlideInLeft);
            SearchSwitcher.SetOutAnimation(this, Android.Resource.Animation.SlideOutRight);

            SearchImage        = FindViewById <ImageView>(Resource.Id.paSearchIV);
            SearchImage.Click += (sender, e) => {
                if (CurrentFocus != null)
                {
                    var imm = (InputMethodManager)GetSystemService(InputMethodService);
                    imm.HideSoftInputFromWindow(CurrentFocus.WindowToken, HideSoftInputFlags.None);
                }

                SearchSwitcher.ShowNext();
            };

            SearchEditor = FindViewById <EditText>(Resource.Id.paSearchET);

            SearchEditor.AfterTextChanged += (sender, e) => {
                var text = e.Editable.ToString();

                (Table.Adapter as AttendanceByWeekAdapter).SetSearchText(text);
            };
        }