public void AddRecordFromCSV(string fileName)
        {
            using (StreamReader sr = new StreamReader(fileName))
            {
                try
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[]         resultArray;
                        PhatMinhGiaiPhap phatMinhGiaiPhap = new PhatMinhGiaiPhap();

                        Regex r = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");
                        resultArray = r.Split(line);
                        string           sohieupm = resultArray[0];
                        PhatMinhGiaiPhap checkpm  = db.PhatMinhGiaiPhaps.Where(p => p.SoHieuPM == sohieupm).FirstOrDefault();
                        if (checkpm == null)
                        {
                            //sohieupm,tenpm,motapm
                            phatMinhGiaiPhap.SoHieuPM = resultArray[0];
                            phatMinhGiaiPhap.TenPM    = resultArray[1];
                            phatMinhGiaiPhap.MotaPM   = resultArray[2];
                            db.PhatMinhGiaiPhaps.Add(phatMinhGiaiPhap);
                            db.SaveChanges();
                        }
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
        }
示例#2
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            PhatMinhGiaiPhap phatMinhGiaiPhap = await db.PhatMinhGiaiPhaps.FindAsync(id);

            db.PhatMinhGiaiPhaps.Remove(phatMinhGiaiPhap);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "MaPM,TenPM,SoHieuPM,MotaPM,DoiTuongSuDung,QuocGiaCap,LinkLienKet,NamCongBo,MotaPM")] PhatMinhGiaiPhap phatMinhGiaiPhap)
        {
            if (ModelState.IsValid)
            {
                db.Entry(phatMinhGiaiPhap).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(phatMinhGiaiPhap));
        }
示例#4
0
        // GET: PhatMinhGiaiPhaps/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PhatMinhGiaiPhap phatMinhGiaiPhap = await db.PhatMinhGiaiPhaps.FindAsync(id);

            if (phatMinhGiaiPhap == null)
            {
                return(HttpNotFound());
            }
            return(View(phatMinhGiaiPhap));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            PhatMinhGiaiPhap phatMinhGiaiPhap = await db.PhatMinhGiaiPhaps.FindAsync(id);

            db.PhatMinhGiaiPhaps.Remove(phatMinhGiaiPhap);

            List <DSPhatMinhNKH> dsPM_NKH = await db.DSPhatMinhNKHs.Where(p => p.MaPM == id).ToListAsync();

            foreach (var tacgia in dsPM_NKH)
            {
                db.DSPhatMinhNKHs.Remove(tacgia);
            }

            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
示例#6
0
        public async Task <ActionResult> GetAllImage(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PhatMinhGiaiPhap phatMinhGiaiPhap = await db.PhatMinhGiaiPhaps.FindAsync(id);

            if (phatMinhGiaiPhap == null)
            {
                return(HttpNotFound());
            }
            List <ImageViewModel> lstImage = new List <ImageViewModel>
            {
                new ImageViewModel(phatMinhGiaiPhap.AnhChupSanPham1),
                new ImageViewModel(phatMinhGiaiPhap.AnhChupSanPham2),
                new ImageViewModel(phatMinhGiaiPhap.AnhScanGiayChungNhan)
            };

            return(View(lstImage));
        }
        public async Task <ActionResult> Create([Bind(Include = "MaPM,TenPM,SoHieuPM,MotaPM,DoiTuongSuDung,QuocGiaCap,LinkLienKet,NamCongBo,MotaPM")] PhatMinhGiaiPhap phatMinhGiaiPhap, int MaChuSoHuu)
        {
            if (ModelState.IsValid)
            {
                db.PhatMinhGiaiPhaps.Add(phatMinhGiaiPhap);
                await db.SaveChangesAsync();

                DSPhatMinhNKH dSPhatMinhNKH = new DSPhatMinhNKH
                {
                    MaNKH      = MaChuSoHuu,
                    MaPM       = phatMinhGiaiPhap.MaPM,
                    LaChuSoHuu = true
                };

                db.DSPhatMinhNKHs.Add(dSPhatMinhNKH);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(phatMinhGiaiPhap));
        }
示例#8
0
        // GET: PhatMinhGiaiPhaps/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PhatMinhGiaiPhap phatMinhGiaiPhap = await db.PhatMinhGiaiPhaps.FindAsync(id);

            if (phatMinhGiaiPhap == null)
            {
                return(HttpNotFound());
            }
            var lstAllNKH = db.NhaKhoaHocs.Where(p => p.MaNKH != 1).Select(p => new
            {
                p.MaNKH,
                TenNKH = p.HoNKH + " " + p.TenNKH
            }).ToList();

            var lstNKH = db.NhaKhoaHocs.Where(p => p.DSPhatMinhNKHs.Any(d => d.MaPM == phatMinhGiaiPhap.MaPM && d.LaChuSoHuu == false)).Select(p => p.MaNKH).ToList();

            ViewBag.DSPhatMinhNKH = new MultiSelectList(lstAllNKH, "MaNKH", "TenNKH", lstNKH);

            return(View(phatMinhGiaiPhap));
        }
示例#9
0
        public async Task <ActionResult> Edit(HttpPostedFileBase anhChup1, HttpPostedFileBase anhChup2, HttpPostedFileBase anhGiayChungNhan, List <string> DSPhatMinhNKH, [Bind(Include = "MaPM,TenPM,SoHieuPM,MotaPM,DoiTuongSuDung,QuocGiaCap,LinkLienKet,NamCongBo,AnhScanGiayChungNhan,AnhChupSanPham1,AnhChupSanPham2")] PhatMinhGiaiPhap phatMinhGiaiPhap)
        {
            if (ModelState.IsValid)
            {
                db.Entry(phatMinhGiaiPhap).State = EntityState.Modified;
                if (QLKHrepo.HasFile(anhChup1))
                {
                    string mimeType   = anhChup1.ContentType;
                    Stream fileStream = anhChup1.InputStream;
                    string fileName   = Path.GetFileName(anhChup1.FileName);
                    int    fileLength = anhChup1.ContentLength;
                    byte[] fileData   = new byte[fileLength];
                    fileStream.Read(fileData, 0, fileLength);
                    phatMinhGiaiPhap.AnhChupSanPham1 = fileData;
                }
                if (QLKHrepo.HasFile(anhChup2))
                {
                    string mimeType   = anhChup2.ContentType;
                    Stream fileStream = anhChup2.InputStream;
                    string fileName   = Path.GetFileName(anhChup2.FileName);
                    int    fileLength = anhChup2.ContentLength;
                    byte[] fileData   = new byte[fileLength];
                    fileStream.Read(fileData, 0, fileLength);
                    phatMinhGiaiPhap.AnhChupSanPham2 = fileData;
                }
                if (QLKHrepo.HasFile(anhGiayChungNhan))
                {
                    string mimeType   = anhGiayChungNhan.ContentType;
                    Stream fileStream = anhGiayChungNhan.InputStream;
                    string fileName   = Path.GetFileName(anhGiayChungNhan.FileName);
                    int    fileLength = anhGiayChungNhan.ContentLength;
                    byte[] fileData   = new byte[fileLength];
                    fileStream.Read(fileData, 0, fileLength);
                    phatMinhGiaiPhap.AnhScanGiayChungNhan = fileData;
                }
                if (DSPhatMinhNKH != null)
                {
                    foreach (var mankh in DSPhatMinhNKH)
                    {
                        DSPhatMinhNKH dSPhatMinhNKH = new DSPhatMinhNKH
                        {
                            LaChuSoHuu = false,
                            MaPM       = phatMinhGiaiPhap.MaPM,
                            MaNKH      = Int32.Parse(mankh)
                        };
                        db.DSPhatMinhNKHs.AddOrUpdate(dSPhatMinhNKH);
                    }
                }
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            var lstAllNKH = db.NhaKhoaHocs.Where(p => p.MaNKH != 1).Select(p => new
            {
                p.MaNKH,
                TenNKH = p.HoNKH + " " + p.TenNKH
            }).ToList();

            var lstNKH = db.NhaKhoaHocs.Where(p => p.DSPhatMinhNKHs.Any(d => d.MaPM == phatMinhGiaiPhap.MaPM && d.LaChuSoHuu == false)).Select(p => p.MaNKH).ToList();

            ViewBag.DSPhatMinhNKH = new MultiSelectList(lstAllNKH, "MaNKH", "TenNKH", lstNKH);
            return(View(phatMinhGiaiPhap));
        }
示例#10
0
        public async Task <ActionResult> Create(HttpPostedFileBase anhChup1, HttpPostedFileBase anhChup2, HttpPostedFileBase anhGiayChungNhan, List <string> DSPhatMinhNKH, [Bind(Include = "MaPM,TenPM,SoHieuPM,MotaPM,DoiTuongSuDung,QuocGiaCap,LinkLienKet,NamCongBo,AnhScanGiayChungNhan,AnhChupSanPham1,AnhChupSanPham2")] PhatMinhGiaiPhap phatMinhGiaiPhap)
        {
            if (ModelState.IsValid)
            {
                if (QLKHrepo.HasFile(anhChup1))
                {
                    string mimeType   = anhChup1.ContentType;
                    Stream fileStream = anhChup1.InputStream;
                    string fileName   = Path.GetFileName(anhChup1.FileName);
                    int    fileLength = anhChup1.ContentLength;
                    byte[] fileData   = new byte[fileLength];
                    fileStream.Read(fileData, 0, fileLength);
                    phatMinhGiaiPhap.AnhChupSanPham1 = fileData;
                }
                if (QLKHrepo.HasFile(anhChup2))
                {
                    string mimeType   = anhChup2.ContentType;
                    Stream fileStream = anhChup2.InputStream;
                    string fileName   = Path.GetFileName(anhChup2.FileName);
                    int    fileLength = anhChup2.ContentLength;
                    byte[] fileData   = new byte[fileLength];
                    fileStream.Read(fileData, 0, fileLength);
                    phatMinhGiaiPhap.AnhChupSanPham2 = fileData;
                }
                if (QLKHrepo.HasFile(anhGiayChungNhan))
                {
                    string mimeType   = anhGiayChungNhan.ContentType;
                    Stream fileStream = anhGiayChungNhan.InputStream;
                    string fileName   = Path.GetFileName(anhGiayChungNhan.FileName);
                    int    fileLength = anhGiayChungNhan.ContentLength;
                    byte[] fileData   = new byte[fileLength];
                    fileStream.Read(fileData, 0, fileLength);
                    phatMinhGiaiPhap.AnhScanGiayChungNhan = fileData;
                }
                db.PhatMinhGiaiPhaps.Add(phatMinhGiaiPhap);

                var id = phatMinhGiaiPhap.MaPM;
                UserLoginViewModel user = (UserLoginViewModel)Session["user"];
                db.DSPhatMinhNKHs.Add(new DSPhatMinhNKH
                {
                    LaChuSoHuu = true,
                    MaPM       = id,
                    MaNKH      = user.MaNKH
                });

                if (DSPhatMinhNKH != null)
                {
                    List <DSPhatMinhNKH> ds = new List <DSPhatMinhNKH>();
                    foreach (var mankh in DSPhatMinhNKH)
                    {
                        ds.Add(new DSPhatMinhNKH
                        {
                            LaChuSoHuu = false,
                            MaPM       = id,
                            MaNKH      = Int32.Parse(mankh)
                        });
                    }
                    db.DSPhatMinhNKHs.AddRange(ds);
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var lstAllNKH = db.NhaKhoaHocs.Where(p => p.MaNKH != 1).Select(p => new
            {
                p.MaNKH,
                TenNKH = p.HoNKH + " " + p.TenNKH
            }).ToList();

            ViewBag.DSPhatMinhNKH = new MultiSelectList(lstAllNKH, "MaNKH", "TenNKH");

            return(View(phatMinhGiaiPhap));
        }