Exemplo n.º 1
0
        private void RemoveAttachedFileButton_Click(object sender, EventArgs e)
        {
            for (int x = attachmentListBox.SelectedIndices.Count - 1; x >= 0; x--)
            {
                int element = attachmentListBox.SelectedIndices[x];

                // decrement total file size
                FilesTotalLength -= new FileInfo(AttachmentFilePaths[element]).Length;

                AttachmentFilePaths.RemoveAt(element);
                AttachmentFileNames.RemoveAt(element);
            }

            UpdateTotalFilesLengthInfo();

            UpdateBindings();

            toolStripStatusLabel.Text = string.Empty;
        }
Exemplo n.º 2
0
        private void AttachFileButton_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                foreach (string file in openFileDialog.FileNames)
                {
                    // check, if list contains current file
                    if (AttachmentFilePaths.Contains(file))
                    {
                        MessageBox.Show($"File '{file}' already added", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        continue;
                    }

                    long fileLength = new FileInfo(file).Length;

                    if (FilesTotalLength + fileLength > (long.Parse(fileSizeLimitTextBox.Text) * 1048576))
                    {
                        toolStripStatusLabel.Text = string.Empty;
                        MessageBox.Show($"Attachment(s) total file size exceeds the limit allowed", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        continue;
                    }
                    else
                    {
                        // increment total file size
                        FilesTotalLength += fileLength;
                    }

                    AttachmentFilePaths.Add(file);
                    AttachmentFileNames.Add(Path.GetFileName(file));
                }

                UpdateTotalFilesLengthInfo();

                UpdateBindings();

                toolStripStatusLabel.Text = "File(s) added";
            }
        }