/// <summary>
        /// 订单导入
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="dataResult"></param>
        /// <param name="errMessage"></param>
        /// <param name="importFile"></param>
        /// <returns></returns>
        public bool ImportOrder(SaleOrderImportFileEntity importFile, DataTable dt, out DataTable dataResult,
                                out string errMessage)
        {
            string userId = ManageProvider.Provider.Current().UserId;

            //构造导入返回结果表
            DataTable resultTable = new DataTable("Result");

            resultTable.Columns.Add("rowid", typeof(string));  //行号
            resultTable.Columns.Add("locate", typeof(string)); //位置
            resultTable.Columns.Add("reason", typeof(string)); //原因
            errMessage = string.Empty;
            bool isSuccess = false;

            if (dt != null && dt.Rows.Count > 0)
            {
                IDatabase database = DataFactory.Database();
                try
                {
                    List <SaleOrderImportItemEntity> lstEntities = new List <SaleOrderImportItemEntity>();
                    foreach (DataRow item in dt.Rows)
                    {
                        var importEntity = new SaleOrderImportItemEntity();
                        importEntity.Create();
                        //
                        importEntity.FileId      = importFile.FileId;
                        importEntity.ProductCode = item["商品编码"].ToString();
                        if (string.IsNullOrWhiteSpace(importEntity.ProductCode))
                        {
                            throw new Exception("商品编码不能为空");
                        }
                        importEntity.SourceOrderNo = item["外部单号"].ToString();
                        if (string.IsNullOrWhiteSpace(importEntity.SourceOrderNo))
                        {
                            throw new Exception("外部订单号不能为空");
                        }
                        //string OrderDate = item["制单日期"].ToString();
                        importEntity.OrderDate        = DateTime.Now;
                        importEntity.ReceiveContact   = item["联系人"].ToString();
                        importEntity.ReceivePhone     = item["固定电话"].ToString();
                        importEntity.ReceiveCellPhone = item["联系电话"].ToString();
                        importEntity.ReceiveZip       = item["邮编"].ToString();
                        importEntity.ExpressNum       = item["快递单号"].ToString();
                        importEntity.Province         = item["所在省"].ToString();
                        importEntity.City             = item["所在市"].ToString();
                        importEntity.County           = item["所在县/区"].ToString();
                        importEntity.ReceiveAddress   = item["详细地址"].ToString();
                        importEntity.Qty          = int.Parse(item["数量"].ToString());
                        importEntity.SellerNote   = item["卖家留言"].ToString();
                        importEntity.BuyerNote    = item["买家留言"].ToString();
                        importEntity.ShipTypeName = item["物流方式"].ToString();
                        importEntity.Remark       = item["备注"].ToString();

                        bool flag = _saleOrderBLL.IsExistSourceOrderNo(importEntity.SourceOrderNo);
                        if (flag)
                        {
                            throw new Exception(string.Format("外部单号{0}已存在,请作废后重新导入", importEntity.SourceOrderNo));
                        }

                        lstEntities.Add(importEntity);
                    }

                    lstEntities = lstEntities.OrderBy(a => a.SourceOrderNo).ToList();

                    var shipTypeList = _shipTypeBLL.GetList();

                    DbTransaction isOpenTrans = database.BeginTrans();

                    string sourceOrderNo = string.Empty;
                    string orderNo       = string.Empty;
                    List <SaleOrderEntity>     orderEntities     = new List <SaleOrderEntity>();
                    List <SaleOrderItemEntity> orderItemEntities = new List <SaleOrderItemEntity>();
                    foreach (SaleOrderImportItemEntity orderImportEntity in lstEntities)
                    {
                        var shipType = shipTypeList.Find(a => a.ShipTypeName == orderImportEntity.ShipTypeName);
                        if (shipType == null)
                        {
                            throw new Exception(string.Format("物流方式{0}不存在", orderImportEntity.ShipTypeName));
                        }

                        SaleOrderEntity orderEntity = new SaleOrderEntity();
                        var             select      = orderEntities.Where(i => i.ReceiveContact == orderImportEntity.ReceiveContact &&
                                                                          i.ReceivePhone == orderImportEntity.ReceivePhone
                                                                          &&
                                                                          i.ReceiveCellPhone == orderImportEntity.ReceiveCellPhone &&
                                                                          i.ReceiveZip == orderImportEntity.ReceiveZip &&
                                                                          i.Province == orderImportEntity.Province &&
                                                                          i.City == orderImportEntity.City &&
                                                                          i.County == orderImportEntity.County &&
                                                                          i.ReceiveAddress == orderImportEntity.ReceiveAddress &&
                                                                          i.WarehouseId == importFile.WarehouseId &&
                                                                          i.ShipTypeId == shipType.ShipTypeId &&
                                                                          i.ExpressNum == orderImportEntity.ExpressNum &&
                                                                          i.SellerNote == orderImportEntity.SellerNote &&
                                                                          i.BuyerNote == orderImportEntity.BuyerNote &&
                                                                          i.Remark == orderImportEntity.Remark);
                        if (select.Any())
                        {
                            orderEntity = select.First();
                            var otherSourceOrderNos = orderEntity.SourceOrderNo.Split(',').ToList();
                            if (!otherSourceOrderNos.Contains(orderImportEntity.SourceOrderNo))
                            {
                                otherSourceOrderNos.Add(orderImportEntity.SourceOrderNo);
                            }
                            orderEntity.SourceOrderNo = String.Join(",", otherSourceOrderNos.ToArray());
                        }
                        else
                        {
                            orderEntity.Create();
                            orderEntity.OrderId          = orderImportEntity.ItemId;
                            orderEntity.OrderNo          = _codeRuleBll.GetBillCode(userId, SaleOrderCodeName);
                            orderEntity.SourceOrderNo    = orderImportEntity.SourceOrderNo;
                            orderEntity.OrderDate        = DateTime.Now;
                            orderEntity.WarehouseId      = importFile.WarehouseId;
                            orderEntity.MerchantId       = importFile.MerchantId;
                            orderEntity.MerchantMallId   = importFile.MerchantMallId;
                            orderEntity.ShipTypeId       = shipType.ShipTypeId;
                            orderEntity.Province         = orderImportEntity.Province;
                            orderEntity.City             = orderImportEntity.City;
                            orderEntity.County           = orderImportEntity.County;
                            orderEntity.ReceiveAddress   = orderImportEntity.ReceiveAddress;
                            orderEntity.ReceiveContact   = orderImportEntity.ReceiveContact;
                            orderEntity.ReceivePhone     = orderImportEntity.ReceivePhone;
                            orderEntity.ReceiveCellPhone = orderImportEntity.ReceiveCellPhone;
                            orderEntity.ReceiveZip       = orderImportEntity.ReceiveZip;
                            orderEntity.SellerNote       = orderImportEntity.SellerNote;
                            orderEntity.BuyerNote        = orderImportEntity.BuyerNote;
                            orderEntity.ExpressNum       = orderImportEntity.ExpressNum;
                            orderEntity.City             = orderImportEntity.City;
                            orderEntity.Remark           = orderImportEntity.Remark;
                            orderEntities.Add(orderEntity);

                            _codeRuleBll.OccupyBillCode(ManageProvider.Provider.Current().UserId, SaleOrderCodeName,
                                                        isOpenTrans);

                            sourceOrderNo = orderImportEntity.SourceOrderNo;
                            orderNo       = orderEntity.OrderNo;
                        }

                        var product = _productBLL.GetProductByCode(orderImportEntity.ProductCode);
                        if (product == null)
                        {
                            throw new Exception(string.Format("商品编号{0}不存在", orderImportEntity.ProductCode));
                        }

                        var saleOrderItem = new SaleOrderItemEntity();
                        saleOrderItem.Create();
                        saleOrderItem.OrderId       = orderEntity.OrderId;
                        saleOrderItem.OrderNo       = orderNo;
                        saleOrderItem.ProductId     = product.ProductId;
                        saleOrderItem.Code          = product.Code;
                        saleOrderItem.ProductName   = product.ProductName;
                        saleOrderItem.Weight        = product.Weight;
                        saleOrderItem.Volume        = product.Volume;
                        saleOrderItem.Specification = product.Specification;
                        saleOrderItem.BaseUnit      = product.BaseUnit;
                        saleOrderItem.BarCode       = product.BarCode;
                        saleOrderItem.Price         = product.Price;
                        saleOrderItem.Qty           = orderImportEntity.Qty;

                        orderItemEntities.Add(saleOrderItem);
                    }


                    database.Insert(importFile);
                    foreach (SaleOrderImportItemEntity orderImportEntity in lstEntities)
                    {
                        database.Insert(orderImportEntity, isOpenTrans);
                    }

                    foreach (SaleOrderEntity orderImportEntity in orderEntities)
                    {
                        database.Insert(orderImportEntity, isOpenTrans);
                    }

                    foreach (SaleOrderItemEntity orderImportEntity in orderItemEntities)
                    {
                        database.Insert(orderImportEntity, isOpenTrans);
                    }

                    database.Commit();
                    isSuccess = true;
                }
                catch (Exception ex)
                {
                    database.Rollback();
                    BaseSysLogBll.Instance.WriteLog("", OperationType.Add, "-1", "异常错误:" + ex.Message);
                    isSuccess  = false;
                    errMessage = ex.Message;
                }
            }
            dataResult = resultTable;
            return(isSuccess);
        }