Пример #1
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                ftp ftpClient = new ftp(@"ftp://112.213.89.7", "sanvekhu", "Pnht!)!!**");

                ftpClient.upload("public_html/var/import/test.txt", @"D:\test.txt");

                ftpClient = null;
                MessageBox.Show("Done");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Пример #2
0
        private void timerSync_Tick(object sender, EventArgs e)
        {
            try
            {
                timerSync.Stop();

                string outFileName    = "syncToWeb.csv";
                string exportFilePath = Path.Combine(Directory.GetCurrentDirectory() + @"\Export\", outFileName);
                if (File.Exists(exportFilePath))
                {
                    File.Delete(exportFilePath);
                }

                DataTable dt = new DataTable();
                dt = SanPhamBUS.XuatKhoHang();
                string store       = "admin";
                string sku         = "";
                string qty         = "";
                string is_in_stock = "";
                string gia_si      = "";
                string price       = "";

                foreach (DataRow row in dt.Rows)
                {
                    sku         = row.ItemArray.GetValue(0).ToString();
                    qty         = row.ItemArray.GetValue(1).ToString() + ".0000";
                    is_in_stock = row.ItemArray.GetValue(2).ToString();
                    gia_si      = row.ItemArray.GetValue(3).ToString() + ".0000";
                    price       = row.ItemArray.GetValue(4).ToString() + ".0000";

                    DataRow dr = resultTable.NewRow();
                    dr[0] = store;
                    dr[1] = sku;
                    dr[2] = qty;
                    dr[3] = is_in_stock;
                    dr[4] = gia_si;
                    dr[5] = price;


                    resultTable.Rows.Add(dr);
                }

                StringBuilder sb = new StringBuilder();

                var columnNames = resultTable.Columns.Cast <DataColumn>().Select(column => "\"" + column.ColumnName.Replace("\"", "\"\"") + "\"").ToArray();
                sb.AppendLine(string.Join(",", columnNames));

                foreach (DataRow row in resultTable.Rows)
                {
                    var fields = row.ItemArray.Select(field => "\"" + field.ToString().Replace("\"", "\"\"") + "\"").ToArray();
                    sb.AppendLine(string.Join(",", fields));
                }

                File.WriteAllText(exportFilePath, sb.ToString(), Encoding.UTF8);

                // Upload to FTP
                ftp ftpClient = new ftp(@"ftp://115.84.181.41", "thoitra", "Pnht!)!!**");

                ftpClient.upload("public_html/var/import/syncToWeb.csv", exportFilePath);

                ftpClient = null;

                navigateToMagmiPage();

                MessageBox.Show("Done");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }