Пример #1
0
        private CustImpRecordList GetCustomer(CustImpRecordList customer, string value, int index)
        {
            int i = 0;

            if (index == i++)
            {
                customer.Name = value;
            }
            if (index == i++)
            {
                string sex = value;
                if (value == "男")
                {
                    sex = "1";
                }
                if (value == "女")
                {
                    sex = "0";
                }
                customer.Sex = sex;
            }
            if (index == i++)
            {
                customer.Mobile = value;
            }
            if (index == i++)
            {
                customer.PlateNumber = value.ToUpper();
            }
            if (index == i++)
            {
                customer.VinCode = value;
            }
            if (index == i++)
            {
                customer.Brand = value;
            }
            if (index == i++)
            {
                customer.Model = value;
            }
            if (index == i++)
            {
                customer.Series = value;
            }
            if (index == i++)
            {
                customer.CarYear = value;
            }
            if (index == i++)
            {
                customer.Manufacturer = value;
            }
            if (index == i++)
            {
                customer.SaleName = value;
            }

            return(customer);
        }
Пример #2
0
        public JsonResult UploadExcel(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;
                    Customers cus   = new Customers();
                    List <CustImpRecordList> customerList = new List <CustImpRecordList>();
                    for (int i = (sheet.FirstRowNum + 2); i <= rowCount; i++)
                    {
                        IRow row = sheet.GetRow(i);

                        CustImpRecordList customer = new CustImpRecordList();
                        if (row != null)
                        {
                            for (int j = 0; j < headerRow.Cells.Count; j++)
                            {
                                if (row.GetCell(j) != null)
                                {
                                    value = GetCellValue(row.GetCell(j)).Trim();
                                }
                                customer = GetCustomer(customer, value, j);
                                value    = string.Empty;
                            }
                            customerList.Add(customer);
                        }
                    }
                    cus.custImpRecordList = customerList;
                    string jsonStr = JsonConvert.SerializeObject(cus);
                    return(Json(new { Result = true, Msg = "导入成功", Data = jsonStr }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = false, Msg = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }