Beispiel #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            bool isObserve = false;

            if (Bussiness.currentLuotKhamID == -1)
            {
                isObserve = true;
            }
            LuotThuoc lt = new LuotThuoc();

            lt.LuotKham = Bussiness.currentLuotKhamID;
            lt.Thuoc    = (ThemThuocListView.SelectedItem as Thuoc).TenThuoc;
            ThemLuotThuocDialog dialog = new ThemLuotThuocDialog(lt, isObserve);

            if (dialog.ShowDialog() == true)
            {
                try
                {
                    Bussiness.addLuotThuoc(lt.Thuoc, (int)lt.SoLuong);
                    LuotKham lk = LuotKhamDAO.getLuotKham(Bussiness.currentLuotKhamID);
                    TienKhamTxtBlock.Text          = "Tien kham: " + lk.TienKham.ToString();
                    TienThuocTxtBlock.Text         = "Tien thuoc: " + lk.TienThuoc.ToString();
                    TongChiPhiTxtBlock.Text        = "Tong chi phi: " + lk.ChiPhi.ToString();
                    ThongTinLuotKhamTab.IsSelected = true;
                }
                catch (Exception ex) { MessageBox.Show(ex.ToString()); }
            }
        }
Beispiel #2
0
        public static void updateLuotThuoc(int ID, int soLuongThem)
        {
            if (currentLuotKhamID == -1)
            {
                return;
            }
            LuotThuoc lt    = LuotThuocDAO.getLuotThuoc(ID);
            int       index = -1;

            for (int i = 0; i < listLuotThuoc.Count; i++)
            {
                if (listLuotThuoc.ElementAt(i).ID == ID)
                {
                    index = i;
                }
            }
            if (index == -1 || lt == null)
            {
                return;
            }
            lt.SoLuong += soLuongThem;
            lt.ChiPhi  += soLuongThem * ThuocDAO.getThuoc(lt.Thuoc).DonGia;
            listLuotThuoc.ElementAt(index).soluong2 = (int)lt.SoLuong;
            listLuotThuoc.ElementAt(index).chiphi2  = (double)lt.ChiPhi;
            LuotThuocDAO.updateLuotThuoc(ID, lt);
        }
Beispiel #3
0
        public static bool removeLuotThuoc(int ID)
        {
            if (currentLuotKhamID == -1)
            {
                return(false);
            }
            LuotKham lk = LuotKhamDAO.getLuotKham(currentLuotKhamID);

            LuotThuoc lt = LuotThuocDAO.getLuotThuoc(ID);

            if (lt == null)
            {
                return(false);
            }
            lk.TienThuoc -= lt.ChiPhi;
            LuotKhamDAO.updateLuotKham(lk.ID, lk);
            foreach (LuotThuoc l in listLuotThuoc)
            {
                if (l.ID == ID)
                {
                    lt = l;
                    break;
                }
            }
            listLuotThuoc.Remove(lt);
            LuotThuocDAO.removeLuotThuoc(ID);
            return(true);
        }
 public static void addLuotThuoc(LuotThuoc lt)
 {
     using (var context = new DataModel())
     {
         context.LuotThuocs.Add(lt);
         context.SaveChanges();
     }
 }
        public static LuotThuoc getLuotThuoc(int ID)
        {
            LuotThuoc lt = null;

            using (var context = new DataModel())
            {
                lt = context.LuotThuocs.Include("LuotKham1")
                     .Include("Thuoc1").Where(s => s.ID == ID).FirstOrDefault();
            }
            return(lt);
        }
        public static bool removeLuotThuoc(int ID)
        {
            LuotThuoc lt = null;

            using (var context = new DataModel())
            {
                lt = context.LuotThuocs.Find(ID);
                context.LuotThuocs.Remove(lt);
                context.SaveChanges();
            }
            return(lt == null);
        }
Beispiel #7
0
        public static void addLuotThuoc(string thuoc, int soLuong)
        {
            if (currentLuotKhamID == -1)
            {
                return;
            }
            int      check = -1;
            LuotKham lk;

            foreach (Thuoc th in listAllThuoc)
            {
                if (th.TenThuoc.Equals(thuoc))
                {
                    check = 0;
                    break;
                }
            }
            if (check == -1)
            {
                return;
            }
            else
            {
                lk = LuotKhamDAO.getLuotKham(currentLuotKhamID);
                IList <LuotThuoc> list = lk.LuotThuocs.ToList();
                foreach (LuotThuoc lth in list)
                {
                    if (lth.Thuoc.Equals(thuoc))
                    {
                        lk.TienThuoc += soLuong * ThuocDAO.getThuoc(thuoc).DonGia;
                        LuotKhamDAO.updateLuotKham(lk.ID, lk);
                        updateLuotThuoc(lth.ID, soLuong);
                        return;
                    }
                }
            }
            LuotThuoc lt = new LuotThuoc();

            lt.ID         = currentLTID++;
            lt.LuotKham   = currentLuotKhamID;
            lt.SoLuong    = soLuong;
            lt.Thuoc      = thuoc;
            lt.ChiPhi     = lt.SoLuong * ThuocDAO.getThuoc(thuoc).DonGia;
            lk.TienThuoc += lt.ChiPhi;
            listLuotThuoc.Add(lt);
            LuotKhamDAO.updateLuotKham(lk.ID, lk);
            LuotThuocDAO.addLuotThuoc(lt);
        }
        public ThemLuotThuocDialog(LuotThuoc lt, bool isObserve)
        {
            InitializeComponent();
            this.lt = lt;
            TenThuocLabel.Content = lt.Thuoc;
            this.isObserve        = isObserve;
            if (isObserve)
            {
                AdjustAmountPanel.Visibility = Visibility.Hidden;
            }
            Thuoc thuoc = ThuocDAO.getThuoc(lt.Thuoc);

            DonViLabel.Content  = "Don vi tinh: " + thuoc.DonVi;
            DonGiaLabel.Content = "Don gia: " + thuoc.DonGia;
            CachDungLabel.Text  = "Cach dung: " + thuoc.CachDung;
        }
        public static void updateLuotThuoc(int ID, LuotThuoc lt)
        {
            if (ID != lt.ID)
            {
                return;
            }
            LuotThuoc l = null;

            using (var context = new DataModel())
            {
                l = context.LuotThuocs.Find(ID);
                if (l == null)
                {
                    context.LuotThuocs.Add(lt);
                }
                else
                {
                    context.Entry(l).CurrentValues.SetValues(lt);
                }
                context.SaveChanges();
            }
        }