处理每个文件的数据记录

6ie5vjzr  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(134)

我有一个文本文件,我们从一个网站供应商那里得到,它显示了一个表单中的所有字段,如下所示(我把akward格式留给产品来帮助解释)。目的地是tsql中每个合同的标题和产品详细信息表:

submissionid:
form:
formnum:
contract_ID:
buyer_info:
seller_info:
date:
product_1:
bio_holder_1:
term_start_date_1:
term_start_end_1:
rin_vintage_1:
product_quant_1:
matches_info_1:
delivery_location_1:
stateValueHolder:
delivery_state_1:
deliveryMethodHolder:
method_of_delivery_1:
payment_terms_1:
product_price_1:
notes_1:
product_2:
product_quant_2:
delivery_location_2:
delivery_state_2:
product_price_2:
product_3:
product_quant_3:
delivery_location_3:
delivery_state_3:
product_price_3:
bio_holder_2:
term_start_date_2:
term_start_end_2:
rin_vintage_2:
matches_info_2:
method_of_delivery_2:
payment_terms_2:
notes_2:
bio_holder_3:
term_start_date_3:
term_start_end_3:
rin_vintage_3:
matches_info_3:
method_of_delivery_3:
payment_terms_3:
notes_3:

我最初的计划是循环并动态地获取产品字段并将它们存储在一个列表中,但是您可以看到,文件并不是在两个条目之后按顺序构造的。最多有五个条目。这是我丑陋的数据循环和类:

string[] contracts = System.IO.File.ReadAllLines(file);
            Contract contract = new Contract();
            Contract.ProductDetail productDetail = new Contract.ProductDetail();
            int productNo = 1;

            foreach (var item in contracts)
            {
                if (data[0] == "product_" + productNo)
                    productDetail.Product = data[1];
                if (data[0] == "term_start_date_" + productNo)
                    productDetail.StartDate = Convert.ToDateTime(data[1]);
                if (data[0] == "term_start_end_" + productNo)
                    productDetail.EndDate = Convert.ToDateTime(data[1]);
                if (data[0] == "rin_vintage_" + productNo)
                    productDetail.Rin = data[1];
                if (data[0] == "product_quant_" + productNo)
                    productDetail.Qunatity = data[1];
                if (data[0] == "delivery_location_" + productNo)
                    productDetail.DeliveryLocation = data[1];
                if (data[0] == "matches_info_" + productNo)
                    productDetail.Matches = data[1];
                if (data[0] == "delivery_state_" + productNo)
                    productDetail.State = data[1];
                if (data[0] == "method_of_delivery_" + productNo)
                    productDetail.DeliveryMethod = data[1];
                if (data[0] == "payment_terms_" + productNo)
                    productDetail.Terms = data[1];
                if (data[0] == "product_price_" + productNo)
                    productDetail.Price = data[1];
                if (data[0] == "notes_" + productNo)
                {
                    productDetail.Notes = data[1];
                    productNo++;
                    contract.Details.Add(productDetail);
                    productDetail = new Contract.ProductDetail();
                }
             }
class Contract
    {
        public Contract()
        {

        }

        public string ContractID;
        public string Type;
        public string Trader;
        public DateTime EntryDate;
        public string BuyerCo;
        public string SellerCo;
        public string BuyerTrader;
        public string SellerTrader;
        public List<ProductDetail> Details = new List<ProductDetail>();

        public class ProductDetail
        {
            public ProductDetail()
            {

            }

            public string Product;
            public DateTime StartDate;
            public DateTime EndDate;
            public string Rin;
            public string Qunatity;
            public string DeliveryLocation;
            public string State;
            public string DeliveryMethod;
            public string Terms;
            public string Price;
            public string Notes;
            internal string Matches;
        }
    }

我在寻找任何解决方案,我没有嫁给我现在拥有的那个,我只是受我自己经验的限制,我似乎无法用词组搜索来找到一个类似的例子。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题