
function WF_Client()
{
  var obj=workflowUI;
  obj.ActType=document.workflowpostform.kolbit_hidden_acttype.value;//活动类型，发起者或处理者
  obj.DataSet;
  obj.GetParams=WF_Client_GetParams;//取参数
  obj.GetGenID=WF_Client_GetGenID;//取得唯一编号
  obj.Open=WF_Client_Open;//数据集打开
  obj.Apply=WF_Client_Apply;//数据集提交
  obj.OnApply;
  return obj;
}
//将参数Query转换成参数字符串
function WF_Client_GetParams()
{
	if(!this.DataSet)return;
    var count=this.DataSet.Fields.Count;
    var paramsstr="";
    for (var i=0;i<count;i++){
		paramsstr+=this.DataSet.Fields.Fieldx[i].FieldName; 
		paramsstr+="=";
		paramsstr+=this.DataSet.Fields.Fieldx[i].Value;
		paramsstr+=",";
    }
    return paramsstr;
}



function WF_Client_Open(){
    if(isInspect)return;
	if(this.DataSet){
	  var pkfield,pkvalue;
	  pkvalue = WF_Client_GetGenID();
	  //如果primarykey不为空，则以设置的primarykey打开
	  if(this.DataSet.PrimaryKey)
		  pkfield=this.DataSet.Fields.Field[this.DataSet.PrimaryKey];
	  //如果primarykey为空，则以第一个字段打开
	  else
		  pkfield=this.DataSet.Fields.Fieldx[0];
	  this.DataSet.Params.Clear();
	  //发起者
	  if(this.ActType=='start')
		  this.DataSet.Params.Add(new Param(pkvalue.Name,'','string'));
	  //中间活动
	  else
		  this.DataSet.Params.Add(new Param(pkvalue.Name,pkvalue,'string'));
	  this.DataSet.Open();
	  if(this.ActType=='start'){
		  this.DataSet.Append();
		  pkfield.Value=WF_Client_GetGenID();//set PrimaryKey=default value
	  }
	  else{
		if(this.DataSet.RecordCount==0)
		  alert("流程系统发生错误：没有找到对应的业务数据.");
	  }
	}
}
function WF_Client_Apply(){
  if(!this.DataSet)return;
  window.Exception = false;

  if(!confirm("确定提交吗？")) return false;
  try
  {
	  if(this.OnApply)
		  this.OnApply(this);
      this.DataSet.Apply();
	  //设置参数隐藏域
	  document.workflowpostform.kolbit_hidden_params.value=this.GetParams();
	  if(this.ActType=='start')
		  //设置ProcessID隐藏域
		  document.workflowpostform.kolbit_hidden_processID.value=WF_Client_GetGenID();
  }
  catch (e)
  {
      window.Exception = true;
	  alert("数据提交失败！"+e);
	  return;
  }
  window.Exception = true;
  document.workflowpostform.submit();
}
//取得唯一编号ID
function WF_Client_GetGenID()
{
   if(document.workflowpostform.kolbit_hidden_processID.value!=null){
    var genid = document.workflowpostform.kolbit_hidden_processID.value;
    return genid;
   }

}


