Ejemplo n.º 1
0
        protected internal object GetValueForExcelExport(ExcelColumn col, BaseRecord rec)
        {
            object  val        = "";
            bool    isNull     = false;
            decimal deciNumber = default(decimal);

            if (col == null)
            {
                return(null);
            }
            //DFKA value is evaluated in the <tablename>ExportExcelButton_Click method in the <tablename>.controls file
            //if (col.DisplayColumn.TableDefinition.IsExpandableNonCompositeForeignKey(col.DisplayColumn))
            //{
            //    //  Foreign Key column, so we will use DFKA and String type.
            //    val = rec.Format(col.DisplayColumn);
            //}
            //else
            //{
            switch (col.DisplayColumn.ColumnType)
            {
            case BaseColumn.ColumnTypes.Number:
            case BaseColumn.ColumnTypes.Percentage:
            case BaseColumn.ColumnTypes.Currency:
                ColumnValue numVal = rec.GetValue(col.DisplayColumn);

                //If the value of the column to be exported is nothing, add an empty cell to the Excel file
                if (numVal.IsNull)
                {
                    isNull = true;
                }
                else
                {
                    deciNumber = numVal.ToDecimal();
                    val        = deciNumber;
                }

                break;

            case BaseColumn.ColumnTypes.Date:
                ColumnValue dateVal = rec.GetValue(col.DisplayColumn);
                if (dateVal.IsNull)
                {
                    isNull = true;
                }
                else
                {
                    // Specify the default Excel format for the date field
                    // val = rec.Format(col.DisplayColumn, "s");
                    // val += ".000";
                    val = rec.GetValue(col.DisplayColumn).Value;
                }

                break;

            case BaseColumn.ColumnTypes.Very_Large_String:
                val = rec.GetValue(col.DisplayColumn).ToString();


                break;

            case BaseColumn.ColumnTypes.Boolean:
                val = rec.Format(col.DisplayColumn);

                break;

            default:

                val = rec.Format(col.DisplayColumn);

                break;
            }
            //}
            if (isNull)
            {
                return(null);
            }
            else
            {
                return(val);
            }
        }