Peter Chan
asked on
Problem to codes
Hi,
there is no output file generated due to the writer below
there is no output file generated due to the writer below
For Each companyCode In ds.Select(Function(x) x.CompanyCode).Distinct
Using writer As StreamWriter = New StreamWriter("c:\\out1.txt")
writer.WriteLine("33 " + companyCode)
End Using
For Each journalCode In ds.Where(Function(x) x.CompanyCode.Equals(companyCode, StringComparison.OrdinalIgnoreCase)).Select(Function(x) x.JournalCode).Distinct
GenerateFile(companyCode, journalCode, dataRangeCollection)
Next
Next
what can I further check, for the reason of this?
ASKER
Right before the above codes, I really am able to write to "c:\".
The problem is, how to capture the reason why the above writer part codes are not able to create file, as expected.
The problem is, how to capture the reason why the above writer part codes are not able to create file, as expected.
ASKER
Any other way to capture any other reasons there?
>>Right before the above codes, I really am able to write to "c:\".
How? Is it the same way with a stream writer? (Please show some code you use)
How? Is it the same way with a stream writer? (Please show some code you use)
ASKER
Yes, same way.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If the part cannot be executed, how to find out more reasons, to the following codes?
ds = New ExportInterComSalesDataToSunAccountDataSource(dataRangeCollection, ReportOption.GetDatabases, conn)
TotalLoadedRows += ds.LoadReportData
CloseConnection(conn)
For Each companyCode In ds.Select(Function(x) x.CompanyCode).Distinct
For Each journalCode In ds.Where(Function(x) x.CompanyCode.Equals(companyCode, StringComparison.OrdinalIgnoreCase)).Select(Function(x) x.JournalCode).Distinct
GenerateFile(companyCode, journalCode, dataRangeCollection)
Next
Next
ASKER
And here is
Public Class ExportInterComSalesDataToSunAccountDataSource
Inherits ExportDataToSunAccountDataSourceBase
Public Sub New(ByVal reportOptions As ISalesReportOptions,
Optional ByVal Databases() As String = Nothing,
Optional ByVal dataConnection As MySqlConnection = Nothing)
MyBase.New(reportOptions, Databases, dataConnection)
DocumentCode = "INTERCOM SALES"
End Sub
Public Sub New(ByVal dataRanges As DataRangeOptionCollection,
Optional ByVal Databases() As String = Nothing,
Optional ByVal dataConnection As MySqlConnection = Nothing)
MyBase.New(dataRanges, Databases, dataConnection)
DocumentCode = "INTERCOM SALES"
End Sub
Private brandList As BrandCollection
Public Overrides Function LoadReportData() As Integer
Dim loadCount As Integer = 0
Dim conn As MySqlConnection = OpenConnection()
If brandList Is Nothing Then
brandList = New BrandCollection
brandList.LoadFromDb(conn)
End If
loadCount += LoadSalesData(conn)
loadCount += LoadPaymentData(conn)
CloseConnection()
Return loadCount
End Function
Public Function LoadSalesData(conn As MySqlConnection) As Integer
Dim rtv As Integer = 0
Dim sqls() As String = Nothing
If OptionForm IsNot Nothing Then
sqls = GetQueries(Function(db) GetSalesDataSqlProductLevel(db, OptionForm))
Else
sqls = GetQueries(Function(db) GetSalesDataSqlProductLevel(db, DataRanges, True))
End If
Dim sql As String = String.Join(" union all ", sqls)
Dim data As DataTable = GetDataTable(sql, conn)
Dim companyCode As String = ""
Dim journalCode As String = ""
Dim accountCode As String = ""
Dim description As String = ""
Dim transactionRef As String = ""
Dim tdate As Date = Nothing
Dim debitCredit As String = ""
Dim brandName As String = ""
Dim brandCode As String = ""
Dim productTypeCode As String = ""
Dim department As String = ""
Dim staffNo As String = ""
Dim shopCode As String = ""
Dim shopName As String = ""
Dim stakeholder As String = ""
Dim analysisValue As String = ""
Dim accCodeItem As SunAccountCodeItem
For Each row As DataRow In data.Rows
journalCode = ""
accountCode = ""
debitCredit = ""
description = "Sales Import"
transactionRef = ""
tdate = row(TXNDATE_FIELD.AliasName).ToString.Trim
productTypeCode = row(PRODUCTTYPECODE_FIELD.AliasName).ToString.Trim
department = "SHOES"
brandName = row(PRODUCTBRANDNAME_FIELD.AliasName).ToString.Trim
If brandList.Contains(brandName) Then brandCode = brandList.Item(brandName).BrandCodes.Min()
shopCode = row(SHOPCODE_FIELD.AliasName).ToString.Trim
shopName = FromDbText(row(SHOPNAME_FIELD.AliasName).ToString.Trim)
companyCode = GetSunAccountCompanyCode(row(DBGROUP_FIELD.AliasName).ToString)
If GetSunShopCompany(shopCode) <> "" Then companyCode = GetSunShopCompany(shopCode)
staffNo = ""
stakeholder = ""
analysisValue = String.Format("{0}.{1}.{2}.{3}", companyCode, shopCode, FOR_ALL, C_SALES)
accCodeItem = GetSunAccountCode(DocumentCode, analysisValue)
If accCodeItem IsNot Nothing Then
journalCode = accCodeItem.JournalCode
accountCode = accCodeItem.AccountCode
debitCredit = accCodeItem.DebitCredit
transactionRef = String.Format("{0}{1:yyyyMMdd}{2}", journalCode, tdate, shopCode)
Dim theItem As ExportDataToSunAccountItem = item(companyCode, journalCode, accountCode, description, transactionRef, tdate, debitCredit, productTypeCode, department, brandCode, staffNo, shopCode, stakeholder)
If theItem Is Nothing Then
theItem = New ExportDataToSunAccountItem(companyCode, journalCode, accountCode, description, transactionRef, tdate, debitCredit, productTypeCode, department, brandCode, staffNo, shopCode, stakeholder)
Add(theItem)
End If
theItem.Amount += row("damount")
End If
rtv += 1
Next
Return rtv
End Function
Public Function LoadPaymentData(conn As MySqlConnection) As Integer
Dim rtv As Integer = 0
Dim ds As FinanceDailyPaymentDataSource
If OptionForm IsNot Nothing Then
ds = New FinanceDailyPaymentDataSource(OptionForm, Databases, conn)
Else
ds = New FinanceDailyPaymentDataSource(DataRanges, Databases, conn)
End If
rtv += ds.LoadReportData()
Dim companyCode As String = ""
Dim journalCode As String = ""
Dim accountCode As String = ""
Dim description As String = ""
Dim transactionRef As String = ""
Dim tdate As Date = Nothing
Dim debitCredit As String = ""
Dim brandName As String = ""
Dim brandCode As String = ""
Dim productTypeCode As String = ""
Dim department As String = ""
Dim staffNo As String = ""
Dim shopCode As String = ""
Dim shopName As String = ""
Dim stakeholder As String = ""
Dim totalAmount As Double = 0.0
Dim bankCharges As Double = 0.0
Dim analysisValue As String = ""
Dim accCodeItem As SunAccountCodeItem
For Each country In ds
For Each shop In country
For Each docDate In shop
For Each paymentItem In docDate
accountCode = ""
journalCode = ""
debitCredit = ""
description = "Sales Import"
transactionRef = ""
tdate = docDate.DocumentDate
productTypeCode = ""
department = "SHOES"
brandName = ""
shopCode = shop.ShopAlias
shopName = shop.ShopName
companyCode = GetSunAccountCompanyCode(shop.DB)
If GetSunShopCompany(shopCode) <> "" Then companyCode = GetSunShopCompany(shopCode)
staffNo = ""
stakeholder = ""
bankCharges = Math.Round(paymentItem.Value * paymentItem.PaymentChgRate, 2)
totalAmount = paymentItem.Value
Dim theItem As ExportDataToSunAccountItem
analysisValue = String.Format("{0}.{1}.{2}.{3}", companyCode, shopCode, paymentItem.Code, C_BANKAMT)
accCodeItem = GetSunAccountCode(DocumentCode, analysisValue)
If accCodeItem Is Nothing Then
analysisValue = String.Format("{0}.{1}.{2}.{3}", companyCode, shopCode, FOR_ALL, C_BANKAMT)
accCodeItem = GetSunAccountCode(DocumentCode, analysisValue)
End If
If accCodeItem IsNot Nothing Then
journalCode = accCodeItem.JournalCode
accountCode = accCodeItem.AccountCode
debitCredit = accCodeItem.DebitCredit
transactionRef = String.Format("{0}{1:yyyyMMdd}{2}", journalCode, tdate, shopCode)
theItem = item(companyCode, journalCode, accountCode, description, transactionRef, tdate,
debitCredit, productTypeCode, department, brandCode, staffNo, shopCode, stakeholder)
If theItem Is Nothing Then
theItem = New ExportDataToSunAccountItem(companyCode, journalCode, accountCode, description, transactionRef,
tdate, debitCredit, productTypeCode, department, brandCode, staffNo, shopCode, stakeholder)
Add(theItem)
End If
theItem.Amount += (totalAmount - bankCharges)
End If
analysisValue = String.Format("{0}.{1}.{2}.{3}", companyCode, shopCode, paymentItem.Code, C_BANKCHARGES)
accCodeItem = GetSunAccountCode(DocumentCode, analysisValue)
If accCodeItem Is Nothing Then
analysisValue = String.Format("{0}.{1}.{2}.{3}", companyCode, shopCode, FOR_ALL, C_BANKCHARGES)
accCodeItem = GetSunAccountCode(DocumentCode, analysisValue)
End If
If accCodeItem IsNot Nothing Then
journalCode = accCodeItem.JournalCode
accountCode = accCodeItem.AccountCode
debitCredit = accCodeItem.DebitCredit
transactionRef = String.Format("{0}{1:yyyyMMdd}{2}", journalCode, tdate, shopCode)
theItem = item(companyCode, journalCode, accountCode, description,
transactionRef, tdate, debitCredit, productTypeCode,
department, brandCode, staffNo, shopCode, stakeholder)
If theItem Is Nothing Then
theItem = New ExportDataToSunAccountItem(companyCode, journalCode, accountCode, description,
transactionRef, tdate, debitCredit, productTypeCode,
department, brandCode, staffNo, shopCode, stakeholder)
Add(theItem)
End If
theItem.Amount += (bankCharges)
End If
analysisValue = String.Format("{0}.{1}.{2}.{3}", companyCode, shopCode, paymentItem.Code, C_ACCRECEIVABLE)
accCodeItem = GetSunAccountCode(DocumentCode, analysisValue)
If accCodeItem Is Nothing Then
analysisValue = String.Format("{0}.{1}.{2}.{3}", companyCode, shopCode, FOR_ALL, C_ACCRECEIVABLE)
accCodeItem = GetSunAccountCode(DocumentCode, analysisValue)
End If
If accCodeItem IsNot Nothing Then
journalCode = accCodeItem.JournalCode
accountCode = accCodeItem.AccountCode
debitCredit = accCodeItem.DebitCredit
transactionRef = String.Format("{0}{1:yyyyMMdd}{2}", journalCode, tdate, shopCode)
theItem = item(companyCode, journalCode, accountCode, description, transactionRef, tdate, debitCredit,
productTypeCode, department, brandCode, staffNo, shopCode, stakeholder)
If theItem Is Nothing Then
theItem = New ExportDataToSunAccountItem(companyCode, journalCode, accountCode, description, transactionRef,
tdate, debitCredit, productTypeCode, department, brandCode,
staffNo, shopCode, stakeholder)
Add(theItem)
End If
theItem.Amount += (totalAmount)
End If
Next
Next
Next
Next
Return rtv
End Function
End Class
ASKER
I want to capture some values in detail, that is being used by "For Each ..." part, how?
ASKER
Any other help?
I think your original question is partially solved - you know why the file isn't being created/written to.
ASKER
No, I still cannot step further, as I did originally want to step to the next.
ASKER
By this thread.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try creating a directory (eg. C:\test) and writing to a file in that.
Open in new window
ps. Your code only writes the 33 plus the company code - do you want the using outside the loop?
Open in new window