Example #1
0
        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;
                            }
                        }
                    }
                }
            }
        }