private void Merge(CalculationDictionary dictionary, Dictionary <double, ColorReason> excludedDocsDictionary, string[] groupIDs) { foreach (var groupID in groupIDs) { //Create group Group currentGroup = new Group(_views, groupID); //Get only for this group CalculationDictionary dictionaryOfCurrentGroup = currentGroup.GetItemsForCurrentGroup(groupID, dictionary); var dictionaryOfCurrentGroupObject = dictionaryOfCurrentGroup.GetDictionary(); foreach (KeyValuePair <DictionaryKey, ColorReason> item in dictionaryOfCurrentGroupObject) { // If (entry.ED_ENC_NUM and current filter is in dictionary[document-ED_ENC_NUM, FilterID] //and the entry in dictionary[document-ED_ENC_NUM, FilterID] is Red or Exclude) Then //CONTINUE; /* Red and exclude are not over written by green at this point */ try { ColorReason colorReason; bool exc = excludedDocsDictionary.TryGetValue(item.Key.ED_ENC_NUM, out colorReason); if (exc != false) { if (excludedDocsDictionary[item.Key.ED_ENC_NUM].Color == "RED") { continue; } else if (excludedDocsDictionary[item.Key.ED_ENC_NUM].Color == "EXCLUDE") { continue; } //2. If (DOCUMENT is already in dictionary) AND color is green AND Category of document is not in the "Excluded" group //Then: assign to it color/reason from the dictionary[groupID,ED_ENC_NUM] entry (same as above) else if (excludedDocsDictionary[item.Key.ED_ENC_NUM].Color == "GREEN") { //Get document var document = _views.MainForm.datasetBilling.Documents.FindByPrimaryKey(item.Key.ED_ENC_NUM); //Check if category is in excluded group var excludedCategory = ExcludedByCategoryType(document.Category, _filterId); if (excludedCategory.Length == 0) { excludedDocsDictionary[item.Key.ED_ENC_NUM] = item.Value; } } } else { //1. Is DOCUMENT is NOT already in dictionary - assign to it color/reason from the dictionary[groupID,ED_ENC_NUM] entry excludedDocsDictionary.Add(item.Key.ED_ENC_NUM, item.Value); } } catch (Exception ex) { MainForm.ShowExceptionMessage(ex); } } } }
private void Loop2(CalculationDictionary dictionary, string[] groupIDs) { foreach (var groupID in groupIDs) { //Create group Group currentGroup = new Group(_views, groupID); foreach (var document in _views.MainForm.datasetBilling.Documents) { //If (Doc has one-way or not one-way code form Group) Then dictionary[groupID,ED_ENC_NUM] = Green var icdInStandard = currentGroup.DocumentHaveICDInStandardWithoutOneWay(document); if (icdInStandard.Length > 0) { // I would like to check here if dictionary already has an entry for groupID, document.ED_ENC_NUM which is green // If it does then - let's leave the entry from Loop 1 because the reason there is more complete - it also indicates // that DISC has the code. Can we do that? Ok? Looks good - let's try // Looks good // One thing: in the reason, it is important to see DISC: first // we should probably change that in Loop1 - possible? var dictionaryKey = new DictionaryKey() { GroupID = groupID, ED_ENC_NUM = document.ED_ENC_NUM }; //If dictionary have this key if (dictionary.GetDictionary().ContainsKey(dictionaryKey)) { //Check for the color of the entry with this key if (dictionary.GetDictionary()[dictionaryKey].Color != "GREEN") { //Make it green var reason = "EDMD: " + icdInStandard; dictionary.Add(groupID, document.ED_ENC_NUM, "GREEN", reason); } } else { //Add new entry with color GREEN var reason = "EDMD: " + icdInStandard; dictionary.Add(groupID, document.ED_ENC_NUM, "GREEN", reason); } } } } }
public CalculationDictionary GetItemsForCurrentGroup(string groupID, CalculationDictionary dictionary) { var returnDictionary = new CalculationDictionary(); var dicionaryObject = dictionary.GetDictionary(); foreach (KeyValuePair <DictionaryKey, ColorReason> entry in dicionaryObject) { if (entry.Key.GroupID == groupID) { returnDictionary.Add(entry.Key.GroupID, entry.Key.ED_ENC_NUM, entry.Value.Color, entry.Value.Reason); } } return(returnDictionary); }
//Save to DB private void SaveDictionaryToDatabase(int filterId, CalculationDictionary dictionary) { var dictionaryItems = dictionary.GetDictionary(); foreach (KeyValuePair <DictionaryKey, ColorReason> item in dictionaryItems) { var newRedRow = _views.MainForm.datasetBilling.DocsToFilters.NewDocsToFiltersRow(); newRedRow.ED_ENC_NUM = item.Key.ED_ENC_NUM; newRedRow.FilterID = filterId; newRedRow.Type = item.Value.Color; newRedRow.Reason = item.Value.Reason; _views.MainForm.datasetBilling.DocsToFilters.Rows.Add(newRedRow); } //Save data to database try { _views.MainForm.adapterDocsToFiltersBilling.Update(_views.MainForm.datasetBilling.DocsToFilters); } catch (Exception ex) { MainForm.ShowExceptionMessage(ex); } }