Showing posts with label Infopath. Show all posts
Showing posts with label Infopath. Show all posts

Sep 3, 2008

Data Validation in TextBox with Two Digits

In this example we are validating text box with two digits integer value only.
Follow the following steps:
(i) Double click on the textbox and press Data Validation button.
(ii) From popup window click on Add button.
(iii) Select does not match pattern from second dropdown list.
(iv) Click select a pattern from last dropdown list and a popupwindow will be displayed.









(v) Select your pattern from Standard patterns list.in this case select Custom pattern.

















(vi) In custom pattern put your custom pattern and press OK.
(vii) Give your messages in Screen Tip and message box.
(viii) Check the check box to show the message in browser.









(ix) Press Ok.

Add Code in Infopath Form.

First we install VSTA for write code in infopath.
How we install VSTA.

  1. Go to Control Panel | add/remove programs | Change office 2007 | Click on add or remove Features
  2. Go to Microsoft infopath option |.net programability support | .net programability support from .net 2.0 version
  3. right click on visual studio tools for applications | run from my computer
  4. click on continue and VSTA has been install

How we write the Code

  1. Go to Tool Menu | Form option | programming | language
  2. select Security and trust option | Full trust and check the option of sign this form template |Certificate | OK.
  3. Go to Tools menu | programming |Microsoft visual studion tools application.
  4. Copy and Paste the Code.


using Microsoft.Office.InfoPath;
using
System;
using
System.Windows.Forms;
using
System.Xml;
using
System.Xml.XPath;
using
mshtml;
using
System.Web;
using
System.Web.Services;
using
System.Web.Services.Protocols;
namespace
Publicutilities
{
public
partial class FormCode
{

//Make the object of webservices

Publicutilities.@in.disnic.services.PublicUtility_Services ObjService = new Publicutilities.@in.disnic.services.PublicUtility_Services();
// NOTE: The following procedure is required by Microsoft Office InfoPath.
// It can be modified using Microsoft Office InfoPath.
public
void InternalStartup()
{

((ButtonEvent)EventManager.ControlEvents["btnSubmit"]).Clicked += new ClickedEventHandler(btnSubmit_Clicked);
EventManager.FormEvents.Submit += new SubmitEventHandler(FormEvents_Submit);

}

///

/// Method to Submit UserData in CategoryData Table;For submitting Data we have Used a [webMethod]

/// that will accept 3 parameters as Array Object as AvailabilityStatus,ObjectDistanceCode,Code.

public void btnSubmit_Clicked(object sender, ClickedEventArgs e)
{
// Write your code here.
int
[] ObjectDistanceCode = new int[4];
XPathNavigator root = this.MainDataSource.CreateNavigator();
XPathNavigator field = root.SelectSingleNode("/my:myFields/my:CodeIH",

this.NamespaceManager);

if (field.Value != "")

ObjectDistanceCode[0] = Convert.ToInt16(field.Value);

XPathNavigator field2 = root.SelectSingleNode("/my:myFields/my:CodeNh",

this.NamespaceManager);

if (field2.Value != "")

ObjectDistanceCode[1] = Convert.ToInt16(field2.Value);

XPathNavigator field3 = root.SelectSingleNode("/my:myFields/my:CodeSh",

this.NamespaceManager);

if (field3.Value != "")

ObjectDistanceCode[2] = Convert.ToInt16(field3.Value);

XPathNavigator field4 = root.SelectSingleNode("/my:myFields/my:CodeMD",

this.NamespaceManager);

if (field4.Value != "")

ObjectDistanceCode[3] = Convert.ToInt16(field4.Value);

XPathNavigator field5 = root.SelectSingleNode("/my:myFields/my:CodeOD",

this.NamespaceManager);

//Define An Array to Store Avalability Status for CheckBoxes

int[] AvailabilityStatus = new int[4];

XPathNavigator Field1 = root.SelectSingleNode("/my:myFields/my:catIH",

this.NamespaceManager);

if (Field1.Value == "true")

AvailabilityStatus[0] = 1;

else

AvailabilityStatus[0] = 0;

XPathNavigator Field2 = root.SelectSingleNode("/my:myFields/my:CatNH",

this.NamespaceManager);

if (Field2.Value == "true")

AvailabilityStatus[1] = 1;

else

AvailabilityStatus[1] = 0;

XPathNavigator Field3 = root.SelectSingleNode("/my:myFields/my:CatSH",

this.NamespaceManager);

if (Field3.Value == "true")

AvailabilityStatus[2] = 1;

else

AvailabilityStatus[2] = 0;

XPathNavigator Field4 = root.SelectSingleNode("/my:myFields/my:CatMD",

this.NamespaceManager);

if (Field4.Value == "true")

AvailabilityStatus[3] = 1;

else

AvailabilityStatus[3] = 0;

//InsertDistanceData is a [web method] used to store user information.

ObjService.InsertDistanceData(ObjectDistanceCode, AvailabilityStatus);

}

public void FormEvents_Submit(object sender, SubmitEventArgs e)

{

// If the submit operation is successful, set

e.CancelableArgs.Cancel = false;

// Write your code here.

}

}

}


After writing the code publish the infopath form.u can check the following link.
if any infopath form have code then u can check the 2nd option of publishing.
Publish a Infopath Form

Save Infopath Data into Database.

1. Create a webservice in asp.net.

1. Click on new open in file menu and select website and then select asp.net we bservices.
2. Add a webmethod in .cs file.

[WebMethod]
public
void InsertVillage(int villageId,string CatA,string DDLA,string CatB,string DDLB)
{
cmd =
new SqlCommand("select * from Entry", con);
mydataset =
new DataSet();
myadapter =
new SqlDataAdapter(cmd);
myadapter.Fill(mydataset);
string
strsql = string.Empty;
strsql =
"insert into Entry values(" + villageId + ",'" + CatA + "','" + DDLA + "','" + CatB + "','" + DDLB + "')";
cmd.ExecuteNonQuery();
}

(ii) After binding all the controls double click the button through which you want to submit the data.Select Submit option from Action dropdown list.The page look likes:














Now click on Submit Options.. button.

(ii) Select Web service option from first dropdown list.If you have already added a data connection, you can choose from second dropdown list or click Add button to add a new data connection.The popup window looks like:
















(iii) Enter your web services address.













(iv) Select Submit data option.













(v)Choose the first option to submit data through web service.

Fill dropdown from the selection of another dropdown

(i) double click on dropdown list and select the listbox enteries.

There are three option.
(i) Enter listbox manually.
(ii) look up value int the form datasource.
(iii) look up value from external datasource.
when we select value from external data source then click on add button and select the create a new connection option.













and select Receive data and click on next button.
(iv) select the datasource.













After Selecting the webservice option click on next button.
(v)enter the webservice path













(vi) Select the method fromthe webservice.













(vii) if we want to fill the dropdown on pageload the we select the checkbox of automatically reterive data when page is open else uncheck the check box.













Note:
if we want to fill the drop down on selection of another then we uncheck the option of automatically.
(viii) after completing the above process we will select datasource from the DropDown.
(ix) click on the entries button and select the table from the datasource.



















Binding Checkbox in Infopath 2007

(i) Double click on checkbox and open the properties window.
(ii) Change the datatype from boolean to text.
(iii) Write false when value is cleared.
(iv) write true when value is checked.
















(v) Go to Datasource in design task and double click on checkbox and select the fx button.














(vi) Double click of fx button and click on select insert field or group.













vii) Select the datasource and select the value from the datasource.



















Create A New InfoPath 2007 Form

We can create or design a infopath form into 2 ways.
1. Using Form Template
2. Using Template Part
Note: If we Want to open a form in the browser then we will check the checkbox of enable browser compatible features.
1. Using Form Template

we can design a form in many ways.

(i) we can select blank form
(ii)we can select using webservices
(iii)using Database
(iv) using xml schema
(v) using Connection Library.

2. Using Template part

there are 2 ways to design a form in template part
(i) Blank form
(ii) using XML Schema
if we want to open the form in the browser then we will select the checkbox of browser compatible.

Design a form:
Drag and drop the control from the design task to the page.
There are different type of control in the design task.
  • TextBox
  • RichTextBox
  • Dropdownlist
  • ListBox
  • DatePicker
  • Checkbox
  • Option Button
  • Button
  • Section(Section is used as a container like panel control in asp.net)

Conditional Display Formatting of Control in Infopath Form

You can make a control Disable or Hide on the basis of value of other controls.
In this Exp. we make a dropdown list Disable if a check box is Checked.
(i) Double click the second dropdown list.Select Display tab and click Conditional Formatting.



















(ii) Click Add button from popup window.
(iii) From first dropdown list select the control/field on the basis of which you want to make the control disable.









(iv) Select appropriate condition from second dropdown list.










(v) From third dropdown list type the condition after selection of appropriate condition.
in this case select Type Text and type true in dropdown list.









Note: After selection of appropriate condition the dropdown list will appear blank.Type your condition.
(vi) Select the formatting condition from the given conditions and press OK.


How to publish a Infopath Form

We can publish a infopath to Sharepoint Library into 2 ways .
1. We can publish a infopath form into direct sharepoint library.Step by step to publish a form.
(i) Click the Publish option in file menu a new wizard will be open.Select the first option of the wizard i.e
To a sharepoint server with or without infopath Form services and click next.












(ii) Enter the location of Sharepoint Server for ex in our case Http://virtual2k3/disnic/Forms















When we click next then it ask the password to connect Sharepoint Server.In our case enter the password and then click ok and next.
(iii) Selct the Document type where we publish the form.There are 3 options.
(i) In Document library
(ii) In Site Content Type
(iii) Administrative Approved














In Our case we select the site content type and then click next.
(iv) There are two option if we want to create or modify the site content type.
(i) if we select the create a new content type and click on next then new screen will be displayed.














(ii) If we select Modify the site content type then the following screen will be displayed.














when we click on next button after both operation we will put the complete path of form where the form weill be displayed.














and then click next.

(v) Verify the Form information.









click on publish button

(vi) when we click on publish the infopath save the form in sharepoint.









and form will be saved.














after successfull completion of form we can open the form in browser.

2. First we Publish the form in anetwork location and then publish the form.Step by step to publish a form with code.
(1) When we clcik the publish option in File menu then select the option publish on a network location.














After selecting the network location we will click on next button.
(ii) we will select the location where we publish the form.














after selecting the location wewill click on next button.
(iii) If all the user can access the form then we publish the form in same location as step 2.














then click on next button.
(iv) Verify the form














and then click publish button.
(v) After clcik on publish the form will be published successfully.

How we uplaod a infopath form using Sharepoint Central administarion 3.0.

(i) Go to Start option and click on all programs | administrative tools | select sharepoint 3.0 central administartive.Click on Application Management and then select Manage form template in Infopath Form service and then browse the form from the location and verify the form then upload.













when we click on ok button then page will be uploaded successfully. If any error then it will shows.














(ii) How we activate the form.

(i) Go to Internet Explorer and type your address like http://virtual2k3/ .
(ii)Select Site Action link button at top right of your page and Go to Site setting | modify all site settings.












(iii) Go to Site Collection Administration | site collection features and the activate the form.












(iv) Go to Main Site and select Form Setting and select advanced setting.












(V) From Content Type section click on Add from existing site content types link button.












(v)Select the page from the list and add the form in the existing Collection Library.












After adding the page you will be back on previous page.The added page will we displayed in Content Types.












(vi)Click the form in Form menu.Select New from menu.It will display a list of available page.Select your page and it willl be opened in the browser.