Username:   Password:  

test

/***********************************************************************************************************************
* Description      : PLUSGMOC class
*
*					 * This class generates the TB autonumbering and revisioning for Technical
*					 Bulletin application.
*
* Created For      :
* Modification Log :
* -----------------------------------------------------------------------------------------------
* Date                 Author                       Description
* -----------------------------------------------------------------------------------------------
* 20/04/2010           Infosys       				Initial Version
**************************************************************************************************************************/
 
//WORKORDER Package
package com.custom.app.workorder;
 
//JAVA Imports
import java.rmi.RemoteException;
import psdi.mbo.MboSet;
import psdi.security.UserInfo;
import psdi.util.BidiUtils;
import psdi.util.MXException;
import psdi.util.MXApplicationException;
import java.util.Calendar;
import java.util.Date;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.mbo.MboConstants;
import com.custom.app.workorder.PlusGMOCRequest;
import java.text.DateFormat;
//Extending OOB PlusGMOC
public class PlusGMOC extends psdi.plusg.app.workorder.PlusGMOC
implements  com.custom.app.workorder.PlusGMOCRemote
{
	//Constructor
	public PlusGMOC(MboSet mboset)
	throws MXException, RemoteException
	{
		//Calling super
		super(mboset);
	}
 
  	public void init() throws MXException
  	{
 
		System.out.println("PlusGMOC :: init() :: Inside init method");
		super.init();
		try
		{
			  System.out.println("PlusGMOC :: init() :: Application Name "+getThisMboSet().getApp());
			  System.out.println("PlusGMOC :: init() :: WONUM "+getString("WONUM"));
		}
		catch (RemoteException e)
		{
			  // TODO Auto-generated catch block
			  e.printStackTrace();
		}
  	}
 
 
	/*-----------------------------------------------------------------------------------------------------------------------------------
	 * Description       :  Overridden the add method of the PLUSGMOC Mbo.
	 * Parameters        :  NA
	 * Return Value      :  void
	 * Modification Log  :
	 * ----------------------------------------------------------------------------------------------------------------------------------
	 * Date          Author            Description
	 * ----------------------------------------------------------------------------------------------------------------------------------
	 * 25/03/2010	 Infosys  	Generating the autonumbering and setting the WONUM and BHITBNUMBER
	 *							attribute accordingly.(Have suppressed it from configuration to avoid wastage.)
	 *
	 * 25/03/2010	 Infosys    TB numbering revision logic to generate subsequent TBs to have revision #(B,C, and so on)
	 *							where I, O, Q, S, V, X,Z should never be used for revisions and Upon exhaustion of the alphabet,
	 *							revisions should be identified by AA, AB, AC, etc, then BA, BB, etc.and so on.
	 *
	 * -----------------------------------------------------------------------------------------------------------------------------------
	 */
	public void add() throws MXException,RemoteException
	{
		//Calling super
		super.add();
		System.out.println("PlusGMOC :: add() :: Application Name : "+getThisMboSet().getApp());
		String str_appName = getThisMboSet().getApp();
		String strWoClass = getString("WOCLASS");
		System.out.println("PlusGMOC :: add() :: WOCLASS : "+strWoClass);
 
		if ("PLUSGMOC".equals(str_appName) || str_appName==null)
		{
			System.out.println("PlusGMOC :: add() :: It's Not a TB application.");
			this.generateAutoKey();
			System.out.println("PlusGMOC :: add() :: WONUM = "+getString("WONUM"));
		}
		else if (str_appName.equals("BHITB"))
		{
			if (((PlusGMOCSet) getThisMboSet()).getIsRevisedTB())
			{
				String str_revisedTB=null;
				String strPreWoNum = ((PlusGMOCSet) getThisMboSet()).getPreWoNum();
				if(strPreWoNum.length()!=0)
				{
					int Length = strPreWoNum.length();
					System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Length is " +Length);
					char character = strPreWoNum.charAt(Length-1);
					System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Last char is " +character);
 
					//Check if the last character is a numeric value.If a numeric value then
					//  append the revision number with -A.
					if (character == '0' || character == '1' || character == '2' || character == '3' || character == '4' || character == '5' || character == '6' || character == '7' || character == '8' || character == '9')
					{
						int i = 65;
						str_revisedTB = strPreWoNum+"-"+(char)i;
					}
					else
					{
						// If the last character is not a numeric value then depending on the number
						//  of characters after last -,calculate the revision number.
						int LastIndex = strPreWoNum.lastIndexOf("-");
						System.out.println("PlusGMOC :: add() ::  Is Revise TB :: LastIndex is " +LastIndex);
						System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Last alphabets after - is "+strPreWoNum.substring(LastIndex, Length));
 
						// If the last character in the revision number is -Y then the new number is -AA.
						// e.g.if WONUM = TB-1000-Y then the next revision number is TB-1000-AA.
						if(strPreWoNum.substring(LastIndex, Length-1).length() == 1 && strPreWoNum.substring(LastIndex, Length).equalsIgnoreCase("-Y") )
						{
							System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Last alphabet is " +strPreWoNum.substring(LastIndex+1, Length));
							character = (char)65;
							System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +(strPreWoNum.substring(0, Length-1)+character+character));
							str_revisedTB = strPreWoNum.substring(0, Length-1)+character+character;
						}
						// If the last character in the revision number is not -Y then the new number is the next increment.
						// e.g.if WONUM = TB-1000-B then the new revision number is TB-1000-C.
						if(strPreWoNum.substring(LastIndex, Length-1).length() == 1 && !strPreWoNum.substring(LastIndex, Length).equalsIgnoreCase("-Y") )
						{
							System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Last alphabet is " +strPreWoNum.substring(LastIndex+1, Length));
							int i = (int)character;
							System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Last alphabet's ASCII is " +i);
							i = i+1;
 
							// The revision number should not contain following alphabets:
							// I, O, Q, S, V, X, Z
							// If the revision number contains H then the new number should skip I.
							// e.g.if WONUM = TB-1000-H then the new revision number is TB-1000-J.
							if((i != 73) && (i != 79) && (i != 81) && (i != 83) && (i != 86) && (i != 88) && (i != 90))
							{
								character = (char)i;
								System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +(strPreWoNum.substring(0, Length-1)+character));
								str_revisedTB = strPreWoNum.substring(0, Length-1)+character;
							}
							else
							{
								character = (char)(i+1);
								System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Else New WONUM is " +(strPreWoNum.substring(0, Length-1)+character));
								str_revisedTB = strPreWoNum.substring(0, Length-1)+character;
							}
						}
 
						// If the last character in the revision number is not -YY then the new number is the next increment.
						// e.g.if WONUM = TB-1000-AB then the new revision number is TB-1000-AC.
						if(strPreWoNum.substring(LastIndex, Length-1).length() == 2 && !strPreWoNum.substring(LastIndex, Length).equalsIgnoreCase("-YY"))
						{
							if(!strPreWoNum.substring(LastIndex+2, Length).equalsIgnoreCase("Y"))
							{
								int i = (int)character;
								i = i+1;
 
								// The revision number should not contain following alphabets:
								// I, O, Q, S, V, X, Z
								// If the revision number contains H then the new number should skip I.
								// e.g.if WONUM = TB-1000-H then the new revision number is TB-1000-J.
								if((i != 73) && (i != 79) && (i != 81) && (i != 83) && (i != 86) && (i != 88) && (i != 90))
								{
									character = (char)i;
									System.out.println("PlusGMOC :: add() ::  Is Revise TB :: character is " +character);
									System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +(strPreWoNum.substring(0, Length-1)+character));
									str_revisedTB = strPreWoNum.substring(0, Length-1)+character;
								}
								else
								{
									character = (char)(i+1);
									System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +(strPreWoNum.substring(0, Length-1)+character));
									str_revisedTB = strPreWoNum.substring(0, Length-1)+character;
								}
							}
							else
							{
								// If the revision number contains Y in the end then the new number increments.
								// e.g.if WONUM = TB-1000-AY then the new revision number is TB-1000-BA.
								character = strPreWoNum.charAt(Length-2);
								System.out.println("PlusGMOC :: add() ::  Is Revise TB :: First char is "+character);
								int i = (int)character;
								i = i+1;
 
								// The revision number should not contain following alphabets:
								// I, O, Q, S, V, X, Z
								// If the revision number contains H then the new number should skip I.
								// e.g.if WONUM = TB-1000-H then the new revision number is TB-1000-J.
								if((i != 73) && (i != 79) && (i != 81) && (i != 83) && (i != 86) && (i != 88) && (i != 90))
								{
									character = (char)i;
									System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +strPreWoNum.substring(0, Length-2)+character+(char)65);
									str_revisedTB = strPreWoNum.substring(0, Length-2)+character+(char)65;
								}
								else
								{
									character = (char)(i+1);
									System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +strPreWoNum.substring(0, Length-2)+character+(char)65);
									str_revisedTB = strPreWoNum.substring(0, Length-2)+character+(char)65;
								}
							}
						}
						if(strPreWoNum.endsWith("-YY"))
						{
							System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Cannot create ReviseTB after "+strPreWoNum);
							throw new MXApplicationException("TB","BHIReviseTB");
						}
					}
				}
				//Set the revised TB Number generated on BHITBNUMBER and WONUM
				System.out.println("PlusGMOC :: add() ::  Is Revise TB :: str_revisedTB =="+str_revisedTB);
				this.setValue("BHITBNUMBER",str_revisedTB);
				setValue("WONUM",getString("BHITBNUMBER"));
				String strReportedBy1 = getString("REPORTEDBY");
				System.out.println("PlusGMOC :: add() :: strReportedBy1 = "+strReportedBy1);
				setValue("OWNER",strReportedBy1);
				setValue("WOCLASS","TB");
				System.out.println("PlusGMOC :: add() ::  Is Revise TB :: WONUM= "+getString("WONUM"));
				getThisMboSet().setApp("BHITB");
				System.out.println("PlusGMOC :: add() ::  Application Name ="+getThisMboSet().getApp());
				this.changeStatus("DRAFT",null,"Draft", 11L);
				System.out.println("PlusGMOC :: add() :: STATUS = "+getString("STATUS"));
			}
			else
			{
				this.getMboValue("BHITBNUMBER").autoKey();
				String str_woNum= getString("BHITBNUMBER")+"-A";
				setValue("BHITBNUMBER",str_woNum);
				setValue("WONUM",getString("BHITBNUMBER"));
				String strReportedBy = getString("REPORTEDBY");
				System.out.println("PlusGMOC :: add() :: strReportedBy = "+strReportedBy);
				setValue("OWNER",strReportedBy);
				setValue("WOCLASS","TB");
 
				System.out.println("PlusGMOC :: add() :: WONUM = "+getString("WONUM"));
				System.out.println("PlusGMOC :: add() :: BEFORE STATUS = "+getString("STATUS"));
				this.changeStatus("DRAFT",null,"Draft", 11L);
				System.out.println("PlusGMOC :: add() :: STATUS = "+getString("STATUS"));
			}
		}
 	}
	/*------------------------------------------------------------------------------------------------------------
	 * Description       :  Created new method createTB in PLUSGMOC Mbo.
	 * Parameters        :  String
	 * Return Value      :  MboRemote
	 * Modification Log  :
	 * -----------------------------------------------------------------------------------------------------------
	 * Date          Author            Description
	 * -----------------------------------------------------------------------------------------------------------
	 * 10/05/2010	 Infosys/Jai      This method is invoked while creating a revise TB
	 * -----------------------------------------------------------------------------------------------------------
	 */
	public MboRemote createTB(String s)
	throws MXException, RemoteException
	{
		System.out.println("PlusGMOC :: createTB()");
		MboSet mboset = (MboSet)(MboSet)getMboServer().getMboSet(s, getUserInfo());
		System.out.println("PlusGMOC :: createTB() :: mboset = "+mboset);
 
		mboset.setInsertSite(getString("siteid"));
		mboset.setInsertOrg(getString("orgid"));
 
		//Set the Application name
		mboset.setApp("BHITB");
		System.out.println("PlusGMOCRequest :: createTB() :: app name = "+getThisMboSet().getApp());
		System.out.println("PlusGMOC :: createTB() :: current wonum = "+getString("WONUM"));
 
		//If the Application is TB, then set the previous WONUM and isRevisedTB to true on current MBOSet
		if ("BHITB".equals(getThisMboSet().getApp()))
		{
			((PlusGMOCSet) mboset).setPreWoNum(getString("WONUM"));
			((PlusGMOCSet) mboset).setIsRevisedTB(true);
		}
		((PlusGMOCSet) mboset).setWoClass("TB");
		MboRemote mboremote = mboset.add();
		System.out.println("PlusGMOC :: Revised TB # = "+mboremote.getString("WONUM"));
		System.out.println("PlusGMOC :: createTB() :: 1");
		UserInfo userinfo = mboremote.getUserInfo();
		userinfo.setInteractive(false);
		mboremote.setValue("origrecordid", getString("wonum"), 11L);
		System.out.println("PlusGMOC :: createTB() :: origrecordid = "+mboremote.getString("ORIGRECORDID"));
		mboremote.setValue("origrecordclass", getString("woclass"), 11L);
		mboremote.setValue("origwoid", getString("wonum"), 2L);
		if(!mboremote.isNull("origrecordid"))
		{
			mboremote.setValue("reportedby", userinfo.getPersonId(), 2L);
		}
		System.out.println("PlusGMOC :: createTB() :: 2");
		doClassificationCreateWOViews(mboremote);
		System.out.println("PlusGMOC :: createTB() :: 3");
		setValue("hasfollowupwork", true, 2L);
		mboremote.setValueNull("onbehalfof");
		mboremote.setValue("plusgpmnumref", getString("plusgpmnumref"), 11L);
		mboremote.setValue("jpnum", getString("jpnum"), 11L);
		if(!mboremote.getString("assetnum").equalsIgnoreCase("") && !mboremote.getString("location").equalsIgnoreCase(""))
		{
			if(!getString("assetnum").equalsIgnoreCase(mboremote.getString("assetnum")))
			{
				mboremote.setValue("assetnum", getString("assetnum"), 2L);
			}
			if(!getString("location").equalsIgnoreCase(mboremote.getString("location")))
			{
				mboremote.setValue("location", getString("location"), 2L);
			}
		}
		userinfo.setInteractive(true);
		System.out.println("PlusGMOC :: createTB() :: Creating related record.");
		MboSetRemote mbosetremote = mboremote.getMboSet("RELATEDRECORD");
		MboRemote mboremote1 = mbosetremote.add();
		mboremote1.setValue("relatedreckey", getString("wonum"), 11L);
		System.out.println("PlusGMOC :: createTB() :: related record key = "+mboremote1.getString("RELATEDRECKEY"));
		mboremote1.setValue("relatedrecclass", getString("woclass"), 11L);
		mboremote1.setValue("relatedrecsiteid", getString("siteid"), 11L);
		mboremote1.setValue("relatedrecorgid", getString("orgid"), 11L);
		mboremote1.setValue("relatetype", getTranslator().toExternalDefaultValue
			
			

MySQL table optimize table cron job

<?php
/**
 * Runs the query "OPTIMIZE TABLE" on each database and table
 * 
 * @author Marc Steinert <marc@bithub.net>
 * @version $Id$
 * @link http://bithub.net/
 */
 
// MySQL Data
define('SQL_HOST', '127.0.0.1');
define('SQL_USER', 'root');
define('SQL_PASS', 'xxxxxx');
 
 
$link = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS);
$allDbsResult = mysql_query("SHOW DATABASES", $link);
 
while(($databaseRow = mysql_fetch_assoc($allDbsResult))) {
	// Select the found database
	mysql_select_db($databaseRow['Database'], $link);
 
	$alltablesResult = mysql_query("SHOW TABLES", $link);
 
	while (($table = mysql_fetch_assoc($alltablesResult))) {
		foreach ($table as $db => $tablename) {
 
			echo "OPTIMIZE TABLE '".$tablename."'";
 
			if (mysql_query("OPTIMIZE TABLE ".$tablename.""))
			{
				echo " - done'n";
			}
			else
			{
				echo " - failed'n";
			}
	   }
	}
}
die;
 

This script connects to a MySQL server and runs the command "optimize table" on each database and table on the MySQL server .

Tags

MySQL PHP optimize table

Read File Permissions in C#

String fullPath = Path.GetFullPathInternal(path);
// For security check, path should be resolved to an absolute path.
new System.Security.Permissions.FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullPath }, false, false ).Demand(); 

Tags

permissions files c#

Simple PHP templating engine with extract

<?php
 
class Template {
 
	private $_bound = array();
 
	private $_file;
 
 
    public function __construct($tplName, $tplDir = '' ) {
        // Define template directory
        if ($tplDir == '' && defined('TEMPLATE_DIR')) {
            $tplDir = TEMPLATE_DIR;
		}
 
        // Add trailing slash
        if (substr( $tplDir, strlen($tplDir) - 1, 1 ) != '/' && $tplDir != '' ) {
            $tplDir .= '/';
		}
 
        // Get templates contents
        $this->_file = $tplDir.$tplName;
    }
 
    public function set($name, $value = null) {
        // Bind associative array
        if(is_array($name)) {
			foreach ($name as $key => $value) {
				$this->_bound[$key] = $value;
            }
        } else {
			// If instance of self then save as reference
            if ($value instanceof self) {
				$this->_bound[$name] = &$value;
			} else {
				$this->_bound[$name] = $value;
			}
        }
    }
 
    public function parse() {
        // Parse templates and bind to variables
        foreach ($this->_bound as $key => $value) {
            if ($value instanceof self) {
				$value = $value->parse();
            }
 
            $$key = $value;
        }
 
        // Start outputbuffering
        ob_start();
 
        // Include template
        if (file_exists($this->_file)) {
            require($this->_file);
        } else {
            return false;
		}
 
        // Stop buffering and get its contents
        return ob_get_clean();
    }
}

Simple template engine in PHP, which uses extract to set variables in the output. Example: $pTemplate = new Template('template.php'); $pTemplate->set('title', 'Here is a title'); echo $pTemplate->parse(); Contents of template.php: <title><?php echo $title;?></title>

Tags

PHP template extract variables templating

Test if browser is Internet Explorer in Javascript

function isIE {
	var name = 'MSIE';
 
	var agent = navigator.userAgent.toLowerCase();  
 
	return (agent.indexOf(name.toLowerCase()) > - 1);
}

This function tests, if the browser that is viewing the site, is some version of the internet explorer

Tags

internet explorer javascript user agent

<< older