ibms-dome/z01_WinAPP/fmImportXls.cs
2022-10-14 16:08:54 +08:00

109 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using NPOI;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Repository.Models;
using tpDomeWinAPP.Service;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Repository.BackendRepository.Implement;
using Repository.BackendRepository.Interface;
using Repository.BaseRepository.Implement;
using Repository.BaseRepository.Interface;
using Repository.FrontendRepository.Implement;
using Repository.FrontendRepository.Interface;
namespace tpDomeWinAPP
{
public partial class fmImportXls : Form
{
getDeviceSvc svcDevice = new getDeviceSvc();
public IConfiguration Configuration { get; }
public fmImportXls()
{
InitializeComponent();
}
private void btAction_Click(object sender, EventArgs e)
{
//string myDateString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//rtx.AppendText(Environment.NewLine + myDateString + " 收到訊息: Topic = " + topic + ", msg = " + payload);
//getDeviceSvc dev = new getDeviceSvc();
//dataGridView1.DataSource = dev.getDevices();
}
private void fmMain_Load(object sender, EventArgs e)
{
//IConfiguration configuration;
//Configuration = configuration;
//dBConfig.MSSqlDBConfig.Server = Configuration.GetValue<string>("DBConfig:MSSqlDBConfig:Server");
//dBConfig.MSSqlDBConfig.Port = Configuration.GetValue<string>("DBConfig:MSSqlDBConfig:Port");
//dBConfig.MSSqlDBConfig.Root = Configuration.GetValue<string>("DBConfig:MSSqlDBConfig:Root");
//dBConfig.MSSqlDBConfig.Password = Configuration.GetValue<string>("DBConfig:MSSqlDBConfig:Password");
//dBConfig.MSSqlDBConfig.Database = Configuration.GetValue<string>("DBConfig:MSSqlDBConfig:Database");
//dBConfig.MySqlDBConfig.Server = Configuration.GetValue<string>("DBConfig:MySqlDBConfig:Server");
//dBConfig.MySqlDBConfig.Port = Configuration.GetValue<string>("DBConfig:MySqlDBConfig:Port");
//dBConfig.MySqlDBConfig.Root = Configuration.GetValue<string>("DBConfig:MySqlDBConfig:Root");
//dBConfig.MySqlDBConfig.Password = Configuration.GetValue<string>("DBConfig:MySqlDBConfig:Password");
//dBConfig.MySqlDBConfig.Database = Configuration.GetValue<string>("DBConfig:MySqlDBConfig:Database");
}
public DBConfig dBConfig = new DBConfig()
{
MSSqlDBConfig = new MSSqlDBConfig(),
MySqlDBConfig = new MySqlDBConfig()
};
private void bt_readExcel_Click(object sender, EventArgs e)
{
List<string> tbs = new List<string>();
tbs.Add("importData");
string msg = string.Empty;
string fileName = string.Empty;
getDeviceSvc devSvc = new getDeviceSvc();
DataTable dt = ioExcel.ExcelToDataTable(tbs, out msg, out fileName);
if (msg != "0")
{
MessageBox.Show(msg);
}
else {
rtx.AppendText(DateTime.Now.ToString("HH-mm-ss") + " 匯入: " +fileName + Environment.NewLine);
dataGridView1.DataSource = dt;
if (dt.Rows.Count > 0)
{
devSvc.insertDB(dt);
}
lbMsg.Text = "匯入完成!" + Environment.NewLine + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
}
}
private void btInsertData_Click(object sender, EventArgs e)
{
//getDeviceSvc devSvc = new getDeviceSvc();
svcDevice.insertDB_batch();
lbMsg.Text = "展開完成!" + Environment.NewLine + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"); MessageBox.Show("OK"); }
private void btClear_Click(object sender, EventArgs e)
{
svcDevice.clearTb_importData();
lbMsg.Text = "清除完成!" + Environment.NewLine + System.DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
}
}
}