void saveFile(string fileName, string safeFileName) { if (new FileInfo(fileName).Length > 6500000) { MessageBox.Show("Файл " + safeFileName + " не может быть сохранен.\nРазмер больше 6.5 мегабайт."); return; } BidFiles bidFile = new BidFiles(); bidFile.Name = safeFileName; bidFile.Id_bid = bid.Id; bidFile.FileBody = File.ReadAllBytes(fileName); bidFile.Ext = Path.GetExtension(fileName); bidFile.IsCurrent = true; //start task Task.Factory.StartNew(() => { //save file if (!bidFile.save()) { MessageBox.Show(bidFile.LastError); return; } else { Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { })); } }); }
void BtnDownload_Click(object sender, RoutedEventArgs e) { BidFiles bidFile = dgvBidFiles.SelectedItem as BidFiles; if (bidFile == null) { return; } SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = bidFile.Ext + " |*" + bidFile.Ext; dialog.FileName = bidFile.Name; if (dialog.ShowDialog() == false) { return; } string url = Settings.uri.GetLeftPart(UriPartial.Authority) + "/" + bidFile.Path; MessageBox.Show(url); WebClient webClient = new WebClient(); webClient.DownloadFile(url, dialog.FileName); }
public bool @remove <T>(T modelItem) { BidFiles bidFiles = modelItem as BidFiles; if (bidFiles == null) { bidFiles.LastError = "Не удалось преобразовать входные данные."; return(false); } if (!_collection.Contains(bidFiles)) { return(true); } return(_collection.Remove(bidFiles)); }
void BtnDeleteFile_Click(object sender, RoutedEventArgs e) { BidFiles bidFile = dgvBidFiles.SelectedItem as BidFiles; if (bidFile == null) { return; } if (MessageBox.Show("Удалить файл?", "Удалить файл?", MessageBoxButton.YesNo) == MessageBoxResult.No) { return; } if (!bidFile.remove()) { MessageBox.Show(bidFile.LastError); } }
public BidShipmentSaveWindow(Bid bid, Action callback = null) { InitializeComponent(); defaultBrush = cbxTransportCompany.Background; Title += bid.Id.ToString(); current_archive = bid.Is_archive; tbxComment.Text = bid.Comment; this.bid = bid; this.callback = callback; CollectionViewSource viewSource = new CollectionViewSource(); viewSource.Source = TransportCompanyViewModel.instance().Collection; cbxTransportCompany.ItemsSource = viewSource.View; viewSource.SortDescriptions.Add(new SortDescription("Row_order", ListSortDirection.Descending)); cbxTransportCompany.SelectedIndex = -1; if (bid.Id_transport_company != null) { cbxTransportCompany.SelectedValue = bid.Id_transport_company; } tbxWaybill.Text = bid.Waybill; bidFilesViewSource.Source = bid.BidFilesCollection; bidFilesViewSource.Filter += delegate(object sender, FilterEventArgs e) { BidFiles bidFiles = e.Item as BidFiles; if (bidFiles == null) { e.Accepted = false; return; } e.Accepted = bidFiles.IsCurrent; }; DataContext = new { BidFilesCollection = bidFilesViewSource.View, }; }
public bool @add <T>(T modelItem) { BidFiles bidFiles = modelItem as BidFiles; if (bidFiles == null) { bidFiles.LastError = "Не удалось преобразовать входные данные."; return(false); } BidFiles exist = getById(bidFiles.Id); if (exist != null || _collection.Contains(bidFiles)) { //bidFiles.LastError = "Данная запись уже есть в коллекции."; return(true); } _collection.Add(bidFiles); return(true); }