Пример #1
0
        void RefreshPharmacyTable()
        {
            pharamcyTable.Visibility = ViewStates.Visible;

            //Add Header Row
            TableRow hRow = new TableRow(this);

            hRow.SetBackgroundResource(Resource.Drawable.bottomline);

            TextView hID = GetHeadItem(ColumnPosition.cpFirst);

            hID.Gravity = GravityFlags.Center;
            hID.Text    = @"ID";
            hRow.AddView(hID);

            TextView hShortName = GetHeadItem(ColumnPosition.cpMiddle);

            hShortName.Gravity = GravityFlags.CenterVertical;
            hShortName.Text    = @"Аптека";
            hRow.AddView(hShortName);

            TextView hTradeNet = GetHeadItem(ColumnPosition.cpMiddle);

            hTradeNet.Gravity = GravityFlags.CenterVertical;
            hTradeNet.Text    = @"Сеть";
            hRow.AddView(hTradeNet);

            TextView hAddress = GetHeadItem(ColumnPosition.cpMiddle);

            hAddress.Gravity = GravityFlags.CenterVertical;
            hAddress.Text    = @"Адрес";
            hRow.AddView(hAddress);

            TextView hWeekM2 = GetHeadItem(ColumnPosition.cpMiddle);

            hWeekM2.Gravity = GravityFlags.CenterVertical;
            hWeekM2.Text    = @"Неделя -2";
            hRow.AddView(hWeekM2);

            TextView hWeekM1 = GetHeadItem(ColumnPosition.cpMiddle);

            hWeekM1.Gravity = GravityFlags.CenterVertical;
            hWeekM1.Text    = @"Неделя -1";
            hRow.AddView(hWeekM1);

            TextView hWeek = GetHeadItem(ColumnPosition.cpMiddle);

            hWeek.Gravity = GravityFlags.CenterVertical;
            hWeek.Text    = @"Текущ. неделя";
            hRow.AddView(hWeek);

            TextView hWeekP1 = GetHeadItem(ColumnPosition.cpMiddle);

            hWeekP1.Gravity = GravityFlags.CenterVertical;
            hWeekP1.Text    = @"Неделя +1";
            hRow.AddView(hWeekP1);

            TextView hWeekP2 = GetHeadItem(ColumnPosition.cpLast);

            hWeekP2.Gravity = GravityFlags.CenterVertical;
            hWeekP2.Text    = @"Неделя +2";
            hRow.AddView(hWeekP2);

            pharamcyTable.AddView(hRow);

            // Content
            if (pharamcyTable != null)
            {
                int childCount = pharamcyTable.ChildCount;

                // Remove all rows except the first one
                if (childCount > 1)
                {
                    pharamcyTable.RemoveViews(1, childCount - 1);
                }

                pageNum.Text = string.Format(@"СТРАНИЦА : {0}", page);
                var pharmacies = (from pharm in PharmacyManager.GetPharmacies(string.Empty)
                                  orderby pharm.next, pharm.id
                                  select pharm).Skip((page - 1) * itemsNum)
                                 .Take(itemsNum);

                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);
                }
                ;

                foreach (var pharmacy in pharmacies)
                {
                    TableRow cRow = new TableRow(this);
                    if (pharmacy.prev.Date == DateTime.Now.Date)
                    {
                        cRow.SetBackgroundResource(Resource.Drawable.bottomline_green);
                    }
                    else if (pharmacy.next.Date < DateTime.Now.Date && pharmacy.prev != DateTime.MinValue)
                    {
                        cRow.SetBackgroundResource(Resource.Drawable.bottomline_red);
                    }
                    else
                    {
                        cRow.SetBackgroundResource(Resource.Drawable.bottomline);
                    }

                    TextView id = GetItem(ColumnPosition.cpFirst);
                    id.Gravity = GravityFlags.Center;
                    id.Text    = pharmacy.id.ToString();
                    cRow.AddView(id);

                    TextView shortName = GetItem(ColumnPosition.cpMiddle);
                    shortName.Gravity = GravityFlags.CenterVertical;
                    shortName.Text    = pharmacy.shortName;
                    shortName.SetSingleLine(true);
                    shortName.Ellipsize = Android.Text.TextUtils.TruncateAt.End;
                    cRow.AddView(shortName);

                    TextView tradeNet = GetItem(ColumnPosition.cpMiddle);
                    tradeNet.Gravity = GravityFlags.CenterVertical;
                    //tradeNet.Text = pharmacy.tradenet.ToString();
                    tradeNet.Text = tnDict[pharmacy.tradenet];
                    cRow.AddView(tradeNet);

                    TextView address = GetItem(ColumnPosition.cpMiddle);
                    address.Gravity = GravityFlags.CenterVertical;
                    address.Text    = pharmacy.address;
                    cRow.AddView(address);

                    DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
                    Calendar           cal = dfi.Calendar;
                    int dWeekM             = (cal.GetWeekOfYear(pharmacy.prev, dfi.CalendarWeekRule, dfi.FirstDayOfWeek) - cal.GetWeekOfYear(DateTime.Now, dfi.CalendarWeekRule, dfi.FirstDayOfWeek));
                    int dWeekP             = (cal.GetWeekOfYear(pharmacy.next, dfi.CalendarWeekRule, dfi.FirstDayOfWeek) - cal.GetWeekOfYear(DateTime.Now, dfi.CalendarWeekRule, dfi.FirstDayOfWeek));

                    TextView weekM2 = GetItem(ColumnPosition.cpMiddle);
                    weekM2.Gravity = GravityFlags.CenterVertical;
                    weekM2.Text    = (dWeekM == -2) ? pharmacy.prev.ToString(@"d") : string.Empty;
                    cRow.AddView(weekM2);

                    TextView weekM1 = GetItem(ColumnPosition.cpMiddle);
                    weekM1.Gravity = GravityFlags.CenterVertical;
                    weekM1.Text    = (dWeekM == -1) ? pharmacy.prev.ToString(@"d") : string.Empty;
                    cRow.AddView(weekM1);

//					ImageView action = GetImageItem (ColumnPosition.cpMiddle);
//					action.SetImageResource (Resource.Drawable.ic_adjust_black_24dp);
//					action.SetTag (Resource.String.pharmacyID, pharmacy.id);
//					action.Click += Action_Click;
//					cRow.AddView (action);

                    Button action = GetButtonItem(ColumnPosition.cpMiddle);
                    action.Text = DateTime.Now.ToString(@"d");
                    action.SetTag(Resource.String.pharmacyID, pharmacy.id);
                    action.Click += Action_Click;
                    cRow.AddView(action);

                    TextView weekP1 = GetItem(ColumnPosition.cpMiddle);
                    weekP1.Gravity = GravityFlags.CenterVertical;
                    weekP1.Text    = (dWeekP == 1) ? pharmacy.next.ToString(@"d") : string.Empty;
                    cRow.AddView(weekP1);

                    TextView weekP2 = GetItem(ColumnPosition.cpLast);
                    weekP2.Gravity = GravityFlags.CenterVertical;
                    weekP2.Text    = (dWeekP == 2) ? pharmacy.next.ToString(@"d") : string.Empty;
                    cRow.AddView(weekP2);

                    pharamcyTable.AddView(cRow);
                }
            }
        }