Last active
March 29, 2016 10:44
-
-
Save smarenich/221df85fed64edf4b867 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ImportTransactionsFromFile(PX.SM.FileInfo file) | |
{ | |
ImportTest graph = new ImportTest(); | |
Byte[] bytes = file.BinData; | |
using(PX.Data.XLSXReader reader = new XLSXReader(bytes)) | |
{ | |
//Initialising Reader | |
reader.Reset(); | |
//Creating a dictionary to find column index by name | |
Dictionary<String, Int32> indexes = reader.IndexKeyPairs.ToDictionary(p => p.Value, p => p.Key); | |
//Skipping first row with collumns names. | |
reader.MoveNext(); | |
while(reader.MoveNext()) | |
{ | |
Tran row = graph.Transactions.Insert(); | |
//Transforming External representation to Internal by using SetValueExt method. | |
graph.Transactions.Cache.SetValueExt(row, "AccountID", reader.GetValue(indexes["Account"])); | |
graph.Transactions.Cache.SetValueExt(row, "SubID", reader.GetValue(indexes["Account"])); | |
//Converting to Decimal | |
row.Qty = Decimal.Parse(reader.GetValue(indexes["Quantity"])); | |
row.DebitAmt = Decimal.Parse(reader.GetValue(indexes["Debit Amount"])); | |
row.CreditAmt = Decimal.Parse(reader.GetValue(indexes["Credit Amount"])); | |
row = graph.Transactions.Update(row); | |
} | |
graph.Actions.PressSave(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment