hi, if you can use LIQN use below code
// master page buttons i.e in master page if you have buttons outside contentPlaceHolder
IEnumerable<Button> masterButtons = this.Form.Controls.OfType<Button>();
foreach (Button button in masterButtons)
{
Response.Write(button.Text);
}
//all buttons of contentPlaceHolder
IEnumerable<ContentPlaceHolder> contentPlaceHolders = this.Form.Controls.OfType<ContentPlaceHolder>();
foreach (ContentPlaceHolder contentPlaceHolder in contentPlaceHolders)
{
IEnumerable<Button> buttons = contentPlaceHolder.Controls.OfType<Button>();
foreach (Button button in buttons)
{
Response.Write(button.Text);
}
}
else you can use for loop like below
for (int index = 0; index < this.Form.Controls.Count; index++)
{
if (this.Form.Controls[index] is ContentPlaceHolder)
{
ContentPlaceHolder contentPlaceHolder = this.Form.Controls[index] as ContentPlaceHolder;
for (int i = 0; i < contentPlaceHolder.Controls.Count; i++)
{
if (contentPlaceHolder.Controls[i] is Button)
Response.Write((contentPlaceHolder.Controls[i] as Button).Text);
}
}
}
private void Page_Load(object sender, System.EventArgs e)
{
LoopButtons(Page.Controls);
}
private void LoopButtons(ControlCollection controlCollection)
{
foreach (var control in controlCollection)
{
if (control is Button)
{
// This is sample code
// You get each button here
// Do something else here
Response.Write(((Button)control).Text);
}
if (control.Controls.Count > 0)
{
LoopButtons(control.Controls);
}
}
}
ThanX karthicks, jerryjoseph 4 reply.... i used the code on master page and content page pageload
individually. but it not working. my code is below.. Please tel me where should i place code
i used the code on master page and content page pageload individually. but it not working. my code is below.. Please tel me where should i place code
You didn't paste the code correctly. You pasted this.
private void LoopButtons(ControlCollection controlCollection)
{
foreach (var control in controlCollection)
{
if (control is Button)
{
// This is sample code
// You get each button here
// Do something else here
Response.Write(((Button)control).Text);
}
}
}
It should be like this.
private void LoopButtons(ControlCollection controlCollection)
{
foreach (var control in controlCollection)
{
if (control is Button)
{
// This is sample code
// You get each button here
// Do something else here
Response.Write(((Button)control).Text);
}
if (control.Controls.Count > 0){LoopButtons(control.Controls);}
}
}
That piece of code is needed to make it recursive.
An observation: The Page_Load is too fat. you have to refactor it.
rajuthri
Member
16 Points
35 Posts
find control in Asp.net page with Master page
Mar 01, 2012 10:32 AM|LINK
Hi,
I have page which has master page. I want to findout all buttons available in my page . How can i find out?
Thanks!!!
karthicks
All-Star
31382 Points
5424 Posts
Re: find control in Asp.net page with Master page
Mar 01, 2012 11:46 AM|LINK
hi, if you can use LIQN use below code // master page buttons i.e in master page if you have buttons outside contentPlaceHolder IEnumerable<Button> masterButtons = this.Form.Controls.OfType<Button>(); foreach (Button button in masterButtons) { Response.Write(button.Text); } //all buttons of contentPlaceHolder IEnumerable<ContentPlaceHolder> contentPlaceHolders = this.Form.Controls.OfType<ContentPlaceHolder>(); foreach (ContentPlaceHolder contentPlaceHolder in contentPlaceHolders) { IEnumerable<Button> buttons = contentPlaceHolder.Controls.OfType<Button>(); foreach (Button button in buttons) { Response.Write(button.Text); } } else you can use for loop like below for (int index = 0; index < this.Form.Controls.Count; index++) { if (this.Form.Controls[index] is ContentPlaceHolder) { ContentPlaceHolder contentPlaceHolder = this.Form.Controls[index] as ContentPlaceHolder; for (int i = 0; i < contentPlaceHolder.Controls.Count; i++) { if (contentPlaceHolder.Controls[i] is Button) Response.Write((contentPlaceHolder.Controls[i] as Button).Text); } } }Karthick S
jerryjoseph
Contributor
6740 Points
1257 Posts
Re: find control in Asp.net page with Master page
Mar 01, 2012 11:02 PM|LINK
You have to loop recursively. Try like this.
private void Page_Load(object sender, System.EventArgs e) { LoopButtons(Page.Controls); } private void LoopButtons(ControlCollection controlCollection) { foreach (var control in controlCollection) { if (control is Button) { // This is sample code // You get each button here // Do something else here Response.Write(((Button)control).Text); } if (control.Controls.Count > 0) { LoopButtons(control.Controls); } } }linkedin | twitter | www.jerryjoseph.net
rajuthri
Member
16 Points
35 Posts
Re: find control in Asp.net page with Master page
Mar 02, 2012 08:21 AM|LINK
ThanX karthicks, jerryjoseph 4 reply.... i used the code on master page and content page pageload individually. but it not working. my code is below.. Please tel me where should i place code
Master page.. Aspx:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="QMS.SiteMaster" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head runat="server"> <title></title> <link href="~/Styles/stylesheet.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="../Scripts/QMSValidations.js"></script> <link rel="stylesheet" type="text/css" href="~/pro_drop_1/pro_drop_1.css" /> <script src="~/pro_drop_1/stuHover.js" type="text/javascript"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <asp:ContentPlaceHolder ID="HeadContent" runat="server"> </asp:ContentPlaceHolder> <%--<script type="text/javascript"> function doHourglass() { document.body.style.cursor = 'wait'; } </script>--%> </head> <body > <%--<form id="form1" >--%> <div align="center" class="page"> <div oncontextmenu="return false" class="header"> <div class="title"> <h1> QMS Application </h1> </div> <div class="loginDisplay"> <%--<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false"> <AnonymousTemplate> [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ] </AnonymousTemplate> <LoggedInTemplate> Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>! [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ] </LoggedInTemplate> </asp:LoginView>--%> </div> <div class="clear hideSkiplink"> <%--<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal"> <Items> <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/> <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/> </Items> </asp:Menu>--%> </div> </div> <div class="main"> <asp:ContentPlaceHolder ID="MainContent" runat="server"/> </div> <div class="clear"> </div> </div> <div class="footer" align="center"> DataBase Name: <asp:Label ID="dbName" runat="server" ForeColor="Black"></asp:Label> </div> <%-- </form>--%> </body> </html>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; namespace QMS { public partial class SiteMaster : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetDatabaseName(); } FindControls(); //Disable(); } private void Disable() { foreach (Control masterControl in Page.Controls) { if (masterControl is MasterPage) { foreach (Control formControl in masterControl.Controls) { if (formControl is System.Web.UI.HtmlControls.HtmlForm) { foreach (Control contentControl in formControl.Controls) { if (contentControl is ContentPlaceHolder) { foreach (Control childControl in contentControl.Controls) { if (childControl is Button) { Button newLabel = (Button)childControl; newLabel.Enabled = false; } } } } } } } } } public void FindControls() { var controls = new List<Control>(); foreach (Control ctrl in Page.Controls) { if (ctrl is Button) { Button newLabel = (Button)ctrl; newLabel.Enabled = false; } } } //to show Popup messages private void showalert(string message) { string script = @"alert('" + message + "');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", script, true); } private void GetDatabaseName() { try { int count = 0; Char[] a = ConfigurationManager.AppSettings["QMSDBcon"].ToCharArray(); for (int i = 0; i < a.Length; i++) { if (a[i].ToString() == "=") { count++; if (count == 2) { string b = ""; for (int j = i + 1; j < a.Length; j++) { if (a[j].ToString() != ";") { b = b + a[j].ToString(); } else { break; } dbName.Text = b; } } } } } catch (Exception ex) { showalert(ex.Message); } } } }<%@ Page Title="Client Information" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="ClientInfo.aspx.cs" Inherits="QMS.ClientInfo" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <%@ Register Src="LeftMenu.ascx" TagName="LeftMenu" TagPrefix="uc1" %> <%@ Register Src="AdminTopMenu.ascx" TagName="AdminTopMenu" TagPrefix="uc2" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> <script type="text/javascript"> </script> <style type="text/css"> .style1 { width: 100%; } .style2 { height: 37px; } .style4 { width: 336px; } .style9 { width: 179px; } .style10 { width: 122px; } .style11 { width: 343px; } .style12 { height: 37px; width: 343px; } </style> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <form id="form1" runat="server"> <script type="text/javascript" language="JavaScript"> var needToConfirm = true; window.onbeforeunload = confirmExit; function confirmExit() { if (needToConfirm) { document.getElementById('TxtLeavePage').value = 'yes'; document.getElementById('IBtnSave').click(); } } //script for get city function FillCity(id) { document.getElementById(id).click(); } // function Required(id1, id2) { // // var a = document.getElementById(id1); // var b = document.getElementById(id2); // if (a.value.trim() == '' && b.value.trim() == '') { // if (!b.hasFocus) { // alert("Please enter D/B/A Name or Insured !!!"); // a.focus()=true; // } // } // } function DBA(id1, id2) { var a = document.getElementById(id1); var b = document.getElementById(id2); if (a.value.trim() == '' && b.value.trim() == '') { alert("Please enter D/B/A Name or Insured !!!"); } } </script> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager> <asp:UpdatePanel ID="up1" runat="server"> <ContentTemplate> <div id="clientdiv" runat="server" clientidmode="Static"> <table width="960" height="500" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2" align="center" valign="top"> <uc2:AdminTopMenu ID="AdminTopMenu1" AdminMainPage="Quote" runat="server" /> </td> </tr> <tr> <td width="245" rowspan="3" align="left" valign="top" class="bdr" bgcolor="#FFFFFF"> <uc1:LeftMenu ID="LeftMenu1" MainPage="ClientInfo" runat="server" /> </td> <td width="714" rowspan="3" align="left" valign="top" bgcolor="#FFFFFF" class="bdr"> <table width="677" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td height="17" colspan="2"> </td> </tr> <tr height="15"> <td colspan="2" class="box_bdr"> <table width="677" height="15" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="338" align="left" valign="middle" bgcolor="#ebedf1" class="text txt_pad1"> Line Code, Status & Issue Date </td> <td width="339" align="right" valign="middle" bgcolor="#ebedf1" class="txt_pad2 text"> Quote No : <asp:Label ID="CurrentQuoteNumber" CssClass="red" runat="server"></asp:Label> </td> </tr> </table> </td> </tr> <tr> <td height="8" colspan="2"> </td> </tr> <tr> <td class="txt_pad1 bodytext" colspan="2" height="35" style="width: 679px" width="214"> <table class="style1"> <tr> <td class="style4"> Line Code </td> <td> </td> </tr> <tr> <td class="style4"> <asp:DropDownList ID="ddlLineCode" runat="server" Width="250px"> </asp:DropDownList> </td> <td> <asp:DropDownList ID="ddlQuoteStatus" runat="server" Width="125px"> </asp:DropDownList> </td> </tr> <tr> <td class="style4"> Status Code<asp:Button ID="Button2" runat="server" Text="Button" /> </td> <td> Issue Date </td> </tr> <tr> <td class="style4"> <asp:DropDownList ID="ddlStatusCode" runat="server"> </asp:DropDownList> <asp:ImageButton ID="ibtnSendToBilling" runat="server" ImageUrl="~/images/sendtobilling.jpg" ImageAlign="AbsBottom" OnClick="ibtnSendToBilling_Click" /> <asp:Button ID="btnBill" runat="server" Text="" ClientIDMode="Static" Style="display: none" OnClick="btnBill_Click" /> </td> <td> <asp:TextBox ID="txtIssueDate" runat="server" Width="100"></asp:TextBox> <asp:CalendarExtender ID="txtIssueDate_CalendarExtender" runat="server" CssClass="cal_Theme1" TargetControlID="txtIssueDate"> </asp:CalendarExtender> Today's Date:<asp:Label ID="TodaysDate" runat="server"></asp:Label> </td> </tr> </table> <%--</fieldset>--%> </td> </tr> <tr> <td class="txt_pad1 bodytext" colspan="2" height="15" style="width: 679px" width="214"> </td> </tr> <tr height="15"> <td colspan="2" class="box_bdr"> <table width="677" height="15" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="338" align="left" valign="middle" bgcolor="#ebedf1" class="text txt_pad1"> Insured Contact Info</legend> </td> <td width="339" align="right" valign="middle" bgcolor="#ebedf1" class="txt_pad2 text"> </td> </tr> </table> </td> </tr> <tr> <td height="8" colspan="2"> </td> </tr> <tr> <td class="txt_pad1 bodytext" height="32" colspan="2"> <%-- <fieldset>--%> <table class="style1"> <tr> <td class="style9"> D/B/AName </td> <td> Insured </td> <td> Address 1 </td> </tr> <tr> <td class="style9"> <asp:TextBox ID="txtDBAName" runat="server" ClientIDMode="Static" MaxLength="30" CssClass="UppercaseText" ></asp:TextBox> </td> <td> <asp:TextBox ID="TxtInsured" runat="server" ClientIDMode="Static" MaxLength="30" CssClass="UppercaseText"></asp:TextBox> <asp:TextBox ID="TxtOldInsured" runat="server" ClientIDMode="Static"></asp:TextBox> </td> <td> <asp:TextBox ID="TxtAddress1" runat="server" ClientIDMode="Static" Width="200" CssClass="UppercaseText"></asp:TextBox> </td> </tr> <tr> <td class="style9"> Address 2 </td> <td> State </td> <td> <table class="style1"> <tr> <td class="style10"> Zipcode </td> <td> City </td> </tr> </table> </td> </tr> <tr> <td class="style9"> <asp:TextBox ID="TxtAddress2" runat="server" ClientIDMode="Static" Width="150px" CssClass="UppercaseText"></asp:TextBox> </td> <td> <asp:DropDownList ID="ddlState" runat="server" ClientIDMode="Static" Width="120px"> </asp:DropDownList> </td> <td> <table class="style1"> <tr> <td> <asp:TextBox ID="TxtZip" runat="server" ClientIDMode="Static" Width="92px"></asp:TextBox> </td> <td> <asp:TextBox ID="TxtCity" runat="server" ClientIDMode="Static" CssClass="UppercaseText"></asp:TextBox> </td> </tr> </table> </td> </tr> <tr> <td class="style9"> </td> <td> </td> <td> </td> </tr> </table> </td> </tr> <tr height="15"> <td colspan="2" class="box_bdr"> <table width="677" height="15" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="338" align="left" valign="middle" bgcolor="#ebedf1" class="text txt_pad1"> Agent, Insurer & Premium Financiers </td> <td width="339" align="right" valign="middle" bgcolor="#ebedf1" class="txt_pad2 text"> </td> </tr> </table> </td> </tr> <tr> <td height="8" colspan="2"> </td> </tr> <tr> <td class="txt_pad1 bodytext" colspan="2" height="32"> <table class="style1"> <tr> <td class="style11"> Agent </td> <td> Agent Contact </td> <td> <asp:CheckBox ID="ChkBrokerAssigned" runat="server" Text="Broker Assigned" /> </td> </tr> <tr> <td class="style12"> <%-- <asp:DropDownList ID="ddlAgent" runat="server" AppendDataBoundItems="True" AutoPostBack="True" OnSelectedIndexChanged="ddlAgent_SelectedIndexChanged" Width="330px" ondatabound="ddlAgent_DataBound"> <asp:ListItem Value=""> </asp:ListItem> </asp:DropDownList>--%> <asp:ComboBox ID="ddlAgent" runat="server" DropDownStyle="DropDownList" Width="270px" Height="17px" ClientIDMode="Static" OnSelectedIndexChanged="ddlAgent_SelectedIndexChanged" AutoPostBack="true" AutoCompleteMode="Suggest"> <%--<asp:ListItem Value=""></asp:ListItem>--%> </asp:ComboBox> <asp:ImageButton ID="imgBtnAgent" runat="server" ImageUrl="~/images/search.png" Style="width: 20px" OnClick="imgBtnAgent_Click" /> </td> <td> <asp:DropDownList ID="ddlAgentContact" runat="server" Width="130px"> <asp:ListItem Value="0">---Select Contact---</asp:ListItem> </asp:DropDownList> </td> <td class="style2"> <asp:ImageButton ID="IBtnSelectBroker" runat="server" ImageUrl="~/images/selectbroker.gif" Width="111" /> <asp:ModalPopupExtender ID="IBtnSelectBroker_ModalPopupExtender" runat="server" DynamicServicePath="" Enabled="True" PopupControlID="popupPanel" TargetControlID="IBtnSelectBroker"> </asp:ModalPopupExtender> </td> </tr> <tr> <td class="style11"> Company </td> <td colspan="2"> Company Contact </td> </tr> <tr> <td class="style11"> <asp:DropDownList ID="ddlCompany" runat="server" AppendDataBoundItems="True" AutoPostBack="True" OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged" Width="320px"> <asp:ListItem Value="0">-Select Company-</asp:ListItem> </asp:DropDownList> <asp:ImageButton ID="ImgBtnCompany" runat="server" ImageUrl="~/images/search.png" Style="width: 20px" OnClick="ImgBtnCompany_Click" /> <%--<asp:ComboBox ID="ddlCompany" runat="server" DropDownStyle="DropDownList" Width="300px" Height="17px" ClientIDMode="Static" OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged" AutoPostBack="true" AutoCompleteMode="Suggest"> <asp:ListItem Value=""></asp:ListItem> </asp:ComboBox>--%> </td> <td colspan="2"> <asp:DropDownList ID="ddlCompanyContact" runat="server" Width="130px"> <asp:ListItem Value="0">---Select Contact---</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td class="style11"> Premium Financier </td> <td colspan="2"> Premium Financier Contact </td> </tr> <tr> <td class="style11"> <asp:DropDownList ID="ddlPreFinancier" runat="server" AppendDataBoundItems="True" AutoPostBack="True" OnSelectedIndexChanged="ddlPreFinancier_SelectedIndexChanged" Width="320px"> <asp:ListItem Value="0">-Select Premium Financier-</asp:ListItem> </asp:DropDownList> <asp:ImageButton ID="ImgBtnPremierFinance" runat="server" ImageUrl="~/images/search.png" Style="width: 20px" OnClick="ImgBtnPremierFinance_Click" /> </td> <td colspan="2"> <asp:DropDownList ID="ddlPreFinancierContact" runat="server" Width="130px"> <asp:ListItem Value="0">---Select Contact---</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td colspan="3"> <asp:Panel ID="popupPanel" Style="display: none" runat="server" CssClass="popupControl3"> <table class="style1"> <tr> <td align="left" class="txt_pad1 bodytext" height="35" valign="middle"> Broker Company </td> <td> <asp:DropDownList ID="ddlBrokerCompany" runat="server" AppendDataBoundItems="True"> <asp:ListItem Value="0">-Select Broker-</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td align="right"> </td> <td align="right"> <asp:ImageButton ID="IBtnExit" runat="server" ImageUrl="~/images/exit.gif" Width="59" Height="27" /> <asp:ImageButton ID="IBtnBrokerSave" runat="server" ImageUrl="~/images/save.gif" Width="59" Height="27" OnClick="IBtnBrokerSave_Click" /> </td> </tr> </table> </asp:Panel> </td> </tr> </table> </td> </tr> <tr> <td colspan="2" height="15"> </td> </tr> <tr height="15"> <td colspan="2" class="box_bdr"> <table width="677" height="15" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="338" align="left" valign="middle" bgcolor="#ebedf1" class="text txt_pad1"> Policy Dates </td> <td width="339" align="right" valign="middle" bgcolor="#ebedf1" class="txt_pad2 text"> </td> </tr> </table> </td> </tr> <tr> <td height="8" colspan="2"> </td> </tr> <tr> <td align="left" class="bodytext txt_pad1" height="35" valign="middle" colspan="2"> <table class="style1"> <tr> <td> Policy Number </td> <td> Effective Start Date </td> <td> Effective End Date </td> </tr> <tr> <td> <asp:TextBox ID="txtPolicyNumber" runat="server" ClientIDMode="Static" onkeypress="ShowEffEndDate()"></asp:TextBox> </td> <td> <asp:TextBox ID="txtEffStartDate" runat="server" ClientIDMode="Static" AutoPostBack="True" OnTextChanged="txtEffStartDate_TextChanged"></asp:TextBox> <asp:CalendarExtender ID="txtEffStartDate_CalendarExtender" runat="server" CssClass="cal_Theme1" TargetControlID="txtEffStartDate"> </asp:CalendarExtender> </td> <td> <asp:TextBox ID="txtEffEndDate" runat="server" ClientIDMode="Static"></asp:TextBox> <asp:CalendarExtender ID="CEEffEndDate" runat="server" CssClass="cal_Theme1" TargetControlID="txtEffEndDate"> </asp:CalendarExtender> </td> </tr> </table> </td> </tr> <tr> <td align="left" class="bodytext txt_pad1" height="15" valign="middle"> <asp:Button ID="btnSelectCity" ClientIDMode="Static" Style="display: none" runat="server" Text="Button" OnClick="btnSelectCity_Click" /> </td> <td> </td> </tr> <tr> <td align="right" colspan="2" height="40" valign="bottom"> <table border="0" cellpadding="0" cellspacing="0" width="400"> <tr> <td align="left" valign="bottom" width="74"> <asp:ImageButton ID="IBtnCancel" runat="server" Height="27" ImageUrl="~/images/cancle.gif" Width="59" OnClick="IBtnCancel_Click" ClientIDMode="Static" /> </td> <td> </td> <td align="left" valign="bottom" width="131"> <asp:ImageButton ID="IBtnMultiQuote" runat="server" Height="27" ImageUrl="~/images/multiquote.gif" OnClick="IBtnMultiQuote_Click" Width="111" /> </td> <td> </td> <td align="left" valign="bottom" width="131"> <asp:ImageButton ID="IBtnPolicyNo" runat="server" Height="27" ImageUrl="~/images/policynumber.jpg" OnClick="IBtnPolicyNo_Click" Width="111" /> </td> <td> </td> <td align="left" valign="bottom" width="112"> <asp:ImageButton ID="IBtnSave" runat="server" ClientIDMode="Static" Height="27" ImageUrl="~/images/save.gif" OnClick="IBtnSave_Click" Width="59" /> </td> <td> </td> <td align="right" valign="bottom" width="100"> <asp:ImageButton ID="IBtnSaveClose" runat="server" Height="27" ImageUrl="~/images/saveclose.gif" OnClick="IBtnSaveClose_Click" Width="111" /> </td> </tr> </table> </td> </tr> <tr> <td colspan="2" height="10"> <asp:Button ID="MQuote" runat="server" ClientIDMode="Static" Height="2px" Text="" OnClick="MQuote_Click" Width="2px" Style="display: none" /> <asp:Button ID="MQuoteNo" runat="server" ClientIDMode="Static" Height="2px" Text="" OnClick="MQuoteNo_Click" Width="2px" Style="display: none" /> <%--<asp:Button ID="btnEnterPno" runat="server" ClientIDMode="Static" Height="2px" Text="" OnClick="btnEnterPno_Click" Width="2px" Style="display: none" />--%> <%--<asp:Button ID="btnAutoGenP" runat="server" ClientIDMode="Static" Height="2px" Text="" OnClick="btnAutoGenP_Click" Width="2px" Style="display: none" />--%> <asp:Button ID="btnCancelUpdate" runat="server" ClientIDMode="Static" Height="2px" Text="" OnClick="btnCancelUpdate_Click" Width="2px" Style="display: none" /> <asp:Button ID="btnHidAuto" runat="server" ClientIDMode="Static" Height="2px" Text="" Width="2px" Style="display: none" /> <asp:Button ID="btnHidEnterPno" runat="server" ClientIDMode="Static" Height="2px" Text="" Width="2px" Style="display: none" /> <asp:Button ID="btnHidShowAutoGenConfirm" runat="server" ClientIDMode="Static" Height="2px" Text="" Width="2px" Style="display: none" OnClick="btnHidShowAutoGenConfirm_Click" /> <asp:Button ID="btnHidSendBillingPolicy" runat="server" ClientIDMode="Static" Height="2px" Text="" Width="2px" Style="display: none" OnClick="btnHidSendBillingPolicy_Click" /> <asp:TextBox ID="TxtLeavePage" runat="server" ClientIDMode="Static" Style="display: none"></asp:TextBox> <asp:Button ID="btnHidComisionBilling" runat="server" ClientIDMode="Static" Height="2px" Text="" Width="2px" OnClick="btnHidComisionBilling_Click" Style="display: none" /> </td> </tr> <tr> <td colspan="2" height="10"> <asp:Panel ID="PanelAutoGenConfirm" Style="display: none" runat="server" CssClass="popupControlConfirm"> <table class="style1"> <tr> <td align="left" class="txt_pad1 bodytext" height="30" valign="middle"> Do you want to Auto Generate a Policy Number? </td> <td align="right" valign="top"> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/close-button.png" /> </td> </tr> <tr> <td colspan="2" align="center"> <asp:Button ID="btnAutoGenP" Text="Yes" runat="server" OnClick="btnAutoGenP_Click" /> <asp:Button ID="btnEnterPno" Text="No" runat="server" OnClick="btnEnterPno_Click" ClientIDMode="Static" /> </td> </tr> </table> </asp:Panel> <asp:ModalPopupExtender ID="MEAuotGenConfirm" ClientIDMode="Static" runat="server" TargetControlID="btnHidAuto" PopupControlID="PanelAutoGenConfirm" DynamicServicePath="" Enabled="True"> </asp:ModalPopupExtender> </td> </tr> <tr> <td colspan="2" height="10"> <asp:Panel ID="PopPanelGenPolicyNo" Style="display: none" runat="server" CssClass="popupControl"> <table class="style1"> <tr> <td colspan="2" align="left" class="txt_pad1 bodytext" height="35" valign="middle"> Please Enter Policy Number </td> </tr> <tr> <td colspan="2"> <asp:TextBox ID="TxtGenPolicyNo" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:ImageButton ID="IBtnGenPolicyNo" runat="server" ImageUrl="~/images/save.gif" Width="59" Height="27" OnClick="IBtnGenPolicyNo_Click" /> </td> <td> <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/Exit.gif" Width="59" Height="27" /> </td> </tr> </table> </asp:Panel> <asp:ModalPopupExtender ID="MEEnterPolicyNo" runat="server" TargetControlID="btnHidEnterPno" PopupControlID="PopPanelGenPolicyNo" DynamicServicePath="" Enabled="True"> </asp:ModalPopupExtender> </td> <td> <asp:Panel ID="Panel1" runat="server" CssClass="ModalPopupPanel" Width="400px" Style="display: none"> <table class="style1"> <tr> <td class="txt_pad1 bodytext"> Name: </td> <td> <asp:Label ID="lblName" runat="server" Width="273px" ClientIDMode="Static"></asp:Label> <%--<asp:TextBox ID="txtSelectedName" runat="server" Width="200px" ClientIDMode="Static"></asp:TextBox>--%> </td> <tr> <td class="txt_pad1 bodytext"> PhNo: </td> <td> <asp:Label ID="lblPhone" runat="server" ClientIDMode="Static" Width="200px"></asp:Label> <%--<asp:TextBox ID="txtPhno" runat="server" ClientIDMode="Static"></asp:TextBox>--%> </td> </tr> <tr> <td class="txt_pad1 bodytext"> Memo: </td> <td> <asp:Label ID="lblMemo" runat="server" Width="300px" Style="overflow-y: scroll;" Height="150px"></asp:Label> <%--<asp:TextBox ID="TxtMemo" runat="server" Width="200px" Height="100" runat="server" TextMode="MultiLine" ClientIDMode="Static"></asp:TextBox>--%> </td> </tr> <tr> <td class="txt_pad1 bodytext"> </td> <td> </td> </tr> <tr> <td> </td> <td> <asp:ImageButton ID="ImgBtnCancel" runat="server" ImageUrl="~/images/cancle.gif" OnClick="ImgBtnCancel_Click" /> </td> <%--<td> <asp:ImageButton ID="ibtnSubmit" runat="server" ImageUrl="~/images/submit.gif" ClientIDMode="Static" OnClientClick="ButtonLoading()" /> </td>--%> </tr> </table> </asp:Panel> <asp:ModalPopupExtender ID="mpeAgent" runat="server" DynamicServicePath="" Enabled="True" TargetControlID="Button1" PopupControlID="Panel1" BackgroundCssClass="ModalPopupControl"> </asp:ModalPopupExtender> <asp:Button ID="Button1" runat="server" Text="Button" Style="display: none" /> </td> </tr> </table> </td> </tr> <tr> <td height="670" align="left" valign="top" bgcolor="#FFFFFF" class="bdr_right"> </td> </tr> <%--<tr> <td width="7" height="7" align="right" bgcolor="#FFFFFF" valign="bottom"><img src="../images/box_bottomleft.gif" width="7" height="7" /></td> </tr>--%> </table> <table> <tr> <td height="35" align="center" valign="middle" class="footer"> Designed & Developed By : <a href="http://www.zeninfotech.com" target="_blank" class="footer1">Zeninfotech</a> </td> </tr> </table> <%--<asp:Panel ID="Panel1" runat="server" ClientIDMode="Static">--%> <%--</asp:Panel>--%> <%-- <asp:ModalPopupExtender ClientIDMode="Static" ID="ModalPopupExtender1" Enabled="true" TargetControlID="LinkButton1" PopupControlID="Panel1" runat="server"> </asp:ModalPopupExtender>--%> </div> </ContentTemplate> </asp:UpdatePanel> <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="up1" DynamicLayout="true"> <ProgressTemplate> <%-- <div id="progressBackgroundFilter" ></div>--%> <div id="Progressbar" class="Progressbar" align="center" valign="middle" runat="server"> <asp:Image ID="Image1" Width="75" Height="95" runat="server" ImageUrl="~/images/animation_processing.gif" /> </div> </ProgressTemplate> </asp:UpdateProgress> </form> </asp:Content>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using System.ComponentModel; using Microsoft.ApplicationBlocks.Data; using System.Configuration; using System.IO; using QMS.LogFile; using System.Net.Mail; //using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling; //using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging; //using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration; //using Microsoft.Practices.EnterpriseLibrary.Logging; namespace QMS { public partial class ClientInfo : System.Web.UI.Page { ///Database connection string SqlConnection QMSConn = new SqlConnection(ConfigurationManager.AppSettings["QMSDBCon"]); LogException Log = new LogException(); protected void Page_Load(object sender, EventArgs e) { TxtInsured.Focus(); if (Session["UserID"] == null) { Response.Redirect("Login.aspx"); } this.Page.Form.DefaultButton = IBtnSave.UniqueID; TxtZip.Attributes.Add("onfocusout", "FillCity('btnSelectCity')"); // btnAutoGenP.Attributes.Add("onclick", "ButtonLoading('btnAutoGenP')"); //display current date in today's date label String s = DateTime.Now.ToString(); TodaysDate.Text = DateTime.Now.ToShortDateString(); btnCancelUpdate.Attributes.Add("onclick", "needToConfirm=false;"); if (Session["CurrQuoteNumber"] != null) { CurrentQuoteNumber.Text = Session["CurrQuoteNumber"].ToString(); //LeftMenu1.LMQuote = CurrentQuoteNumber.Text; // filldata(); } else { if (Request.QueryString["CurrQuoteNumber"] != null && Request.QueryString["CurrQuoteNumber"] != "") { Session["CurrQuoteNumber"] = Request.QueryString["CurrQuoteNumber"].ToString(); CurrentQuoteNumber.Text = Session["CurrQuoteNumber"].ToString(); } } LeftMenu1.LMQuote = CurrentQuoteNumber.Text; //fill the data in all drop down boxs if (!IsPostBack) { filldropdowns(); if (Request.QueryString["NewName"] != null && Request.QueryString["NewName"] != "") { TxtInsured.Text = Request.QueryString["NewName"].ToString().ToUpper(); Session["CurrQuoteNumber"] = null; //Set default values for new Quote DefaultSet(); } TxtOldInsured.Visible = false; if (Session["CurrQuoteNumber"] != null) { //get the data filldata(Session["CurrQuoteNumber"].ToString()); //pn1.DefaultButton = lbButton.UniqueID; } else { DateTime dt = DateTime.Now; txtIssueDate.Text = dt.ToShortDateString(); txtEffStartDate.Text = dt.ToShortDateString(); txtEffEndDate.Text = dt.AddMonths(12).ToShortDateString(); } //if (Session["CurrQuoteNumber"] == null) //{ // txtEffStartDate.Text = DateTime.Now.ToShortDateString(); // txtEffEndDate.Text = (Convert.ToDateTime(txtEffStartDate.Text).AddMonths(12)).ToShortDateString(); //} } SqlCommand cmd = new SqlCommand("usp_LockQuote", QMSConn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@QuoteNumber", SqlDbType.VarChar).Value = Session["CurrQuoteNumber"].ToString(); DataSet LDS = new DataSet(); SqlDataAdapter LDA = new SqlDataAdapter(cmd); LDA.Fill(LDS); if (LDS.Tables[0].Rows[0][0].ToString() != "") { if (Convert.ToBoolean(LDS.Tables[0].Rows[0][0])) { Session["QLock"] = "Locked"; foreach (Control c in Page.Controls) foreach (Control ctrl in c.Controls) if (ctrl is Button) ((Button)ctrl).Enabled = false; } else { Session["QLock"] = "UnLocked"; } } else { Session["QLock"] = "UnLocked"; } //for (int index = 0; index < this.Form.Controls.Count; index++) //{ // if (this.Form.Controls[index] is ContentPlaceHolder) // { // ContentPlaceHolder contentPlaceHolder = this.Form.Controls[index] as ContentPlaceHolder; // for (int i = 0; i < contentPlaceHolder.Controls.Count; i++) // { // if (contentPlaceHolder.Controls[i] is Button) // { // //Response.Write((contentPlaceHolder.Controls[i] as Button).Text); // Button newLabel = (Button)contentPlaceHolder.Controls[i]; // newLabel.Enabled = false; // } // } // } //} LoopButtons(Page.Controls); } protected override void OnUnload(EventArgs e) { base.OnUnload(e); LoopButtons(Page.Controls); } private void LoopButtons(ControlCollection controlCollection) { foreach (var control in controlCollection) { if (control is Button) { // This is sample code // You get each button here // Do something else here Response.Write(((Button)control).Text); } } } //set default values for new Quote private void DefaultSet() { //Status Code, Line Code, State try { SqlDataReader dr = SqlHelper.ExecuteReader(QMSConn, "usp_GetNewQuoteDefaultValues"); while (dr.Read()) { ddlStatusCode.SelectedValue = dr["StatusCode"].ToString(); ddlLineCode.SelectedValue = dr["LineCode"].ToString(); ddlState.SelectedValue = dr["State"].ToString(); } } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } try { SetAgent(); //ddlAgent.Items.Insert(0, ""); } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } } private void SetAgent() { if (Request.QueryString["NewName"] != null && Request.QueryString["NewName"] != "") { ddlAgent.SelectedValue = "2614"; } } protected void btnSelectCity_Click(object sender, EventArgs e) { String State = ddlState.SelectedItem.Text; String Zipcode = TxtZip.Text; DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_GetCity", new SqlParameter("@State", State), new SqlParameter("@Zipcode", Zipcode)); try { if (ds.Tables[0].Rows.Count > 0) { TxtCity.Text = ds.Tables[0].Rows[0]["City"].ToString().ToUpper(); } else { TxtCity.Text = ""; } } catch (Exception ex) { showalert(ex.Message); } finally { TxtCity.Focus(); } } //to get the policy info details from database and fill the form private void filldata(string strQuoteNumber) { string QuoteNumber = strQuoteNumber; int AgentContactId = 0; int CompanyContactId = 0; int PreFinancierContactId = 0; try { SqlDataReader dr = SqlHelper.ExecuteReader(QMSConn, "usp_GetClientInfo", new SqlParameter("@QuoteNumber", QuoteNumber)); while (dr.Read()) { if (dr["LineCode"].ToString() == "34") { //ddlLineCode.Items.Insert(0, new ListItem("VD - Vacant Dwelling - No Liability", "34")); ddlLineCode.Items.Add(new ListItem("VD - Vacant Dwelling - No Liability", "34")); ddlLineCode.SelectedValue = "34"; } else { ddlLineCode.SelectedValue = dr["LineCode"].ToString(); } ddlStatusCode.SelectedValue = dr["StatusCode"].ToString(); txtIssueDate.Text = DateTime.Now.ToShortDateString();//dr["IssueDate"].ToString(); if (dr["Name"].ToString().Length > 30) { TxtOldInsured.Visible = true; TxtInsured.Visible = false; TxtOldInsured.Text = dr["Name"].ToString(); TxtInsured.Text = " "; } else { TxtInsured.Text = dr["Name"].ToString().ToUpper(); } TxtAddress1.Text = dr["Address1"].ToString().ToUpper(); TxtAddress2.Text = dr["Address2"].ToString().ToUpper(); TxtCity.Text = dr["City"].ToString().ToUpper(); ddlState.SelectedValue = dr["State"].ToString(); TxtZip.Text = dr["Zipcode"].ToString(); ddlAgent.SelectedValue = dr["AgentID"].ToString(); if (dr["AgentContactID"].ToString() != null && dr["AgentContactID"].ToString() != "") { AgentContactId = Convert.ToInt32(dr["AgentContactID"].ToString()); } //string CType = "AF"; //fillContact(AgentId, CType); if (dr["CompanyStatus"].ToString() != "") { if (Convert.ToBoolean(dr["CompanyStatus"])) { //adding the company to company dropdownlist if not available in the list ddlCompany.Items.Add(new ListItem(dr["CompanyName"].ToString(), dr["CompanyID"].ToString())); } } if (dr["CompanyContactID"].ToString() != null && dr["CompanyContactID"].ToString() != "") { CompanyContactId = Convert.ToInt32(dr["CompanyContactID"].ToString()); } ddlPreFinancier.SelectedValue = dr["PremiumFinancierID"].ToString(); if (dr["PremiumFinancierContactID"].ToString() != null && dr["PremiumFinancierContactID"].ToString() != "") { PreFinancierContactId = Convert.ToInt32(dr["PremiumFinancierContactID"].ToString()); } txtPolicyNumber.Text = dr["PolicyNumber"].ToString(); //if (strQuoteNumber == null) //{ // txtEffStartDate.Text=DateTime.Now.ToShortDateString(); // txtEffEndDate.Text = (Convert.ToDateTime(txtEffStartDate.Text).AddMonths(12)).ToShortDateString(); //} //else //{ txtEffStartDate.Text = dr["EffectiveStartDate"].ToString(); //int PolicyPeriod = GetPolicyPeriod(strQuoteNumber); txtEffEndDate.Text = dr["EffectiveEndDate"].ToString(); //} if (dr["Broker"].ToString() == "True") { ChkBrokerAssigned.Checked = true; } if (dr["BrokerStatus"].ToString() != "") { if (Convert.ToBoolean(dr["BrokerStatus"])) { if (dr["BrokerName"].ToString() != "") { //adding the Broker company to Brokercompany dropdownlist if not available in the list ddlBrokerCompany.Items.Add(new ListItem(dr["BrokerName"].ToString(), dr["BrokerID"].ToString())); } } } ddlBrokerCompany.SelectedValue = dr["BrokerID"].ToString(); //if (ChkBrokerAssigned.Checked) //{ ddlCompany.SelectedValue = dr["CompanyID"].ToString(); //} if (dr["Type"].ToString() != null && dr["Type"].ToString() != "") { ddlQuoteStatus.SelectedValue = dr["Type"].ToString(); } txtDBAName.Text = dr["DBAName"].ToString().ToUpper(); } QMSConn.Close(); int PPeriod = 0; SqlCommand cmd = new SqlCommand("usp_GetPolicyPeriod", QMSConn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@QuoteNumber", SqlDbType.VarChar); cmd.Parameters["@QuoteNumber"].Value = QuoteNumber; QMSConn.Open(); PPeriod = Convert.ToInt16(cmd.ExecuteScalar()); if (PPeriod != 0) { DateTime EffEndDate; if (txtEffStartDate.Text != "") { DateTime EffStartDate = Convert.ToDateTime(txtEffStartDate.Text); EffEndDate = EffStartDate.AddMonths(PPeriod); txtEffEndDate.Text = EffEndDate.ToShortDateString(); } } QMSConn.Close(); } catch (Exception ex) { showalert(ex.Message); QMSConn.Close(); } finally { //QMSConn.Close(); } //Display the agent contact details int AgentId = 0; if (ddlAgent.SelectedItem.Value != "") { AgentId = Convert.ToInt32(ddlAgent.SelectedItem.Value); } string CType = "AF"; fillContact(AgentId, CType); ddlAgentContact.SelectedValue = AgentContactId.ToString(); //Display the company contact details AgentId = 0; if (ddlCompany.SelectedItem.Value != "") { AgentId = Convert.ToInt32(ddlCompany.SelectedItem.Value); } CType = "CF"; fillContact(AgentId, CType); ddlCompanyContact.SelectedValue = CompanyContactId.ToString(); //Display the Premium Financier contact details AgentId = 0; if (ddlPreFinancier.SelectedItem.Value != "") { AgentId = Convert.ToInt32(ddlPreFinancier.SelectedItem.Value); } CType = "PF"; fillContact(AgentId, CType); ddlPreFinancierContact.SelectedValue = PreFinancierContactId.ToString(); } //function used to fill all the drop down values from database private void filldropdowns() { //quote status try { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_GetQuoteStatus"); ddlQuoteStatus.DataSource = ds; ddlQuoteStatus.DataValueField = "QuoteStatusValue"; ddlQuoteStatus.DataTextField = "QuoteStatusValue"; ddlQuoteStatus.DataBind(); } catch (Exception ex) { showalert(ex.Message); } //linecode try { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_GetLineCode"); ddlLineCode.DataSource = ds; ddlLineCode.DataValueField = "ID"; ddlLineCode.DataTextField = "LineName"; ddlLineCode.DataBind(); } catch (Exception ex) { showalert(ex.Message); } //Statuscode try { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_GetStatusCode"); ddlStatusCode.DataSource = ds; ddlStatusCode.DataValueField = "ID"; ddlStatusCode.DataTextField = "StatusName"; ddlStatusCode.DataBind(); } catch (Exception ex) { showalert(ex.Message); } //State try { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_GetState"); ddlState.DataSource = ds; ddlState.DataValueField = "ID"; ddlState.DataTextField = "StateAbrv"; ddlState.DataBind(); } catch (Exception ex) { showalert(ex.Message); } //Agent try { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_GetAgent", new SqlParameter("@ID", 0)); ddlAgent.DataSource = ds; ddlAgent.DataValueField = "ID"; ddlAgent.DataTextField = "Name"; ddlAgent.DataBind(); ddlAgent.Items.Insert(0, ""); } catch (Exception ex) { showalert(ex.Message); } //Company try { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_GetCompany", new SqlParameter("@CompanyBroker", "No")); ddlCompany.DataSource = ds; ddlCompany.DataValueField = "ID"; ddlCompany.DataTextField = "Name"; ddlCompany.DataBind(); //ddlCompany.Items.Insert(0, ""); } catch (Exception ex) { showalert(ex.Message); } //Broker Company try { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_GetCompany", new SqlParameter("@CompanyBroker", "Yes")); ddlBrokerCompany.DataSource = ds; ddlBrokerCompany.DataValueField = "ID"; ddlBrokerCompany.DataTextField = "Name"; ddlBrokerCompany.DataBind(); } catch (Exception ex) { showalert(ex.Message); } //Premium Financier try { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_GetPremiumFinancier"); ddlPreFinancier.DataSource = ds; ddlPreFinancier.DataValueField = "ID"; ddlPreFinancier.DataTextField = "Name"; ddlPreFinancier.DataBind(); } catch (Exception ex) { showalert(ex.Message); } } protected void ddlAgent_SelectedIndexChanged(object sender, EventArgs e) { //Display the agent contact details int AgentId = 0; if (ddlAgent.SelectedItem.Value != "") { AgentId = Convert.ToInt32(ddlAgent.SelectedItem.Value); } string CType = "AF"; fillContact(AgentId, CType); } //This method fills the Contact dropdown for the selected Agent/Company/Premimum Financer private void fillContact(int AgentId, string CType) { try { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, CommandType.StoredProcedure, "usp_GetAgentContact", new SqlParameter("@AgentId", AgentId), new SqlParameter("@ContactType", CType)); if (CType == "AF") { ddlAgentContact.DataSource = ds; ddlAgentContact.DataValueField = "ID"; ddlAgentContact.DataTextField = "Name"; ddlAgentContact.DataBind(); ////add first item as blank ddlAgentContact.Items.Insert(0, new ListItem(" ", "0")); ddlAgentContact.SelectedIndex = 0; } if (CType == "CF") { ddlCompanyContact.DataSource = ds; ddlCompanyContact.DataValueField = "ID"; ddlCompanyContact.DataTextField = "Name"; ddlCompanyContact.DataBind(); ////add first item as blank ddlCompanyContact.Items.Insert(0, new ListItem(String.Empty, "0")); ddlCompanyContact.SelectedIndex = 0; } if (CType == "PF") { ddlPreFinancierContact.DataSource = ds; ddlPreFinancierContact.DataValueField = "ID"; ddlPreFinancierContact.DataTextField = "Name"; ddlPreFinancierContact.DataBind(); ////add first item as blank ddlPreFinancierContact.Items.Insert(0, new ListItem(String.Empty, "0")); ddlPreFinancierContact.SelectedIndex = 0; } } catch (Exception ex) { showalert(ex.Message); } } protected void ddlCompany_SelectedIndexChanged(object sender, EventArgs e) { //Display the company contact details int AgentId = 0; if (ddlCompany.SelectedItem.Value != "") { AgentId = Convert.ToInt32(ddlCompany.SelectedItem.Value); } string CType = "CF"; fillContact(AgentId, CType); } protected void ddlPreFinancier_SelectedIndexChanged(object sender, EventArgs e) { //Display the Premium Financier contact details int AgentId = 0; if (ddlPreFinancier.SelectedItem.Value != "") { AgentId = Convert.ToInt32(ddlPreFinancier.SelectedItem.Value); } string CType = "PF"; fillContact(AgentId, CType); } protected void IBtnSave_Click(object sender, ImageClickEventArgs e) { //showalert(TxtLeavePage.Text); if (Session["CurrQuoteNumber"] != null) { //Save the Client Info details if (TxtInsured.Text == "" && txtDBAName.Text == "") { //if (txtDBAName.Text == "") //{ if (TxtLeavePage.Text != "yes") { showalert("Please enter Insured or D/B/A Name"); } //} } else { string SaveValue; string Quote = Session["CurrQuoteNumber"].ToString(); //Get the existing PolicyNumber to check if new policynumber is entered string OldPolicyNumber; OldPolicyNumber = GetQuotePolicyNo(Quote); SaveValue = Save(); if (SaveValue != "Error") { //code for Create FUP file QMS.FUP.CreateFupFile cff = new QMS.FUP.CreateFupFile(); cff.CreateFup(Quote); //manual assigning the policy number //Check the policy no and generate string SaveStatus; string PolicyNo = txtPolicyNumber.Text; if (OldPolicyNumber != PolicyNo) { SaveStatus = CheckGeneratePolicyNo(PolicyNo, OldPolicyNumber); if (SaveStatus == "Sucess") { showalert("Quote has been saved successfully"); } else { showalert(SaveStatus); } } else { showalert("Quote has been saved successfully"); } //CreateFupFile(quote); //if (TxtLeavePage.Text != "yes") //{ //} CurrentQuoteNumber.Text = SaveValue; LeftMenu1.LMQuote = SaveValue; } else { showalert("Error! Could not save Quote"); } } } else { if (Request.QueryString["NewName"] != null && Request.QueryString["NewName"] != "") { string SaveValue; SaveValue = Save(); if (SaveValue != "Error") { //code for Create FUP file QMS.FUP.CreateFupFile cff = new QMS.FUP.CreateFupFile(); cff.CreateFup(SaveValue); //manual assigning the policy number //Check the policy no and generate string SaveStatus; string PolicyNo = txtPolicyNumber.Text; string Quote = SaveValue; //Get the existing PolicyNumber to check if new policynumber is entered string OldPolicyNumber; OldPolicyNumber = GetQuotePolicyNo(Quote); if (PolicyNo != "") { SaveStatus = CheckGeneratePolicyNo(PolicyNo, OldPolicyNumber); if (SaveStatus == "Sucess") { if (TxtLeavePage.Text != "yes") { showalert("Quote has been saved successfully"); } } else { showalert(SaveStatus); } } else { if (TxtLeavePage.Text != "yes") { showalert("Quote has been saved successfully"); //Code For Sending Mail After Creating New Quote SendMail(Quote); } } CurrentQuoteNumber.Text = SaveValue; LeftMenu1.LMQuote = SaveValue; } else { showalert("Error! Could not save Quote"); } } } } private void SendMail(string Quote) { System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(); MailMessage message = new MailMessage(); DataSet DSSubject = GetSubject(); DataSet DSQuoteDetails = GetQuoteDetails(Quote); string Contact = ddlAgentContact.SelectedItem.Text; string AgentName = ddlAgent.SelectedItem.Text; DataSet DSMailAddress = GetMailAddress(Server.HtmlEncode(Contact), Server.HtmlEncode(AgentName)); try { if (DSMailAddress.Tables.Count > 0) { if (DSMailAddress.Tables[0].Rows.Count > 0) { if (DSSubject.Tables.Count > 0) { if (DSSubject.Tables[0].Rows.Count > 0) { if (DSQuoteDetails.Tables[0].Rows.Count > 0) { string Name = DSQuoteDetails.Tables[0].Rows[0]["Name"].ToString(); string ToEmailAddress = DSMailAddress.Tables[0].Rows[0]["Email"].ToString(); if (ToEmailAddress == "") { ToEmailAddress = "noagentemail@mail.com"; } message.To.Add(ToEmailAddress); message.From = new System.Net.Mail.MailAddress(DSSubject.Tables[0].Rows[0]["QuoteFrom"].ToString()); MailAddress copy = new MailAddress(DSSubject.Tables[0].Rows[0]["QuoteCC"].ToString()); message.CC.Add(copy); //string Body = DSSubject.Tables[0].Rows[0]["QuoteBody"].ToString(); message.Subject = DSSubject.Tables[0].Rows[0]["QuoteSubject"].ToString(); // Message body content System.Text.StringBuilder sb = new System.Text.StringBuilder(); //sb.Append(Body); //sb.Append("<html><head><title>Test</title><body>"); //sb.Append("<body style=\"margin:50px 0px 0px 0px;\">"); //sb.Append("<table width=\"535\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" bgcolor=\"#f4f7fa\"><tr><td align=\"left\" style=\"font-family:Verdana, Geneva, sans-serif; font-size:15px; color:#5d5d5d; line-height:30px; font-weight:bold; border-bottom:#e2e5e8 dotted 1px; \"> <b>New Quote Details</b></td> </tr> <tr> "); //sb.Append("<td align=\"left\" style=\"font-family:Verdana, Geneva, sans-serif; font-size:10px; color:#5d5d5d; line-height:30px; font-weight:bold; border-bottom:#e2e5e8 dotted 1px; \"> QuoteNumber : " + Quote + "</td> </tr> <tr> "); //sb.Append("<td align=\"left\" style=\"font-family:Verdana, Geneva, sans-serif; font-size:10px; color:#5d5d5d; line-height:30px; font-weight:bold; border-bottom:#e2e5e8 dotted 1px;\" > DBA Name : " + DBAName + "</td> </tr> <tr> <td align=\"left\" style=\"font-family:Verdana, Geneva, sans-serif; font-size:10px; color:#5d5d5d; line-height:30px; font-weight:bold; border-bottom:#e2e5e8 dotted 1px; \"> Insure Name : " + InsuredName + "</td> </tr> <tr> "); //AlternateView htmlView = AlternateView.CreateAlternateViewFromString(sb.ToString(), null, "text/html"); //message.AlternateViews.Add(htmlView); sb.Append("\nThank you for the new submission!"); sb.Append("\n\nYour quote " + "\"" + Name + "\"" + " has been received and assigned the following quote number " + "\"" + Quote + "\"."); sb.Append("\n\n An underwriter will be in contact with you shortly regarding terms or additional information needed."); sb.Append("\n\n Please feel free to call or email if you have any questions."); sb.Append("\n\n Chris-Leef General Agency, Inc.\n P.O. Box 3747 \n Shawnee Mission, KS 66203 \n Phone (913) 631-1232 \n Fax (913) 631-1128 \n contract@chris-leef.com"); message.Body = sb.ToString(); smtp.EnableSsl = false; smtp.Send(message); smtp.Dispose(); } } } } } } catch (Exception ex) { showalert(ex.Message); } finally { message.Dispose(); } } private DataSet GetQuoteDetails(string Quote) { DataSet DSQuoteDetails = SqlHelper.ExecuteDataset(QMSConn, "Usp_GetQuoteName", new SqlParameter("QuoteNumber", Quote)); return DSQuoteDetails; } private DataSet GetMailAddress(string Contact, string AgentName) { string Contact1 = Server.HtmlDecode(Contact); string AgentName1 = Server.HtmlDecode(AgentName); DataSet DSMailAddress = SqlHelper.ExecuteDataset(QMSConn, "usp_GetQuoteMailAddress", new SqlParameter("Contact", Contact1), new SqlParameter("AgentName", AgentName1)); return DSMailAddress; } private DataSet GetSubject() { DataSet DSSubject = SqlHelper.ExecuteDataset(QMSConn, "usp_GetMailSubject"); return DSSubject; } private string GetQuotePolicyNo(string Quote) { string strLineCode = ""; try { SqlCommand cmd = new SqlCommand("usp_GetQuotePolicyNumber", QMSConn); cmd.CommandType = CommandType.StoredProcedure; // Insured cmd.Parameters.Add("@QuoteNumber", SqlDbType.VarChar); cmd.Parameters["@QuoteNumber"].Value = Quote; QMSConn.Open(); strLineCode = Convert.ToString(cmd.ExecuteScalar()); } catch (Exception ex) { } finally { QMSConn.Close(); } return strLineCode; } //private void CreateFupFile(string quote) //{ // try // { // //QMSConn.Open(); // DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_getFupFields", new SqlParameter("@QuoteNumber", quote)); // string fup; // //string path = HttpContext.Current.Server.MapPath("~/PPS/" + "Hansi.FUP"); // string path = ConfigurationManager.AppSettings["MyPath"]; // string FUPFilename; // Random rand = new Random((int)DateTime.Now.Ticks); // int RandomNumber; // RandomNumber = rand.Next(100000, 999999); // FUPFilename = Convert.ToString(RandomNumber); // path = path + "\\" + FUPFilename + ".FUP"; // //"\\Hansi.FUP"; // FileStream fs = new FileStream(path, FileMode.Create); // StreamWriter sw = new StreamWriter(fs); // string StatusCode = ds.Tables[0].Rows[0]["LineCode"].ToString(); // string FupFile; // int len; // if (StatusCode == "B" || StatusCode == "P" || StatusCode == "C") // { // FupFile = "UNDR"; // } // else // { // FupFile = "QUOT"; // } // FupFile = FupFile + ds.Tables[0].Rows[0]["QuoteNumber"].ToString(); // len = 44 - FupFile.Length; // FupFile = FupFile.PadRight(len); // FupFile = FupFile + ds.Tables[0].Rows[0]["Name"].ToString(); // len = 122 - FupFile.Length; // FupFile = FupFile.PadRight(len); // FupFile = FupFile + ds.Tables[0].Rows[0]["UnderwriterInitials"].ToString(); // FupFile = FupFile + "/" + ds.Tables[0].Rows[0]["LineCode"].ToString(); // len = 132 - FupFile.Length; // FupFile = FupFile.PadRight(len); // FupFile = FupFile + ds.Tables[0].Rows[0]["PolicyNumber"].ToString(); // len = 152 - FupFile.Length; // FupFile = FupFile.PadRight(len); // FupFile = FupFile + ds.Tables[0].Rows[0]["Name"].ToString(); // len = 182 - FupFile.Length; // FupFile = FupFile.PadRight(len); // FupFile = FupFile + ds.Tables[0].Rows[0]["EffectiveStartDate"].ToString(); // len = 222 - FupFile.Length; // FupFile = FupFile.PadRight(len); // FupFile = FupFile + ds.Tables[0].Rows[0]["EffectiveEndDate"].ToString(); // sw.WriteLine(FupFile.ToString()); // sw.Close(); // //showalert("test"); // } // catch (Exception ex) // { // //HttpContext.Current.Response.Write(ex.Message); // showalert(ex.Message); // } //} private string Save() { if (TxtInsured.Text == "") { if (txtDBAName.Text == "") { showalert("Please enter Insured or D/B/A Name"); } } string QuoteNumber; int UpdateFlag; if (Session["CurrQuoteNumber"] != null) { QuoteNumber = Session["CurrQuoteNumber"].ToString(); UpdateFlag = 1; } else { //generate Quote Number QuoteNumber = GenQuoteNumber(); UpdateFlag = 0; } string savesuccess = ""; try { SqlCommand cmd = new SqlCommand("usp_AddClientInfo", QMSConn); cmd.CommandType = CommandType.StoredProcedure; // Line code cmd.Parameters.Add("@LineCode", SqlDbType.VarChar); string LineCode; LineCode = ddlLineCode.SelectedItem.Text; LineCode = LineCode.Substring(0, 2); cmd.Parameters["@LineCode"].Value = LineCode; // Status Code string StatusCode; StatusCode = ddlStatusCode.SelectedItem.Text; StatusCode = StatusCode.Substring(0, 1); cmd.Parameters.Add("@StatusCode", SqlDbType.VarChar); cmd.Parameters["@StatusCode"].Value = StatusCode; //IssueDate cmd.Parameters.Add("@IssueDate", SqlDbType.DateTime); cmd.Parameters.Add("@DateTyped", SqlDbType.DateTime); if (txtIssueDate.Text != "") { cmd.Parameters["@IssueDate"].Value = txtIssueDate.Text; cmd.Parameters["@DateTyped"].Value = txtIssueDate.Text; } else { cmd.Parameters["@IssueDate"].Value = SqlDateTime.Null; cmd.Parameters["@DateTyped"].Value = SqlDateTime.Null; } //Insured Name if (TxtInsured.Visible == true) { cmd.Parameters.Add("@Name", SqlDbType.VarChar); cmd.Parameters["@Name"].Value = TxtInsured.Text; } else { cmd.Parameters.Add("@Name", SqlDbType.VarChar); cmd.Parameters["@Name"].Value = TxtOldInsured.Text; } //Address fields cmd.Parameters.Add("@Address1", SqlDbType.VarChar); cmd.Parameters["@Address1"].Value = TxtAddress1.Text; cmd.Parameters.Add("@Address2", SqlDbType.VarChar); cmd.Parameters["@Address2"].Value = TxtAddress2.Text; cmd.Parameters.Add("@City", SqlDbType.VarChar); cmd.Parameters["@City"].Value = TxtCity.Text; cmd.Parameters.Add("@State", SqlDbType.VarChar); cmd.Parameters["@State"].Value = ddlState.SelectedItem.Text; cmd.Parameters.Add("@Zip", SqlDbType.VarChar); cmd.Parameters["@Zip"].Value = TxtZip.Text; //Agent details cmd.Parameters.Add("@AgentId", SqlDbType.BigInt); if (ddlAgent.SelectedItem.Value != "") { cmd.Parameters["@AgentId"].Value = ddlAgent.SelectedItem.Value; } else { cmd.Parameters["@AgentId"].Value = 0; } cmd.Parameters.Add("@AgentContactId", SqlDbType.BigInt); if (ddlAgentContact.Items.Count > 0) { if (ddlAgentContact.SelectedItem.Value != null && ddlAgentContact.SelectedItem.Value != "") { cmd.Parameters["@AgentContactId"].Value = ddlAgentContact.SelectedItem.Value; } else { cmd.Parameters["@AgentContactId"].Value = 0; } } else { cmd.Parameters["@AgentContactId"].Value = 0; } //Company details cmd.Parameters.Add("@CompanyId", SqlDbType.BigInt); if (ddlCompany.SelectedItem.Value != "") { cmd.Parameters["@CompanyId"].Value = ddlCompany.SelectedItem.Value; } else { cmd.Parameters["@CompanyId"].Value = 0; } cmd.Parameters.Add("@CompanyContactId", SqlDbType.BigInt); if (ddlCompanyContact.Items.Count > 0) { if (ddlCompanyContact.SelectedItem.Value != "") { cmd.Parameters["@CompanyContactId"].Value = ddlCompanyContact.SelectedItem.Value; } else { cmd.Parameters["@CompanyContactId"].Value = 0; } } else { cmd.Parameters["@CompanyContactId"].Value = 0; } //Premium Financier details cmd.Parameters.Add("@PremiumFinancierId", SqlDbType.BigInt); if (ddlPreFinancier.SelectedItem.Value != "") { cmd.Parameters["@PremiumFinancierId"].Value = ddlPreFinancier.SelectedItem.Value; } else { cmd.Parameters["@PremiumFinancierId"].Value = 0; } cmd.Parameters.Add("@PremiumFinancierContactId", SqlDbType.BigInt); if (ddlPreFinancierContact.Items.Count > 0) { if (ddlPreFinancierContact.SelectedItem.Value != "" && ddlPreFinancierContact.SelectedItem.Value != null) { cmd.Parameters["@PremiumFinancierContactId"].Value = ddlPreFinancierContact.SelectedItem.Value; } else { cmd.Parameters["@PremiumFinancierContactId"].Value = 0; } } else { cmd.Parameters["@PremiumFinancierContactId"].Value = 0; } cmd.Parameters.Add("@Broker", SqlDbType.Bit); if (ChkBrokerAssigned.Checked) { cmd.Parameters["@Broker"].Value = 1; } else { cmd.Parameters["@Broker"].Value = 0; } cmd.Parameters.Add("@BrokerId", SqlDbType.BigInt); if (ChkBrokerAssigned.Checked == true) { if (ddlBrokerCompany.SelectedItem.Value != "") { cmd.Parameters["@BrokerId"].Value = ddlBrokerCompany.SelectedItem.Value; } else { cmd.Parameters["@BrokerId"].Value = 0; } } else { cmd.Parameters["@BrokerId"].Value = 0; } //Policy Details cmd.Parameters.Add("@PolicyNumber", SqlDbType.VarChar); cmd.Parameters["@PolicyNumber"].Value = txtPolicyNumber.Text; cmd.Parameters.Add("@EffectiveStartDate", SqlDbType.DateTime); if (txtEffStartDate.Text != "") { cmd.Parameters["@EffectiveStartDate"].Value = txtEffStartDate.Text; } else { cmd.Parameters["@EffectiveStartDate"].Value = SqlDateTime.Null; } cmd.Parameters.Add("@EffectiveEndDate", SqlDbType.DateTime); if (txtEffEndDate.Text != "") { cmd.Parameters["@EffectiveEndDate"].Value = txtEffEndDate.Text; } else { cmd.Parameters["@EffectiveEndDate"].Value = SqlDateTime.Null; } //update flag (Add=0, Update=1) cmd.Parameters.Add("@UpdateFlag", SqlDbType.BigInt); cmd.Parameters["@UpdateFlag"].Value = UpdateFlag; //Quote Number cmd.Parameters.Add("@QuoteNumber", SqlDbType.VarChar); cmd.Parameters["@QuoteNumber"].Value = QuoteNumber; //Quote status cmd.Parameters.Add("@Type", SqlDbType.VarChar); cmd.Parameters["@Type"].Value = ddlQuoteStatus.SelectedItem.Value; cmd.Parameters.Add("@DBAName", SqlDbType.VarChar); cmd.Parameters["@DBAName"].Value = txtDBAName.Text; string UserId = ""; if (Session["UserID"] != null) { UserId = Session["UserID"].ToString(); } cmd.Parameters.Add("@UpdatedBy", SqlDbType.VarChar); cmd.Parameters["@UpdatedBy"].Value = UserId; //cmd.Parameters.Add("@Build", SqlDbType.Int); //cmd.Parameters["@Build"].Value = 0; QMSConn.Open(); cmd.ExecuteNonQuery(); savesuccess = QuoteNumber; Session["CurrQuoteNumber"] = QuoteNumber; return savesuccess; } catch (Exception ex) { string Error = ex.Message; LogException.ErrorLogText(Error, 1); savesuccess = "Error"; ////showalert(ex.Message); return savesuccess; //ExceptionPolicy.HandleException(ex, "MyException"); //savesuccess = "Error"; ////showalert(ex.Message); //return savesuccess; } finally { QMSConn.Close(); } } private string GenQuoteNumber() { string NewQuoteNumber; string strAlpha; int i = 65; int DbCount = 0; int CurrQuote = 1; string NewCount; string InsuredQuote = "0"; string TodaysDate = Convert.ToString(System.DateTime.Now.ToString("MM/dd/yyyy")); //get the count of quotes from that database for current Customer try { SqlCommand cmd = new SqlCommand("usp_GetQuoteCount", QMSConn); cmd.CommandType = CommandType.StoredProcedure; // Insured cmd.Parameters.Add("@Name", SqlDbType.VarChar); cmd.Parameters["@Name"].Value = TxtInsured.Text; cmd.Parameters.Add("@FlagCheck", SqlDbType.VarChar); cmd.Parameters["@FlagCheck"].Value = "Insured"; QMSConn.Open(); DbCount = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { } finally { QMSConn.Close(); } if (DbCount > 0) { i = i + DbCount; } strAlpha = ((char)i).ToString(); //get the current quote number for current date //Check for Quote Number with Insured Name try { SqlCommand cmd1 = new SqlCommand("usp_CheckInsuredQuote", QMSConn); cmd1.CommandType = CommandType.StoredProcedure; cmd1.Parameters.Add("@Name", SqlDbType.VarChar); cmd1.Parameters["@Name"].Value = TxtInsured.Text.Trim(); QMSConn.Open(); InsuredQuote = cmd1.ExecuteScalar().ToString(); } catch (Exception ex) { } finally { QMSConn.Close(); } if (InsuredQuote == "0") { try { SqlCommand cmd = new SqlCommand("usp_GetQuoteCount", QMSConn); cmd.CommandType = CommandType.StoredProcedure; // Current Date cmd.Parameters.Add("@Name", SqlDbType.VarChar); cmd.Parameters["@Name"].Value = TodaysDate; cmd.Parameters.Add("@FlagCheck", SqlDbType.VarChar); cmd.Parameters["@FlagCheck"].Value = "CurrentDate"; QMSConn.Open(); CurrQuote = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { } finally { QMSConn.Close(); } if (CurrQuote <= 0) { CurrQuote = 0; } CurrQuote = CurrQuote + 1; if ((CurrQuote.ToString()).Length == 1) { NewCount = "00" + CurrQuote.ToString(); } else if ((CurrQuote.ToString()).Length == 2) { NewCount = "0" + CurrQuote.ToString(); } else { NewCount = CurrQuote.ToString(); } NewQuoteNumber = TodaysDate + NewCount + strAlpha; } else { NewQuoteNumber = InsuredQuote.Substring(0, InsuredQuote.Length - 1) + strAlpha; } return NewQuoteNumber; } //to show Popup messages private void showalert(string message) { string script = @"alert('" + message + "');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", script, true); } //save the broker company details protected void IBtnBrokerSave_Click(object sender, ImageClickEventArgs e) { if (Session["CurrQuoteNumber"] != null) { try { if (ChkBrokerAssigned.Checked) { SqlCommand cmd = new SqlCommand("usp_UpdateBrokerCompany", QMSConn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@BrokerCompany", SqlDbType.BigInt); if (ddlBrokerCompany.SelectedItem.Value != "") { cmd.Parameters["@BrokerCompany"].Value = ddlBrokerCompany.SelectedItem.Value; } else { cmd.Parameters["@BrokerCompany"].Value = 0; } //Quote Number cmd.Parameters.Add("@QuoteNumber", SqlDbType.VarChar); cmd.Parameters["@QuoteNumber"].Value = Session["CurrQuoteNumber"].ToString(); QMSConn.Open(); cmd.ExecuteNonQuery(); } else { showalert("Please Select CheckBox Broker Assigned"); } } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } } } protected void IBtnSaveClose_Click(object sender, ImageClickEventArgs e) { //Save the Client Info details string SaveValue; string Quote = Session["CurrQuoteNumber"].ToString(); //Get the existing PolicyNumber to check if new policynumber is entered string OldPolicyNumber; OldPolicyNumber = GetQuotePolicyNo(Quote); SaveValue = Save(); if (SaveValue != "Error") { //code for Create FUP file QMS.FUP.CreateFupFile cff = new QMS.FUP.CreateFupFile(); cff.CreateFup(Quote); //manual assigning the policy number //Check the policy no and generate string SaveStatus; string PolicyNo = txtPolicyNumber.Text; if (OldPolicyNumber != PolicyNo) { SaveStatus = CheckGeneratePolicyNo(PolicyNo, OldPolicyNumber); if (SaveStatus == "Sucess") { showalert("Quote has been saved successfully"); } else { showalert(SaveStatus); } } else { showalert("Quote has been saved successfully"); } CurrentQuoteNumber.Text = SaveValue; LeftMenu1.LMQuote = SaveValue; Session["CurrQuoteNumber"] = null; Response.Redirect("SearchQuote.aspx"); } else { showalert("Error! Could not save Quote"); } } protected void IBtnMultiQuote_Click(object sender, ImageClickEventArgs e) { showconfirm("Copy all the client details to new record?", "MQuote"); } private void showconfirm(string message, string btnid) { String js; if (btnid == "MQuote") { js = @" if(confirm('" + message + "')==true) " + "document.getElementById('MQuote').click();" + "else " + "document.getElementById('MQuoteNo').click();"; } else if (btnid == "btnAutoGenP") { // js = @" // if(confirm('" + message + "')==true) " + // "{if(confirm('Do you want to Auto Generate a Policy Number?')==true)" + // "document.getElementById('" + btnid + "').click();else document.getElementById('btnEnterPno').click()};"; js = @" if(confirm('" + message + "')==true) " + "{document.getElementById('btnHidShowAutoGenConfirm').click()};"; //MEEnterPolicyNo.Show(); } else { js = @" if(confirm('" + message + "')==true) " + "document.getElementById('" + btnid + "').click();"; } ScriptManager.RegisterStartupScript(this, this.GetType(), "Key", js, true); } protected void MQuote_Click(object sender, EventArgs e) { //create new multi quote if (Session["CurrQuoteNumber"] != null) { string QuoteNumber = Session["CurrQuoteNumber"].ToString(); string InsuredName = TxtInsured.Text; string InsertType = "AllDetails"; Utility CFG = new Utility(); string MultiQuoteSuccess; MultiQuoteSuccess = CFG.CFGenerateMultiQuote(QuoteNumber, InsuredName, InsertType); //fill the form with new quote number if (MultiQuoteSuccess != "Error") { Session["CurrQuoteNumber"] = MultiQuoteSuccess; CurrentQuoteNumber.Text = MultiQuoteSuccess; filldata(MultiQuoteSuccess); } } } protected void MQuoteNo_Click(object sender, EventArgs e) { //create new multi quote if (Session["CurrQuoteNumber"] != null) { string QuoteNumber = Session["CurrQuoteNumber"].ToString(); string InsuredName = TxtInsured.Text; string InsertType = "InsuredDetails"; Utility CFG = new Utility(); string MultiQuoteSuccess; MultiQuoteSuccess = CFG.CFGenerateMultiQuote(QuoteNumber, InsuredName, InsertType); //fill the form with new quote number if (MultiQuoteSuccess != "Error") { Session["CurrQuoteNumber"] = MultiQuoteSuccess; CurrentQuoteNumber.Text = MultiQuoteSuccess; filldata(MultiQuoteSuccess); } } } protected void IBtnPolicyNo_Click(object sender, ImageClickEventArgs e) { string PolicyNoStatus; //get the Status check to generate policy number and check with present quote Status PolicyNoStatus = CheckStatus(); if (ddlStatusCode.SelectedValue != PolicyNoStatus) { showalert("Error! Status should be Binder"); ddlStatusCode.Focus(); } else { //Generate Policy Number showconfirm("Are you sure you want to assign a Policy Number?", "btnAutoGenP"); } } //function to get the Status check to generate Policy Number private string CheckStatus() { string Status = "0"; //Status Code, Line Code, State try { SqlDataReader dr = SqlHelper.ExecuteReader(QMSConn, "usp_GetPolicyNumberStatus"); while (dr.Read()) { Status = dr["Value"].ToString(); } } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } return Status; } //Allow to enter Policy number protected void btnEnterPno_Click(object sender, EventArgs e) { //show popup to enter policy no. MEAuotGenConfirm.Hide(); MEEnterPolicyNo.Show(); } //Auto Generate Policy number protected void btnAutoGenP_Click(object sender, EventArgs e) { //get the avaliable policy number of the company string NewPolicyNumber; int CompanyId = 0; string LineCode = ""; if (ddlCompany.SelectedValue != "") { CompanyId = Convert.ToInt32(ddlCompany.SelectedValue.ToString()); } if (ddlLineCode.SelectedValue != "") { LineCode = ddlLineCode.SelectedItem.Text; LineCode = LineCode.Substring(0, 2); } string OldPolicyNumber; OldPolicyNumber = GetQuotePolicyNo(Session["CurrQuoteNumber"].ToString()); NewPolicyNumber = GetPolicyNumber(CompanyId, LineCode); if (NewPolicyNumber != "0") { //Save Policy Number string QuoteNumber = Session["CurrQuoteNumber"].ToString(); string InsuredName = TxtInsured.Text; SavePolicyNo(NewPolicyNumber, InsuredName, CompanyId, QuoteNumber, OldPolicyNumber); txtPolicyNumber.Text = NewPolicyNumber; MEEnterPolicyNo.Hide(); } else { showalert("No Policy Number Avaliable!"); } } //function to get the avaliable policy number based on company and linecode private string GetPolicyNumber(int CompanyId, string LineCode) { string NewPolicyNumber = ""; try { SqlCommand cmd = new SqlCommand("usp_GetCompanyAvaliablePolicyNo", QMSConn); cmd.CommandType = CommandType.StoredProcedure; // Insured cmd.Parameters.Add("@CompanyId", SqlDbType.BigInt); cmd.Parameters["@CompanyId"].Value = CompanyId; cmd.Parameters.Add("@LineCode", SqlDbType.VarChar); cmd.Parameters["@LineCode"].Value = LineCode; QMSConn.Open(); NewPolicyNumber = cmd.ExecuteScalar().ToString(); } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } return NewPolicyNumber; } //Display a popup to enter Policy Number and Save the policy number after doing the exists validation check protected void IBtnGenPolicyNo_Click(object sender, ImageClickEventArgs e) { MEEnterPolicyNo.Show(); //Check the policy no and generate string SaveStatus; string PolicyNo = TxtGenPolicyNo.Text; string Quote = Session["CurrQuoteNumber"].ToString(); //Get the existing PolicyNumber to check if new policynumber is entered string OldPolicyNumber; OldPolicyNumber = GetQuotePolicyNo(Quote); SaveStatus = CheckGeneratePolicyNo(PolicyNo, OldPolicyNumber); if (SaveStatus == "Sucess") { txtPolicyNumber.Text = PolicyNo; MEEnterPolicyNo.Hide(); } else { MEEnterPolicyNo.Show(); showalert(SaveStatus); } ////int CompanyId = 0; ////if (ddlCompany.SelectedValue != "") ////{ //// CompanyId = Convert.ToInt32(ddlCompany.SelectedValue.ToString()); ////} ////string PolicyNumber = TxtGenPolicyNo.Text; ////string LineCode = ""; ////if (ddlLineCode.SelectedValue != "") ////{ //// LineCode = ddlLineCode.SelectedItem.Text; //// LineCode = LineCode.Substring(0, 2); ////} ////int PolicyNoExists; //////check if policy no exists and assigned to any other quote ////PolicyNoExists = CheckpolicynumberAssigned(CompanyId, PolicyNumber, LineCode); ////string InsuredName = ""; ////string QuoteNumber = Session["CurrQuoteNumber"].ToString(); ////if (PolicyNoExists == 0) ////{ //// //Save Policy Number //// InsuredName = TxtInsured.Text; //// SavePolicyNo(PolicyNumber, InsuredName, CompanyId, QuoteNumber); //// txtPolicyNumber.Text = PolicyNumber; //// MEEnterPolicyNo.Hide(); ////} ////else ////{ //// MEEnterPolicyNo.Show(); //// showalert("Policy Number is already assigned to other Insured!"); ////} //////if (PolicyNoExists != 0) //////{ ////// //Save Policy Number ////// InsuredName = TxtInsured.Text; ////// SavePolicyNo(PolicyNumber, InsuredName, CompanyId, QuoteNumber); ////// txtPolicyNumber.Text = PolicyNumber; ////// MEEnterPolicyNo.Hide(); //////} //////else //////{ ////// MEEnterPolicyNo.Show(); ////// showalert("Policy Number does not exists!"); //////} } //Check the policy no and generate private string CheckGeneratePolicyNo(string GenPolicyNo, string OldPolicyNumber) { string strOldPolicyNumber = OldPolicyNumber; string RecStatus = "0"; int CompanyId = 0; if (ddlCompany.SelectedValue != "") { CompanyId = Convert.ToInt32(ddlCompany.SelectedValue.ToString()); } string PolicyNumber = GenPolicyNo; string LineCode = ""; if (ddlLineCode.SelectedValue != "") { LineCode = ddlLineCode.SelectedItem.Text; LineCode = LineCode.Substring(0, 2); } int PolicyNoExists; //check if policy no exists and assigned to any other quote PolicyNoExists = CheckpolicynumberAssigned(CompanyId, PolicyNumber, LineCode); string InsuredName = ""; string QuoteNumber = Session["CurrQuoteNumber"].ToString(); if (PolicyNoExists == 0) { //Save Policy Number InsuredName = TxtInsured.Text; SavePolicyNo(PolicyNumber, InsuredName, CompanyId, QuoteNumber, strOldPolicyNumber); //txtPolicyNumber.Text = PolicyNumber; RecStatus = "Sucess"; //MEEnterPolicyNo.Hide(); } else { // MEEnterPolicyNo.Show(); //showalert("Policy Number is already assigned to other Insured!"); //update the quote with previous PolicyNumber try { SqlCommand cmd = new SqlCommand("usp_UpdateQuoteWithOldPolicyNumber", QMSConn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@QuoteNumber", SqlDbType.VarChar); cmd.Parameters["@QuoteNumber"].Value = QuoteNumber; cmd.Parameters.Add("@OldPolicyNumber", SqlDbType.VarChar); cmd.Parameters["@OldPolicyNumber"].Value = strOldPolicyNumber; QMSConn.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } RecStatus = "Policy Number is already assigned to other Insured!"; } return RecStatus; } private int CheckpolicynumberAssigned(int CompanyId, string PolicyNumber, string LineCode) { int RecordExists = 0; try { SqlCommand cmd = new SqlCommand("usp_GetCompanyPolicyNumberAssigned", QMSConn); cmd.CommandType = CommandType.StoredProcedure; // Insured cmd.Parameters.Add("@CompanyId", SqlDbType.BigInt); cmd.Parameters["@CompanyId"].Value = CompanyId; cmd.Parameters.Add("@PolicyNumber", SqlDbType.VarChar); cmd.Parameters["@PolicyNumber"].Value = PolicyNumber; cmd.Parameters.Add("@LineCode", SqlDbType.VarChar); cmd.Parameters["@LineCode"].Value = LineCode; QMSConn.Open(); RecordExists = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } return RecordExists; } //save the policy number with Insured name private void SavePolicyNo(string PolicyNumber, string InsuredName, int CompanyId, string QuoteNumber, string OldPolicyNumber) { try { SqlCommand cmd = new SqlCommand("usp_UpdateQuotePolicyNumber", QMSConn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@PolicyNumber", SqlDbType.VarChar); cmd.Parameters["@PolicyNumber"].Value = PolicyNumber; cmd.Parameters.Add("@InsuredName", SqlDbType.VarChar); cmd.Parameters["@InsuredName"].Value = InsuredName; cmd.Parameters.Add("@CompanyId", SqlDbType.BigInt); cmd.Parameters["@CompanyId"].Value = CompanyId; cmd.Parameters.Add("@QuoteNumber", SqlDbType.VarChar); cmd.Parameters["@QuoteNumber"].Value = QuoteNumber; cmd.Parameters.Add("@OldPolicyNumber", SqlDbType.VarChar); cmd.Parameters["@OldPolicyNumber"].Value = OldPolicyNumber; QMSConn.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } } //function to check if the policy no entered exists with the selected company and linecode private int Checkpolicynumber(int CompanyId, string PolicyNumber, string LineCode) { int RecordExists = 0; try { SqlCommand cmd = new SqlCommand("usp_GetCompanyPolicyNumber", QMSConn); cmd.CommandType = CommandType.StoredProcedure; // Insured cmd.Parameters.Add("@CompanyId", SqlDbType.BigInt); cmd.Parameters["@CompanyId"].Value = CompanyId; cmd.Parameters.Add("@PolicyNumber", SqlDbType.VarChar); cmd.Parameters["@PolicyNumber"].Value = PolicyNumber; cmd.Parameters.Add("@LineCode", SqlDbType.VarChar); cmd.Parameters["@LineCode"].Value = LineCode; QMSConn.Open(); RecordExists = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } return RecordExists; } protected void IBtnCancel_Click(object sender, ImageClickEventArgs e) { showconfirm("Cancel Updates?", "btnCancelUpdate"); } protected void btnCancelUpdate_Click(object sender, EventArgs e) { Session["CurrQuoteNumber"] = null; Response.Redirect("SearchQuote.aspx"); } //get the Policy period from policy info private int GetPolicyPeriod(string QuoteNumber) { int PPeriod = 0; try { SqlCommand cmd = new SqlCommand("usp_GetPolicyPeriod", QMSConn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@QuoteNumber", SqlDbType.VarChar); cmd.Parameters["@QuoteNumber"].Value = QuoteNumber; QMSConn.Open(); PPeriod = Convert.ToInt16(cmd.ExecuteScalar()); } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } return PPeriod; } protected void txtEffStartDate_TextChanged(object sender, EventArgs e) { if (Session["CurrQuoteNumber"] != null) { string QuoteNumber = Session["CurrQuoteNumber"].ToString(); int PolicyPeriod; PolicyPeriod = GetPolicyPeriod(QuoteNumber); if (PolicyPeriod != 0) { DateTime EffEndDate; DateTime EffStartDate = Convert.ToDateTime(txtEffStartDate.Text); EffEndDate = EffStartDate.AddMonths(PolicyPeriod); txtEffEndDate.Text = EffEndDate.ToShortDateString(); } } } protected void ibtnSendToBilling_Click(object sender, ImageClickEventArgs e) { string QuoteNumber = Session["CurrQuoteNumber"].ToString(); DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_getcommission", new SqlParameter("@AgentName", ""), new SqlParameter("@QuoteNumber", QuoteNumber)); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Rate"].ToString() == "" || ds.Tables[0].Rows[0]["Rate"].ToString() == "NULL" || ds.Tables[0].Rows[0]["Rate"].ToString() == "0") { showconfirm("Commission Rate is Zero.Do you want to Send to Billng?", "btnHidComisionBilling"); } else { SendToBilling(QuoteNumber); } } else { showconfirm("Commission Rate is Zero.Do you want to Send to Billng?", "btnHidComisionBilling"); } } private void SendToBilling(string QuoteNumber) { if (Session["CurrQuoteNumber"] != null) { //check the Status of the Quote. It should be Binder String BillStatus = CheckStatus(); if (ddlStatusCode.SelectedValue != BillStatus) { if (ddlStatusCode.SelectedValue == "5") { showconfirm("Error! Wrong status to send the billing. Do you want to proceed?", "btnHidSendBillingPolicy"); } else { showalert("Error! Wrong status to send the billing"); ddlStatusCode.Focus(); } } else { int EndorsementNo = 0; try { int i; //i = Convert.ToInt32(SqlHelper.ExecuteScalar(QMSConn, "usp_CheckNavasionDb", new SqlParameter("@QuoteNumber", QuoteNumber))); DataSet dsExist = SqlHelper.ExecuteDataset(QMSConn, "usp_BuildStatus", new SqlParameter("@QuoteNumber", QuoteNumber)); if (dsExist.Tables[0].Rows.Count > 0) { string Status = dsExist.Tables[0].Rows[0]["Status"].ToString(); if (Status == "0") { SqlHelper.ExecuteDataset(QMSConn, "usp_InsertNavasion", new SqlParameter("@QuoteNumber", QuoteNumber), new SqlParameter("@EndorsementNumber", EndorsementNo)); showalert("Successfully sent to billing!!!"); } else { showconfirm1("Quote already billed! Do you want to rebill?"); } } } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } } } } private void showconfirm1(string message) { String js = @" if(confirm('" + message + "')==true) " + "document.getElementById('btnBill').click();"; ScriptManager.RegisterStartupScript(this, this.GetType(), "Key", js, true); } protected void btnBill_Click(object sender, EventArgs e) { if (Session["CurrQuoteNumber"] != null) { string QuoteNumber = Session["CurrQuoteNumber"].ToString(); int EndorsementNo = 0; try { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_InsertNavasion", new SqlParameter("@QuoteNumber", QuoteNumber), new SqlParameter("@EndorsementNumber", EndorsementNo)); //showalert("Saved Successfully!!!"); } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } } } protected void ddlAgent_DataBound(object sender, EventArgs e) { //DropDownList ddl = (DropDownList)sender; //ListItem emptyItem = new ListItem("", ""); //ddl.Items.Insert(0, emptyItem); } protected void test_Click(object sender, EventArgs e) { { if (Session["CurrQuoteNumber"] != null) { //Save the Client Info details if (TxtInsured.Text == "" && txtDBAName.Text == "") { //if (txtDBAName.Text == "") //{ if (TxtLeavePage.Text != "yes") { showalert("Please enter Insured or D/B/A Name"); } //} } else { string SaveValue; SaveValue = Save(); if (SaveValue != "Error") { if (TxtLeavePage.Text != "yes") { showalert("Quote has been saved successfully"); } CurrentQuoteNumber.Text = SaveValue; LeftMenu1.LMQuote = SaveValue; } else { showalert("Error! Could not save Quote"); } } } else { if (Request.QueryString["NewName"] != null && Request.QueryString["NewName"] != "") { string SaveValue; SaveValue = Save(); if (SaveValue != "Error") { if (TxtLeavePage.Text != "yes") { showalert("Quote has been saved successfully"); } CurrentQuoteNumber.Text = SaveValue; LeftMenu1.LMQuote = SaveValue; } else { showalert("Error! Could not save Quote"); } } } } } protected void btnHidShowAutoGenConfirm_Click(object sender, EventArgs e) { MEAuotGenConfirm.Show(); } protected void btnHidSendBillingPolicy_Click(object sender, EventArgs e) { if (Session["CurrQuoteNumber"] != null) { string QuoteNumber = Session["CurrQuoteNumber"].ToString(); int EndorsementNo = 0; try { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "usp_InsertNavasion", new SqlParameter("@QuoteNumber", QuoteNumber), new SqlParameter("@EndorsementNumber", EndorsementNo)); showalert("Successfully sent to billing!!!"); } catch (Exception ex) { showalert(ex.Message); } finally { QMSConn.Close(); } } } protected void btnHidComisionBilling_Click(object sender, EventArgs e) { string QuoteNumber = Session["CurrQuoteNumber"].ToString(); SendToBilling(QuoteNumber); } protected void imgBtnAgent_Click(object sender, ImageClickEventArgs e) { if (ddlAgent.SelectedItem.Text != "") { string Id = ddlAgent.SelectedValue; string Status = "Agent"; DataSet ds = GetMemo(Status, Id); mpeAgent.Show(); } else { showalert("No Agent Name is Selected"); } } protected void ImgBtnCompany_Click(object sender, ImageClickEventArgs e) { if (ddlCompany.SelectedItem.Text != "") { string Id = ddlCompany.SelectedValue; string Status = "Company"; DataSet ds = GetMemo(Status, Id); mpeAgent.Show(); } else { showalert("No Company Name is Selected"); } } public DataSet GetMemo(string Status, string Id) { DataSet ds = SqlHelper.ExecuteDataset(QMSConn, "Usp_GetMemo", new SqlParameter("@Id", Id), new SqlParameter("@Status", Status)); if (ds.Tables[0].Rows.Count > 0) { lblPhone.Text = ds.Tables[0].Rows[0]["Phone"].ToString(); lblName.Text = ds.Tables[0].Rows[0]["Name"].ToString(); lblMemo.Text = ds.Tables[0].Rows[0]["Memo"].ToString(); } return ds; } protected void ImgBtnPremierFinance_Click(object sender, ImageClickEventArgs e) { if (ddlPreFinancier.SelectedItem.Text != "") { string Id = ddlPreFinancier.SelectedValue; string Status = "Premium"; DataSet ds = GetMemo(Status, Id); mpeAgent.Show(); } else { showalert("No Premier Name is Selected"); } } protected void ImgBtnCancel_Click(object sender, ImageClickEventArgs e) { Response.Redirect("ClientInfo.aspx"); } } }jerryjoseph
Contributor
6740 Points
1257 Posts
Re: find control in Asp.net page with Master page
Mar 02, 2012 10:19 AM|LINK
You didn't paste the code correctly. You pasted this.
private void LoopButtons(ControlCollection controlCollection) { foreach (var control in controlCollection) { if (control is Button) { // This is sample code // You get each button here // Do something else here Response.Write(((Button)control).Text); } } }It should be like this.
private void LoopButtons(ControlCollection controlCollection) { foreach (var control in controlCollection) { if (control is Button) { // This is sample code // You get each button here // Do something else here Response.Write(((Button)control).Text); } if (control.Controls.Count > 0) { LoopButtons(control.Controls); } } }That piece of code is needed to make it recursive.
An observation: The Page_Load is too fat. you have to refactor it.
linkedin | twitter | www.jerryjoseph.net
rajuthri
Member
16 Points
35 Posts
Re: find control in Asp.net page with Master page
Mar 05, 2012 05:29 AM|LINK
ThanX!!!!
With your idea i wrote other code ..
private void ListControlCollections()
{
ArrayList controlList = new ArrayList();
AddControls(Page.Controls, controlList);
}
private void AddControls(ControlCollection page, ArrayList controlList)
{
foreach (Control c in page)
{
if (c.ID != null)
{
if (c is ImageButton)
{
ImageButton b = (ImageButton)c;
b.Enabled = false;
}
}
if (c.HasControls())
{
AddControls(c.Controls, controlList);
}
}
}