public override bool isCompatibleDef(SQLTypeDef def) { if (this.getTypeID() != def.getTypeID()) { return(false); } int thisPrecision = this.getParam("precision"); int thisScale = this.getParam("scale"); int defPrecision = def.getParam("precision"); int defScale = def.getParam("scale"); thisPrecision -= thisScale; defPrecision -= defScale; if (thisPrecision < defPrecision) { return(false); } if (thisScale < defScale) { return(false); } return(true); }
/* Returns a new SQLTypeDef instance recommended for the array of cell * data passed. */ public static SQLTypeDef getColumnTypeDef(string[] cellData) { int numCells = cellData.Length; SQLTypeDef[] cellTypes = new SQLTypeDef[numCells]; SQLTypeDef columnType = getNew((SQLTypeDef.SQLTypeID) 0); for (int i = 0; i < numCells; ++i) { cellTypes[i] = getNew(cellData[i]); if (cellTypes[i] != null) { int columnTypeID = (int)columnType.getTypeID(); int cellTypeID = (int)cellTypes[i].getTypeID(); if (columnTypeID < cellTypeID) { columnType = getCopy(cellTypes[i]); } else if (columnTypeID == cellTypeID) { columnType.setCompatibleParams(cellTypes[i]); } } } return(columnType); }
// Run when the edit current attribute button is pressed private void btnEditAttribute_Click(object sender, EventArgs e) { grpSQLOutput.Enabled = false; cboxCurrentAttribute.Enabled = false; btnEditAttribute.Enabled = false; grpAttributeOptions.Enabled = true; int columnIndex = cboxCurrentAttribute.SelectedIndex; txtAttributeName.Text = columns[columnIndex].getName(); cboxAttributeType.Items.Clear(); foreach (SQLTypeDef.SQLTypeID typeID in (SQLTypeDef.SQLTypeID[])Enum.GetValues(typeof(SQLTypeDef.SQLTypeID))) { cboxAttributeType.Items.Add(SQLTypeDef.getSQLTypeName(typeID)); } cboxAttributeType.SelectedIndex = (int)columns[columnIndex].getTypeID(); if (columns[columnIndex].getTypeDef().getParams().Length == 0) { btnAdvancedAttribute.Enabled = false; } else { btnAdvancedAttribute.Enabled = true; } currentEditDef = columns[columnIndex].getTypeDef(); }
// Constructor public Column(string name, string[] data, SQLTypeDef typeDef) { this.name = name; this.data = new string[data.Length]; Array.Copy(data, this.data, data.Length); this.typeDef = getCopy(typeDef); this.setFlags(); }
public override bool isCompatibleDef(SQLTypeDef def) { if (this.getTypeID() == def.getTypeID()) { return(true); } else { return(false); } }
public override bool setCompatibleParams(SQLTypeDef def) { if (this.getTypeID() != def.getTypeID()) { return(false); } if (def.getParam("length") > this.getParam("length")) { this.setParam("length", def.getParam("length")); } return(true); }
// Run when the attribute type is changed private void cboxAttributeType_SelectedIndexChanged(object sender, EventArgs e) { int columnIndex = cboxCurrentAttribute.SelectedIndex; currentEditDef = SQLTypeDefFactory.getNew((SQLTypeDef.SQLTypeID)cboxAttributeType.SelectedIndex); if (currentEditDef.getParams().Length == 0) { btnAdvancedAttribute.Enabled = false; } else { btnAdvancedAttribute.Enabled = true; } }
// Run when the advanced button is pressed private void btnAdvancedAttribute_Click(object sender, EventArgs e) { int columnIndex = cboxCurrentAttribute.SelectedIndex; SQLTypeDef def = SQLTypeDefFactory.getCopy(currentEditDef); AdvancedAttributeForm popupForm = new AdvancedAttributeForm(def); if (popupForm.ShowDialog(this) == DialogResult.OK) { currentEditDef = def; MessageBox.Show("Successfully saved attribute parameter changes!", "Success"); } else { MessageBox.Show("Attribute parameter changes have been cancelled!", "Cancelled"); } }
public static void run() { string[] decStrs = new string[3]; decStrs[0] = "31.234"; decStrs[1] = "315.267"; decStrs[2] = "1234.5678"; SQLTypeDef[] decs = new SQLTypeDef[3]; for (int i = 0; i < decs.Length; i++) { decs[i] = getSQLDecimal(decStrs[i]); if (decs[i] == null) { Console.WriteLine("null at " + i.ToString()); } else { Console.WriteLine(decs[i].getSQLDefString() + " at " + i.ToString()); } } }
/* Returns a SQLTypeDef fitting for the passed cell data example. */ public static SQLTypeDef getNew(string dataStr) { SQLTypeDef def = getSQLBoolean(dataStr); if (def != null) { return(def); } def = getSQLInteger(dataStr); if (def != null) { return(def); } def = getSQLDecimal(dataStr); if (def != null) { return(def); } def = getSQLVarchar(dataStr); return(def); }
/* Returns a copy of the passed SQLTypeDef subclass/implementation instance. */ public static SQLTypeDef getCopy(SQLTypeDef obj) { SQLTypeID typeID = obj.getTypeID(); switch (typeID) { case SQLTypeID.BOOLEAN: return(new SQLBoolean()); case SQLTypeID.INTEGER: return(new SQLInteger()); case SQLTypeID.DECIMAL: return(new SQLDecimal((SQLDecimal)obj)); case SQLTypeID.VARCHAR: return(new SQLVarchar((SQLVarchar)obj)); default: return(null); } }
/* Returns a list of columns by taking the passed 2D cell data * string array and separating the column names and data. */ public static List <Column> getColumnsFromCells(string[,] cellData) { int numRows = cellData.GetLength(0); int numColumns = cellData.GetLength(1); List <Column> columns = new List <Column>(numColumns); for (int i = 0; i < numColumns; ++i) { string colName = cellData[0, i]; string[] tmpCells = new string[numRows - 1]; for (int j = 1; j < numRows; ++j) { tmpCells[j - 1] = cellData[j, i]; } SQLTypeDef tempDef = getColumnTypeDef(tmpCells); columns.Add(new Column(colName, tmpCells, tempDef)); } return(columns); }
public override bool setCompatibleParams(SQLTypeDef def) { if (this.getTypeID() != def.getTypeID()) { return(false); } int thisPrecision = this.getParam("precision"); int thisScale = this.getParam("scale"); int defPrecision = def.getParam("precision"); int defScale = def.getParam("scale"); thisPrecision -= thisScale; defPrecision -= defScale; int maxPrecision = (thisPrecision > defPrecision) ? thisPrecision : defPrecision; int maxScale = (thisScale > defScale) ? thisScale : defScale; this.setParam("precision", maxPrecision + maxScale); this.setParam("scale", maxScale); return(true); }
/* Changes the parameters of the caller to the most lenient value out of * the caller's and the passed object's parameters if this is possible * (i.e. they still must be the same type). If they are incompatible types, * returns false. */ public abstract bool setCompatibleParams(SQLTypeDef def);
/* Returns true if the given SQLTypeDef child instance is of the same * type as the caller and it can be defined given the caller's * parameters. That is, the caller's parameters must be at least as * lenient as the passed object's parameters. Otherwise, returns false. */ public abstract bool isCompatibleDef(SQLTypeDef def);
public override bool setCompatibleParams(SQLTypeDef def) { return(this.isCompatibleDef(def)); }
/* Sets the SQLTypeDef of the column to the passed one. */ public void setTypeDef(SQLTypeDef def) { this.typeDef = getCopy(def); }
private SQLTypeDef tdCng; // Temporary copy of edited SQLTypeDef to validate changes // Constructor public AdvancedAttributeForm(SQLTypeDef typeDef) { InitializeComponent(); tdRef = typeDef; tdCng = SQLTypeDefFactory.getCopy(typeDef); }