public CClink_Variable() { _X = new X(MAX_X_COUNT); _Y = new Y(MAX_Y_COUNT); _SB = new SB(MAX_SB_COUNT); _SW = new SW(MAX_SW_COUNT); _RAB = new RAB(MAX_RAB_COUNT); _WW = new WW(MAX_WW_COUNT); _WR = new WR(MAX_WR_COUNT); _SPB = new SPB(MAX_SPB_COUNT); }
public ActionResult CodesTable(int countryId, string R = "0") { List <BaseTable> UIcodesTable = new List <BaseTable>(); BaseTable table = null; // init table with default values for (int i = 0; i < 100; ++i) { table = new BaseTable { R = R, AB = i < 10 ? $"0{i}" : $"{i}" }; for (int j = 0; j < 10; ++j) { table.codes[j] = new CodeDt() { code = $"{table.AB}{j}" }; } UIcodesTable.Add(table); } Country country = db.Countries.Find(countryId); ICollection <Code> countryCodes = country.Codes; // paint cells with roots colors if (R.Length > 1) { foreach (var ABrow in UIcodesTable) { IEnumerable <Code> rootCodes = null; string RAB; for (int i = 1; i < R.Length; i++) { RAB = R + ABrow.AB; if (i > 1) { RAB = RAB.Remove(RAB.Length - i + 1); } RAB = RAB.Substring(RAB.Length - 3); rootCodes = countryCodes.Where(code => code.R == R.Remove(R.Length - i) && code.Value.Equals(RAB)); if (rootCodes.Count() > 0) { break; } } if (rootCodes.Count() > 0) { foreach (var rootCode in rootCodes) { char lastDigit = rootCode.Value[rootCode.Value.Length - 1] == ' ' ? rootCode.Value[rootCode.Value.Length - 2] : rootCode.Value[rootCode.Value.Length - 1]; for (int i = 0; i < 10; ++i) { if (lastDigit == i.ToString()[0]) { for (int k = 0; k < 10; k++) { ABrow.codes[k].colorHEX = rootCode.Network.Color.Hex; ABrow.codes[k].id = -rootCode.Id; } } continue; } } } } } // fill table with codes IEnumerable <Code> codesOfR = countryCodes.Where(code => code.R == R); if (codesOfR.Count() > 0) { foreach (var ABrow in UIcodesTable) { foreach (var cell in ABrow.codes) { Code code = codesOfR.FirstOrDefault(_code => _code.Value == cell.code); if (code != null) { cell.colorHEX = code.Network.Color.Hex; cell.id = code.Id; } } } } // paint cells with inherited codes colors IEnumerable <Code> inheritedCodes = null; foreach (var ABrow in UIcodesTable) { foreach (var cell in ABrow.codes) { inheritedCodes = countryCodes.Where(code => $"{code.R}{code.Value}".StartsWith(R + cell.code)); if (inheritedCodes.Count() == 0) { continue; } string colorHEX = null; foreach (var code in inheritedCodes) { if (cell.colorHEX == "#FFFFFF") { colorHEX = greyColorHEX; break; } if (colorHEX == null) { colorHEX = code.Network.Color.Hex; } else if (colorHEX != code.Network.Color.Hex) { colorHEX = greyColorHEX; break; } } cell.colorHEX = colorHEX; } } return(PartialView(UIcodesTable)); }