public void getExcel() { pozItems = new List <Poz>(); OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Excel Files(*.xls;*.xlsx)|*.xls;*.xlsx"; if (dialog.ShowDialog() == DialogResult.OK) { DialogResult result = MessageBox.Show("Yüklemek istediğinizden emin misiniz?", "Yükleme Dosya içeriğine göre biraz zaman alabilir", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result.Equals(DialogResult.Yes)) { try { pnlYuke.Visible = false; string filename = System.IO.Path.GetFileName(dialog.FileName); FileStream stream = System.IO.File.Open(dialog.FileName, FileMode.Open, FileAccess.Read); IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); int i = 0; while (excelReader.Read()) { if (i > 0) { string pozno = string.Empty; try { pozno = excelReader.GetString(0); } catch (Exception ex) { double poznodouble = excelReader.GetDouble(0); pozno = poznodouble.ToString(); //LoggingManager.Instance.SaveErrorLog(ex); } string description = excelReader.GetString(1); string unit = excelReader.GetString(2); double unitprice = 0; try { unitprice = excelReader.GetDouble(3); } catch (Exception ex) { //LoggingManager.Instance.SaveErrorLog(ex); } if (!string.IsNullOrEmpty(pozno) && !string.IsNullOrEmpty(description) && !string.IsNullOrEmpty(unit)) { List <PozModel> existingPozs = UIPozManager.Instance.GetPozs(pozno, description); if (existingPozs != null && existingPozs.Count != 0) { listBox1.Items.Add(existingPozs.First().Number); listBox1.Items.Add(existingPozs.First().Description); listBox1.Items.Add(existingPozs.First().Unit); listBox1.Items.Add(existingPozs.First().UnitPrice); } else { Poz poz = new Poz(); poz.Number = pozno; poz.Description = description; poz.Unit = unit; poz.UnitPrice = unitprice; poz.Year = DateTime.Now.Year; poz.IsActive = true; Application.DoEvents(); lblPosSayisi.Text = i.ToString(); pozItems.Add(poz); listBox1.Items.Add(poz.Number); listBox1.Items.Add(poz.Description); listBox1.Items.Add(poz.Unit); listBox1.Items.Add(poz.UnitPrice); } listBox1.Items.Add("-------------------------------------------------------------"); listBox1.TopIndex = listBox1.Items.Count - 1; } } i++; } if (pozItems == null || pozItems.Count == 0) { pnlYuke.Visible = false; MessageBox.Show("Yüklenecek yeni poz bulunamadı."); this.Close(); return; } LoadingManager.Instance.Hide(); this.Hide(); frm_TopluPozTemp pozTemp = new frm_TopluPozTemp(this._owner); pozTemp.pozItems = pozItems; pozTemp.ShowDialog(); frm_MesajFormu mesaj = new frm_MesajFormu(); mesaj.lblMesaj.Text = "Pozlar başarıyla yüklendi..."; mesaj.Close(); } catch (Exception ex) { LoadingManager.Instance.Hide(); pnlYuke.Visible = true; MessageBox.Show("Beklenmedik bir sorunla karşılaşıldı.."); } } else { pnlYuke.Visible = true; } } }
private void ReadExcel(string path) { obfItems = new List <IhalematikProBL.Entity.OBF>(); try { pnlYuke.Visible = false; FileStream stream = System.IO.File.Open(@"" + path + "", FileMode.Open, FileAccess.Read); IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); int i = 0; while (excelReader.Read()) { Application.DoEvents(); try { if (i > 0) { string stokKodu = string.Empty; try { stokKodu = excelReader.GetString(0); } catch (Exception ex) { double stokKodudouble = excelReader.GetDouble(0); stokKodu = stokKodudouble.ToString(); //LoggingManager.Instance.SaveErrorLog(ex); } string description = excelReader.GetString(1); string unit = excelReader.GetString(2); double unitPrice = 0; try { unitPrice = excelReader.GetDouble(3); } catch (Exception) { //unitPrice = double.Parse(excelReader.GetString(2), CultureInfo.InvariantCulture); } //IhalematikProBL.Entity.OBF existingObf = OBFProvider.Instance.GetOne("Description", description); //if (existingObf != null) //{ // existingObf.UnitPrice = unitPrice; // OBFProvider.Instance.Save(existingObf); //} //else //{ if (!string.IsNullOrEmpty(stokKodu) && !string.IsNullOrEmpty(description) && !string.IsNullOrEmpty(unit)) { IhalematikProBL.Entity.OBF existingObf = OBFProvider.Instance.GetOne("Description", description); if (existingObf != null) { listBox1.Items.Add(existingObf.Number); listBox1.Items.Add(existingObf.Description); listBox1.Items.Add(existingObf.Unit); listBox1.Items.Add(existingObf.UnitPrice); //OBFProvider.Instance.Save(existingObf); } else { IhalematikProBL.Entity.OBF newOBF = new IhalematikProBL.Entity.OBF(); int lastTenderNumber = UIOBFManager.Instance.GetLastOBFNumber(); newOBF.Number = string.Format("{0}", (lastTenderNumber + 1).ToString().PadLeft(8, '0')); newOBF.IsActive = true; newOBF.StokNumber = stokKodu; newOBF.Description = description; newOBF.Unit = unit; newOBF.UnitPrice = unitPrice; Application.DoEvents(); lblPosSayisi.Text = i.ToString(); obfItems.Add(newOBF); listBox1.Items.Add(newOBF.Number); listBox1.Items.Add(newOBF.Description); listBox1.Items.Add(newOBF.Unit); listBox1.Items.Add(newOBF.UnitPrice); } listBox1.Items.Add("-------------------------------------------------------------"); listBox1.TopIndex = listBox1.Items.Count - 1; } //OBFProvider.Instance.Save(newOBF); //} } } catch (Exception ex) { pnlYuke.Visible = true; MessageBox.Show("Yuklediğiniz excel in formatını kontrol ediniz."); LoggingManager.Instance.SaveErrorLog(ex); this.Close(); break; } i++; } if (this.obfItems == null || this.obfItems.Count == 0) { pnlYuke.Visible = false; MessageBox.Show("Yüklemeye çalıştığınız tüm malzemelerin sitemde yüklü oldukları tespit edildi.\nDoğru dosyayı seçtiğinize dikkat ediniz."); return; this.Close(); } stream.Close(); frm_MesajFormu mesaj = new frm_MesajFormu(); mesaj.lblMesaj.Text = "Malzemeler başarıyla yüklendi..."; mesaj.Close(); } catch (Exception) { pnlYuke.Visible = true; MessageBox.Show("Yuklediğiniz excel in formatını kontrol ediniz.\n Yuklemeye calistiginiz excel dosyasi en az office 2010 ile olusturulmus olmasi gerekmektedir.\n Excel in kapali oldugundan emin olunuz"); } }
public void getExcel() { materialListItems = new List <MaterialList>(); OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Excel Files(*.xls;*.xlsx)|*.xls;*.xlsx"; if (dialog.ShowDialog() == DialogResult.OK) { DialogResult result = MessageBox.Show("Yüklemek istediğinizden emin misiniz?", "Yükleme Dosya içeriğine göre biraz zaman alabilir", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result.Equals(DialogResult.Yes)) { try { pnlYuke.Visible = false; string filename = System.IO.Path.GetFileName(dialog.FileName); FileStream stream = System.IO.File.Open(dialog.FileName, FileMode.Open, FileAccess.Read); IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); int i = 0; while (excelReader.Read()) { if (i > 0) { int pozId = 0; string pozno = string.Empty; try { pozno = excelReader.GetString(0); } catch (Exception ex) { double poznodouble = excelReader.GetDouble(0); pozno = poznodouble.ToString(); } string description = excelReader.GetString(1); string unit = excelReader.GetString(2); if (!string.IsNullOrEmpty(pozno) && !string.IsNullOrEmpty(description)) { List <Poz> existingPozs = UIPozManager.Instance.GetExistingPozs(pozno, description); if (existingPozs != null && existingPozs.Count != 0) { //poz = existingPozs.First(); pozId = existingPozs.First().Id; listBox1.Items.Add(existingPozs.First().Number); listBox1.Items.Add(existingPozs.First().Description); listBox1.Items.Add(existingPozs.First().Unit); lblPosSayisi.Text = i.ToString(); } else { Poz poz = new Poz(); poz.Number = pozno; poz.Description = description; poz.Unit = unit; poz.UnitPrice = 0; poz.Year = DateTime.Now.Year; poz.IsActive = true; PozProvider.Instance.Save(poz); pozId = poz.Id; lblPosSayisi.Text = i.ToString(); listBox1.Items.Add(poz.Number); listBox1.Items.Add(poz.Description); listBox1.Items.Add(poz.Unit); } double quantity = 0; try { quantity = excelReader.GetDouble(3); } catch (Exception ex) { } listBox1.Items.Add(quantity.ToString()); listBox1.Items.Add("-------------------------------------------------------------"); listBox1.TopIndex = listBox1.Items.Count - 1; if (pozId != 0) { MaterialList materialList = new MaterialList(); materialList.IsPoz = true; materialList.PozOBFId = pozId; materialList.Quantity = (float)quantity; materialList.KDVPercentage = 18; materialList.Tender = UICurrentManager.Instance.CurrentTender; materialList.TenderGroupId = this._owner.SelectedGroupId; materialListItems.Add(materialList); } } } i++; } stream.Close(); this.Hide(); if (this.materialListItems == null || this.materialListItems.Count == 0) { pnlYuke.Visible = true; MessageBox.Show("Yüklenecek Poz bulunamadı."); this.Close(); return; } frm_TopluPozIhaleTemp pozTemp = new frm_TopluPozIhaleTemp(this._owner); pozTemp.MaterialListItems = materialListItems; pozTemp.ShowDialog(); frm_MesajFormu mesaj = new frm_MesajFormu(); mesaj.lblMesaj.Text = "Pozlar başarıyla yüklendi..."; mesaj.Close(); } catch (Exception ex) { pnlYuke.Visible = true; MessageBox.Show("Beklenmedik bir sorunla karşılaşıldı.."); } } else { pnlYuke.Visible = true; } } }
private void ReadExcel(string path) { materialListItems = new List <MaterialList>(); // obfItems = new List<IhalematikProBL.Entity.OBF>(); try { FileStream stream = System.IO.File.Open(@"" + path + "", FileMode.Open, FileAccess.Read); IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); int i = 0; while (excelReader.Read()) { try { if (i > 0) { int obfId = 0; string stokKodu = string.Empty; try { stokKodu = excelReader.GetString(0); } catch (Exception ex) { double stokKodudouble = excelReader.GetDouble(0); stokKodu = stokKodudouble.ToString(); } string description = excelReader.GetString(1); if (!string.IsNullOrEmpty(stokKodu) && !string.IsNullOrEmpty(description)) { string unit = excelReader.GetString(2); IhalematikProBL.Entity.OBF existingObf = OBFProvider.Instance.GetOne("Description", description); if (existingObf != null) { obfId = existingObf.Id; lblPosSayisi.Text = i.ToString(); listBox1.Items.Add(existingObf.Number); listBox1.Items.Add(existingObf.Description); listBox1.Items.Add(existingObf.Unit); //OBFProvider.Instance.Save(existingObf); } else { IhalematikProBL.Entity.OBF obf = new IhalematikProBL.Entity.OBF(); int lastTenderNumber = UIOBFManager.Instance.GetLastOBFNumber(); obf.Number = string.Format("{0}", (lastTenderNumber + 1).ToString().PadLeft(8, '0')); obf.StokNumber = stokKodu; obf.Description = description; obf.Unit = unit; obf.UnitPrice = 0; obf.IsActive = true; OBFProvider.Instance.Save(obf); obfId = obf.Id; lblPosSayisi.Text = i.ToString(); listBox1.Items.Add(obf.Number); listBox1.Items.Add(obf.Description); listBox1.Items.Add(obf.Unit); } double quantity = 0; try { quantity = excelReader.GetDouble(3); } catch (Exception ex) { } listBox1.Items.Add(quantity.ToString()); listBox1.Items.Add("-------------------------------------------------------------"); listBox1.TopIndex = listBox1.Items.Count - 1; if (obfId != 0) { MaterialList materialList = new MaterialList(); materialList.IsPoz = false; materialList.PozOBFId = obfId; materialList.Quantity = (float)quantity; materialList.KDVPercentage = 18; materialList.Tender = UICurrentManager.Instance.CurrentTender; materialList.TenderGroupId = this._owner.SelectedGroupId; materialListItems.Add(materialList); } } } i++; } catch (Exception ex) { pnlYukle.Visible = true; MessageBox.Show("Yuklediğiniz excel in formatını kontrol ediniz."); LoggingManager.Instance.SaveErrorLog(ex); this.Close(); break; } } stream.Close(); this.Hide(); if (this.materialListItems == null || this.materialListItems.Count == 0) { pnlYukle.Visible = false; MessageBox.Show("Yüklenecek OBF bulunamadı."); this.Close(); return; } frm_TopluObfYukleIhaleTemp pozTemp = new frm_TopluObfYukleIhaleTemp(this._owner); pozTemp.MaterialListItems = materialListItems; pozTemp.ShowDialog(); frm_MesajFormu mesaj = new frm_MesajFormu(); mesaj.lblMesaj.Text = "OBFler başarıyla yüklendi..."; mesaj.Close(); } catch (Exception) { pnlYukle.Visible = true; MessageBox.Show("Yuklediğiniz excel in formatını kontrol ediniz.\n Yuklemeye calistiginiz excel dosyasi en az office 2010 ile olusturulmus olmasi gerekmektedir.\n Excel in kapali oldugundan emin olunuz"); } }