Example #1
0
        public static bool isValidCandidateForField(string field, string candidate)
        {
            int fieldIndex = getIndexForField(field);

            switch (fieldIndex)
            {
            case 3:    //Security Code
                return(MasterListManager.isExistSecurityCode(candidate));

            case 5:    //Contract Type
                return(ContractNote.isEqual(candidate, "SELL") || ContractNote.isEqual(candidate, "BUY"));
            }
            if (fieldType[fieldIndex] == 'C')
            {
                return(ContractNote.getValidationOfCurrency(ContractNote.getAdjustedCurrency(candidate)));
            }
            if (fieldType[fieldIndex] == 'D')
            {
                return(ContractNote.getValidationOfDate(ContractNote.getAdjustedDate(candidate)));
            }
            if (fieldType[fieldIndex] == 'M')
            {
                if (candidate.Length >= 4 && candidate[candidate.Length - 4] == '-')
                {
                    candidate = candidate.Remove(candidate.Length - 4, 1).Substring(1);
                }
                return(candidate.Length > 1 && ContractNote.getValidationOfNumber(candidate.Substring(1)));
            }
            return(candidate.Length > 0);
        }
Example #2
0
        public void validateContractNoteItems(bool skip = false)
        {
            success = true;
            if (skip)
            {
                for (int i = 0; i < FIELD_COUNT; i++)
                {
                    contractNoteItems[i].Valid = true;
                }
                return;
            }
            if (contractNoteItems[0].Value.Equals("NoTemplate"))
            {
                contractNoteItems[23].Value = "NoTemplate";
            }
            else
            {
                contractNoteItems[23].Value = string.Format(@"{0}-{1}-{2}-{3}", contractNoteItems[0].Value, contractNoteItems[16].Value, contractNoteItems[1].Value, contractNoteItems[14].Value);
            }

            for (int i = 0; i < FIELD_COUNT; i++)
            {
                if (mandatory[i])
                {
                    if (contractNoteItems[i].Value.Equals("NoTemplate"))
                    {
                        contractNoteItems[i].Valid = false;
                    }
                    else
                    {
                        switch (fieldType[i])
                        {
                        case 'N':
                            contractNoteItems[i].Valid = ContractNote.getValidationOfNumber(contractNoteItems[i].Value);
                            break;

                        case 'C':
                            contractNoteItems[i].Valid = ContractNote.getValidationOfCurrency(contractNoteItems[i].Value);
                            break;

                        case 'D':
                            contractNoteItems[i].Valid = ContractNote.getValidationOfDate(contractNoteItems[i].Value);
                            break;

                        case 'B':
                            contractNoteItems[i].Valid = ContractNote.getValidationOfBoolean(contractNoteItems[i].Value);
                            break;

                        default:
                            contractNoteItems[i].Valid = !contractNoteItems[i].Value.Equals("");
                            break;
                        }
                    }
                    if (!contractNoteItems[i].Valid)
                    {
                        success = false;
                    }
                }
            }

            contractNoteItems[4].Valid = contractNoteItems[3].Valid;

            double units         = ContractNote.getCurrency(contractNoteItems[8].Value);
            double average       = ContractNote.getCurrency(contractNoteItems[18].Value);
            double consideration = ContractNote.getCurrency(contractNoteItems[19].Value);

            if (contractNoteItems[8].Valid && contractNoteItems[18].Valid && contractNoteItems[19].Valid && consideration > 0)
            {
                double rate = units * average / consideration;
                if (rate < 0.95 || rate > 1.05)
                {
                    success = contractNoteItems[8].Valid = contractNoteItems[18].Valid = contractNoteItems[19].Valid = false;
                }
            }
            else
            {
                success = contractNoteItems[8].Valid = contractNoteItems[18].Valid = contractNoteItems[19].Valid = false;
            }

            double brokerage = ContractNote.getCurrency(contractNoteItems[9].Value);
            double gstAmount = ContractNote.getCurrency(contractNoteItems[10].Value);
            double miscFee   = ContractNote.getCurrency(contractNoteItems[12].Value);

            if (contractNoteItems[9].Valid && contractNoteItems[10].Valid && contractNoteItems[11].Valid && gstAmount > 0)
            {
                double rate         = (brokerage + miscFee) / gstAmount;
                double expectedRate = contractNoteItems[11].Value == "Y" ? 11 : 10;
                if (rate < expectedRate - 0.3 || rate > expectedRate + 0.3)
                {
                    success = contractNoteItems[9].Valid = contractNoteItems[10].Valid = false;
                }
            }
        }