public static bool Validate(OrderImportRowData rowData, out string errorMsg) { //-- 基础数据验证 Type type = rowData.GetType(); PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); for (int i = 0; i < properties.Length; i++) { PropertyInfo property = properties[i]; if (property.PropertyType.IsAssignableFrom(typeof(OrderImportCellData))) { OrderImportCellData cellData = (OrderImportCellData)property.GetValue(rowData, null); ParseValidationAttribute(property, cellData); if (cellData.Validators != null && cellData.Validators.Count > 0) { foreach (var validator in cellData.Validators) { if (!validator.Validate(rowData, cellData, out errorMsg)) { return(false); } } } } } errorMsg = null; return(true); }
public bool Validate(OrderImportRowData rowData, OrderImportCellData cellData, out string errorMsg) { if (string.IsNullOrWhiteSpace(cellData.Value)) { errorMsg = string.Format("{0}的值不能为空!", cellData.Comment); return(false); } errorMsg = null; return(true); }
public bool Validate(OrderImportRowData rowData, OrderImportCellData cellData, out string errorMsg) { if (!string.IsNullOrWhiteSpace(cellData.Value) && cellData.Value.Length > MaxLength) { errorMsg = string.Format("{0}的值超过最大长度限制{1}!", cellData.Comment, MaxLength); return(false); } errorMsg = null; return(true); }
public bool Validate(OrderImportRowData rowData, OrderImportCellData cellData, out string errorMsg) { if (!RegexExpression.IsMatch(cellData.Value)) { errorMsg = string.Format("{0}的格式不正确!", cellData.Comment); return(false); } errorMsg = null; return(true); }
public bool Validate(OrderImportRowData rowData, OrderImportCellData cellData, out string errorMsg) { decimal value; if (!decimal.TryParse(cellData.Value, out value)) { errorMsg = string.Format("{0}的值必须是整数或小数!", cellData.Comment); return(false); } errorMsg = null; return(true); }
private SOCreateRequestInfo Convert2ContractInfo(OrderImportRowData item) { SOCreateRequestInfo contractInfo = new SOCreateRequestInfo(); contractInfo.MerchantOrderID = item.MerchantOrderID.Value; contractInfo.ServerType = item.ServerType.ExtractValue; contractInfo.WarehouseID = int.Parse(item.WarehouseID.Value); contractInfo.ArteryLogisticID = int.Parse(item.ArteryLogisticID.Value); contractInfo.IsMerchantSelfFEP = int.Parse(item.IsMerchantSelfFEP.Value); contractInfo.PayInfo = new SOPayInfo(); contractInfo.PayInfo.ProductAmount = decimal.Parse(item.ProductAmount.Value); contractInfo.PayInfo.ShippingAmount = decimal.Parse(item.ShippingAmount.Value); contractInfo.PayInfo.TaxAmount = 0; contractInfo.PayInfo.CommissionAmount = 0; contractInfo.PayInfo.PayTypeSysNo = int.Parse(item.PayTypeID.ExtractValue); contractInfo.PayInfo.PaySerialNumber = item.PaySerialNumber.Value; contractInfo.ShippingInfo = new SOShippingInfo(); contractInfo.ShippingInfo.ReceiveName = item.ReceiveName.Value; contractInfo.ShippingInfo.ReceivePhone = item.ReceiveCellPhone.Value; contractInfo.ShippingInfo.ReceiveAddress = item.ReceiveAddress.Value; contractInfo.ShippingInfo.ReceiveAreaName = item.ReceiveAreaName.Value.Substring(0, item.ReceiveAreaName.Value.LastIndexOf('[')); contractInfo.ShippingInfo.ReceiveAreaCode = item.ReceiveAreaName.ExtractValue.Substring(item.ReceiveAreaName.ExtractValue.LastIndexOf(',') + 1); contractInfo.ShippingInfo.ReceiveZip = item.ReceiveZip.Value; contractInfo.ShippingInfo.ShipTypeID = int.Parse(item.ShipTypeID.Value); contractInfo.AuthenticationInfo = new SOAuthenticationInfo(); contractInfo.AuthenticationInfo.Name = item.AuthName.Value; contractInfo.AuthenticationInfo.IDCardType = 0; contractInfo.AuthenticationInfo.IDCardNumber = item.IDCardNumber.Value; contractInfo.AuthenticationInfo.PhoneNumber = item.AuthCellPhone.Value; contractInfo.AuthenticationInfo.Email = item.AuthEmail.Value; contractInfo.ItemList = new List <SOItemInfo>(); string[] productIDs = item.ProductIDs.Value.Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries); string[] productQtys = item.ProductQtys.Value.Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries); string[] productPrices = item.ProductPrices.Value.Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < productIDs.Length; i++) { contractInfo.ItemList.Add(new SOItemInfo() { ProductID = productIDs[i], Quantity = int.Parse(productQtys[i]), SalePrice = decimal.Parse(productPrices[i]), TaxPrice = 0 }); } return(contractInfo); }
private bool ValidateData(OrderImportRowData item, out string errorMsg) { try { errorMsg = string.Empty; if (!ValidationManager.Validate(item, out errorMsg)) { throw new BusinessException(errorMsg); } if (item.IDCardNumber.Value.Length != 18 || !CheckIDCard18(item.IDCardNumber.Value)) { throw new BusinessException("身份证格式不正确"); } string[] productIDs = item.ProductIDs.Value.Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries); string[] productQtys = item.ProductQtys.Value.Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries); string[] productPrices = item.ProductPrices.Value.Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries); if (!(productIDs.Length == productQtys.Length && productQtys.Length == productPrices.Length)) { throw new BusinessException("商品ID、购买数量、商品价格 不对应"); } int qtyTmp; for (int i = 0; i < productQtys.Length; i++) { if (!int.TryParse(productQtys[i], out qtyTmp) || qtyTmp <= 0) { throw new BusinessException("商品购买数量 {0} 不正确", productQtys[i]); } } decimal priceTmp; for (int i = 0; i < productPrices.Length; i++) { if (!decimal.TryParse(productPrices[i], out priceTmp) || priceTmp < 0) { throw new BusinessException("商品价格 {0} 不正确", productPrices[i]); } } } catch (Exception ex) { errorMsg = ex.Message; return(false); } errorMsg = null; return(true); }
private List <OrderImportRowData> ReadDocumentToList(string templateFilePath) { List <OrderImportRowData> docData = new List <OrderImportRowData>(); using (FileStream fs = new FileStream(templateFilePath, FileMode.Open, FileAccess.Read)) { IWorkbook workBook = new XSSFWorkbook(fs); ISheet sheet = workBook.GetSheetAt(0); int skipRowCount = 1; int rowIndex = skipRowCount; while (true) { IRow row = sheet.GetRow(rowIndex++); if (row == null || row.GetCell(0) == null || string.IsNullOrWhiteSpace(row.GetCell(0).ToString())) { break; } OrderImportRowData docRowData = new OrderImportRowData(); docRowData.MerchantOrderID = new OrderImportCellData("商户订单编号", row.GetCell(0).ToString()); docRowData.ServerType = new OrderImportCellData("进口模式", row.GetCell(1).ToString()); docRowData.WarehouseID = new OrderImportCellData("仓库编号", row.GetCell(2).ToString()); docRowData.PayTypeID = new OrderImportCellData("支付方式", row.GetCell(3).ToString()); docRowData.PaySerialNumber = new OrderImportCellData("支付流水号", row.GetCell(4).ToString()); docRowData.ProductAmount = new OrderImportCellData("商品总金额", row.GetCell(5).ToString()); docRowData.ShippingAmount = new OrderImportCellData("运费总金额", row.GetCell(6).ToString()); docRowData.ShipTypeID = new OrderImportCellData("配送方式", row.GetCell(7).ToString()); docRowData.ReceiveName = new OrderImportCellData("收件人姓名", row.GetCell(8).ToString()); docRowData.ReceiveCellPhone = new OrderImportCellData("收件人手机电话", row.GetCell(9).ToString()); docRowData.ReceiveAreaName = new OrderImportCellData("收件人省市区", row.GetCell(10).ToString()); docRowData.ReceiveAddress = new OrderImportCellData("收货地址", row.GetCell(11).ToString()); docRowData.ReceiveZip = new OrderImportCellData("收货邮编", row.GetCell(12) == null?"000000": row.GetCell(12).ToString()); docRowData.AuthName = new OrderImportCellData("实名认证姓名", row.GetCell(13).ToString()); docRowData.IDCardNumber = new OrderImportCellData("身份证号码", row.GetCell(14).ToString()); docRowData.AuthCellPhone = new OrderImportCellData("手机号码", row.GetCell(15).ToString()); docRowData.AuthEmail = new OrderImportCellData("电子邮箱", row.GetCell(16).ToString()); docRowData.ProductIDs = new OrderImportCellData("商品ID(多个用逗号分隔)", row.GetCell(17).ToString()); docRowData.ProductQtys = new OrderImportCellData("购买数量(多个用逗号分隔)", row.GetCell(18).ToString()); docRowData.ProductPrices = new OrderImportCellData("商品价格(多个用逗号分隔)", row.GetCell(19).ToString()); docRowData.ArteryLogisticID = new OrderImportCellData("干线ID", row.GetCell(20) == null? "0": row.GetCell(20).ToString()); docRowData.IsMerchantSelfFEP = new OrderImportCellData("自行购汇", row.GetCell(21) == null ? "0" : row.GetCell(21).ToString()); docData.Add(docRowData); } } return(docData); }
public bool Validate(OrderImportRowData rowData, OrderImportCellData cellData, out string errorMsg) { decimal value; decimal.TryParse(cellData.Value, out value); decimal minValue = Convert.ToDecimal(this.MinValue); bool isInValid = !this.Inclusive ? value < minValue : value <= minValue; if (isInValid) { errorMsg = string.Format("{0}的值必须大于{1}{2}!", cellData.Comment, (this.Inclusive ? "等于" : ""), this.MinValue); return(false); } errorMsg = null; return(true); }