Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Can I edit a existing row with a BizForm? View modes: 
User avatar
Member
Member
lbrenes-nacion - 5/8/2010 10:47:53 PM
   
Can I edit a existing row with a BizForm?
I wonder if is possible using a BizForm can edit an existing row?

Right now, I can show the row information on the BizForm but when you press the Send button, the system inserts a new row instead of update it.

Can I edit a existing row with a BizForm?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 5/11/2010 5:48:37 AM
   
RE:Can I edit a existing row with a BizForm?
Hi,


You can manage the Bizform data in CMS Desk -> Tools section: Managing bizforms.

Best regards,
Juraj Ondrus

User avatar
Member
Member
lbrenes-nacion - 5/11/2010 12:47:31 PM
   
RE:Can I edit a existing row with a BizForm?
Hi,

Let me explain you my requirement. On a BizForm, I want to permit a user has only one row. If the current user does not have a row, the BizForm has to render it empty. But, if he has a row, the BizForm has to show the information to allow him to update it.

Right now, I can show the row information on the BizForm. But, when the user click the send button, the system inserts a new one instead of update it.

What am I doing wrong?


This is my code:


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CMS.PortalControls;
using CMS.FormEngine;
using CMS.CMSHelper;
using CMS.GlobalHelper;
using CMS.FormControls;
using CMS.DataEngine;
using CMS.SettingsProvider;

public partial class CMSWebParts_nacioncom_LNBizForm: CMSAbstractWebPart
{

#region "Public properties"

/// <summary>
/// Gets or sets the form name of BizForm
/// </summary>
public string BizFormName
{
get
{
return ValidationHelper.GetString(GetValue("BizFormName"), "");
}
set
{
this.SetValue("BizFormName", value);
}
}


/// <summary>
/// Gets or sets the alternative form full name (ClassName.AlternativeFormName)
/// </summary>
public string AlternativeFormName
{
get
{
return ValidationHelper.GetString(GetValue("AlternativeFormName"), "");
}
set
{
this.SetValue("AlternativeFormName", value);
}
}


/// <summary>
/// Gets or sets the site name
/// </summary>
public string SiteName
{
get
{
return ValidationHelper.GetString(GetValue("SiteName"), "");
}
set
{
this.SetValue("SiteName", value);
}
}


/// <summary>
/// Gets or sets the value that indicates whether the WebPart use colon behind label
/// </summary>
public bool UseColonBehindLabel
{
get
{
return ValidationHelper.GetBoolean(GetValue("UseColonBehindLabel"), true);
}
set
{
this.SetValue("UseColonBehindLabel", value);
}
}


/// <summary>
/// Gets or sets the message which is displayed after validation failed
/// </summary>
public string ValidationErrorMessage
{
get
{
return ValidationHelper.GetString(this.GetValue("ValidationErrorMessage"), "");
}
set
{
this.SetValue("ValidationErrorMessage", value);
}
}

#endregion

/// <summary>
/// Content loaded event handler
/// </summary>
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
viewBiz.OnBeforeSave += new BizForm.OnBeforeSaveEventHandler(BizForm_OnBeforeSave);
}


/// <summary>
/// Reloads data for partial caching
/// </summary>
public override void ReloadData()
{
base.ReloadData();
SetupControl();
}


/// <summary>
/// Initializes the control properties
/// </summary>
protected void SetupControl()
{
try
{
if (!this.StopProcessing)
{
// Set BizForm properties
viewBiz.FormName = this.BizFormName;
viewBiz.SiteName = this.SiteName;
viewBiz.UseColonBehindLabel = this.UseColonBehindLabel;
viewBiz.AlternativeFormFullName = this.AlternativeFormName;
viewBiz.ValidationErrorMessage = this.ValidationErrorMessage;
}


if (!this.StopProcessing)
{
// Get BizForm definition
BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo(viewBiz.FormName, viewBiz.SiteName);

if (bfi != null)
{
// Get data type definition
DataClassInfo dci = DataClassInfoProvider.GetDataClass(bfi.FormClassID);
if (dci != null)
{
// Para buscar el registro asociado a este usuario
String WhereCondition = String.Format("UserName = '{0}'", CMSContext.CurrentUser.UserName);

// Get all bizform data
GeneralConnection genConn = ConnectionHelper.GetConnection();
DataSet ds = genConn.ExecuteQuery(dci.ClassName + ".selectall", null, WhereCondition);

if (!DataHelper.DataSourceIsEmpty(ds) && ds.Tables[0].Rows.Count == 1)
{
viewBiz.BasicForm.LoadData(ds.Tables[0].Rows[0]);
viewBiz.BasicForm.Mode = FormModeEnum.Update;
viewBiz.FormMode = FormModeEnum.Update;
}
}
}
}
}
catch (Exception ex)
{
CMS.EventLog.EventLogProvider eventLog = new CMS.EventLog.EventLogProvider();
eventLog.LogEvent("LNBizForm", "EXCEPTION", ex);
Visible = false;
}
}

/// <summary>
/// Agrega los datos del usuario actual al BizForm
/// </summary>
private void BizForm_OnBeforeSave()
{
viewBiz.BasicForm.DataRow["Username"] = CMSContext.CurrentUser.UserName;
}
}


P.D.
Sorry, I don't write or speak a good english.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 5/13/2010 3:27:45 AM
   
RE:Can I edit a existing row with a BizForm?
Hi,

According to this example -[url= devnet.kentico.com/docs/devguide/bizforms_api.htm]bizform API[/url] I do not see in your code where the new values are set (updated) into the existing values.

Best regards,
Juraj Ondrus