Using Microsoft Project Grid "MSPJGRID.ocs"

Y

Yasir Attiq Butt

Hi all



I am trying to use MSPJGrid.ocx which is used in project server 2003. and try to put the grid in a Web part and having the following problems but here is a desccritpin that i am doing.

In the web part code i am accessing the javascript code from wpResource directory in my IIS default web site. and registering the javascritp tag dynaminally. and accessing the functions in render web part method.



To Run the code copy the java script file in a text file and rename it as Hello.js.

Create a Folder with the name of the Web part in the WpResource Virtual Directory in IIS and Put this Hello.Js file to the folder.



Queston 1 : As per Microsoft Documentation we have to Call this Function in the Body Tag's onLoad. But how can we call this function using our code.

Issue 1: I had tried to call this function in a button click but it is giving me error that "MsPJGrid is Unexpeted" which means gird's object is unaccessable.

Issue 2: I had tried to call the Init function in my sharepoint site Body Tags onload function but it is giving me "MSPJgrid is unexpected" error.



can any oby please tell me what is going wrong in this code or how can i enter the function is the body tag dynamically.



Thanks



Yasir Attiq Butt



Web Part Code

//Class Level Variables

private const string HelloFileName = "Hello.js";

private const string HelloIncludeScriptKey = "myHelloIncludeScript";

private const string IncludeScriptFormat =

@"<script language=""{0}"" src=""{1}{2}""></script>";

private const string ByeByeIncludeScriptKey = "myByeByeIncludeScript";

private string text = defaultText;

public ScriptWP()

{

this.PreRender += new EventHandler(WebPart_ScriptWP_PreRender);

}



}

private void WebPart_ScriptWP_PreRender(object sender , System.EventArgs e )

{

RegisterCommonScript();

}

//Function which will register the linked file script and the

//embedded script

protected void RegisterCommonScript()

{

string location = null;

// Make sure that the script was not already added to the

//page.

if (!Page.IsClientScriptBlockRegistered(HelloIncludeScriptKey))

{

location = this.ClassResourcePath + "/";

// Create the client script block.

string includeScript =

String.Format(IncludeScriptFormat, "javascript", location, HelloFileName);

Page.RegisterClientScriptBlock(HelloIncludeScriptKey, includeScript);

}

// //Embedded Client Script

// if(!Page.IsClientScriptBlockRegistered(ByeByeIncludeScriptKey))

// Page.RegisterClientScriptBlock(ByeByeIncludeScriptKey,

// EmbeddedScriptFormat);

}

protected override void RenderWebPart(HtmlTextWriter output)

{

output.Write("<OBJECT ID='MSPJGrid' CLASSID='CLSID:5531B412-313F-4b42-9B48-0966457AA6FA' WIDTH=100% HEIGHT=220 VIEWASTEXT> </OBJECT>");

output.Write(

"<br><br>");

output.Write(

"<br><br><input class='ms-SPButton' value=\'Test Linked Script code\' type=button onclick='javascript:Init();'>");

}



Java Script File

=======================================

function Init() {

var adUseClient = 3;
var adInteger = 3;
var adDate = 7;
var adBoolean = 11;
var adVarWChar = 202;

var rs = new ActiveXObject("ADODB.Recordset");
rs.CursorLocation = adUseClient;

rs.Fields.Append("DocumentId", adInteger, -1, 0);
rs.Fields.Append("Document_Name", adVarWChar, -1, 0);
rs.Fields.Append("Auther_Name", adVarWChar, -1, 0);
rs.Fields.Append("Checked_Out_By", adVarWChar, -1, 0);
rs.Fields.Append("Start_Date", adDate, -1, 0);
rs.Fields.Append("End_Date", adDate, -1, 0);

rs.Open();

var fieldnames = new Array();

fieldnames[0] = "DocumentId";
fieldnames[1] = "Document_Name";
fieldnames[2] = "Auther_Name";
fieldnames[3] = "Checked_Out_By";
fieldnames[4] = "Start_Date"
fieldnames[5] = "End_Date"
var fieldvalues = new Array();

var dStart = new Date;
var dFinish = new Date;
dFinish.setDate( dFinish.getDate() + 5 );

fieldvalues[0] = 0;
fieldvalues[1] = "My First Document";
fieldvalues[2] = "Yasir Attiq Butt";
fieldvalues[3] = "Administrator";
fieldvalues[4] = "10/12/2003";
fieldvalues[5] = "10/16/2003";
rs.AddNew(fieldnames, fieldvalues);


fieldvalues[0] = 1;
fieldvalues[1] = "My Second Document";
fieldvalues[2] = "John Mouns";
fieldvalues[3] = "Yasir Attiq Butt"
fieldvalues[4] = "11/12/2003";
fieldvalues[5] = "12/16/2003";
rs.AddNew(fieldnames, fieldvalues);

fieldvalues[0] = 2;
fieldvalues[1] = "My Third Document";
fieldvalues[2] = "Yasir Attiq Butt";
fieldvalues[3] = "Noman Khan"
fieldvalues[4] = "8/22/2003";
fieldvalues[5] = "9/18/2003";
rs.AddNew(fieldnames, fieldvalues);


fieldvalues[0] = 3;
fieldvalues[1] = "Project Documents";
fieldvalues[2] = "Noman Khan";
fieldvalues[3] = "Noman Khan"
fieldvalues[4] = "11/22/2003";
fieldvalues[5] = "11/26/2003";
rs.AddNew(fieldnames, fieldvalues);
rs.Update();

MSPJGrid.Binding = rs;

MSPJGrid.FieldList = "#DocumentId[Document Number]<10>Document_Name[Document Name]<31>,Auther_Name[Auther Name],Checked_Out_By[Last Checkedout By],Start_Date[Start Date],End_Date[Finish Date]";
// MSPJGrid.Outlining = true;
MSPJGrid.SetGroupBy(3,"Auther_Name[Checked_Out_By]");
// MSPJGrid.GroupBy =strGroupBy;
MSPJGrid.GanttView = false;
MSPJGrid.Refresh();

}

//--------------------------------------------------------------------------
function ExpandTS_onclick()
{
MSPJGrid.SetCurrentCell(0,2,4);
MSPJGrid.ExpandTimeScale();
MSPJGrid.Refresh();
}
//--------------------------------------------------------------------------
function CollapseTS_onclick()
{
MSPJGrid.CollapseTimeScale();
MSPJGrid.Refresh();
}
//--------------------------------------------------------------------------
function Goto_onclick()
{
MSPJGrid.GotoSelectedTask();
MSPJGrid.Refresh();
}

//--------------------------------------------------------------------------
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top