private void btnSave_Click(object sender, RoutedEventArgs e) { Timeout = int.Parse(txtTimeout.Text); DataView dv = gridProduct.DataContext as DataView; if (!File.Exists(txtFilePath.Text) || dv == null) { MessageBox.Show("Sorry! No data to save"); return; } using (StreamWriter writer = new StreamWriter(txtFilePath.Text)) { Rfc4180Writer.WriteDataTable(dv.Table, writer, true); } }
private string automationExport() { DataView dv = gridProduct.DataContext as DataView; if (dv == null) { //MessageBox.Show("Sorry! Nothing to export"); return(null); } DataRow[] outputRows = dv.Table.Select("sync_state = 'changed'"); if (outputRows.Length <= 0) { //MessageBox.Show("Sorry! Nothing to export"); return(null); } DataTable dtPriceChanged = dv.Table.Select("sync_state = 'changed'").CopyToDataTable(); lbPriceChangedCount.Text = dtPriceChanged.Rows.Count + " rows"; if (ckPublishValidPrice.IsChecked == true) { foreach (DataRow dr in dtPriceChanged.Rows) { dr[Product.IS_PUBLISHED] = Product.TRUE; } } FileInfo info = new FileInfo(txtFilePath.Text); string outFile = info.Directory.FullName + "\\" + info.Name.Replace(".csv", "") + "_auto_" + DateTime.Now.ToString("yyyyMdd_hhmmss") + ".csv"; using (StreamWriter writer = new StreamWriter(outFile)) { Rfc4180Writer.WriteDataTable(dtPriceChanged, writer, true); } txtPriceChangedExport.Text = outFile; //MessageBox.Show("Export success.\n" + outFile); return(outFile); }
private void btnExportInvalidPrice_Click(object sender, RoutedEventArgs e) { DataView dv = gridProduct.DataContext as DataView; if (dv == null) { MessageBox.Show("Sorry! Nothing to export"); return; } DataRow[] outputRows = dv.Table.Select("sync_state = 'error'"); if (outputRows.Length <= 0) { MessageBox.Show("Sorry! Nothing to export"); return; } DataTable dtPriceError = dv.Table.Select("sync_state = 'error'").CopyToDataTable(); if (ckUnpublishInvalidPrice.IsChecked == true) { foreach (DataRow dr in dtPriceError.Rows) { dr[Product.IS_PUBLISHED] = "FALSE"; } } lbInvalidPriceCount.Text = dtPriceError.Rows.Count + " rows"; FileInfo info = new FileInfo(txtFilePath.Text); string outFile = info.Directory.FullName + "\\" + info.Name.Replace(".csv", "") + "_unpublished_" + DateTime.Now.ToString("yyyyMdd_hhmmss") + ".csv"; using (StreamWriter writer = new StreamWriter(outFile)) { Rfc4180Writer.WriteDataTable(dtPriceError, writer, true); } txtInvalidPrice.Text = outFile; MessageBox.Show("Export success.\n" + outFile); }