Save value to table from run time control in MSD Axapta

Save value to table from run time control in Axapta

 void SaveAll()  
 {  
 int i;  
 int a;  
 int c;  
 boolean flg=true,flg1=true;  
 FormStringControl FormStr1;  
 FormStringControl formStringControl1;  
 FormGroupControl formGroupControl1;  
 str oldqid,tid,oldtxt;  
 FormTabControl formTabControl1;  
 FormTabPageControl formTabPageControl1;  
 FormBuildTabControl formBuildTabControl;  
 FormBuildGroupControl formBuildGroupControl;  
 FormBuildTabPageControl formBuildTabPageControl;  
 FormBuildStringControl formBuildStringControl;  
 _TestResult _testResult1;  
 str s,fcname;  
 formControl fc,fc1;  
 boolean f=false;  
 FormStringControl control = element.controlCallingMethod();  
 Integer yy,x;  
 int cnt=0,cnt1=0;  
 str id,AnsTxtGrid;  
 int t;  
 int rcnt,tmpcnt,rowid1;  
 str 10 AnsTxt;  
 str lable;  
 DictTable dictTable;  
 TableId tableID;  
 object formRunCaller;  
 TestId testId2;  
 ;  
 idrow=1;  
 rowid1=1;  
 //tmpcnt=16;  
 formRunCaller = element.args().caller();  
 testId2=formRunCaller.MethodA();  
 i = 1;  
 x=12000;  
 for(yy = x;yy <20000;yy++)  
  { fc = element.Control(yy);  
 if (fc)  
  {  
 while select * from _Question where (_Question.TestID==testid2) //order by RecId  
 {  
 while select * from tmpControlId where tmpControlId.ControlID==int2str(yy)  
  {  
 flg=false;  
  }  
 //select * from _TestResult; _TestResult.QId = _Question.QId;  
  _TestResult.Text= ""; a = 1;  
  while select * from answer where answer.GroupId == _Question.GroupId  
  {  
  if(_Question.ControlId == QuestionControlInputType::CheckBox)  
  {  
 }  
  if(_Question.ControlId == QuestionControlInputType::RadioButton)  
 {  
 }  
 a = a+1;  
  }  
  if(_Question.ControlId == QuestionControlInputType::Text)  
 {  
 // formGroupControl if(fc.name()=="QuestionStr")  
 {  
 // cnt=cnt+1;  
  // cnt1=i-12;  
 if (flg1==true)  
 {  
 fc = element.Control(yy);  
 //formBuildStringControl = formBuildTabPageControl.controlNum(i);  
 // lable =formBuildStringControl.name();  
  _TestResult.GroupId ="0";  
  _TestResult.RowId = "0";  
  // if(cnt==cnt1)  
 ///ss  
  while select _testResult1 where _testResult1.QId ==_Question.QId && _testResult1.TestId==testid2 {  
  flg=false;  
 }  
 if (flg==false)  
  {  
 flg=true;  
  }  
  else if(flg==true)  
  {  
 // _testResult.ItemID=inventTrans1.ItemId;  
 // _testResult.ItemName=InventTable::find(inventTrans1.ItemId).ItemName;  
 AnsTxt=fc.valueStr();  
  _TestResult1.Text=AnsTxt;  
 _TestResult1.QId = _Question.QId; _TestResult1.TestId=testId2;  
 //"1";  
 _TestResult1.GroupId ="0";  
 _TestResult1.RowId = "0";  
  _testResult1.insert();  
 tmpControlId.ControlID=int2str(yy);  
  tmpControlId.Qid=_question.QId;  
  tmpControlId.insert(); } flg=true;  
 } }  
  else  
  { flg1=true;  
 } ///ss  
 // _testResult.insert();  
 }  
 else if (_Question.ControlId == QuestionControlInputType::Grid)  
 {  
 // rcnt=rcnt+1  
 info(_testGridResult1.Row); fcname=fc.name(); if(substr(fc.name(),12,16)=="Col1")  
  {  
  idrow=rowid1;  
 _TestGridResult1.Column="1";  
  fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
  _TestGridResult1.Text=AnsTxtGrid;  
 _TestGridResult1.insert();  
  rowid1=idrow+1;  
 }  
  else if(substr(fc.name(),12,16)=="Col2")  
 { fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
  _TestGridResult1.Column="2";  
 _TestGridResult1.Text=AnsTxtGrid;  
 _TestGridResult1.insert();  
 }  
  else if(substr(fc.name(),12,16)=="Col3")  
  {  
  fc = element.Control(yy);  
  _TestGridResult1.Column="3";  
  AnsTxtGrid=fc.valueStr();  
 _TestGridResult1.Text=AnsTxtGrid;  
  _TestGridResult1.insert();  
 }  
 else if(substr(fc.name(),12,16)=="Col4")  
  {  
 fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
 _TestGridResult1.Column="4";  
 _TestGridResult1.Text=AnsTxtGrid;  
  _TestGridResult1.insert();  
  }  
 else if(substr(fc.name(),12,16)=="Col5")  
 {  
 fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
 _TestGridResult1.Column="5";  
  _TestGridResult1.Text=AnsTxtGrid;  
  _TestGridResult1.insert();  
  }  
 else if(substr(fc.name(),12,16)=="Col6")  
  {  
 fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
 _TestGridResult1.Column="6";  
 _TestGridResult1.Text=AnsTxtGrid;  
 _TestGridResult1.insert();  
  }  
  else if(substr(fc.name(),12,16)=="Col7")  
 {  
  fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
 _TestGridResult1.Column="7";  
 _TestGridResult1.Text=AnsTxtGrid;  
 _TestGridResult1.insert();  
  }  
 else if(substr(fc.name(),12,16)=="Col8")  
  {  
 fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
  _TestGridResult1.Column="8";  
  _TestGridResult1.Text=AnsTxtGrid;  
  _TestGridResult1.insert();  
  }  
 else if(substr(fc.name(),12,16)=="Col9")  
  { fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
  _TestGridResult1.Column="9";  
 _TestGridResult1.Text=AnsTxtGrid;  
 _TestGridResult1.insert();  
 }  
 else if(substr(fc.name(),12,16)=="Col10")  
  {  
 fc = element.Control(yy);  
  AnsTxtGrid=fc.valueStr();  
 _TestGridResult1.Column="10";  
 _TestGridResult1.Text=AnsTxtGrid;  
 _TestGridResult1.insert();  
 } //ss else if(substr(fc.name(),12,16)=="Col11")  
  { fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
 _TestGridResult1.Column="11";  
 _TestGridResult1.Text=AnsTxtGrid;  
 _TestGridResult1.insert();  
 }  
 else if(substr(fc.name(),12,16)=="Col12")  
 {  
 fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
 _TestGridResult1.Column="12";  
 _TestGridResult1.Text=AnsTxtGrid;  
  _TestGridResult1.insert();  
 }  
  else if(substr(fc.name(),12,16)=="Col13")  
 { fc = element.Control(yy);  
  AnsTxtGrid=fc.valueStr();  
 _TestGridResult1.Column="13";  
 _TestGridResult1.Text=AnsTxtGrid;  
 _TestGridResult1.insert();  
 } else if(substr(fc.name(),12,16)=="Col14")  
 {  
 fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
 _TestGridResult1.Column="14";  
  _TestGridResult1.Text=AnsTxtGrid;  
  _TestGridResult1.insert();  
 }  
 else if(substr(fc.name(),12,16)=="Col15")  
 { fc = element.Control(yy);  
  AnsTxtGrid=fc.valueStr();  
  _TestGridResult1.Column="15";  
  _TestGridResult1.Text=AnsTxtGrid;  
  _TestGridResult1.insert();  
  }  
 else if(substr(fc.name(),12,16)=="Col16")  
 { fc = element.Control(yy);  
 AnsTxtGrid=fc.valueStr();  
 _TestGridResult1.Column="16";  
  _TestGridResult1.Text=AnsTxtGrid;  
  _TestGridResult1.insert(); }  
 //rowid=rowid1; //ss i = i+1; } i = i+1;  
 }  
  }  
 }  
 info ("Record Saved Success");  
 }