Private Sub WRITEFILESALES()
Dim dt As New DataTable
Dim strQ As String = ""
strQ = "SELECT * FROM SALES WHERE RouteNo=" & Session.Contents("irouteno") & ""
dt = GetData(strQ, "SALES.mdb")
If dt.Rows.Count <= 0 Then
Response.Write("<script language='javascript'>window.alert('ไม่มีข้อมูล!');</script>")
Return
End If
Dim sw As StreamWriter
'Dim isoStorage As IsolatedStorage.IsolatedStorageFile
''isoStorage = IsolatedStorage.IsolatedStorageFile.GetUserStoreForDomain
'isoStorage = IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication
''Dim writer As New (stmWriter, Encoding.UTF8)
'Dim sw As New IsolatedStorage.IsolatedStorageFileStream(Session.Contents("irouteno") & "Sales.txt", _
' FileMode.Create, isoStorage)
'Dim writer As New System.Xml.XmlTextWriter(sw, Encoding.UTF8)
If File.Exists(txtsaveto.Text.Trim & Session.Contents("irouteno") & "Sales.txt") Then
Response.Write("<script language='javascript'>window.alert('ชื่อไฟล์ซ้ำมีไฟล์ชื่อนี้อยู่แล้ว!');</script>")
Return
Else
sw = File.CreateText(txtsaveto.Text.Trim & Session.Contents("irouteno") & "Sales.txt")
End If
Dim line As String = ""
Try
Dim SalesDate As String
Dim RouteNo As String
Dim InvNo As String
Dim BookNo As String
Dim CustCode As String
Dim AmphorCode As String
Dim BILLITEM As String
Dim StockGroup As String
Dim SHCode As String
Dim Qty As String
Dim Discount As String
Dim Amount As String
Dim PriceBig As String
Dim PriceSmall As String
Dim PVAT As String
Dim LastUpdate As String
Dim LastUser As String
For i As Integer = 0 To dt.Rows.Count - 1
SalesDate = CheckNull(dt.Rows(i).Item("SalesDate")) '8
RouteNo = CheckNull(dt.Rows(i).Item("RouteNo")) '3
InvNo = CheckNull(dt.Rows(i).Item("InvNo")) '6
BookNo = CheckNull(dt.Rows(i).Item("BookNo")) '2
CustCode = CheckNull(dt.Rows(i).Item("CustCode")) '8
AmphorCode = CheckNull(dt.Rows(i).Item("AmphorCode")) '4
BILLITEM = CheckNull(dt.Rows(i).Item("BILLITEM")) '3
StockGroup = CheckNull(dt.Rows(i).Item("StockGroup")) '4
SHCode = CheckNull(dt.Rows(i).Item("SHCode")) '7
Qty = CheckNull(dt.Rows(i).Item("Qty")) '7
Discount = CheckNull(dt.Rows(i).Item("Discount")) '12
Amount = CheckNull(dt.Rows(i).Item("Amount")) '12
PriceBig = CheckNull(dt.Rows(i).Item("PriceBig")) '12
PriceSmall = CheckNull(dt.Rows(i).Item("PriceSmall")) '12
PVAT = CheckNull(dt.Rows(i).Item("PVAT")) '7
LastUpdate = CheckNull(dt.Rows(i).Item("LastUpdate")) '13
LastUser = CheckNull(dt.Rows(i).Item("LastUser")) '10
line = SalesDate.PadRight(8, "") & RouteNo.PadRight(3, "") & _
InvNo.PadRight(6, "") & BookNo.PadRight(2, "") & _
CustCode.PadRight(8, "") & AmphorCode.PadRight(4, "") & _
BILLITEM.PadRight(3, "") & StockGroup.PadRight(4, "") & _
SHCode.PadLeft(7, "0") & Qty.PadLeft(7, "0") & _
Discount.PadLeft(12, "0") & Amount.PadLeft(12, "0") & _
PriceBig.PadLeft(12, "0") & PriceSmall.PadLeft(12, "0") & _
PVAT.PadLeft(7, "0") & LastUpdate.PadRight(13, "") & _
LastUser.PadRight(10, "")
sw.WriteLine(line) ' change padding parameter accordingly!
Next
sw.WriteLine("EOD")
dt.Dispose()
sw.Close()
Response.Write("<script language='javascript'>window.alert('ดาวน์โหลดข้อมูลเรียบร้อย');</script>")
Catch ex As Exception
Response.Write("<script language='javascript'>window.alert('ไม่สามารถดาวน์โหลดข้อมูลได้!');</script>")
Exit Sub
End Try
End Sub
Tag : .NET
Date :
2010-08-03 22:27:00
By :
njnight
View :
1433
Reply :
6
No. 1
Guest
Code (C#)
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace StorageCardInfo
{
class Program
{
const ulong Megabyte = 1048576;
const ulong Gigabyte = 1073741824;
[DllImport("CoreDLL")]
static extern int GetDiskFreeSpaceEx(
string DirectoryName,
out ulong lpFreeBytesAvailableToCaller,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes
);
static void Main(string[] args)
{
DirectoryInfo root = new DirectoryInfo("\\");
DirectoryInfo[] directoryList = root.GetDirectories();
ulong FreeBytesAvailable;
ulong TotalCapacity;
ulong TotalFreeBytes;
for (int i = 0; i < directoryList.Length; ++i)
{
if ((directoryList.Attributes & FileAttributes.Temporary) != 0)
{
GetDiskFreeSpaceEx(directoryList.FullName, out FreeBytesAvailable, out TotalCapacity, out TotalFreeBytes);
Console.Out.WriteLine("Storage card name: {0}", directoryList.FullName);
Console.Out.WriteLine("Available Bytes : {0}", FreeBytesAvailable);
Console.Out.WriteLine("Total Capacity : {0}", TotalCapacity);
Console.Out.WriteLine("Total Free Bytes : {0}", TotalFreeBytes);
}
}
}
}
Private Sub WRITEFILESALES()
Dim dt As New DataTable
Dim strQ As String = ""
strQ = "SELECT * FROM SALES WHERE RouteNo=" & Session.Contents("irouteno") & ""
dt = GetData(strQ, "SALES.mdb")
If dt.Rows.Count <= 0 Then
Response.Write("<script language='javascript'>window.alert('ไม่มีข้อมูล!');</script>")
Return
End If
'==============================================
Dim rootDir As DirectoryInfo = New DirectoryInfo("\")
Dim attrStorageCard As FileAttributes = (FileAttributes.Directory Or FileAttributes.Temporary)
Dim fsi As FileSystemInfo
Dim strpath As String = ""
For Each fsi In rootDir.GetFileSystemInfos()
Dim n As Integer = fsi.FullName.IndexOf("\")
strpath = fsi.FullName.Substring(0, n)
Next
Dim sw As StreamWriter
If File.Exists(strpath + txtsaveto.Text.Trim & Session.Contents("irouteno") & "Sales.txt") Then
Response.Write("<script language='javascript'>window.alert('ชื่อไฟล์ซ้ำมีไฟล์ชื่อนี้อยู่แล้ว!');</script>")
Return
Else
sw = File.CreateText(strpath + txtsaveto.Text.Trim & Session.Contents("irouteno") & "Sales.txt")
End If
Dim line As String = ""
Try
Dim SalesDate As String
Dim RouteNo As String
Dim InvNo As String
Dim BookNo As String
Dim CustCode As String
Dim AmphorCode As String
Dim BILLITEM As String
Dim StockGroup As String
Dim SHCode As String
Dim Qty As String
Dim Discount As String
Dim Amount As String
Dim PriceBig As String
Dim PriceSmall As String
Dim PVAT As String
Dim LastUpdate As String
Dim LastUser As String
For i As Integer = 0 To dt.Rows.Count - 1
SalesDate = CheckNull(dt.Rows(i).Item("SalesDate")) '8
RouteNo = CheckNull(dt.Rows(i).Item("RouteNo")) '3
InvNo = CheckNull(dt.Rows(i).Item("InvNo")) '6
BookNo = CheckNull(dt.Rows(i).Item("BookNo")) '2
CustCode = CheckNull(dt.Rows(i).Item("CustCode")) '8
AmphorCode = CheckNull(dt.Rows(i).Item("AmphorCode")) '4
BILLITEM = CheckNull(dt.Rows(i).Item("BILLITEM")) '3
StockGroup = CheckNull(dt.Rows(i).Item("StockGroup")) '4
SHCode = CheckNull(dt.Rows(i).Item("SHCode")) '7
Qty = CheckNull(dt.Rows(i).Item("Qty")) '7
Discount = CheckNull(dt.Rows(i).Item("Discount")) '12
Amount = CheckNull(dt.Rows(i).Item("Amount")) '12
PriceBig = CheckNull(dt.Rows(i).Item("PriceBig")) '12
PriceSmall = CheckNull(dt.Rows(i).Item("PriceSmall")) '12
PVAT = CheckNull(dt.Rows(i).Item("PVAT")) '7
LastUpdate = CheckNull(dt.Rows(i).Item("LastUpdate")) '13
LastUser = CheckNull(dt.Rows(i).Item("LastUser")) '10
line = SalesDate.PadRight(8, "") & RouteNo.PadRight(3, "") & _
InvNo.PadRight(6, "") & BookNo.PadRight(2, "") & _
CustCode.PadRight(8, "") & AmphorCode.PadRight(4, "") & _
BILLITEM.PadRight(3, "") & StockGroup.PadRight(4, "") & _
SHCode.PadLeft(7, "0") & Qty.PadLeft(7, "0") & _
Discount.PadLeft(12, "0") & Amount.PadLeft(12, "0") & _
PriceBig.PadLeft(12, "0") & PriceSmall.PadLeft(12, "0") & _
PVAT.PadLeft(7, "0") & LastUpdate.PadRight(13, "") & _
LastUser.PadRight(10, "")
sw.WriteLine(line)
Next
sw.WriteLine("EOD")
dt.Dispose()
sw.Close()
Catch ex As Exception
Response.Write("<script language='javascript'>window.alert('ไม่สามารถดาวน์โหลดข้อมูลได้!');</script>")
Exit Sub
End Try
End Sub
ใช่ค่ะเราก็คิดว่าติดเรื่องสิทธิ์ สงสัยจะชี้พาท ไปผิดที่ เพราะถ้าดาวน์โหลดลงในมือถือ user เองไม่น่าจะติดเรื่องสิทธิ์ได้
Code (VB.NET)
'==============================================
Dim rootDir As DirectoryInfo = New DirectoryInfo("\")
Dim attrStorageCard As FileAttributes = (FileAttributes.Directory Or FileAttributes.Temporary)
Dim fsi As FileSystemInfo
Dim strpath As String = ""
For Each fsi In rootDir.GetFileSystemInfos()
Dim n As Integer = fsi.FullName.IndexOf("\")
strpath = fsi.FullName.Substring(0, n)
Next