Ejemplo n.º 1
0
        private async void Save(object sender, EventArgs e)
        {
            _this.Name        = txtName.Text;
            _this.Description = txtDescription.Text;
            _this.PlaceId     = cmbPlace.GetSelectedValue <Place>();

            try
            {
                Looper.Show(this);
                if (mode == 1)
                {
                    _this.CreatedBy = RuntimeSettings.UserId;
                    _this.CreatedOn = DateTime.Now;

                    if (await _this.Add())
                    {
                        mode      = 2;
                        this.Text = "Szczegóły komponentu";
                    }
                }
                else if (mode == 2)
                {
                    _this.Edit();
                }
            }catch (Exception ex)
            {
            }
            finally
            {
                Looper.Hide();
            }
        }
Ejemplo n.º 2
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            PlaceId = cmbPlace.GetSelectedValue <Place>();
            if (PlaceId == null || PlaceId == 0)
            {
                MessageBox.Show("Z listy rozwijanej wybierz zasób, dla którego chcesz utworzyć komponenty.", "Nie wybrano zasobu", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string[] components;
                components = txtComponents.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                List <Task <bool> > tasks = new List <Task <bool> >();
                if (components.Length > 0)
                {
                    foreach (string s in components)
                    {
                        Component c = new Component();
                        c.CreatedBy = RuntimeSettings.UserId;
                        c.CreatedOn = DateTime.Now;
                        c.PlaceId   = PlaceId;
                        c.Name      = s;
                        tasks.Add(c.Add());
                    }

                    string             response = "";
                    IEnumerable <bool> res      = await Task.WhenAll <bool>(tasks);

                    if (res.Where(r => r == false).Any())
                    {
                        MessageBox.Show($"Nie udało się dodać {res.Count(r => r == false)} komponentów. Dodano {res.Count(r => r)} komponentów.", "Niepełne powodzenie", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show($"Dodawanie {res.Count(r => r)} komponentów zakończone powodzeniem.", "Sukces", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("W polu tekstowym wpisz nazwy komponentów dla tego zasobu. Jeden komponent w jednej linii!", "Nie podano komponentów", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }