- Data:
- 2009-04-28 15:41:04 (17 years ago)
- Lokalizacja:
- branches/ReklamaReorganizacja/BazaReklam
- Pliki:
-
- 2 zmodyfikowane
-
Classes/Helpers/ExcelHelper.cs (zmodyfikowane) (3 diffs)
-
ClientsForm.cs (zmodyfikowane) (2 diffs)
Legenda:
- Bez zmian
- Dodane
- Usunięte
-
branches/ReklamaReorganizacja/BazaReklam/Classes/Helpers/ExcelHelper.cs
r613 r620 1 using System; 2 using System.Data; 3 using System.IO; 4 using System.Text; 1 5 using System.Windows.Forms; 2 6 … … 5 9 public class ExcelHelper 6 10 { 11 //TODO: replace ExcelHelper Export method with ExportToCsv (see below). This will remove unneccesary depedencies.. 7 12 public void Export(DataGridView source) 8 13 { … … 36 41 } 37 42 } 38 // excel.Save("New.xls");39 43 excel.Visible = true; 44 } 45 46 public void ExportToCsv(DataGridView gridView, string strFilePath) 47 { 48 StreamWriter sw = new StreamWriter(strFilePath, false, Encoding.Default); 49 50 //write all the columns 51 StringBuilder columns = new StringBuilder(); 52 for (int i = 0; i < gridView.Columns.Count; i++) 53 { 54 columns.Append(string.Format("\"{0}\",", gridView.Columns[i].HeaderText)); 55 } 56 57 sw.WriteLine(columns.ToString().Remove(columns.ToString().Length-1)); 58 59 // Now write all the rows. 60 StringBuilder rowBuilder; 61 foreach (DataGridViewRow row in gridView.Rows) 62 { 63 rowBuilder = new StringBuilder(); 64 foreach (DataGridViewColumn column in gridView.Columns) 65 rowBuilder.Append(string.Format("\"{0}\",", row.Cells[column.Name].Value)); 66 67 sw.WriteLine(rowBuilder.ToString().Remove(rowBuilder.ToString().Length - 1)); 68 } 69 sw.Flush(); 70 sw.Close(); 71 sw.Dispose(); 72 } 73 74 public void ExportToCsv(DataTable dt, string strFilePath) 75 { 76 // Create the CSV file to which grid data will be exported. 77 StreamWriter sw = new StreamWriter(strFilePath, false, Encoding.UTF8); 78 79 // First we will write the headers. 80 int iColCount = dt.Columns.Count; 81 for (int i = 0; i < iColCount; i++) 82 { 83 sw.Write(string.Format("\"{0}\"", dt.Columns[i])); 84 85 if (i < iColCount - 1) //write comma after every column, not after the last one 86 sw.Write(","); 87 } 88 89 sw.Write(sw.NewLine); 90 91 // Now write all the rows. 92 foreach (DataRow dr in dt.Rows) 93 { 94 for (int i = 0; i < iColCount; i++) 95 { 96 if (!Convert.IsDBNull(dr[i])) 97 sw.Write(string.Format("\"{0}\"", dr[i])); 98 99 if (i < iColCount - 1) //write comma after every column, not after the last one 100 sw.Write(","); 101 } 102 103 sw.Write(sw.NewLine); 104 } 105 sw.Flush(); 106 sw.Close(); 107 sw.Dispose(); 40 108 } 41 109 } -
branches/ReklamaReorganizacja/BazaReklam/ClientsForm.cs
r616 r620 3 3 using System.Data; 4 4 using System.Data.SqlClient; 5 using System.Diagnostics; 5 6 using System.Drawing; 6 7 using System.Windows.Forms; … … 2203 2204 } 2204 2205 2206 //TODO: replace ExcelHelper Export method with ExportToCsv to remove unneccesary depedencies.. 2205 2207 private void excelToolStripButton_Click(object sender, EventArgs e) 2206 2208 { 2207 2209 Cursor = Cursors.WaitCursor; 2208 2210 2209 ExcelHelper ex = new ExcelHelper();2210 ex .Export(clientsDataGridView);2211 2211 ExcelHelper excelHelper = new ExcelHelper(); 2212 excelHelper.Export(clientsDataGridView); 2213 2212 2214 Cursor = Cursors.Default; 2213 2215 } 2214 2215 //private void dodajTytulButton_Click(object sender, EventArgs e)2216 //{2217 // if (kLIENCIBindingSource.Current == null) return;2218 2219 // if (tytulyListBox.SelectedValue == null)2220 // {2221 // MessageBox.Show("Wybierz tytu³.");2222 // return;2223 // }2224 2225 // DataRowView row = (DataRowView)kLIENCIBindingSource.Current;2226 // int custId = Int32.Parse(row["CustomerId"].ToString());2227 2228 // kLIENCI_TYTULTableAdapter.Insert(tytulyListBox.SelectedValue.ToString(), custId, User.Instance().Login, DateTime.Now);2229 // kLIENCI_TYTULTableAdapter.FillByCustomerId(rEKLAMADataSet.KLIENCI_TYTUL, custId);2230 2231 //}2232 2233 //private void usunTytulButton_Click(object sender, EventArgs e)2234 //{2235 // if (kLIENCITYTULBindingSource.Current != null)2236 // {2237 // if (kLIENCITYTULBindingSource.Current != null)2238 // {2239 // kLIENCITYTULBindingSource.RemoveCurrent();2240 // kLIENCI_TYTULTableAdapter.Update(rEKLAMADataSet.KLIENCI_TYTUL);2241 // }2242 // }2243 //}2244 2216 2245 2217 private void agencjaToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e)
