Esempio n. 1
0
        /// <summary>
        /// 转换成产品库存信息列表
        /// </summary>
        /// <param name="excelPath"></param>
        /// <returns></returns>
        public static List <ProductInventoryImportDto> ConvertToProductInventorys(string excelPath)
        {
            List <ProductInventoryImportDto> objs = new List <ProductInventoryImportDto>();
            ExcelHelper helper = new ExcelHelper(excelPath);
            var         table  = helper.ExcelToDataTable("Sheet1");

            foreach (DataRow row in table.Rows)
            {
                string _sku = VariableHelper.SaferequestStr(row[2].ToString());
                if (!string.IsNullOrEmpty(_sku))
                {
                    var obj = new ProductInventoryImportDto
                    {
                        MallSapCode     = VariableHelper.SaferequestStr(row[0].ToString()),
                        MallProductName = VariableHelper.SaferequestStr(row[1].ToString()),
                        ProductType     = VariableHelper.SaferequestStr(row[2].ToString()),
                        SKU             = VariableHelper.SaferequestStr(row[3].ToString()),
                        OuterProduct    = VariableHelper.SaferequestStr(row[4].ToString()),
                        OuterSku        = VariableHelper.SaferequestStr(row[5].ToString()),
                        SalesPrice      = VariableHelper.SaferequestDecimal(row[6].ToString()),
                        IsOnSale        = VariableHelper.SaferequestIntToBool(row[7].ToString()),
                        IsUsed          = VariableHelper.SaferequestIntToBool(row[8].ToString()),
                        Result          = true,
                        ResultMsg       = string.Empty
                    };
                    objs.Add(obj);
                }
            }
            return(objs);
        }
Esempio n. 2
0
        /// <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);
        }