public void Validate_WhenMultipleErrors_ReturnsAllErrors()
        {
            var validator = new Validator();

            var chi = new ItemValidator();

            chi.PrimaryConstraint = (PrimaryConstraint)Validator.CreateConstraint("chi", Consequence.Wrong);
            var prediction = new Prediction(new ChiSexPredictor(), "gender");

            chi.AddSecondaryConstraint(prediction);
            validator.AddItemValidator(chi, "chi", typeof(string));

            var         age           = new ItemValidator();
            BoundDouble ageConstraint = (BoundDouble)Validator.CreateConstraint("bounddouble", Consequence.Wrong);

            ageConstraint.Lower = 0;
            ageConstraint.Upper = 30;
            age.AddSecondaryConstraint(ageConstraint);
            validator.AddItemValidator(age, "age", typeof(int));

            var row = new Dictionary <string, object>();

            row.Add("chi", TestConstants._INVALID_CHI_CHECKSUM);
            row.Add("age", 31);
            row.Add("gender", "F");

            ValidationFailure result = validator.Validate(row);

            Assert.AreEqual(2, result.GetExceptionList().Count);
        }
    public void CombinationIsInitTwoTest()
    {
        Descriptor desc = ScriptableObject.CreateInstance <Descriptor>();

        desc.name = "Descriptor";

        DescriptorValidator descVal = ScriptableObject.CreateInstance <DescriptorValidator>();

        descVal.descriptor = desc;

        ItemValidator itemVal = ScriptableObject.CreateInstance <ItemValidator>();

        itemVal.name = "Item";

        Combination comb = ScriptableObject.CreateInstance <Combination>();

        comb.itemValidator1 = descVal;
        comb.itemValidator2 = itemVal;

        bool isInit = comb.IsInitialized();

        Assert.IsTrue(isInit);

        ScriptableObject.DestroyImmediate(comb);
        ScriptableObject.DestroyImmediate(itemVal);
        ScriptableObject.DestroyImmediate(descVal);
        ScriptableObject.DestroyImmediate(desc);
    }
        private BulkTestsData SetupTestData(out ColumnInfo l2ColumnInfo)
        {
            //Setup test data
            var testData = new BulkTestsData(CatalogueRepository, DiscoveredDatabaseICanCreateRandomTablesIn);

            testData.SetupTestData();
            testData.ImportAsCatalogue();

            //Setup some validation rules
            Validator v = new Validator();

            //rule is that previous address line 1 cannot be the same as previous address line 2
            var iv = new ItemValidator("previous_address_L1");

            l2ColumnInfo = testData.columnInfos.Single(c => c.GetRuntimeName().Equals("previous_address_L2"));

            //define the secondary constraint
            var referentialConstraint = new ReferentialIntegrityConstraint(CatalogueRepository);

            referentialConstraint.InvertLogic     = true;
            referentialConstraint.OtherColumnInfo = l2ColumnInfo;

            //add it to the item validator for previous_address_L1
            iv.SecondaryConstraints.Add(referentialConstraint);

            //add the completed item validator to the validator (normally there would be 1 item validator per column with validation but in this test we only have 1)
            v.ItemValidators.Add(iv);

            testData.catalogue.ValidatorXML = v.SaveToXml();
            testData.catalogue.SaveToDatabase();

            return(testData);
        }
Exemple #4
0
        /// <summary>
        /// Validate spread row.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="forceValidate">force to validate.</param>
        /// <returns></returns>
        private bool ValidateRowSpread(int row, bool forceValidate)
        {
            if (!forceValidate && !m_bRowHasModified)
            {
                return(true);
            }

            //Check item
            string   itemCode = shtIssueList.Cells[row, (int)eColView.ITEM_CODE].Text;
            NZString LocCD    = new NZString(cboFromLoc, cboFromLoc.SelectedValue);
            NZString LotNo    = new NZString(null, shtIssueList.Cells[row, (int)eColView.LOT_NO].Value);

            if (String.IsNullOrEmpty(itemCode))
            {
                ErrorItem error = new ErrorItem(null, TKPMessages.eValidate.VLM0006.ToString());
                MessageDialog.ShowBusiness(this, error.Message);
                return(false);
            }
            else
            {
                ItemValidator     itemValidator = new ItemValidator();
                BusinessException error         = itemValidator.CheckItemNotExist(itemCode.ToNZString());
                if (error != null)
                {
                    MessageDialog.ShowBusiness(this, error.Error.Message);
                    return(false);
                }
            }

            // ถ้า Validate Row ผ่าน แสดงว่า แถวนั้นไม่จำเป็นต้องเช็คอีกรอบ
            m_bRowHasModified = false;
            return(true);
        }
 public void Setup()
 {
     mapper    = BaseTest.GetMapper();
     context   = BaseTest.GetContext();
     validator = BaseTest.GetValidator();
     service   = new ItemService(context, validator, mapper);
 }
Exemple #6
0
        public void GetItemValidator_InitialisedState_ReturnsNullItemValidator()
        {
            var           validator     = new Validator();
            ItemValidator itemValidator = validator.GetItemValidator("non-existent");

            Assert.Null(itemValidator);
        }
 public static void FindControls(string id, Control ctrlToFind, ref ArrayList ctrls, ItemValidator valid)
 {
     foreach (Control ctrl in ctrlToFind.Controls)
     {
         if (ctrl.ID == id && valid(ctrl)) ctrls.Add(ctrl);
         FindControls(id, ctrl, ref ctrls, valid);
     }
 }
Exemple #8
0
        /// <summary>
        /// Validate เมื่อ Cell มีการแก้ไขเรียบร้อย  และค่าที่แก้ไขเป็นค่าใหม่
        /// </summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        private bool ValidateCellEdited(int row, int column)
        {
            if (column == (int)eColView.ITEM_CD)
            {
                ItemValidator itemValidator = new ItemValidator();

                object objItemCode = shtView.GetValue(row, column);
                if (objItemCode != null)
                {
                    NZString itemCode  = new NZString(null, objItemCode);
                    bool     bLoadItem = LoadItemIntoRow(row, itemCode);
                    if (!bLoadItem)
                    {
                        return(false);
                    }
                }
            }
            else if (column == (int)eColView.ORDER_QTY)
            {
                try
                {
                    NZDecimal orderRate = new NZDecimal(null, shtView.Cells[row, (int)eColView.ORDER_UM_RATE].Value);
                    NZDecimal invRate   = new NZDecimal(null, shtView.Cells[row, (int)eColView.INV_UM_RATE].Value);
                    NZDecimal orderQty  = new NZDecimal(null, shtView.Cells[row, (int)eColView.ORDER_QTY].Value);
                    NZDecimal price     = new NZDecimal(null, shtView.Cells[row, (int)eColView.PRICE].Value);

                    decimal invQty = (invRate.NVL(0) / orderRate.NVL(1)) * orderQty.NVL(0);
                    decimal amount = price.NVL(0) * orderQty.NVL(0);

                    shtView.Cells[row, (int)eColView.QTY].Value    = invQty;
                    shtView.Cells[row, (int)eColView.AMOUNT].Value = amount;
                }
                catch
                {
                    shtView.Cells[row, (int)eColView.AMOUNT].Value = 0;
                    shtView.Cells[row, (int)eColView.QTY].Value    = 0;
                }
            }

            else if (column == (int)eColView.PRICE)
            {
                try
                {
                    NZDecimal orderQty = new NZDecimal(null, shtView.Cells[row, (int)eColView.ORDER_QTY].Value);
                    NZDecimal price    = new NZDecimal(null, shtView.Cells[row, (int)eColView.PRICE].Value);

                    decimal amount = price.NVL(0) * orderQty.NVL(0);

                    shtView.Cells[row, (int)eColView.AMOUNT].Value = amount;
                }
                catch
                {
                    shtView.Cells[row, (int)eColView.AMOUNT].Value = 0;
                }
            }

            return(true);
        }
Exemple #9
0
        private bool LoadItemIntoRow(int row, NZString ITEM_CD)
        {
            ItemValidator itemValidator = new ItemValidator();

            if (ITEM_CD != null)
            {
                BusinessException error = itemValidator.CheckItemNotExist(ITEM_CD);
                if (error != null)
                {
                    shtView.Cells[row, (int)eColView.ITEM_DESC].Value     = null;
                    shtView.Cells[row, (int)eColView.ORDER_UM_CLS].Value  = null;
                    shtView.Cells[row, (int)eColView.INV_UM_CLS].Value    = null;
                    shtView.Cells[row, (int)eColView.ORDER_UM_RATE].Value = null;
                    shtView.Cells[row, (int)eColView.INV_UM_RATE].Value   = null;
                    return(false);
                }

                ItemBIZ itemBIZ = new ItemBIZ();
                ItemDTO itemDTO = itemBIZ.LoadItem(ITEM_CD);
                shtView.Cells[row, (int)eColView.ITEM_CD].Value   = itemDTO.ITEM_CD.Value;
                shtView.Cells[row, (int)eColView.ITEM_DESC].Value = itemDTO.ITEM_DESC.Value;
                //shtView.Cells[row, (int)eColView.ORDER_UM_CLS].Value = itemDTO.ORDER_UM_CLS.Value;
                //shtView.Cells[row, (int)eColView.INV_UM_CLS].Value = itemDTO.INV_UM_CLS.Value;
                //shtView.Cells[row, (int)eColView.ORDER_UM_RATE].Value = itemDTO.ORDER_UM_RATE.Value;
                //shtView.Cells[row, (int)eColView.INV_UM_RATE].Value = itemDTO.INV_UM_RATE.Value;

                //shtView.Cells[row, (int)eColView.LOT_CONTROL_CLS].Value = itemDTO.LOT_CONTROL_CLS.Value;



                //if (itemDTO.LOT_CONTROL_CLS == DataDefine.Convert2ClassCode(DataDefine.eLOT_CONTROL_CLS.Yes))
                //{
                //    //shtView.Cells[row, (int)eColView.LOT_NO].Value = dtReceiveDate.Value.Value.ToString(DataDefine.LOT_NO_FORMAT);

                //    if (rdoReceive.Checked)
                //    {
                //        RunningNumberBIZ runningNoBiz = new RunningNumberBIZ();

                //        NZString strLotNoPrefix = runningNoBiz.GenerateLotNoPrefix(new NZDateTime(null, dtReceiveDate.Value));
                //        NZInt iLastRunningNo = runningNoBiz.GetLastLotNoRunningBox(strLotNoPrefix, new NZString(cboStoredLoc, (string)cboStoredLoc.SelectedValue), itemDTO.ITEM_CD, new NZInt(null, 0));

                //        ReceivingEntryController rcvController = new ReceivingEntryController();
                //        NZString strLotNo = rcvController.GenerateLotNo(strLotNoPrefix, ref iLastRunningNo);
                //        shtView.Cells[row, (int)eColView.LOT_NO].Value = strLotNo.StrongValue;

                //    }
                //}
                //else
                //{
                //    shtView.Cells[row, (int)eColView.LOT_NO].Value = null;
                //}

                ItemProcessDTO processDTO = itemBIZ.LoadItemProcess(ITEM_CD);
                //shtView.Cells[row, (int)eColView.LOT_SIZE].Value = processDTO.LOT_SIZE.NVL(0);
            }

            return(true);
        }
Exemple #10
0
        private void ValidateBeforeSave()
        {
            AdjustmentValidator  adjustmentValidator = new AdjustmentValidator();
            ItemValidator        itemValidator       = new ItemValidator();
            DealingValidator     locationValidator   = new DealingValidator();
            TransactionValidator valTran             = new TransactionValidator();
            CommonBizValidator   commonVal           = new CommonBizValidator();

            ValidateException.ThrowErrorItem(adjustmentValidator.CheckEmptyAdjustDate(new NZDateTime(dtAdjustDate, dtAdjustDate.Value)));
            ValidateException.ThrowErrorItem(adjustmentValidator.CheckEmptyReasonCode(new NZString(cboReasonCode, cboReasonCode.SelectedValue)));
            ValidateException.ThrowErrorItem(valTran.DateIsInCurrentPeriod(new NZDateTime(dtAdjustDate, dtAdjustDate.Value)));
            ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(new NZString(txtMasterNo, txtMasterNo.Text.Trim())));
            ValidateException.ThrowErrorItem(locationValidator.CheckEmptyLocationCode(new NZString(cboStoredLoc, cboStoredLoc.SelectedValue)));

            if (cboStoredLoc.SelectedValue == null)
            {
                return;
            }

            string strProcess = cboStoredLoc.SelectedValue.ToString();
            DealingConstraintDTO constriant = bizConstraint.LoadDealingConstraint(strProcess.ToNZString());

            AdjustmentValidator validator = new AdjustmentValidator();
            ErrorItem           errorItem = null;

            //if (constriant != null && constriant.ENABLE_PACK_FLAG.StrongValue == 1)
            //{
            //    errorItem = validator.CheckEmptyPackNo(txtPackNo.ToNZString());
            //    if (null != errorItem)
            //        ValidateException.ThrowErrorItem(errorItem);//error.AddError(errorItem);
            //}

            if (rdoDecrease.Checked && constriant != null && constriant.ENABLE_PACK_FLAG.StrongValue == 1)
            {
                errorItem = validator.CheckEmptyPackNo(txtPackNo.ToNZString());
                if (null != errorItem)
                {
                    ValidateException.ThrowErrorItem(errorItem);
                }
            }

            if (constriant != null && constriant.ENABLE_LOT_FLAG.StrongValue == 1)
            {
                errorItem = validator.CheckEmptyLotNo(txtLotNo.ToNZString());
                if (null != errorItem)
                {
                    ValidateException.ThrowErrorItem(errorItem);//error.AddError(errorItem);
                }
                FormatUtil.CheckFormatLotNo(new NZString(txtLotNo, txtLotNo.Text.Trim()));

                //errorItem = validator.CheckEmptyCustomerLotNo(txtCustomerLotNo.ToNZString());
                //if (null != errorItem)
                //    ValidateException.ThrowErrorItem(errorItem);//error.AddError(errorItem);
            }

            ValidateException.ThrowErrorItem(adjustmentValidator.CheckEmptyAdjustQty(new NZDecimal(txtAdjustQty, txtAdjustQty.Decimal)));
            ValidateException.ThrowErrorItem(adjustmentValidator.CheckIsZeroAdjustQty(new NZDecimal(txtAdjustQty, txtAdjustQty.Decimal)));
        }
Exemple #11
0
        private void ValidateBeforeSave()
        {
            ItemValidator itemValidator = new ItemValidator();

            ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(txtMasterNo.Text.ToNZString()));

            //PackingValidator validator = new PackingValidator();
            //ValidateException.ThrowErrorItem(validator.CheckEmptyFGNo(txtFGNo.Text.ToNZString()));
        }
        private void lbMissingReferences_MouseDown(object sender, MouseEventArgs e)
        {
            int indexFromPoint = lbMissingReferences.IndexFromPoint(e.X, e.Y);

            if (indexFromPoint != ListBox.NoMatches)
            {
                _dragTarget = lbMissingReferences.Items[indexFromPoint] as ItemValidator;
            }
        }
        private static Validator CreateParentDobValidator(BoundDate b)
        {
            var v = new Validator();
            var i = new ItemValidator();

            i.AddSecondaryConstraint(b);
            v.AddItemValidator(i, "parent_dob", typeof(DateTime));

            return(v);
        }
        private static Validator CreateOperationDateValidator(BoundDate b)
        {
            var v = new Validator();
            var i = new ItemValidator();

            i.AddSecondaryConstraint(b);
            v.AddItemValidator(i, "operation_date", typeof(DateTime));

            return(v);
        }
Exemple #15
0
        /// <summary>
        /// Uses the Published Item Comparer
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public string Execute(FieldGutterArgs args)
        {
            if (args.InnerItem == null)
            {
                return(string.Format("<span title=\"The item could not be retrieved from Sitecore.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></span>"));
            }

            if (args.InnerItem.Database != null && args.InnerItem.Database.Name.ToLower() == "core")
            {
                return(string.Empty);
            }

            //verify settings item exists
            ItemComparerSettingsItem settingsItem = ItemComparerSettingsItem.GetSettingsItem();

            if (settingsItem == null)
            {
                Logger.Error("Published Item Comparer: The Settings Item Could not be retrieved.");
                return("<span title=\"The settings item could not be retrieved from Sitecore.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></span>");
            }

            //verify target database
            Database targetDatabase = ItemComparerUtil.GetTargetDatabase();

            if (targetDatabase == null)
            {
                Logger.Error("Published Item Comparer: The Target Database Could not be retrieved.");
                return("<span title=\"The target database could not be retrieved from Sitecore.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></span>");
            }

            try
            {
                ItemComparerContext context = new ItemComparerContext();
                context.Item = args.InnerItem;
                context.ItemComparerSettingsItem = settingsItem;
                context.TargetDatabase           = targetDatabase;

                ItemValidator itemValidator = new ItemValidator();
                List <string> validations   = itemValidator.Validate(context);
                if (validations != null && validations.Count > 0)
                {
                    return(string.Format("<span title=\"The item did not pass validation.\"><a href=\"#\" style=\"border:0;padding:0;\" class=\"itemComparerGutterLink\" onclick=\"FieldSuite.Fields.OpenItemComparer('{0}','{1}')\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></a></span>", args.InnerItem.ID, args.FieldId));
                }

                return("<span title=\"The item passed validation.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_green.png\"/></span>");
            }
            catch (Exception e)
            {
                Logger.Error("Field Gutter - Published Item Comparer: Error trying to validate");
                Logger.Error(e.InnerException);
                Logger.Error(e.Message);
            }

            return(string.Empty);
        }
Exemple #16
0
        private static Validator CreateInitialisedValidatorWithNoPrimaryConstraint(SecondaryConstraint prediction)
        {
            var i = new ItemValidator();

            i.SecondaryConstraints.Add(prediction);

            var v = new Validator();

            v.AddItemValidator(i, "chi", typeof(string));
            return(v);
        }
        public bool TryToUseItemOnPokemon(IPokemon targetPokemon)
        {
            bool pokemonIsEligibleToReceiveItem = ItemValidator.CanUsePotionOnPokemon(targetPokemon);

            if (pokemonIsEligibleToReceiveItem)
            {
                targetPokemon.CurrentHealthPoints += GetPositiveDifferenceInHealthPoints(targetPokemon);
            }

            return(pokemonIsEligibleToReceiveItem);
        }
Exemple #18
0
        private static Validator CreateValidatorForNonExistentProperty()
        {
            var validator     = new Validator();
            var itemValidator = new ItemValidator {
                PrimaryConstraint = (PrimaryConstraint)Validator.CreateConstraint("chi", Consequence.Wrong)
            };

            validator.AddItemValidator(itemValidator, "non-existent", typeof(string));

            return(validator);
        }
Exemple #19
0
        public void ReturnAnEnumerableWhenCallingGetAll()
        {
            var     myProfile              = new PopipProfile();
            var     configuration          = new MapperConfiguration(cfg => cfg.AddProfile(myProfile));
            IMapper mapper                 = new Mapper(configuration);
            IValidator <ItemDto> validator = new ItemValidator();
            var serv = new ItemService(itemRepositoryMock.Object, mapper, validator);

            var elements = serv.GetAll();

            Assert.NotNull(elements);
        }
Exemple #20
0
        private static void ValidateItem(PantryItem item)
        {
            if (ItemValidator.NameIsEmpty(item))
            {
                throw new ValidationException("Item name cannot be empty!");
            }

            if (ItemValidator.QuantityIsEmpty(item))
            {
                throw new ValidationException("Item quantity cannot be empty!");
            }
        }
Exemple #21
0
        protected void OnJobStart(Message message)
        {
            var uri = ItemUri.ParseQueryString();

            if (uri != null)
            {
                var validator = new ItemValidator {
                    ItemUri = uri, Cookies = HttpContext.Current.Request.Cookies
                };
                Monitor.Start("Preview", "Crownpeak", new JobWorker(validator).GetPreview);
            }
        }
Exemple #22
0
        private void DeleteItem()
        {
            try
            {
                if (shtItemView.Rows.Count == 0)
                {
                    return;
                }
                if (shtItemView.ActiveRowIndex < 0)
                {
                    return;
                }

                NZString ItemCD = new NZString(null, shtItemView.Cells[shtItemView.ActiveRowIndex, (int)eColView.ITEM_CD].Text);

                ItemValidator validator = new ItemValidator();
                ErrorItem     errorItem = validator.ValidateBeforeDelete(ItemCD);
                if (errorItem != null)
                {
                    ValidateException.ThrowErrorItem(errorItem);
                }

                errorItem = validator.CheckExistsTransactionByItem(ItemCD);
                if (errorItem != null)
                {
                    MessageDialog.ShowBusiness(this, errorItem.Message);
                }


                MessageDialogResult dr = MessageDialog.ShowConfirmation(this, new EVOFramework.Message(SystemMaintenance.Messages.eConfirm.CFM9002.ToString()).MessageDescription);
                switch (dr)
                {
                case MessageDialogResult.Cancel:
                    return;

                case MessageDialogResult.No:
                    return;

                case MessageDialogResult.Yes:
                    break;
                }

                ItemController ctlItem = new ItemController();
                ctlItem.DeleteItem(ItemCD);

                shtItemView.RemoveRows(shtItemView.ActiveRowIndex, 1);
            }
            catch (ValidateException err)
            {
                MessageDialog.ShowBusiness(this, err.ErrorResults[0].Message);
                err.ErrorResults[0].FocusOnControl();
            }
        }
Exemple #23
0
        public void CheckIfItemIsAgedBrie()
        {
            var item = new Item()
            {
                Name = "Aged Brie"
            };

            var validator = new ItemValidator();
            var expected  = validator.IsAgedBrie(item);

            Assert.IsTrue(expected);
        }
Exemple #24
0
        public static void Setup(TestContext tc)
        {
            //build startup pipeline for test
            var webHost = Microsoft.AspNetCore.WebHost.CreateDefaultBuilder()
                          .UseStartup <TestStartup>().Build();

            mapper = webHost.Services.GetService(typeof(IMapper)) as IMapper;
            //seed data for item entity
            validator = webHost.Services.GetService(typeof(ItemValidator)) as ItemValidator;
            fakes     = new DatabaseContextFake();
            dbContext = fakes.GetDatabaseItemContext();
        }
Exemple #25
0
        protected virtual void OnSave()
        {
            // Validate data
            try {
                ItemValidator itemValidator = new ItemValidator();
                ValidateException.ThrowErrorItem(itemValidator.CheckEmptyItemCode(txtItemCode.ToNZString()));
                BusinessException itemException = itemValidator.CheckItemNotExist(txtItemCode.ToNZString());
                if (itemException != null)
                {
                    ValidateException.ThrowErrorItem(itemException.Error);
                }

                if (txtUpperQty.Decimal == 0)
                {
                    ValidateException.ThrowErrorItem(new ErrorItem(txtUpperQty, string.Empty, "Can't input zero"));
                }

                if (txtLowerQty.Decimal == 0)
                {
                    ValidateException.ThrowErrorItem(new ErrorItem(txtLowerQty, string.Empty, "Can't input zero"));
                }

                ItemController controller = new ItemController();
                ItemUIDM       uidm       = controller.LoadItem(txtItemCode.Text.Trim().ToNZString());

                BOMRegisterUIDM model = new BOMRegisterUIDM();
                model.ITEM_CD   = uidm.ITEM_CD;
                model.ITEM_DESC = uidm.ITEM_DESC;
                //model.ITEM_CLS = uidm.ITEM_CLS;
                //model.LOT_CONTROL_CLS = uidm.LOT_CONTROL_CLS;
                //model.ORDER_LOC_CD = uidm.ORDER_LOC_CD;
                //model.STORE_LOC_CD = uidm.STORE_LOC_CD;
                //model.ORDER_PROCESS_CLS = uidm.ORDER_PROCESS_CLS;
                //model.CONSUMTION_CLS = uidm.CONSUMTION_CLS;
                //model.PACK_SIZE = uidm.PACK_SIZE;
                //model.INV_UM_CLS = uidm.INV_UM_CLS;
                //model.ORDER_UM_CLS = uidm.ORDER_UM_CLS;
                //model.INV_UM_RATE = uidm.INV_UM_RATE;
                //model.ORDER_UM_RATE = uidm.ORDER_UM_RATE;
                model.LOWER_QTY.Value          = txtLowerQty.Decimal;
                model.UPPER_QTY.Value          = txtUpperQty.Decimal;
                model.CHILD_ORDER_LOC_CD.Value = (chkChildOrderLoc.Checked ? null : (string)cboOrderLoc.SelectedValue);
                model.MRP_FLAG.Value           = (chkMRPFlag.Checked ? null : (string)cboMRPFlag.SelectedValue);

                m_model = model;

                this.Close();
            }
            catch (ValidateException err) {
                MessageDialog.ShowBusiness(this, err.ErrorResults[0].Message);
                err.ErrorResults[0].FocusOnControl();
            }
        }
Exemple #26
0
        public int AddNew(ItemDTO dtoItem, List <ItemProcessDTO> NewProcess, List <BOMDTO> NewComponent, List <ItemMachineDTO> NewItemMachine)
        {
            ItemValidator validator = new ItemValidator();

            validator.ValidateBeforeSaveNew(dtoItem, null);

            Database db = CommonLib.Common.CurrentDatabase;

            db.KeepConnection = true;
            db.BeginTransaction();
            try
            {
                ItemDAO daoItem = new ItemDAO(CommonLib.Common.CurrentDatabase);
                daoItem.AddNew(null, dtoItem);

                ItemProcessDAO daoItemProcess = new ItemProcessDAO(CommonLib.Common.CurrentDatabase);
                BOMDAO         daoBOM         = new BOMDAO(CommonLib.Common.CurrentDatabase);
                ItemMachineDAO daoItemMachine = new ItemMachineDAO(CommonLib.Common.CurrentDatabase);

                foreach (ItemProcessDTO dto in NewProcess)
                {
                    daoItemProcess.AddNew(null, dto);
                }

                //Component
                foreach (BOMDTO dto in NewComponent)
                {
                    daoBOM.AddNew(null, dto);
                }

                //Item Machine
                foreach (ItemMachineDTO dto in NewItemMachine)
                {
                    daoItemMachine.AddNew(null, dto);
                }

                db.Commit();
                return(1);
            }
            catch (Exception err)
            {
                db.Rollback();
                throw err;
            }
            finally
            {
                if (db.DBConnectionState == ConnectionState.Open)
                {
                    db.Close();
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// Validate spread row.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="forceValidate">force to validate.</param>
        /// <returns></returns>
        private bool ValidateRowSpread(int row, bool forceValidate)
        {
            if (!forceValidate && !m_bRowHasModified)
            {
                return(true);
            }

            //Check item
            string itemCode = shtCustomerOrder.Cells[row, (int)eColView.ITEM_CD].Text;

            if (String.IsNullOrEmpty(itemCode))
            {
                ErrorItem error = new ErrorItem(null, TKPMessages.eValidate.VLM0006.ToString());
                MessageDialog.ShowBusiness(this, error.Message);
                return(false);
            }
            else
            {
                ItemValidator     itemValidator = new ItemValidator();
                BusinessException error         = itemValidator.CheckItemNotExist(itemCode.ToNZString());
                if (error != null)
                {
                    MessageDialog.ShowBusiness(this, error.Error.Message);
                    return(false);
                }
            }

            // Check ReceiveQty
            //NZDecimal qty = new NZDecimal(null, shtCustomerOrder.Cells[row, (int)eColView.ISSUE_QTY].Value);
            //if (qty.IsNull || qty.StrongValue == decimal.Zero)
            //{
            //    ErrorItem error = new ErrorItem(null, TKPMessages.eValidate.VLM0039.ToString());
            //    MessageDialog.ShowBusiness(this, error.Message);
            //    return false;
            //}

            //NZDecimal onhandqty = new NZDecimal(null, shtCustomerOrder.Cells[row, (int)eColView.ONHAND_QTY].Value);
            //if (onhandqty.IsNull || onhandqty.StrongValue == decimal.Zero)
            //{
            //    onhandqty.Value = 0;
            //}
            //if (qty.StrongValue > onhandqty.StrongValue)
            //{
            //    ErrorItem error = new ErrorItem(null, TKPMessages.eValidate.VLM0040.ToString());
            //    MessageDialog.ShowBusiness(this, error.Message);
            //    return false;
            //}

            // ถ้า Validate Row ผ่าน แสดงว่า แถวนั้นไม่จำเป็นต้องเช็คอีกรอบ
            m_bRowHasModified = false;
            return(true);
        }
Exemple #28
0
        public IActionResult Add([FromForm] ItemRequest item)
        {
            var validator        = new ItemValidator();
            var validationResult = validator.Validate(item);

            if (validationResult.IsValid)
            {
                var newItem = _mapper.Map <Item>(item);
                _itemService.Add(newItem);
                return(Ok());
            }
            return(BadRequest());
        }
Exemple #29
0
        protected void OnJobStart(Message message)
        {
            var uri = ItemUri.ParseQueryString();

            if (uri != null)
            {
                var checkpointId = HttpContext.Current.Request.QueryString["checkpointId"];
                var validator    = new ItemValidator {
                    ItemUri = uri, CheckpointId = checkpointId, Cookies = HttpContext.Current.Request.Cookies
                };
                Monitor.Start("Source", "Crownpeak", new JobWorker(validator).GetSource);
            }
        }
        public void Delete(T item)
        {
            ItemValidator.Validate(item).OnDelete();

            var itemIndex = Items.FindIndex(x => x.Id == item.Id);

            if (itemIndex == -1)
            {
                return;
            }

            Items.RemoveAt(itemIndex);
            PersistState();
        }
Exemple #31
0
        private void SetupAdditionalValidationRules(ICheckNotifier notifier)
        {
            //for each description
            foreach (QueryTimeColumn descQtc in _queryBuilder.SelectColumns.Where(qtc => qtc.IsLookupDescription))
            {
                try
                {
                    //if we have a the foreign key too
                    var foreignQtc = _queryBuilder.SelectColumns.SingleOrDefault(fk => fk.IsLookupForeignKey && fk.LookupTable.ID == descQtc.LookupTable.ID);
                    if (foreignQtc != null)
                    {
                        var descriptionFieldName = descQtc.IColumn.GetRuntimeName();
                        var foreignKeyFieldName  = foreignQtc.IColumn.GetRuntimeName();

                        ItemValidator itemValidator = _validator.GetItemValidator(foreignKeyFieldName);

                        //there is not yet one for this field
                        if (itemValidator == null)
                        {
                            itemValidator = new ItemValidator(foreignKeyFieldName);
                            _validator.ItemValidators.Add(itemValidator);
                        }

                        //if it doesn't already have a prediction
                        if (itemValidator.SecondaryConstraints.All(constraint => constraint.GetType() != typeof(Prediction)))
                        {
                            //Add an item validator onto the fk column that targets the description column with a nullness prediction
                            var newRule = new Prediction(new ValuePredictsOtherValueNullness(), descriptionFieldName);
                            newRule.Consequence = Consequence.Missing;

                            //add one that says 'if I am null my fk should also be null'
                            itemValidator.SecondaryConstraints.Add(newRule);

                            notifier.OnCheckPerformed(
                                new CheckEventArgs(
                                    "Dynamically added value->value Nullnes constraint with consequence Missing onto columns " +
                                    foreignKeyFieldName + " and " + descriptionFieldName + " because they have a configured Lookup relationship in the Catalogue", CheckResult.Success));
                        }
                    }
                }
                catch (Exception ex)
                {
                    notifier.OnCheckPerformed(
                        new CheckEventArgs(
                            "Failed to add new lookup validation rule for column " +
                            descQtc.IColumn.GetRuntimeName(), CheckResult.Fail, ex));
                }
            }
        }
Exemple #32
0
 /// <summary>
 ///     Constructs a new BibTex Parser.
 /// </summary>
 /// <param name="validator">An <see cref="ItemValidator" /> for validating if an item fulfills given requirements.</param>
 public BibTexParser(ItemValidator validator)
 {
     _validator = validator;
 }
        /// <summary>
        /// Uses the Published Item Comparer
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public string Execute(FieldGutterArgs args)
        {
            if (args.InnerItem == null)
            {
                return string.Format("<span title=\"The item could not be retrieved from Sitecore.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></span>");
            }

            if (args.InnerItem.Database != null && args.InnerItem.Database.Name.ToLower() == "core")
            {
                return string.Empty;
            }

            //verify settings item exists
            ItemComparerSettingsItem settingsItem = ItemComparerSettingsItem.GetSettingsItem();
            if (settingsItem == null)
            {
                Logger.Error("Published Item Comparer: The Settings Item Could not be retrieved.");
                return "<span title=\"The settings item could not be retrieved from Sitecore.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></span>";
            }

            //verify target database
            Database targetDatabase = ItemComparerUtil.GetTargetDatabase();
            if (targetDatabase == null)
            {
                Logger.Error("Published Item Comparer: The Target Database Could not be retrieved.");
                return "<span title=\"The target database could not be retrieved from Sitecore.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></span>";
            }

            try
            {
                ItemComparerContext context = new ItemComparerContext();
                context.Item = args.InnerItem;
                context.ItemComparerSettingsItem = settingsItem;
                context.TargetDatabase = targetDatabase;

                ItemValidator itemValidator = new ItemValidator();
                List<string> validations = itemValidator.Validate(context);
                if (validations != null && validations.Count > 0)
                {
                    return string.Format("<span title=\"The item did not pass validation.\"><a href=\"#\" style=\"border:0;padding:0;\" class=\"itemComparerGutterLink\" onclick=\"FieldSuite.Fields.OpenItemComparer('{0}','{1}')\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></a></span>", args.InnerItem.ID, args.FieldId);
                }

                return "<span title=\"The item passed validation.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_green.png\"/></span>";
            }
            catch (Exception e)
            {
                Logger.Error("Field Gutter - Published Item Comparer: Error trying to validate");
                Logger.Error(e.InnerException);
                Logger.Error(e.Message);
            }

            return string.Empty;
        }
 public ItemFileFixBehaviour()
 {
     Validator = new ItemValidator();
 }