public ActivityInfo GetActivityInfo(int activityID, int nodeID, int wfProcessID, Ctx ctx) { ActivityInfo info = new ActivityInfo(); try { MWFNode node = new MWFNode(ctx, nodeID, null); info.NodeAction = node.GetAction(); info.NodeName = node.GetName(); if (MWFNode.ACTION_UserChoice.Equals(node.GetAction())) { MColumn col = node.GetColumn(); info.ColID = col.GetAD_Column_ID(); info.ColReference = col.GetAD_Reference_ID(); info.ColReferenceValue = col.GetAD_Reference_Value_ID(); info.ColName = col.GetColumnName(); } else if (MWFNode.ACTION_UserWindow.Equals(node.GetAction())) { info.AD_Window_ID = node.GetAD_Window_ID(); MWFActivity activity = new MWFActivity(ctx, activityID, null); info.KeyCol = activity.GetPO().Get_TableName() + "_ID"; } else if (MWFNode.ACTION_UserForm.Equals(node.GetAction())) { info.AD_Form_ID = node.GetAD_Form_ID(); } string sql = @"SELECT node.ad_wf_node_ID, node.Name AS NodeName, usr.Name AS UserName, wfea.wfstate, wfea.TextMsg FROM ad_wf_eventaudit wfea INNER JOIN Ad_WF_Node node ON (node.Ad_Wf_node_ID=wfea.AD_Wf_Node_id) INNER JOIN AD_User usr ON (usr.Ad_User_ID =wfea.ad_User_ID) WHERE wfea.AD_WF_Process_ID=" + wfProcessID + @" Order By wfea.ad_wf_eventaudit_id desc"; DataSet ds = DB.ExecuteDataset(sql); if (ds != null && ds.Tables[0].Rows.Count > 0) { List <NodeInfo> nodeInfo = new List <NodeInfo>(); List <int> nodes = new List <int>(); NodeInfo ni = null; NodeHistory nh = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (!nodes.Contains(Util.GetValueOfInt(ds.Tables[0].Rows[i]["AD_WF_Node_ID"]))) { ni = new NodeInfo(); ni.Name = Util.GetValueOfString(ds.Tables[0].Rows[i]["NodeName"]); nh = new NodeHistory(); nh.State = Util.GetValueOfString(ds.Tables[0].Rows[i]["WFState"]); nh.ApprovedBy = Util.GetValueOfString(ds.Tables[0].Rows[i]["UserName"]); ni.History = new List <NodeHistory>(); if (ds.Tables[0].Rows[i]["TextMsg"] == null || ds.Tables[0].Rows[i]["TextMsg"] == DBNull.Value) { nh.TextMsg = string.Empty; } else { nh.TextMsg = ds.Tables[0].Rows[i]["TextMsg"].ToString(); } ni.History.Add(nh); nodes.Add(Util.GetValueOfInt(ds.Tables[0].Rows[i]["AD_WF_Node_ID"])); nodeInfo.Add(ni); } else { int index = nodes.IndexOf(Util.GetValueOfInt(ds.Tables[0].Rows[i]["AD_WF_Node_ID"])); nh = new NodeHistory(); nh.State = Util.GetValueOfString(ds.Tables[0].Rows[i]["WFState"]); nh.ApprovedBy = Util.GetValueOfString(ds.Tables[0].Rows[i]["UserName"]); if (ds.Tables[0].Rows[i]["TextMsg"] == null || ds.Tables[0].Rows[i]["TextMsg"] == DBNull.Value) { nh.TextMsg = string.Empty; } else { nh.TextMsg = ds.Tables[0].Rows[i]["TextMsg"].ToString(); } nodeInfo[index].History.Add(nh); } } info.Node = nodeInfo; } return(info); } catch { return(info); } }
/// <summary> /// Create default columns for Master Data Version Table /// e.g. Processed, Processing, IsApproved etc. /// </summary> /// <param name="Ver_AD_Table_ID"></param> /// <returns></returns> private string CreateDefaultVerCols(int Ver_AD_Table_ID) { DataSet dstblCols = DB.ExecuteDataset("SELECT ColumnName FROM AD_Column WHERE AD_Table_ID = " + Ver_AD_Table_ID, null, null); for (int i = 0; i < listDefVerCols.Count; i++) { bool hasCol = false; if (dstblCols != null && dstblCols.Tables[0].Rows.Count > 0) { DataRow[] dr = dstblCols.Tables[0].Select("ColumnName = '" + listDefVerCols[i] + "'"); if (dr != null && dr.Length > 0) { hasCol = true; } } if (hasCol) { continue; } MColumn colVer = new MColumn(GetCtx(), 0, _trx); colVer.SetExport_ID(null); colVer.SetAD_Table_ID(Ver_AD_Table_ID); colVer.SetColumnName(listDefVerCols[i]); colVer.SetAD_Element_ID(_listDefVerElements[i]); colVer.SetAD_Reference_ID(listDefVerRef[i]); //if (listDefVerCols[i] == "VersionValidFrom") // colVer.SetIsParent(true); if (listDefVerRef[i] == 10) { colVer.SetFieldLength(10); } if (listDefVerRef[i] == 14) { colVer.SetFieldLength(2000); } if (listDefVerRef[i] == 13) { colVer.SetIsKey(true); colVer.SetIsMandatory(true); colVer.SetIsMandatoryUI(true); } if (!colVer.Save()) { ValueNamePair vnp = VLogger.RetrieveError(); string error = ""; if (vnp != null) { error = vnp.GetName(); if (error == "" && vnp.GetValue() != null) { error = vnp.GetValue(); } } if (error == "") { error = "Error in creating Version Column " + listDefVerCols[i]; } log.Log(Level.SEVERE, "Version Column not created :: " + listDefVerCols[i] + " :: " + error); _trx.Rollback(); return(Msg.GetMsg(GetCtx(), "VersionColNotCreated")); } else { oldVerCol = colVer.GetAD_Column_ID(); } } return(""); }
}// prepare /// <summary> /// Alert table /// </summary> /// <returns>int</returns> /// override protected string DoIt() { string exception = ""; log.Info("C_Column_ID=" + p_AD_Column_ID); if (p_AD_Column_ID == 0) { // return ""; throw new Exception("@No@ @AD_Column_ID@"); } //IDbTransaction trx = ExecuteQuery.GerServerTransaction(); MColumn column = new MColumn(GetCtx(), p_AD_Column_ID, Get_Trx()); if (column.Get_ID() == 0) { throw new Exception("@NotFound@ @AD_Column_ID@" + p_AD_Column_ID); } MTable table = MTable.Get(GetCtx(), column.GetAD_Table_ID()); if (table.Get_ID() == 0) { throw new Exception("@NotFound@ @AD_Table_ID@" + column.GetAD_Table_ID()); } // Find Column in Database if (column.IsVirtualColumn()) { return("@IsVirtualColumn@"); } int noColumns = 0; string sql = CommonFunctions.SyncColumn(table, column, out noColumns); //DatabaseMetaData md = new DatabaseMetaData(); //String catalog = ""; //String schema = DataBase.DB.GetSchema(); ////get table name //string tableName = table.GetTableName(); //int noColumns; //string sql = null; ////get columns of a table //DataSet dt = md.GetColumns(catalog, schema, tableName); //md.Dispose(); ////for each column //for (noColumns = 0; noColumns < dt.Tables[0].Rows.Count; noColumns++) //{ // string columnName = dt.Tables[0].Rows[noColumns]["COLUMN_NAME"].ToString().ToLower(); // if (!columnName.Equals(column.GetColumnName().ToLower())) // continue; // //check if column is null or not // string dtColumnName = "is_nullable"; // string value = "YES"; // //if database is oracle // if (DatabaseType.IsOracle) // { // dtColumnName = "NULLABLE"; // value = "Y"; // } // bool notNull = false; // //check if column is null // if (dt.Tables[0].Rows[noColumns][dtColumnName].ToString() == value) // notNull = false; // else // notNull = true; // //............................ // //if column is virtual column then alter table and drop this column // if (column.IsVirtualColumn()) // { // sql = "ALTER TABLE " + table.GetTableName() // + " DROP COLUMN " + columnName; // } // else // { // sql = column.GetSQLModify(table, column.IsMandatory() != notNull); // noColumns++; // break; // } //} //dt = null; ////while (rs.next()) ////{ //// noColumns++; //// String columnName = rs.getString ("COLUMN_NAME"); //// if (!columnName.equalsIgnoreCase(column.getColumnName())) //// continue; //// // update existing column //// boolean notNull = DatabaseMetaData.columnNoNulls == rs.getInt("NULLABLE"); //// if (column.isVirtualColumn()) //// sql = "ALTER TABLE " + table.getTableName() //// + " DROP COLUMN " + columnName; //// else //// sql = column.getSQLModify(table, column.isMandatory() != notNull); //// break; ////} ////rs.close(); ////rs = null; //// No Table //if (noColumns == 0) //{ // sql = table.GetSQLCreate(); //} //// No existing column //else if (sql == null) //{ // if (column.IsVirtualColumn()) // { // return "@IsVirtualColumn@"; // } // sql = column.GetSQLAdd(table); //} int no = 0; if (sql.IndexOf(";") == -1) { //no = //ExecuteQuery.ExecuteNonQuery(sql, false, Get_Trx()); try { no = DataBase.DB.ExecuteQuery(sql, null, Get_Trx()); AddLog(0, DateTime.MinValue, Decimal.Parse(no.ToString()), sql); } catch (Exception ex) { exception = ex.Message; } //addLog (0, null, new BigDecimal(no), sql); } else { //string ss = "; "; string[] statements = sql.Split(';'); for (int i = 0; i < statements.Length; i++) { int count = DataBase.DB.ExecuteQuery(statements[i].ToString(), null, Get_Trx()); AddLog(0, DateTime.MinValue, Decimal.Parse(count.ToString()), statements[i]); no += count; //ExecuteQuery.ExecuteNonQuery(statements[i].ToString()); } } if (no == -1) { string msg = "@Error@ "; ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { msg += exception + " - "; } msg += sql; throw new Exception(msg); } string r = createFK(noColumns); // Change here for Master Data Versioning bool hasMainVerCol = Util.GetValueOfInt(DB.ExecuteScalar("SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID = " + column.GetAD_Table_ID() + " AND IsActive ='Y' AND IsMaintainVersions = 'Y'", null, Get_Trx())) > 0; // check whether there are any columns in the table // marked as "Maintain Versions", then proceed else return if (!hasMainVerCol) { hasMainVerCol = Util.GetValueOfString(DB.ExecuteScalar("SELECT IsMaintainVersions FROM AD_Table WHERE AD_Table_ID = " + column.GetAD_Table_ID(), null, Get_Trx())) == "Y"; } string versionMsg = ""; if (hasMainVerCol) { // call CreateVersionInfo function of MasterVersions class // to create version table and all columns MasterVersions mv = new MasterVersions(); versionMsg = mv.CreateVersionInfo(column.GetAD_Column_ID(), column.GetAD_Table_ID(), Get_Trx()); } return(sql + "; " + r + "; " + versionMsg); } // doIt