public static void InsertListThietBi(int maPhieuNhap, int[] maLoai, int[] soLuong) { using (Context context = new Context()) { int maLoaiLength = maLoai.Length; int increase = 1; for (int i = 0; i < maLoaiLength; i++) { PhieuNhap phieuNhap = (from p in context.PhieuNhap where p.MaPhieuNhap == maPhieuNhap select p).FirstOrDefault(); for (int j = 0; j < soLuong[i]; j++) { //ThietBi t = InsertThietBi(maLoai[i]); ThietBi thietBi = new ThietBi(); thietBi.MaThietBi = SelectLastMaThietBi() + increase++; thietBi.MaLoai = maLoai[i]; thietBi.NgayDuaVaoSuDung = null; thietBi.TinhTrang = 0; phieuNhap.ThietBi.Add(thietBi); } context.SaveChanges(); } } }
public static void InsertChiTietPhieuGiaoNhan(int maPhieuGiaoNhan, int[] maThietBi, int[] tinhTrang) { using (Context context = new Context()) { for (int i = 0; i < maThietBi.Length; i++) { ChiTietPhieuGiaoNhan ct = new ChiTietPhieuGiaoNhan(maPhieuGiaoNhan, maThietBi[i], tinhTrang[i]); context.ChiTietPhieuGiaoNhan.Add(ct); ThietBi tb = context.ThietBi.Find(maThietBi[i]); tb.TinhTrang = tinhTrang[i]; } context.SaveChanges(); } }
public static ThietBi InsertThietBi(int maLoai) { using (Context context = new Context()) { ThietBi thietBi = new ThietBi(); thietBi.MaThietBi = SelectLastMaThietBi() + 1; thietBi.MaLoai = maLoai; thietBi.NgayDuaVaoSuDung = null; thietBi.TinhTrang = 0; context.ThietBi.Add(thietBi); context.SaveChanges(); return(thietBi); } }
public static List <ThietBi> ThongKeTheoLoai(string tenLoai, string date) { using (Context context = new Context()) { List <ThietBi> result = new List <ThietBi>(); List <ThietBi> listThietBi = new List <ThietBi>(); int maLoai = GetMaLoai(tenLoai); DateTime time = Convert.ToDateTime(date); List <PhieuNhap> listPhieuNhap = (from l in context.PhieuNhap where l.NgayNhap <= time select l).ToList(); foreach (PhieuNhap phieuNhap in listPhieuNhap) { listThietBi.AddRange(phieuNhap.ThietBi); } foreach (ThietBi tb in listThietBi) { if (tb.MaLoai != maLoai) { continue; } ThietBi temp = new ThietBi(); temp.MaThietBi = tb.MaThietBi; temp.NgayDuaVaoSuDung = tb.NgayDuaVaoSuDung; temp.MaLoai = maLoai; ChiTietPhieuGiaoNhan ct = (from l in context.ChiTietPhieuGiaoNhan join c in context.PhieuGiaoNhan on l.MaPhieuGiaoNhan equals c.MaPhieuGiaoNhan where c.NgayGiaoNhan <= time where l.MaThietBi == tb.MaThietBi orderby c.NgayGiaoNhan descending select l).FirstOrDefault(); if (ct == null) { temp.TinhTrang = 0; } else { temp.TinhTrang = ct.TinhTrang ?? default(int); } result.Add(temp); } return(result); } }
public static List <ThietBi> ThongKeTheoLoai(string tenLoai, string date) { using (Context context = new Context()) { int maLoai = getMaLoai(tenLoai); DateTime time = Convert.ToDateTime(date); List <ThietBi> result = new List <ThietBi>(); List <ThietBi> listThietBi = (from l in context.ThietBi where l.MaLoai == maLoai select l).ToList(); //string query = "SELECT TOP 1 PhieuGiaoNhan.MaPhieuGiaoNhan, MaLoaiGiaoNhan, MaDonVi, NgayGiaoNhan FROM PhieuGiaoNhan, ChiTietPhieuGiaoNhan WHERE ChiTietPhieuGiaoNhan.MaPhieuGiaoNhan = PhieuGiaoNhan.MaPhieuGiaoNhan AND NgayGiaoNhan < '2016-06-15' AND MaThietBi = 0 ORDER BY NgayGiaoNhan DESC"; //var listPhieuGiaoNhan = from p in context.PhieuGiaoNhan // select p; //PhieuGiaoNhan phieuGiaoNhan = context.PhieuGiaoNhan.SqlQuery(query).ToList().First(); foreach (ThietBi thietBi in listThietBi) { ThietBi rs = new ThietBi(); rs.MaThietBi = thietBi.MaThietBi; rs.NgayDuaVaoSuDung = thietBi.NgayDuaVaoSuDung; List <PhieuGiaoNhan> listPhieuGiaoNhan = (from pgn in context.PhieuGiaoNhan where pgn.NgayGiaoNhan <= time orderby pgn.NgayGiaoNhan descending select pgn).ToList(); PhieuGiaoNhan p = new PhieuGiaoNhan(); foreach (PhieuGiaoNhan pgn in listPhieuGiaoNhan) { List <ThietBi> list = pgn.ThietBi.ToList(); bool isFound = false; foreach (ThietBi tb in list) { if (tb.MaThietBi == thietBi.MaThietBi) { isFound = true; p = pgn; } } if (isFound) { break; } } // 1 còn hoạt động -> đang dùng // 2 đang dùng -> còn hoạt động // 3 đang dùng -> đã hư // 4 đã hư -> còn hoạt động // 5 đã hư -> thanh lý switch (p.MaLoaiGiaoNhan) { case "1": rs.TinhTrang = DANG_DUNG; break; case "2": rs.TinhTrang = CON_DUNG_DUOC; break; case "3": rs.TinhTrang = DA_HU; break; case "4": rs.TinhTrang = CON_DUNG_DUOC; break; case "5": rs.TinhTrang = DA_THANH_LY; break; default: break; } result.Add(rs); } return(result); } }