我在Visual Studio 2017中創建一個項目,我需要填寫一個複選框,用我以前創建的文本文件的名稱創建併發送到FTP服務器。 這可能嗎? 下面是我的一些代碼,隨意問更多的代碼:連接一個窗體與控制檯
創建文件,並將其保存:
using (StreamWriter writer = new StreamWriter("C:\\Users\\HP8200\\Desktop\\Faturas Teste\\Fatura " + _transaction.TransDocNumber + ".txt"))
{
string numcont = _transaction.PartyFederalTaxID;
double numenc = _transaction.BillToPartyID;
double numfatura = _transaction.TransDocNumber;
DateTime data = _transaction.CreateDate;
double valor = _transaction.TotalAmount;
int zona = transaction.UnloadPlaceAddress.AddressID;
string zona2 = transaction.UnloadPlaceAddress.AddressLine2;
double precoantesdisc = bsoItemTrans.BSOItemTransactionDetail.TransactionDetail.PackUnitPrice;
double preconet = transaction.TotalTransactionAmount;
double quantidade = transaction.Details.Count;
string bonus = "0";
string valorStr = valor.ToString(CultureInfo.InvariantCulture);
string preconetStr = preconet.ToString(CultureInfo.InvariantCulture);
string precoantesdiscStr = precoantesdisc.ToString(CultureInfo.InvariantCulture);
writer.WriteLine($"{numcont};{numenc};{numfatura};{data:dd/MM/yyyy};{valorStr};{zona};");
foreach (ItemTransactionDetail detail in transaction.Details)
{
var item = MyApp.DSOCache.ItemProvider.GetItem(detail.ItemID, MyApp.SystemSettings.BaseCurrency);
double taxRate = MyApp.DSOCache.TaxesProvider.GetTaxRateFromTaxableGroupID(detail.TaxableGroupID, "PRT", "CON");
string barcode = item.BarCode;
writer.WriteLine($"{barcode};{taxRate};{precoantesdiscStr};{preconetStr};{quantidade};{bonus}");
}
}
SqlConnection conn = new SqlConnection(@"Data source = 2c4138928627\Sage ; Database=ARMINDOData ; User Id=sa ; Password=sage2008+");
SqlCommand command = new SqlCommand("IF OBJECT_ID('UXZona', 'U') IS NULL CREATE TABLE UXZona(IDZona int,Morada char(50));", conn);
conn.Open();
SqlCommand insertCommand = new SqlCommand("INSERT INTO UXZona(FirstColumn, SecondColumn) VALUES (@0, @1)", conn);
command.ExecuteNonQuery();
SqlCommand con = new SqlCommand("IF OBJECT_ID('UXZona', 'U') IS NULL CREATE TABLE UXZona(IDZona int,Morada char(50));", conn);
MessageBox.Show("gravou");
表單代碼:
在窗體上我只是一個空的清單和一個提交按鈕。
UPDATE
新增2截圖更具體
在這裏,我,我跟上面的代碼
創建文本文件,我需要把名字在這個清單中的文件,然後當我按下提交按鈕時,它將文本文件發送到我擁有的FTP服務器。
更新2: 添加一些代碼的M Idrees給我。
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
void LoadFileNames()
{
string path = @"C:\Users\HP8200\Desktop\Faturas Teste";
string fileNameOnly = "";
foreach (var item in System.IO.Directory.GetFiles(path, "*.txt")) // here you can change file extension according to your needs.
{
fileNameOnly = System.IO.Path.GetFileNameWithoutExtension(item);
checkedListBox1.Items.Add(fileNameOnly); // actually adding files names to checkbox listing
}
}
}
評論不適用於擴展討論;這個對話已經[轉移到聊天](http://chat.stackoverflow.com/rooms/151621/discussion-on-question-by-joao-costa-connecting-a-form-with-console)。 –