Exemplo n.º 1
0
        private void selectionFileButton_Click(object sender, EventArgs e)
        {
            Stream         myStream       = null;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter           = "Text files (*.txt, *.doc, *.docx)|*.txt;*.doc;*.docx|Image files (*.png, *.bmp, *.jpg)|*.png;*.bmp;*.jpg";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            string fileName = Path.GetFileName(openFileDialog.FileName);
                            if (!checkFile(fileName))
                            {
                                CFile file = new CFile();
                                file.fileName = fileName;
                                file.filePath = openFileDialog.FileName;
                                file.fileByte = getFile(file.filePath);
                                file.dataAdd  = dateTimePicker.Text;
                                fileItems.Add(file);
                                fileNameListBox.Items.Add(fileName);
                                deleteFileNameListBox.Items.Add("X");
                            }
                            else
                            {
                                MessageBox.Show("Этот файл уже выбран", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        private void addAtachment_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter = "Text files (*.txt, *.doc, *.docx)|*.txt;*.doc;*.docx|Image files (*.png, *.bmp, *.jpg)|*.png;*.bmp;*.jpg";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            string fileName = Path.GetFileName(openFileDialog.FileName);
                            CFile file = new CFile();
                            file.fileName = fileName;
                            file.filePath = openFileDialog.FileName;
                            file.fileByte = getFile(file.filePath);
                            file.dataAdd = DateTime.Today.ToString();
                            srv.createNewAtachments(file.fileName, file.fileByte, file.dataAdd);
                            int i = AtachmentsGrid.Rows.Add();
                            AtachmentsGrid.Rows[i].Cells[1].Value = file.dataAdd;
                            AtachmentsGrid.Rows[i].Cells[3].Value = file.fileName;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Exemplo n.º 3
0
        private void addAtachment_Click(object sender, EventArgs e)
        {
            Stream         myStream       = null;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter           = "Text files (*.txt, *.doc, *.docx)|*.txt;*.doc;*.docx|Image files (*.png, *.bmp, *.jpg)|*.png;*.bmp;*.jpg";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            string fileName = Path.GetFileName(openFileDialog.FileName);
                            CFile  file     = new CFile();
                            file.fileName = fileName;
                            file.filePath = openFileDialog.FileName;
                            file.fileByte = getFile(file.filePath);
                            file.dataAdd  = DateTime.Today.ToString();
                            srv.createNewAtachments(file.fileName, file.fileByte, file.dataAdd);
                            int i = AtachmentsGrid.Rows.Add();
                            AtachmentsGrid.Rows[i].Cells[1].Value = file.dataAdd;
                            AtachmentsGrid.Rows[i].Cells[3].Value = file.fileName;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        private void selectionFileButton_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter = "Text files (*.txt, *.doc, *.docx)|*.txt;*.doc;*.docx|Image files (*.png, *.bmp, *.jpg)|*.png;*.bmp;*.jpg";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            string fileName = Path.GetFileName(openFileDialog.FileName);
                            if (!checkFile(fileName))
                            {
                                CFile file = new CFile();
                                file.fileName = fileName;
                                file.filePath = openFileDialog.FileName;
                                file.fileByte = getFile(file.filePath);
                                file.dataAdd = dateTimePicker.Text;
                                fileItems.Add(file);
                                fileNameListBox.Items.Add(fileName);
                                deleteFileNameListBox.Items.Add("X");
                            }
                            else
                            {
                                MessageBox.Show("Этот файл уже выбран", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }