/// <summary> /// 更新库存 /// </summary> /// <param name="objMallSapCode"></param> /// <param name="objProductType"></param> /// <param name="objSku"></param> /// <param name="objQuantity"></param> public static void UpdateProductInventory(string objMallSapCode, ProductType objProductType, string objSku, int objQuantity) { using (var db = new ebEntities()) { if (!string.IsNullOrEmpty(objSku)) { db.Database.ExecuteSqlCommand($"update MallProduct set Quantity=Quantity-{objQuantity} where MallSapCode='{objMallSapCode}' and ProductType={(int)objProductType} and Sku='{objSku}'"); } } }
/// <summary> /// 保存产品信息 /// </summary> /// <param name="item"></param> /// <returns></returns> public static FuncResult SaveProducts(ProductImportDto item) { FuncResult _result = new FuncResult(); using (var db = new ebEntities()) { StringBuilder sb = new StringBuilder(); try { if (item.IsCommon) { //只有sku不为空,Material长度为5位,GdVal长度为4位 if (!string.IsNullOrEmpty(item.SKU) && item.Material.Length == 5 && item.GdVal.Length == 4) { string _ProductId = item.Material + item.GdVal; sb.AppendLine($"if exists(select * from Product where SKU = '{item.SKU}')"); sb.AppendLine("begin"); sb.AppendLine($"UPDATE Product set Name='{item.Name}',MatlGroup='{item.MatlGroup}',Description='{item.Description}',ProductName='{item.ProductName}',Material='{item.Material}',GdVal='{item.GdVal}',ProductId='{_ProductId}',EAN='{item.EAN}',MarketPrice={item.MarketPrice},IsDelete={VariableHelper.SaferequestBoolToInt(!item.IsUsed)},IsCommon={VariableHelper.SaferequestBoolToInt(item.IsCommon)},IsGift={VariableHelper.SaferequestBoolToInt(item.IsGift)},IsSet={VariableHelper.SaferequestBoolToInt(item.IsSet)},EditDate='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'"); sb.AppendLine($" WHERE SKU = '{item.SKU}';"); sb.AppendLine("end"); sb.AppendLine("else"); sb.AppendLine("begin"); sb.AppendLine("insert into Product(GroupDesc,Name,MatlGroup,Description,ProductName,Material,GdVal,ProductId,EAN,SupplyPrice,MarketPrice,SalesPrice,IsDelete,IsCommon,IsGift,IsSet,SKU,AddDate,EditDate)"); sb.AppendLine($"values('','{item.Name}','{item.MatlGroup}','{item.Description}','{item.ProductName}','{item.Material}','{item.GdVal}','{_ProductId}','{item.EAN}',0,{item.MarketPrice},0,{VariableHelper.SaferequestBoolToInt(!item.IsUsed)},{VariableHelper.SaferequestBoolToInt(item.IsCommon)},{VariableHelper.SaferequestBoolToInt(item.IsGift)},{VariableHelper.SaferequestBoolToInt(item.IsSet)},'{item.SKU}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')"); sb.AppendLine("end"); } else { if (string.IsNullOrEmpty(item.SKU)) { throw new Exception($"The SKU can not be empty!"); } if (item.Material.Length != 5) { throw new Exception($"The length of Material must be 5!"); } if (item.GdVal.Length != 4) { throw new Exception($"The length of GdVal must be 4!"); } } } else { //只有sku不为空 if (!string.IsNullOrEmpty(item.SKU)) { sb.AppendLine($"if exists(select * from Product where SKU = '{item.SKU}')"); sb.AppendLine("begin"); sb.AppendLine($"UPDATE Product set Name='{item.Name}',MatlGroup='{item.MatlGroup}',Description='{item.Description}',ProductName='{item.ProductName}',Material='{item.Material}',GdVal='{item.GdVal}',EAN='{item.EAN}',MarketPrice={item.MarketPrice},IsDelete={VariableHelper.SaferequestBoolToInt(!item.IsUsed)},IsCommon={VariableHelper.SaferequestBoolToInt(item.IsCommon)},IsGift={VariableHelper.SaferequestBoolToInt(item.IsGift)},IsSet={VariableHelper.SaferequestBoolToInt(item.IsSet)},EditDate='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'"); sb.AppendLine($" WHERE SKU = '{item.SKU}';"); sb.AppendLine("end"); sb.AppendLine("else"); sb.AppendLine("begin"); sb.AppendLine("insert into Product(GroupDesc,Name,MatlGroup,Description,ProductName,Material,GdVal,EAN,SupplyPrice,MarketPrice,SalesPrice,IsDelete,IsCommon,IsGift,IsSet,SKU,AddDate,EditDate)"); sb.AppendLine($"values('','{item.Name}','{item.MatlGroup}','{item.Description}','{item.ProductName}','{item.Material}','{item.GdVal}','{item.EAN}',0,{item.MarketPrice},0,{VariableHelper.SaferequestBoolToInt(!item.IsUsed)},{VariableHelper.SaferequestBoolToInt(item.IsCommon)},{VariableHelper.SaferequestBoolToInt(item.IsGift)},{VariableHelper.SaferequestBoolToInt(item.IsSet)},'{item.SKU}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')"); sb.AppendLine("end"); } else { throw new Exception($"The SKU can not be empty!"); } } if (db.Database.ExecuteSqlCommand(sb.ToString()) > 0) { _result.Result = true; _result.Message = string.Empty; } else { throw new Exception($"SKU:{item.SKU} save fail!"); } } catch (Exception ex) { _result.Result = false; _result.Message = ex.Message; } } return(_result); }
/// <summary> /// 保存产品库存信息 /// </summary> /// <param name="item"></param> /// <returns></returns> public static FuncResult SaveProductInventorys(ProductInventoryImportDto item) { FuncResult _result = new FuncResult(); using (var db = new ebEntities()) { StringBuilder sb = new StringBuilder(); try { int _productType = VariableHelper.SaferequestInt(item.ProductType); //店铺编码和sku不能为空 if (!string.IsNullOrEmpty(item.MallSapCode) && _productType > 0 && _productType < 3 && !string.IsNullOrEmpty(item.SKU) && !string.IsNullOrEmpty(item.OuterProduct)) { sb.AppendLine($"if exists(select * from MallProduct where MallSapCode='{item.MallSapCode}' and MallProductId='{item.OuterProduct}' and MallSkuId = '{item.OuterSku}')"); sb.AppendLine("begin"); sb.AppendLine($"Update MallProduct set MallProductTitle='{item.MallProductName}',SKU='{item.SKU}',SalesPrice='{item.SalesPrice}',IsOnSale={VariableHelper.SaferequestBoolToInt(item.IsOnSale)},IsUsed={VariableHelper.SaferequestBoolToInt(item.IsUsed)},EditDate='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'"); sb.AppendLine($" WHERE (MallSapCode='{item.MallSapCode}' and MallProductId='{item.OuterProduct}' and MallSkuId = '{item.OuterSku}');"); sb.AppendLine("end"); sb.AppendLine("else"); sb.AppendLine("begin"); sb.AppendLine($"Insert Into MallProduct (MallSapCode,MallProductTitle,MallProductPic,MallProductId,MallSkuId,MallSkuPropertiesName,ProductType,SKU,SalesPrice,Quantity,IsOnSale,IsUsed,EditDate) values('{item.MallSapCode}','{item.MallProductName}','','{item.OuterProduct}','{item.OuterSku}','',{_productType},'{item.SKU}',{item.SalesPrice},0,{VariableHelper.SaferequestBoolToInt(item.IsOnSale)},{VariableHelper.SaferequestBoolToInt(item.IsUsed)},'{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')"); sb.AppendLine("end"); } else { if (string.IsNullOrEmpty(item.MallSapCode)) { throw new Exception($"The MallSapCode can not be empty!"); } if (_productType < 0 || _productType > 3) { throw new Exception($"The type of product is incorrect!"); } if (string.IsNullOrEmpty(item.SKU)) { throw new Exception($"The SKU can not be empty!"); } if (string.IsNullOrEmpty(item.OuterProduct)) { throw new Exception($"The Outer Product ID can not be empty!"); } } if (db.Database.ExecuteSqlCommand(sb.ToString()) > 0) { _result.Result = true; _result.Message = string.Empty; } else { throw new Exception($"SKU:{item.SKU} save fail!"); } } catch (Exception ex) { _result.Result = false; _result.Message = ex.Message; } } return(_result); }