Esempio n. 1
0
        public List <CheckError> CheckError(string name, string address, int age, DateTime birth, int idClass)
        {
            List <CheckError> checkErrors = new List <CheckError>();

            if (name == null || name.Trim() == "")
            {
                CheckError check = new CheckError {
                    nameInput = "name", error = "Tên không được để trống"
                };
                checkErrors.Add(check);
            }
            if (address == null || address.Trim() == "")
            {
                CheckError check = new CheckError {
                    nameInput = "address", error = "Địa chỉ không được để trống"
                };
                checkErrors.Add(check);
            }
            if (age == 0)
            {
                CheckError check = new CheckError {
                    nameInput = "age", error = "Tuổi không được để trống"
                };
                checkErrors.Add(check);
            }
            if (birth == null || birth == DateTime.MinValue)
            {
                CheckError check = new CheckError {
                    nameInput = "birth", error = "Ngày sinh không được để trống"
                };
                checkErrors.Add(check);
            }
            return(checkErrors);
        }
Esempio n. 2
0
 private void button6_Click(object sender, EventArgs e)
 {
     if (lbxLog.SelectedItem != null)
     {
         CheckError error = lbxLog.SelectedItem as CheckError;
         if (error.Locations != null && error.Locations.Count > 0)
         {
             AppManager am = AppManager.GetInstance();
             am.AppForm.LocateCheckError(error.Locations[0]);
         }
     }
 }
Esempio n. 3
0
        private PhyCombine()
        {
            rawText = new byte[rawText_maxlength];
            Array.Clear(rawText, 0, rawText_maxlength);
            machineinfo = new MachineInfo();
            //初始化机器类型
            initmachineinfo();

            CombineFragmentSg = delegate(byte[] rawitem)
            {
                #region phase1: get machine header

                /*
                 * ////phase 1: 获取机器格式头////
                 * int st = -1;
                 *
                 * if (!append(rawitem))
                 * {
                 *  Console.WriteLine("到达尾部,无法append");
                 *  return;
                 * }
                 * rawText_length += rawitem.Length;
                 *
                 * for (int i = rawText_bigpct_prt; i < rawText_length -1; i++)  //查找包起始标志
                 * {
                 *  if (rawText[i] == 0x46 && rawText[i+1] == 0x4C )  //找到'FL'
                 *  {
                 *      st = i;
                 *      break;
                 *  }
                 * }
                 * if (st == -1 && rawText_length > rawText_maxlength - 100)  //长时间不能收到机器类型包
                 * {
                 *  Console.WriteLine("长时间不能收到机器类型包");
                 *  if(CombineError_Ev != null) CombineError_Ev(CombineErrorInfo.NOT_FOUND_MACHINE_HEADER_LONG);
                 *
                 *  return;
                 * }
                 * if (st == -1 ||(st + MachineTypeHeaderLength > rawText_length ))  //找不到起始标志'F', 或者碎片太短,继续拼包
                 * {
                 *  return;
                 * }
                 * if(rawText[st+2] != 0x01)   //未能识别的机器类型
                 * {
                 *  Console.WriteLine("未能识别的机器类型");
                 *  if (CombineError_Ev != null) { CombineError_Ev(CombineErrorInfo.INVALID_MACHINE_TYPE); }
                 *  return;
                 * }
                 *
                 * //找到机器类型包,准备自弃
                 * switch (rawText[st+2])
                 * {
                 *  case 0x01:
                 *      machineinfo.CrtPctEndTag = 16;
                 *      machineinfo.CrtPctLength = 17;
                 *      machineinfo.CrtPctMiddleTag = 7;
                 *      machineinfo.CrtPctDStart = 2;
                 *      machineinfo.CrtPctSStart = 10;        //序号起始位置
                 *      machineinfo.CrtPctVStart = 8;
                 *
                 *      machineinfo.DataPctEndTag = 10;
                 *      machineinfo.DataPctLength = 11;
                 *      machineinfo.DataPctMiddleTag = 7;
                 *      machineinfo.DataPctDStart = 2;
                 *      machineinfo.DataPctVStart = 8;
                 *
                 *      machineinfo.SrlPctEndTag = 8;
                 *      machineinfo.SrlPctLength = 9;
                 *
                 *      //气体流量包
                 *      machineinfo.AirFluPctDataWidth = 1;
                 *      machineinfo.AirFluPctDStart = 2;
                 *      machineinfo.AirFluPctEndStart = 6;
                 *      machineinfo.AirFluPctEndTag = 0x49;
                 *      machineinfo.AirFluPctLength = 7;
                 *      machineinfo.AirFluPctMiddleStart = 3;
                 *      machineinfo.AirFluPctMiddleTag = 0x45;
                 *      machineinfo.AirFluPctVStart = 4;
                 *
                 *      //气体取样时间包
                 *      machineinfo.AirSTPctDataWidth = 2;
                 *      machineinfo.AirSTPctDStart = 2;
                 *      machineinfo.AirSTPctEndStart = 7;
                 *      machineinfo.AirSTPctEndTag = 0x49;
                 *      machineinfo.AirSTPctLength = 8;
                 *      machineinfo.AirSTPctMiddleStart = 4;
                 *      machineinfo.AirSTPctMiddleTag = 0x42;
                 *      machineinfo.AirSTPctVStart = 5;
                 *
                 *      //状态获取命令回应包
                 *      machineinfo.GetStatusResPctDataWidth = 8;
                 *      machineinfo.GetStatusResPctDStart = 4;
                 *      machineinfo.GetStatusResPctEndStart = 16;
                 *      machineinfo.GetStatusResPctEndTag = 0x49;
                 *      machineinfo.GetStatusResPctLength = 17;
                 *      machineinfo.GetStatusResPctMiddleStart = 13;
                 *      machineinfo.GetStatusResPctMiddleTag = 0x48;
                 *      machineinfo.GetStatusResPctVStart = 14;
                 *
                 *      //普通命令回应包
                 *      machineinfo.NorCmdResPctDataWidth =3 ;
                 *      machineinfo.NorCmdResPctDStart = 2;
                 *      machineinfo.NorCmdResPctEndStart = 8;
                 *      machineinfo.NorCmdResPctEndTag = 0x49;
                 *      machineinfo.NorCmdResPctLength = 9;
                 *      machineinfo.NorCmdResPctMiddleStart = 5;
                 *      machineinfo.NorCmdResPctMiddleTag = 0x48;
                 *      machineinfo.NorCmdResPctVStart = 6;
                 *
                 *      machineinfo.DataWidth = 5;
                 *      machineinfo.SequenceLength = 6;
                 *      machineinfo.Type = 0x01;
                 *
                 *      rawText_bigpct_prt = st + MachineTypeHeaderLength;
                 *      break;
                 * }
                 */
                #endregion

                #region phase2: analyze
                ////phase 2: 分析数据////
                CombineFragmentSg = delegate(byte[] rawit)
                {
                    PacketType out_ptype; PacketCombineStatus out_ftype;

                    if (!append(rawit))
                    {
                        return;
                    }
                    rawText_length += rawit.Length;

                    //串口上传过来的一片数据可能包含多个包,循环直到处理完该片中的所有包
                    CheckError errslt = CheckError.OK;
                    while (errslt == CheckError.OK || errslt == CheckError.DATA_FORMAT_ERROR ||
                           errslt == CheckError.PACKET_TPYE_ERROR)
                    {
                        errslt = check(rawText_frag_status, out out_ftype, out out_ptype);
                        switch (errslt)
                        {
                        case CheckError.OK:     //成功组包,拨动指针。如果尾部没有其它数据添加回车换行符合
                            switch (out_ptype)
                            {
                            case PacketType.CORRECT_RESPONSE:
                                if (rawText_purepct_prt + machineinfo.CrtPctLength == rawText_length)
                                {
                                    if (appendCRLF())
                                    {
                                        rawText_length    += "\r\n".Length;
                                        rawText_bigpct_prt = rawText_length;
                                    }
                                }
                                else
                                {
                                    rawText_bigpct_prt = (rawText_purepct_prt + machineinfo.CrtPctLength);
                                }

                                break;

                            case PacketType.DATA_VALUE:
                                if (rawText_purepct_prt + machineinfo.DataPctLength == rawText_length)
                                {
                                    if (appendCRLF())
                                    {
                                        rawText_length    += "\r\n".Length;
                                        rawText_bigpct_prt = rawText_length;
                                    }
                                }
                                else
                                {
                                    rawText_bigpct_prt = (rawText_purepct_prt + machineinfo.DataPctLength);
                                }

                                break;

                            case PacketType.RES_COMPUTE_VALUE:
                                if (rawText_purepct_prt + machineinfo.ResComputePctLength == rawText_length)
                                {
                                    if (appendCRLF())
                                    {
                                        rawText_length    += "\r\n".Length;
                                        rawText_bigpct_prt = rawText_length;
                                    }
                                }
                                else
                                {
                                    rawText_bigpct_prt = (rawText_purepct_prt + machineinfo.ResComputePctLength);
                                }
                                break;

                            case PacketType.SEQUENCE:
                                if (rawText_purepct_prt + machineinfo.SrlPctLength == rawText_length)
                                {
                                    if (appendCRLF())
                                    {
                                        rawText_length    += "\r\n".Length;
                                        rawText_bigpct_prt = rawText_length;
                                    }
                                }
                                else
                                {
                                    rawText_bigpct_prt = (rawText_purepct_prt + machineinfo.SrlPctLength);
                                }

                                break;

                            case PacketType.AIR_FLUENT:
                                if (rawText_purepct_prt + machineinfo.AirFluPctLength == rawText_length)
                                {
                                    if (appendCRLF())
                                    {
                                        rawText_length    += "\r\n".Length;
                                        rawText_bigpct_prt = rawText_length;
                                    }
                                }
                                else
                                {
                                    rawText_bigpct_prt = (rawText_purepct_prt + machineinfo.AirFluPctLength);
                                }
                                break;

                            case PacketType.AIR_SAMPLE_TIME:
                                if (rawText_purepct_prt + machineinfo.AirSTPctLength == rawText_length)
                                {
                                    if (appendCRLF())
                                    {
                                        rawText_length    += "\r\n".Length;
                                        rawText_bigpct_prt = rawText_length;
                                    }
                                }
                                else
                                {
                                    rawText_bigpct_prt = (rawText_purepct_prt + machineinfo.AirSTPctLength);
                                }
                                break;

                            case PacketType.GETSTATUS_RESPONSE:
                                if (rawText_purepct_prt + machineinfo.GetStatusResPctLength == rawText_length)
                                {
                                    if (appendCRLF())
                                    {
                                        rawText_length    += "\r\n".Length;
                                        rawText_bigpct_prt = rawText_length;
                                    }
                                }
                                else
                                {
                                    rawText_bigpct_prt = (rawText_purepct_prt + machineinfo.GetStatusResPctLength);
                                }
                                break;

                            case PacketType.NORCMD_RESPONSE:
                                if (rawText_purepct_prt + machineinfo.NorCmdResPctLength == rawText_length)
                                {
                                    if (appendCRLF())
                                    {
                                        rawText_length    += "\r\n".Length;
                                        rawText_bigpct_prt = rawText_length;
                                    }
                                }
                                else
                                {
                                    rawText_bigpct_prt = (rawText_purepct_prt + machineinfo.NorCmdResPctLength);
                                }
                                break;
                            }
                            break;

                        case CheckError.CONTINUE:     //碎片,不要拨动指针
                            break;

                        case CheckError.DATA_FORMAT_ERROR:     //抛弃,拨动指针,跳过这个坏包,发出事件
                            switch (out_ftype)
                            {
                            case PacketCombineStatus.FRAGMENT_CORRECT:
                                rawText_bigpct_prt = rawText_purepct_prt + machineinfo.CrtPctLength;
                                if (CombineError_Ev != null)
                                {
                                    CombineError_Ev(CombineErrorInfo.CORRECT_PCT_DATA_FORMAT_ERROR);
                                }
                                break;

                            case PacketCombineStatus.FRAGMENT_SEQUENCE:
                                rawText_bigpct_prt = rawText_purepct_prt + machineinfo.SrlPctLength;
                                if (CombineError_Ev != null)
                                {
                                    CombineError_Ev(CombineErrorInfo.SEQUENCE_PCT_DATA_FORMAT_ERROR);
                                }
                                break;

                            case PacketCombineStatus.FRAGMENT_VALUE:
                                rawText_bigpct_prt = rawText_purepct_prt + machineinfo.DataPctLength;
                                if (CombineError_Ev != null)
                                {
                                    CombineError_Ev(CombineErrorInfo.VALUE_PCT_DATA_FORMAT_ERROR);
                                }
                                break;

                            case PacketCombineStatus.FRAGMENT_RES_COMPUTE:
                                rawText_bigpct_prt = rawText_purepct_prt + machineinfo.ResComputePctLength;
                                if (CombineError_Ev != null)
                                {
                                    CombineError_Ev(CombineErrorInfo.RES_COMPUTE_VALUE_PCT_DATA_FORMAT_ERROR);
                                }
                                break;

                            case PacketCombineStatus.FRAGMENT_AIR_FLUENT:
                                rawText_bigpct_prt = rawText_purepct_prt + machineinfo.AirFluPctLength;
                                if (CombineError_Ev != null)
                                {
                                    CombineError_Ev(CombineErrorInfo.AIR_FLUENT_PCT_DATA_FORMAT_ERROR);
                                }
                                break;

                            case PacketCombineStatus.FRAGMENT_AIR_SAMPLE_TIME:
                                rawText_bigpct_prt = rawText_purepct_prt + machineinfo.AirSTPctLength;
                                if (CombineError_Ev != null)
                                {
                                    CombineError_Ev(CombineErrorInfo.AIR_SAMPLE_TIME_PCT_DATA_FORMAT_ERROR);
                                }
                                break;

                            case PacketCombineStatus.FRAGMENT_GETSTATUS_RESPONSE:
                                rawText_bigpct_prt = rawText_purepct_prt + machineinfo.GetStatusResPctLength;
                                if (CombineError_Ev != null)
                                {
                                    CombineError_Ev(CombineErrorInfo.GETSTATUS_RESPONSE_FORMAT_ERROR);
                                }
                                break;

                            case PacketCombineStatus.FRAGMENT_NORCMD_RESPONSE:
                                rawText_bigpct_prt = rawText_purepct_prt + machineinfo.NorCmdResPctLength;
                                if (CombineError_Ev != null)
                                {
                                    CombineError_Ev(CombineErrorInfo.NORCMD_RESPONSE_FORMAT_ERROR);
                                }
                                break;
                            }
                            rawText_frag_status = PacketCombineStatus.OK;     //抛弃格式错误包
                            break;

                        case CheckError.PACKET_TPYE_ERROR: ////抛弃,拨动指针,发出事件
                            rawText_bigpct_prt += 1;       //跳过"S"
                            if (CombineError_Ev != null)
                            {
                                CombineError_Ev(CombineErrorInfo.INVALID_PACKET_TYPE);
                            }
                            break;
                        }
                    }
                }; return;

                #endregion
            };
        }
 public CheckEqualError(CheckError CheckError = default, slice <object> Out1 = default, slice <object> Out2 = default)
 {
     this.m_CheckErrorRef = new ptr <CheckError>(CheckError);
     this.Out1            = Out1;
     this.Out2            = Out2;
 }
Esempio n. 5
0
        /// <summary>
        /// Validate proposed payment records before generating the payment file in the XML format Credit Transfer ISO20022 pain003.
        /// </summary>
        /// <param name="xxx">xxx.</param>
        /// <param name="xxx">xxx.</param>
        /// <returns>An XML payment file</returns>
        public XMLDocumentGenerateResult ValidateISO20022(Company company, UnicontaClient.Pages.CreditorTransPayment trans, SQLCache bankAccountCache, bool journalGenerated = false)
        {
            XmlDocument dummyDoc = new XmlDocument();

            CreditTransferDocument doc = new CreditTransferDocument();

            glJournalGenerated = journalGenerated;
            var bankAccount = (BankStatement)bankAccountCache.Get(credPaymFormat._BankAccount);
            var credCache   = company.GetCache(typeof(Uniconta.DataModel.Creditor));
            var creditor    = (Creditor)credCache.Get(trans.Account);

            if (creditor == null && !glJournalGenerated)
            {
                CheckError.Add(new CheckError(String.Format("{0} : {1}",
                                                            Uniconta.ClientTools.Localization.lookup("AccountDoesNotExist"),
                                                            Uniconta.ClientTools.Localization.lookup(trans.Account))));
                return(new XMLDocumentGenerateResult(dummyDoc, CheckError.Count > 0, 0, CheckError));
            }

            exportFormat = (ExportFormatType)credPaymFormat._ExportFormat;

            companyCountryId = UnicontaCountryToISO(company._CountryId);

            creditorIBAN  = string.Empty;
            creditorSWIFT = string.Empty;

            checkErrors.Clear();

            //Validations >>

            RequestedExecutionDate(trans._PaymentDate, company);
            PaymentCurrency(trans.CurrencyLocalStr, trans._PaymentMethod, trans._PaymentId, trans.SWIFT);

            if (glJournalGenerated == false)
            {
                CreditorAddress(creditor);
            }

            if (trans.PaymentMethod == null)
            {
                checkErrors.Add(new CheckError(fieldCannotBeEmpty("PaymentMethod")));
            }
            else if (trans._PaymentMethod == PaymentTypes.None)
            {
                checkErrors.Add(new CheckError(string.Concat(Uniconta.ClientTools.Localization.lookup("PaymentMethod"), " = ", trans.PaymentMethod)));
            }

            if (trans.MergePaymId == Uniconta.ClientTools.Localization.lookup("Excluded") && trans.PaymentAmount <= 0)
            {
                checkErrors.Add(new CheckError(string.Concat(Uniconta.ClientTools.Localization.lookup("PaymentAmount"), "< 0")));
            }

            switch (trans._PaymentMethod)
            {
            case PaymentTypes.VendorBankAccount:
                PaymentMethodBBAN(creditor, company, trans._PaymentId);
                CreditorBIC(trans._SWIFT, true);
                break;

            case PaymentTypes.IBAN:
                PaymentMethodIBAN(creditor, company, trans._PaymentId);
                CreditorBIC(trans._SWIFT);
                break;

            case PaymentTypes.PaymentMethod3:     //FIK71
                PaymentMethodFIK71(trans._PaymentId);
                break;

            case PaymentTypes.PaymentMethod4:     //FIK73
                PaymentMethodFIK73(trans._PaymentId);
                break;

            case PaymentTypes.PaymentMethod5:     //FIK75
                PaymentMethodFIK75(trans._PaymentId);
                break;

            case PaymentTypes.PaymentMethod6:     //FIK04
                PaymentMethodFIK04(trans._PaymentId);
                break;
            }

            var countryCode = glJournalGenerated ? (CountryCode)company._Country : creditor._Country;

            ISOPaymentType(trans.CurrencyLocalStr, bankAccount._IBAN, trans._PaymentMethod, UnicontaCountryToISO(countryCode));

            //Validations <<

            return(new XMLDocumentGenerateResult(dummyDoc, CheckError.Count > 0, 0, CheckError));
        }