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); } } } }
public OrganizationFile(OrganizationFile file) { Id = file.Id; Name = file.Name; Path = file.Path; OrganizaionId = file.OrganizaionId; }
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()); }
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()); }
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); }
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); } } }
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("Файл не найден"); } } }