public ActionResult ExcellTest(FormCollection formCollection)
        {
            if (Request != null)
            {
                HttpPostedFileBase file = Request.Files["UploadedFile"];
                if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                {
                    string fileName        = file.FileName;
                    string fileContentType = file.ContentType;
                    byte[] fileBytes       = new byte[file.ContentLength];
                    var    data            = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));

                    using (var package = new ExcelPackage(file.InputStream))
                    {
                        var currentSheet = package.Workbook.Worksheets;
                        var workSheet    = currentSheet.First();
                        var noOfCol      = workSheet.Dimension.End.Column;
                        var noOfRow      = workSheet.Dimension.End.Row;
                        for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                        {
                            string[] Liste = new string[20];
                            for (int i = 2; i < 22; i++)
                            {
                                try
                                {
                                    Liste[i - 2] = workSheet.Cells[rowIterator, i].Value.ToString();
                                }
                                catch
                                {
                                    Liste[i - 2] = null;
                                }
                            }
                            UrunRepo.ExcelKaydet(Liste);
                        }
                    }
                }
            }
            return(View());
        }
示例#2
0
 public ActionResult DatabaseSystem(FormCollection formCollection)
 {
     if (Session["User"] != null && Session["Yetki"].ToString() == "Admin")
     {
         if (Request != null)
         {
             List <Urun>        urunler = new List <Urun>();
             HttpPostedFileBase file    = Request.Files["UploadedFile"];
             if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
             {
                 try
                 {
                     using (var package = new ExcelPackage(file.InputStream))
                     {
                         var currentSheet = package.Workbook.Worksheets;
                         var workSheet    = currentSheet.First();
                         int noOfRow      = workSheet.Dimension.End.Row;
                         for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                         {
                             urunler.Add(new Urun
                             {
                                 Marka       = (workSheet.Cells[rowIterator, 2].Value ?? String.Empty).ToString(),
                                 Model       = (workSheet.Cells[rowIterator, 3].Value ?? String.Empty).ToString(),
                                 SinifKodu   = (workSheet.Cells[rowIterator, 4].Value ?? String.Empty).ToString(),
                                 SinifTanimi = (workSheet.Cells[rowIterator, 5].Value ?? String.Empty).ToString(),
                                 MalzemeKodu = (workSheet.Cells[rowIterator, 6].Value ?? String.Empty).ToString(),
                                 Section1    = (workSheet.Cells[rowIterator, 7].Value ?? String.Empty).ToString(),
                                 Section2    = (workSheet.Cells[rowIterator, 8].Value ?? String.Empty).ToString(),
                                 Section3    = (workSheet.Cells[rowIterator, 9].Value ?? String.Empty).ToString(),
                                 Section4    = (workSheet.Cells[rowIterator, 10].Value ?? String.Empty).ToString(),
                                 Section5    = (workSheet.Cells[rowIterator, 11].Value ?? String.Empty).ToString(),
                                 Section6    = (workSheet.Cells[rowIterator, 12].Value ?? String.Empty).ToString(),
                                 Section7    = (workSheet.Cells[rowIterator, 13].Value ?? String.Empty).ToString(),
                                 Section8    = (workSheet.Cells[rowIterator, 14].Value ?? String.Empty).ToString(),
                                 Section9    = (workSheet.Cells[rowIterator, 15].Value ?? String.Empty).ToString(),
                                 Section10   = (workSheet.Cells[rowIterator, 16].Value ?? String.Empty).ToString(),
                                 Section11   = (workSheet.Cells[rowIterator, 17].Value ?? String.Empty).ToString(),
                                 Section12   = (workSheet.Cells[rowIterator, 18].Value ?? String.Empty).ToString(),
                                 Section13   = (workSheet.Cells[rowIterator, 19].Value ?? String.Empty).ToString(),
                                 Section14   = (workSheet.Cells[rowIterator, 20].Value ?? String.Empty).ToString(),
                                 Section15   = (workSheet.Cells[rowIterator, 21].Value ?? String.Empty).ToString()
                             });
                         }
                     }
                     bool sonuc = UrunRepo.ExcelKaydet(urunler);
                     if (sonuc == true)
                     {
                         TempData["UyariTipi"] = "panel panel-success";
                         TempData["Sonuc"]     = "Database Başarıyla Güncelleştirildi!";
                         return(View());
                     }
                     else
                     {
                         TempData["UyariTipi"] = "panel panel-danger";
                         TempData["Sonuc"]     = "Geçerli Bir Excel Dosyası Seçilmedi! Database Güncelleme Başarılı Olmadı!";
                         return(View());
                     }
                 }
                 catch
                 {
                     TempData["UyariTipi"] = "panel panel-danger";
                     TempData["Sonuc"]     = "Geçerli Bir Excel Dosyası Seçilmedi! Database Güncelleme Başarılı Olmadı!";
                     return(View());
                 }
             }
             else
             {
                 TempData["UyariTipi"] = "panel panel-warning";
                 TempData["Sonuc"]     = "Geçerli Dosyada Veri Yok yada Veri İçeren Bir Dosya Tipi Değil!";
                 return(View());
             }
         }
         else
         {
             TempData["UyariTipi"] = "panel panel-warning";
             TempData["Sonuc"]     = "Dosya Seçilmedi!";
             return(View());
         }
     }
     else
     {
         TempData["UyariTipi"] = "text-danger";
         TempData["Sonuc"]     = "Tarayıcıda Oturum Süreniz Dolmuş! Lütfen Tekrar Oturum Açın!";
         return(RedirectToAction("Logon", "Login"));
     }
 }