Example #1
0
        protected virtual void InitializeEntries()
        {
            if (editedType == null)
            {
                editedType = new PaymentType();
            }
            else
            {
                txtName.Text = editedType.Name;
            }

            cboType.Load(PaymentType.GetAllBaseTypePairs(), "Key", "Value", (int)editedType.BaseType);
        }
        private void InitializeGrid()
        {
            try {
                if (initialized)
                {
                    return;
                }

                ColumnController cc = new ColumnController();
                supportsSumming = false;

                for (int i = 0; i < dataQueryResult.Result.Columns.Count; i++)
                {
                    DbField  field            = dataQueryResult.Columns [i].Field;
                    DataType fieldType        = ReportProvider.GetDataFieldType(field);
                    string   columnName       = dataQueryResult.Result.Columns [i];
                    string   columnHeaderText = ReportProvider.GetReportFieldColumnName(dataQueryResult, i);

                    CellText cell;
                    bool     thisColumnSummable = false;
                    switch (fieldType)
                    {
                    case DataType.Date:
                        cell = new CellTextDate(columnName);
                        break;

                    case DataType.DateTime:
                        cell = new CellTextDateTime(columnName);
                        break;

                    case DataType.Quantity:
                        cell = new CellTextQuantity(columnName);
                        thisColumnSummable = true;
                        break;

                    case DataType.CurrencyIn:
                        cell = new CellTextCurrency(columnName, PriceType.Purchase);
                        thisColumnSummable = true;
                        break;

                    case DataType.CurrencyOut:
                        cell = new CellTextCurrency(columnName);
                        thisColumnSummable = true;
                        break;

                    case DataType.Currency:
                        cell = new CellTextCurrency(columnName, PriceType.Unknown);
                        thisColumnSummable = true;
                        break;

                    case DataType.Percent:
                        cell = new CellTextDouble(columnName)
                        {
                            FixedFaction = BusinessDomain.AppConfiguration.PercentPrecision
                        };
                        break;

                    case DataType.Id:
                    case DataType.UserId:
                        cell = new CellTextNumber(columnName);
                        break;

                    case DataType.DocumentNumber:
                        cell = new CellTextNumber(columnName)
                        {
                            FixedDigits = BusinessDomain.AppConfiguration.DocumentNumberLength
                        };
                        break;

                    case DataType.OperationType:
                        cell = new CellTextLookup <int> (columnName);
                        CellTextLookup <int> cellOperationType = (CellTextLookup <int>)cell;
                        foreach (OperationType operationType in Enum.GetValues(typeof(OperationType)))
                        {
                            if (operationType > 0)
                            {
                                cellOperationType.Lookup.Add((int)operationType, Translator.GetOperationTypeName(operationType));
                            }
                        }
                        break;

                    case DataType.DocumentType:
                        cell = new CellTextLookup <int> (columnName).Load(DocumentBase.GetAllDocumentTypes());
                        break;

                    case DataType.BasePaymentType:
                        cell = new CellTextLookup <int> (columnName).Load(PaymentType.GetAllBaseTypePairs());
                        break;

                    case DataType.PaymentType:
                        cell = new CellTextLookup <long> (columnName);
                        CellTextLookup <long> cellPaymentType = (CellTextLookup <long>)cell;
                        foreach (PaymentType paymentType in PaymentType.GetAll())
                        {
                            cellPaymentType.Lookup.Add(paymentType.Id, paymentType.Name);
                        }
                        break;

                    case DataType.PriceGroupType:
                        cell = new CellTextLookup <int> (columnName).Load(Currency.GetAllPriceGroups());
                        break;

                    case DataType.PartnerType:
                        cell = new CellTextLookup <int> (columnName).Load(Partner.GetAllTypes());
                        break;

                    case DataType.ItemType:
                        cell = new CellTextLookup <int> (columnName).Load(Item.GetAllTypes());
                        break;

                    case DataType.UserAccessLevel:
                        cell = new CellTextLookup <int> (columnName).Load(User.GetAllAccessLevels());
                        break;

                    case DataType.TurnoverType:
                        cell = new CellTextLookup <int> (columnName).Load(CashBookEntry.GetAllTurnoverTypes());
                        break;

                    case DataType.TurnoverDirection:
                        cell = new CellTextLookup <int> (columnName).Load(CashBookEntry.GetAllTurnoverDirections());
                        break;

                    case DataType.TaxGroupCode:
                        cell = new CellTextLookup <string> (columnName).Load(VATGroup.AllCodes);
                        break;

                    case DataType.Sign:
                        cell = new CellTextLookup <int> (columnName).Load(Payment.GetAllSignTypes());
                        break;

                    case DataType.PaymentMode:
                        cell = new CellTextLookup <int> (columnName).Load(Payment.GetAllModeTypes());
                        break;

                    case DataType.Text:
                        cell = new CellText(columnName);
                        break;

                    default:
                        continue;
                    }
                    Column col = new Column(columnHeaderText, cell, 0.1, columnName)
                    {
                        MinWidth = 100,
                        Visible  = !skip.Contains(field) && CheckColumnVisible(dataQueryResult, i)
                    };
                    cc.Add(col);
                    supportsSumming |= thisColumnSummable && col.Visible;
                }

                grid.ColumnController = cc;
                // Prevent the grid from reapplying the old sort
                grid.Model               = null;
                grid.Model               = model;
                grid.AllowSelect         = true;
                grid.AllowMultipleSelect = true;
                grid.CellsFucusable      = true;
                grid.RulesHint           = true;
                grid.SortColumnsHint     = true;
                grid.RowActivated       -= grid_RowActivated;
                grid.RowActivated       += grid_RowActivated;
                initialized              = true;
            } finally {
                EventHandler onInitialized = Initialized;
                if (onInitialized != null)
                {
                    onInitialized(this, EventArgs.Empty);
                }
            }
        }