Save Data on TextEditorClose

Stimulsoft Reports.NET discussion
Post Reply
OC-Thorsten
Posts: 31
Joined: Thu Jul 16, 2015 12:22 pm

Save Data on TextEditorClose

Post by OC-Thorsten »

Hello,

we want to save text from an editable back to the database.
Therefore we call the TextEditorClose Event.
We found the table name and the field name, but we find no reference to the data row.
We need it for a where clause. In a List is the Field and TableName not unique.

Code: Select all

private void stiViewerControl1_TextEditorClose(object sender, Stimulsoft.Report.Viewer.StiTextEditorEventArgs e)
{
    var txt = string.Empty;
    var fieldName = string.Empty;
    var tableName = string.Empty;
    var id = string.Empty;
    if (e.TextBox is System.Windows.Forms.RichTextBox)
    {
        var rtfBox = (System.Windows.Forms.RichTextBox)e.TextBox;
        var stiRtfBox = (Stimulsoft.Report.Components.StiRichText)rpt.GetComponentByName(rtfBox.Name);
        txt= rtfBox.Rtf;
        fieldName = stiRtfBox.DataColumn.Substring(stiRtfBox.DataColumn.IndexOf('.') + 1);
        tableName = stiRtfBox.DataColumn.Substring(0, stiRtfBox.DataColumn.IndexOf('.'));               
    }
    else if (e.TextBox is System.Windows.Forms.TextBox)
    {
        var txtBox = (System.Windows.Forms.TextBox)e.TextBox;
        var stiBox = (Stimulsoft.Report.Components.StiRichText)rpt.GetComponentByName(txtBox.Name);
        txt = txtBox.Text;
        fieldName = stiBox.DataColumn.Substring(stiBox.DataColumn.IndexOf('.') + 1);
        tableName = stiBox.DataColumn.Substring(0, stiBox.DataColumn.IndexOf('.'));
    }
    if (fieldName != string.Empty && tableName != string.Empty)
    {
        DataAccess.ExecuteSql("UPDATE " + tableName + " set " + fieldName + " = '" + General.SqlFormatText(txt) + "' where id = " + id);
    }
}
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Save Data on TextEditorClose

Post by Alex K. »

Hello,

Please send us a sample with test data which reproduce the issue for analysis.
Also, as a way, please try to use the Tag property for storage "id" value for the editable text value.

Thank you.
OC-Thorsten
Posts: 31
Joined: Thu Jul 16, 2015 12:22 pm

Re: Save Data on TextEditorClose

Post by OC-Thorsten »

Hi Aleksey,

a sample is in this case difficult.

The idea with the tag is very useful. I set the Tag in the databand and in the TextControl.
But how can i read the tag from TextEditorClose?

Code: Select all

private void stiViewerControl1_TextEditorClose(object sender, Stimulsoft.Report.Viewer.StiTextEditorEventArgs e)
{
   var rtfBox = (System.Windows.Forms.RichTextBox)e.TextBox;
   var stiRtfBox = (Stimulsoft.Report.Components.StiRichText)rpt.GetComponentByName(rtfBox.Name);
rtfBox.Tag is null
stiRtfBox.Tag is null
stiRtfBox.TagValue is null
stiRtfBox.GetDataBand().TagValue is null

Any ideas?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Save Data on TextEditorClose

Post by Alex K. »

Hello,

We need some additional time for check the issue. We will try to prepare the sample for you.

Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Save Data on TextEditorClose

Post by Alex K. »

Hello,

Sorry for the delay with response.
As a way, in this case, you can use the following method before Open Text Editor and after Close:
((StiViewerControl)sender).Report.SaveEditableFields();
than compare changed values.

Thank you.
OC-Thorsten
Posts: 31
Joined: Thu Jul 16, 2015 12:22 pm

Re: Save Data on TextEditorClose

Post by OC-Thorsten »

Hello,

i can compare with this function, but how do I find out what the primary key is the record?
I've used the setTag Event in the report with: e.Value = quotes_orders_lines.id;
The SaveEditableFields() do not export the Tag. Here is my export:

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<StiSerializer version="1.02" type="Net" application="Editable Fields of Rendered Report">
  <Items isList="true" count="2">
    <Item1 Ref="1" type="Stimulsoft.Report.StiEditableItem" isKey="true">
      <ComponentName>RichText1</ComponentName>
      <PageIndex>0</PageIndex>
      <Position>1</Position>
      <TextValue>__LP___x005C_rtf1_x005C_ansi_x005C_ansicpg1252_x005C_deff0_x005C_deflang1031__LP___x005C_fonttbl__LP___x005C_f0_x005C_fnil_x005C_fcharset0_x0020_Arial_x003B___RP____RP___x000D__x000A___LP___x005C_colortbl_x0020__x003B__x005C_red0_x005C_green0_x005C_blue102_x003B___RP___x000D__x000A__x005C_viewkind4_x005C_uc1_x005C_pard_x005C_cf1_x005C_fs18_x0020_Beschreibung_x0020_4234_x005C_par_x000D__x000A___RP___x000D__x000A_</TextValue>
    </Item1>
    <Item2 Ref="2" type="Stimulsoft.Report.StiEditableItem" isKey="true">
      <ComponentName>RichText1</ComponentName>
      <PageIndex>0</PageIndex>
      <Position>2</Position>
      <TextValue>__LP__\rtf1\ansi\ansicpg1252\deff0\deflang1031__LP__\fonttbl__LP__\f0\fnil\fcharset0 Microsoft Sans Serif;__RP____RP__
\viewkind4\uc1\pard\f0\fs17\par
__RP__
 </TextValue>
    </Item2>
  </Items>
</StiSerializer>
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Save Data on TextEditorClose

Post by Alex K. »

Hello,

As a way, try to place the additional Text box with zero height or width and with the necessary value, set Editable to true.

Thank you.
OC-Thorsten
Posts: 31
Joined: Thu Jul 16, 2015 12:22 pm

Re: Save Data on TextEditorClose

Post by OC-Thorsten »

Hi,

I solved the problem. Here is my code for anyone interested.
The tag must be set in the editable.

Code: Select all

private void stiViewerControl1_TextEditorClose(object sender, Stimulsoft.Report.Viewer.StiTextEditorEventArgs e)
        {
            var txt = string.Empty;
            var fieldName = string.Empty;
            var tableName = string.Empty;
            var id = string.Empty;
            object internalControl = null;
            if (e.TextBox is System.Windows.Forms.RichTextBox)
            {
                var rtfBox = (System.Windows.Forms.RichTextBox)e.TextBox;
                var stiRtfBox = (Stimulsoft.Report.Components.StiRichText)rpt.GetComponentByName(rtfBox.Name);
                internalControl = stiRtfBox;
                txt = rtfBox.Rtf;
                fieldName = stiRtfBox.DataColumn.Substring(stiRtfBox.DataColumn.IndexOf('.') + 1);
                tableName = stiRtfBox.DataColumn.Substring(0, stiRtfBox.DataColumn.IndexOf('.'));
            }
            else if (e.TextBox is System.Windows.Forms.TextBox)
            {
                var txtBox = (System.Windows.Forms.TextBox)e.TextBox;
                var stiBox = (Stimulsoft.Report.Components.StiText)rpt.GetComponentByName(txtBox.Name);
                internalControl = stiBox;
                txt = txtBox.Text;
                fieldName = stiBox.Text.Value.Substring(stiBox.Text.Value.IndexOf('.') + 1);
                tableName = stiBox.Text.Value.Substring(0, stiBox.Text.Value.IndexOf('.'));
            }
            fieldName = fieldName.Replace("{", "").Replace("}", "");
            tableName = tableName.Replace("{", "").Replace("}", "");
            var stiViewerProperty = internalControl.GetType().GetProperty("ParentContainerControl", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var stiViewerControl = (Stimulsoft.Report.Viewer.StiViewerControl)stiViewerProperty.GetValue(internalControl, null);
            var stiTextEditorField = stiViewerControl.GetType().GetField("textEditor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var stiTextEditorControl = stiTextEditorField.GetValue(stiViewerControl);
            var componentProperty = stiTextEditorControl.GetType().GetProperty("Component", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
            var componentControl = (Stimulsoft.Report.Components.StiComponent)componentProperty.GetValue(stiTextEditorControl, null);
            if (componentControl.TagValue != null && componentControl.TagValue.ToString() != string.Empty)
                id = componentControl.TagValue.ToString();
            if (fieldName != string.Empty && tableName != string.Empty)
                DataAccess.ExecuteSql("UPDATE " + tableName + " set " + fieldName + " = '" + General.SqlFormatText(txt) + "' where id = " + id);
        }
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Save Data on TextEditorClose

Post by HighAley »

Hello.

Thank you for your solution.
Post Reply