private void Search()
        {
            var personList = new List <Person>();

            var lokalizacje = LokalizacjaHelper.DajDozwoloneLokalizacje(_lokalizacja);

            using (var ctx = new MineContext())
            {
                personList = ctx.Persons.Include(x => x.Binocles).Include(y => y.Binocles.Select(z => z.Doplaty)).Where(x => lokalizacje.Contains(x.Lokalizacja)).ToList();
            }

            //TODO: refactor above query???
            //https://stackoverflow.com/questions/7259567/linq-to-entities-does-not-recognize-the-method/7259649
            var doWyswietlenia = personList.Where(x => x.Binocles.Any(y => _priceHelper.CzyZbalansowany(y))).ToList(); //zmienić jak w Nieodebrane...czyli przenieść logikę do pobrania wyżej zamiast pobierać wszystkich ludzi

            dataGridView1.DataSource = doWyswietlenia;
            dataGridView1.Columns["Binocles"].Visible = false;
            dataGridView1.Columns["PersonId"].Visible = false;
            dataGridView1.RowHeadersVisible           = true;
            dataGridView1.RowHeadersWidth             = 60;

            dataGridView1.Columns["FirstName"].HeaderText = "Imię";
            dataGridView1.Columns["LastName"].HeaderText  = "Nazwisko";
            dataGridView1.Columns["Address"].HeaderText   = "Adres";
            dataGridView1.Columns["Address"].Width        = 240;
            dataGridView1.Columns["BirthDate"].HeaderText = "Data urodzenia";
            dataGridView1.Columns["Lokalizacja"].Width    = 75;

            if (!dataGridView1.Columns.Contains("ZamowieniaNazwa"))
            {
                DataGridViewButtonColumn col = new DataGridViewButtonColumn();
                col.UseColumnTextForButtonValue = true;
                col.Text       = "Zamówienia";
                col.Name       = "ZamowieniaNazwa";
                col.HeaderText = "Zamówienia";
                dataGridView1.Columns.Add(col);
            }

            if (!dataGridView1.Columns.Contains("UsunCol"))
            {
                DataGridViewButtonColumn col = new DataGridViewButtonColumn();
                col.UseColumnTextForButtonValue = true;
                col.Visible = true;
                col.Text    = "Usuń";
                col.Name    = "UsunCol";
                dataGridView1.Columns.Add(col);
            }

            dataGridView1.Columns["UsunCol"].Visible    = true;
            dataGridView1.Columns["UsunCol"].HeaderText = "Usuń";

            SetRowNumber(dataGridView1);
        }
Esempio n. 2
0
        private void Laduj()
        {
            var binocleList = new List <Binocle>();

            //using (var ctx = new MineContext())
            //{
            binocleList = _context.Binocles.Include(x => x.Doplaty).Where(x => x.Person_PersonId == _personId).ToList();
            //}

            dataGridView1.DataSource = binocleList;

            for (int i = 0; i < dataGridView1.Columns.Count; i++)
            {
                dataGridView1.Columns[i].Visible = false;
            }

            dataGridView1.Columns["BuyDate"].Visible    = true;
            dataGridView1.Columns["BuyDate"].HeaderText = "Data zakupu";

            if (!dataGridView1.Columns.Contains("ZakupCol"))
            {
                DataGridViewButtonColumn col = new DataGridViewButtonColumn();
                col.UseColumnTextForButtonValue = true;
                col.Visible = true;
                col.Text    = "Zakup";
                col.Name    = "ZakupCol";
                dataGridView1.Columns.Add(col);
            }

            dataGridView1.Columns["ZakupCol"].Visible    = true;
            dataGridView1.Columns["ZakupCol"].HeaderText = "Zakup";

            if (!dataGridView1.Columns.Contains("UsunCol"))
            {
                DataGridViewButtonColumn col = new DataGridViewButtonColumn();
                col.UseColumnTextForButtonValue = true;
                col.Visible = true;
                col.Text    = "Usuń";
                col.Name    = "UsunCol";
                dataGridView1.Columns.Add(col);
            }

            dataGridView1.Columns["UsunCol"].Visible    = true;
            dataGridView1.Columns["UsunCol"].HeaderText = "Usuń";

            foreach (var row in dataGridView1.Rows)
            {
                if (_fromWhereOpened == FromWhereConsts.ZBALANSOWANI)
                {
                    if (_priceHelper.CzyZbalansowany((Binocle)((DataGridViewRow)row).DataBoundItem))
                    {
                        ((DataGridViewRow)row).DefaultCellStyle.BackColor = Color.Crimson;
                    }
                }

                if (_fromWhereOpened == FromWhereConsts.ODEBRANIE)
                {
                    if (!_orderHelper.CzyOdebrany((Binocle)((DataGridViewRow)row).DataBoundItem))
                    {
                        ((DataGridViewRow)row).DefaultCellStyle.BackColor = Color.DarkViolet;
                    }
                }
            }
        }