/// <summary>
        /// Thực hiện nghiệp vụ Delete dữ liệu
        /// </summary>
        private void PerformDeleteAction()
        {
            if (Utility.AcceptQuestion("Bạn có muốn xóa Loại thuốc đang chọn hay không?", "Xác nhận xóa", true))
            {
                Int16 v_shtIdLoaithuoc = Convert.ToInt16(txtID.Text.Trim());
                //Kiểm tra xem đã được sử dụng trong bảng khác chưa

                if (new DmucThuocController().FetchByQuery(DmucThuoc.CreateQuery().AddWhere("Id_Loaithuoc", Comparison.Equals, v_shtIdLoaithuoc)).Count > 0)
                {
                    Utility.SetMsg(lblMsg, "Loại thuốc này đã được sử dụng trong danh mục thuốc(vật tư) nên bạn không thể xóa", true);
                    return;
                }
                DataRow[] arrDr = m_dtLoaithuoc.Select(DmucLoaithuoc.Columns.IdLoaithuoc + "=" + txtID.Text);
                //Gọi nghiệp vụ xóa dữ liệu\
                int Count = DmucLoaithuoc.Delete(v_shtIdLoaithuoc);

                if (arrDr.Length > 0)//Nếu xóa thành công trong CSDL
                {
                    m_dtLoaithuoc.Rows.Remove(arrDr[0]);
                    m_dtLoaithuoc.AcceptChanges();
                    //Return to the InitialStatus
                    m_enAction = action.FirstOrFinished;
                    SetControlStatus();
                    Utility.SetMsg(lblMsg, "Đã xóa Loại có mã: " + v_shtIdLoaithuoc + " ra khỏi hệ thống.", false);
                }
                else//Có lỗi xảy ra
                {
                    Utility.SetMsg(lblMsg, "Lỗi khi xóa loại thuốc", true);
                }
            }
        }
Example #2
0
        //Các phương thức khởi tạo của Class

        #region "Constructors"
        /// <summary>
        /// hàm thực hiện việc khởi tạo thông tin của thuốc
        /// </summary>
        /// <param name="p_strDrugOnly"></param>
        public frm_themmoi_thuoc(string p_strDrugOnly)
        {
            InitializeComponent();
            
            InitializeEvents();
            m_Query = DmucThuoc.CreateQuery();
            m_QueryCmd = m_Query.BuildSelectCommand();
            //Khởi tạo các giá trị mặc định. Có thể đặt ở Form load và có thể sử dụng Thread để Load trong 
            //một số trường hợp cần cải thiện Performance
            if (p_strDrugOnly.ToUpper() == "DRUGONLY")
            {

            }
            txtCode.Enabled = false;
            cboDrugNature.SelectedIndex = 0;

          


        }
Example #3
0
        /// <summary>
        /// Thực hiện nghiệp vụ Update dữ liệu
        /// </summary>
        private void PerformUpdateAction()
        {
            Utility.SetMsg(lblMsg, "", false);
            //Gọi Business cập nhật dữ liệu
            Int16 v_intUpdateDrugID = Convert.ToInt16(txtID.Text);
            SqlQuery sqlQuery = new Select().From(DmucThuoc.Schema)
                  .Where(DmucThuoc.Columns.MaThuoc).IsEqualTo(txtCode.Text)
                  .And(DmucThuoc.Columns.IdThuoc).IsNotEqualTo(v_intUpdateDrugID);

            //Kiểm tra nếu trùng Mã Drug Code thì bắt nhập mã khác
            //DmucThuocCollection v_arrSameCodeObject = new DmucThuocController().FetchByQuery(m_Query.AddWhere("Drug_Code", txtCode.Text.Trim().ToUpper()).AND("id_thuoc", Comparison.NotEquals, v_intUpdateDrugID));
            if (sqlQuery.GetRecordCount() > 0)
            {
                Utility.SetMsg(lblMsg, "Đã tồn tại thuốc có mã =" + txtCode.Text.Trim() +
                                ".Đề nghị bạn nhập mã khác",true);
                m_Query = DmucThuoc.CreateQuery();
                return;
            }
            //Create Again to ignore Where Clause
            m_Query = DmucThuoc.CreateQuery();
            //Tạo giá trị mới cho đối tượng đang cần Update
            DmucThuoc objThuoc = DmucThuoc.FetchByID(txtID.Text);
            
            objThuoc.MaThuoc = Utility.sDbnull(txtCode.Text);
            objThuoc.MaQD40 = Utility.sDbnull(txtMaQD40.Text);
            objThuoc.MaQDTinh = Utility.sDbnull(txtMaQDTinh.Text);
            objThuoc.SluongVuottran = (int)Utility.DecimaltoDbnull(txtSlVuottran.Text, 0);

            objThuoc.TenThuoc = Utility.GetValue(txtName.Text, false);
            objThuoc.TenBhyt = Utility.GetValue(txtTEN_BHYT.Text, false);
            objThuoc.DonGia = Utility.DecimaltoDbnull( txtDongia.Text,0);
            objThuoc.GiaDv = Utility.DecimaltoDbnull(txtGiaDV.Text, 0);
            objThuoc.GiaBhyt = Utility.DecimaltoDbnull(txtGiaBHYT.Text, 0);
            objThuoc.PhuthuDungtuyen = Utility.DecimaltoDbnull(txtPTDT.Text, 0);
            objThuoc.PhuthuTraituyen = Utility.DecimaltoDbnull(txtPTTT.Text, 0);
            objThuoc.MaThuoc = Utility.GetValue(txtCode.Text, false);
            objThuoc.IdLoaithuoc = Convert.ToInt16(txtLoaithuoc.MyID);
            objThuoc.TinhChat = Convert.ToByte(cboDrugNature.SelectedIndex);
            objThuoc.MaDonvitinh = txtDonvitinh.myCode;
            objThuoc.TuTuc = Utility.Bool2byte(chkTutuc.Checked);
            objThuoc.MotaThem = Utility.GetValue(txtDesc.Text, false);
            objThuoc.HoatChat = Utility.GetValue(txtActice.Text, false);
            objThuoc.NuocSanxuat = txtNuocSX.Text;
            objThuoc.HangSanxuat = txtHangSX.Text;
            objThuoc.HamLuong = txtContent.Text;
            objThuoc.QD31 = Utility.DoTrim(txtQD31.Text);
            objThuoc.SoDangky = txtNumber_Register.Text;
            objThuoc.TrangThai = chkHieuLuc.Checked ? (byte)1 : (byte)0;
            objThuoc.DangBaoche = Utility.DoTrim(txtDangBaoChe.Text);
            objThuoc.NguoiSua = globalVariables.UserName;
            objThuoc.NgaySua = DateTime.Now;
            objThuoc.GioihanKedon = (Int16)Utility.DecimaltoDbnull(txtSoluong.Text, -1);
            objThuoc.DonviBut = (int)Utility.DecimaltoDbnull(txtBut.Text, -1);
            objThuoc.CachSudung = txtCachsudung.myCode;
            objThuoc.SingleService = Utility.Bool2byte(chkSingle.Checked);
            objThuoc.CoChiathuoc = Utility.Bool2byte(chkChiathuoc.Checked);
            objThuoc.MaDvichia = txtDonvichia.myCode;
            objThuoc.SluongChia = (int)Utility.DecimaltoDbnull(txtSoluongchia.Text, 0);
            objThuoc.DongiaChia = Utility.DecimaltoDbnull(txtDongiachia.Text, 0);
            objThuoc.NguonGoc = Utility.sDbnull(txtNguongoc.Text, "");
            objThuoc.NoitruNgoaitru=optAll.Checked?"ALL":(optNoitru.Checked?"NOI":"NGOAI");
            objThuoc.KieuThuocvattu = txtKieuthuocVT.myCode;
            objThuoc.IsNew = false;
            objThuoc.MarkOld();
            dmucThuoc_busrule.Insert(objThuoc, GetQheCamchidinhChungphieuCollection());
            //Update to Datasource to reflect on DataGridView
           

            DataRow dr = Utility.FetchOnebyCondition(m_dtDrugDataSource, "id_thuoc=" + v_intUpdateDrugID.ToString().Trim());
            if (dr != null)
            {
                Utility.FromObjectToDatarow(objThuoc, ref dr);
                dr[DmucThuoc.Columns.TinhChat] = Convert.ToByte(cboDrugNature.SelectedIndex);
                dr["ten_loaithuoc"] = txtLoaithuoc.Text;
                dr["ten_donvitinh"] = txtDonvitinh.Text;
                dr["ten_donvichia"] = txtDonvichia.Text;
                dr["ten_cachsudung"] = txtCachsudung.Text;


                dr[DmucThuoc.Columns.HamLuong] = txtContent.Text;
                dr[DmucThuoc.Columns.SoDangky] = txtNumber_Register.Text;
                dr[DmucThuoc.Columns.NuocSanxuat] = txtNuocSX.Text;
                dr[DmucThuoc.Columns.HangSanxuat] = txtHangSX.Text;
                txtName.UpdateItems(dr);
                m_dtDrugDataSource.AcceptChanges();
            }
            //Return to the InitialStatus
            m_enAction = action.FirstOrFinished;

            //Nhảy đến bản ghi vừa cập nhật trên lưới. Do txtID chưa bị reset nên dùng luôn
            if (grdList != null) Utility.GotoNewRowJanus(grdList, "id_thuoc", txtID.Text.Trim());
            SetControlStatus();
            Utility.SetMsg(lblMsg, "Cập nhật dữ liệu thành công.", false);
            this.Close();
        }
Example #4
0
        /// <summary>
        /// Thực hiện nghiệp vụ Insert dữ liệu
        /// </summary>
        private void PerformInsertAction()
        {
            try
            {
                Utility.SetMsg(lblMsg, "", false);
                SqlQuery sqlQuery = new Select().From(DmucThuoc.Schema)
                    .Where(DmucThuoc.Columns.MaThuoc).IsEqualTo(txtCode.Text);
                if (sqlQuery.GetRecordCount() > 0)
                {
                    Utility.SetMsg(lblMsg, "Đã tồn tại thuốc có mã(Drug Code)=" + txtCode.Text.Trim() + ".Đề nghị bạn nhập mã khác",true);
                    m_Query = DmucThuoc.CreateQuery();
                    return;
                }
                //Bước 0: Thêm mới thuốc
                DmucThuoc objThuoc = new DmucThuoc();
                objThuoc.TenThuoc = Utility.sDbnull(txtName.Text);
                objThuoc.TenBhyt = Utility.sDbnull(txtTEN_BHYT.Text);
                objThuoc.MaThuoc = Utility.sDbnull(txtCode.Text);
                objThuoc.MaQD40 = Utility.sDbnull(txtMaQD40.Text);
                objThuoc.MaQDTinh = Utility.sDbnull(txtMaQDTinh.Text);
                objThuoc.SluongVuottran = (int)Utility.DecimaltoDbnull(txtSlVuottran.Text, 0);

                objThuoc.IdLoaithuoc = Utility.Int16Dbnull(txtLoaithuoc.MyID);
                objThuoc.DonGia = Utility.DecimaltoDbnull( txtDongia.Text, 0);
                objThuoc.GiaDv = Utility.DecimaltoDbnull(txtGiaDV.Text, 0);
                objThuoc.GiaBhyt = Utility.DecimaltoDbnull(txtGiaBHYT.Text, 0);
                objThuoc.PhuthuDungtuyen = Utility.DecimaltoDbnull(txtPTDT.Text, 0);
                objThuoc.PhuthuTraituyen = Utility.DecimaltoDbnull(txtPTTT.Text, 0);
                objThuoc.MotaThem = Utility.sDbnull(txtDesc.Text);
                objThuoc.DangBaoche = Utility.DoTrim(txtDangBaoChe.Text);
                objThuoc.HamLuong = Utility.sDbnull(txtContent.Text);
                objThuoc.HangSanxuat = Utility.sDbnull(txtHangSX.Text);
                objThuoc.TrangThai = chkHieuLuc.Checked ? (byte)1 : (byte)0;
                objThuoc.TuTuc =Utility.Bool2byte( chkTutuc.Checked );
                objThuoc.NgayTao = DateTime.Now;
                objThuoc.QD31 = Utility.DoTrim(txtQD31.Text);
                objThuoc.NguoiTao = globalVariables.UserName;
                objThuoc.NuocSanxuat = Utility.sDbnull(txtNuocSX.Text);
                objThuoc.GioihanKedon = (Int16)Utility.DecimaltoDbnull(txtSoluong.Text,-1);
                objThuoc.DonviBut = (int)Utility.DecimaltoDbnull(txtBut.Text, -1);
                objThuoc.MaDonvitinh = txtDonvitinh.myCode;
                objThuoc.CachSudung = txtCachsudung.myCode;
                objThuoc.NguonGoc = Utility.sDbnull(txtNguongoc.Text,"");
                objThuoc.CoChiathuoc = Utility.Bool2byte(chkChiathuoc.Checked);
                objThuoc.MaDvichia = txtDonvichia.myCode;
                objThuoc.SluongChia =(int) Utility.DecimaltoDbnull(txtSoluongchia.Text, 0);
                objThuoc.DongiaChia = Utility.DecimaltoDbnull(txtDongiachia.Text, 0);
                objThuoc.SingleService = Utility.Bool2byte(chkSingle.Checked);
                objThuoc.TinhChat = Convert.ToByte(cboDrugNature.SelectedIndex);
                objThuoc.HoatChat = Utility.sDbnull(txtActice.Text);
                objThuoc.KieuThuocvattu = txtKieuthuocVT.myCode;
                objThuoc.NoitruNgoaitru = optAll.Checked ? "ALL" : (optNoitru.Checked ? "NOI" : "NGOAI");
                objThuoc.IsNew = true;
                dmucThuoc_busrule.Insert(objThuoc, GetQheCamchidinhChungphieuCollection());
                int v_intNewDrugID = objThuoc.IdThuoc;
                txtID.Text = Utility.sDbnull(objThuoc.IdThuoc);
                DataRow dr = m_dtDrugDataSource.NewRow();
                Utility.FromObjectToDatarow(objThuoc, ref dr);
                dr[DmucThuoc.Columns.TinhChat] = Convert.ToByte(cboDrugNature.SelectedIndex);
                dr["ten_loaithuoc"] = txtLoaithuoc.Text;
                dr["ten_donvitinh"] = txtDonvitinh.Text;
                dr["ten_donvichia"] = txtDonvichia.Text;
                dr["ten_cachsudung"] = txtCachsudung.Text;
                dr[DmucThuoc.Columns.NguoiTao] = globalVariables.UserName;
                dr[DmucThuoc.Columns.NgayTao] = DateTime.Now;
                m_dtDrugDataSource.Rows.Add(dr);
                txtName.AddNewItems(dr);
                m_dtDrugDataSource.AcceptChanges();
                m_enAction = action.Insert;
                //Nhảy đến bản ghi vừa thêm mới trên lưới. Do txtID chưa bị reset nên dùng luôn
                try
                {
                    Utility.GotoNewRowJanus(grdList, "id_thuoc", v_intNewDrugID.ToString().Trim());
                    if (chkThemlientuc.Checked)
                        SetControlStatus();
                    else
                        this.Close();
                }
                catch (Exception exception)
                {
                   Utility.ShowMsg("Lỗi:"+ exception.Message);
                }
                Utility.SetMsg(lblMsg, "Thêm mới dữ liệu thành công!",false);
                SetControlStatus();
               txtMaQD40.Focus();
            }
            catch
            {
            }
        }