Ejemplo n.º 1
0
        public string ImportFile(IFormFile postedFiles)
        {
            string wwwPath     = this.Environment.WebRootPath;
            string contentPath = this.Environment.ContentRootPath;
            string path        = Path.Combine(this.Environment.WebRootPath, "Uploads");

            try
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileName = Path.GetFileName(postedFiles.FileName);
                using (FileStream stream = new FileStream(Path.Combine(path, fileName), FileMode.Create))
                {
                    postedFiles.CopyTo(stream);
                }
                string[] lines = System.IO.File.ReadAllLines(path + "/" + fileName);

                for (int i = 0; i < lines.Length; i++)
                {
                    string[]     cell = lines[i].Split(',');
                    Catalog_Data cd   = new Catalog_Data()
                    {
                        TagName     = cell[0].ToString(),
                        DeviceName  = cell[1].ToString(),
                        Unit        = cell[2].ToString(),
                        Address     = cell[3].ToString(),
                        WarnningMin = Convert.ToDouble(cell[4]),
                        WarnningMax = Convert.ToDouble(cell[5])
                    };
                    _context.Catalog_Datas.Add(cd);
                }
                _context.SaveChanges();


                return("success");
            }
            catch (Exception)
            {
                return("Lỗi tải file(chưa chọn file)");
            }
        }
Ejemplo n.º 2
0
 public bool CreateCatalog(string TagName, string deviceName, string Address, string Unit, string WarningMin, string WarningMax)
 {
     try
     {
         Catalog_Data cld = new Catalog_Data()
         {
             TagName     = TagName,
             DeviceName  = deviceName,
             Address     = Address,
             Unit        = Unit,
             WarnningMin = double.Parse(WarningMin),
             WarnningMax = double.Parse(WarningMax)
         };
         _context.Add(cld);
         _context.SaveChanges();
     }
     catch
     {
         return(false);
     }
     return(true);
 }