private void ButtonUlozenka(object sender, EventArgs e) { ExportedBoxesCounter = 0; StringBuilder builder = new StringBuilder(); StringBuilder builderExpedovani = new StringBuilder(); string DefaultFileName = DateTime.Today.ToString("d.M.yy") + " Ulozenka.csv"; string DefaultFileExpedovaniName = DateTime.Today.ToString("d.M.yy") + " UlozenkaExpedovani.csv"; SaveFileDialog sfd = SaveFile(DefaultFileName); sfd.Dispose(); if (sfd.ShowDialog() == DialogResult.OK) { pathUlozenka = sfd.FileName; pathUlozenka.Replace("/", ""); string pathUlozenkaExpedovani = pathUlozenka.Substring(0, pathUlozenka.Length - 4) + "Expedovani.csv"; writer = new StreamWriter(pathUlozenka); writerExpedovani = new StreamWriter(pathUlozenkaExpedovani); objednavky obj = new objednavky(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[1].Value) == true && dataGridView1.Rows[i].Cells[2].Value.ToString().Contains("Ulož") == true) { ExportedBoxesCounter++; string NObjednavky = dataGridView1.Rows[i].Cells[0].Value.ToString(); string Cena = dataGridView1.Rows[i].Cells[3].Value.ToString(); string Dobirka = dataGridView1.Rows[i].Cells[4].Value.ToString(); string Firma = dataGridView1.Rows[i].Cells[5].Value.ToString(); string Jmeno = obj.NameSurname(dataGridView1.Rows[i].Cells[6].Value.ToString())[0]; string Prijmeni = obj.NameSurname(dataGridView1.Rows[i].Cells[6].Value.ToString())[1]; string Telefon = dataGridView1.Rows[i].Cells[13].Value.ToString(); string Email = dataGridView1.Rows[i].Cells[14].Value.ToString(); string Doprava = obj.UlozenkaCode(dataGridView1.Rows[i].Cells[2].Value.ToString()); finalLine = builder.Append(NObjednavky + ';' + Cena + ';' + Dobirka + ';' + Jmeno + ';' + Prijmeni + ';' + Telefon + ';' + Email + ';' + Doprava + ";\n").ToString(); mainTableAdapter.DeleteQuery(Convert.ToInt32(NObjednavky)); finalLineExpedovani = builderExpedovani.Append(NObjednavky + ";\n").ToString(); } } MessageBox.Show(ExportedBoxesCounter + " packages exported"); if (String.IsNullOrWhiteSpace(finalLine)) { MessageBox.Show("No checked packages found"); } else { finalLine = finalLine.Substring(0, finalLine.Length - 2); /*uziznem posledni \n*/ writerExpedovani.WriteLine(finalLineExpedovani); writer.WriteLine(finalLine); writerExpedovani.Close(); writer.Close(); } this.mainTableAdapter.Fill(this.localDatabaseDataSet.Main); } }
private void Import(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Csv files (*.csv) | *.csv;"; if (ofd.ShowDialog() == DialogResult.OK) { CSVPath = ofd.FileName; } ofd.Dispose(); try { StreamReader readerCSV = new StreamReader(File.OpenRead(CSVPath), Encoding.GetEncoding(1250)); while (!readerCSV.EndOfStream) { this.progressBar1.Increment(1); string[] hodnoty = readerCSV.ReadLine().Split(';'); if (hodnoty.Length > 15) { if (hodnoty[15] == "P") { hodnoty = RemoveLastInArray(hodnoty, 15); } if (hodnoty.Length > 15) { hodnoty = RemoveArray(14, hodnoty); } } objednavky obj = new objednavky(); if (hodnoty[13].Contains("Uloženka") || hodnoty[13].Contains("PPL")) { obj.CObjednavky = hodnoty[0]; obj.Cena = hodnoty[1]; obj.Dobirka = hodnoty[2]; obj.Firma = hodnoty[3]; obj.Jmeno = hodnoty[4]; obj.Adresa = hodnoty[5]; obj.PSC = hodnoty[6]; obj.Mesto = hodnoty[7]; obj.Vaha = hodnoty[8]; obj.Sluzby = hodnoty[9]; obj.VSymbol = hodnoty[10]; obj.Telefon = obj.minus420(hodnoty[11]); obj.Emal = hodnoty[12]; obj.Doprava = hodnoty[13]; obj.Vzkaz = hodnoty[14]; obj.Stav = false; if (LookForDublicates(obj.CObjednavky) == true) { continue; } mainTableAdapter.Insert(Convert.ToInt32(obj.CObjednavky), obj.Stav, obj.Cena, obj.Dobirka, obj.Firma, obj.Jmeno, obj.Adresa, obj.PSC, obj.Mesto, obj.Vaha, obj.Sluzby, obj.VSymbol, obj.Telefon, obj.Emal, obj.Doprava, obj.Vzkaz); } } this.mainTableAdapter.Fill(this.localDatabaseDataSet.Main); DubbleBuffer(); MesseagePainter(); this.progressBar1.Increment(100); MessageBox.Show("Data loaded"); this.progressBar1.Value = 0; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void Import(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Csv files (*.csv) | *.csv;"; if (ofd.ShowDialog() == DialogResult.OK) CSVPath = ofd.FileName; ofd.Dispose(); try { StreamReader readerCSV = new StreamReader(File.OpenRead(CSVPath), Encoding.GetEncoding(1250)); while (!readerCSV.EndOfStream) { this.progressBar1.Increment(1); string[] hodnoty = readerCSV.ReadLine().Split(';'); if (hodnoty.Length > 15) { if (hodnoty[15] == "P") hodnoty = RemoveLastInArray(hodnoty, 15); if (hodnoty.Length > 15) hodnoty = RemoveArray(14, hodnoty); } objednavky obj = new objednavky(); if (hodnoty[13].Contains("Uloženka") || hodnoty[13].Contains("PPL")) { obj.CObjednavky = hodnoty[0]; obj.Cena = hodnoty[1]; obj.Dobirka = hodnoty[2]; obj.Firma = hodnoty[3]; obj.Jmeno = hodnoty[4]; obj.Adresa = hodnoty[5]; obj.PSC = hodnoty[6]; obj.Mesto = hodnoty[7]; obj.Vaha = hodnoty[8]; obj.Sluzby = hodnoty[9]; obj.VSymbol = hodnoty[10]; obj.Telefon = obj.minus420(hodnoty[11]); obj.Emal = hodnoty[12]; obj.Doprava = hodnoty[13]; obj.Vzkaz = hodnoty[14]; obj.Stav = false; if (LookForDublicates(obj.CObjednavky) == true) continue; mainTableAdapter.Insert(Convert.ToInt32(obj.CObjednavky), obj.Stav, obj.Cena, obj.Dobirka, obj.Firma, obj.Jmeno, obj.Adresa, obj.PSC, obj.Mesto, obj.Vaha, obj.Sluzby, obj.VSymbol, obj.Telefon, obj.Emal, obj.Doprava, obj.Vzkaz); } } this.mainTableAdapter.Fill(this.localDatabaseDataSet.Main); DubbleBuffer(); MesseagePainter(); this.progressBar1.Increment(100); MessageBox.Show("Data loaded"); this.progressBar1.Value = 0; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }