private void addButton_Click(object sender, RoutedEventArgs e) { DataScriptMapDAL.delAll(FID); DataScriptRuleDAL.updateBusinessPK(FID, columnConnection.BusinessPK); foreach (var key in columnConnection.ColumnMap.Keys) { DataScriptMap map = new DataScriptMap(); map.FID = Guid.NewGuid().ToString().Replace("-", ""); map.MdsImpDataScriptRuleID = FID; map.TableColName = key; map.FileColName = columnConnection.ColumnMap[key]; map.TransferType = "02"; map.LastUpdateIp = "127.0.0.1"; map.LastUpdatedBy = MainWindow.UserID; map.CreatedBy = MainWindow.UserID; // 如果有算式,保存 if (columnConnection.ScriptMap.ContainsKey(key)) { map.TransferScript = columnConnection.ScriptMap[key]; } DataScriptMapDAL.Insert(map); } MessageBox.Show("对应关系已经保存!"); MainWindow window = App.Current.MainWindow as MainWindow; window.StartPage(new DataScriptList()); }
private void Comments() { foreach (DataColumn column in sourceDt.Columns) { if (structures.FirstOrDefault(it => it.Comments == column.ColumnName) == null) { var st = structures.FirstOrDefault(it => string.IsNullOrEmpty(it.Comments)); TableDAL.Comment(dataScript.TableName, st.ColumnName, column.ColumnName); st.Comments = column.ColumnName; if (update.IsChecked.Value) { DataScriptMap map = new DataScriptMap(); map.FID = Guid.NewGuid().ToString().Replace("-", ""); map.MdsImpDataScriptRuleID = dataScript.FID; map.TableColName = st.ColumnName; map.FileColName = column.ColumnName; map.TransferType = "02"; map.CreatedBy = MainWindow.UserID; map.LastUpdatedBy = MainWindow.UserID; map.LastUpdateIp = "127.0.0.1"; DataScriptMapDAL.Insert(map); } } } }
private void updateTableStructure(string tableName) { DataTable dt = GetDataTable(txtTemplageFile.Text); // 增加对应关系 var structures = TableDAL.getTableStructure(tableName); int max = getMaxColumnIndex(structures); for (int i = 0; i < dt.Columns.Count; i++) { DataColumn column = dt.Columns[i]; if (structures.FirstOrDefault(it => it.Comments == column.ColumnName) == null) { max++; double d = 0.0; if (double.TryParse(dt.Rows[0][column].ToString(), out d)) { TableDAL.AddColumn(tableName, "COLUMN" + max.ToString(), "number"); } else { TableDAL.AddColumn(tableName, "COLUMN" + max.ToString(), "string"); } TableDAL.Comment(tableName, "COLUMN" + max.ToString(), column.ColumnName); } } structures = TableDAL.getTableStructure(tableName); for (int i = 0; i < dt.Columns.Count; i++) { DataColumn column = dt.Columns[i]; var structure = structures.FirstOrDefault(it => it.Comments == column.ColumnName); if (structure != null) { DataScriptMap map = new DataScriptMap(); map.FID = Guid.NewGuid().ToString().Replace("-", ""); map.MdsImpDataScriptRuleID = dScript.FID; map.TableColName = structure.ColumnName; map.FileColName = structure.Comments; map.TransferType = "02"; map.CreatedBy = MainWindow.UserID; map.LastUpdatedBy = MainWindow.UserID; map.LastUpdateIp = "127.0.0.1"; DataScriptMapDAL.Insert(map); } } }
public static int Insert(DataScriptMap item) { string sql = string.Format("INSERT INTO MDS_IMP_DATA_SCRIPT_MAP(FID,MDS_IMP_DATA_SCRIPT_RULE_ID,TABLE_COL_NAME,FILE_COL_NAME,TRANSFER_TYPE,INSERT_VALUE_METHOD,TRANSFER_SCRIPT,REMARK,CREATED_BY,CREATION_DATE,LAST_UPDATED_BY,LAST_UPDATE_DATE,LAST_UPDATE_IP,VERSION) "); sql += string.Format("VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',to_date('{9}','yyyy/mm/dd hh24:mi:ss'),'{10}',to_date('{11}','yyyy/mm/dd hh24:mi:ss'),'{12}',{13})", item.FID, item.MdsImpDataScriptRuleID, item.TableColName, item.FileColName, item.TransferType, item.InsertValueMethod, item.TransferScript.Replace("'", "''").Replace("\r\n", "'||chr(13)||chr(10)||'"), item.Remark, item.CreatedBy, item.CreationDate.ToString("yyyy/MM/dd HH:mm:ss"), item.LastUpdatedBy, item.LastUpdateDate.ToString("yyyy/MM/dd HH:mm:ss"), item.LastUpdateIp, item.Version); //SaveScriptFile(item); return(OracleHelper.Excuse(sql)); }
public static List <DataScriptMap> getList(string mdsID) { List <DataScriptMap> result = new List <DataScriptMap>(); string sql = string.Format("SELECT * FROM MDS_IMP_DATA_SCRIPT_MAP WHERE MDS_IMP_DATA_SCRIPT_RULE_ID='{0}'", mdsID); DataSet ds = OracleHelper.Query(sql); foreach (DataRow dr in ds.Tables[0].Rows) { DataScriptMap item = DataScriptMap.Parse(dr); result.Add(item); } return(result); }
public static List <DataScriptMap> getList() { List <DataScriptMap> result = new List <DataScriptMap>(); string sql = "SELECT * FROM MDS_IMP_DATA_SCRIPT_MAP"; DataSet ds = OracleHelper.Query(sql); foreach (DataRow dr in ds.Tables[0].Rows) { DataScriptMap item = DataScriptMap.Parse(dr); result.Add(item); } return(result); }
/// <summary> /// 保存数据更新值转换解析器 /// </summary> private static void SaveScriptFile(DataScriptMap entity) { if (!Directory.Exists("script")) { Directory.CreateDirectory("script"); } if (File.Exists(string.Format("script/{0}.py", entity.FID))) { File.Delete(string.Format("script/{0}.py", entity.FID)); } FileStream fs = new FileStream(string.Format("script/{0}.py", entity.FID), FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(entity.TransferScript); sw.Flush(); sw.Close(); }
public static void AutoScriptMap(string scriptid, DataTable source, string tablename, string userid) { delAll(scriptid); var structures = TableDAL.getTableStructure(tablename); foreach (DataColumn column in source.Columns) { var st = structures.FirstOrDefault(it => it.Comments == column.ColumnName); if (st != null) { DataScriptMap map = new DataScriptMap(); map.FID = Guid.NewGuid().ToString().Replace("-", ""); map.MdsImpDataScriptRuleID = scriptid; map.TableColName = st.ColumnName; map.FileColName = column.ColumnName; map.TransferType = "02"; map.CreatedBy = userid; map.LastUpdatedBy = userid; map.LastUpdateIp = "127.0.0.1"; Insert(map); } } }
private void btnNext_Click(object sender, RoutedEventArgs e) { ImportRun mapModify = new ImportRun(); mapModify.DataScript = this.DataScript; mapModify.DataScriptRule = this.DataScriptRule; mapModify.ColumnMap = columnConnection.ColumnMap; mapModify.ScriptMap = columnConnection.ScriptMap; mapModify.sourceFile = sourceFile; mapModify.DataScriptRule.DesBusinessPk = columnConnection.BusinessPK; if (!mapModify.ColumnMap.ContainsKey("COLUMN0")) { MessageBox.Show("您需要指定时间列的关联关系,才可以导入数据!"); return; } foreach (string key in mapModify.ScriptMap.Keys) { string script = mapModify.ScriptMap[key].Trim(); if (!string.IsNullOrEmpty(script)) { DataScriptMapDAL.SaveScriptFile(key, script); } } // 保存对应关系 if (DataScriptInfo.saveScript || true) { DataScriptMapDAL.delAll(FID); DataScriptRuleDAL.updateBusinessPK(FID, columnConnection.BusinessPK); foreach (var key in columnConnection.ColumnMap.Keys) { DataScriptMap map = new DataScriptMap(); map.FID = Guid.NewGuid().ToString().Replace("-", ""); map.MdsImpDataScriptRuleID = FID; map.TableColName = key; map.FileColName = columnConnection.ColumnMap[key]; map.TransferType = "02"; map.CreatedBy = MainWindow.UserID; map.LastUpdatedBy = MainWindow.UserID; map.LastUpdateIp = "127.0.0.1"; // 如果有算式,保存 if (columnConnection.ScriptMap.ContainsKey(key)) { map.TransferScript = columnConnection.ScriptMap[key]; } DataScriptMapDAL.Insert(map); } //MessageBox.Show("对应关系已经保存!"); } ImportStack.Push(this); MainWindow window = App.Current.MainWindow as MainWindow; window.StartPage(mapModify); }