C# .net windows application - Printing Text Box Values - c#-2.0

I have two text boxes when i input in these text boxes , by clicking the print button , it should directly printed with the connected printer. can anybody help me how should i do this?

The example below is a basic idea of using/inheriting the PrintDocument class:
using System.Drawing.Printing;
public class PrintDoc : PrintDocument
{
// there are other properties you can enter here
// for instance, page orientation, size, font, etc.
private string textout;
public string PrintText
{
get { return textout; }
set { textout = value; }
}
// you will also need to add any appropriate class ctor
// experiment with the PrintDocument class to learn more
}
Then from your form's button event, call something like:
public void PrintDocument()
{
//instance PrintDocument class
PrintDoc printer = new PrintDoc();
//set PrintText
printer.PrintText = myTextBox.Text;
printer.Print(); // very straightforward
}

Related

Change invoice pdf file name dynamics d365

can someone help me how to change the file name of a invoice ?
WHen I export a pdf file from screen it always saves as 'show invoice' and in pdf its psaprojinvoice.myprecisiondesign. But I want that there is Invoice num.
Where might be the problem here?
class ProjInvoiceControllerSZM extends PSAProjAndContractInvoiceController
{
public static ProjInvoiceControllerSZM construct()
{
return new ProjInvoiceControllerSZM();
}
public static void main(Args _args)
{
SrsReportRunController formLetterController = ProjInvoiceControllerSZM::construct();
ProjInvoiceControllerSZM controller = formLetterController;
srsPrintDestinationSettings srsPrintDestinationSettings;
controller.initArgs(_args);
Controller.parmReportName(ssrsReportStr(PSAProjInvoiceSZM, PrecisionDesign1));
PSAProjInvoiceContract rdpContract = new PSAProjInvoiceContract();
SRSPrintDestinationSettings settings;
// Define report and report design to use
controller.parmReportName(ssrsReportStr(PSAProjInvoiceSZM, PrecisionDesign1));
// Use execution mode appropriate to your situation
controller.parmExecutionMode(SysOperationExecutionMode::ScheduledBatch);
// Suppress report dialog
controller.parmShowDialog(false);
// Explicitly provide all required parameters
// rdpContract.parmReportStateDate(systemDateGet());
controller.parmReportContract().parmRdpContract(rdpContract);
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.fileName('Invoice.pdf');
// Execute the report
// controller.startOperation();
formLetterController.startOperation();
}
protected void outputReport()
{
SRSCatalogItemName reportDesign;
reportDesign = ssrsReportStr(PSAProjInvoiceSZM,PrecisionDesign1);
this.parmReportName(reportDesign);
this.parmReportContract().parmReportName(reportDesign);
formletterReport.parmReportRun().settingDetail().parmReportFormatName(reportDesign);
super();
}
}

MVVM Light TextView two-way binding in Xamarin (Android)

Has anyone successfully implemented a two-way binding on a TextView with MVVM Light? Two-way works perfectly fine with EditView, but the moment I try two-way binding with TextView - only one way binding works. Does anyone have any insight as to why, please?
View Model:
private string _someField;
public string SomeField
{
get { return _someField; }
set { Set(ref _someField, value); }
}
View:
private EditText _editableText;
public EditText EditableText;
{
get { return _editableTex ?? (_editableTex = FindViewById<EditText>(Resource.Id.editText1)); }
}
private TextView _simpleText
public TextView SimpleText
{
get { return _simpleText ?? (_simpleText = FindViewById<TextView>(Resource.Id.textDateDisplay)); }
}
protected override void OnCreate(Bundle savedInstanceState)
{
bindings.Add(this.SetBinding(() => vm.SomeField, () => EditableText.Text, BindingMode.TwoWay));
bindings.Add(this.SetBinding(() => vm.SomeField, () => SimpleText.Text, BindingMode.TwoWay));
}
No errors are thrown. But when I change (in code) of the View the text of the EditableText (EditableText.Text="asdf";) the corresponding set { Set(ref _someField, value); } triggers in the VewModel. It also triggers, naturally, if I just type in the EditText widget.
However, when I change (in code) the text property of the SimpleText (SimpleText.Text="2145";) it does not trigger the corresponding set.
Does anyone know why?
Thank you very much for help,
mike
You can't set a two-way binding with TextViews, because they doesn't allow input by user.
When you are using MVVM pattern you should never update the view. You should update the bound model property. So you should replace SimpleText.Text = "2145"; with vm.SomeField = "2145";.

How to print a view in MVC with out showing printer options screen

I have a view which contains few tables and it has some dynamic data.
I need to print this view up on clicking some button.
for ex:
I have following method in my controller
[HttpPost]
public ActionResult SomeMethod(Someparameter)
{
if(someclass.somemethod())
//if the above method returns true I need a print function here to print my view
}
I need this print function to be handled in C#,unlike js print().
And the more challenging is I dont want to display the print options to user and user is not aware of printing.
Print function should take configurable printer options and print directly.
Any help?
Thanks in advance.
EDIT:
i got the following code:
using System.Drawing;
using System.Drawing.Printing;
public void Print()
{
var doc = new PrintDocument();
doc.PrinterSettings.PrinterName = "\\\\deployment-machine-name\\share-name";
doc.PrintPage += new PrintPageEventHandler(ProvideContent);
doc.Print();
}
public void ProvideContent(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString(
"Hello world",
new Font("Arial", 12),
Brushes.Black,
e.MarginBounds.Left,
e.MarginBounds.Top);
}
where it takes the printer name and prints the required with out showing printer settings window.
But the problem is I want to print a view(in the above code,it prints a string value).

Validation icon not shown in Table fields

When I enter edit mode of my Table, I want the data validation exclamation mark icon (!) to be shown as soon as the user goes out of bounds of any of the validation constraints.
First, a couple of notes:
I'm using Vaadin 7, so the Bean Validation addon sadly won't work.
The data validation works as intended.
Now, I have a perfectly working table for which I am using a BeanItemContainer to keep my Person beans inside.
The code for the table and the TableFieldFactory looks something like this:
table.setContainerDataSource(buildContainer());
table.setTableFieldFactory(new TableFieldFactory() {
#Override
public Field createField(Container container, Object itemId, Object propertyId, Component uiContext) {
TextField field = (TextField) DefaultFieldFactory.get().createField(container, itemId, propertyId,
uiContext);
field.setImmediate(true);
if (propertyId.equals("firstName")) {
field.addValidator(new BeanValidator(Person.class, "firstName"));
}
return field;
}
});
The Person bean looks as follows:
public class Person {
#Size(min = 5, max = 50)
private String firstName;
... setters + getters...
}
The problem is that when I type something in the firstName field and then press enter or blur/unfocus that field, no indication whatsoever of error is shown. I have to mouseover the field to see that something is wrong.
My question is two folded...
How do I get the exclamation mark icon to appear when the field is
invalid? (This works for a normal TextField that is not in a Table)
Is there a way to get an immediate response from the invalid field
(show the icon) (i.e. immediately after you type under 5 chars,
without having to press enter or blur/unfocus the field in
question).
Would be great if I could have both questions answered! =)
Thanks in advance!
The Caption, Required Indicator (the red asterisk) and - most importantly here - Error Indicator (exclamation mark) are actually provided by the layouts containing the component, not the component themselves. When editable components are displayed in a table, they are displayed without a layout - that's why no error indicator is displayed.
If I were trying to square this circle, I would look at creating a CustomField as a wrapper for the editable field - and within that CustomField display an error indicator when the wrapped/delegate field becomes invalid. I've not tried this - I've not used editable fields in a table at all - but should be fairly easy to do.
Add a TextChangeListener to the field in FieldFactory, and call field.validate() in the listener. Note, though, that field.getValue() value is not normally changed until blur/unfocus, ergo the validator will be validating the old value - unless you do field.setValue(event.getText()) in the listener. See this post on the Vaadin forum for more details.
This is the sort of thing I meant for a validating wrapper - not tried using it. You'll see initComponent simply returns the field inside a FormLayout, which should give you the icon(s) you're seeking. (You may need to delegate more methods from ValidatingWrapper to delegate than I have- but quick look suggests this may be enough.)
You'd then wrap the field in your tableFieldFactory (second code block)
public class ValidatingWrapper<T> extends CustomField<T> {
private static final long serialVersionUID = 9208404294767862319L;
protected Field<T> delegate;
public ValidatingWrapper(final Field<T> delegate) {
this.delegate = delegate;
if (delegate instanceof TextField) {
final TextField textField = (TextField) delegate;
textField.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.TIMEOUT);
textField.setTextChangeTimeout(200);
textField.addTextChangeListener(new FieldEvents.TextChangeListener() {
#Override
public void textChange(FieldEvents.TextChangeEvent event) {
textField.setValue(event.getText());
textField.validate();
}
});
}
}
#Override
public Class<? extends T> getType() {
return delegate.getType();
}
#Override
protected Component initContent() {
return new FormLayout(delegate);
}
#Override
public Property getPropertyDataSource() {
return delegate.getPropertyDataSource();
}
#Override
public void setPropertyDataSource(Property newDataSource) {
delegate.setPropertyDataSource(newDataSource);
}
}
table.setContainerDataSource(buildContainer());
table.setTableFieldFactory(new TableFieldFactory() {
#Override
public Field createField(Container container, Object itemId, Object propertyId, Component uiContext) {
TextField field = (TextField) DefaultFieldFactory.get().createField(container, itemId, propertyId,
uiContext);
field.setImmediate(true);
if (propertyId.equals("firstName")) {
field.addValidator(new BeanValidator(Person.class, "firstName"));
}
return ValidatingWrapper(field);
}
});

How to get input text into the listfield of autocompletefield in blackberry?

I want to make something like the contact selection in OS 5.0 while composing message
For that I have made an autocompletefield with contacts as datasource. Now I want to add the user input, that is what he types into the drop down list which appears in autocompletefield so that if the contact is not available in the phonebook he can use the number.
Check this link: How to get the selected item as String in a Blackberry AutoCompleteField?
public void onSelect(Object selection, int type) {
super.onSelect(selection, type);
if(selection != null) {
String selectionAsString = getEditField().getText();
// Do whatever else you need to do with the String.
}
}

Resources