private void btnsuathuoc_Click(object sender, EventArgs e)
 {
     ltdto = new LoaiThuocDTO();
      ltdto.MaLoaiThuoc = int.Parse(txtmaloaithuoc.Text.ToString());
      ltdto.TenLoaiThuoc = txttenloaithuoc.Text.ToString();
      ltdto.MaDonViTinh=int.Parse(cmbdonvitinh.SelectedValue.ToString());
      if (ltbus.update(ltdto) > 0)
         {
         ltbus.showInListView(lvLoaiThuoc);
         lbldonvi.Text = cmbdonvitinh.Text.ToString();
      }
     btnthemthuoc.Text = "Hủy";
 }
 public int insert(LoaiThuocDTO dto)
 {
     int result = 0;
     if (dto.TenLoaiThuoc == "")
     {
         MessageBox.Show(" Nhập tên loại thuốc !");
     }
     else
     {
         LoaiThuocDTO[] dv = dao.getList();
         if (dv != null || dv.Length == 0)
         {
             bool check = false; // kieim tra trung ten
             for (int i = 0; i < dv.Length; i++)
             {
                 if (string.Equals(dto.TenLoaiThuoc,dv[i].TenLoaiThuoc.ToString()))
                 {
                     check = true;
                     break;
                 }
             }
             if (check != true)
             {
                  result = dao.insert(dto);
                 if (result > 0)
                     MessageBox.Show(" Thêm loại thuốc thành công !");
                 else
                     MessageBox.Show(" Thêm loại thuốc thất bại !");
             }
             else
                 MessageBox.Show(" Tên  loại thuốc đã tồn tại !");
         }
         else
         {
             result = dao.insert(dto);
             if (result > 0)
                 MessageBox.Show(" Thêm loại thuốc thành công !");
             else
                 MessageBox.Show(" Thêm loại thuốc  thất bại !");
         }
     }
     return result;
 }
 private void btnthemthuoc_Click(object sender, EventArgs e)
 {
     if (btnthemthuoc.Text == "Thêm")
     {
         ltdto = new LoaiThuocDTO();
         ltdto.TenLoaiThuoc = txttenloaithuoc.Text.ToString();
         ltdto.SoLuong = 0;
         ltdto.MaDonViTinh = int.Parse(cmbdonvitinh.SelectedValue.ToString());
         if(ltbus.insert(ltdto)>0)
             ltbus.showInListView(lvLoaiThuoc);
     }
     else
     {
         txtmaloaithuoc.Text = "";
         txttenloaithuoc.Text = "";
         btnthemthuoc.Text = "Thêm";
         btnxoathuoc.Enabled = false;
         btnsuathuoc.Enabled = false;
     }
 }
 // list of all loaithuoc
 public LoaiThuocDTO[] getBaoCaoThuocTheoNgay(string ngaybaocao)
 {
     LoaiThuocDTO[] list;
     string sql = " select ctk.MaLoaiThuoc ,sum(ctk.SoLuong) as SoLuong from CT_KHAM ctk, HOADON hd";
     sql += " where ctk.MaPhieuKhamBenh=hd.MaPhieuKhamBenh and hd.TienThuoc>0 and substring(ctk.MaPhieuKhamBenh,6,10)=@ngay group by ctk.MaLoaiThuoc order by SoLuong DESC ";
     DataTable dt = new DataTable();
     SqlParameter sp = new SqlParameter("@ngay", ngaybaocao);
     dt = conectData.LoadData(sql,sp);
     if (dt == null || dt.Rows.Count == 0)
         return null;
     else
     {
         list = new LoaiThuocDTO[dt.Rows.Count];
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             list[i] = new LoaiThuocDTO();
             list[i].MaLoaiThuoc = int.Parse(dt.Rows[i]["MaLoaiThuoc"].ToString());
              list[i].SoLuong = int.Parse(dt.Rows[i]["SoLuong"].ToString());
         }
     }
     return list;
 }
 // list of all loaithuoc
 public LoaiThuocDTO[] getBaoCaoThuocTheoThang(int thang, int nam)
 {
     LoaiThuocDTO[] list;
     string sql = " select ctk.MaLoaiThuoc ,sum(ctk.SoLuong) as SoLuong from CT_KHAM ctk, HOADON hd";
     sql += " where ctk.MaPhieuKhamBenh=hd.MaPhieuKhamBenh and hd.TienThuoc>0 and left(Substring(hd.MaPhieuKhamBenh,6,10),Charindex('/',Substring(hd.MaPhieuKhamBenh,6,10),0)-1)=@thang and right(Substring(hd.MaPhieuKhamBenh,6,10),4)=@nam group by ctk.MaLoaiThuoc order by SoLuong DESC ";
     DataTable dt = new DataTable();
     SqlParameter[] sp = new SqlParameter[2];
     sp[0] = new SqlParameter("@thang", thang);
     sp[1] = new SqlParameter("@nam", nam);
     dt = conectData.LoadData(sql, sp);
     if (dt == null || dt.Rows.Count == 0)
         return null;
     else
     {
         list = new LoaiThuocDTO[dt.Rows.Count];
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             list[i] = new LoaiThuocDTO();
             list[i].MaLoaiThuoc = int.Parse(dt.Rows[i]["MaLoaiThuoc"].ToString());
             list[i].SoLuong = int.Parse(dt.Rows[i]["SoLuong"].ToString());
         }
     }
     return list;
 }
 public int updateTenThuoc(LoaiThuocDTO cd)
 {
     string sql = "update LOAITHUOC set TenLoaiThuoc=@SoLuong, MaDonViTinh=@MaDonViTinh where MaLoaiThuoc=@MaLoaiThuoc";
     SqlParameter[] sp = new SqlParameter[3];
     sp[0] = new SqlParameter("@SoLuong", cd.TenLoaiThuoc);
     sp[1] = new SqlParameter("@MaDonViTinh", cd.MaDonViTinh);
     sp[2] = new SqlParameter("@MaLoaiThuoc", cd.MaLoaiThuoc);
     return conectData.Insert_Update_Delete(sql, sp);
 }
 public int updateSoLuong(LoaiThuocDTO cd)
 {
     string sql = "update LOAITHUOC set SoLuong=@SoLuong where MaLoaiThuoc=@MaLoaiThuoc";
     SqlParameter[] sp = new SqlParameter[2];
     sp[0] = new SqlParameter("@SoLuong", cd.SoLuong);
     sp[1] = new SqlParameter("@MaLoaiThuoc", cd.MaLoaiThuoc);
     return conectData.Insert_Update_Delete(sql, sp);
 }
 public int update(LoaiThuocDTO cd)
 {
     string sql = "update LOAITHUOC set TenLoaiThuoc=@TenLoaiThuoc, MaDonViTinh=@MaDonViTinh, DonGia=@DonGia, SoLuong=@SoLuong where MaLoaiThuoc=@MaLoaiThuoc";
     SqlParameter[] sp = new SqlParameter[6];
     sp[0] = new SqlParameter("@TenLoaiThuoc", cd.TenLoaiThuoc);
     sp[1] = new SqlParameter("@MaDonViTinh", cd.MaDonViTinh);
     sp[2] = new SqlParameter("@DonGia", cd.DonGia);
     sp[3] = new SqlParameter("@SoLuong", cd.SoLuong);
     sp[4] = new SqlParameter("@MaLoaiThuoc", cd.MaLoaiThuoc);
     return conectData.Insert_Update_Delete(sql, sp);
 }
 public int insert(LoaiThuocDTO cd)
 {
     string sql = "insert into LOAITHUOC values (@TenLoaiThuoc,@MaDonViTinh,@DonGia,@SoLuong)";
     SqlParameter[] sp = new SqlParameter[4];
     sp[0] = new SqlParameter("@TenLoaiThuoc", cd.TenLoaiThuoc);
     sp[1] = new SqlParameter("@MaDonViTinh", cd.MaDonViTinh);
     sp[2] = new SqlParameter("@DonGia", cd.DonGia);
     sp[3] = new SqlParameter("@SoLuong", cd.SoLuong);
     return conectData.Insert_Update_Delete(sql, sp);
 }
Exemple #10
0
        // list of all loaithuoc
        public LoaiThuocDTO[] getList()
        {
            LoaiThuocDTO[] list;
            string sql = " select * from LOAITHUOC ";
            DataTable dt = new DataTable();
            dt = conectData.LoadData(sql);
            if (dt == null || dt.Rows.Count == 0)
                return null;
            else
            {
                list = new LoaiThuocDTO[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    list[i] = new LoaiThuocDTO();
                    list[i].MaLoaiThuoc = int.Parse(dt.Rows[i]["MaLoaiThuoc"].ToString());
                    list[i].TenLoaiThuoc = dt.Rows[i]["TenLoaiThuoc"].ToString();
                    list[i].MaDonViTinh = int.Parse(dt.Rows[i]["MaDonViTinh"].ToString());
                    list[i].DonGia= float.Parse(dt.Rows[i]["DonGia"].ToString());
                    try
                    {
                        list[i].SoLuong = int.Parse(dt.Rows[i]["SoLuong"].ToString());
                    }
                    catch
                    {
                        list[i].SoLuong=0;
                    }

                }
            }
            return list;
        }
Exemple #11
0
        // list of all benhnhan
        public LoaiThuocDTO getByPrimaryKey(int maloaithuoc)
        {
            LoaiThuocDTO loaithuoc = new LoaiThuocDTO();
            string sql = " select * from LOAITHUOC Where MaLoaiThuoc=@MaLoaiThuoc ";
            SqlParameter sp = new SqlParameter("@MaLoaiThuoc", maloaithuoc);
            DataTable dt = new DataTable();
            dt = conectData.LoadData(sql,sp);
            if (dt == null || dt.Rows.Count == 0)
                return null;
            else
            {
                loaithuoc.MaLoaiThuoc = int.Parse(dt.Rows[0]["MaLoaiThuoc"].ToString());
                loaithuoc.TenLoaiThuoc = dt.Rows[0]["TenLoaiThuoc"].ToString();
                loaithuoc.MaDonViTinh = int.Parse(dt.Rows[0]["MaDonViTinh"].ToString());
                loaithuoc.DonGia = float.Parse(dt.Rows[0]["DonGia"].ToString());
                loaithuoc.SoLuong = float.Parse(dt.Rows[0]["SoLuong"].ToString());

            }
            return loaithuoc;
        }
Exemple #12
0
 public void updateSoLuong(LoaiThuocDTO ltdto)
 {
     try
     {
         int n = dao.updateSoLuong(ltdto);
     }
     catch
     {
         MessageBox.Show("Không thể cập nhật số lượng thuốc ");
     }
 }
Exemple #13
0
        public int update(LoaiThuocDTO dto)
        {
            int result = 0;
            if (dto.TenLoaiThuoc == "")
            {
                MessageBox.Show(" Nhập tên loại thuốc !");
            }
            else
            {
                if (dao.getByPrimaryKey(dto.MaLoaiThuoc).TenLoaiThuoc.ToString().Equals(dto.TenLoaiThuoc.ToString()))
                {
                    if (dao.getByPrimaryKey(dto.MaLoaiThuoc).MaDonViTinh == dto.MaDonViTinh)
                    {
                        MessageBox.Show(" Bạn đã không thay đổi thông tin nào !");

                    }
                    else
                    {
                        result = dao.updateTenThuoc(dto);
                        if (result > 0)
                            MessageBox.Show(" Cập nhật thông tin loại thuốc thành công !");
                        else
                            MessageBox.Show(" Cập nhật thông tin loại thuốc thất bại !");
                    }
                }
                else
                {
                    LoaiThuocDTO[] dv = dao.getList();
                    if (dv != null || dv.Length == 0)
                    {
                        bool check = false; // kieim tra trung ten
                        for (int i = 0; i < dv.Length; i++)
                        {
                            if (dto.TenLoaiThuoc == (dv[i].TenLoaiThuoc.ToString()))
                            {
                                check = true;
                                break;
                            }
                            if (dao.getByPrimaryKey(dto.MaLoaiThuoc).TenLoaiThuoc.ToString().Equals(dto.TenLoaiThuoc.ToString()))
                            {
                                check = false;
                                break;
                            }

                        }
                        if (check == true)
                        {
                            MessageBox.Show(" Tên loại thuốc đã tồn tại !");
                        }
                        else
                        {
                            result = dao.updateTenThuoc(dto);
                            if (result > 0)
                                MessageBox.Show(" Cập nhật thông tin loại thuốc thành công !");
                            else
                                MessageBox.Show(" Cập nhật thông tin loại thuốc thất bại !");

                        }
                    }
                    else
                    {
                        result = dao.updateTenThuoc(dto);
                        if (result > 0)
                            MessageBox.Show(" Cập nhật thông tin loại thuốc thành công !");
                        else
                            MessageBox.Show(" Cập nhật thông tin loại thuốc thất bại !");
                    }
                }
            }
            return result;
        }
Exemple #14
0
 private void btnindonthuoc_Click(object sender, EventArgs e)
 {
     DialogResult result;
      result = MessageBox.Show("Bạn có thật sự muốn lập hóa đơn cho bệnh nhân : " + lbltenbenhnhan.Text + " ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
      if (result == DialogResult.Yes)
      {
          hddto = new HoaDonDTO();
          hddto.MaPhieuKhamBenh = lblmabenhnhan.Text.ToString() + lblngaykham.Text.ToString();
          hddto.TienKham = float.Parse(lbltienkham.Text.ToString());
          if (checkBoxMuathuoc.Checked == true)
          {
              LoaiThuocDTO ltdto;
              bool check = false;
              listctk = ctkbus.getListByMaPhieuKham(lblmabenhnhan.Text.ToString() + dtimengaykham.Text.ToString());
              for (int i = 0; i < listctk.Length; i++)
              {
                  ltdto = new LoaiThuocDTO();
                  ltdto.MaLoaiThuoc = listctk[i].MaLoaiThuoc;
                  ltdto.SoLuong = lbbus.getByPrimaryKey(ltdto.MaLoaiThuoc).SoLuong - listctk[i].SoLuong;
                  if (ltdto.SoLuong < 0)
                  {
                      //MessageBox.Show(" Số lượng thuốc trong kho không đủ cho hóa đơn này, vui lòng nhập thuốc hoặc để bệnh nhân lấy thuốc ở ngoài !");
                      check = true;
                      break;
                  }
              }
              if (check == false)
              {
                  hddto.TienThuoc = float.Parse(lbltienthuoc.Text.ToString());
                  int n = hdbus.insert(hddto);
                  if (n > 0)
                  {
                      btnindonthuoc.Enabled = false;
                      checkBoxMuathuoc.Enabled = false;
                      btninhoadon.Enabled = true;
                      bnbus.showBNChuaLapHD(lvdsbenhnhan, bnbus.getListByPhieuKham(dtimengaykham.Text.ToString(), "in"), dtimengaykham.Text.ToString());
                  }
                  for (int i = 0; i < listctk.Length; i++)
                  {
                      ltdto = new LoaiThuocDTO();
                      ltdto.MaLoaiThuoc = listctk[i].MaLoaiThuoc;
                      ltdto.SoLuong = lbbus.getByPrimaryKey(ltdto.MaLoaiThuoc).SoLuong - listctk[i].SoLuong;
                      lbbus.updateSoLuong(ltdto);
                  }
              }
              else
              {
                    DialogResult result2;
                    result2 = MessageBox.Show("Số lượng thuốc trong kho không đủ cho hóa đơn này, vui lòng nhập thuốc. Nếu muốn tiếp tục lập hóa đơn sẽ không bao gồm tiền thuốc trong hóa đơn này!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                      if (result2 == DialogResult.Yes)
                      {   hddto.TienThuoc = 0;
                          lbltongcong.Text = lbltienkham.Text;
                          checkBoxMuathuoc.Checked = false;
                          int n = hdbus.insert(hddto);
                          if (n > 0)
                          {
                              btnindonthuoc.Enabled = false;
                              checkBoxMuathuoc.Enabled = false;
                              btninhoadon.Enabled = true;
                              bnbus.showBNChuaLapHD(lvdsbenhnhan, bnbus.getListByPhieuKham(dtimengaykham.Text.ToString(), "in"), dtimengaykham.Text.ToString());
                          }
                      }
              }
          }
          else
          {
              hddto.TienThuoc = 0;
              lbltongcong.Text = lbltienkham.Text;
              checkBoxMuathuoc.Checked = false;
              int n = hdbus.insert(hddto);
              if (n > 0)
              {
                  btnindonthuoc.Enabled = false;
                  checkBoxMuathuoc.Enabled = false;
                  btninhoadon.Enabled = true;
                  bnbus.showBNChuaLapHD(lvdsbenhnhan, bnbus.getListByPhieuKham(dtimengaykham.Text.ToString(), "in"), dtimengaykham.Text.ToString());
              }
          }
      }
 }