public override bool Save(DCAnalyticsObject obj) { try { SkipCondition condition = obj as SkipCondition; var exists = RecordExists("dsto_skipcondition", condition.Key); string query = string.Empty; string targetKey = (condition.Target.Section != null) ? condition.Target.Section.Key : (condition.Target.SubSection != null) ? condition.Target.SubSection.Key: condition.Target.Question.Key; if (!exists) { query = $"insert into dsto_skipcondition([guid],[created_by],[yref_attribute],[yref_target],[answer],[yref_question],[dataCollectionObectType]) " + $"values('{condition.Key}','Admin','{condition.AttributeKey}','{targetKey}','{condition.Answer.Key}','{condition.QuestionKey}', '{(int)condition.DataCollectionObectType}')"; } else { query = $"UPDATE dsto_skipcondition SET" + $"[yref_attribute] = '{condition.AttributeKey}', " + $"[yref_target] = '{targetKey}', " + $"[dataCollectionObectType] = '{(int)condition.DataCollectionObectType}', " + $"[answer] = '{condition.Answer.Key}', " + $"[Deleted]='{condition.Deleted}' " + $"WHERE [guid] = '{condition.Key}'"; } return(DbInfo.ExecuteNonQuery(query) > -1); } catch (Exception ex) { throw ex; } }
private static bool makeBoard(int[,] board, int row, int col, SkipCondition skipCondition) { //adjusting rows and columns to stay within board if (row == 9) { row = 0; col++; } //base case - column out of bounds if (col == 9) return true; //recursive case else { if (skipCondition(board, row, col)) return makeBoard(board, row + 1, col, skipCondition); // if the cell is skippable, ignore it and move onto the next cell int[] availableNums = SudokuMethods.getValidMoves(board, row, col); for (int i = 0; i < availableNums.Length; i++) { board[row, col] = availableNums[i]; // fill cell with a valid value if (makeBoard(board, row + 1, col, skipCondition)) return true; // if the rest of the puzzle is correct, then this cell is correct board[row, col] = 0; // otherwise reset cell and try the next value } return false; } }
private void AddSkipCondition() { SkipCondition skipCondition = _choiceQuestion.Conditions.Add(); SkipConditionBuilder skipConditionBuilder = new SkipConditionBuilder(skipCondition); if (skipConditionBuilder.ShowDialog() == DialogResult.OK) { RefreshSkipConditions(); } }
public SkipConditions GetConditions(Question question) { SkipConditions conditions = new SkipConditions(null); try { string query = $"select * from dsto_skipcondition where [yref_question]='{question.Key}' and Deleted=0 order by oid asc"; var table = DbInfo.ExecuteSelectQuery(query); if (table.Rows.Count > 0) { foreach (DataRow row in table.Rows) { SkipCondition condition = new SkipCondition(null); condition.Key = row["guid"].ToString(); condition.OID = int.Parse(row["OID"].ToString()); condition.Deleted = bool.Parse(row["deleted"].ToString()); condition.Answer = new EnumListValueProvider(DbInfo).GetEnumList(row["answer"].ToString()); condition.DataCollectionObectType = (row["dataCollectionObectType"] != DBNull.Value) ? (DataCollectionObectTypes)Enum.Parse(typeof(DataCollectionObectTypes), row["dataCollectionObectType"].ToString()) : DataCollectionObectTypes.None; switch (condition.DataCollectionObectType) { case DataCollectionObectTypes.Section: condition.Target.Section = new SectionProvider(DbInfo).GetTargetSection(row["yref_target"].ToString()); break; case DataCollectionObectTypes.SubSection: condition.Target.SubSection = new SubSectionProvider(DbInfo).GetSubSection(row["yref_target"].ToString()); break; case DataCollectionObectTypes.Question: condition.Target.Question = new QuestionProvider(DbInfo).GetQuestion(row["yref_target"].ToString()); break; } condition.AttributeKey = row["yref_attribute"].ToString(); conditions.Add(condition); } } } catch (Exception ex) { throw ex; } return(conditions); }
public SkipConditionBuilder(SkipCondition condition) { InitializeComponent(); _condition = condition; Bind(); }