Пример #1
0
        private async void Sheet_CellsChanged(object sender, CellChangedEvent e)
        {
            var addCells = e.Cells
                           .Where(c => c.Column.Index == this.InvoiceLinesFirstColumn + 1 &&
                                  !this.Controls.ControlByCell.ContainsKey(c)).ToArray();

            // When a new detail line is added or deleted.
            if (addCells.Length > 0)
            {
                // Cell with an detail invoice Line
                foreach (ICell cell in addCells)
                {
                    var invoiceLine = (InvoiceLine)this.program.Services.Database.Create <InvoiceLine>(typeof(InvoiceLine), 1 + cell.Row.Index - this.InvoiceLinesRange.Row);
                    this.Invoice.AddInvoiceLine(invoiceLine);

                    var columnIndex = cell.Column.Index - 1;
                    this.Controls.Label <InvoiceLine>(cell.Row.Index, columnIndex++, invoiceLine, "Index");
                    this.Controls.TextBox <InvoiceLine>(cell.Row.Index, columnIndex++, invoiceLine, "Description");
                    this.Controls.TextBox <InvoiceLine>(cell.Row.Index, columnIndex++, invoiceLine, "Quantity");
                    this.Controls.TextBox <InvoiceLine>(cell.Row.Index, columnIndex++, invoiceLine, "UnitPrice");
                    this.Controls.Label <InvoiceLine>(cell.Row.Index, columnIndex++, invoiceLine, "TaxRate");

                    invoiceLine.Description = cell.ValueAsString;
                }

                this.Controls.Bind();
            }

            await this.Sheet.Flush().ConfigureAwait(false);
        }
Пример #2
0
        private async void Sheet_CellsChanged(object sender, CellChangedEvent e)
        {
            // First columns will trigger an insert new Organisation
            var addCells = e.Cells
                           .Where(c => c.Column.Index == 0 &&
                                  c.Value != null &&
                                  !this.Controls.ControlByCell.ContainsKey(c)).ToArray();

            if (addCells.Length > 0)
            {
                var options = new Range(0, 0, null, null, null, KnownNames.ValidationRangePaymentTerms);

                // Cell with an detail invoice Line
                foreach (ICell cell in addCells)
                {
                    var organisation = (Organisation)this.program.Services.Database.Create <Organisation>(typeof(Organisation));
                    organisation.Name = cell.ValueAsString;

                    this.Organisations.Add(organisation);

                    var colIndex = 0;
                    var icell    = this.Controls.TextBox(cell.Row.Index, colIndex++, organisation, "Name");
                    icell.Style = Constants.ChangedStyle;

                    this.Controls.TextBox(cell.Row.Index, colIndex++, organisation, "Street");
                    this.Controls.TextBox(cell.Row.Index, colIndex++, organisation, "City");
                    this.Controls.TextBox(cell.Row.Index, colIndex++, organisation, "Country");
                    this.Controls.TextBox(cell.Row.Index, colIndex++, organisation, "VatNumber");
                    this.Controls.TextBox(cell.Row.Index, colIndex++, organisation, "Email");
                    this.Controls.TextBox(cell.Row.Index, colIndex++, organisation, "Phone");
                    this.Controls.TextBox(cell.Row.Index, colIndex++, organisation, "FinancialContact");

                    this.Controls.Select <Organisation>(cell.Row.Index, colIndex++, options, organisation, nameof(organisation.DefaultPaymentTerm), nameof(PaymentTerm.Name),
                                                        toDomain: (object key) =>
                    {
                        return(this.program.Services.Database.FirstOrDefault <PaymentTerm>(o => string.Equals(o.Name, key)));
                    });
                }

                this.Controls.Bind();

                await this.Sheet.Flush().ConfigureAwait(false);
            }
        }
Пример #3
0
        private async void Worksheet_CellsChanged(object sender, CellChangedEvent e)
        {
            var changesReverted = false;

            foreach (var cell in e.Cells)
            {
                if (this.ControlByCell.TryGetValue(cell, out var control))
                {
                    control.OnCellChanged();

                    if (IsGenericStaticContent(control))
                    {
                        changesReverted = true;
                    }
                }
            }

            if (changesReverted)
            {
                // a single message to the user should be done here:
            }

            await this.Worksheet.Flush().ConfigureAwait(false);
        }