Exemple #1
0
        protected List<Bills> GeListByDt(DataTable dt, string name)
        {
            var list = new List<Bills>();

            try
            {
                var productRepository = ComMethod.GetRepository<Products>();
                var saleManRepository = ComMethod.GetRepository<Salesman>();
                var merchantRepository = ComMethod.GetRepository<Merchants>();
                var billsRepository = ComMethod.GetRepository<Bills>();

                foreach (DataRow row in dt.Rows)
                {
                    var productName = row["产品"].ToString();
                    var merchantNo = row["商户编号"].ToString();
                    var product = productRepository.Table.FirstOrDefault(p => p.Name == productName);
                    var saleMan = saleManRepository.Table.FirstOrDefault(p => p.Name == name);
                    var merchant = merchantRepository.Table.FirstOrDefault(p => p.MerchantNo == merchantNo);

                    if (product == null)
                    {
                        product = new Products() { Name = productName };
                        productRepository.Insert(product);
                        product = productRepository.Table.FirstOrDefault(p => p.Name == productName);
                    }
                    if (saleMan == null)
                    {
                        saleMan = new Salesman() { Name = name };
                        saleManRepository.Insert(saleMan);
                        saleMan = saleManRepository.Table.FirstOrDefault(p => p.Name == name);
                    }
                    if (merchant == null)
                    {
                        merchant = new Merchants()
                        {
                            MerchantNo = merchantNo,
                            Name = row["商户"].ToString()
                        };
                        merchantRepository.Insert(merchant);
                        merchant = merchantRepository.Table.FirstOrDefault(p => p.MerchantNo == merchantNo);
                    }

                    var model = new Bills
                    {
                        Product = product,
                        ProductId = product.Id,
                        ChargeSource = row["计费来源"].ToString(),
                        Salesman = saleMan,
                        SalesmanId = saleMan.Id,
                        ServiceRequestNo = row["业务请求编号"].ToString(),
                        Merchant = merchant,
                        MerchantId = merchant.Id,
                        Amount = decimal.Parse(row["计费金额"].ToString()),
                        TradingTime = DateTime.Parse(row["交易时间"].ToString().ComTime()),
                        CompletionTime = DateTime.Parse(row["完成时间"].ToString().ComTime()),
                        ProductExpense = decimal.Parse(row["产品费用"].ToString()),
                        CompleteState = row["状态"].ToString() == "已完成"
                    };

                    billsRepository.Insert(model);
                }
            }
            catch (Exception ex)
            {
                //写入日志
            }
            return list;
        }
Exemple #2
0
 public Bills()
 {
     Salesman=new Salesman();
     Product=new Products();
     Merchant=new Merchants();
 }