コード例 #1
0
        private void RemoveFileItem(object sender, EventArgs e)
        {
            OrganizationFile file = (OrganizationFile)lbFiles.SelectedItem;

            if (file != null)
            {
                var result = MessageBox.Show("Вы действительно хотите удалить выбранный файл?", "Удаление файла",
                                             MessageBoxButtons.YesNo,
                                             MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    lbFiles.Items.Remove(file);

                    var item = org.OrganizationFilesToAdd.FirstOrDefault(p => p.Path == file.Path);
                    if (item != null)
                    {
                        org.OrganizationFilesToAdd.Remove(item);
                    }
                    if (org.Id != 0)
                    {
                        org.OrganizationFilesToRemove.Add(file);
                    }
                }
            }
        }
コード例 #2
0
 public OrganizationFile(OrganizationFile file)
 {
     Id            = file.Id;
     Name          = file.Name;
     Path          = file.Path;
     OrganizaionId = file.OrganizaionId;
 }
コード例 #3
0
        public int Remove(OrganizationFile file)
        {
            string query;

            query = String.Format("DELETE FROM OrganizationFile  WHERE Id={0}", file.Id);

            SqlCommand cmd = new SqlCommand(query, _conn);

            return(cmd.ExecuteNonQuery());
        }
コード例 #4
0
        public int Add(OrganizationFile file)
        {
            string query;

            query = String.Format("INSERT INTO OrganizationFile (Path,Name,OrganizationId)  VALUES ('{0}','{1}',{2})", file.Path, file.Name, file.OrganizaionId);

            SqlCommand cmd = new SqlCommand(query, _conn);

            return(cmd.ExecuteNonQuery());
        }
コード例 #5
0
        public List <OrganizationFile> GetFilesByOrganizationId(int id)
        {
            List <OrganizationFile> files = new List <OrganizationFile>();

            string     query  = "SELECT * FROM OrganizationFile WHERE OrganizationId=" + id;
            SqlCommand cmd    = new SqlCommand(query, _conn);
            var        reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                OrganizationFile phone = new OrganizationFile(reader);
                files.Add(phone);
            }

            return(files);
        }
コード例 #6
0
        private void btnAddFile_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Title = "Добавить файл";

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string localPath = db.copyFileLocally(org, dlg.FileName);

                    OrganizationFile file = new OrganizationFile();
                    file.Name = Path.GetFileName(dlg.FileName);
                    file.Path = localPath;
                    org.OrganizationFilesToAdd.Add(file);
                    lbFiles.Items.Add(file);
                }
            }
        }
コード例 #7
0
        private void OpenFileItem(object sender, EventArgs e)
        {
            OrganizationFile file = (OrganizationFile)lbFiles.SelectedItem;

            if (file != null)
            {
                if (File.Exists(file.Path))
                {
                    try
                    {
                        System.Diagnostics.Process.Start(file.Path);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка при открытии файла " + ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Файл не найден");
                }
            }
        }