/// <summary> /// This function to select a question from database using his type from manger. /// </summary> private static int SelectIdType(TypeOfQuestion TypeOfQustion, ref int Id) { try { if (IsServerConnected()) { int ResultOfBulid = BuildConnectionString(); if (ResultOfBulid == GenralVariables.Succeeded) { string SelectIdTypeStatment = GenralVariables.SelectMaxId + TypeOfQustion.ToString(); Id = -1; using (SqlConnection Connection = new SqlConnection(GenralVariables.ConnectionString)) { SqlCommand CommandForSelectIdType = new SqlCommand(SelectIdTypeStatment, Connection); CommandForSelectIdType.Connection.Open(); SqlDataReader Reader = CommandForSelectIdType.ExecuteReader(); while (Reader.Read()) { Id = Convert.ToInt32(Reader[GenralVariables.IdQuestion]); //break; } Reader.Close(); if (Id != -1) { return(GenralVariables.Succeeded); } } return(GenralVariables.ErrorInDataBase); } return(ResultOfBulid); } return(GenralVariables.ErrorWhileConnectiong); } catch (Exception ex) { Id = -1; GenralVariables.Errors.Log(ex.Message); return(GenralVariables.ErrorInSelectionQuestion); } }