private void cboThuoc_SelectedIndexChanged(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            string khoCapCuuGUID = cboKhoCapCuu.SelectedValue.ToString();
            Result result        = NhapKhoCapCuuBus.GetNgayHetHanCuaKhoCapCuu(khoCapCuuGUID);

            if (!result.IsOK)
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("NhapKhoCapCuuBus.GetNgayHetHanCuaKhoCapCuu"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.GetNgayHetHanCuaKhoCapCuu"));
                return;
            }

            if (result.QueryResult != null)
            {
                dtpkNgayHetHan.Value = Convert.ToDateTime(result.QueryResult);
            }

            result = NhapKhoCapCuuBus.GetKhoCapCuuTonKho(khoCapCuuGUID);
            if (!result.IsOK)
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("NhapKhoCapCuuBus.GetKhoCapCuuTonKho"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.GetKhoCapCuuTonKho"));
                return;
            }

            if (result.QueryResult != null)
            {
                numSoLuongTon.Value = Convert.ToInt32(result.QueryResult);
            }
        }
Beispiel #2
0
        private void OnSaveInfo()
        {
            try
            {
                MethodInvoker method = delegate
                {
                    _nhapKhoCapCuu.NgayNhap        = dtpkNgayNhap.Value;
                    _nhapKhoCapCuu.KhoCapCuuGUID   = Guid.Parse(cboKhoCapCuu.SelectedValue.ToString());
                    _nhapKhoCapCuu.SoDangKy        = txtSoDangKy.Text;
                    _nhapKhoCapCuu.NgaySanXuat     = dtpkNgaySanXuat.Value;
                    _nhapKhoCapCuu.NgayHetHan      = dtpkNgayHetHan.Value;
                    _nhapKhoCapCuu.HangSanXuat     = txtHangSanXuat.Text;
                    _nhapKhoCapCuu.NhaPhanPhoi     = cboNhaPhanPhoi.Text;
                    _nhapKhoCapCuu.SoLuongNhap     = (int)numSoLuongNhap.Value;
                    _nhapKhoCapCuu.GiaNhap         = (double)numGiaNhap.Value;
                    _nhapKhoCapCuu.DonViTinhNhap   = cboDonViTinhNhap.Text;
                    _nhapKhoCapCuu.DonViTinhQuiDoi = txtDonViTinhQuiDoi.Text;
                    _nhapKhoCapCuu.SoLuongQuiDoi   = (int)numSoLuongQuiDoi.Value;
                    _nhapKhoCapCuu.GiaNhapQuiDoi   = (double)numGiaNhapQuiDoi.Value;
                    _nhapKhoCapCuu.SoLuongXuat     = 0;
                    _nhapKhoCapCuu.Status          = (byte)Status.Actived;

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

                    Result result = NhapKhoCapCuuBus.InsertNhapKhoCapCuu(_nhapKhoCapCuu);

                    if (!result.IsOK)
                    {
                        MsgBox.Show(this.Text, result.GetErrorAsString("NhapKhoCapCuuBus.InsertNhapKhoCapCuu"), IconType.Error);
                        Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.InsertNhapKhoCapCuu"));
                        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);
            }
        }
Beispiel #3
0
        private void cmbox_SelectedValueChanged(object sender, EventArgs e)
        {
            if (!_flag)
            {
                return;
            }

            if (dgChiTiet.CurrentCell.ColumnIndex == 1)
            {
                _flag = false;
                DataGridViewComboBoxEditingControl cbo = (DataGridViewComboBoxEditingControl)sender;
                if (cbo.SelectedValue == null || cbo.SelectedValue.ToString() == "System.Data.DataRowView")
                {
                    return;
                }
                string khoCapCuuGUID = cbo.SelectedValue.ToString();

                Result result = NhapKhoCapCuuBus.GetNgayHetHanCuaKhoCapCuu(khoCapCuuGUID);
                if (result.IsOK)
                {
                    if (result.QueryResult != null)
                    {
                        DateTime ngayHetHan = Convert.ToDateTime(result.QueryResult);
                        dgChiTiet.Rows[dgChiTiet.CurrentRow.Index].Cells[3].Value = ngayHetHan;
                    }
                    else
                    {
                        dgChiTiet.Rows[dgChiTiet.CurrentRow.Index].Cells[3].Value = DBNull.Value;
                    }
                }
                else
                {
                    MsgBox.Show(this.Text, result.GetErrorAsString("NhapKhoCapCuuBus.GetNgayHetHanCuaKhoCapCuu"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.GetNgayHetHanCuaKhoCapCuu"));
                }

                result = NhapKhoCapCuuBus.GetKhoCapCuuTonKho(khoCapCuuGUID);
                if (result.IsOK)
                {
                    if (result.QueryResult != null)
                    {
                        int soLuongTon = Convert.ToInt32(result.QueryResult);
                        dgChiTiet.Rows[dgChiTiet.CurrentRow.Index].Cells[4].Value = soLuongTon;
                    }
                    else
                    {
                        dgChiTiet.Rows[dgChiTiet.CurrentRow.Index].Cells[4].Value = DBNull.Value;
                    }
                }
                else
                {
                    MsgBox.Show(this.Text, result.GetErrorAsString("NhapKhoCapCuuBus.GetKhoCapCuuTonKho"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.GetKhoCapCuuTonKho"));
                }
                _flag = true;
            }
        }
        private bool CheckInfo()
        {
            if (cboKhoCapCuu.SelectedValue == null || cboKhoCapCuu.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng chọn thông tin cấp cứu.", IconType.Information);
                cboKhoCapCuu.Focus();
                return(false);
            }

            if (numSoLuongXuat.Value <= 0)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập số lượng xuất.", IconType.Information);
                numSoLuongXuat.Focus();
                return(false);
            }

            string khoCapCuuGUID = cboKhoCapCuu.SelectedValue.ToString();
            Result r             = NhapKhoCapCuuBus.CheckKhoCapCuuTonKho(khoCapCuuGUID, (int)numSoLuongXuat.Value);

            if (r.IsOK)
            {
                if (!Convert.ToBoolean(r.QueryResult))
                {
                    MsgBox.Show(this.Text, string.Format("Cấp cứu '{0}' đã hết hoặc không đủ số lượng để xuất.", cboKhoCapCuu.Text), IconType.Information);
                    return(false);
                }
            }
            else
            {
                MsgBox.Show(this.Text, r.GetErrorAsString("NhapKhoCapCuuBus.CheckKhoCapCuuTonKho"), IconType.Error);
                Utility.WriteToTraceLog(r.GetErrorAsString("NhapKhoCapCuuBus.CheckKhoCapCuuTonKho"));
                return(false);
            }

            r = NhapKhoCapCuuBus.CheckKhoCapCuuHetHan(khoCapCuuGUID);
            if (r.IsOK)
            {
                if (Convert.ToBoolean(r.QueryResult))
                {
                    MsgBox.Show(this.Text, string.Format("Cấp cứu '{0}' đã hết hạn sử dụng.", cboKhoCapCuu.Text), IconType.Information);
                    return(false);
                }
            }
            else
            {
                MsgBox.Show(this.Text, r.GetErrorAsString("NhapKhoCapCuuBus.CheckKhoCapCuuHetHan"), IconType.Error);
                Utility.WriteToTraceLog(r.GetErrorAsString("NhapKhoCapCuuBus.CheckKhoCapCuuHetHan"));
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        private void UpdateNgayHetHanVaSoLuongTon()
        {
            foreach (DataGridViewRow row in dgChiTiet.Rows)
            {
                if (row.Cells["KhoCapCuuGUID"].Value == null || row.Cells["KhoCapCuuGUID"].Value == DBNull.Value ||
                    row.Cells["KhoCapCuuGUID"].Value.ToString() == Guid.Empty.ToString())
                {
                    continue;
                }

                string khoCapCuuGUID = row.Cells["KhoCapCuuGUID"].Value.ToString();
                Result result        = NhapKhoCapCuuBus.GetNgayHetHanCuaKhoCapCuu(khoCapCuuGUID);
                if (result.IsOK)
                {
                    if (result.QueryResult != null)
                    {
                        DateTime ngayHetHan = Convert.ToDateTime(result.QueryResult);
                        row.Cells[3].Value = ngayHetHan;
                    }
                    else
                    {
                        row.Cells[3].Value = DBNull.Value;
                    }
                }
                else
                {
                    MsgBox.Show(this.Text, result.GetErrorAsString("NhapKhoCapCuuBus.GetNgayHetHanCuaKhoCapCuu"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.GetNgayHetHanCuaKhoCapCuu"));
                }

                result = NhapKhoCapCuuBus.GetKhoCapCuuTonKho(khoCapCuuGUID);
                if (result.IsOK)
                {
                    if (result.QueryResult != null)
                    {
                        int soLuongTon = Convert.ToInt32(result.QueryResult);
                        row.Cells[4].Value = soLuongTon;
                    }
                    else
                    {
                        row.Cells[4].Value = DBNull.Value;
                    }
                }
                else
                {
                    MsgBox.Show(this.Text, result.GetErrorAsString("NhapKhoCapCuuBus.GetKhoCapCuuTonKho"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.GetKhoCapCuuTonKho"));
                }
            }
        }
Beispiel #6
0
        private double GetGiaCapCuuNhap()
        {
            double giaCapCuuNhap = 0;
            string khoCapCuuGUID = cboCapCuu.SelectedValue.ToString();
            Result result        = NhapKhoCapCuuBus.GetGiaCapCuuNhap(khoCapCuuGUID);

            if (result.IsOK)
            {
                giaCapCuuNhap = Convert.ToDouble(result.QueryResult);
            }
            else
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("NhapKhoCapCuuBus.GetGiaCapCuuNhap"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.GetGiaCapCuuNhap"));
            }

            return(giaCapCuuNhap);
        }
        private void OnDisplayNhapKhoCapCuuList()
        {
            lock (ThisLock)
            {
                Result result = NhapKhoCapCuuBus.GetNhapKhoCapCuuList(_name, _tuNgay, _denNgay, _isTenCapCuu);
                if (result.IsOK)
                {
                    dgNhapKhoCapCuu.Invoke(new MethodInvoker(delegate()
                    {
                        if (dgNhapKhoCapCuu.CurrentRow != null)
                        {
                            _currentRowIndex = dgNhapKhoCapCuu.CurrentRow.Index;
                        }

                        ClearData();

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

                        if (_currentRowIndex < dt.Rows.Count)
                        {
                            dgNhapKhoCapCuu.CurrentCell = dgNhapKhoCapCuu[0, _currentRowIndex];
                            dgNhapKhoCapCuu.Rows[_currentRowIndex].Selected = true;
                        }
                    }));
                }
                else
                {
                    MsgBox.Show(Application.ProductName, result.GetErrorAsString("NhapKhoCapCuuBus.GetNhapKhoCapCuuList"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.GetNhapKhoCapCuuList"));
                }
            }
        }
Beispiel #8
0
        private bool CheckInfo()
        {
            if (cboKhoCapCuu.SelectedValue == null || cboKhoCapCuu.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng chọn thông tin cấp cứu.", IconType.Information);
                cboKhoCapCuu.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          = NhapKhoCapCuuBus.GetNhapKhoCapCuu(_nhapKhoCapCuu.NhapKhoCapCuuGUID.ToString());
                if (!rs.IsOK)
                {
                    MsgBox.Show(this.Text, rs.GetErrorAsString("NhapKhoCapCuuBus.GetNhapKhoCapCuu"), IconType.Error);
                    return(false);
                }

                int soLuongXuat = (rs.QueryResult as NhapKhoCapCuuView).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);
                }
            }

            return(true);
        }
Beispiel #9
0
        private void OnDisplayNhaPhanPhoiList()
        {
            Cursor.Current = Cursors.WaitCursor;
            Result result = NhapKhoCapCuuBus.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("NhapKhoCapCuuBus.GetNhaPhanPhoiList"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.GetNhaPhanPhoiList"));
            }
        }
        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 (cboMaToaCapCuu.SelectedValue == null || cboMaToaCapCuu.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập mã toa thuốc.", IconType.Information);
                cboMaToaCapCuu.Focus();
                return(false);
            }

            //string phieuThuCapCuuGUID = _isNew ? string.Empty : _phieuThuCapCuu.PhieuThuCapCuuGUID.ToString();
            //Result result = PhieuThuCapCuuBus.CheckPhieuThuCapCuuExistCode(phieuThuCapCuuGUID, 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("PhieuThuCapCuuBus.CheckPhieuThuCapCuuExistCode"), IconType.Error);
            //    return false;
            //}

            if (dgChiTiet.RowCount > 0)
            {
                for (int i = 0; i < dgChiTiet.RowCount; i++)
                {
                    DataGridViewRow row = dgChiTiet.Rows[i];

                    //if (row.Cells["KhoCapCuuGUID"].Value == null || row.Cells["KhoCapCuuGUID"].Value == DBNull.Value ||
                    //row.Cells["KhoCapCuuGUID"].Value.ToString() == string.Empty)
                    //{
                    //    MsgBox.Show(this.Text, "Vui lòng chọn cấp cứu để xuất phiếu thu.", IconType.Information);
                    //    return false;
                    //}

                    string khoCapCuuGUID = row.Cells["KhoCapCuuGUID"].Value.ToString();
                    string tenCapCuu     = GetTenCapCuu(khoCapCuuGUID);

                    if (row.Cells[4].Value.ToString() == "0")
                    {
                        MsgBox.Show(this.Text, string.Format("Cấp cứu '{0}' chưa có nhập giá bán. Vui lòng chọn cấp cứu khác.", tenCapCuu), IconType.Information);
                        return(false);
                    }

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

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

                    r = NhapKhoCapCuuBus.CheckKhoCapCuuHetHan(khoCapCuuGUID);
                    if (r.IsOK)
                    {
                        if (Convert.ToBoolean(r.QueryResult))
                        {
                            MsgBox.Show(this.Text, string.Format("Cấp cứu '{0}' đã hết hạn sử dụng. Vui lòng chọn cấp cứu khác.", tenCapCuu), IconType.Information);
                            return(false);
                        }
                    }
                    else
                    {
                        MsgBox.Show(this.Text, r.GetErrorAsString("NhapKhoCapCuuBus.CheckKhoCapCuuHetHan"), IconType.Error);
                        Utility.WriteToTraceLog(r.GetErrorAsString("NhapKhoCapCuuBus.CheckKhoCapCuuHetHan"));
                        return(false);
                    }
                }
            }
            else
            {
                MsgBox.Show(this.Text, "Vui lòng chọn ít nhất 1 cấp cứu.", IconType.Information);
                return(false);
            }

            //if (dgChiTiet.RowCount > 1)
            //{
            //    for (int i = 0; i < dgChiTiet.RowCount - 1; i++)
            //    {
            //        DataGridViewRow row1 = dgChiTiet.Rows[i];
            //        for (int j = i + 1; j < dgChiTiet.RowCount; j++)
            //        {
            //            DataGridViewRow row2 = dgChiTiet.Rows[j];
            //            if (row1.Cells["KhoCapCuuGUID"].Value.ToString() == row2.Cells["KhoCapCuuGUID"].Value.ToString())
            //            {
            //                string tenCapCuu = GetTenCapCuu(row1.Cells["KhoCapCuuGUID"].Value.ToString());
            //                MsgBox.Show(this.Text, string.Format("Cấp cứu '{0}' đã tồn tại rồi. Vui lòng chọn cấp cứu khác", tenCapCuu), IconType.Information);
            //                return false;
            //            }
            //        }
            //    }
            //}

            return(true);
        }
Beispiel #11
0
        private void OnDelete()
        {
            if (_dictNhapKhoCapCuu == null)
            {
                return;
            }
            List <string>  deletedList = new List <string>();
            List <DataRow> deletedRows = _dictNhapKhoCapCuu.Values.ToList();

            foreach (DataRow row in deletedRows)
            {
                deletedList.Add(row["NhapKhoCapCuuGUID"].ToString());
            }

            if (deletedList.Count > 0)
            {
                foreach (string key in deletedList)
                {
                    Result rs = NhapKhoCapCuuBus.GetNhapKhoCapCuu(key);
                    if (!rs.IsOK)
                    {
                        MsgBox.Show(Application.ProductName, rs.GetErrorAsString("NhapKhoCapCuuBus.GetNhapKhoCapCuu"), IconType.Error);
                        Utility.WriteToTraceLog(rs.GetErrorAsString("NhapKhoCapCuuBus.GetNhapKhoCapCuu"));
                        return;
                    }

                    NhapKhoCapCuuView nkcc = rs.QueryResult as NhapKhoCapCuuView;
                    if (nkcc.SoLuongXuat > 0)
                    {
                        MsgBox.Show(Application.ProductName, string.Format("Cấp cứu: '{0}' này đã xuất rồi không thể xóa.", nkcc.TenCapCuu),
                                    IconType.Information);
                        return;
                    }
                }

                if (MsgBox.Question(Application.ProductName, "Bạn có muốn xóa những thông tin nhập kho cấp cứu mà bạn đã đánh dấu ?") == DialogResult.Yes)
                {
                    Result result = NhapKhoCapCuuBus.DeleteNhapKhoCappCuu(deletedList);
                    if (result.IsOK)
                    {
                        DataTable dt = dgNhapKhoCapCuu.DataSource as DataTable;
                        if (dt == null || dt.Rows.Count <= 0)
                        {
                            return;
                        }

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

                        _dictNhapKhoCapCuu.Clear();
                        _dtTemp.Rows.Clear();
                    }
                    else
                    {
                        MsgBox.Show(Application.ProductName, result.GetErrorAsString("NhapKhoCapCuuBus.DeleteNhapKhoCappCuu"), IconType.Error);
                        Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.DeleteNhapKhoCappCuu"));
                    }
                }
            }
            else
            {
                MsgBox.Show(Application.ProductName, "Vui lòng đánh dấu những thông tin nhập kho cấp cứu cần xóa.", IconType.Information);
            }
        }
Beispiel #12
0
        private bool CheckInfo()
        {
            if (txtMaToaCapCuu.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập mã toa cấp cứu.", IconType.Information);
                txtMaToaCapCuu.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 toaCapCuuGUID = _isNew ? string.Empty : _toaCapCuu.ToaCapCuuGUID.ToString();
            Result result        = KeToaCapCuuBus.CheckToaCapCuuExistCode(toaCapCuuGUID, txtMaToaCapCuu.Text);

            if (result.Error.Code == ErrorCode.EXIST || result.Error.Code == ErrorCode.NOT_EXIST)
            {
                if (result.Error.Code == ErrorCode.EXIST)
                {
                    MsgBox.Show(this.Text, "Mã toa cấp cứu này đã tồn tại rồi. Vui lòng nhập mã khác.", IconType.Information);
                    txtMaToaCapCuu.Focus();
                    return(false);
                }
            }
            else
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("KeToaCapCuuBus.CheckToaCapCuuExistCode"), IconType.Error);
                return(false);
            }

            if (dgChiTiet.RowCount > 1)
            {
                for (int i = 0; i < dgChiTiet.RowCount - 1; i++)
                {
                    DataGridViewRow row = dgChiTiet.Rows[i];

                    if (row.Cells[1].Value == null || row.Cells[1].Value == DBNull.Value || row.Cells[1].Value.ToString() == Guid.Empty.ToString())
                    {
                        MsgBox.Show(this.Text, "Vui lòng nhập cấp cứu.", IconType.Information);
                        return(false);
                    }

                    string khoCapCuuGUID = row.Cells[1].Value.ToString();
                    string tenCapCuu     = GetTenCapCuu(khoCapCuuGUID);

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

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

                    r = NhapKhoCapCuuBus.CheckKhoCapCuuHetHan(khoCapCuuGUID);
                    if (r.IsOK)
                    {
                        if (Convert.ToBoolean(r.QueryResult))
                        {
                            MsgBox.Show(this.Text, string.Format("Cấp cứu '{0}' đã hết hạn sử dụng. Vui lòng chọn cấp cứu khác.", tenCapCuu), IconType.Information);
                            return(false);
                        }
                    }
                    else
                    {
                        MsgBox.Show(this.Text, r.GetErrorAsString("NhapKhoCapCuuBus.CheckKhoCapCuuHetHan"), IconType.Error);
                        Utility.WriteToTraceLog(r.GetErrorAsString("NhapKhoCapCuuBus.CheckKhoCapCuuHetHan"));
                        return(false);
                    }
                }
            }
            else
            {
                MsgBox.Show(this.Text, "Vui lòng chọn ít nhất 1 cấp cứu.", IconType.Information);
                return(false);
            }

            if (dgChiTiet.RowCount > 2)
            {
                for (int i = 0; i < dgChiTiet.RowCount - 2; i++)
                {
                    DataGridViewRow row1 = dgChiTiet.Rows[i];
                    for (int j = i + 1; j < dgChiTiet.RowCount - 1; j++)
                    {
                        DataGridViewRow row2 = dgChiTiet.Rows[j];
                        if (row1.Cells[1].Value.ToString() == row2.Cells[1].Value.ToString())
                        {
                            string tenCapCuu = GetTenCapCuu(row1.Cells[1].Value.ToString());
                            MsgBox.Show(this.Text, string.Format("Cấp cứu '{0}' đã tồn tại rồi. Vui lòng chọn cấp cứu khác", tenCapCuu), IconType.Information);
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }