Exemplo n.º 1
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);

            base.OnCreateView (inflater, container, savedInstanceState);

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

            pharmacyID = Arguments.GetInt (Common.PHARMACY_ID);
            user = Common.GetCurrentUser ();
            netCategories = Common.GetNetCategories (user.username);
            promos = Common.GetPromos (user.username);
            merchant = Common.GetMerchant (user.username);
            territory = Common.GetTerritory (user.username);
            pharmacy = PharmacyManager.GetPharmacy (pharmacyID);

            var tradenets = Common.GetTradeNets (user.username);
            Dictionary <int, string> tnDict = new Dictionary<int, string> ();
            foreach (var item in tradenets) {
                tnDict.Add (item.id, item.shortName);
            };

            attendance = AttendanceManager.GetCurrentAttendance ();
            if (attendance == null) {
                attendance = AttendanceManager.GetLastAttendance (pharmacyID);

                if (attendance == null) {
                    attendance = new Attendance () {
                        pharmacy = pharmacyID,
                        date = DateTime.Now,
                        merchant = merchant.id
                    };
                } else {
                    attendance.id = -1;
                    attendance.date = DateTime.Now;
                }
            }

            rootView.FindViewById<TextView> (Resource.Id.b1fTradenetText).Text = tnDict [pharmacy.tradenet];//@"Аптечная Сеть";
            rootView.FindViewById<TextView> (Resource.Id.b1fCityText).Text = territory.baseCity;
            rootView.FindViewById<TextView> (Resource.Id.b1fPharmacyNameText).Text = pharmacy.shortName;
            rootView.FindViewById<TextView> (Resource.Id.b1fPharmacyAddressText).Text = pharmacy.address;
            rootView.FindViewById<TextView> (Resource.Id.b1fCategoryInOTCText).Text = pharmacy.category_otc;
            rootView.FindViewById<TextView> (Resource.Id.b1fLastAttendanceText).Text = pharmacy.prev == DateTime.MinValue ? String.Empty : pharmacy.prev.ToString (@"d");
            rootView.FindViewById<TextView> (Resource.Id.b1fNextAttendanceText).Text = pharmacy.next == DateTime.MinValue ? String.Empty : pharmacy.next.ToString (@"d");
            rootView.FindViewById<TextView> (Resource.Id.b1fAllAttendanciesText).Text = AttendanceManager.GetStatistics(pharmacy.id);

            categoryNetSpinner = rootView.FindViewById<Spinner> (Resource.Id.b1fCategoryNetSpinner);
            ArrayAdapter adapter = new ArrayAdapter (Activity, Android.Resource.Layout.SimpleSpinnerItem, (from item in netCategories select item.key).ToArray<string>());
            adapter.SetDropDownViewResource(Resource.Layout.SpinnerItem);
            categoryNetSpinner.Adapter = adapter;
            categoryNetSpinner.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => {
                attendance.category_net = netCategories[e.Position].id;
            };
            // SetValue
            for (int i = 0; i < netCategories.Count; i++) {
                if (netCategories [i].id == attendance.category_net) {
                    categoryNetSpinner.SetSelection (i);
                }
            }

            telephoneEdit = rootView.FindViewById<EditText> (Resource.Id.b1fTelephoneEdit);
            telephoneEdit.Text = attendance.telephone;

            purchaserFIOEdit = rootView.FindViewById<EditText> (Resource.Id.b1fPurchaserFIOEdit);
            purchaserFIOEdit.Text = attendance.purchaserFIO;

            promosEdit = rootView.FindViewById<EditText> (Resource.Id.b1fPromosEdit);
            promosButton = rootView.FindViewById<Button> (Resource.Id.b1fPromosButton);
            promosButton.Click += (object sender, EventArgs e) => {
                bool[] checkedItems = new bool[promos.Count];
                if (attendance.promos != null) {
                    for (int i = 0; i < promos.Count; i++) {
                        if(attendance.promos.Contains(promos[i].id)){
                            checkedItems[i] = true;
                            tempPromos.Add(promos[i].id);
                        }
                    }
                }
                string[] items = (from promo
                                 	in promos
                                orderby promo.id
                                 select promo.name).ToArray<string>();
                AlertDialog.Builder builder;
                builder = new AlertDialog.Builder(Activity);
                builder.SetTitle("Выбор ПРОМО-матералов");
                builder.SetCancelable(false);
                builder.SetMultiChoiceItems(items, checkedItems, MultiListClicked);
                builder.SetPositiveButton(@"Сохранить",
                    delegate {
                        attendance.promos = tempPromos.ToArray<int>();
                        builder.Dispose();
                        RefreshPromos();
                    }
                );
                builder.SetNegativeButton(@"Отмена", delegate { builder.Dispose(); });
                builder.Show();
            };
            RefreshPromos();

            pharmacistCountEdit = rootView.FindViewById<EditText> (Resource.Id.b1fPharmacistCountEdit);
            pharmacistCountEdit.Text = attendance.pharmacistCount.ToString ();

            commentEdit = rootView.FindViewById<EditText> (Resource.Id.b1fCommentEdit);
            commentEdit.Text = attendance.comment;

            RefreshControlsState ();
            return rootView;
        }
Exemplo n.º 2
0
        public static bool SetTerritory(string username, Territory territory)
        {
            string storeLocation = Path.Combine(DatabaseFileDir, username, @"territory.xml");
            new FileInfo(storeLocation).Directory.Create();
            var serializer = new XmlSerializer(typeof(Territory));
            using (var writer = new StreamWriter(storeLocation))
            {
                serializer.Serialize(writer, territory);
            }

            return true;
        }