private void GenerateTubeGroups() { //Limpiar los grupos ya existentes tubeGroupMemory.Clear(); tubeGroupList.Clear(); for (int i = 0; i < tubeList.Count; i++) { Vector2Int gridPosition = GetGridPositionFromIndex(i); TubeController tube = tubeList[i]; //Obtener los tubos conectados a este List <TubeController> connectedTubes = GetConnectedTubes(gridPosition, tube); connectedTubes.Add(tube); //Obtener el grupo al que pertenece si es que existe TubeGroup tubeGroup = null; if (tubeGroupMemory.ContainsKey(tube)) { tubeGroup = tubeGroupMemory[tube]; } //Si el tubo no tiene un grupo asignado if (tubeGroup == null) { //Chequear sus tubos conexos, si estos ya están en un grupo, asignarle este for (int j = 0; j < connectedTubes.Count; j++) { TubeController connectedTube = connectedTubes[j]; if (tubeGroupMemory.ContainsKey(connectedTube)) { tubeGroup = tubeGroupMemory[connectedTube]; break; } } //Si ningún tubo conexo está en algún grupo, crear uno nuevo if (tubeGroup == null) { tubeGroup = new TubeGroup(); tubeGroupList.Add(tubeGroup); } } //Verificar todos los tubos conexos y agregarlos a las memorias for (int j = 0; j < connectedTubes.Count; j++) { TubeController connectedTube = connectedTubes[j]; if (!tubeGroupMemory.ContainsKey(connectedTube)) { tubeGroupMemory.Add(connectedTube, tubeGroup); tubeGroup.GetTubeSet().Add(connectedTube); } } } }
private void btn_del_Click(object sender, RoutedEventArgs e) { if (dg_TubesGroup.SelectedItem != null) { TubeGroup _TubeGroup = ((TubeGroup)dg_TubesGroup.SelectedItem); foreach (string TubesPosition in ((TubeGroup)dg_TubesGroup.SelectedItem).TubesPosition.Split(']')) { if (string.IsNullOrEmpty(TubesPosition)) { continue; } string str = TubesPosition.Remove(0, 1); int ColumnIndex = int.Parse(str.Split(',')[0]); int RowIndex = int.Parse(str.Split(',')[1]); Tubes.Rows[RowIndex - 1]["Background" + ColumnIndex.ToString()] = null; string TextItemCount = Tubes.Rows[RowIndex - 1]["TextItemCount" + ColumnIndex.ToString()].ToString(); foreach (TestingItemConfiguration _TestingItemConfiguration in _TubeGroup.TestingItemConfigurations) { TextItemCount = TextItemCount.Replace("," + _TubeGroup.RowIndex.ToString() + ";" + _TestingItemConfiguration.TestingItemColor, ""); } Tubes.Rows[RowIndex - 1]["TextItemCount" + ColumnIndex.ToString()] = TextItemCount; Tubes.Rows[RowIndex - 1]["DetailView" + ColumnIndex.ToString()] = Tubes.Rows[RowIndex - 1]["DetailView" + ColumnIndex.ToString()].ToString().Replace(_TubeGroup.TubesGroupName + " " + _TubeGroup.PoolingRulesName + _TubeGroup.TestintItemName + ",", ""); //int i = 0; //while (_TubeGroup.TestingItemConfigurations.Count > i) //{ // TestingItemConfiguration _TestingItemConfiguration = _TubeGroup.TestingItemConfigurations.ToList()[i++]; // Tubes.Rows[RowIndex - 1]["TextItemCount" + ColumnIndex.ToString()] = TextItemCount.Replace("," + _TubeGroup.RowIndex.ToString() + ";" + _TestingItemConfiguration.TestingItemColor, ""); // //((WanTai.DataModel.TubeGroup)(dg_TubesGroup.SelectedItem)).TestintItemName = ((WanTai.DataModel.TubeGroup)(dg_TubesGroup.SelectedItem)).TestintItemName.Replace(" " + _TestingItemConfiguration.TestingItemName, ""); // //if (_TestingItemConfiguration.TestingItemName == "HBV") // // HBVNumber -= _TubeGroup.TubesNumber; // //if (_TestingItemConfiguration.TestingItemName == "HCV") // // HCVNumber -= _TubeGroup.TubesNumber; // //if (_TestingItemConfiguration.TestingItemName == "HIV") // // HIVNumber -= _TubeGroup.TubesNumber; // // bool b = _TubeGroup.TestingItemConfigurations.Remove(_TubeGroup.TestingItemConfigurations.Where(tic => tic.TestingItemID == _TestingItemConfiguration.TestingItemID).FirstOrDefault()); //} } while (_TubeGroup.TestingItemConfigurations.Count > 0) { TestingItemConfiguration _TestingItemConfiguration = _TubeGroup.TestingItemConfigurations.First(); ((WanTai.DataModel.TubeGroup)(dg_TubesGroup.SelectedItem)).TestintItemName = ((WanTai.DataModel.TubeGroup)(dg_TubesGroup.SelectedItem)).TestintItemName.Replace(" " + _TestingItemConfiguration.TestingItemName, ""); //if (CurrentTubesBatch.TestingItem == null) // CurrentTubesBatch.TestingItem = new Dictionary<Guid, int>(); //int TestintItemNumber = _TubeGroup.TubesNumber / _TubeGroup.PoolingRulesTubesNumber + (_TubeGroup.TubesNumber % _TubeGroup.PoolingRulesTubesNumber > 0 ? 1 : 0); //if (CurrentTubesBatch.TestingItem.ContainsKey(_TestingItemConfiguration.TestingItemID)) // CurrentTubesBatch.TestingItem[_TestingItemConfiguration.TestingItemID] -= TestintItemNumber; //else // CurrentTubesBatch.TestingItem.Add(_TestingItemConfiguration.TestingItemID, 0); bool b = _TubeGroup.TestingItemConfigurations.Remove(_TubeGroup.TestingItemConfigurations.Where(tic => tic.TestingItemID == _TestingItemConfiguration.TestingItemID).FirstOrDefault()); } dg_TubesGroup.Items.Remove(dg_TubesGroup.SelectedItem); for (int i = 0; i < dg_TubesGroup.Items.Count; i++) { Label labTuubesGroupName = CommFuntion.FindName(dg_TubesGroup, 0, i, "lab_TubesGroupName") as Label; // Label labTuubesGroupName = CommFuntion.FindCellControl<Label>("lab_TubesGroupName", dg_TubesGroup, i, 0); if (labTuubesGroupName != null) { labTuubesGroupName.Content = "分组" + (i + 1).ToString(); } // ((TubeGroup)dg_TubesGroup.Items[i]).TuubesGroupName = "分组" + (i+1).ToString(); TuubesGroupName = i + 1; } if (dg_TubesGroup.Items.Count == 0) { TuubesGroupName = 0; btn_Next.IsEnabled = false; btn_Save.IsEnabled = false; } else { dg_TubesGroup.SelectedIndex = TuubesGroupName - 1; } } }