How to create print forms dynamically

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Active user
1C:Professional
Rating: 4
Joined: Feb 8, 2013
Company: First BIT Middle East

Hello!

Is there are any possibility to put standard command of spreadsheet document into command bar using a code?

We create some spreadsheet documents in form through code, so we want to add "Page Setup" and "Preview" commands in command bar for those spreadsheet documents.

Example is PrintingDocuments Form from SL.

Thank you.

 
#2
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Hello, Pavel!

I think it is better to place those commands on the form in Designer mode and after this, change their visibility using the script.

 
#3
People who like this:0Yes/0No
Active user
1C:Professional
Rating: 4
Joined: Feb 8, 2013
Company: First BIT Middle East

Timofey Bugaevsky,

Hello,

I create spreadsheet document through script, so i can not do it in designer mode.

Because number of spreadsheets is dynamically. As an example i give you form from SL.

Is there any variants to solve it using a script?

Edited: Pavel Zhgulev - Jun 26, 2015 10:02 AM
 
#4
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Hello, Pavel!

Here is an example that I made for you on how to add a button on the form using the script:

Code
&AtClient
Procedure OnOpen(Cancel)
   AddButtonServer();
EndProcedure

&AtServer
Procedure AddButtonServer()
   
   Command = Commands.Add("Button");
   Command.Action = "ButtonAction";
   Command.Title = NStr("en = 'New button'");
   
   Item = Items.Add("FormButton", Type("FormButton"), ThisForm);
   Item.Type = FormButtonType.UsualButton;
   Item.CommandName = "Button";

EndProcedure

&AtClient
Procedure ButtonAction()
  ShowMessageBox(, NStr("en = 'Some action performed.'"));
EndProcedure

 
#5
People who like this:0Yes/0No
Active user
1C:Professional
Rating: 4
Joined: Feb 8, 2013
Company: First BIT Middle East

Timofey Bugaevsky,

Dear Timofey,

Thank you for response, but unfortunately it's not what i'm asking about.

I know how to create button using a script. My task is create buttons for predefined commands of spreadsheet document such as "Page Setup" or "Preview".

Thank you.

 
#6
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Pavel,

Unfortunately, adding a standard command in this way is not possible, you need to create a procedure that will execute analog of standard command and assign this action to the button.

For example:

Code
&AtClient
Procedure ButtonAction()
   SpreadsheetDocument.TopMargin = 5;
   SpreadsheetDocument.BottomMargin = 5;
   SpreadsheetDocument.LeftMargin = 5;
   SpreadsheetDocument.RightMargin = 5;
   SpreadsheetDocument.PageOrientation = PageOrientation.Landscape;
EndProcedure

Thus it is easier to create a separate form where place attribute of the SpreadsheetDocument type and you will have those buttons available automatically. Same as it was implemented in 1C:Subsystems Library 1.0.

You could open this form sending the generated print form as a parameter with your dynamic buttons.

 
#7
People who like this:0Yes/0No
Active user
1C:Professional
Rating: 4
Joined: Feb 8, 2013
Company: First BIT Middle East

Timofey Bugaevsky,

Does 1C have plans to add such functional in future releases of platform. I mean possibility to assign buttons added by using script with standart commands?

Thank you.

Edited: Pavel Zhgulev - Jun 29, 2015 05:39 AM
 
#8
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

This is not yet clear for me that this feature is useful.
Would you please explain use cases with examples?
If they will be reasonable, I could submit the feature request for you.

 
#9
People who like this:0Yes/0No
Active user
1C:Professional
Rating: 4
Joined: Feb 8, 2013
Company: First BIT Middle East

Timofey Bugaevsky,

As i wrote above, we are using SL provided by 1C and in case of common form "Printing Documents" where all spreadsheet documents generated dynamically using a script we want to put such commands as "Preview" and "Page Setup" in command bar because it will be useful and clear for users (more useful than in window bar at the top right side).

Why you recommend to do it like it was in SL v1.0 if current version of SL change vision for this mechanism?

So that's why i am asking about this feature because its a huge scope of work to create new PrintingDocuments form and in general we would like to use SL version and update it everytime.

Edited: Pavel Zhgulev - Jun 29, 2015 08:00 AM
 
#10
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Pavel,

I made a more complete example for you.

Here two buttons are added to the form programmatically, each of them generate an individual print form.

After this they are opened in an additional form where standard buttons for the spreadsheet document print preview and page setup are added.

Think, this covers your needs without an enhancement that you are asking for.

Code
&AtClient
Procedure OnOpen(Cancel)

   AddButtonServer("Invoice");
   AddButtonServer("Receipt");

EndProcedure

&AtServer
Procedure AddButtonServer(PrintFormName)
   
   CommandName = "Open" + PrintFormName;
   
   Command = Commands.Add(CommandName);
   Command.Action = CommandName;
   Command.Title = StrReplace(NStr("en = 'Open %1'"), "%1", PrintFormName);
   
   Item = Items.Add("Form" + CommandName, Type("FormButton"), ThisForm);
   Item.Type = FormButtonType.UsualButton;
   Item.CommandName = CommandName;

EndProcedure

&AtClient
Procedure OpenInvoice()

   PrintForm = GeneratePrintForm("Invoice");
   
   FormParameters = New Structure;
   FormParameters.Insert("PrintForm", PrintForm);
   
   OpenForm("DataProcessor.AddButtonTest.Form.PrintForm", FormParameters);
   
EndProcedure

&AtClient
Procedure OpenReceipt()

   PrintForm = GeneratePrintForm("Receipt");
   
   FormParameters = New Structure;
   FormParameters.Insert("PrintForm", PrintForm);
   
   OpenForm("DataProcessor.AddButtonTest.Form.PrintForm", FormParameters);
   
EndProcedure

&AtServer
Function GeneratePrintForm(TemplateName)

   Output = New SpreadsheetDocument;
   
   DataProcessorObject = FormAttributeToValue("Object");
   Template = DataProcessorObject.GetTemplate(TemplateName);
   
   Header = Template.GetArea("Header");
   Output.Put(Header);
   
   Row = Template.GetArea("Row");
   Total = 0;
   For I = 0 To 2 Do
      Price = 12;
      Quantity = 2;
      Row.Parameters.Item = NStr("en = 'Item'");
      Row.Parameters.Price = Price;
      Row.Parameters.Quantity = Quantity;
      Row.Parameters.Total = Price * Quantity;
      Total = Total + Row.Parameters.Total;
      Output.Put(Row);
   EndDo;
   
   Footer = Template.GetArea("Footer");
   Footer.Parameters.Total = Total;
   Output.Put(Footer);
   
   Return Output;
   
EndFunction

When the form is already opened, its content does not update. To have all print forms opened in separate windows you need to specify the difference between forms by setting the PrintForm parameter as the key parameter.
To display the spreadsheet document, simply assign it to the form attribute:
Code
&AtServer
Procedure OnCreateAtServer(Cancel, StandardProcessing)
   
   SpreadsheetDocument = Parameters.PrintForm;
   
EndProcedure


Please see the attached configuration dump.

Download 1Cv8.cf (13.03 KB)
 
#11
People who like this:0Yes/0No
Active user
1C:Professional
Rating: 4
Joined: Feb 8, 2013
Company: First BIT Middle East

Timofey Bugaevsky,

Unfortunately its not cover my needs.

In general i dont understand why you try to push me to create a new form for printforms if we already have a very functional form from SL, which provide much more functionality than you put in your example. And in case of your suggestion we will lose all this functionality. As i told we want to use all functionality from SL form and we need just to have a possibility to add those 2 standard commands for spreadsheet document.

 
#12
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Hello, Pavel.

I'm trying to solve your problem. If it is not urgent, I submitted the feature request for you. But I'm afraid it might take a long time for this feature to be developed. If it will be accepted.

 
#13
People who like this:0Yes/0No
Active user
1C:Professional
Rating: 4
Joined: Feb 8, 2013
Company: First BIT Middle East

Timofey Bugaevsky,

it's not very urgent.

In our vision this feature will help us to make our solution more friendly for users.

Please keep in touch regarding a decision of your developers.

Thank you.

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.