예제 #1
0
        private void AutoComplete_ItemClick(object sender, EventArgs eventArgs)
        {
            var itemView = sender as TextView;

            if (itemView.Text == limitRows.limValueText)
            {
                autocomplete.SetText("", TextView.BufferType.Normal);
                return;
            }

            if (хdoc == null)
            {
                хdoc = XDocument.Load(Resources.GetXml(Resource.Xml.codes));
            }

            var search = itemView.Text.Split('|').Select(p => p.Trim()).ToList();

            var item  = хdoc.Root.Elements("item").Where(x => (string)x.Attribute("order") == search[0] && (string)x.Attribute("type") == search[1]).FirstOrDefault();
            var brend = item.FirstAttribute.Value;

            textView2.SetText(Html.FromHtml("<b>Бренд:</b> " + brend), TextView.BufferType.Editable);

            tableLayout.RemoveAllViewsInLayout();
            tableLayout.RemoveAllViews();

            TableLayout.LayoutParams par = new TableLayout.LayoutParams(TableLayout.LayoutParams.WrapContent, TableLayout.LayoutParams.MatchParent);
            par.SetMargins(20, 0, 20, 0);
            tableLayout.LayoutParameters = par;

            if (item != null)
            {
                var codeData = new List <string>()
                {
                    item.Attribute("series").Value,
                    item.Attribute("custom").Value,
                    item.Attribute("model").Value
                };

                var isVacon = (brend == "Vacon" ? true : false);

                txtView = new TextView(this);
                txtView.SetText(Html.FromHtml("<b>Аналог марки VLT</b>"), TextView.BufferType.Editable);
                txtView.Gravity = GravityFlags.Left;
                txtView.SetPadding(25, 25, 25, 25);
                txtView.SetTextColor(Color.Black);
                txtView.SetTextSize(Android.Util.ComplexUnitType.Dip, 20);

                var tableRow = new TableRow(this);
                tableRow.AddView(txtView);
                tableLayout.AddView(tableRow);

                for (int i = 0; i < codeData.Count; i++)
                {
                    var txt = "<b>";
                    if (i == 0)
                    {
                        txt += "Серия:";
                    }
                    else if (i == 1)
                    {
                        txt += "Заказной код:";
                    }
                    else if (i == 2)
                    {
                        txt += "Типовой код:";
                    }
                    txt += "</b> ";

                    txtView = new TextView(this);
                    txtView.SetText(Html.FromHtml(txt + (i == 0 && isVacon ? "Micro Drive" : codeData[i])), TextView.BufferType.Editable);
                    txtView.SetBackgroundResource(Resource.Layout.finded);
                    txtView.Gravity = GravityFlags.Left;
                    txtView.SetPadding(25, 25, 25, 25);
                    txtView.SetTextColor(Color.Black);

                    tableRow = new TableRow(this);
                    tableRow.LayoutParameters = new TableRow.LayoutParams(TableRow.LayoutParams.WrapContent, TableRow.LayoutParams.MatchParent);
                    tableRow.AddView(txtView);
                    tableLayout.AddView(tableRow);
                }

                if (!isVacon)
                {
                    var items = хdoc.Root.Elements("item")
                                .Where(x => (string)x.Attribute("brend") == "Vacon" &&
                                       (string)x.Attribute("custom") == item.Attribute("custom").Value &&
                                       (string)x.Attribute("series") != "VACON 10" && (string)x.Attribute("series") != "VACON NXL")
                                .ToList();

                    if (items != null && items.Count > 0)
                    {
                        txtView = new TextView(this);
                        txtView.SetText(Html.FromHtml("<b>Аналог марки Vacon</b>"), TextView.BufferType.Editable);
                        txtView.Gravity = GravityFlags.Left;
                        txtView.SetPadding(25, 50, 25, 25);
                        txtView.SetTextColor(Color.Black);
                        txtView.SetTextSize(Android.Util.ComplexUnitType.Dip, 20);

                        tableRow = new TableRow(this);
                        tableRow.AddView(txtView);

                        tableLayout.AddView(tableRow);

                        drawItems(items, tableLayout, tableRow);
                    }
                }

                Toast.MakeText(this, "Поиск завершен", ToastLength.Short).Show();

                hideKeyBoard();

                bntSendFromMain.Visibility = ViewStates.Visible;
            }
        }