using HotelPms.Share.Data; using HotelPms.Share.Windows.Util; using HotelPms.SourceFactory.Table; using HotelPms.SourceFactory.Util; using NPOI.SS.UserModel; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace HotelPms.SourceFactory { public partial class ExcelToTable : Form { public ExcelToTable() { InitializeComponent(); } private void OpenExcel_Click(object sender, EventArgs e) { if (txtExcelPath.Text.Length == 0) { openFileDialog1.InitialDirectory = Application.StartupPath; if (openFileDialog1.ShowDialog() != DialogResult.OK) { return; } txtExcelPath.Text = openFileDialog1.FileName; } cmbSheet.Items.Clear(); using (NPOIExcel excel = new NPOIExcel(txtExcelPath.Text)) { for (int i = 0; i < excel.Workbook.NumberOfSheets; i++) { cmbSheet.Items.Add(excel.Workbook.GetSheetAt(i).SheetName); } } } private void button3_Click(object sender, EventArgs e) { using(SqlFactory sqlFactory = new SqlFactory()) { sqlFactory.CreateByExcel(txtExcelPath.Text, new DBConnectItem() { HostName = txtHost.Text, UserID = txtUser.Text, Password = txtPassword.Text, DBName = txtDB.Text }); } } private void button1_Click(object sender, EventArgs e) { using (NPOIExcel excel = new NPOIExcel(txtExcelPath.Text)) { ICell A1 = excel.GetCell("A1"); ICell B1 = excel.GetCell("B1"); ICell C1 = excel.GetCell("C1"); ICell D1 = excel.GetCell("D1"); ICell E1 = excel.GetCell("E1"); ICell F1 = excel.GetCell("F1"); ICell G1 = excel.GetCell("G1"); ICell H1 = excel.GetCell("H1"); ICell I1 = excel.GetCell("I1"); ICell J1 = excel.GetCell("J1"); ICell K1 = excel.GetCell("K1"); ICell L1 = excel.GetCell("L1"); } } private void button2_Click(object sender, EventArgs e) { using (NPOIExcel excel = new NPOIExcel(txtExcelPath.Text)) { excel.SetCurrentSheet(cmbSheet.SelectedIndex); using (SqlFactory sqlFactory = new()) { sqlFactory.DBSetting = new DBConnectItem() { HostName = txtHost.Text, UserID = txtUser.Text, Password = txtPassword.Text, DBName = txtDB.Text }; bool ret = sqlFactory.CreateBySheet(excel); MessageBox.Show($"結果:{ret}"); } } } private void button4_Click(object sender, EventArgs e) { txtContext.Text = EnumFactory.Create(txtExcelPath.Text, cmbSheet.SelectedIndex); } } }