I create form Absence Request for leave employee in infopath sharepoint 2010.
I create code connect to database for cal FromDate EndDate in holiday, my code is little bit ^^
I read this site in
http://ashrafhossain.wordpress.com/2010/08/30/publishing-administrator-approved-infopath-form-template-with-custom-code for upload template with code
I do follow all step and complete !!
But I don't know when I run form that have code, it can't run code me why ??
However I debug code on infopath, it run code = ="
Help me,, please suggest !!
My code
XPathNavigator Form = this.MainDataSource.CreateNavigator();
if (Form.SelectSingleNode("/my:myFields/my:FromDate", NamespaceManager).Value != "" && Form.SelectSingleNode("/my:myFields/my:EndDate", NamespaceManager).Value != "")
{
DateTime fr = Form.SelectSingleNode("/my:myFields/my:FromDate", NamespaceManager).ValueAsDateTime;
DateTime en = Form.SelectSingleNode("/my:myFields/my:EndDate", NamespaceManager).ValueAsDateTime;
SqlConnection MyConnection = new SqlConnection("Server=192.168.1.4;Database=HR;Trusted_Connection=True;");
//Find Holiday date
MyConnection.Open();
SqlCommand Cmd = new SqlCommand();
Cmd.Connection = MyConnection;
Cmd.CommandType = CommandType.Text;
Cmd.CommandText = "SELECT Count(*) HDate FROM Holidays where HolidaysDate between '" + fr + "' AND '" + en + "'";
SqlDataAdapter DA = new SqlDataAdapter(Cmd);
DataSet DS = new DataSet();
DA.Fill(DS);
string HoliCount = DS.Tables[0].Rows[0][0].ToString();
MyConnection.Close();
//Find Datediff
MyConnection.Open();
SqlCommand Cmd2 = new SqlCommand();
Cmd2.Connection = MyConnection;
Cmd2.CommandType = CommandType.Text;
Cmd2.CommandText = "select datediff(day,'" + fr + "','" + en + "')+1 as DateDD";
SqlDataAdapter DA2 = new SqlDataAdapter(Cmd2);
DataSet DS2 = new DataSet();
DA2.Fill(DS2);
string SelectLeave = DS2.Tables[0].Rows[0][0].ToString();
MyConnection.Close();
//
int TotalDayLeave = Convert.ToInt32(SelectLeave) - Convert.ToInt32(HoliCount);
Form.SelectSingleNode("/my:myFields/my:TotalDate", NamespaceManager).SetValue(TotalDayLeave.ToString());
}