Ejemplo n.º 1
0
        private void SetupLabelObject()
        {
            // clear edit control
            ObjectDataEdit.Clear();

            // clear all items first
            ObjectNameCmb.Items.Clear();

            // get the objects on the label
            string ObjNames = DymoLabels.GetObjectNames(true);

            // parse the result
            if (ObjNames != null)
            {
                int i = ObjNames.IndexOf('|');
                while (i >= 0)
                {
                    ObjectNameCmb.Items.Add(ObjNames.Substring(0, i));
                    ObjNames = ObjNames.Remove(0, i + 1);
                    i        = ObjNames.IndexOf('|');
                }
                if (ObjNames.Length > 0)
                {
                    ObjectNameCmb.Items.Add(ObjNames);
                    ObjectNameCmb.SelectedIndex = 0;
                }
            }
        }
Ejemplo n.º 2
0
        private void InitLabelObjects()
        {
            objNamesCmb.Items.Clear();
            string str = _dymoLabels.GetObjectNames(false);

            foreach (string name in str.Split(new char[] { '|' }))
            {
                objNamesCmb.Items.Add(name);
            }

            if (objNamesCmb.Items.Count > 0)
            {
                objDataEdit.Enabled       = true;
                objNamesCmb.SelectedIndex = 0;
                objDataEdit.Text          = _dymoLabels.GetText(objNamesCmb.Text);
            }
            else
            {
                objDataEdit.Enabled = false;
                objDataEdit.Text    = string.Empty;
            }
        }
Ejemplo n.º 3
0
        private void printBtn_Click(object sender, EventArgs e)
        {
            try
            {
                DymoAddInClass  _dymoAddin = new DymoAddInClass();
                DymoLabelsClass _dymoLabel = new DymoLabelsClass();

                // this call returns a list of objects on the label
                string[] objNames = _dymoLabel.GetObjectNames(false).Split(new Char[] { '|' });

                // Create OpenFileDialog
                OpenFileDialog dlg = new OpenFileDialog();

                dlg.DefaultExt = ".zip";
                dlg.Filter     = "ZIP Files (.zip)|*.zip";

                dlg.ShowDialog();

                // Open document
                string filename = dlg.FileName;

                // Get the file path to use
                string thePath = System.IO.Path.GetDirectoryName(dlg.FileName);

                ZipFile zf = null;

                // Open the stream
                FileStream fs = File.OpenRead(filename);
                zf = new ZipFile(fs);

                // List that will hold all the files found in the ZIP
                List <string> Files = new List <string>();

                //Loop over the files
                foreach (ZipEntry zipEntry in zf)
                {
                    if (!zipEntry.IsFile)
                    {
                        continue;
                    }

                    String entryFileName = zipEntry.Name;
                    // to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
                    // Optionally match entrynames against a selection list here to skip as desired.
                    // The unpacked length is available in the zipEntry.Size property.

                    byte[] buffer    = new byte[4096];  // 4K is optimum
                    Stream zipStream = zf.GetInputStream(zipEntry);

                    // Manipulate the output filename here as desired.
                    String fullZipToPath = Path.Combine(thePath, entryFileName);
                    string directoryName = Path.GetDirectoryName(fullZipToPath);
                    if (directoryName.Length > 0)
                    {
                        Directory.CreateDirectory(directoryName);
                    }

                    // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
                    // of the file, but does not waste memory.
                    // The "using" will close the stream even if an exception occurs.
                    using (FileStream streamWriter = File.Create(fullZipToPath))
                    {
                        StreamUtils.Copy(zipStream, streamWriter, buffer);

                        Files.Add(fullZipToPath);
                    }
                }

                for (int i = 0; i < Files.Count; i++)
                {
                    if (_dymoAddin.Open(Files[i]))
                    {
                        _dymoAddin.Print(1, false);
                    }
                }

                if (zf != null)
                {
                    zf.IsStreamOwner = true; // Makes close also shut the underlying stream
                    zf.Close();              // Ensure we release resources
                }
            }
            catch (Exception)
            {
                throw;
            }
        }