示例#1
0
        private MaterilasImportList GetGoodsData(MaterilasImportList material, string value, int index)
        {
            int i = 0;

            if (index == i++) //门店物料编号
            {
                material.AppItemID = value;
            }
            if (index == i++)
            {
                material.AppItemName = value;
            }
            if (index == i++) //物料名称
            {
                material.Brand = value;
            }

            if (index == i++) //主单位
            {
                material.MainUnitId = value;
            }
            if (index == i++) //辅单位
            {
                material.AuxiliaryUnit = value;
            }
            if (index == i++) //转换率
            {
                material.factor = value;
            }

            if (index == i++) //货品分类
            {
                material.AppItemType = value;
            }
            if (index == i++) //库存成本单价
            {
                material.CostPrice = value;
            }
            if (index == i++) //库存现有量
            {
                material.QtyOnhand = value;
            }

            if (index == i++) //是否代销
            {
                if (value == "是")
                {
                    material.SalesByProxy = "true";
                }
                else if (value == "否")
                {
                    material.SalesByProxy = "false";
                }
                else
                {
                    material.SalesByProxy = value;
                }
            }
            if (index == i++) //备注
            {
                material.Remark = value;
            }

            return(material);
        }
示例#2
0
        public JsonResult UploadGoodsExcel(FormCollection formCtl)
        {
            try
            {
                HttpPostedFileBase file = Request.Files["dataFile"];//接收客户端传递过来的数据.
                if (file == null)
                {
                    return(Json(new { Result = false, Msg = "请选择要上传的Excel文件" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    string errorMsg = string.Empty;
                    ISheet sheet    = GetFileSheet(file, out errorMsg);

                    if (errorMsg != string.Empty)
                    {
                        return(Json(new { Result = false, Msg = errorMsg }, JsonRequestBehavior.AllowGet));
                    }

                    IRow headerRow = sheet.GetRow(1);//第一行为标题行
                    int  rowCount  = sheet.LastRowNum;

                    string value = string.Empty;
                    Goods  cus   = new Goods();
                    List <MaterilasImportList> materialList = new List <MaterilasImportList>();
                    for (int i = (sheet.FirstRowNum + 2); i <= rowCount; i++)
                    {
                        IRow row = sheet.GetRow(i);

                        MaterilasImportList material = new MaterilasImportList();
                        if (row != null)
                        {
                            for (int j = 0; j < headerRow.Cells.Count; j++)
                            {
                                if (row.GetCell(j) != null)
                                {
                                    value = GetCellValue(row.GetCell(j)).Trim();
                                }
                                material = GetGoodsData(material, value, j);
                                value    = string.Empty;
                            }
                            materialList.Add(material);
                        }
                    }

                    //统计重复的门店号
                    var result = from t in materialList
                                 group t by t.AppItemID into g
                                 where g.Count() > 1
                                 select new { AppItemID = string.Join(",", g.Select(x => x.AppItemID).Distinct()) };
                    string repeat = string.Empty;
                    foreach (var item in result)
                    {
                        repeat += item.AppItemID + ",";
                    }
                    if (repeat != string.Empty)
                    {
                        repeat = "门店物料编号重复:" + repeat.TrimEnd(',');
                    }
                    cus.MaterilasImportList = materialList;
                    string jsonStr = JsonConvert.SerializeObject(cus);
                    return(Json(new { Result = true, Msg = "上传成功", Error = repeat, Data = jsonStr }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = false, Msg = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }