コード例 #1
0
 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();
     }
 }
コード例 #2
0
        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);
            }
        }