Ejemplo n.º 1
0
 private void LoadData()
 {
     try
     {
         List <WarehouseViewModel> listW = _logicW.Read(null);
         if (listW != null)
         {
             comboBoxWarehouse.DisplayMember = "Name";
             comboBoxWarehouse.ValueMember   = "Id";
             comboBoxWarehouse.DataSource    = listW;
             comboBoxWarehouse.SelectedItem  = null;
         }
         List <ComponentViewModel> listC = _logicС.Read(null);
         if (listC != null)
         {
             comboBoxComponents.DisplayMember = "ComponentName";
             comboBoxComponents.ValueMember   = "Id";
             comboBoxComponents.DataSource    = listC;
             comboBoxComponents.SelectedItem  = null;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
 }
        private void LoadData()
        {
            try
            {
                var list = _logicW.Read(null);
                if (list != null)
                {
                    dataGridView.DataSource         = list;
                    dataGridView.Columns[0].Visible = false;
                    dataGridView.Columns[4].Visible = false;

                    dataGridView.Columns[1].AutoSizeMode =
                        DataGridViewAutoSizeColumnMode.Fill;
                    dataGridView.Columns[2].AutoSizeMode =
                        DataGridViewAutoSizeColumnMode.Fill;
                    dataGridView.Columns[3].AutoSizeMode =
                        DataGridViewAutoSizeColumnMode.Fill;
                }



                dataGridViewComponents.Rows.Clear();
                if (dataGridView.SelectedRows.Count == 1)
                {
                    int compId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);

                    var listComp = _logicW.Read(new WarehouseBindingModel
                    {
                        Id = compId
                    })?[0];
                    if (listComp != null)
                    {
                        foreach (var lc in listComp.WerehouseComponents)
                        {
                            dataGridViewComponents.Rows.Add(new object[] {
                                lc.Key, lc.Value.Item1, lc.Value.Item2
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }