From 0da614bc468b562d0182cb6378614110c67262bf Mon Sep 17 00:00:00 2001 From: "nelson.kai" Date: Thu, 23 Mar 2023 17:00:54 +0800 Subject: [PATCH] Update --- Form1.Designer.cs | 121 ++----------- Form1.cs | 109 ++++++++++-- Form1.resx | 24 --- ProgressForm.Designer.cs | 60 +++++++ ProgressForm.cs | 25 +++ ProgressForm.resx | 120 +++++++++++++ ShowForm.Designer.cs | 72 ++++++++ ShowForm.cs | 20 +++ ShowForm.resx | 120 +++++++++++++ UpgradeLog.htm | 273 ++++++++++++++++++++++++++++++ Utility/MySQLUtilityClass.cs | 206 ++++++++++++++++++++++ Utility/OracleUtilityClass.cs | 207 ++++++++++++++++++++++ Utility/PostgreSQLUtilityClass.cs | 204 ++++++++++++++++++++++ 13 files changed, 1418 insertions(+), 143 deletions(-) create mode 100644 ProgressForm.Designer.cs create mode 100644 ProgressForm.cs create mode 100644 ProgressForm.resx create mode 100644 ShowForm.Designer.cs create mode 100644 ShowForm.cs create mode 100644 ShowForm.resx create mode 100644 UpgradeLog.htm create mode 100644 Utility/MySQLUtilityClass.cs create mode 100644 Utility/OracleUtilityClass.cs create mode 100644 Utility/PostgreSQLUtilityClass.cs diff --git a/Form1.Designer.cs b/Form1.Designer.cs index fa9571e..2e84d10 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -55,14 +55,6 @@ namespace ExportDataToFile this.txtSourcePWD = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.dgvExportList = new System.Windows.Forms.DataGridView(); - this.clExport = new System.Windows.Forms.DataGridViewCheckBoxColumn(); - this.clCancel = new System.Windows.Forms.DataGridViewButtonColumn(); - this.clShow = new System.Windows.Forms.DataGridViewButtonColumn(); - this.clSourceTable = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.clTargetTable = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.clTableDel = new System.Windows.Forms.DataGridViewCheckBoxColumn(); - this.clWhere = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.clMappingData = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.label11 = new System.Windows.Forms.Label(); this.dgvColumnMapping = new System.Windows.Forms.DataGridView(); this.clExpColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn(); @@ -97,7 +89,7 @@ namespace ExportDataToFile this.txtTargetID.Name = "txtTargetID"; this.txtTargetID.Size = new System.Drawing.Size(135, 29); this.txtTargetID.TabIndex = 11; - this.txtTargetID.Text = "origtek"; + this.txtTargetID.Text = "postgres"; // // label7 // @@ -116,7 +108,7 @@ namespace ExportDataToFile this.txtTargetDBName.Name = "txtTargetDBName"; this.txtTargetDBName.Size = new System.Drawing.Size(135, 29); this.txtTargetDBName.TabIndex = 10; - this.txtTargetDBName.Text = "origtekpdb"; + this.txtTargetDBName.Text = "EURO"; // // label8 // @@ -135,7 +127,7 @@ namespace ExportDataToFile this.txtTargetIP.Name = "txtTargetIP"; this.txtTargetIP.Size = new System.Drawing.Size(135, 29); this.txtTargetIP.TabIndex = 8; - this.txtTargetIP.Text = "192.168.1.76"; + this.txtTargetIP.Text = "localhost"; // // label9 // @@ -180,7 +172,7 @@ namespace ExportDataToFile this.txtSourceID.Name = "txtSourceID"; this.txtSourceID.Size = new System.Drawing.Size(135, 29); this.txtSourceID.TabIndex = 5; - this.txtSourceID.Text = "origtek"; + this.txtSourceID.Text = "sa"; // // label4 // @@ -199,7 +191,7 @@ namespace ExportDataToFile this.txtSourceDBName.Name = "txtSourceDBName"; this.txtSourceDBName.Size = new System.Drawing.Size(135, 29); this.txtSourceDBName.TabIndex = 4; - this.txtSourceDBName.Text = "origtekpdb"; + this.txtSourceDBName.Text = "EURO_Data"; // // label3 // @@ -218,7 +210,7 @@ namespace ExportDataToFile this.txtSourceIP.Name = "txtSourceIP"; this.txtSourceIP.Size = new System.Drawing.Size(135, 29); this.txtSourceIP.TabIndex = 2; - this.txtSourceIP.Text = "192.168.1.76"; + this.txtSourceIP.Text = "localhost"; // // label2 // @@ -298,7 +290,7 @@ namespace ExportDataToFile this.txtTargetPWD.PasswordChar = '*'; this.txtTargetPWD.Size = new System.Drawing.Size(135, 29); this.txtTargetPWD.TabIndex = 12; - this.txtTargetPWD.Text = "!QAZ2wsx"; + this.txtTargetPWD.Text = "i\'mnelson"; // // label6 // @@ -329,7 +321,7 @@ namespace ExportDataToFile this.txtSourcePWD.PasswordChar = '*'; this.txtSourcePWD.Size = new System.Drawing.Size(135, 29); this.txtSourcePWD.TabIndex = 6; - this.txtSourcePWD.Text = "!QAZ2wsx"; + this.txtSourcePWD.Text = "i\'mnelson"; // // label5 // @@ -350,15 +342,6 @@ namespace ExportDataToFile this.dgvExportList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.dgvExportList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dgvExportList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.clExport, - this.clCancel, - this.clShow, - this.clSourceTable, - this.clTargetTable, - this.clTableDel, - this.clWhere, - this.clMappingData}); this.dgvExportList.Location = new System.Drawing.Point(18, 125); this.dgvExportList.Name = "dgvExportList"; this.dgvExportList.RowTemplate.Height = 25; @@ -367,76 +350,6 @@ namespace ExportDataToFile this.dgvExportList.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvExportList_CellClick); this.dgvExportList.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvExportList_CellContentClick); // - // clExport - // - this.clExport.FalseValue = "false"; - this.clExport.Frozen = true; - this.clExport.HeaderText = "匯出"; - this.clExport.IndeterminateValue = "false"; - this.clExport.Name = "clExport"; - this.clExport.ReadOnly = true; - this.clExport.TrueValue = "true"; - this.clExport.Width = 55; - // - // clCancel - // - this.clCancel.Frozen = true; - this.clCancel.HeaderText = "清除"; - this.clCancel.Name = "clCancel"; - this.clCancel.Text = "..."; - this.clCancel.Width = 55; - // - // clShow - // - this.clShow.Frozen = true; - this.clShow.HeaderText = "顯示來源"; - this.clShow.Name = "clShow"; - this.clShow.Text = "..."; - this.clShow.Width = 80; - // - // clSourceTable - // - this.clSourceTable.DataPropertyName = "TableName"; - this.clSourceTable.Frozen = true; - this.clSourceTable.HeaderText = "來源資料表名稱"; - this.clSourceTable.Name = "clSourceTable"; - this.clSourceTable.ReadOnly = true; - this.clSourceTable.Resizable = System.Windows.Forms.DataGridViewTriState.True; - this.clSourceTable.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; - this.clSourceTable.Width = 300; - // - // clTargetTable - // - this.clTargetTable.Frozen = true; - this.clTargetTable.HeaderText = "目標資料表名稱"; - this.clTargetTable.Name = "clTargetTable"; - this.clTargetTable.ReadOnly = true; - this.clTargetTable.Resizable = System.Windows.Forms.DataGridViewTriState.True; - this.clTargetTable.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; - this.clTargetTable.Width = 300; - // - // clTableDel - // - this.clTableDel.Frozen = true; - this.clTableDel.HeaderText = "清除目標資料表內容"; - this.clTableDel.Name = "clTableDel"; - this.clTableDel.Width = 180; - // - // clWhere - // - this.clWhere.Frozen = true; - this.clWhere.HeaderText = "過濾條件"; - this.clWhere.Name = "clWhere"; - this.clWhere.Visible = false; - this.clWhere.Width = 200; - // - // clMappingData - // - this.clMappingData.Frozen = true; - this.clMappingData.HeaderText = "欄位對應"; - this.clMappingData.Name = "clMappingData"; - this.clMappingData.Visible = false; - // // label11 // this.label11.AutoSize = true; @@ -757,11 +670,6 @@ namespace ExportDataToFile private System.Windows.Forms.ComboBox cbTargetTable; private System.Windows.Forms.Button btnMapping; private System.Windows.Forms.SaveFileDialog sfPath; - private System.Windows.Forms.DataGridViewCheckBoxColumn clExpColumn; - private System.Windows.Forms.DataGridViewButtonColumn clClean; - private System.Windows.Forms.DataGridViewTextBoxColumn clSourceColumn; - private System.Windows.Forms.DataGridViewTextBoxColumn clType; - private System.Windows.Forms.DataGridViewComboBoxColumn clTargetColumn; private System.Windows.Forms.Label label15; private System.Windows.Forms.TextBox txtMaxCount; private System.Windows.Forms.Label label16; @@ -772,14 +680,11 @@ namespace ExportDataToFile private System.Windows.Forms.Button btnImportXML; private System.Windows.Forms.OpenFileDialog ofPath; private System.Windows.Forms.Button btnClean; - private System.Windows.Forms.DataGridViewCheckBoxColumn clExport; - private System.Windows.Forms.DataGridViewButtonColumn clCancel; - private System.Windows.Forms.DataGridViewButtonColumn clShow; - private System.Windows.Forms.DataGridViewTextBoxColumn clSourceTable; - private System.Windows.Forms.DataGridViewTextBoxColumn clTargetTable; - private System.Windows.Forms.DataGridViewCheckBoxColumn clTableDel; - private System.Windows.Forms.DataGridViewTextBoxColumn clWhere; - private System.Windows.Forms.DataGridViewTextBoxColumn clMappingData; + private System.Windows.Forms.DataGridViewCheckBoxColumn clExpColumn; + private System.Windows.Forms.DataGridViewButtonColumn clClean; + private System.Windows.Forms.DataGridViewTextBoxColumn clSourceColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn clType; + private System.Windows.Forms.DataGridViewComboBoxColumn clTargetColumn; } } diff --git a/Form1.cs b/Form1.cs index d36fa68..2637633 100644 --- a/Form1.cs +++ b/Form1.cs @@ -46,7 +46,8 @@ namespace ExportDataToFile private void Form1_Load(object sender, EventArgs e) { - dgvExportList.Columns["clSourceTable"].DataPropertyName = "TableName"; + ResetDataGridView(); + } private void btnSourceConnTest_Click(object sender, EventArgs e) @@ -600,16 +601,10 @@ namespace ExportDataToFile txtTargetPWD.Text = ""; cbTargetTable.SelectedIndex = -1; cbTargetTable.Enabled = false; - - //sqlMSSourceConn.Close(); - //sqlMSTargetConn.Close(); - //sqlPsgSourceConn.Close(); - //sqlPsgTargetConn.Close(); - //sqlMySourceConn.Close(); - //sqlMyTargetConn.Close(); - //sqlOraSourceConn.Close(); - //sqlOraTargetConn.Close(); - + dgvExportList.DataSource = null; + dgvColumnMapping.DataSource = null; + ResetDataGridView(); //重建DataGridView欄位 + sqlMSSourceConn = null; sqlMSTargetConn = null; sqlPsgSourceConn = null; @@ -2586,7 +2581,99 @@ namespace ExportDataToFile } } + private void ResetDataGridView() + { + #region dgvExportList + dgvExportList.Columns.Clear(); + //匯出 + DataGridViewCheckBoxColumn clExport = new DataGridViewCheckBoxColumn(); + clExport.HeaderText = "匯出"; + clExport.Name = "clExport"; + clExport.Width = 50; + //清除 + DataGridViewButtonColumn clCancel = new DataGridViewButtonColumn(); + clCancel.HeaderText = "清除"; + clCancel.Name = "clCancel"; + clCancel.Width = 50; + //顯示來源 + DataGridViewButtonColumn clShow = new DataGridViewButtonColumn(); + clShow.HeaderText = "顯示來源"; + clShow.Name = "clShow"; + //來源資料表名稱 + DataGridViewTextBoxColumn clSourceTable = new DataGridViewTextBoxColumn(); + clSourceTable.HeaderText = "來源資料表名稱"; + clSourceTable.Name = "clSourceTable"; + clSourceTable.DataPropertyName = "TableName"; + clSourceTable.Width = 200; + //目標資料表名稱 + DataGridViewTextBoxColumn clTargetTable = new DataGridViewTextBoxColumn(); + clTargetTable.HeaderText = "目標資料表名稱"; + clTargetTable.Name = "clTargetTable"; + clTargetTable.Width = 200; + //清除目標資料表內容 + DataGridViewCheckBoxColumn clTableDel = new DataGridViewCheckBoxColumn(); + clTableDel.HeaderText = "清除目標資料表內容"; + clTableDel.Name = "clTableDel"; + clTableDel.Width = 200; + //過濾條件 + DataGridViewTextBoxColumn clWhere = new DataGridViewTextBoxColumn(); + clWhere.HeaderText = "過濾條件"; + clWhere.Name = "clWhere"; + clWhere.Visible = false; + //欄位對應 + DataGridViewTextBoxColumn clMappingData = new DataGridViewTextBoxColumn(); + clMappingData.HeaderText = "欄位對應"; + clMappingData.Name = "clMappingData"; + clMappingData.Visible = false; + + dgvExportList.Columns.Add(clExport); + dgvExportList.Columns.Add(clCancel); + dgvExportList.Columns.Add(clShow); + dgvExportList.Columns.Add(clSourceTable); + dgvExportList.Columns.Add(clTargetTable); + dgvExportList.Columns.Add(clTableDel); + dgvExportList.Columns.Add(clWhere); + dgvExportList.Columns.Add(clMappingData); + #endregion + + #region dgvColumnMapping + //匯出 + dgvColumnMapping.Columns.Clear(); + DataGridViewCheckBoxColumn clExpColumn = new DataGridViewCheckBoxColumn(); + clExpColumn.HeaderText = "匯出"; + clExpColumn.Name = "clExpColumn"; + clExpColumn.Width = 50; + //清除 + DataGridViewButtonColumn clClean = new DataGridViewButtonColumn(); + clClean.HeaderText = "清除"; + clClean.Name = "clClean"; + clClean.Width = 50; + //來源欄位 + DataGridViewTextBoxColumn clSourceColumn = new DataGridViewTextBoxColumn(); + clSourceColumn.HeaderText = "來源欄位"; + clSourceColumn.Name = "clSourceColumn"; + clSourceColumn.DataPropertyName = "COLUMN_NAME"; + clSourceColumn.Width = 100; + //型態 + DataGridViewTextBoxColumn clType = new DataGridViewTextBoxColumn(); + clType.HeaderText = "型態"; + clType.Name = "clType"; + clType.DataPropertyName = "DATA_TYPE"; + clType.Width = 100; + //目標欄位 + DataGridViewComboBoxColumn clTargetColumn = new DataGridViewComboBoxColumn(); + clTargetColumn.HeaderText = "目標欄位"; + clTargetColumn.Name = "clTargetColumn"; + clTargetColumn.Width = 100; + + dgvColumnMapping.Columns.Add(clExpColumn); + dgvColumnMapping.Columns.Add(clClean); + dgvColumnMapping.Columns.Add(clSourceColumn); + dgvColumnMapping.Columns.Add(clType); + dgvColumnMapping.Columns.Add(clTargetColumn); + #endregion + } #endregion } } diff --git a/Form1.resx b/Form1.resx index e654215..3710c45 100644 --- a/Form1.resx +++ b/Form1.resx @@ -117,30 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - True diff --git a/ProgressForm.Designer.cs b/ProgressForm.Designer.cs new file mode 100644 index 0000000..8427cb8 --- /dev/null +++ b/ProgressForm.Designer.cs @@ -0,0 +1,60 @@ + +namespace ExportDataToFile +{ + partial class ProgressForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pbExport = new System.Windows.Forms.ProgressBar(); + this.SuspendLayout(); + // + // pbExport + // + this.pbExport.Location = new System.Drawing.Point(12, 12); + this.pbExport.Name = "pbExport"; + this.pbExport.Size = new System.Drawing.Size(297, 23); + this.pbExport.TabIndex = 1; + // + // ProgressForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CausesValidation = false; + this.ClientSize = new System.Drawing.Size(320, 44); + this.ControlBox = false; + this.Controls.Add(this.pbExport); + this.Name = "ProgressForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "匯出進度表"; + this.ResumeLayout(false); + + } + + #endregion + public System.Windows.Forms.ProgressBar pbExport; + } +} \ No newline at end of file diff --git a/ProgressForm.cs b/ProgressForm.cs new file mode 100644 index 0000000..ca3fe7a --- /dev/null +++ b/ProgressForm.cs @@ -0,0 +1,25 @@ +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 ExportDataToFile +{ + public partial class ProgressForm : Form + { + public ProgressForm() + { + InitializeComponent(); + } + + private void button1_Click(object sender, EventArgs e) + { + pbExport.Value += 1; + } + } +} diff --git a/ProgressForm.resx b/ProgressForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ProgressForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShowForm.Designer.cs b/ShowForm.Designer.cs new file mode 100644 index 0000000..169f4dc --- /dev/null +++ b/ShowForm.Designer.cs @@ -0,0 +1,72 @@ + +namespace ExportDataToFile +{ + partial class ShowForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dgvShowResult = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dgvShowResult)).BeginInit(); + this.SuspendLayout(); + // + // dgvShowResult + // + this.dgvShowResult.AllowUserToAddRows = false; + this.dgvShowResult.AllowUserToDeleteRows = false; + this.dgvShowResult.AllowUserToOrderColumns = true; + this.dgvShowResult.AllowUserToResizeRows = false; + this.dgvShowResult.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dgvShowResult.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvShowResult.Location = new System.Drawing.Point(12, 12); + this.dgvShowResult.Name = "dgvShowResult"; + this.dgvShowResult.RowTemplate.Height = 24; + this.dgvShowResult.Size = new System.Drawing.Size(1271, 600); + this.dgvShowResult.TabIndex = 0; + // + // ShowForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1295, 624); + this.Controls.Add(this.dgvShowResult); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "ShowForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "顯示資料"; + ((System.ComponentModel.ISupportInitialize)(this.dgvShowResult)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + public System.Windows.Forms.DataGridView dgvShowResult; + } +} \ No newline at end of file diff --git a/ShowForm.cs b/ShowForm.cs new file mode 100644 index 0000000..a2007ca --- /dev/null +++ b/ShowForm.cs @@ -0,0 +1,20 @@ +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 ExportDataToFile +{ + public partial class ShowForm : Form + { + public ShowForm() + { + InitializeComponent(); + } + } +} diff --git a/ShowForm.resx b/ShowForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShowForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/UpgradeLog.htm b/UpgradeLog.htm new file mode 100644 index 0000000..a44aca9 --- /dev/null +++ b/UpgradeLog.htm @@ -0,0 +1,273 @@ + + + + 移轉報告 +

+ 移轉報告 -

概觀

專案路徑錯誤警告訊息
ExportProject..\ExportProject\ExportProject.vdproj100
方案ExportDataToFile.sln001

方案和專案

\ No newline at end of file diff --git a/Utility/MySQLUtilityClass.cs b/Utility/MySQLUtilityClass.cs new file mode 100644 index 0000000..ec9c9ad --- /dev/null +++ b/Utility/MySQLUtilityClass.cs @@ -0,0 +1,206 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using System.Data; +using System.Data.Sql; +using System.Data.SqlClient; +using System.Configuration; +using MySqlConnector; + + + +namespace ManagementSystem.Utility +{ + public static class MySQLUtility + { + + #region 取得指定Table資料 + public static DataTable GetTable(string strTableName, int intTopCount, string[] strColumnList , string strWhere, string strOrderBy, MySqlConnection sqlConn) + { + DataSet dsData = new DataSet(); + string strCommand = ""; + try + { + string strColumns = ""; + foreach (string strColumn in strColumnList) //取得欄位陣列 + { + if (strColumns != "") + { + strColumns += "," + strColumn.Trim(); + } + else + { + strColumns = strColumn; + } + } + + if (intTopCount > 0) + { + strCommand = string.Format("Select {1} From {2} Limit {0}", intTopCount.ToString(), strColumns, strTableName); + } + else + { + strCommand = string.Format("Select {0} From {1} ", strColumns, strTableName); + } + + if (strWhere != "") //設定過濾條件 + { + strCommand += " Where " + strWhere; + } + + if (strOrderBy != "") //取得排序欄位 + { + strCommand += " Order By " + strOrderBy; + } + + using (MySqlDataAdapter sqlAdapter = new MySqlDataAdapter(strCommand, sqlConn)) + { + if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態 + { + sqlConn.Open(); + } + sqlAdapter.Fill(dsData, "Result"); + } + + if (dsData.Tables.Count != 0) + { + return dsData.Tables["Result"]; + } + else + { + return null; + } + } + catch (Exception ex) + { + return null; + throw ex; + } + } + + public static DataTable GetTable(string strTableName, int intTopCount, string[] strColumnList, string strWhere, MySqlConnection sqlConn) + { + return GetTable(strTableName, intTopCount, strColumnList, strWhere, "", sqlConn); + } + + public static DataTable GetTable(string strTableName, int intTopCount, string[] strColumnList, MySqlConnection sqlConn) + { + return GetTable(strTableName, intTopCount, strColumnList,"","", sqlConn); + } + + public static DataTable GetTable(string strTableName, int intTopCount, MySqlConnection sqlConn) + { + return GetTable(strTableName, intTopCount,new string[] {"*"}, "", "", sqlConn); + } + + public static DataTable GetTable(string strTableName, MySqlConnection sqlConn) + { + return GetTable(strTableName, 0, new string[] { "*" }, "", "", sqlConn); + } + + + #endregion + + #region MyQL命令相關程式集 + public static MySqlConnection GetConn(string strIP, string strDBName, string strID, string strPWD, string strPort) + { + try + { + string strConnectionString = "server=" + strIP + ";port=" + strPort + ";database=" + strDBName + ";user id=" + strID + ";password=" + strPWD + ";charset=utf8;"; + MySqlConnection sqlConn = new MySqlConnection(strConnectionString); + sqlConn.ConnectionString = strConnectionString; + sqlConn.Open(); + return sqlConn; + } + catch (Exception ex) + { + ErrorHandler.WriteErrorLog("MySQLUtilityClass.cs", ex); + return null; + } + } + + public static DataTable GetSQLResult(string strSQL, MySqlConnection sqlConn) + { + DataSet dsData = new DataSet(); + try + { + using (MySqlDataAdapter sqlAdapter = new MySqlDataAdapter(strSQL, sqlConn)) + { + if (sqlConn == null) + return null; + if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態 + { + sqlConn.Open(); + } + sqlAdapter.Fill(dsData, "Result"); + } + + if (dsData.Tables.Count != 0) + { + return dsData.Tables["Result"]; + } + else + { + return null; + } + } + catch(Exception ex) + { + return null; + throw ex; + } + } + + public static bool IsExist(string strSQL, MySqlConnection sqlConn) + { + try + { + DataTable dtResult = GetSQLResult(strSQL, sqlConn); + if (dtResult.Rows.Count > 0) + { return true; } + else + { return false; } + } + catch (Exception ex) + { + throw ex; + } + } + + public static bool RunSQLNonReturn(string strSQL, MySqlConnection sqlConn) + { + try + { + MySqlCommand sqlCmd = new MySqlCommand(strSQL, sqlConn); + if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態 + { + sqlConn.Open(); + } + sqlCmd.ExecuteNonQuery(); + return true; + } + catch (Exception ex) + { + return false; + } + } + + public static string GetSQLCount(string strSQL, MySqlConnection sqlConn) + { + string strCount = ""; + DataTable dtTemp = GetSQLResult(strSQL, sqlConn); + strCount = dtTemp.Rows.Count.ToString(); + + //回傳查詢結果 + if(strCount == "") + { return "0"; } + else + { return strCount; } + } + #endregion + + } +} diff --git a/Utility/OracleUtilityClass.cs b/Utility/OracleUtilityClass.cs new file mode 100644 index 0000000..ff9c3d0 --- /dev/null +++ b/Utility/OracleUtilityClass.cs @@ -0,0 +1,207 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using System.Data; +using System.Data.Sql; +using System.Data.SqlClient; +using System.Configuration; +using Oracle.ManagedDataAccess.Client; + + + +namespace ManagementSystem.Utility +{ + public static class OracleUtility + { + + #region 取得指定Table資料 + public static DataTable GetTable(string strTableName,int intTopCount, string[] strColumnList , string strWhere, string strOrderBy, OracleConnection sqlConn) + { + DataSet dsData = new DataSet(); + string strCommand = ""; + try + { + string strColumns = ""; + foreach (string strColumn in strColumnList) //取得欄位陣列 + { + if (strColumns != "") + { + strColumns += "," + strColumn.Trim(); + } + else + { + strColumns = strColumn; + } + } + + if (intTopCount > 0) + { + strCommand = string.Format("Select {1} From {2} FETCH FIRST {0} ROWS ONLY", intTopCount.ToString(), strColumns, strTableName); + } + else + { + strCommand = string.Format("Select {0} From {1} ", strColumns, strTableName); + } + + if (strWhere != "") //設定過濾條件 + { + strCommand += " Where " + strWhere; + } + + if (strOrderBy != "") //取得排序欄位 + { + strCommand += " Order By " + strOrderBy; + } + + using (OracleDataAdapter sqlAdapter = new OracleDataAdapter(strCommand, sqlConn)) + { + if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態 + { + sqlConn.Open(); + } + sqlAdapter.Fill(dsData, "Result"); + } + + if (dsData.Tables.Count != 0) + { + return dsData.Tables["Result"]; + } + else + { + return null; + } + } + catch (Exception ex) + { + return null; + throw ex; + } + } + + public static DataTable GetTable(string strTableName, int intTopCount, string[] strColumnList, string strWhere, OracleConnection sqlConn) + { + return GetTable(strTableName, intTopCount ,strColumnList, strWhere, "", sqlConn); + } + + public static DataTable GetTable(string strTableName,int intTopCount, string[] strColumnList, OracleConnection sqlConn) + { + return GetTable(strTableName, intTopCount, strColumnList,"","", sqlConn); + } + + public static DataTable GetTable(string strTableName,int intTopCount, OracleConnection sqlConn) + { + return GetTable(strTableName, intTopCount, new string[] {"*"}, "", "", sqlConn); + } + + public static DataTable GetTable(string strTableName, OracleConnection sqlConn) + { + return GetTable(strTableName, 0, new string[] { "*" }, "", "", sqlConn); + } + + #endregion + + #region Oracle命令相關程式集 + public static OracleConnection GetConn(string strIP, string strDBName, string strID, string strPWD, string strPort) + { + try + { + string strConnectionString = "Data Source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = " + strIP + ")(PORT = " + strPort + ")))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = " + strDBName + "))); User Id = " + strID + "; Password = " + strPWD + ";"; + OracleConnection sqlConn = new OracleConnection(strConnectionString); + sqlConn.ConnectionString = strConnectionString; + sqlConn.Open(); + return sqlConn; + } + catch (Exception ex) + { + ErrorHandler.WriteErrorLog("OracleSQLUtilityClass.GetConn", ex); + return null; + } + } + + public static DataTable GetSQLResult(string strSQL, OracleConnection sqlConn) + { + DataSet dsData = new DataSet(); + try + { + using (OracleDataAdapter sqlAdapter = new OracleDataAdapter(strSQL, sqlConn)) + { + if (sqlConn == null) + return null; + if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態 + { + sqlConn.Open(); + } + + sqlAdapter.Fill(dsData, "Result"); + } + + if (dsData.Tables.Count != 0) + { + return dsData.Tables["Result"]; + } + else + { + return null; + } + } + catch(Exception ex) + { + ErrorHandler.WriteErrorLog("OracleSQLUtilityClass.GetSQLResult", ex); + throw ex; + } + } + + public static bool IsExist(string strSQL, OracleConnection sqlConn) + { + try + { + DataTable dtResult = GetSQLResult(strSQL, sqlConn); + if (dtResult.Rows.Count > 0) + { return true; } + else + { return false; } + } + catch (Exception ex) + { + throw ex; + } + } + + public static bool RunSQLNonReturn(string strSQL, OracleConnection sqlConn) + { + try + { + OracleCommand sqlCmd = new OracleCommand(strSQL, sqlConn); + if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態 + { + sqlConn.Open(); + } + sqlCmd.ExecuteNonQuery(); + return true; + } + catch (Exception ex) + { + ErrorHandler.WriteErrorLog("OracleSQLUtilityClass.RunSQLNonReturn", ex); + return false; + } + } + + public static string GetSQLCount(string strSQL, OracleConnection sqlConn) + { + string strCount = ""; + DataTable dtTemp = GetSQLResult(strSQL, sqlConn); + strCount = dtTemp.Rows.Count.ToString(); + + //回傳查詢結果 + if(strCount == "") + { return "0"; } + else + { return strCount; } + } + #endregion + + } +} diff --git a/Utility/PostgreSQLUtilityClass.cs b/Utility/PostgreSQLUtilityClass.cs new file mode 100644 index 0000000..d7eaef0 --- /dev/null +++ b/Utility/PostgreSQLUtilityClass.cs @@ -0,0 +1,204 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using System.Data; +//using System.Data.Sql; +//using System.Data.SqlClient; +using System.Configuration; +using Npgsql; + + +namespace ManagementSystem.Utility +{ + public static class PostgreSQLUtility + { + #region 取得指定Table資料 + public static DataTable GetTable(string strTableName, int intTopCount, string[] strColumnList, string strWhere, string strOrderBy, NpgsqlConnection sqlConn) + { + DataSet dsData = new DataSet(); + try + { + string strColumns = ""; + string strCommand = ""; + foreach (string strColumn in strColumnList) //取得欄位陣列 + { + if (strColumns != "") + { + strColumns += "," + strColumn.Trim(); + } + else + { + strColumns = strColumn; + } + } + + if (intTopCount > 0) + { + strCommand = string.Format("Select {1} From \"{2}\" LIMIT {0}", intTopCount.ToString(), strColumns, strTableName); + } + else + { + strCommand = string.Format("Select {0} From \"{1}\" ", strColumns, strTableName); + } + + if (strWhere != "") //設定過濾條件 + { + strCommand += " Where " + strWhere; + } + + if (strOrderBy != "") //取得排序欄位 + { + strCommand += " Order By " + strOrderBy; + } + + using (NpgsqlDataAdapter sqlAdapter = new NpgsqlDataAdapter(strCommand, sqlConn)) + { + if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態 + { + sqlConn.Open(); + } + sqlAdapter.Fill(dsData, "Result"); + } + + if (dsData.Tables.Count != 0) + { + return dsData.Tables["Result"]; + } + else + { + return null; + } + } + catch (Exception ex) + { + return null; + throw ex; + } + } + + public static DataTable GetTable(string strTableName, int intTopCount, string[] strColumnList, string strWhere, NpgsqlConnection sqlConn) + { + return GetTable(strTableName, intTopCount, strColumnList, strWhere, "", sqlConn); + } + + public static DataTable GetTable(string strTableName, int intTopCount, string[] strColumnList, NpgsqlConnection sqlConn) + { + return GetTable(strTableName, intTopCount, strColumnList, "", "", sqlConn); + } + + public static DataTable GetTable(string strTableName, int intTopCount, NpgsqlConnection sqlConn) + { + return GetTable(strTableName, intTopCount, new string[] { "*" }, "", "", sqlConn); + } + + public static DataTable GetTable(string strTableName, NpgsqlConnection sqlConn) + { + return GetTable(strTableName, 0, new string[] { "*" }, "", "", sqlConn); + } + + #endregion + + #region MS-SQL命令相關程式集 + public static NpgsqlConnection GetConn(string strIP, string strDBName, string strID, string strPWD, string strPort) + { + try + { + string strConnectionString = "Host=" + strIP + ";Port="+ strPort + ";Database=" + strDBName + ";Username=" + strID + ";Password=" + strPWD; + NpgsqlConnection sqlConn = new NpgsqlConnection(strConnectionString); + sqlConn.ConnectionString = strConnectionString; + sqlConn.Open(); + return sqlConn; + } + catch (Exception ex) + { + ErrorHandler.WriteErrorLog("PostgreSQLUtilityClass.cs", ex); + return null; + } + } + + public static DataTable GetSQLResult(string strSQL, NpgsqlConnection sqlConn) + { + DataSet dsData = new DataSet(); + try + { + + using (NpgsqlDataAdapter sqlAdapter = new NpgsqlDataAdapter(strSQL, sqlConn)) + { + if (sqlConn == null) + return null; + if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態 + { + sqlConn.Open(); + } + sqlAdapter.Fill(dsData, "Result"); + } + if (dsData.Tables.Count != 0) + { + return dsData.Tables["Result"]; + } + else + { + return null; + } + } + catch (Exception ex) + { + return null; + throw ex; + } + } + + public static bool IsExist(string strSQL, NpgsqlConnection sqlConn) + { + try + { + DataTable dtResult = GetSQLResult(strSQL, sqlConn); + if (dtResult.Rows.Count > 0) + { return true; } + else + { return false; } + } + catch (Exception ex) + { + throw ex; + } + } + + public static bool RunSQLNonReturn(string strSQL, NpgsqlConnection sqlConn) + { + try + { + NpgsqlCommand sqlCmd = new NpgsqlCommand(strSQL, sqlConn); + if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態 + { + sqlConn.Open(); + } + sqlCmd.ExecuteNonQuery(); + return true; + } + catch (Exception ex) + { + return false; + } + } + + public static string GetSQLCount(string strSQL, NpgsqlConnection sqlConn) + { + string strCount = ""; + DataTable dtTemp = GetSQLResult(strSQL, sqlConn); + strCount = dtTemp.Rows.Count.ToString(); + + //回傳查詢結果 + if (strCount == "") + { return "0"; } + else + { return strCount; } + } + + #endregion + + } +}