Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void barButtonItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- GetList(dt);
- Nowy(list); //TUTAJ JUZ JEST NULL
- }
- private void barButtonItem9_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- ReadCsv();
- }
- public void ReadCsv()
- {
- System.IO.Stream myStream = null;
- //TWORZENIE TABELI NADANIE NAZW KOLUMNOWM
- System.Data.DataTable table = new System.Data.DataTable("produkt");
- table.Columns.Add("ST", typeof(String));
- table.Columns.Add("GE", typeof(String));
- table.Columns.Add("Boxes", typeof(String));
- table.Columns.Add("ManufDate", typeof(String));
- table.Columns.Add("ManufNumber", typeof(String));
- table.Columns.Add("Expireddate", typeof(String));
- table.Columns.Add("FROM", typeof(String));
- table.Columns.Add("TO", typeof(String));
- // ROZPOCZECIE ODCZYTU PLIKu
- //TWORZENIE OBIEKTU OKNA DO WYBORU PLIKU
- OpenFileDialog ofd = new OpenFileDialog();
- //USTAWIENIA FILTROWANIA PLIKOW
- ofd.InitialDirectory = "c:\\";
- ofd.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm;*.txt;*.csv";
- ofd.FilterIndex = 2;
- ofd.Multiselect = false;
- // IEnumerable<Order> records;
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- try
- {
- if ((myStream = ofd.OpenFile()) != null)
- using (myStream = ofd.OpenFile())
- {
- fileLocation = ofd.FileName;
- // StreamReader reader = new StreamReader(myStream,Encoding.Default, true);
- IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(myStream);
- //// reader.IsFirstRowAsColumnNames
- var conf = new ExcelDataSetConfiguration
- {
- ConfigureDataTable = _ => new ExcelDataTableConfiguration
- {
- EmptyColumnNamePrefix = "duppppppp",
- FilterRow = rowReader => rowReader.Depth > 1,
- UseHeaderRow = true,
- ReadHeaderRow = (rowReader) =>
- {
- // F.ex skip the first row and use the 2nd row as column headers:
- rowReader.Read();
- },
- }
- };
- var dataSet = excelReader.AsDataSet(conf);
- table = dataSet.Tables[0];
- gridControl1.DataSource = table;
- //...
- }
- }
- catch (FileNotFoundException)
- {
- MessageBox.Show("FileNotFoundException");
- }
- catch (IOException)
- {
- MessageBox.Show("IOException");
- }
- catch (OutOfMemoryException)
- {
- MessageBox.Show("OutOfMemoryException");
- }
- finally
- {
- dt = table;
- }
- }
- }
- public static List<Order> GetList(System.Data.DataTable dt)
- {
- //List<Order> list = dt.AsEnumerable().Select(x => new Order
- //{
- // ST = (string)(x["ST"]),
- // GE =(string)(x["GE"]),
- // Boxes = (string)(x["Boxes"]),
- // ManufDate = (string)(x["ManufDate"]),
- // ManufNumber = (string)(x["ManufNumber"]),
- // Expireddate = (string)(x["Expireddate"]),
- // From = (string)(x["FROM"]),
- // To = (string)(x["TO"]),
- //}).ToList();
- List<Order> list = new List<Order>();
- foreach (DataRow row in dt.Rows
- {
- ///Pokazuja sie wczytywane wartosci
- Order item = new Order();
- item.ST = row[0].ToString().TrimStart('S', 'T');
- item.GE = row[1].ToString();
- item.Boxes = row[2].ToString();
- item.ManufDate = row[3].ToString();
- item.ManufNumber = row[4].ToString();
- item.Expireddate = row[5].ToString();
- item.From = row[6].ToString();
- item.To = row[7].ToString();
- list.Add(item);
- }
- return list; //Zlicza i podaje count =36
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement