Esempio n. 1
0
        private bool CheckInfo()
        {
            if (txtCode.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập mã nhóm dịch vụ.", IconType.Information);
                txtCode.Focus();
                return(false);
            }

            if (txtName.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập tên nhóm dịch vụ.", IconType.Information);
                txtName.Focus();
                return(false);
            }

            string serviceGroupGUID = _isNew ? string.Empty : _serviceGroup.ServiceGroupGUID.ToString();
            Result result           = ServiceGroupBus.CheckServiceGroupExistCode(serviceGroupGUID, txtCode.Text);

            if (result.Error.Code == ErrorCode.EXIST || result.Error.Code == ErrorCode.NOT_EXIST)
            {
                if (result.Error.Code == ErrorCode.EXIST)
                {
                    MsgBox.Show(this.Text, "Mã nhóm dịch vụ này đã tồn tại rồi. Vui lòng nhập mã khác.", IconType.Information);
                    txtCode.Focus();
                    return(false);
                }
            }
            else
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("ServiceGroupBus.CheckServiceGroupExistCode"), IconType.Error);
                return(false);
            }

            if (dgService.RowCount <= 0)
            {
                MsgBox.Show(this.Text, "Vui lòng chọn ít nhất 1 dịch vụ.", IconType.Information);
                return(false);
            }

            foreach (string serviceGUID in _addedServices)
            {
                result = ServiceGroupBus.CheckServiceExist(serviceGUID);

                if (result.Error.Code == ErrorCode.EXIST || result.Error.Code == ErrorCode.NOT_EXIST)
                {
                    if (result.Error.Code == ErrorCode.EXIST)
                    {
                        string serviceName = GetServiceName(serviceGUID);
                        MsgBox.Show(this.Text, string.Format("Dịch vụ: '{0}' đã thuộc 1 nhóm khác.", serviceName), IconType.Information);

                        DataTable dt = dgService.DataSource as DataTable;
                        if (dt != null)
                        {
                            DataRow[] rows = dt.Select(string.Format("ServiceGUID='{0}'", serviceGUID));
                            if (rows != null && rows.Length > 0)
                            {
                                _addedServices.Remove(rows[0]["ServiceGUID"].ToString());
                                dt.Rows.Remove(rows[0]);
                            }
                        }

                        return(false);
                    }
                }
                else
                {
                    MsgBox.Show(this.Text, result.GetErrorAsString("ServiceGroupBus.CheckServiceExist"), IconType.Error);
                    return(false);
                }
            }

            return(true);
        }