/// <summary> /// 处理原表数据 /// </summary> /// <param name="sourceDt">原表</param> /// <param name="inputDto">入参</param> /// <returns></returns> public DataTable HanderSourceDt(DataTable sourceDt, TargetExcelInputDto inputDto) { int itemSkuRandom = new Random().Next(10000, 99999);//产生随机5位数 long productIdRandom = Convert.ToInt64(inputDto.ExternalProductId + "0"); for (int i = 0; i < sourceDt.Rows.Count; i++) { #region 随机数递增 itemSkuRandom++; productIdRandom = productIdRandom + new Random().Next(5, 20); #endregion var row = sourceDt.Rows[i]; #region 固定值处理 //获取指定类型的公共属性 PropertyInfo[] propertys = inputDto.GetType().GetProperties(); foreach (var item in propertys) { var v = (DescriptionAttribute[])item.GetCustomAttributes(typeof(DescriptionAttribute), false); var descriptionName = v[0].Description; if (!string.IsNullOrEmpty(descriptionName))//描述不为空 { var cellValue = item.GetValue(inputDto, null); string[] columnsArr = descriptionName.Split('|'); foreach (var columnName in columnsArr) { row[columnName] = cellValue == null?"":cellValue.ToString(); } } } #endregion #region 变化值处理 //item_sku string item_sku = row["item_sku"].ToString(); string external_product_id = row["external_product_id"].ToString(); //变体处理 if (!string.IsNullOrEmpty(external_product_id)) { //sku row["item_sku"] = item_sku.IndexOf('-') != -1?item_sku.Substring(0, item_sku.IndexOf('-') + 1) + itemSkuRandom: item_sku; //条形码 row["external_product_id"] = productIdRandom.ToString(); row["part_number"] = productIdRandom.ToString(); } //标准价 = (原销售价 + 50) * 2 / 0.85 / 汇率 var price = ((Convert.ToDecimal(row["standard_price"]) + 50) * 2 / Convert.ToDecimal(0.85) / Convert.ToDecimal(inputDto.CurrencyExchangeRate)).ToString("0.0"); row["standard_price"] = price; #endregion } return(sourceDt); }
private TargetExcelInputDto GetExcelInputDto() { var selectCountry = cbCountry.SelectedItem as Country; var inputDto = new TargetExcelInputDto(); inputDto.ExternalProductId = txtEANCountryCode.Text.Trim() + txtEANFactoryCode.Text.Trim() + txtEANProductCode.Text.Trim(); inputDto.BrandName = txtBrandName.Text.Trim(); inputDto.FeedProductType = cbProductType.SelectedValue.ToString(); inputDto.CurrencyExchangeRate = selectCountry.CurrencyExchangeRate; inputDto.Currency = selectCountry.CurrencyUnit; inputDto.Quantity = txtQuantity.Text.Trim(); inputDto.ConditionNote = $"Delivery Time {txtDeliveryTimeMin.Text.Trim()}-{txtDeliveryTimeMax.Text.Trim()} Days"; inputDto.WebsiteShippingWeight = txtShippingWeight.Text.Trim(); inputDto.RecommendedBrowseNodes1 = browse_nodes1.Text.Trim(); inputDto.RecommendedBrowseNodes2 = browse_nodes2.Text.Trim(); inputDto.GenericKeywords1 = GenericKeywords1; inputDto.GenericKeywords2 = GenericKeywords2; inputDto.GenericKeywords3 = GenericKeywords3; inputDto.GenericKeywords4 = GenericKeywords4; inputDto.GenericKeywords5 = GenericKeywords5; return(inputDto); }