private void bOK_Click(object sender, System.EventArgs e)
        {
            // Verify there are no duplicate names in the embedded list
            Hashtable ht = new Hashtable(lbImages.Items.Count + 1);

            foreach (EmbeddedImageValues eiv in lbImages.Items)
            {
                if (eiv.Name == null || eiv.Name.Length == 0)
                {
                    MessageBox.Show(this, "Name must be specified for all embedded images.", "Image");
                    return;
                }

                if (!ReportNames.IsNameValid(eiv.Name))
                {
                    MessageBox.Show(this,
                                    string.Format("Name '{0}' contains invalid characters.", eiv.Name), "Image");
                    return;
                }

                string name = (string)ht[eiv.Name];
                if (name != null)
                {
                    MessageBox.Show(this,
                                    string.Format("Each embedded image must have a unique name. '{0}' is repeated.", eiv.Name), "Image");
                    return;
                }
                ht.Add(eiv.Name, eiv.Name);
            }

            Apply();
            DialogResult = DialogResult.OK;
        }
        private void bOK_Click(object sender, System.EventArgs e)
        {
            // Verify there are no duplicate names in the data sources
            Hashtable ht = new Hashtable(this.lbDataSources.Items.Count + 1);

            foreach (DataSourceValues dsv in lbDataSources.Items)
            {
                if (dsv.Name == null || dsv.Name.Length == 0)
                {
                    MessageBox.Show(this, "Name must be specified for all DataSources.", "Data Sources");
                    return;
                }

                if (!ReportNames.IsNameValid(dsv.Name))
                {
                    MessageBox.Show(this,
                                    string.Format("Name '{0}' contains invalid characters.", dsv.Name), "Data Sources");
                    return;
                }

                string name = (string)ht[dsv.Name];
                if (name != null)
                {
                    MessageBox.Show(this,
                                    string.Format("Each DataSource must have a unique name. '{0}' is repeated.", dsv.Name), "Data Sources");
                    return;
                }
                ht.Add(dsv.Name, dsv.Name);
            }

            // apply the result
            Apply();
            DialogResult = DialogResult.OK;
        }
 private void tbEIName_Validating(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (!ReportNames.IsNameValid(tbEIName.Text))
     {
         e.Cancel = true;
         MessageBox.Show(this,
                         string.Format("Name '{0}' contains invalid characters.", tbEIName.Text), "Image");
     }
 }
Ejemplo n.º 4
0
        private void tbName_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            bool bRows = HasRows();

            // If no rows and no data in name it's ok
            if (!bRows && this.tbName.Text.Trim().Length == 0)
            {
                return;
            }

            if (!ReportNames.IsNameValid(tbName.Text))
            {
                e.Cancel = true;
                MessageBox.Show(string.Format("{0} is an invalid name.", tbName.Text), "Name");
            }
        }
        private void tbDSName_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            int cur = lbDataSources.SelectedIndex;

            if (cur < 0)
            {
                return;
            }

            if (!ReportNames.IsNameValid(tbDSName.Text))
            {
                e.Cancel = true;
                MessageBox.Show(this,
                                string.Format("Name '{0}' contains invalid characters.", tbDSName.Text), "Data Sources");
            }
        }
        private void bImport_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Bitmap Files (*.bmp)|*.bmp" +
                         "|JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif" +
                         "|GIF (*.gif)|*.gif" +
                         "|TIFF (*.tif;*.tiff)|*.tif;*.tiff" +
                         "|PNG (*.png)|*.png" +
                         "|All Picture Files|*.bmp;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif;*.tif;*.tiff;*.png" +
                         "|All files (*.*)|*.*";
            ofd.FilterIndex     = 6;
            ofd.CheckFileExists = true;
            ofd.Multiselect     = true;
            try
            {
                if (ofd.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                // need to create a new embedded image(s)
                int cur = 0;
                foreach (string filename in ofd.FileNames)
                {
                    Stream strm             = null;
                    System.Drawing.Image im = null;
                    string imagedata        = null;
                    try
                    {
                        strm      = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                        im        = System.Drawing.Image.FromStream(strm);
                        imagedata = this.GetBase64Image(im);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, ex.Message, "Image");
                    }
                    finally
                    {
                        if (strm != null)
                        {
                            strm.Close();
                        }
                        if (im != null)
                        {
                            im.Dispose();
                        }
                    }

                    if (imagedata != null)
                    {
                        FileInfo fi = new FileInfo(filename);

                        string fname;
                        int    offset = fi.Name.IndexOf('.');
                        if (offset >= 0)
                        {
                            fname = fi.Name.Substring(0, offset);
                        }
                        else
                        {
                            fname = fi.Name;
                        }

                        if (!ReportNames.IsNameValid(fname))
                        {
                            fname = "embeddedimage";
                        }
                        // Now check to see if we already have one with that name
                        int  index = 1;
                        bool bDup  = true;
                        while (bDup)
                        {
                            bDup = false;
                            foreach (EmbeddedImageValues ev in lbImages.Items)
                            {
                                if (fname == ev.Name)
                                {
                                    bDup = true;
                                    break;
                                }
                            }
                            if (bDup)
                            {                                                // we have a duplicate name; try adding an index number
                                fname  = Regex.Replace(fname, "[0-9]*", ""); // remove old numbers (side effect removes all numbers)
                                fname += index.ToString();
                                index++;
                            }
                        }

                        EmbeddedImageValues eiv = new EmbeddedImageValues(fname);
                        eiv.MIMEType  = "image/png";
                        eiv.ImageData = imagedata;
                        cur           = this.lbImages.Items.Add(eiv);
                    }
                }
                lbImages.SelectedIndex = cur;
            }
            finally
            {
                ofd.Dispose();
            }
            this.tbEIName.Focus();
        }