public static bool AddEntAppConfig(DbConnection dbConn, uas_EntAppConfig eac) { DbDataReader reader = null; try { int maxEntAppConfigId = -1; using (DbCommand command = dbConn.CreateCommand()) { command.CommandText = "SELECT MAX(EntAppConfigId) FROM [dbo].[uas_EntAppConfig] "; command.CommandType = CommandType.Text; reader = command.ExecuteReader(); reader.Read(); if (!reader.IsDBNull(0)) { maxEntAppConfigId = reader.GetInt32(0); } reader.Close(); } if (maxEntAppConfigId == -1) { throw new Exception("* * * AddEntAppConfig: Failed to retrieve an unused EntAppConfigId"); } using (DbCommand command = dbConn.CreateCommand()) { command.CommandText = "INSERT INTO [dbo].[uas_EntAppConfig] " + "([EntAppConfigId],[EnterpriseID],[ApplicationID],[EnumCode],[baseTypeId],[ConfigName],[ConfigValue],[CreatedDate],[CreatedBy],[StatusFlag]) " + "VALUES(" + (maxEntAppConfigId + 1) + "," + eac.EnterpriseID + "," + eac.ApplicationID + "," + "'" + eac.EnumCode + "'," + eac.baseTypeId + "," + "'" + eac.ConfigName + "'," + "'" + eac.ConfigValue + "'," + "'" + eac.CreatedDate + "'," + eac.CreatedBy + "," + "'" + eac.StatusFlag + "')"; command.CommandType = CommandType.Text; reader = command.ExecuteReader(); } } catch (Exception ex) { Debug.WriteLine("* * * AddEntAppConfig Exception: " + ex.Message); throw; } return(true); }
/// <summary> /// Retrieve a uas_EntAppConfig Record /// /// Used in venture mode SharedValidation, to retrieve a pre-computed list of required def_ItemVariable identifiers /// </summary> /// <param name="dbConn"></param> /// <param name="enumCode"></param> /// <param name="enterpriseID"></param> /// <returns></returns> public static uas_EntAppConfig GetEntAppConfig(DbConnection dbConn, string enumCode, int enterpriseID) { uas_EntAppConfig result = null; DbDataReader reader = null; try { using (DbCommand command = dbConn.CreateCommand()) { command.CommandText = "SELECT EntAppConfigId,EnterpriseID,ApplicationID,EnumCode," + "baseTypeId,ConfigName,ConfigValue,CreatedDate,CreatedBy,StatusFlag FROM [dbo].uas_EntAppConfig WHERE EnumCode = '" + enumCode + "' AND EnterpriseID = " + enterpriseID; command.CommandType = CommandType.Text; reader = command.ExecuteReader(); reader.Read(); if (!reader.IsDBNull(0)) { Debug.WriteLine("* * * GetEntAppConfig uas_EntAppConfig FieldCount: " + reader.FieldCount.ToString()); result = new uas_EntAppConfig(); result.EntAppConfigId = reader.GetInt32(0); result.EnterpriseID = reader.GetInt32(1); result.ApplicationID = reader.GetInt32(2); result.EnumCode = reader["EnumCode"].ToString(); result.baseTypeId = reader.GetInt16(4); result.ConfigName = reader["ConfigName"].ToString(); result.ConfigValue = reader["ConfigValue"].ToString(); result.CreatedDate = Convert.ToDateTime(reader["CreatedDate"].ToString()); result.CreatedBy = reader.GetInt32(8); result.StatusFlag = reader["StatusFlag"].ToString(); } reader.Close(); } } catch (Exception ex) { Debug.WriteLine("* * * GetEntAppConfig Exception: " + ex.Message); throw; } return(result); }
public static List <ItemVariableIdentifierWithPartSection> GetRequiredItemVarsWithPartsSections(IFormsRepository formsRepo, def_Forms frm, int enterpriseId) { //if not in venture mode, get the required item vars as normal (without touching uas_EntApConfig) if (!SessionHelper.IsVentureMode) { return(ComputeRequiredItemVarsWithPartsSections(formsRepo, frm, enterpriseId)); } string configEnumCode = "Required_ItemVariables_FormId_" + frm.formId; //attempt to query a pre-computed list of item variabel identifiers from the local Venture DB uas_EntAppConfig eac = null; using (DbConnection connection = UasAdo.GetUasAdoConnection()) { connection.Open(); eac = UasAdo.GetEntAppConfig(connection, configEnumCode, enterpriseId); } //if no pre-computed list was found, create it now and insert it into the local Venture DB so it can be quickly retrieved next time if (eac == null || String.IsNullOrWhiteSpace(eac.ConfigValue)) { List <ItemVariableIdentifierWithPartSection> requiredIvs = ComputeRequiredItemVarsWithPartsSections(formsRepo, frm, enterpriseId); string configValueString = String.Empty; foreach (ItemVariableIdentifierWithPartSection ivps in requiredIvs) { configValueString += ivps.partId + "," + ivps.sectionId + "," + ivps.itemVariableIdentifier + ";"; } using (DbConnection connection = UasAdo.GetUasAdoConnection()) { connection.Open(); UasAdo.AddEntAppConfig(connection, new uas_EntAppConfig() { EnterpriseID = enterpriseId, ApplicationID = UAS.Business.Constants.APPLICATIONID, EnumCode = configEnumCode, baseTypeId = 14, ConfigName = "Required ItemVariable Identifiers for Form " + frm.identifier, ConfigValue = configValueString, CreatedDate = DateTime.Now, CreatedBy = 1, StatusFlag = "A" }); } return(requiredIvs); } //if a pre-computed list was found in the local Venture DB, parse identifiers, partIds, sectionIds from the configValue List <ItemVariableIdentifierWithPartSection> result = new List <ItemVariableIdentifierWithPartSection>(); string[] chunks = eac.ConfigValue.Split(';'); foreach (string chunk in chunks) { if (String.IsNullOrWhiteSpace(chunk)) { continue; } try { string[] subChunks = chunk.Split(','); result.Add(new ItemVariableIdentifierWithPartSection { partId = Convert.ToInt32(subChunks[0]), sectionId = Convert.ToInt32(subChunks[1]), itemVariableIdentifier = subChunks[2] }); } catch (Exception e) { throw new Exception("Error converting string \"" + chunk + "\" into ItemVariableIdentifierWithPartSection", e); } } return(result); }