public override SpssVariable Clone() { SpssDateVariable other = new SpssDateVariable(); CloneTo(other); return(other); }
internal static SpssVariable LoadVariable(SpssVariablesCollection parent, string varName, int varType) { FormatTypeCode writeFormat, printFormat; int writeDecimal, writeWidth, printDecimal, printWidth; SpssException.ThrowOnFailure(SpssSafeWrapper.spssGetVarWriteFormat(parent.Document.Handle, varName, out writeFormat, out writeDecimal, out writeWidth), "spssGetVarWriteFormat"); SpssException.ThrowOnFailure(SpssSafeWrapper.spssGetVarPrintFormat(parent.Document.Handle, varName, out printFormat, out printDecimal, out printWidth), "spssGetVarPrintFormat"); SpssVariable variable; switch (varType) { case 0: // This may be a date or a numeric if (SpssDateVariable.IsDateVariable(writeFormat)) variable = new SpssDateVariable(parent, varName, writeFormat, writeWidth, printFormat, printWidth); else variable = new SpssNumericVariable(parent, varName, writeFormat, writeDecimal, writeWidth, printFormat, printDecimal, printWidth); break; default: Debug.Assert(varType == printWidth); variable = new SpssStringVariable(parent, varName, varType); break; } return variable; }
internal static SpssVariable LoadVariable(SpssVariablesCollection parent, string varName, int varType) { FormatTypeCode writeFormat, printFormat; int writeDecimal, writeWidth, printDecimal, printWidth; SpssException.ThrowOnFailure(SpssSafeWrapper.spssGetVarWriteFormat(parent.Document.Handle, varName, out writeFormat, out writeDecimal, out writeWidth), "spssGetVarWriteFormat"); SpssException.ThrowOnFailure(SpssSafeWrapper.spssGetVarPrintFormat(parent.Document.Handle, varName, out printFormat, out printDecimal, out printWidth), "spssGetVarPrintFormat"); SpssVariable variable; switch (varType) { case 0: // This may be a date or a numeric if (SpssDateVariable.IsDateVariable(writeFormat)) { variable = new SpssDateVariable(parent, varName, writeFormat, writeWidth, printFormat, printWidth); } else { variable = new SpssNumericVariable(parent, varName, writeFormat, writeDecimal, writeWidth, printFormat, printDecimal, printWidth); } break; default: Debug.Assert(varType == printWidth); variable = new SpssStringVariable(parent, varName, varType); break; } return(variable); }
/// <summary> /// Defines the variables in the SPSS data file so that they mirror /// those defined in a <see cref="DataTable"/>. /// </summary> /// <param name="table"> /// The DataTable whose list of columns are the ones we want to copy. /// </param> /// <param name="fillInMetadataCallback"> /// The callback method to use to retrieve the additional metadata /// to put into the SPSS data document, that is not included in a DataTable. /// Optional. /// </param> public void ImportSchema(DataTable table, Action <SpssVariable> fillInMetadataCallback) { foreach (DataColumn column in table.Columns) { try { SpssVariable var; if (column.DataType == typeof(string)) { var = new SpssStringVariable(); ((SpssStringVariable)var).Length = (column.MaxLength <0 || column.MaxLength> SpssSafeWrapper.SPSS_MAX_LONGSTRING) ? SpssSafeWrapper.SPSS_MAX_LONGSTRING : column.MaxLength; } else if (column.DataType == typeof(DateTime)) { var = new SpssDateVariable(); } else { var = new SpssNumericVariable(); if (column.DataType == typeof(float) || column.DataType == typeof(double)) { ((SpssNumericVariable)var).PrintDecimal = 2; ((SpssNumericVariable)var).WriteDecimal = 2; } } var.Name = this.GenerateColumnName(column.ColumnName); this.Add(var); // Provide opportunity for callback function to fill in variable-specific metadata if (fillInMetadataCallback != null) { try { fillInMetadataCallback(var); } catch (Exception ex) { throw new ApplicationException("Exception in metadata filler callback function on column " + column.ColumnName + ".", ex); } } } catch (Exception ex) { throw new ApplicationException("Error adding column " + column.ColumnName + " schema information to the SPSS .SAV data file.", ex); } } }
protected override bool IsApplicableFormatTypeCode(FormatTypeCode formatType) { return(formatType != FormatTypeCode.SPSS_FMT_A && !SpssDateVariable.IsDateVariable(formatType)); }
public override SpssVariable Clone() { SpssDateVariable other = new SpssDateVariable(); CloneTo(other); return other; }