コード例 #1
0
        /// <summary>
        /// Process
        /// throws Exception
        /// </summary>
        /// <returns>info</returns>
        override protected string DoIt()
        {
            //IDbTransaction trx = ExecuteQuery.GerServerTransaction();
            MTab tab = new MTab(GetCtx(), p_AD_Tab_ID, Get_Trx());

            //MTab tab = new MTab(GetCtx(), p_AD_Tab_ID, trx.ToString());
            if (p_AD_Tab_ID == 0 || tab == null || tab.Get_ID() == 0)
            {
                throw new Exception("@NotFound@: @AD_Tab_ID@ " + p_AD_Tab_ID);
            }
            //log.info(tab.toString());
            int    count = 0;
            string sql   = "SELECT * FROM AD_Column c "
                           + "WHERE NOT EXISTS (SELECT * FROM AD_Field f "
                           + "WHERE c.AD_Column_ID=f.AD_Column_ID"
                           + " AND c.AD_Table_ID=@AD_Table_Id" //	#1
                           + " AND f.AD_Tab_ID=@AD_Tab_Id)"    //	#2
                           + " AND AD_Table_ID=@AD_Table_Id1"  //	#3
                           + " AND NOT (Name LIKE 'Created%' OR Name LIKE 'Updated%')"
                           + " AND IsActive='Y' "
                           + "ORDER BY Name desc";


            try
            {
                SqlParameter[] param = new SqlParameter[3];
                param[0] = new SqlParameter("@AD_Table_Id", tab.GetAD_Table_ID());
                param[1] = new SqlParameter("@AD_Tab_Id", tab.GetAD_Tab_ID());
                param[2] = new SqlParameter("@AD_Table_Id1", tab.GetAD_Table_ID());
                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, Get_Trx());
                //DataSet ds1 = ExecuteQuery.ExecuteDataset(sql);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    //MColumn column = new MColumn (getCtx(),dr, Get_Trx());
                    //MColumn column = new MColumn(GetCtx(), dr, null);
                    MColumn column = new MColumn(GetCtx(), dr, Get_Trx());
                    //
                    MField field = new MField(tab);
                    field.SetColumn(column);
                    if (column.IsKey())
                    {
                        field.SetIsDisplayed(false);
                    }
                    if (column.GetColumnName().ToString() == "AD_Client_ID")
                    {
                        field.SetSeqNo(10);
                    }
                    if (column.GetColumnName().ToString() == "AD_Org_ID")
                    {
                        field.SetIsSameLine(true);
                        field.SetSeqNo(20);
                    }
                    //Export_ID Check  [Hide Export Field]
                    if (column.GetColumnName().ToString() == "Export_ID")
                    {
                        field.SetIsDisplayed(false);
                    }

                    if (field.Save())
                    {
                        AddLog(0, DateTime.MinValue, Decimal.Parse(count.ToString()), column.GetName());
                        //AddLog(0, DateTime.MinValue, null, );
                        count++;
                    }
                }

                ds = null;
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, sql, e);
            }

            return("@Created@ #" + count);
        }
コード例 #2
0
        /// <summary>
        /// Function to Create Version Fields (Defaults for Version tab) against version tab
        /// </summary>
        /// <param name="ver_AD_Tab_ID"> Version TabID</param>
        /// <param name="verFieldDS">Dataset of Version Fields</param>
        /// <param name="hasVerFlds">check of Version Field</param>
        /// <param name="verColumnsDS"> Dataset of Version Columns</param>
        /// <param name="Ver_TableID"> Version TableID</param>
        /// <returns>String (Message)</returns>
        private string CreateDefaultFields(int ver_AD_Tab_ID, DataSet verFieldDS, bool hasVerFlds, DataSet verColumnsDS, int Ver_TableID)
        {
            // Get system elements against Version Table's Columns
            string VerTableName = Util.GetValueOfString(DB.ExecuteScalar("SELECT TableName FROM AD_Table WHERE AD_Table_ID = " + Ver_TableID, null, Get_Trx()));

            GetSystemElements(VerTableName);

            // Get field Group ID for Versioning
            int AD_FieldGroup_ID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT AD_FieldGroup_ID FROM AD_FieldGroup WHERE Name = 'Versioning'", null, Get_Trx()));

            // get max seqno + 500 to set seqnumbers for new fields
            int SeqNo = Util.GetValueOfInt(DB.ExecuteScalar("SELECT MAX(SeqNo) + 500 FROM AD_Field WHERE AD_Tab_ID = " + ver_AD_Tab_ID, null, Get_Trx()));

            for (int i = 0; i < listDefVerCols.Count; i++)
            {
                // check if system element exist
                DataRow[] drVerFld = verFieldDS.Tables[0].Select("AD_Element_ID = " + _listDefVerElements[i]);
                if (drVerFld.Length <= 0)
                {
                    int    VerColID = 0;
                    MField verFld   = new MField(GetCtx(), 0, Get_TrxName());
                    verFld.SetAD_Tab_ID(ver_AD_Tab_ID);

                    DataRow[] drVerCol = verColumnsDS.Tables[0].Select("ColumnName = '" + listDefVerCols[i].ToString() + "'");
                    if (drVerCol.Length > 0)
                    {
                        VerColID = Util.GetValueOfInt(drVerCol[0]["AD_Column_ID"]);
                    }
                    else
                    {
                        log.Log(Level.SEVERE, "Version Column Not Found :: " + listDefVerCols[i].ToString());
                        Get_TrxName().Rollback();
                        return(Msg.GetMsg(GetCtx(), "ColumnNameNotFound") + " :: " + listDefVerCols[i].ToString());
                    }

                    verFld.SetAD_Column_ID(VerColID);

                    if (listDefVerCols[i].ToString() == "Processing" || listDefVerCols[i].ToString() == "Processed" || listDefVerCols[i].ToString() == VerTableName + "_ID")
                    {
                        verFld.SetIsDisplayed(false);
                    }

                    if (listDefVerCols[i].ToString() == "VersionLog")
                    {
                        verFld.SetDisplayLength(100);
                    }

                    //if (listDefVerCols[i].ToString() == "ProcessedVersion" || listDefVerCols[i].ToString() == "RecordVersion")
                    verFld.SetIsSameLine(true);

                    // Set Field Group for Versioning field
                    if (AD_FieldGroup_ID > 0)
                    {
                        verFld.SetAD_FieldGroup_ID(AD_FieldGroup_ID);
                    }
                    verFld.SetSeqNo(SeqNo);
                    //"VersionValidFrom", "IsVersionApproved", "ProcessedVersion", "RecordVersion", "Processed", "Processing", "VersionLog", "OldVersion"
                    if (listDefVerCols[i].ToString() == "VersionValidFrom")
                    {
                        verFld.SetMRIsDisplayed("Y");
                        verFld.SetMRSeqNo(5);
                    }
                    if (listDefVerCols[i].ToString() == "RecordVersion")
                    {
                        verFld.SetMRIsDisplayed("Y");
                        verFld.SetMRSeqNo(2);
                    }
                    if (!verFld.Save())
                    {
                        log.Log(Level.SEVERE, "Version Field not saved :: " + verFld.GetName());
                        Get_TrxName().Rollback();
                        return(Msg.GetMsg(GetCtx(), "FieldNotSaved") + " :: " + verFld.GetName());
                    }
                    else
                    {
                        SeqNo = SeqNo + 10;
                    }
                }
            }
            return("");
        }