/* * Assign values and internal properties from one object to another. */ public void assign(BizDataBaseObjectList dbObjectArray, bool assignObjVersion) { if (objects == null) objects = new ArrayList(); if (objects != null) { objects.Clear(); if (dbObjectArray != null) { for (int i = 0; i < dbObjectArray.count(); i++) { BizDataBaseObject fromObject = (BizDataBaseObject)dbObjectArray.getObjectAt(i); // Priority for dest array template BizDataBaseObject toObject = null; if (parent != null) { toObject = parent.getTemplateObject().newInstance(); } else { toObject = fromObject.newInstance(); } toObject.assign(fromObject, assignObjVersion); this.add(toObject); } } } }
// // Handler specific methods // public void Save(BizDataBaseObjectList dbObjects) { if (dbObjects == null) return; Object OWNER_Save = new StringBuilder("OWNER_Save"); SessionStart(OWNER_Save); try { // Removed Item for (int i = 0; i < dbObjects.count(); i++) { BizDataBaseObject dbObject = dbObjects.getObjectAt(i); if (dbObject != null && dbObject.getState() == BizDataBaseObject.REMOVED) { SaveDetailArray(dbObject); Remove(dbObjects.getObjectAt(i)); } } // Updated Item for (int i = 0; i < dbObjects.count(); i++) { BizDataBaseObject dbObject = dbObjects.getObjectAt(i); if (dbObject != null && dbObject.getState() == BizDataBaseObject.MODIFIED) { Update(dbObject); SaveDetailArray(dbObject); } } // New Item for (int i = 0; i < dbObjects.count(); i++) { BizDataBaseObject dbObject = dbObjects.getObjectAt(i); if (dbObject != null && dbObject.getState() == BizDataBaseObject.NEW) { dbObject.CREATED_BY.setValue(currentUser); Insert(dbObject); SaveDetailArray(dbObject); dbObject.internalSetState(BizDataBaseObject.QUERY); } } SessionClose(OWNER_Save); } catch (BizDataAccessException e) { SessionRollback(OWNER_Save); throw e; } catch (Exception e) { SessionRollback(OWNER_Save); // ------------------------------------------------- throw new BizDataAccessException("Error Saving!", "Error Saving Database objects :\n" + e.Message); } }
public BizDataBaseObjectList Query(BizDataBaseObject tempateDbObject, bool limitedOutput) { Object OWNER_Query = new StringBuilder("OWNER_Query"); SessionStart(OWNER_Query); // // Start Query // DataView objDataView = null; string stmt = ""; try { // // limit output // bool doLimitOutput = false; if (limitedOutput) { Int64 rowCount = GetCount(tempateDbObject, tempateDbObject.CURRENT_WHERE); if (debugEvents) Console.WriteLine("BizDataAccess: No of Items (" + tempateDbObject.view + ") = " + rowCount.ToString()); if (MAX_LIMIT_FOR_NEXT_QUERY > 0) { //AddUserInfo("Display Top " + MAX_LIMIT_FOR_NEXT_QUERY.ToString() + " " + tempateDbObject.displayName + "!"); doLimitOutput = true; } else if (rowCount > MAX_LIMIT) { AddEndUserInfo("Display Top " + MAX_LIMIT.ToString() + " " + tempateDbObject.displayName + "(s)!"); doLimitOutput = true; } } //Columns string columnsStr = ""; ArrayList attributes = tempateDbObject.attributes; bool isFirst = true; for (int i = 0; i < attributes.Count; i++) { BizDataBaseColumn column = (BizDataBaseColumn)attributes[i]; if (column.isNonPersistant) continue; if (!isFirst) columnsStr = columnsStr + ","; if (column.function != null && column.function.Length > 0) columnsStr = columnsStr + column.function + " AS [" + column.name + "]"; else columnsStr = columnsStr + "[" + column.name + "]"; isFirst = false; } string strLimitOutput = ""; if (doLimitOutput) { if (MAX_LIMIT_FOR_NEXT_QUERY > 0) strLimitOutput = "TOP " + MAX_LIMIT_FOR_NEXT_QUERY.ToString(); else strLimitOutput = "TOP " + MAX_LIMIT.ToString(); } if (columnsStr != null && columnsStr.Length > 0) { stmt = "SELECT " + strLimitOutput + " " + columnsStr + " FROM " + tempateDbObject.view; } else { throw new Exception("No columns selected!"); } // Where string where = tempateDbObject.CURRENT_WHERE; tempateDbObject.CURRENT_WHERE = null; // Reset if (where != null && where.Length > 0) stmt = stmt + " WHERE " + where; if (where != null && where.Length > 0 && tempateDbObject.defaultWhere != null && tempateDbObject.defaultWhere.Length > 0) stmt = stmt + " AND " + tempateDbObject.defaultWhere; else if (tempateDbObject.defaultWhere != null && tempateDbObject.defaultWhere.Length > 0) stmt = stmt + " WHERE " + tempateDbObject.defaultWhere; string groupBy = tempateDbObject.CURRENT_GROUP_BY; tempateDbObject.CURRENT_GROUP_BY = null; // Reset if (groupBy != null && groupBy.Length > 0) stmt = stmt + " GROUP BY " + groupBy; string orderBy = tempateDbObject.CURRENT_ORDER_BY; tempateDbObject.CURRENT_ORDER_BY = null; // Reset if (orderBy != null && orderBy.Length > 0) stmt = stmt + " ORDER BY " + orderBy; SqlCommand cmd = new SqlCommand(stmt, SESSION.SqlConn, SESSION.SqlTrans); SqlDataAdapter objDataAdapter = new SqlDataAdapter(); objDataAdapter.SelectCommand = cmd; DataSet objDataSet; objDataSet = new DataSet(tempateDbObject.view); objDataAdapter.Fill(objDataSet); objDataView = new DataView(objDataSet.Tables[0]); SessionClose(OWNER_Query, false); } catch (BizDataAccessException e) { SessionClose(OWNER_Query, false); throw e; } catch (Exception e) { SessionClose(OWNER_Query, false); throw new BizDataAccessException("Error - Object [ " + tempateDbObject.displayName + "]", e.Message, e); } finally { MAX_LIMIT_FOR_NEXT_QUERY = -1; } // try { // Result record (Master) string debugResultRecords = ""; BizDataBaseObjectList dbObjects = new BizDataBaseObjectList(); for (int i = 0; i < objDataView.Count; i++) { BizDataBaseObject dbObject = tempateDbObject.newInstance(); DataRowView row = objDataView[i]; for (int j = 0; j < row.Row.Table.Columns.Count; j++) { System.Data.DataColumn dataColumn = row.Row.Table.Columns[j]; BizDataBaseColumn column = dbObject.findColumn(dataColumn.ColumnName); if (column != null) { if (column.type == BizDataBaseColumn.CLOB) { Encoding u16LE = Encoding.Unicode; if (row[j] != null && row[j].GetType() != typeof(System.DBNull)) column.setValue(u16LE.GetString((byte[])row[j], 0, ((byte[])row[j]).Length)); else column.setValue(null); } else column.setValue(row[j]); } } dbObject.setState(BizDataBaseObject.QUERY); dbObjects.add(dbObject); } // Fetch Detail Records for (int i = 0; i < dbObjects.count(); i++) { BizDataBaseObject dbObject = dbObjects.getObjectAt(i); QueryDetailArray(tempateDbObject, dbObject, limitedOutput); dbObject.setState(BizDataBaseObject.QUERY); } return dbObjects; } catch (Exception ee) { throw new BizDataAccessException("Error - Object [ " + tempateDbObject.displayName + " ]", ee.Message, ee); } }
// // Used by XML serialization (Internal Only) // public void copy(BizDataBaseObjectList dbObjectArray) { if (objects == null) objects = new ArrayList(); if (objects != null) { objects.Clear(); if (dbObjectArray != null) { for (int i = 0; i < dbObjectArray.count(); i++) { BizDataBaseObject fromObject = (BizDataBaseObject)dbObjectArray.getObjectAt(i); BizDataBaseObject toObject = new BizDataBaseObject(); toObject.copy(fromObject); this.add(toObject); } } } }