How to i export data to iif file in C#? Thank!
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;
}
Although the IIF file format is still listed in user documentation for QuickBooks, Intuit been recommending that developers not use the IIF format for many years now. If you want to ignore this recommendation and export to an IIF file anyway, you'll have to write your own formatting routine once you get ahold of the data, either using the QuickBooks SDK or a third party solution like QODBC or rss bus.
精彩评论