示例#1
0
        private void OnDisplayLoThuocList()
        {
            lock (ThisLock)
            {
                Result result = LoThuocBus.GetLoThuocList(_name, _tuNgay, _denNgay, _isTenThuoc);
                if (result.IsOK)
                {
                    dgLoThuoc.Invoke(new MethodInvoker(delegate()
                    {
                        if (dgLoThuoc.CurrentRow != null)
                        {
                            _currentRowIndex = dgLoThuoc.CurrentRow.Index;
                        }

                        ClearData();

                        DataTable dt = result.QueryResult as DataTable;
                        if (_dtTemp == null)
                        {
                            _dtTemp = dt.Clone();
                        }
                        UpdateChecked(dt);
                        dgLoThuoc.DataSource = dt;

                        if (_currentRowIndex < dt.Rows.Count)
                        {
                            dgLoThuoc.CurrentCell = dgLoThuoc[0, _currentRowIndex];
                            dgLoThuoc.Rows[_currentRowIndex].Selected = true;
                        }
                    }));
                }
                else
                {
                    MsgBox.Show(Application.ProductName, result.GetErrorAsString("LoThuocBus.GetLoThuocList"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("LoThuocBus.GetLoThuocList"));
                }
            }
        }
示例#2
0
        private void UpdateNgayHetHan(DataRow row)
        {
            string thuocGUID = row["ThuocGUID"].ToString();
            Result result    = LoThuocBus.GetNgayHetHanCuaThuoc(thuocGUID);

            if (result.IsOK)
            {
                if (result.QueryResult != null)
                {
                    DateTime ngayHetHan = Convert.ToDateTime(result.QueryResult);
                    row["NgayHetHan"] = ngayHetHan.ToString("dd/MM/yyyy");
                }
                else
                {
                    row["NgayHetHan"] = DBNull.Value;
                }
            }
            else
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("LoThuocBus.GetNgayHetHanCuaThuoc"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("LoThuocBus.GetNgayHetHanCuaThuoc"));
            }
        }
示例#3
0
        private void UpdateSLTon(DataRow row)
        {
            string thuocGUID = row["ThuocGUID"].ToString();
            Result result    = LoThuocBus.GetThuocTonKho(thuocGUID);

            if (result.IsOK)
            {
                if (result.QueryResult != null)
                {
                    int soLuongTon = Convert.ToInt32(result.QueryResult);
                    row["SLTon"] = soLuongTon;
                }
                else
                {
                    row["SLTon"] = DBNull.Value;
                }
            }
            else
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("LoThuocBus.GetNgayHetHanCuaThuoc"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("LoThuocBus.GetNgayHetHanCuaThuoc"));
            }
        }
示例#4
0
        private void OnDisplayNhaPhanPhoiList()
        {
            Cursor.Current = Cursors.WaitCursor;
            Result result = LoThuocBus.GetNhaPhanPhoiList();

            if (result.IsOK)
            {
                DataTable dt = result.QueryResult as DataTable;
                foreach (DataRow row in dt.Rows)
                {
                    if (row["NhaPhanPhoi"] == null || row["NhaPhanPhoi"] == DBNull.Value || row["NhaPhanPhoi"].ToString().Trim() == string.Empty)
                    {
                        continue;
                    }

                    cboNhaPhanPhoi.Items.Add(row["NhaPhanPhoi"].ToString());
                }
            }
            else
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("LoThuocBus.GetNhaPhanPhoiList"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("LoThuocBus.GetNhaPhanPhoiList"));
            }
        }
示例#5
0
        private bool CheckInfo()
        {
            if (txtMaPhieuThu.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập mã phiếu thu.", IconType.Information);
                txtMaPhieuThu.Focus();
                return(false);
            }

            if (txtTenBenhNhan.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng chọn tên bệnh nhân.", IconType.Information);
                txtTenBenhNhan.Focus();
                return(false);
            }

            //string phieuThuThuocGUID = _isNew ? string.Empty : _phieuThuThuoc.PhieuThuThuocGUID.ToString();
            //Result result = PhieuThuThuocBus.CheckPhieuThuThuocExistCode(phieuThuThuocGUID, txtMaPhieuThu.Text);

            //if (result.Error.Code == ErrorCode.EXIST || result.Error.Code == ErrorCode.NOT_EXIST)
            //{
            //    if (result.Error.Code == ErrorCode.EXIST)
            //    {
            //        MsgBox.Show(this.Text, "Mã phiếu thu này đã tồn tại rồi. Vui lòng nhập mã khác.", IconType.Information);
            //        txtMaPhieuThu.Focus();
            //        return false;
            //    }
            //}
            //else
            //{
            //    MsgBox.Show(this.Text, result.GetErrorAsString("PhieuThuThuocBus.CheckPhieuThuThuocExistCode"), IconType.Error);
            //    return false;
            //}

            gridViewPTT.UpdateCurrentRow();
            DataTable dt = (gridViewPTT.DataSource as DataView).Table;

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    if (row["ThuocGUID"] == null || row["ThuocGUID"] == DBNull.Value)
                    {
                        MsgBox.Show(this.Text, "Vui lòng chọn thuốc để xuất phiếu thu.", IconType.Information);
                        return(false);
                    }

                    string thuocGUID = row["ThuocGUID"].ToString();
                    string tenThuoc  = GetTenThuoc(thuocGUID);

                    if (row["DonGia"] == null || row["DonGia"] == DBNull.Value || Convert.ToDouble(row["DonGia"]) == 0)
                    {
                        MsgBox.Show(this.Text, string.Format("Thuốc '{0}' chưa có nhập giá bán. Vui lòng chọn thuốc khác.", tenThuoc), IconType.Information);
                        return(false);
                    }

                    int soLuong = 1;
                    if (row["SoLuong"] != null && row["SoLuong"] != DBNull.Value)
                    {
                        soLuong = Convert.ToInt32(row["SoLuong"]);
                    }

                    Result r = LoThuocBus.CheckThuocTonKho(thuocGUID, soLuong);
                    if (r.IsOK)
                    {
                        if (!Convert.ToBoolean(r.QueryResult))
                        {
                            MsgBox.Show(this.Text, string.Format("Thuốc '{0}' đã hết hoặc không đủ số lượng để bán. Vui lòng chọn thuốc khác.", tenThuoc), IconType.Information);
                            return(false);
                        }
                    }
                    else
                    {
                        MsgBox.Show(this.Text, r.GetErrorAsString("LoThuocBus.CheckThuocTonKho"), IconType.Error);
                        Utility.WriteToTraceLog(r.GetErrorAsString("LoThuocBus.CheckThuocTonKho"));
                        return(false);
                    }

                    r = LoThuocBus.CheckThuocHetHan(thuocGUID);
                    if (r.IsOK)
                    {
                        if (Convert.ToBoolean(r.QueryResult))
                        {
                            MsgBox.Show(this.Text, string.Format("Thuốc '{0}' đã hết hạn sử dụng. Vui lòng chọn thuốc khác.", tenThuoc), IconType.Information);
                            return(false);
                        }
                    }
                    else
                    {
                        MsgBox.Show(this.Text, r.GetErrorAsString("LoThuocBus.CheckThuocHetHan"), IconType.Error);
                        Utility.WriteToTraceLog(r.GetErrorAsString("LoThuocBus.CheckThuocHetHan"));
                        return(false);
                    }
                }
            }
            else
            {
                MsgBox.Show(this.Text, "Vui lòng chọn ít nhất 1 thuốc.", IconType.Information);
                return(false);
            }

            if (dt.Rows.Count > 1)
            {
                for (int i = 0; i < dt.Rows.Count - 1; i++)
                {
                    DataRow row1 = dt.Rows[i];
                    for (int j = i + 1; j < dt.Rows.Count; j++)
                    {
                        DataRow row2 = dt.Rows[j];
                        if (row1["ThuocGUID"].ToString() == row2["ThuocGUID"].ToString())
                        {
                            string tenThuoc = GetTenThuoc(row1["ThuocGUID"].ToString());
                            MsgBox.Show(this.Text, string.Format("Thuốc '{0}' đã tồn tại rồi. Vui lòng chọn thuốc khác", tenThuoc), IconType.Information);
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
示例#6
0
        private void OnSaveInfo()
        {
            try
            {
                MethodInvoker method = delegate
                {
                    _loThuoc.MaLoThuoc       = txtMaLoThuoc.Text;
                    _loThuoc.TenLoThuoc      = txtTenLoThuoc.Text;
                    _loThuoc.ThuocGUID       = Guid.Parse(cboThuoc.SelectedValue.ToString());
                    _loThuoc.SoDangKy        = txtSoDangKy.Text;
                    _loThuoc.CreatedDate     = dtpkNgayNhapLo.Value;
                    _loThuoc.NgaySanXuat     = dtpkNgaySanXuat.Value;
                    _loThuoc.NgayHetHan      = dtpkNgayHetHan.Value;
                    _loThuoc.HangSanXuat     = txtHangSanXuat.Text;
                    _loThuoc.NhaPhanPhoi     = cboNhaPhanPhoi.Text;
                    _loThuoc.SoLuongNhap     = (int)numSoLuongNhap.Value;
                    _loThuoc.GiaNhap         = (double)numGiaNhap.Value;
                    _loThuoc.DonViTinhNhap   = cboDonViTinhNhap.Text;
                    _loThuoc.DonViTinhQuiDoi = txtDonViTinhQuiDoi.Text;
                    _loThuoc.SoLuongQuiDoi   = (int)numSoLuongQuiDoi.Value;
                    _loThuoc.GiaNhapQuiDoi   = (double)numGiaNhapQuiDoi.Value;
                    _loThuoc.SoLuongXuat     = 0;

                    _loThuoc.Status = (byte)Status.Actived;

                    if (_isNew)
                    {
                        _loThuoc.SystemDate = DateTime.Now;
                        _loThuoc.CreatedBy  = Guid.Parse(Global.UserGUID);
                    }
                    else
                    {
                        _loThuoc.UpdatedDate = DateTime.Now;
                        _loThuoc.UpdatedBy   = Guid.Parse(Global.UserGUID);

                        if (_loThuoc.Note != null && _loThuoc.Note.Trim() != string.Empty)
                        {
                            _loThuoc.Note += string.Format("\r\nSửa {0}: {1}", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), _ghiChu);
                        }
                        else
                        {
                            _loThuoc.Note = string.Format("Sửa {0}: {1}", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), _ghiChu);
                        }
                    }

                    Result result = LoThuocBus.InsertLoThuoc(_loThuoc);

                    if (!result.IsOK)
                    {
                        MsgBox.Show(this.Text, result.GetErrorAsString("LoThuocBus.InsertLoThuoc"), IconType.Error);
                        Utility.WriteToTraceLog(result.GetErrorAsString("LoThuocBus.InsertLoThuoc"));
                        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    }
                };

                if (InvokeRequired)
                {
                    BeginInvoke(method);
                }
                else
                {
                    method.Invoke();
                }
            }
            catch (Exception e)
            {
                MsgBox.Show(this.Text, e.Message, IconType.Error);
                Utility.WriteToTraceLog(e.Message);
            }
        }
示例#7
0
        private bool CheckInfo()
        {
            if (txtMaLoThuoc.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập mã lô thuốc.", IconType.Information);
                txtMaLoThuoc.Focus();
                return(false);
            }

            if (txtTenLoThuoc.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập tên lô thuốc.", IconType.Information);
                txtTenLoThuoc.Focus();
                return(false);
            }

            if (cboThuoc.SelectedValue == null || cboThuoc.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng chọn thuốc.", IconType.Information);
                cboThuoc.Focus();
                return(false);
            }

            if (dtpkNgaySanXuat.Value >= dtpkNgayHetHan.Value)
            {
                MsgBox.Show(this.Text, "Ngày sản xuất phải nhỏ hơn ngày hết hạn", IconType.Information);
                dtpkNgaySanXuat.Focus();
                return(false);
            }

            if (!_isNew)
            {
                int    soLuongNhap = (int)numSoLuongNhap.Value * (int)numSoLuongQuiDoi.Value;
                Result rs          = LoThuocBus.GetLoThuoc(_loThuoc.LoThuocGUID.ToString());
                if (!rs.IsOK)
                {
                    MsgBox.Show(this.Text, rs.GetErrorAsString("LoThuocBus.GetLoThuoc"), IconType.Error);
                    return(false);
                }

                int soLuongXuat = (rs.QueryResult as LoThuoc).SoLuongXuat;

                if (soLuongNhap < soLuongXuat)
                {
                    MsgBox.Show(this.Text, "Số lượng nhập phải lớn hơn hoặc bằng số lượng xuất.", IconType.Information);
                    numSoLuongNhap.Focus();
                    return(false);
                }
            }

            string loThuocGUID = _isNew ? string.Empty : _loThuoc.LoThuocGUID.ToString();
            Result result      = LoThuocBus.CheckLoThuocExistCode(loThuocGUID, txtMaLoThuoc.Text);

            if (result.Error.Code == ErrorCode.EXIST || result.Error.Code == ErrorCode.NOT_EXIST)
            {
                if (result.Error.Code == ErrorCode.EXIST)
                {
                    MsgBox.Show(this.Text, "Mã lô thuốc này đã tồn tại rồi. Vui lòng nhập mã khác.", IconType.Information);
                    txtMaLoThuoc.Focus();
                    return(false);
                }
            }
            else
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("LoThuocBus.CheckLoThuocExistCode"), IconType.Error);
                return(false);
            }

            return(true);
        }
示例#8
0
        private bool CheckInfo()
        {
            if (cboThuoc.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng chọn 1 thuốc.", IconType.Information);
                cboThuoc.Focus();
                return(false);
            }

            if (_dataSource != null && _dataSource.Rows.Count > 0)
            {
                foreach (DataRow row in _dataSource.Rows)
                {
                    string tenThuoc = row["TenThuoc"].ToString();

                    if (_isNew)
                    {
                        if (tenThuoc.Trim().ToLower() == cboThuoc.Text.Trim().ToLower())
                        {
                            MsgBox.Show(this.Text, string.Format("Thuốc '{0}' đã được kê toa rồi. Vui lòng chọn thuốc khác.", cboThuoc.Text), IconType.Information);
                            cboThuoc.Focus();
                            return(false);
                        }
                    }
                    else
                    {
                        string chiTietToaThuocGUID = string.Empty;
                        if (row["ChiTietToaThuocGUID"] != null && row["ChiTietToaThuocGUID"] != DBNull.Value)
                        {
                            chiTietToaThuocGUID = row["ChiTietToaThuocGUID"].ToString();
                        }

                        if (tenThuoc.Trim().ToLower() == cboThuoc.Text.Trim().ToLower() &&
                            _chiTietToaThuoc.ChiTietToaThuocGUID.ToString() != chiTietToaThuocGUID)
                        {
                            MsgBox.Show(this.Text, string.Format("Thuốc '{0}' đã được kê toa rồi. Vui lòng chọn thuốc khác.", cboThuoc.Text), IconType.Information);
                            cboThuoc.Focus();
                            return(false);
                        }
                    }
                }
            }

            if (cboThuoc.SelectedValue != null && cboThuoc.Text.Trim() != string.Empty && cboThuoc.SelectedValue.ToString() != Guid.Empty.ToString())
            {
                string maThuocGUID = cboThuoc.SelectedValue.ToString();
                int    soLuong     = (int)numSoLuong.Value;
                Result result      = LoThuocBus.CheckThuocTonKho(maThuocGUID, soLuong);
                if (result.IsOK)
                {
                    if (!Convert.ToBoolean(result.QueryResult))
                    {
                        MsgBox.Show(this.Text, string.Format("Thuốc '{0}' đã hết hoặc không đủ số lượng để bán. Vui lòng chọn thuốc khác.", cboThuoc.Text), IconType.Information);
                        return(false);
                    }
                }
                else
                {
                    MsgBox.Show(this.Text, result.GetErrorAsString("LoThuocBus.CheckThuocTonKho"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("LoThuocBus.CheckThuocTonKho"));
                    return(false);
                }

                result = LoThuocBus.CheckThuocHetHan(maThuocGUID);
                if (result.IsOK)
                {
                    if (Convert.ToBoolean(result.QueryResult))
                    {
                        MsgBox.Show(this.Text, string.Format("Thuốc '{0}' đã hết hạn sử dụng. Vui lòng chọn thuốc khác.", cboThuoc.Text), IconType.Information);
                        return(false);
                    }
                }
                else
                {
                    MsgBox.Show(this.Text, result.GetErrorAsString("LoThuocBus.CheckThuocHetHan"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("LoThuocBus.CheckThuocHetHan"));
                    return(false);
                }
            }

            return(true);
        }
示例#9
0
        private void OnDeleteLoThuoc()
        {
            if (_dictLoThuoc == null)
            {
                return;
            }
            List <string>  deletedLoThuocList = new List <string>();
            List <DataRow> deletedRows        = _dictLoThuoc.Values.ToList();

            if (deletedRows.Count > 0)
            {
                foreach (DataRow row in deletedRows)
                {
                    string key = row["LoThuocGUID"].ToString();
                    Result rs  = LoThuocBus.GetLoThuoc(key);
                    if (!rs.IsOK)
                    {
                        MsgBox.Show(Application.ProductName, rs.GetErrorAsString("LoThuocBus.GetLoThuoc"), IconType.Error);
                        Utility.WriteToTraceLog(rs.GetErrorAsString("LoThuocBus.GetLoThuoc"));
                        return;
                    }

                    LoThuoc lt = rs.QueryResult as LoThuoc;
                    if (lt.SoLuongXuat > 0)
                    {
                        MsgBox.Show(Application.ProductName, string.Format("Lô thuốc: '{0}' này đã xuất rồi không thể xóa.", lt.TenLoThuoc),
                                    IconType.Information);
                        return;
                    }
                }

                if (MsgBox.Question(Application.ProductName, "Bạn có muốn xóa những lô thuốc mà bạn đã đánh dấu ?") == DialogResult.Yes)
                {
                    List <string> noteList = new List <string>();

                    foreach (DataRow row in deletedRows)
                    {
                        string     loThuocGUID = row["LoThuocGUID"].ToString();
                        string     maLoThuoc   = row["MaLoThuoc"].ToString();
                        dlgLyDoXoa dlg         = new dlgLyDoXoa(maLoThuoc, 3);
                        if (dlg.ShowDialog(this) == DialogResult.OK)
                        {
                            noteList.Add(dlg.Notes);
                            deletedLoThuocList.Add(loThuocGUID);
                        }
                    }

                    if (deletedLoThuocList.Count > 0)
                    {
                        Result result = LoThuocBus.DeleteLoThuoc(deletedLoThuocList, noteList);
                        if (result.IsOK)
                        {
                            DataTable dt = dgLoThuoc.DataSource as DataTable;
                            if (dt == null || dt.Rows.Count <= 0)
                            {
                                return;
                            }

                            foreach (string key in deletedLoThuocList)
                            {
                                DataRow[] rows = dt.Select(string.Format("LoThuocGUID='{0}'", key));
                                if (rows == null || rows.Length <= 0)
                                {
                                    continue;
                                }
                                dt.Rows.Remove(rows[0]);

                                _dictLoThuoc.Remove(key);
                                rows = _dtTemp.Select(string.Format("LoThuocGUID='{0}'", key));
                                if (rows != null && rows.Length > 0)
                                {
                                    _dtTemp.Rows.Remove(rows[0]);
                                }
                            }
                        }
                        else
                        {
                            MsgBox.Show(Application.ProductName, result.GetErrorAsString("LoThuocBus.DeleteLoThuoc"), IconType.Error);
                            Utility.WriteToTraceLog(result.GetErrorAsString("LoThuocBus.DeleteLoThuoc"));
                        }
                    }
                }
            }
            else
            {
                MsgBox.Show(Application.ProductName, "Vui lòng đánh dấu những lô thuốc cần xóa.", IconType.Information);
            }
        }