From e97d4fda6f4700607f12fee95eeb679e31e38b3d Mon Sep 17 00:00:00 2001 From: "nelson.kai" Date: Fri, 18 Nov 2022 14:50:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90MS-SQL=E5=8C=AF=E5=87=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vs/ExportDataToFile/v16/.suo | Bin 140288 -> 138752 bytes Form1.Designer.cs | 256 +++++++++++++++++----------------- Form1.cs | 212 ++++++++++++++++++++++------ Form1.resx | 6 +- 4 files changed, 304 insertions(+), 170 deletions(-) diff --git a/.vs/ExportDataToFile/v16/.suo b/.vs/ExportDataToFile/v16/.suo index f2482803706ea68353878150c7aff3f22760363a..68f75e136bb23850fbc03f98bdab72d7ae21d8eb 100644 GIT binary patch delta 5623 zcmeHL33Qaz6@K^61SiR4nUFmp8-b9J39}}d$T1TW0)mnSNGo!H$%a_O7!yE1GA>mP zxP-aLe`?*xiK$hTWm;0HHbeDTkEL;|ZO>6C$lgM$6j~KY`n}1_5OLuYsi*Df%lYQM zckf&7f8V|D-51wuTGxx(F5@^6C^16lP!9nHhlYkEn}9sP|no<#F8Un8#wJss7x=(%rbpuo%{ z4J9=R7)r{ep~8Szzcv>dC;@zF?{L3d8VH6E*?|1AOi($WG!RIkoYVKIK?9+~SRi1Q z@u(*O(j4*lSd0Ga4YAg(E8!YloHY(B!~+RHB9H_m11Uf%kOqta(t!*h6JVDvGhV8f zkA|cLemc0_IfMRvGw+z@qA@k1P23`G63wDfw2Mm6+r(nANGwIIjrCDub(umT>2=aG zgFdd4dV=9A?x@!^C8!0Zd^*ZSdE61b-ktP{RvJ^rT~O>founacnm@3^9L>(~ z(Vm#>8!1Mrvk)97&>$si$FAU}@R+Zbx)Un+WyM4rxFca8%;zdHzJf~90`5q>o7V9s z`qyR0QHLQ-CC{g^qsX1#PO;pPU#*d0sy?=t#>&7aJ)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R z$P+Se^unxzTd;~!Qs^a&%u-E!4{fPLETj6?I&rs{K~uDb_CaaxYAgV6GN!17^d0_` zt}1D{1&;h0)#b9~=hnDvZl|l>R-hIX+G+}G>O6H0x9axPhKbFbUT@(Xs>(H8unpSr z-m+=C+U@%^NL`G*O;5|<<6w|)?EpL7JoN$n9?*YthS%r}orSgedAY7!o2%AYU~|{! zI&HPNE{|6|?QA1utH7ntE5E+v9N!UXx^y*z$Nk zqzo=4pnU+Vm2j_EOK%Ap8|dzbO+!x=-KwUQ(tHf2ZZ|5o^Uc^G>rTL@@JDGjC>^1@ z(Y#0{MNSS^qVb<)4*j-a)0D`aIwcPG&CRNIs5wsO(1&&-^$uU1h&qx+?*!WA0eWe2 zeRc2g)8&~%V3K#}Xz}#tC)*855Q~fBWZYp`{=eozSN<>>+}f9MIN5g;Y=g&2NBKJT z7L;L6`NBYQgz`9;FA1x_pCXn0fSDCWNfN0F2-$uTis+R^p#YJ}c-gK~%+mM~SPTmf z@;|!h3I0sQM3}>YlKiE-J4Rm4RfZoIR6@^PzRG}jN{d$%`GY>V;hX6AqF3(4(Xr2< c9Dqwx`sKaKS6(YOx&p@tkYfaO7yKvWzl(GH`v3p{ diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 319b130..54c7d18 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -55,27 +55,27 @@ 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.clSourceTable = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.clTargetTable = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.clTableDel = new System.Windows.Forms.DataGridViewCheckBoxColumn(); - this.clDataTrim = new System.Windows.Forms.DataGridViewCheckBoxColumn(); - this.clMaxRecord = new System.Windows.Forms.DataGridViewTextBoxColumn(); - 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(); - this.clClean = new System.Windows.Forms.DataGridViewButtonColumn(); - this.clSourceColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.clTargetColumn = new System.Windows.Forms.DataGridViewComboBoxColumn(); this.txtWhere = new System.Windows.Forms.TextBox(); this.label13 = new System.Windows.Forms.Label(); this.label14 = new System.Windows.Forms.Label(); this.cbTargetTable = new System.Windows.Forms.ComboBox(); this.btnMapping = new System.Windows.Forms.Button(); this.sfPath = new System.Windows.Forms.SaveFileDialog(); + this.clExpColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.clClean = new System.Windows.Forms.DataGridViewButtonColumn(); + this.clSourceColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.clType = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.clTargetColumn = new System.Windows.Forms.DataGridViewComboBoxColumn(); + this.clExport = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.clCancel = 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.clMaxRecord = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.clWhere = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.clMappingData = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dgvExportList)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvColumnMapping)).BeginInit(); this.SuspendLayout(); @@ -247,6 +247,7 @@ namespace ExportDataToFile // btnExport // this.btnExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnExport.Enabled = false; this.btnExport.Location = new System.Drawing.Point(1649, 85); this.btnExport.Name = "btnExport"; this.btnExport.Size = new System.Drawing.Size(135, 30); @@ -259,7 +260,7 @@ namespace ExportDataToFile // this.label12.AutoSize = true; this.label12.ForeColor = System.Drawing.SystemColors.ControlLight; - this.label12.Location = new System.Drawing.Point(1293, 157); + this.label12.Location = new System.Drawing.Point(1224, 157); this.label12.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(73, 20); @@ -343,87 +344,18 @@ namespace ExportDataToFile this.clSourceTable, this.clTargetTable, this.clTableDel, - this.clDataTrim, this.clMaxRecord, this.clWhere, this.clMappingData}); this.dgvExportList.Location = new System.Drawing.Point(18, 125); this.dgvExportList.Name = "dgvExportList"; this.dgvExportList.RowTemplate.Height = 25; - this.dgvExportList.Size = new System.Drawing.Size(1257, 924); + this.dgvExportList.Size = new System.Drawing.Size(1204, 924); this.dgvExportList.TabIndex = 44; this.dgvExportList.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvExportList_CellClick); this.dgvExportList.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvExportList_CellContentClick); this.dgvExportList.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvExportList_CellEndEdit); // - // 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 = "Clean"; - this.clCancel.Width = 55; - // - // 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 = 250; - // - // clTargetTable - // - 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 = 250; - // - // clTableDel - // - this.clTableDel.HeaderText = "清除目標資料表內容"; - this.clTableDel.Name = "clTableDel"; - this.clTableDel.Width = 180; - // - // clDataTrim - // - this.clDataTrim.HeaderText = "清除尾段空白"; - this.clDataTrim.Name = "clDataTrim"; - this.clDataTrim.Width = 120; - // - // clMaxRecord - // - this.clMaxRecord.HeaderText = "檔案匯出上限筆數"; - this.clMaxRecord.Name = "clMaxRecord"; - this.clMaxRecord.Width = 180; - // - // clWhere - // - this.clWhere.HeaderText = "過濾條件"; - this.clWhere.Name = "clWhere"; - this.clWhere.Width = 200; - // - // clMappingData - // - this.clMappingData.HeaderText = "欄位對應"; - this.clMappingData.Name = "clMappingData"; - // // label11 // this.label11.AutoSize = true; @@ -447,62 +379,32 @@ namespace ExportDataToFile this.clExpColumn, this.clClean, this.clSourceColumn, + this.clType, this.clTargetColumn}); - this.dgvColumnMapping.Location = new System.Drawing.Point(1297, 180); + this.dgvColumnMapping.Location = new System.Drawing.Point(1228, 180); this.dgvColumnMapping.Name = "dgvColumnMapping"; this.dgvColumnMapping.RowTemplate.Height = 25; - this.dgvColumnMapping.Size = new System.Drawing.Size(487, 342); + this.dgvColumnMapping.Size = new System.Drawing.Size(556, 342); this.dgvColumnMapping.TabIndex = 45; this.dgvColumnMapping.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvColumnMapping_CellContentClick); this.dgvColumnMapping.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvColumnMapping_CellEndEdit); // - // clExpColumn - // - this.clExpColumn.HeaderText = "匯出"; - this.clExpColumn.Name = "clExpColumn"; - this.clExpColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; - this.clExpColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; - this.clExpColumn.Width = 65; - // - // clClean - // - this.clClean.HeaderText = "清除"; - this.clClean.Name = "clClean"; - this.clClean.Width = 50; - // - // clSourceColumn - // - this.clSourceColumn.DataPropertyName = "COLUMN_NAME"; - this.clSourceColumn.HeaderText = "來源欄位"; - this.clSourceColumn.Name = "clSourceColumn"; - this.clSourceColumn.ReadOnly = true; - this.clSourceColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; - this.clSourceColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; - this.clSourceColumn.Width = 200; - // - // clTargetColumn - // - this.clTargetColumn.HeaderText = "目標欄位"; - this.clTargetColumn.Name = "clTargetColumn"; - this.clTargetColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; - this.clTargetColumn.Width = 200; - // // txtWhere // this.txtWhere.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.txtWhere.Location = new System.Drawing.Point(1297, 556); + this.txtWhere.Location = new System.Drawing.Point(1228, 556); this.txtWhere.Multiline = true; this.txtWhere.Name = "txtWhere"; - this.txtWhere.Size = new System.Drawing.Size(487, 457); + this.txtWhere.Size = new System.Drawing.Size(556, 457); this.txtWhere.TabIndex = 47; // // label13 // this.label13.AutoSize = true; this.label13.ForeColor = System.Drawing.SystemColors.ControlLight; - this.label13.Location = new System.Drawing.Point(1297, 533); + this.label13.Location = new System.Drawing.Point(1228, 533); this.label13.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label13.Name = "label13"; this.label13.Size = new System.Drawing.Size(73, 20); @@ -513,7 +415,7 @@ namespace ExportDataToFile // this.label14.AutoSize = true; this.label14.ForeColor = System.Drawing.SystemColors.ControlLight; - this.label14.Location = new System.Drawing.Point(1293, 125); + this.label14.Location = new System.Drawing.Point(1224, 125); this.label14.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label14.Name = "label14"; this.label14.Size = new System.Drawing.Size(89, 20); @@ -527,9 +429,9 @@ namespace ExportDataToFile this.cbTargetTable.DisplayMember = "TableName"; this.cbTargetTable.Enabled = false; this.cbTargetTable.FormattingEnabled = true; - this.cbTargetTable.Location = new System.Drawing.Point(1389, 122); + this.cbTargetTable.Location = new System.Drawing.Point(1320, 122); this.cbTargetTable.Name = "cbTargetTable"; - this.cbTargetTable.Size = new System.Drawing.Size(395, 28); + this.cbTargetTable.Size = new System.Drawing.Size(464, 28); this.cbTargetTable.TabIndex = 49; this.cbTargetTable.ValueMember = "TableName"; this.cbTargetTable.SelectedIndexChanged += new System.EventHandler(this.cbTargetTable_SelectedIndexChanged); @@ -545,6 +447,108 @@ namespace ExportDataToFile this.btnMapping.UseVisualStyleBackColor = true; this.btnMapping.Click += new System.EventHandler(this.btnMapping_Click); // + // clExpColumn + // + this.clExpColumn.HeaderText = "匯出"; + this.clExpColumn.Name = "clExpColumn"; + this.clExpColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.clExpColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; + this.clExpColumn.Width = 65; + // + // clClean + // + this.clClean.HeaderText = "清除"; + this.clClean.Name = "clClean"; + this.clClean.Width = 50; + // + // clSourceColumn + // + this.clSourceColumn.DataPropertyName = "COLUMN_NAME"; + this.clSourceColumn.HeaderText = "來源欄位"; + this.clSourceColumn.Name = "clSourceColumn"; + this.clSourceColumn.ReadOnly = true; + this.clSourceColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.clSourceColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.clSourceColumn.Width = 200; + // + // clType + // + this.clType.DataPropertyName = "DATA_TYPE"; + this.clType.HeaderText = "型態"; + this.clType.Name = "clType"; + this.clType.Width = 80; + // + // clTargetColumn + // + this.clTargetColumn.HeaderText = "目標欄位"; + this.clTargetColumn.Name = "clTargetColumn"; + this.clTargetColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.clTargetColumn.Width = 200; + // + // 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 = "Clean"; + this.clCancel.Width = 55; + // + // 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.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.HeaderText = "清除目標資料表內容"; + this.clTableDel.Name = "clTableDel"; + this.clTableDel.Width = 180; + // + // clMaxRecord + // + this.clMaxRecord.HeaderText = "檔案匯出上限筆數"; + this.clMaxRecord.Name = "clMaxRecord"; + this.clMaxRecord.Width = 160; + // + // clWhere + // + this.clWhere.HeaderText = "過濾條件"; + this.clWhere.Name = "clWhere"; + this.clWhere.Visible = false; + this.clWhere.Width = 200; + // + // clMappingData + // + this.clMappingData.HeaderText = "欄位對應"; + this.clMappingData.Name = "clMappingData"; + this.clMappingData.Visible = false; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 20F); @@ -631,21 +635,21 @@ namespace ExportDataToFile private System.Windows.Forms.Label label13; private System.Windows.Forms.Label label14; 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.Button btnMapping; private System.Windows.Forms.DataGridViewCheckBoxColumn clExport; private System.Windows.Forms.DataGridViewButtonColumn clCancel; private System.Windows.Forms.DataGridViewTextBoxColumn clSourceTable; private System.Windows.Forms.DataGridViewTextBoxColumn clTargetTable; private System.Windows.Forms.DataGridViewCheckBoxColumn clTableDel; - private System.Windows.Forms.DataGridViewCheckBoxColumn clDataTrim; private System.Windows.Forms.DataGridViewTextBoxColumn clMaxRecord; private System.Windows.Forms.DataGridViewTextBoxColumn clWhere; private System.Windows.Forms.DataGridViewTextBoxColumn clMappingData; - private System.Windows.Forms.SaveFileDialog sfPath; } } diff --git a/Form1.cs b/Form1.cs index 4743768..2a21657 100644 --- a/Form1.cs +++ b/Form1.cs @@ -57,6 +57,7 @@ namespace ExportDataToFile break; } + EnableExport(); //啟動匯出鈕 } else { @@ -89,6 +90,8 @@ namespace ExportDataToFile { if (cbTargetClass.Enabled) { + LockTargetForm(); + switch (cbTargetClass.SelectedItem.ToString().Trim()) { case "MS-SQL": @@ -108,7 +111,7 @@ namespace ExportDataToFile break; } - LockTargetForm(); + EnableExport(); //啟動匯出鈕 } else { @@ -244,15 +247,23 @@ namespace ExportDataToFile { try { - if (cbSourceClass.SelectedIndex != -1) + if (cbSourceClass.SelectedIndex > 0) { string strPath = ""; - sfPath.ShowDialog(); + sfPath.AddExtension = false; + sfPath.Filter = "All files (*.*)|*.*|SQL Files(*.sql)|*.sql|txt files(*.txt)|*.txt"; + sfPath.FileName = "Output" + DateTime.Now.ToString("_yyyyMMddHHmmss"); + + + if (sfPath.ShowDialog() == DialogResult.Cancel) //如果按下取消,放棄後面動作 + return; + strPath = sfPath.FileName; + switch (cbSourceClass.SelectedItem.ToString().Trim()) { case "MS-SQL": //匯出MS-SQL檔 - ExportMSSQLData(strPath); + ExportMSSQLData(sfPath.FileName,sfPath.DefaultExt); break; case "MySQL": @@ -283,6 +294,9 @@ namespace ExportDataToFile private void btnMapping_Click(object sender, EventArgs e) { + if (dgvColumnMapping.DataSource == null) + return; + //自動預設產生所有的Mapping檔案 dgvExportList.Rows[intExportIndex].Cells["clMappingData"].Value = GenMappingColumn(); dgvExportList.Rows[intExportIndex].Cells["clExport"].Value = true; @@ -350,7 +364,7 @@ namespace ExportDataToFile { try { - string strGetMSSQLColumnList = "Select COLUMN_NAME From INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME ='" + strTableName + "' Order by ORDINAL_POSITION"; + string strGetMSSQLColumnList = "Select COLUMN_NAME,DATA_TYPE From INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME ='" + strTableName + "' Order by ORDINAL_POSITION"; dgvColumnMapping.DataSource = MSSQLUtility.GetSQLResult(strGetMSSQLColumnList, sqlConn).Tables["Result"]; } catch (Exception ex) @@ -374,18 +388,22 @@ namespace ExportDataToFile } } - private void ExportMSSQLData(string strPath) + private void ExportMSSQLData(string strPath,string subFileName) { + int intDataCount = 0; + int intMaxData = 0; string strSourceColumns = ""; string strSourceCol = ""; string strSourceTable = ""; + string strSourceType = ""; string strTargetColumns = ""; string strTargetCol = ""; string strTargetTable = ""; + string strDeleteCommand = ""; string strValues = ""; string[] strColumns = null; + string[,] strColumnResults = new string[dgvExportList.Rows.Count, 2]; StringBuilder sbSelectCommand = new StringBuilder(); - StringBuilder sbInsertCommand = new StringBuilder(); //命令字串處理 strSourceColumns = ""; @@ -396,26 +414,38 @@ namespace ExportDataToFile { if (dgvRow.Cells["clExport"].Value != null) { + intDataCount = 0; + intMaxData = 0; strColumns = null; sbSelectCommand.Clear(); - sbInsertCommand.Clear(); strSourceTable = ""; strSourceColumns = ""; + strSourceType = ""; strTargetTable = ""; strTargetColumns = ""; + strDeleteCommand = ""; strValues = ""; DataTable dtResult = null; + //取得欄位對應 if (dgvRow.Cells["clMappingData"].Value != null) { strColumns = dgvRow.Cells["clMappingData"].Value.ToString().Split('|'); } + //取得欄位上限 + if (dgvRow.Cells["clMaxRecord"].Value != null) + { + intMaxData = Int32.Parse(dgvRow.Cells["clMaxRecord"].Value.ToString()); + } + + #region 產生來源資料查詢命令 foreach (string RowData in strColumns) { strSourceCol = RowData.Substring(0, RowData.IndexOf(',')).Trim(); - strTargetCol = RowData.Substring(RowData.IndexOf(',') + 1).Trim(); + strSourceType = RowData.Substring(RowData.IndexOf(',') + 1, RowData.IndexOf(';') - 1 - RowData.IndexOf(',')).Trim(); + strTargetCol = RowData.Substring(RowData.IndexOf(';') + 1).Trim(); if (strTargetCol == "") { @@ -423,15 +453,15 @@ namespace ExportDataToFile } if (strSourceColumns == "") - { - strSourceColumns += "[" + strSourceCol + "] AS '" + strTargetCol + "'"; - strTargetColumns += strTargetCol; + { + strSourceColumns += ConvertMSSQLColumnType(strSourceCol, strTargetCol, strSourceType); + strTargetColumns += "[" + strTargetCol + "]"; } else { - strSourceColumns += ", [" + strSourceCol + "] AS '" + strTargetCol + "'"; - strTargetColumns += "," + strTargetCol; - } + strSourceColumns += "," + ConvertMSSQLColumnType(strSourceCol, strTargetCol, strSourceType); + strTargetColumns += ",[" + strTargetCol + "]"; + } } if (dgvRow.Cells["clSourceTable"].Value != null) @@ -440,7 +470,6 @@ namespace ExportDataToFile sbSelectCommand.AppendLine(string.Format("Select {0} From {1} ", strSourceColumns, strSourceTable)); } - if (dgvRow.Cells["clWhere"].Value != null) { if (dgvRow.Cells["clWhere"].Value.ToString().Trim() != "") @@ -448,34 +477,77 @@ namespace ExportDataToFile sbSelectCommand.AppendLine("Where 1=1 And " + dgvRow.Cells["clWhere"].Value.ToString()); } } + #endregion - //取得完整SQL查詢Command - //txtWhere.Text = sbResult.ToString(); - //txtWhere.Text = strTargetColumns; 目標欄位對應 + #region 產生匯出資料語法 dtResult = GetMSSQLResult(sbSelectCommand.ToString()).Tables["Result"]; - foreach (DataRow dr in dtResult.Rows) - { - foreach (DataColumn dc in dtResult.Columns) + if (dtResult.Rows.Count > 0) + { + if (dgvRow.Cells["clTargetTable"].Value != null) { - if (strValues == "") + strTargetTable = dgvRow.Cells["clTargetTable"].Value.ToString(); + Utility.WriteFile(strPath + ".sql", " "); + Utility.WriteFile(strPath + ".sql", string.Format("/*======================================================={0}======================================================*/", strTargetTable)); + Utility.WriteFile(strPath + ".sql", string.Format("raiserror('Now Insert {0} Datas .... ', 1, 1)", strTargetTable)); + Utility.WriteFile(strPath + ".sql", "Go"); + } + + //勾選清除目標資料表 + if (dgvRow.Cells["clTableDel"].Value != null) + { + strDeleteCommand = string.Format("Delete From {0} ", strTargetTable); + + if (dgvRow.Cells["clWhere"].Value != null) { - strValues = "'" + dr[dc].ToString() + "'"; + if (dgvRow.Cells["clWhere"].Value.ToString().Trim() != "") + { + strDeleteCommand += "Where 1=1 And " + dgvRow.Cells["clWhere"].Value.ToString(); + } } - else + + Utility.WriteFile(strPath + ".sql", strDeleteCommand + ";"); + Utility.WriteFile(strPath + ".sql", "Go"); + } + + //處理筆數上限似資料匯出 + string strFileCount = ""; + foreach (DataRow dr in dtResult.Rows) + { + strFileCount = (intDataCount / intMaxData).ToString(); //切分檔案 + foreach (DataColumn dc in dtResult.Columns) { - strValues += ",'" + dr[dc].ToString() + "'"; + if (strValues == "") + { + strValues = ConvertMSSQLDataType(dr[dc].ToString().Trim(), dc.DataType.ToString()); + } + else + { + strValues += "," + ConvertMSSQLDataType(dr[dc].ToString().Trim(), dc.DataType.ToString()); + } } - } - if (dgvRow.Cells["clTargetTable"].Value != null) - { - strTargetTable = dgvRow.Cells["clTargetTable"].Value.ToString(); - sbInsertCommand.AppendLine(string.Format("Insert Into {0} ({1}) ",strSourceTable, strValues)); + if (intMaxData == 0) + { + //無設定最大筆數 + Utility.WriteFile(strPath + ".sql", string.Format("Insert Into {0} ({1}) Values ({2}) ", strTargetTable, strTargetColumns, strValues)); + } + else + { + //有設定最大筆數 + if (strFileCount == "0") + strFileCount = ""; + Utility.WriteFile(strPath + strFileCount + ".sql", string.Format("Insert Into {0} ({1}) Values ({2}) ", strTargetTable, strTargetColumns, strValues)); + } + intDataCount += 1; + strValues = ""; //清除已經存在的資料 } - } - } - Utility.WriteFile(strPath, sbInsertCommand.ToString()); + Utility.WriteFile(strPath + strFileCount + ".sql", "Go"); + } + + } + #endregion } + MessageBox.Show("匯出完成"); } #endregion //End of MS-SQL @@ -486,7 +558,7 @@ namespace ExportDataToFile { string strResult = ""; - if (cbSourceClass.SelectedItem == null) + if (cbSourceClass.SelectedIndex <= 0) { strResult = "請選擇來源資料庫類別"; cbSourceClass.Focus(); @@ -529,8 +601,13 @@ namespace ExportDataToFile try { string strResult = ""; - - if (cbTargetClass.SelectedItem != null) + if (cbTargetClass.SelectedIndex <= 0) + { + strResult = "請選擇目標資料庫類別"; + cbTargetClass.Focus(); + return strResult; + } + else { if (txtTargetIP.Text.Trim() == "") { @@ -639,6 +716,7 @@ namespace ExportDataToFile string strExportColumns = ""; string strSourceColumn = ""; string strTargetColumn = ""; + string strSourceColType = ""; //預設所有欄位均匯出 foreach (DataGridViewRow dgRow in dgvColumnMapping.Rows) @@ -657,6 +735,15 @@ namespace ExportDataToFile strSourceColumn = dgRow.Cells["clSourceColumn"].Value.ToString(); } + if (dgRow.Cells["clType"].Value == null) + { + strSourceColType = " "; + } + else + { + strSourceColType = dgRow.Cells["clType"].Value.ToString(); + } + if (dgRow.Cells["clTargetColumn"].Value == null) { strTargetColumn = " "; @@ -669,11 +756,11 @@ namespace ExportDataToFile if (strExportColumns == "") { - strExportColumns += strSourceColumn + "," + strTargetColumn; + strExportColumns += strSourceColumn + "," + strSourceColType + ";" + strTargetColumn; } else { - strExportColumns += "|" + strSourceColumn + "," + strTargetColumn; + strExportColumns += "|" + strSourceColumn + "," + strSourceColType + ";" + strTargetColumn; } } } @@ -779,7 +866,6 @@ namespace ExportDataToFile senderGrid.Rows[intRowIndex].Cells["clExport"].Value = false; senderGrid.Rows[intRowIndex].Cells["clTargetTable"].Value = ""; senderGrid.Rows[intRowIndex].Cells["clTableDel"].Value = false; - senderGrid.Rows[intRowIndex].Cells["clDataTrim"].Value = false; senderGrid.Rows[intRowIndex].Cells["clMaxRecord"].Value = ""; senderGrid.Rows[intRowIndex].Cells["clWhere"].Value = ""; senderGrid.Rows[intRowIndex].Cells["clMappingData"].Value = ""; @@ -794,8 +880,52 @@ namespace ExportDataToFile CleanTable.Rows.Clear(); dgvColumnMapping.DataSource = CleanTable; } + + private void EnableExport() + { + if (sqlSourceConn.State.ToString().ToUpper() == "OPEN" && sqlTargetConn.State.ToString().ToUpper() == "OPEN") + { + btnExport.Enabled = true; + } + } + + private string ConvertMSSQLColumnType(string strSourceCol, string strTargetCol, string strType) + { + switch (strType.ToUpper()) + { + case "VARCHAR": + return "[" + strSourceCol + "] AS " + strTargetCol ; + case "VAR": + return "[" + strSourceCol + "] AS " + strTargetCol ; + case "INT": + return "[" + strSourceCol + "] AS " + strTargetCol; + case "DATETIME": + return "Convert(varchar,[" + strSourceCol + "],21) AS " + strTargetCol; + default: + return "[" + strSourceCol + "] AS " + strTargetCol; + } + } + + private string ConvertMSSQLDataType(string strData, string strType) + { + if(strData == "") + { + return "Null"; + } + switch (strType.ToUpper()) + { + case "STRING": + return "'" + strData.ToString().Trim() + "'"; + case "INT32": + return strData.ToString().Trim(); + case "DECIMAL": + return strData.ToString().Trim(); + default: + return "'" + strData.ToString().Trim() + "'"; + } + } #endregion - + } } diff --git a/Form1.resx b/Form1.resx index 1727aa0..8a02208 100644 --- a/Form1.resx +++ b/Form1.resx @@ -132,9 +132,6 @@ True - - True - True @@ -153,6 +150,9 @@ True + + True + True