在C#中将数据导出到iif文件(quickbooks文件)

时间:2011-08-23 09:50:13

标签: quickbooks iif

如何在C#中将数据导出到iif文件?谢谢!

2 个答案:

答案 0 :(得分:1)

public StringBuilder GetExportDataForQB(int content, DateTime startDate, DateTime endDate, int[] QBData, string accNum, string accName)
        {
            IJobRepository jobRepo = new JobRepository(conn);
            ICustomerRepository cusRepo = new CustomerRepository(conn);
            IUserRepository userRepo = new UserRepository(conn);
            IProductRepository proRepo = new ProductRepository(conn);
            IInvoiceRepository invoiceRepo = new InvoiceRepository(conn);
            IJobProductRepository jobProductRepo = new JobProductRepository(conn);
            IAccountRepository accRepo = new AccountRepository(conn);
            StringBuilder sb = new StringBuilder();
            switch (content)
            {
                case 1:
                    {

                        #region CustomerData
                        if (QBData[0] == 1)
                        {
                            sb.Append(GetHeader(3));
                            List<Customer> cusList = cusRepo.RetriveAll().ToList();
                            string[][] CusData = new string[cusList.Count][];
                            int i = 0;
                            foreach (Customer cus in cusList)
                            {
                                string[] CustomerData = new string[32];
                                CustomerData[0] = "CUST";
                                CustomerData[1] = cus.Name;
                                CustomerData[2] = cus.Street;
                                CustomerData[3] = cus.Surburb + cus.State + cus.AreaCode;
                                CustomerData[4] = cus.Country;
                                CustomerData[5] = "";
                                CustomerData[6] = "";
                                CustomerData[7] = "";
                                CustomerData[8] = "";
                                CustomerData[9] = "";
                                CustomerData[10] = "";
                                CustomerData[11] = "";
                                CustomerData[12] = cus.Phone;
                                CustomerData[13] = cus.Mobile;
                                CustomerData[14] = "";
                                CustomerData[15] = "";
                                CustomerData[16] = "";
                                CustomerData[17] = cus.Name;
                                CustomerData[18] = "";
                                CustomerData[19] = "";
                                CustomerData[20] = "";
                                CustomerData[21] = "N";
                                CustomerData[22] = "";
                                CustomerData[23] = "";
                                CustomerData[24] = "";
                                CustomerData[25] = "";
                                CustomerData[26] = "";
                                CustomerData[27] = "";
                                CustomerData[28] = cus.Name;
                                CustomerData[29] = cus.Name;
                                CustomerData[30] = "";
                                CustomerData[31] = "";
                                CusData[i] = CustomerData;
                                i++;
                            }
                            sb.Append(GenerateStringBuilderForQB(CusData));
                        }
                        #endregion

                        #region ProductData
                        if (QBData[2] == 1)
                        {

                            List<Product> LstProduct = proRepo.RetriveAll().ToList();
                            int tempForProducts = 0;
                            sb.Append(GetHeader(2));
                            string[][] ProductData = new string[LstProduct.Count][];
                            foreach (Product Pro in LstProduct)
                            {
                                Pro.Accnt = accRepo.GetAccountByProductID(Pro.ProductID);
                                string[] SingleProductData = new string[17];
                                SingleProductData[0] = "INVITEM";
                                SingleProductData[1] = Pro.Name;
                                SingleProductData[2] = "SERV";
                                SingleProductData[3] = Pro.Description;
                                SingleProductData[4] = "";
                                SingleProductData[5] = Pro.Accnt.Name;
                                SingleProductData[6] = "";
                                SingleProductData[7] = "";
                                SingleProductData[8] = Pro.Rate.ToString();
                                SingleProductData[9] = "";
                                SingleProductData[10] = "N";
                                SingleProductData[11] = "";
                                SingleProductData[12] = "";
                                SingleProductData[13] = "";
                                SingleProductData[14] = "";
                                SingleProductData[15] = "";
                                SingleProductData[16] = "";
                                ProductData[tempForProducts] = SingleProductData;
                                tempForProducts++;
                            }
                            sb.Append(GenerateStringBuilderForQB(ProductData));
                        }
                        #endregion

                        #region Transaction Data
                        if (QBData[3] == 1)
                        {
                            sb.Append(GetHeader(1));
                            List<Account> accountList = accRepo.RetriveAll().ToList();
                            string[][] Accounts = new string[accountList.Count][];
                            int tempForAcc = 0;
                            foreach (Account acc in accountList)
                            {
                                string[] AccData = new string[6];
                                AccData[0] = "ACCNT";
                                AccData[1] = acc.Name;
                                AccData[2] = acc.AccType.Name;
                                AccData[3] = acc.description;
                                AccData[4] = accName;
                                Accounts[tempForAcc] = AccData;
                                tempForAcc++;
                            }
                            sb.Append(GenerateStringBuilderForQB(Accounts));

                            sb.Append(GetHeader(4));
                            List<Invoice> PaidInvoiceList = invoiceRepo.GetPaidInvoiceList(startDate, endDate);
                            foreach (Invoice Inv in PaidInvoiceList)
                            {
                                Inv.Job = jobRepo.getJobByInvoiceID(Inv.InvoiceID);
                                string[] Transaction = new string[18];
                                Transaction[0] = "TRNS";
                                Transaction[1] = "";
                                Transaction[2] = "INVOICE";
                                Transaction[3] = string.Format("{0:M/d/yyyy}", Inv.IssueTime);
                                Transaction[4] = accName;
                                Transaction[5] = Inv.Customer.Name;
                                Transaction[6] = "";
                                Transaction[7] = Inv.Amount.ToString();
                                Transaction[8] = "";
                                Transaction[9] = Inv.Job.Desciption;
                                Transaction[10] = "";
                                Transaction[11] = "";
                                Transaction[12] = "N";
                                Transaction[13] = "";
                                Transaction[14] = "";
                                Transaction[15] = "";
                                Transaction[16] = "";
                                Transaction[17] = "";
                                sb.Append(GenerateStringBuilderForQB((new string[1][] { Transaction })));
                                List<JobProduct> JobProductList = jobProductRepo.GetJobProductListByInvoiceID(Inv.InvoiceID);

                                foreach (JobProduct JP in JobProductList)
                                {
                                    JP.Product = proRepo.GetByID(JP.Product.ProductID);
                                    string[] SPL = new string[18];
                                    SPL[0] = "SPL";
                                    SPL[1] = "";
                                    SPL[2] = "INVOICE";
                                    SPL[3] = string.Format("{0:M/d/yyyy}", Inv.IssueTime);
                                    SPL[4] = JP.Product.Accnt.Name;
                                    SPL[5] = "";
                                    SPL[6] = "";
                                    SPL[7] = "-" + JP.Total.ToString();
                                    SPL[8] = "";
                                    SPL[9] = JP.Product.Description;
                                    SPL[10] = "";
                                    SPL[11] = "";
                                    SPL[12] = JP.Total.ToString();
                                    SPL[13] = JP.Product.Description;
                                    SPL[14] = "N";
                                    SPL[15] = "";
                                    SPL[16] = "";
                                    SPL[17] = "";
                                    sb.Append(GenerateStringBuilderForQB((new string[1][] { SPL })));
                                }
                                sb.Append("ENDTRNS" + System.Environment.NewLine);
                            }
                        }
                        #endregion

                        break;
                    }
            }
            return sb;
     }

答案 1 :(得分:0)

虽然IIF文件格式仍然列在QuickBooks的用户文档中,但Intuit已经recommending that developers not use the IIF format多年了。如果你想忽略这个建议并导出到IIF文件,你必须在获得数据之后编写自己的格式化例程,使用QuickBooks SDK或第三方解决方案,如{{3 }或QODBC