I want to read the table data from RFCtable in c# , I am able to get the table structure but I am not getting the data in the table.
Below is the code for that
RfcDestinationManager.RegisterDestinationConfiguration(config__);
RfcDestination prdData = RfcDestinationManager.GetDestination("Vim Analytics");
RfcRepository repos = prdData.Repository;
IRfcFunction InvoiceVIMAny = repos.CreateFunction("BAPI NAME");
InvoiceVIMAny.SetValue("I_INVOICE_NO", InvoiceNumber);
InvoiceVIMAny.SetValue("I_VENDOR_ID", VendorID);
InvoiceVIMAny.Invoke(prdData);
if (InvoiceVIMAny.ElementCount > 0 && InvoiceVIMAny.ElementCount != null)
{
IRfcTable rfcTable = InvoiceVIMAny.GetTable(0);
foreach (IRfcStructure dataRow in rfcTable)
{
invstatusResp.E_STATUS = dataRow.GetValue("E_STATUS").ToString();
invstatusResp.E_DOC_ID = dataRow.GetValue("E_DOC_ID").ToString();
invstatusResp.E_PO_NUMBER = dataRow.GetValue("E_PO_NUMBER").ToString();
invstatusResp.E_INVOICE = dataRow.GetValue("E_INVOICE").ToString();
invstatusResp.E_REASON = dataRow.GetValue("E_REASON").ToString();
invstatusResp.E_DOC_DATE = dataRow.GetValue("E_DOC_DATE").ToString();
invstatusResp.E_POSTING_DATE = dataRow.GetValue("E_POSTING_DATE").ToString();
invstatusResp.E_ENTRY_DATE = dataRow.GetValue("E_ENTRY_DATE").ToString();
invstatusResp.E_DUE_DATE = dataRow.GetValue("E_DUE_DATE").ToString();
invstatusResp.E_GROSS_AMT = dataRow.GetValue("E_GROSS_AMT").ToString();
invstatusResp.E_COMMENTS = dataRow.GetValue("E_COMMENTS").ToString();
invstatusResp.E_CUR_ROLE = dataRow.GetValue("E_CUR_ROLE").ToString();
listinvstatusResp.Add(invstatusResp);
}
}
RfcDestinationManager.UnregisterDestinationConfiguration(config__);
Related
I have a .csv file structured like so, first row is the header column, for each SomeID I need to add the NetCharges together(or substract if the code calls for it) and put each item into its own column by the SomeCode column.
Heres the file I receive;
SomeID,OrderNumber,Code,NetCharge,Total
23473,30388,LI 126.0000, 132.00
96021, 000111, LI, 130.00, 126.00
23473,30388,FU 6.0000, 132.00
4571A,10452,LI,4100.0000, 4325.0000
4571A,10452,FU,150.00,4325.0000
4571A,10452,DT,75.00,4325.0000
I need to insert the data to my sql table which is structured like this. This is what I'm aiming for:
ID OrderNumber LICode LICodeValue FUCode FUCodeValue DTCode, DTCodeValue, total
23473 30388n LI 126.000 FU 6.0000 NULL NULL 132.0000
4571A 10452 LI 4100.0000 FU 150.0000 DT 75.00 4325.0000
My SomeID will not always be grouped together like the 4571A id is.I basically need to iterate over this file and create one record for each SomeID. I cannot seem to find a way with csvHelper. I'm using C# and csvHelper. I have trid this so far but I cannot get back to the SomeId after passing on to the nexr one:
using (var reader = new StreamReader( "C:\testFiles\some.csv" ))
using (var csv = new CsvReader( reader, CultureInfo.InvariantCulture ))
{
var badRecords = new List<string>();
var isRecordBad = false;
csv.Configuration.HasHeaderRecord = true;
csv.Configuration.HeaderValidated = null;
csv.Configuration.IgnoreBlankLines = true;
csv.Configuration.Delimiter = ",";
csv.Configuration.BadDataFound = context =>
{
isRecordBad = true;
badRecords.Add( context.RawRecord );
};
csv.Configuration.MissingFieldFound = ( s, i, context ) =>
{
isRecordBad = true;
badRecords.Add( context.RawRecord );
};
List<DataFile> dataFile = csv.GetRecords<DataFile>().ToList();
//initialize variable
string lastSomeId = "";
if (!isRecordBad)
{
foreach (var item in dataFile)
{
// check if its same record
if (lastSomeId != item.SomeID)
{
MyClass someClass = new MyClass();
lastSomeId = item.SomeID;
//decimal? LI = 0;//was going to use these as vars for calculations not sure I need them???
//decimal? DSC = 0;
//decimal? FU = 0;
someClass.Id = lastSomeId;
someClass.OrdNum = item.OrderNumber;
if (item.Code == "LI")
{
someClass.LICode = item.Code;
someClass.LICodeValue = item.NetCharge;
}
if (item.Code == "DT")
{
someClass.DTCode = item.Code;
someClass.DTCodeValue = item.NetCharge
}
if (item.Code == "FU")
{
someClass.FUCode = item.Code;
someClass.FUCodeValue = item.NetCharge;
}
someClass.Total = (someClass.LICodeValue + someClass.FUCodeValue);
//check for other values to calculate
//insert record to DB
}
else
{
//Insert into db after maipulation of values
}
}
}
isRecordBad = false;
}//END Using
Any clues would be greatly appreciated. Thank you in advance.
I am developing a web application in which i have to import the data in SQL Server from given Excel files using C# and ASP.NET MVC. For this purpose I followed this article. So I used ExcelDataReader to read the Excel files. Furthermore I have used SqlBulkCopy in my code to insert the data into the database. following is my code:
The Create method
var bData = getBillData();
var connString = ConfigurationManager.ConnectionStrings["WASABill"].ConnectionString;
DataTable table = new DataTable();
using (var reader = ObjectReader.Create(bData))
{
table.Load(reader);
}
using (SqlBulkCopy bcp = new SqlBulkCopy(connString))
{
bcp.ColumnMappings.Add("AccountNo", "AccountNo");
bcp.ColumnMappings.Add("BillNo", "BillNo");
bcp.ColumnMappings.Add("Category", "Category");
bcp.ColumnMappings.Add("Billing_Period", "Billing_Period");
bcp.ColumnMappings.Add("Name", "Name");
bcp.ColumnMappings.Add("Address", "Address");
bcp.ColumnMappings.Add("Issue_Date", "Issue_Date");
bcp.ColumnMappings.Add("Due_Date", "Due_Date");
bcp.ColumnMappings.Add("Water_Bill", "Water_Bill");
bcp.ColumnMappings.Add("Sewerage_Bill", "Sewerage_Bill");
bcp.ColumnMappings.Add("Aquifer_Charges", "Aquifer_Charges");
bcp.ColumnMappings.Add("Current_Amount", "Current_Amount");
bcp.ColumnMappings.Add("Arrears", "Arrears");
bcp.ColumnMappings.Add("Service_Charges", "Service_Charges");
bcp.ColumnMappings.Add("Payable_within_DueDate", "Payable_within_DueDate");
bcp.ColumnMappings.Add("Surcharge", "Surcharge");
bcp.ColumnMappings.Add("Payable_after_DueDate", "Payable_after_DueDate");
bcp.ColumnMappings.Add("Payment_History_1", "Payment_History_1");
bcp.ColumnMappings.Add("Paid_1", "Paid_1");
bcp.ColumnMappings.Add("Payment_History_2", "Payment_History_2");
bcp.ColumnMappings.Add("Paid_2", "Paid_2");
bcp.ColumnMappings.Add("Payment_History_3", "Payment_History_3");
bcp.ColumnMappings.Add("Paid_3", "Paid_3");
bcp.ColumnMappings.Add("Area", "Area");
bcp.ColumnMappings.Add("Water_Rate", "Water_Rate");
bcp.ColumnMappings.Add("Sewerage_Rate", "Sewerage_Rate");
bcp.ColumnMappings.Add("Discharge_Basis", "Discharge_Basis");
bcp.ColumnMappings.Add("Pump_Size", "Pump_Size");
bcp.ColumnMappings.Add("Ferrule_Size", "Ferrule_Size");
bcp.ColumnMappings.Add("Meter_Type", "Meter_Type");
bcp.ColumnMappings.Add("Meter_Status", "Meter_Status");
bcp.ColumnMappings.Add("Last_Readin", "Last_Readin");
bcp.ColumnMappings.Add("Current_Reading", "Current_Reading");
bcp.ColumnMappings.Add("Water_Aquiffer_Charges", "Water_Aquiffer_Charges");
bcp.DestinationTableName = "WASA_Bill_Detail";
bcp.WriteToServer(table);
}
var rowCount = table.Rows.Count; //Number of rows in data table
//if (ModelState.IsValid)
//{
// db.WASA_Bill_Detail.Add(wASA_Bill_Detail);
// db.SaveChanges();
// return RedirectToAction("Index");
//}
TempData["RowCount"] = rowCount;
return RedirectToAction("Index");
The method which reads the Excel file and returns the data as a list
public IEnumerable<WASA_Bill_Detail> getBillData()
{
List<WASA_Bill_Detail> billDetaileList = new List<WASA_Bill_Detail>();
//string path = #TempData["FilePath"].ToString();//#"E:\W317.xlsx";
string path = TempData["FilePath"].ToString();
string excelpath = Server.MapPath(path);
if(path!=null)
{
var excelData = new ExcelData(excelpath);
var billRecords = excelData.getData("Sheet1");
foreach (var row in billRecords)
{
var billDetail = new WASA_Bill_Detail()
{
AccountNo = row["ACCOUNT#"].ToString(),
BillNo = row["BILLNO"].ToString(),
Category = row["CATEGORY"].ToString(),
Billing_Period = row["BILLING_PERIOD"].ToString(),
Name = row["NAME"].ToString(),
Address = row["ADDRESS"].ToString(),
Issue_Date = row["ISSUE_DATE"].ToString(),
Due_Date = row["DUE_DATE"].ToString(),
Water_Bill = row["WATER_BILL"].ToString(),
Sewerage_Bill = row["SEWERAGE BILL"].ToString(),
Aquifer_Charges = row["AQUIFER"].ToString(),
Current_Amount = row["CURRENT AMOUNT"].ToString(),
Arrears = row["ARREARS"].ToString(),
Service_Charges = row["SERVICE CHARGES"].ToString(),
Payable_within_DueDate = row["PAYABLE WITHIN DUEDATE"].ToString(),
Surcharge = row["SURCHARGE"].ToString(),
Payable_after_DueDate = row["AFTER DUE DATE"].ToString(),
Payment_History_1 = row["PAY HISTORY 1"].ToString(),
Paid_1 = row["PAID 1"].ToString(),
Payment_History_2 = row["PAY HISOTRY 2"].ToString(),
Paid_2 = row["PAID 2"].ToString(),
Payment_History_3 = row["PAY HISOTRY 3"].ToString(),
Paid_3 = row["PAID 3"].ToString(),
Area = row["AREA"].ToString(),
Water_Rate = row["WATER RATE"].ToString(),
Sewerage_Rate = row["SEWER RATE"].ToString(),
Discharge_Basis = row["DISCHAGE"].ToString(),
Pump_Size = row["PUMP SIZE"].ToString(),
Ferrule_Size = row["FERRULE SIZE"].ToString(),
Meter_Type = row["METER TYPE"].ToString(),
Meter_Status = row["METER STATUS"].ToString(),
Last_Readin = row["LAST READING"].ToString(),
Current_Reading = row["CURRENT READING"].ToString(),
Water_Aquiffer_Charges = row["AQUIFER CHARGES"].ToString(),
};
billDetaileList.Add(billDetail);
}
}
return billDetaileList;
}
Everything is working fine on my development machine. File uploaded properly and then inserted into the database using bcp.
But when I publish this to the hosting server the NullReferenceException occurred at
WASAWeb.Controllers.AdminControllers.WASA_Bill_DetailController.getBillData() +128
I could not understand as it is working 100% fine in my development machine. I have checked that file is properly uploaded to the server.
Any help with this?
you can use this:
private string GetStringValue(object obj)
{
string str = null;
if(obj != null)
str = obj.ToString().Trim();
return str;
}
call
......
AccountNo = GetStringValue(row["ACCOUNT#"])
......
i am making a Job reporter application, and till now what i did is, imported C.S.V file to grid view and displaying it by saving it in a data table, now what i want is,update and save the record back in the c.s.v file, i am not using any S.Q.L or any type of database, is it possible to do this?
please help me, i have to deliver project in two hours.
The project is C# Win forms.
Also help me in how i can serialize it to upload into ftp server.
THE CODE IS here...
private void openProjectToolStripMenuItem_Click_1(object sender, EventArgs e)
{
// int size = -1;
OpenFileDialog ofd = new OpenFileDialog()
{
Title = "Choose a File",
InitialDirectory = #"c:\dev\",
Filter = "Text Files (.txt)|*.txt|XML Files|*.xml|Word Documents (.docx)|*.docx",
RestoreDirectory = true,
Multiselect = false
};
if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
MessageBox.Show("No file selected!");
return;
}
using (StreamReader oStreamReader = new StreamReader(ofd.FileName))
{
try
{
Application.DoEvents();
DataSet ds = new DataSet("ApplicationData");
//some updates in the Datatable
DataTable JobHeaderDataTable = new DataTable("JobHeaderDataTable");
DataTable JobDate = new DataTable("JobDate");
DataTable JobDateItems = new DataTable("JobDateItems");
ds.Tables.Add(JobHeaderDataTable);
ds.Tables.Add(JobDate);
ds.Tables.Add(JobDateItems);
int rowCount = 0;
string[] columnNames = null;
string[] oStreamDataValues = null;
while (!oStreamReader.EndOfStream)
{
string oStreamRowData = oStreamReader.ReadLine().Trim();
if (oStreamRowData.Length > 0)
{
oStreamDataValues = oStreamRowData.Split('-');
if (rowCount == 0 && oStreamDataValues[0].ToString() == "HDR")
{
rowCount = 1;
columnNames = oStreamDataValues;
for (int i = 1; i < columnNames.Length; i++)
{
DataColumn oDataColumn = new DataColumn(columnNames[i].ToUpper(), typeof(string));
oDataColumn.DefaultValue = string.Empty;
JobHeaderDataTable.Columns.Add(oDataColumn);
}
//// For Slider
//txtCompany.Text = oStreamDataValues.GetValue(1).ToString();
//txtLocation.Text = oStreamDataValues.GetValue(2).ToString();
//txtRigName.Text = oStreamDataValues.GetValue(3).ToString();
//txtState.Text = oStreamDataValues.GetValue(4).ToString();
//txtCounty.Text = oStreamDataValues.GetValue(5).ToString();
//txtWellName.Text = oStreamDataValues.GetValue(6).ToString();
//txtTownship.Text = oStreamDataValues.GetValue(7).ToString();
//txtDescription.Text = oStreamDataValues.GetValue(8).ToString();
//txtBentHstSub.Text = oStreamDataValues.GetValue(9).ToString();
//txtBilToBend.Text = oStreamDataValues.GetValue(10).ToString();
//txtPadOD.Text = oStreamDataValues.GetValue(11).ToString();
//txtNBStab.Text = oStreamDataValues.GetValue(11).ToString();
//txtJob_ID.Text = oStreamDataValues.GetValue(12).ToString();
//// For Header
//txtCompanyHeader.Text = oStreamDataValues.GetValue(1).ToString();
//txtLocationHeader.Text = oStreamDataValues.GetValue(2).ToString();
//txtRigNameHeader.Text = oStreamDataValues.GetValue(3).ToString();
//txtStateHeader.Text = oStreamDataValues.GetValue(4).ToString();
//txtCountyHeader.Text = oStreamDataValues.GetValue(5).ToString();
//txtWellNameHeader.Text = oStreamDataValues.GetValue(6).ToString();
//txtTownshipHeader.Text = oStreamDataValues.GetValue(7).ToString();
//txtDescriptionHeader.Text = oStreamDataValues.GetValue(8).ToString();
//txtBentHstSubHeader.Text = oStreamDataValues.GetValue(9).ToString();
//txtBillToBendHeader.Text = oStreamDataValues.GetValue(10).ToString();
//txtPadODHeader.Text = oStreamDataValues.GetValue(11).ToString();
//txtNBStabHeader.Text = oStreamDataValues.GetValue(11).ToString();
//txtJob_IDHeader.Text = oStreamDataValues.GetValue(12).ToString();
}
else
{
DataRow oDataRow = JobHeaderDataTable.NewRow();
for (int i = 1; i < columnNames.Length; i++)
{
oDataRow[columnNames[i]] = oStreamDataValues[i] == null ? string.Empty : oStreamDataValues[i].ToString();
}
JobHeaderDataTable.Rows.Add(oDataRow);
}
}
}
oStreamReader.Close();
oStreamReader.Dispose();
foreach (DataRow dr in JobHeaderDataTable.Rows)
{
dataGridView2.DataSource = JobHeaderDataTable;
dataGridView4.DataSource = JobDate;
dataGridView5.DataSource = JobDateItems;
}
}
catch (IOException)
{
}
}
}
Save yourself some headache and check out, ClosedXML, and create the csv using this answer is available Can I save an EXCEL worksheet as CSV via ClosedXML?.
System.IO.File.WriteAllLines(csvFileName,
worksheet.RowsUsed().Select(row =>
string.Join(";", row.Cells(1, row.LastCellUsed(false).Address.ColumnNumber)
.Select(cell => cell.GetValue<string>()))
));
I have to fetch Work Order record from NetSuite based on work order number, I can do that using a saved search but would like to do it without it, so as i do not have a to create another saved search record in production. My code is not returning any result, however the search is successful.
here is the code i am using:
TransactionSearch ts = new TransactionSearch();
TransactionSearchBasic tsb = new TransactionSearchBasic();
// work order number
SearchStringField sfTranId = new SearchStringField();
sfTranId.#operator = SearchStringFieldOperator.#is;
sfTranId.searchValue = workorder;
sfTranId.operatorSpecified = true;
// type
SearchEnumMultiSelectField sfType = new SearchEnumMultiSelectField();
sfType.#operator = SearchEnumMultiSelectFieldOperator.anyOf;
sfType.operatorSpecified = true;
sfType.searchValue = new String[] {"_workOrder"};
tsb.tranId = sfTranId;
tsb.type = sfType;
ts.basic = tsb;
tsa3.criteria = ts;
// perform the search
SearchResult res = _service.search(ts);
res.pageSizeSpecified = true;
if (res.status.isSuccess)
{
SearchRow[] searchRows = res.searchRowList;
if (searchRows != null && searchRows.Length >= 1)
{
TransactionSearchRow tranRow = (TransactionSearchRow)searchRows[0];
if (tranRow.basic.internalId != null && tranRow.basic.internalId.Length > 0)
{
woResult = tranRow.basic.internalId[0].searchValue.internalId;
}
}
}
I realized my mistake, basic search returns RecordList and not SearchRowList.
I try to import data from my POS System to Quickbooks to create General Journal entries. When i add some static(hard coded) data all saved successfully. But when I try to add data from my app QB add data to dataService but when i sync QB data didn't come. Please could you help with my problem. Here is my code.
//main code to add General Journal Entry to QB
var header = GenerateReportHeader(model);
var creditInfo = GenerateJournalEntryLines(model.CreditInformation, PostingTypeEnum.Credit);
var debitInfo = GenerateJournalEntryLines(model.DebitInformation, PostingTypeEnum.Debit);
var allLines = creditInfo.Concat(debitInfo).ToArray();
var result = new JournalEntry();
result.Header = header;
result.Line = allLines;
dataService.Add(result);
//Add Header
private JournalEntryHeader GenerateReportHeader(GeneralJournalModel model)
{
var result = new JournalEntryHeader
{
TxnDate = new DateTime(2013,7,1),
Status = "Payable",
Adjustment = false,
TxnDateSpecified = true
};
if (!String.IsNullOrEmpty(model.EntryNo))
{
result.DocNumber = model.EntryNo;
}
return result;
}
//Add Line
private JournalEntryLine[] GenerateJournalEntryLines(List<GeneralJournalEntryModel> model, PostingTypeEnum postType)
{
var result = new JournalEntryLine[model.Count];
for (int i = 0; i < model.Count; i++)
{
var journalEntryLine = model[i];
var account = GetAccountByNumber(journalEntryLine.AccountNumber);
var toAdd = new JournalEntryLine
{
AccountId = account.Id,
AccountType = account.Type,
AccountName = account.Name,
Amount = Convert.ToDecimal(journalEntryLine.Amount),
AmountSpecified = true,
PostingType = postType,
AccountTypeSpecified = true,
Id = new IdType(),
PostingTypeSpecified = true
};
if (journalEntryLine.EntityId != null)
{
toAdd.EntityId = GetEntityId(journalEntryLine.EntityType, journalEntryLine.EntityId);
toAdd.EntityType = GetEntityType(journalEntryLine.EntityType);
toAdd.EntityName = GetEntityName(journalEntryLine.EntityType, journalEntryLine.EntityId);
toAdd.EntityTypeSpecified = true;
}
result[i] = toAdd;
}
return result;
}
Did you check the SyncStatus, and find out why not?
This should be where you start:
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0500_quickbooks_windows/0600_object_reference/syncstatus
It will give you more detail about specifically why the data failed to sync over.