void SetMaskIsDefault(MaskContainer mask, bool isDefault) { bool success; if (wgDB == null) { wgDB = new WaveguideDB(); } if (isDefault) // if setting to true, set any others are true to false (to make sure we don't have multiple defaults) { PlateTypeItem ptItem = null; // find parent PlateTypeItem foreach (PlateTypeItem pti in VM.PlateTypeList) { if (mask.PlateTypeID == pti.PlateType.PlateTypeID) { ptItem = pti; break; } } if (ptItem != null) { foreach (MaskContainer mc in ptItem.MaskList) { if (mc.IsDefault) { mc.IsDefault = false; success = wgDB.UpdateMask(mc); } } } } mask.IsDefault = isDefault; success = wgDB.UpdateMask(mask); if (!success) { MessageBox.Show("Failed to Update Mask", wgDB.GetLastErrorMsg(), MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Mask_Save_Click(object sender, EventArgs e) { MaskContainer mask = new MaskContainer(); mask.Rows = m_mask.Mask.Rows; mask.Cols = m_mask.Mask.Cols; mask.XOffset = m_mask.Mask.XOffset; mask.YOffset = m_mask.Mask.YOffset; mask.XSize = m_mask.Mask.XSize; mask.YSize = m_mask.Mask.YSize; mask.XStep = m_mask.Mask.XStep; mask.YStep = m_mask.Mask.YStep; mask.Angle = m_mask.Mask.Angle; mask.Shape = m_mask.Mask.Shape; mask.Description = m_mask.Mask.Description; bool available = true; int existingMaskID = 0; if (m_refImage == null) { MessageBoxResult result = MessageBox.Show("Mask cannot be saved without a Reference Image. You must Load a Reference Image.", "No Image Loaded", MessageBoxButton.OK, MessageBoxImage.Error); } else if (mask.Description.Length < 1) { MessageBoxResult result = MessageBox.Show("Mask cannot be saved without a Name. Please give the Mask a Name.", "No Name given for Mask", MessageBoxButton.OK, MessageBoxImage.Error); } else { if (m_mask.PlateType != null) { mask.PlateTypeID = m_mask.PlateType.PlateTypeID; } else { mask.PlateTypeID = 0; } bool exists = false; bool success = wgDB.ReferenceImageExists(m_refImage.ReferenceImageID, ref exists); if (!exists) { MessageBoxResult result = MessageBox.Show("Image being used is not in Database. Save the Image to database first.", "Reference Image not saved in Database", MessageBoxButton.OK, MessageBoxImage.Error); } else if (wgDB.MaskDescriptionAvailable(mask.Description, ref available, ref existingMaskID)) { if (available) { success = wgDB.InsertMask(ref mask); if (success) { m_mask.Mask.MaskID = mask.MaskID; } } else { MessageBoxResult result = MessageBox.Show("'" + mask.Description + "' already exists. Do you want to over write it?", "Overwrite Existing Mask", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { mask.MaskID = existingMaskID; success = wgDB.UpdateMask(mask); if (success) { m_mask.Mask.MaskID = mask.MaskID; } } } } } }