//================================================================= // 【傳入table name】 取得該table的select語句,代換成delete語句 //================================================================= private string GetDeleteScript(string script) { GetDataDao dao = new GetDataDao(); string scriptString = string.Empty; scriptString = dao.GetScriptString(script, strRefPdtCode); scriptString = scriptString.Replace("select * ", "delete "); return(scriptString); }
//================================================================= // 【傳入商品類別代碼】 帶出商品下拉列表 //================================================================= protected void ShowProductList(string productKind) { GetDataDao dao = new GetDataDao(); DataTable dt = dao.GetProducts(productKind); DataRow row = dt.NewRow(); row["fullName"] = "請選擇"; row["PD_PDTCODE"] = ""; dt.Rows.InsertAt(row, 0); comboBox1.DisplayMember = "fullName"; comboBox1.ValueMember = "PD_PDTCODE"; comboBox1.DataSource = dt; }
//================================================================= // 【ComboBox SelectedIndexChanged】 選擇商品代碼,將該商品已設定之table name勾選 //================================================================= protected void cbbProduct_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex.Equals(0)) { if (rdoTrad.Checked.Equals(true)) { ShowScriptList("1"); } else { ShowScriptList("2"); } } ComboBox cbb = (ComboBox)sender; string pdtCode = cbb.SelectedValue.ToString(); Generate.strRefPdtCode = pdtCode; DataSet ds = new DataSet(); GetDataDao dao = new GetDataDao(); if (rdoTrad.Checked.Equals(true)) { ds = dao.GetProductScriptList("1", pdtCode); foreach (DataTable tb in ds.Tables) { if (tb.Rows.Count > 0) { CheckBox ckb = groupSQLScript.Controls.Find(tb.TableName, true).First() as CheckBox; ckb.Checked = true; } } } else { ds = dao.GetProductScriptList("2", pdtCode); foreach (DataTable tb in ds.Tables) { if (tb.Rows.Count > 0) { CheckBox ckb = groupSQLScript.Controls.Find(tb.TableName, true).First() as CheckBox; ckb.Checked = true; } } } }
//================================================================= // 【傳入單個Table Name】 取得該tabledata並轉成script //================================================================= private string GenerateScript(string script) { GetDataDao dao = new GetDataDao(); DataTable dt = new DataTable(); dt = dao.GetScriptData(script, strRefPdtCode); StringBuilder sb = new StringBuilder(); sb.AppendLine(GetDeleteScript(script)); sb.AppendLine(); sb.Append("INSERT INTO [dbo]."); sb.Append("[" + dt.TableName + "]"); sb.Append("("); foreach (DataColumn col in dt.Columns) { sb.Append("[" + col.ToString() + "], "); } sb = sb.Remove(sb.Length - 2, 2); sb.AppendLine(")"); sb.AppendLine("values"); foreach (DataRow row in dt.Rows) { sb.Append("("); foreach (DataColumn col in dt.Columns) { if (col.DataType.ToString().Equals("System.String")) { sb.Append(" N'" + row[col].ToString() + "',"); } else if (col.DataType.ToString().Equals("System.DateTime")) { sb.Append(" '" + Convert.ToDateTime(row[col]).ToString("yyyyMMdd hh:mm:ss.fff") + "',"); } else { sb.Append(" " + row[col].ToString() + ","); } } sb = sb.Remove(sb.Length - 1, 1); sb.AppendLine(" ),"); } sb = sb.Remove(sb.Length - 3, 3); string finalStr = ReplaceToNewPdt(sb.ToString()); return(finalStr); }
private string GenerateAllSelectScript(string strNewPdt, string strRefPdt, List <string> checkedScript) { GetDataDao dao = new GetDataDao(); StringBuilder sb = new StringBuilder(); sb.AppendLine(); foreach (var script in checkedScript) { if (script.Equals("RPT_SECTION_D") || script.Equals("PLI_PDTRIDERSUM")) { sb.AppendLine(dao.GetScriptString(script, strRefPdt)); } else { sb.AppendLine(dao.GetScriptString(script, strNewPdt)); } sb.AppendLine(dao.GetScriptString(script, strRefPdt)); sb.AppendLine(); } return(sb.ToString()); }