/// <summary> /// Return the GasConcentrations of the cylinder's part number. /// </summary> /// <param name="factoryCylinder"></param> /// <param name="trx"></param> /// <returns>Returned list is empty if part number can't be found.</returns> internal IList <GasConcentration> FindByFactoryCylinder(FactoryCylinder factoryCylinder, DataAccessTransaction trx) { List <GasConcentration> list = new List <GasConcentration>(); using (IDbCommand cmd = GetCommand("SELECT * FROM FACTORYCYLINDERGAS WHERE PARTNUMBER = @PARTNUMBER", trx)) { cmd.Parameters.Add(GetDataParameter("@PARTNUMBER", factoryCylinder.PartNumber)); using (IDataReader reader = cmd.ExecuteReader()) { DataAccessOrdinals ordinals = new DataAccessOrdinals(reader); while (reader.Read()) { string gasCode = SqlSafeGetString(reader, ordinals["GASCODE"]); double concentration = SqlSafeGetDouble(reader, ordinals["CONCENTRATION"], 0.0f); GasConcentration gasConcentration = new GasConcentration(gasCode, concentration); list.Add(gasConcentration); } } } return(list); }
private bool Insert(FactoryCylinder factoryCylinder, DataAccessTransaction trx) { using (IDbCommand cmd = GetCommand("INSERT INTO FACTORYCYLINDER ( PARTNUMBER, RECUPDATETIMEUTC, MANUFACTURERCODE ) VALUES ( @PARTNUMBER, @RECUPDATETIMEUTC, @MANUFACTURERCODE )", trx)) { cmd.Parameters.Add(GetDataParameter("@PARTNUMBER", factoryCylinder.PartNumber)); cmd.Parameters.Add(GetDataParameter("@RECUPDATETIMEUTC", trx.TimestampUtc)); cmd.Parameters.Add(GetDataParameter("@MANUFACTURERCODE", factoryCylinder.ManufacturerCode)); try { cmd.ExecuteNonQuery(); } catch (SQLiteException e) { if (e.ErrorCode == SQLiteErrorCode.Constraint) { return(false); // assume we have a 'duplicate' error. } throw; // any other error is unexpected, so just rethrow it } // insert the child gases new FactoryCylinderGasDataAccess().InsertForFactoryCylinder(factoryCylinder, trx); } return(true); }
/// <summary> /// Return the GasConcentrations of the cylinder's part number. /// </summary> /// <param name="factoryCylinder"></param> /// <returns></returns> internal IList <GasConcentration> FindByFactoryCylinder(FactoryCylinder factoryCylinder) { using (DataAccessTransaction trx = new DataAccessTransaction(true)) { return(FindByFactoryCylinder(factoryCylinder, trx)); } }
public void Save(FactoryCylinder factoryCylinder, DataAccessTransaction trx) { try { // We first always try and insert, under the assumption that most cylinder // changes are new cylinders, not modified cylinders. if (Insert(factoryCylinder, trx)) { return; } // The above Insert call will return false if the cylinder is found to already // be in the database. In that situation, just delete the cylinder in the database, // then add it as all new. Delete(factoryCylinder, trx); Insert(factoryCylinder, trx); } catch (DataAccessException) { throw; } catch (Exception e) { throw new DataAccessException(factoryCylinder.PartNumber, e); } }
/// <summary> /// /// </summary> /// <param name="factoryCylinder"></param> /// <param name="trx"></param> /// <returns>Number of rows deleted</returns> public int Delete(FactoryCylinder factoryCylinder, DataAccessTransaction trx) { using (IDbCommand cmd = GetCommand("DELETE FROM FACTORYCYLINDER WHERE PARTNUMBER = @PARTNUMBER", trx)) { cmd.Parameters.Add(GetDataParameter("@PARTNUMBER", factoryCylinder.PartNumber)); return(cmd.ExecuteNonQuery()); } }
/// <summary> /// Find all the FactoryCylinderGases for the specified FactoryCylinder /// </summary> /// <param name="factoryCylinder"></param> /// <param name="factoryCylinderGasDataAccess"></param> /// <param name="trx"></param> private void LoadFactoryCylinderGases(FactoryCylinder factoryCylinder, FactoryCylinderGasDataAccess factoryCylinderGasDataAccess, DataAccessTransaction trx) { factoryCylinder.GasConcentrations.Clear(); foreach (GasConcentration gasConcentration in factoryCylinderGasDataAccess.FindByFactoryCylinder(factoryCylinder, trx)) { factoryCylinder.GasConcentrations.Add(gasConcentration); } }
internal void InsertForFactoryCylinder(FactoryCylinder factoryCylinder, DataAccessTransaction trx) { using (IDbCommand cmd = GetCommand("INSERT INTO FACTORYCYLINDERGAS ( PARTNUMBER, GASCODE, CONCENTRATION ) VALUES ( @PARTNUMBER, @GASCODE, @CONCENTRATION )", trx)) { foreach (GasConcentration gasConcentration in factoryCylinder.GasConcentrations) { cmd.Parameters.Clear(); cmd.Parameters.Add(GetDataParameter("@PARTNUMBER", factoryCylinder.PartNumber)); cmd.Parameters.Add(GetDataParameter("@GASCODE", gasConcentration.Type.Code)); cmd.Parameters.Add(GetDataParameter("@CONCENTRATION", gasConcentration.Concentration)); int inserted = cmd.ExecuteNonQuery(); } } }
private GasEndPoint MakeInstalledCylinder(IDataReader reader, DataAccessOrdinals ordinals, DataAccessTransaction trx) { short position = SqlSafeGetShort(reader, ordinals["POSITION"]); string partNumber = SqlSafeGetString(reader, ordinals["PARTNUMBER"]); // Try and get the Factory Cylinder information for the part number. // Note that there may not be any factory cylinder info available if the // part number is for a new cylinder type that's unknown to to iNet. FactoryCylinder factoryCylinder = null; if (partNumber != string.Empty) { factoryCylinder = new FactoryCylinderDataAccess().FindByPartNumber(partNumber, trx); } Cylinder cylinder; if (factoryCylinder != null) { cylinder = new Cylinder(factoryCylinder); } else { cylinder = new Cylinder(); cylinder.PartNumber = partNumber; } string installationTypeString = SqlSafeGetString(reader, ordinals["INSTALLATIONTYPE"]); GasEndPoint.Type installationType = (GasEndPoint.Type)Enum.Parse(typeof(GasEndPoint.Type), installationTypeString, true); GasEndPoint gep = new GasEndPoint(cylinder, position, installationType); gep.Cylinder.FactoryId = SqlSafeGetString(reader, ordinals["FACTORYID"]); gep.Cylinder.ExpirationDate = SqlSafeGetDate(reader, ordinals["EXPIRATIONDATE"]); gep.Cylinder.RefillDate = SqlSafeGetDate(reader, ordinals["REFILLDATE"]); string pressure = SqlSafeGetString(reader, ordinals["PRESSURE"]); gep.Cylinder.Pressure = (PressureLevel)Enum.Parse(typeof(PressureLevel), pressure, true); return(gep); }
/// <summary> /// Finds and returns a specific FactoryCylinder by its part number. /// </summary> /// <param name="partNumber"></param> /// <param name="trx"></param> /// <returns>null if no match can be found.</returns> public FactoryCylinder FindByPartNumber(string partNumber, DataAccessTransaction trx) { FactoryCylinder cylinder = null; using (IDbCommand cmd = GetCommand("SELECT * FROM FACTORYCYLINDER WHERE PARTNUMBER = @PARTNUMBER", trx)) { cmd.Parameters.Add(GetDataParameter("@PARTNUMBER", partNumber)); using (IDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { cylinder = CreateFromReader(reader); } } } if (cylinder != null) { LoadFactoryCylinderGases(cylinder, new FactoryCylinderGasDataAccess(), trx); } return(cylinder); }