舊有資料匯入v2
This commit is contained in:
parent
a16468f22c
commit
1db98a9e7e
@ -74,8 +74,9 @@ namespace solarApp.Service
|
||||
int i = 0;
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
//ss.Append(@"INSERT INTO solar_import.auo_taiping(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID)
|
||||
ss.Append(@"INSERT INTO solar_import.auo_aimai(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID)
|
||||
//ss.Append(@"INSERT INTO solar_import.auo_taiping_October(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID)
|
||||
//ss.Append(@"INSERT INTO solar_import.auo_aimai(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID)
|
||||
ss.Append(@"INSERT INTO solar_import.auo_aimai_october(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID)
|
||||
values( '"
|
||||
+ row.Field<string>("1").ToString() + "' ,'"
|
||||
+ row.Field<string>("2").ToString() + "' ,'"
|
||||
@ -202,7 +203,7 @@ values( '"
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool insert_dailyReport2DB(DataTable dt, string filename)
|
||||
public bool insert_dailyReport2DB(DataTable dt, string filename, string tablename)
|
||||
{
|
||||
bool result = false;
|
||||
StringBuilder ss = new StringBuilder();
|
||||
@ -211,9 +212,9 @@ values( '"
|
||||
conn.Open();
|
||||
int i = 0;
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
//ss.Append(@"INSERT INTO solar_import.auo_taiping(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID)
|
||||
ss.Append(@"INSERT INTO solar_import.iPVita_temp (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, insertDate)
|
||||
{ //c10, c11, c12, c13, c14, c15, c16,
|
||||
//iPVita_temp ss.Append(@"INSERT INTO solar_import.auo_taiping(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID)
|
||||
ss.Append(@"INSERT INTO solar_import."+ tablename + @"(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13 , c14, c15, c16, insertDate)
|
||||
values( '"
|
||||
+ row.Field<string>("1").ToString() + "' ,'"
|
||||
+ row.Field<string>("2").ToString() + "' ,'"
|
||||
@ -229,9 +230,8 @@ values( '"
|
||||
+ row.Field<string>("12").ToString() + "' ,'"
|
||||
+ row.Field<string>("13").ToString() + "' ,'"
|
||||
+ row.Field<string>("14").ToString() + "' ,'"
|
||||
+ row.Field<string>("15").ToString() + "', '"
|
||||
+ row.Field<string>("Column1").ToString() + "', now());");
|
||||
|
||||
+ row.Field<string>("15").ToString() + "', '"
|
||||
+ row.Field<string>("Column1").ToString() + "', now());");
|
||||
if (i % 10 == 0)
|
||||
{
|
||||
conn.Execute(ss.ToString());
|
||||
|
||||
80
solarApp/fmExcel.Designer.cs
generated
80
solarApp/fmExcel.Designer.cs
generated
@ -42,6 +42,7 @@ namespace solarApp
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.lbSiteName_sensor = new System.Windows.Forms.Label();
|
||||
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
|
||||
this.bt_dailyReport = new System.Windows.Forms.Button();
|
||||
this.bt_sun_yadong = new System.Windows.Forms.Button();
|
||||
this.bt_sun_taoyuan = new System.Windows.Forms.Button();
|
||||
this.bt_gong34 = new System.Windows.Forms.Button();
|
||||
@ -51,7 +52,9 @@ namespace solarApp
|
||||
this.rt1 = new System.Windows.Forms.RichTextBox();
|
||||
this.tb1 = new System.Windows.Forms.TabPage();
|
||||
this.tabControl = new System.Windows.Forms.TabControl();
|
||||
this.bt_dailyReport = new System.Windows.Forms.Button();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.button3 = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
|
||||
this.panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
|
||||
@ -97,7 +100,7 @@ namespace solarApp
|
||||
// bt_archive
|
||||
//
|
||||
this.bt_archive.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.bt_archive.Location = new System.Drawing.Point(3, 640);
|
||||
this.bt_archive.Location = new System.Drawing.Point(0, 682);
|
||||
this.bt_archive.Name = "bt_archive";
|
||||
this.bt_archive.Size = new System.Drawing.Size(226, 60);
|
||||
this.bt_archive.TabIndex = 8;
|
||||
@ -120,7 +123,7 @@ namespace solarApp
|
||||
// bt_read_taiping
|
||||
//
|
||||
this.bt_read_taiping.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.bt_read_taiping.Location = new System.Drawing.Point(0, 337);
|
||||
this.bt_read_taiping.Location = new System.Drawing.Point(3, 286);
|
||||
this.bt_read_taiping.Name = "bt_read_taiping";
|
||||
this.bt_read_taiping.Size = new System.Drawing.Size(192, 47);
|
||||
this.bt_read_taiping.TabIndex = 6;
|
||||
@ -131,7 +134,7 @@ namespace solarApp
|
||||
// bt_inv_day_hj
|
||||
//
|
||||
this.bt_inv_day_hj.Font = new System.Drawing.Font("Microsoft JhengHei UI", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.bt_inv_day_hj.Location = new System.Drawing.Point(0, 270);
|
||||
this.bt_inv_day_hj.Location = new System.Drawing.Point(0, 236);
|
||||
this.bt_inv_day_hj.Name = "bt_inv_day_hj";
|
||||
this.bt_inv_day_hj.Size = new System.Drawing.Size(143, 44);
|
||||
this.bt_inv_day_hj.TabIndex = 5;
|
||||
@ -202,6 +205,9 @@ namespace solarApp
|
||||
// splitContainer1.Panel1
|
||||
//
|
||||
this.splitContainer1.Panel1.BackColor = System.Drawing.Color.PaleGoldenrod;
|
||||
this.splitContainer1.Panel1.Controls.Add(this.button3);
|
||||
this.splitContainer1.Panel1.Controls.Add(this.button2);
|
||||
this.splitContainer1.Panel1.Controls.Add(this.button1);
|
||||
this.splitContainer1.Panel1.Controls.Add(this.bt_dailyReport);
|
||||
this.splitContainer1.Panel1.Controls.Add(this.bt_sun_yadong);
|
||||
this.splitContainer1.Panel1.Controls.Add(this.bt_sun_taoyuan);
|
||||
@ -225,32 +231,45 @@ namespace solarApp
|
||||
this.splitContainer1.SplitterWidth = 10;
|
||||
this.splitContainer1.TabIndex = 0;
|
||||
//
|
||||
// bt_dailyReport
|
||||
//
|
||||
this.bt_dailyReport.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.bt_dailyReport.Location = new System.Drawing.Point(7, 748);
|
||||
this.bt_dailyReport.Name = "bt_dailyReport";
|
||||
this.bt_dailyReport.Size = new System.Drawing.Size(237, 74);
|
||||
this.bt_dailyReport.TabIndex = 15;
|
||||
this.bt_dailyReport.Text = "daily_report 太陽能光電-桃園全虹";
|
||||
this.bt_dailyReport.UseVisualStyleBackColor = true;
|
||||
this.bt_dailyReport.Click += new System.EventHandler(this.bt_dailyReport_Click);
|
||||
//
|
||||
// bt_sun_yadong
|
||||
//
|
||||
this.bt_sun_yadong.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.bt_sun_yadong.Location = new System.Drawing.Point(5, 576);
|
||||
this.bt_sun_yadong.Location = new System.Drawing.Point(3, 479);
|
||||
this.bt_sun_yadong.Name = "bt_sun_yadong";
|
||||
this.bt_sun_yadong.Size = new System.Drawing.Size(213, 47);
|
||||
this.bt_sun_yadong.TabIndex = 14;
|
||||
this.bt_sun_yadong.Text = "太陽能光電-亞東觀音";
|
||||
this.bt_sun_yadong.UseVisualStyleBackColor = true;
|
||||
this.bt_sun_yadong.Visible = false;
|
||||
this.bt_sun_yadong.Click += new System.EventHandler(this.bt_sun_yadong_Click);
|
||||
//
|
||||
// bt_sun_taoyuan
|
||||
//
|
||||
this.bt_sun_taoyuan.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.bt_sun_taoyuan.Location = new System.Drawing.Point(3, 523);
|
||||
this.bt_sun_taoyuan.Location = new System.Drawing.Point(3, 433);
|
||||
this.bt_sun_taoyuan.Name = "bt_sun_taoyuan";
|
||||
this.bt_sun_taoyuan.Size = new System.Drawing.Size(213, 47);
|
||||
this.bt_sun_taoyuan.TabIndex = 13;
|
||||
this.bt_sun_taoyuan.Text = "太陽能光電-桃園全虹";
|
||||
this.bt_sun_taoyuan.UseVisualStyleBackColor = true;
|
||||
this.bt_sun_taoyuan.Visible = false;
|
||||
this.bt_sun_taoyuan.Click += new System.EventHandler(this.bt_sun_taoyuan_Click);
|
||||
//
|
||||
// bt_gong34
|
||||
//
|
||||
this.bt_gong34.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.bt_gong34.Location = new System.Drawing.Point(0, 443);
|
||||
this.bt_gong34.Location = new System.Drawing.Point(3, 392);
|
||||
this.bt_gong34.Name = "bt_gong34";
|
||||
this.bt_gong34.Size = new System.Drawing.Size(189, 47);
|
||||
this.bt_gong34.TabIndex = 12;
|
||||
@ -261,7 +280,7 @@ namespace solarApp
|
||||
// bt_AUO_aimai
|
||||
//
|
||||
this.bt_AUO_aimai.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.bt_AUO_aimai.Location = new System.Drawing.Point(0, 390);
|
||||
this.bt_AUO_aimai.Location = new System.Drawing.Point(3, 339);
|
||||
this.bt_AUO_aimai.Name = "bt_AUO_aimai";
|
||||
this.bt_AUO_aimai.Size = new System.Drawing.Size(189, 47);
|
||||
this.bt_AUO_aimai.TabIndex = 11;
|
||||
@ -283,7 +302,7 @@ namespace solarApp
|
||||
// bt_day_archive_hj
|
||||
//
|
||||
this.bt_day_archive_hj.Font = new System.Drawing.Font("Microsoft JhengHei UI", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.bt_day_archive_hj.Location = new System.Drawing.Point(149, 270);
|
||||
this.bt_day_archive_hj.Location = new System.Drawing.Point(149, 236);
|
||||
this.bt_day_archive_hj.Name = "bt_day_archive_hj";
|
||||
this.bt_day_archive_hj.Size = new System.Drawing.Size(119, 44);
|
||||
this.bt_day_archive_hj.TabIndex = 9;
|
||||
@ -325,16 +344,38 @@ namespace solarApp
|
||||
this.tabControl.Size = new System.Drawing.Size(1782, 853);
|
||||
this.tabControl.TabIndex = 1;
|
||||
//
|
||||
// bt_dailyReport
|
||||
// button1
|
||||
//
|
||||
this.bt_dailyReport.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.bt_dailyReport.Location = new System.Drawing.Point(5, 706);
|
||||
this.bt_dailyReport.Name = "bt_dailyReport";
|
||||
this.bt_dailyReport.Size = new System.Drawing.Size(237, 74);
|
||||
this.bt_dailyReport.TabIndex = 15;
|
||||
this.bt_dailyReport.Text = "daily_report 太陽能光電-桃園全虹";
|
||||
this.bt_dailyReport.UseVisualStyleBackColor = true;
|
||||
this.bt_dailyReport.Click += new System.EventHandler(this.bt_dailyReport_Click);
|
||||
this.button1.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.button1.Location = new System.Drawing.Point(5, 527);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(213, 47);
|
||||
this.button1.TabIndex = 16;
|
||||
this.button1.Text = "太陽能光電-高雄臨廣";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.button2.Location = new System.Drawing.Point(3, 569);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(213, 47);
|
||||
this.button2.TabIndex = 17;
|
||||
this.button2.Text = "太陽能光電-翔億大";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||
//
|
||||
// button3
|
||||
//
|
||||
this.button3.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.button3.Location = new System.Drawing.Point(3, 613);
|
||||
this.button3.Name = "button3";
|
||||
this.button3.Size = new System.Drawing.Size(213, 47);
|
||||
this.button3.TabIndex = 18;
|
||||
this.button3.Text = "太陽能光電-翔億小";
|
||||
this.button3.UseVisualStyleBackColor = true;
|
||||
this.button3.Click += new System.EventHandler(this.button3_Click);
|
||||
//
|
||||
// fmExcel
|
||||
//
|
||||
@ -383,5 +424,8 @@ namespace solarApp
|
||||
private System.Windows.Forms.Button bt_sun_taoyuan;
|
||||
private System.Windows.Forms.Button bt_sun_yadong;
|
||||
private System.Windows.Forms.Button bt_dailyReport;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Button button3;
|
||||
}
|
||||
}
|
||||
@ -697,7 +697,7 @@ namespace solarApp
|
||||
//str = inverterID.Split(" ");
|
||||
//inverterID = str[str.Length - 1];
|
||||
|
||||
xlsSvc.insert_dailyReport2DB(dt, filename);
|
||||
xlsSvc.insert_dailyReport2DB(dt, filename, "daily_taoyuan_quanhong");
|
||||
dt.Rows.Clear();
|
||||
x++;
|
||||
}
|
||||
@ -716,8 +716,73 @@ namespace solarApp
|
||||
|
||||
private void bt_dailyReport_Click(object sender, EventArgs e)
|
||||
{
|
||||
ImporExcel_dailyReport("");
|
||||
|
||||
ImporExcel_dailyReport("daily_taoyuan_quanhong");
|
||||
//insert_dailyReport2DB("daily_taoyuan_quanhong");
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
insert_sunLightCsv("sun_zhanghua_xy1");
|
||||
}
|
||||
|
||||
private void button3_Click(object sender, EventArgs e)
|
||||
{
|
||||
insert_sunLightCsv("sun_zhanghua_xy2");
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
insert_sunLightCsv("sun_gaoxiong_linguang");
|
||||
}
|
||||
|
||||
void insert_sunLightCsv(string tableName) {
|
||||
string fname = "";
|
||||
string[] fileEntries = new string[0];
|
||||
Array.Clear(fileEntries, 0, fileEntries.Length);
|
||||
//取得選取檔案的路徑
|
||||
string dir;//= Path.GetDirectoryName(fname);
|
||||
|
||||
using (var fbd = new FolderBrowserDialog())
|
||||
{
|
||||
DialogResult result = fbd.ShowDialog();
|
||||
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
|
||||
{
|
||||
//dir = Path.GetDirectoryName(fname);
|
||||
//fileEntries = Directory.GetFiles(fbd.SelectedPath);
|
||||
fileEntries = Directory.GetFiles(fbd.SelectedPath, "*.*", SearchOption.AllDirectories);
|
||||
MessageBox.Show("Files found: " + fileEntries.Length.ToString(), "Message");
|
||||
}
|
||||
}
|
||||
|
||||
Service.operateCSV csvSvc = new Service.operateCSV(); // readCsvTxt
|
||||
System.Data.DataTable dt = new System.Data.DataTable();
|
||||
bool isFirst = true;
|
||||
foreach (string fileName in fileEntries)
|
||||
{
|
||||
#region 取得 filename 中的 InvID
|
||||
string fName = Path.GetFileName(fileName);
|
||||
rt1.AppendText(fName + " ");
|
||||
rt1.SelectionStart = rt1.Text.Length;
|
||||
rt1.ScrollToCaret();
|
||||
#endregion
|
||||
|
||||
if (isFirst)
|
||||
{
|
||||
//csvSvc.clear_inv("hour");
|
||||
csvSvc.taoYuan_createColumnHour(ref dt, fileName);
|
||||
csvSvc.taoYuan_readCsvFile(ref dt, fileName, dt.Columns.Count, isFirst);
|
||||
isFirst = false;
|
||||
}
|
||||
else
|
||||
csvSvc.taoYuan_readCsvFile(ref dt, fileName, dt.Columns.Count, isFirst);
|
||||
}
|
||||
MessageBox.Show(" 共 " + dt.Rows.Count.ToString());
|
||||
|
||||
//System.Data.DataTable dt = solarApp.Service.csvHelper.OpenCSV(fname);
|
||||
csvSvc.taoYuan_insertHour2DB(ref dt, tableName);
|
||||
MessageBox.Show("OK");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user