[text] frmreliance

Viewer

copydownloadembedprintName: frmreliance
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. using System.Configuration;
  9. using Reliance.CMS.Common.Helper;
  10. using System.IO;
  11. using System.Runtime.Remoting.Messaging;
  12. using Reliance_CMS.FSMService;
  13. using Reliance_CMS.SolomonService;
  14. using SHDocVw;
  15. using System.Data;
  16. using System.Runtime.InteropServices;
  17.  
  18. namespace Reliance_CMS
  19. {
  20.     /// <summary>
  21.     /// Author: Mohammed El-Araby
  22.     /// Created: October, 2012
  23.     /// Description: Desktop Form
  24.     /// </summary>
  25.     public partial class FrmReliance_CMS : Form
  26.     {
  27.  
  28.         [DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  29.         internal static extern bool SetProcessWorkingSetSize(IntPtr pProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);
  30.  
  31.         [DllImport("KERNEL32.DLL", EntryPoint = "GetCurrentProcess", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  32.         internal static extern IntPtr GetCurrentProcess();
  33.  
  34.         StickyMessage stickyMessage = new StickyMessage();
  35.         private SyncSrv.SynchronizationServiceClient _syncServClient;
  36.         private SolomonService.CMS_ServiceBookingClient SolomonService;
  37.         private SolomonService.SolomonCustomerInfo solomonCustomer;
  38.         private FSMService.CMS_ServiceBookingClient FSMService;
  39.         private FSMService.SolomonCustomerInfo fsmCustomer;
  40.  
  41.  
  42.         private Thread _thrSyncSer;
  43.         private ServiceCallParams _serviceCallParams;
  44.         private ServiceCallParams _SiteSearchserviceCallParams;
  45.         private string _creationTypeParam;
  46.         private bool _isNewCustomer;
  47.  
  48.         public bool HasNewNote
  49.         {
  50.             get
  51.             {
  52.                 var hf = GetHiddenNote();
  53.                 if (hf != null)
  54.                     return hf.GetAttribute("value") == "1" ? true : false;
  55.                 return false;
  56.             }
  57.             set
  58.             {
  59.                 var hf = GetHiddenNote();
  60.                 if (hf != null)
  61.                     hf.SetAttribute("value", value ? "1" : "0");
  62.  
  63.             }
  64.         }
  65.  
  66.         private HtmlElement GetHiddenNote()
  67.         {
  68.             HtmlElement element = null;
  69.  
  70.             if (wbCRMSuperScreen.Document != null)
  71.             {
  72.                 if (wbCRMSuperScreen.Document.Window.Frames.Count > 0)
  73.                 {
  74.                     foreach (HtmlWindow item in wbCRMSuperScreen.Document.Window.Frames)
  75.                     {
  76.                         if (item.Frames.Count > 0)
  77.                         {
  78.                             foreach (HtmlWindow item1 in item.Frames)
  79.                             {
  80.                                 element = item1.Document.GetElementById("hdnNote");
  81.                                 if (element != null)
  82.                                     return element;
  83.  
  84.                             }
  85.                         }
  86.                     }
  87.                 }
  88.             }
  89.  
  90.             return element;
  91.         }
  92.  
  93.         // create new popup
  94.         FrmPopup popup;
  95.  
  96.         public FrmReliance_CMS()
  97.         {
  98.             InitializeComponent();
  99.         }
  100.  
  101.         private void frmReliance_CMS_Load(object sender, EventArgs e)
  102.         {
  103.             //Log method start
  104.             LogWrapper.LogMethodStart("frmReliance_CMS_Load(object sender, EventArgs e)", new string[] { "sender", "e" }, new object[] { sender, e });
  105.  
  106.             DBConfigurations.LoadConfigurations();
  107.  
  108.             // Code updated By Mohamed ElAtafy to View CRM Organization Name ISR# 52899
  109.             LblCRMIndicator.Text = ConfigurationManager.AppSettings["CMSInstanceDisplayName"];
  110.             LblCRMIndicator2.Text = LblCRMIndicator.Text;
  111.             /***********************************************************************************************************/
  112.  
  113.             popup = new FrmPopup(false);
  114.             dgvSearchResultSearchSites.AutoGenerateColumns = false;
  115.             dgvSearchResult.AutoGenerateColumns = false;
  116.             Screen Srn = Screen.PrimaryScreen;
  117.             int tempHeight = Srn.Bounds.Width;
  118.             int tempWidth = Srn.Bounds.Height;
  119.             if (tempHeight == 1024 && tempWidth == 768)
  120.             {
  121.                 this.Size = new Size(832, 726);
  122.                 dgvSearchResult.Columns["CustomerCode"].Width = 80;
  123.                 dgvSearchResult.Columns["PremiseCode"].Width = 80;
  124.                 dgvSearchResult.Columns["CustomerName"].Width = 120;
  125.                 dgvSearchResult.Columns["Address2"].Width = 80;
  126.                 dgvSearchResult.Columns["CustomerType"].Width = 80;
  127.                 dgvSearchResult.Columns["CustomerStatus"].Width = 75;
  128.                 dgvSearchResult.Columns["CrmID"].Width = 100;
  129.                 dgvSearchResult.Columns["CrmGUID"].Width = 100;
  130.             }
  131.             this.Height = Screen.PrimaryScreen.WorkingArea.Height;
  132.             try
  133.             {
  134.                 //Fill customer type dropdown list
  135.                 BindCustomerTypeddl();
  136.  
  137.                 //Watch for changes in the given Sticky key. By calling this function, you register to receive events of type StickyValueChanged for the key you specify
  138.                 stickyData.WatchStickyValue(ConfigurationManager.AppSettings["UPSTARTAppID"], ConfigurationManager.AppSettings["SEARCHKey"]);
  139.                 stickyData.WatchStickyValue(ConfigurationManager.AppSettings["AvayaAppID"], ConfigurationManager.AppSettings["AvayaKey"]);
  140.             }
  141.             catch (Exception exception)
  142.             {
  143.                 HandleExceptions(exception);
  144.             }
  145.             CenterToScreen();
  146.  
  147.             //To Add new Web Control on the screen called webQASSearch
  148.             //webQASSearch.Navigate("http://" + ConfigurationManager.AppSettings["ServerName"] + "/" + ConfigurationManager.AppSettings["WebResourcesVirualDirectory"] + "/CMSQAS.htm");
  149.  
  150.             //Log method End
  151.             LogWrapper.LogMethodEnd("frmReliance_CMS_Load(object sender, EventArgs e)", true);
  152.  
  153.             LoadLookups();
  154.  
  155.         }
  156.  
  157.         private void LoadLookups()
  158.         {
  159.             LoadDirections();
  160.             LoadSuffix();
  161.             LoadUnitType();
  162.             LoadProvince();
  163.         }
  164.  
  165.         private void LoadProvince()
  166.         {
  167.             string CanadaCode = "CAN";
  168.             if(ConfigurationManager.AppSettings["CanadaCode"]!=null && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["CanadaCode"]))
  169.                 CanadaCode=ConfigurationManager.AppSettings["CanadaCode"];
  170.  
  171.              DataSet ds = Reliance.CMS.CRM.Helper.CMSCRMDataAccessWrapper.GetProvincesByCountry(true, CanadaCode);
  172.             if (ds != null)
  173.             {
  174.                 ddlProvince.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
  175.                 ddlProvince.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
  176.                 ddlProvince.AutoCompleteSource = AutoCompleteSource.ListItems;
  177.                 DataTable t = new DataTable();
  178.  
  179.                 t.Columns.Add("Description", typeof(string));
  180.                 t.Columns.Add("Code", typeof(string));
  181.  
  182.                 foreach (DataRow dr in ds.Tables[0].Rows)
  183.                 {
  184.  
  185.                     //Description
  186.                   //  ddlProvince.Items.Add(dr["Code"]).ToString();
  187.                     t.Rows.Add(dr["Description"].ToString(), dr["Code"].ToString());
  188.                 }
  189.                 ddlProvince.DataSource = t;
  190.                 ddlProvince.ValueMember = "Code";
  191.                 ddlProvince.DisplayMember = "Description";
  192.                 ddlProvince.SelectedItem = null;
  193.  
  194.             }
  195.         }
  196.  
  197.         private void LoadUnitType()
  198.         {
  199.             DataSet ds = Reliance.CMS.CRM.Helper.CMSCRMDataAccessWrapper.GetUnitTypes(true);
  200.             if (ds != null)
  201.             {
  202.  
  203.                 ddlUnitType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
  204.                 ddlUnitType.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
  205.                 ddlUnitType.AutoCompleteSource = AutoCompleteSource.ListItems;
  206.  
  207.                 DataTable t = new DataTable();
  208.                 t.Columns.Add("Code", typeof(string));
  209.                 t.Columns.Add("Id", typeof(string));
  210.  
  211.                 foreach (DataRow dr in ds.Tables[0].Rows)
  212.                 {
  213.                     t.Rows.Add(dr["Code"].ToString(), dr["Id"].ToString());
  214.                 }
  215.  
  216.                 ddlUnitType.DataSource = t;
  217.                 ddlUnitType.ValueMember = "Id";
  218.                 ddlUnitType.DisplayMember = "Code";
  219.                 ddlUnitType.SelectedItem = null;
  220.             }
  221.         }
  222.  
  223.         private void LoadSuffix()
  224.         {
  225.             DataSet ds = Reliance.CMS.CRM.Helper.CMSCRMDataAccessWrapper.GetSuffix(true);
  226.             if (ds != null)
  227.             {
  228.  
  229.                 ddlSuffix.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
  230.                 ddlSuffix.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
  231.                 ddlSuffix.AutoCompleteSource = AutoCompleteSource.ListItems;
  232.  
  233.                 DataTable t = new DataTable();
  234.                 t.Columns.Add("Code", typeof(string));
  235.                 t.Columns.Add("Id", typeof(string));
  236.  
  237.                 foreach (DataRow dr in ds.Tables[0].Rows)
  238.                 {
  239.                     t.Rows.Add(dr["Code"].ToString(), dr["Id"].ToString());
  240.                 }
  241.  
  242.                 ddlSuffix.DataSource = t;
  243.                 ddlSuffix.ValueMember = "Id";
  244.                 ddlSuffix.DisplayMember = "Code";
  245.                 ddlSuffix.SelectedItem = null;
  246.             }
  247.         }
  248.  
  249.         private void LoadDirections()
  250.         {
  251.  
  252.             DataSet ds = Reliance.CMS.CRM.Helper.CMSCRMDataAccessWrapper.GetDirections(true);
  253.             if (ds != null)
  254.             {
  255.                 //Pre Direction
  256.                 ddlPreDir.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
  257.                 ddlPreDir.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
  258.                 ddlPreDir.AutoCompleteSource = AutoCompleteSource.ListItems;
  259.                 ////Post Direction
  260.                 ddlPostDir.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
  261.                 ddlPostDir.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
  262.                 ddlPostDir.AutoCompleteSource = AutoCompleteSource.ListItems;
  263.  
  264.                 DataTable t1 = new DataTable();
  265.                 t1.Columns.Add("Code", typeof(string));
  266.                 t1.Columns.Add("Id", typeof(string));
  267.  
  268.                 DataTable t2 = new DataTable();
  269.                 t2.Columns.Add("Code", typeof(string));
  270.                 t2.Columns.Add("Id", typeof(string));
  271.  
  272.  
  273.                 foreach (DataRow dr in ds.Tables[0].Rows)
  274.                 {
  275.                     t1.Rows.Add(dr["Code"].ToString(), dr["Id"].ToString());
  276.                     t2.Rows.Add(dr["Code"].ToString(), dr["Id"].ToString());
  277.                 }
  278.  
  279.                 ddlPreDir.DataSource = t1;
  280.                 ddlPreDir.ValueMember = "Id";
  281.                 ddlPreDir.DisplayMember = "Code";
  282.                 ddlPreDir.SelectedItem = null;
  283.  
  284.  
  285.                 ddlPostDir.DataSource = t2;
  286.                 ddlPostDir.ValueMember = "Id";
  287.                 ddlPostDir.DisplayMember = "Code";
  288.                 ddlPostDir.SelectedItem = null;
  289.             }
  290.         }
  291.  
  292.         /// <summary>
  293.         /// The connection with CTI System is fully established
  294.         /// </summary>
  295.         private void stickyData_NowConnected(object sender, EventArgs e)
  296.         {
  297.             //Log method start
  298.             LogWrapper.LogMethodStart("stickyData_NowConnected(object sender, EventArgs e)", new string[] { "sender", "e" }, new object[] { sender, e });
  299.  
  300.             //Log Message: Now Connected 
  301.             LogWrapper.LogInformation(Messages.Inf0101020001, "0101020001");
  302.  
  303.             //Log method End
  304.             LogWrapper.LogMethodEnd("stickyData_NowConnected(object sender, EventArgs e)", true);
  305.         }
  306.  
  307.         /// <summary>
  308.         /// The connection with CTI System is lost
  309.         /// </summary>
  310.         private void stickyData_NowDisconnected(object sender, EventArgs e)
  311.         {
  312.             //Log method start
  313.             LogWrapper.LogMethodStart("stickyData_NowDisconnected(object sender, EventArgs e)", new string[] { "sender", "e" }, new object[] { sender, e });
  314.  
  315.             //Log Message: Now Disconnected 
  316.             LogWrapper.LogInformation(Messages.Inf0101030001, "0101030001");
  317.  
  318.             //Log method End
  319.             LogWrapper.LogMethodEnd("stickyData_NowDisconnected(object sender, EventArgs e)", true);
  320.         }
  321.  
  322.         /// <summary>
  323.         /// This event is fired when a problem is encountered with CTI connection, such as a version mismatch between the control and the CT client software
  324.         /// </summary>
  325.         private void stickyData_Problem(object sender, UpstreamWorks.SDK.Components.ProblemEventArgs e)
  326.         {
  327.             //Log method start
  328.             LogWrapper.LogMethodStart("stickyData_Problem(object sender, UpstreamWorks.SDK.Components.ProblemEventArgs e)", new string[] { "sender", "e" }, new object[] { sender, e });
  329.  
  330.             //Log Message: A problem is encountered with CTI connection 
  331.             LogWrapper.LogInformation(Messages.Err0101040001, "0101040001");
  332.  
  333.             //Log method End
  334.             LogWrapper.LogMethodEnd("stickyData_Problem(object sender, UpstreamWorks.SDK.Components.ProblemEventArgs e)", true);
  335.         }
  336.  
  337.         /// <summary>
  338.         /// This event fires when the sticky value being watched has changed
  339.         /// </summary>
  340.         private void stickyData_StickyValueChanged(object sender, UpstreamWorks.SDK.Components.StickyValueChangedEventArgs e)
  341.         {
  342.             //Log method start
  343.             LogWrapper.LogMethodStart("stickyData_StickyValueChanged(object sender, UpstreamWorks.SDK.Components.StickyValueChangedEventArgs e)", new string[] { "sender", "e" }, new object[] { sender, e });
  344.  
  345.             try
  346.             {
  347.                 stickyMessage.ApplicationID = e.ApplicationId.Trim();
  348.                 stickyMessage.Msgkey = e.Key.Trim();
  349.                 stickyMessage.MsgValue = e.Value.Trim();
  350.  
  351.                 if (stickyMessage.IsUpStartAckMsg())
  352.                 {
  353.                     //Ignore and log debug
  354.                     LogWrapper.LogInformation(Messages.Inf0101070001);
  355.                 }
  356.                 else if (stickyMessage.IsCMSAckMsg())
  357.                 {
  358.                     //Log and display a notification message i.e. message has been successfully sent to Upstart
  359.                     LogWrapper.LogInformation(Messages.Inf0101070002);
  360.                 }
  361.                 else if (stickyMessage.IsCMSMsg())
  362.                 {
  363.                     //Ignore and log debug
  364.                     LogWrapper.LogInformation(Messages.Inf0101070003);
  365.                 }
  366.                 else if (stickyMessage.ValidateAvayaMessage())
  367.                 {
  368.                     //Reset application controls 
  369.                     ResetCMSDesktopApp();
  370.  
  371.                     //Open either search screen or super screen
  372.                     var objCust = stickyMessage.ParseAvayaMsg();
  373.  
  374.                     // Get Cust Id from the CRM and the customer type
  375.                     SearchByCustPremCode(objCust);
  376.                 }
  377.                 else if (stickyMessage.ValidateStickyMessage())
  378.                 {
  379.                     //Reset application controls 
  380.                     ResetCMSDesktopApp();
  381.  
  382.                     //Open either search screen or super screen
  383.                     OpenSuitableTab(stickyMessage.ParseSearchMsg());
  384.  
  385.                     //Normal UpStart messages to be processed
  386.                     SendAckMSG();
  387.                 }
  388.             }
  389.             catch (Exception exception)
  390.             {
  391.                 HandleExceptions(exception);
  392.             }
  393.  
  394.             //Log method End
  395.             LogWrapper.LogMethodEnd("stickyData_StickyValueChanged(object sender, UpstreamWorks.SDK.Components.StickyValueChangedEventArgs e)", true);
  396.         }
  397.  
  398.         /// <summary>
  399.         /// Send successfully received acknowledgement message to UpStart 
  400.         /// </summary>
  401.         void SendAckMSG()
  402.         {
  403.             //Log method start
  404.             LogWrapper.LogMethodStart("SendAckMSG()", null, null);
  405.  
  406.             //Send acknowledgement to UpStart
  407.             stickyData.SetSticky(stickyMessage.ApplicationID, stickyMessage.Msgkey, stickyMessage.SuccessMSG);
  408.  
  409.             //Log method End
  410.             LogWrapper.LogMethodEnd("SendAckMSG()", true);
  411.         }
  412.  
  413.         /// <summary>
  414.         /// Open either advanced search tab or CRM tab with customer info
  415.         /// </summary>
  416.         /// <param name="customer">Customer Information</param>
  417.         void OpenSuitableTab(Customer customer)
  418.         {
  419.             //Log method start
  420.             LogWrapper.LogMethodStart("OpenSuitableTab(Customer customer)", new string[] { "customer" }, new object[] { customer });
  421.  
  422.             if (customer.Match.ToUpper() == stickyMessage.MultipleMatch || customer.Match.ToUpper() == stickyMessage.MultipleMatchSystem)
  423.             {
  424.                 //Multiple match
  425.                 //Open advanced search with customer info
  426.                 BindCusInfoToSearchScreen(customer);
  427.  
  428.                 //Display the matched records in the gridview
  429.                 SearchCustomer();
  430.             }
  431.             else if (customer.Match.ToUpper() == stickyMessage.NoMatch)
  432.             {
  433.                 //No match
  434.                 //Open advanced search with customer info
  435.                 BindCusInfoToSearchScreen(customer);
  436.                 //Empty gripview with message no data found
  437.             }
  438.             else
  439.             {
  440.                 //Single match
  441.                 //Open the super screen with customer info
  442.                 OpenAccountInfoTab(customer);
  443.             }
  444.  
  445.             //Log method End
  446.             LogWrapper.LogMethodEnd("OpenSuitableTab(Customer customer)", true);
  447.         }
  448.  
  449.         /// <summary>
  450.         /// Open advanced search with customer info.
  451.         /// </summary>
  452.         /// <param name="customer">Customer Information</param>
  453.         void BindCusInfoToSearchScreen(Customer customer)
  454.         {
  455.             //Log method start
  456.             LogWrapper.LogMethodStart("BindCusInfoToSearchScreen(Customer customer)", new string[] { "customer" }, new object[] { customer });
  457.  
  458.             //Open search screen
  459.             tcRelianceDesktop.SelectedTab = tbCustomersSearch;
  460.  
  461.             //Bing customer info. to the screen 
  462.             if (!string.IsNullOrEmpty(customer.Phone))
  463.                 txtPhoneNo.Text = customer.Phone;
  464.             if (!string.IsNullOrEmpty(customer.Street))
  465.                 txtStreetNo.Text = customer.Street;
  466.             if (!string.IsNullOrEmpty(customer.Bkend))
  467.             {
  468.                 //Banner customer
  469.                 if (customer.Bkend.ToUpper() == stickyMessage.BannerCust)
  470.                     ddlCustomerType.SelectedItem = Messages.CustRental;
  471.                 //Solomon Customer
  472.                 else
  473.                     ddlCustomerType.SelectedItem = Messages.CustWarranty;
  474.             }
  475.             else
  476.                 //No match
  477.                 ddlCustomerType.SelectedItem = Messages.CustBoth;
  478.  
  479.             //Log method End
  480.             LogWrapper.LogMethodEnd("BindCusInfoToSearchScreen(Customer customer)", true);
  481.         }
  482.  
  483.         Customer _Customer = new Customer();
  484.         string PageLayoutId = "";
  485.  
  486.         /// <summary>
  487.         /// Open Account Information Tab
  488.         /// </summary>
  489.         /// <param name="customer">Customer Information</param>
  490.         void OpenAccountInfoTab(Customer customer)
  491.         {
  492.             _isNewCustomer = false;
  493.             _Customer = customer;
  494.             //Log method start
  495.             LogWrapper.LogMethodStart("OpenAccountInfoTab(Customer customer)", new string[] { "customer" }, new object[] { customer });
  496.  
  497.  
  498.             if (!string.IsNullOrEmpty(customer.Bkend) && customer.Bkend.Equals(stickyMessage.BannerCust))
  499.                 //Banner customer
  500.                 PageLayoutId = ConfigurationManager.AppSettings["BannerPageLayoutId"];
  501.             else
  502.                 //Solomon customer
  503.                 PageLayoutId = ConfigurationManager.AppSettings["SolomonPageLayoutId"];
  504.  
  505.             string curDir = Directory.GetCurrentDirectory();
  506.  
  507.             //WaitUntilIEisFree();
  508.  
  509.             //CreateNewIEControl();
  510.  
  511.             CheckOpenedServiceBookingWindow();
  512.             RefreshwebBroswerControl();
  513.  
  514.             wbCRMSuperScreen.Navigate(String.Format("file:///{0}/progress.htm", curDir));
  515.  
  516.  
  517.             refreshed = false;
  518.  
  519.             //Open super screen
  520.             tcRelianceDesktop.SelectedTab = tbAccountInfo;
  521.  
  522.             //Log method End
  523.             LogWrapper.LogMethodEnd("OpenAccountInfoTab(Customer customer)", true);
  524.         }
  525.         /// <summary>
  526.         /// Webbroswer control has extensive memory leak issue. This function does not totlally resolve the isssue
  527.         /// but reduces the effect 
  528.         /// </summary>
  529.         private void RefreshwebBroswerControl()
  530.         {
  531.             this.wbCRMSuperScreen.Dispose();
  532.             this.wbCRMSuperScreen = null;
  533.             this.tbAccountInfo.Controls.Remove(this.wbCRMSuperScreen);
  534.  
  535.             IntPtr pHandle = GetCurrentProcess();
  536.             SetProcessWorkingSetSize(pHandle, -1, -1);
  537.  
  538.             GC.Collect();
  539.             GC.WaitForPendingFinalizers();
  540.             GC.Collect();
  541.  
  542.             this.wbCRMSuperScreen = new System.Windows.Forms.WebBrowser();
  543.             this.wbCRMSuperScreen.Dock = System.Windows.Forms.DockStyle.Fill;
  544.             this.wbCRMSuperScreen.Location = new System.Drawing.Point(3, 3);
  545.             this.wbCRMSuperScreen.Margin = new System.Windows.Forms.Padding(0);
  546.             this.wbCRMSuperScreen.MinimumSize = new System.Drawing.Size(20, 20);
  547.             this.wbCRMSuperScreen.Name = "wbCRMSuperScreen";
  548.             this.wbCRMSuperScreen.Size = new System.Drawing.Size(1013, 697);
  549.             this.wbCRMSuperScreen.TabIndex = 6;
  550.             this.wbCRMSuperScreen.Url = new System.Uri("", System.UriKind.Relative);
  551.             this.wbCRMSuperScreen.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.wbCRMSuperScreen_DocumentCompleted);
  552.             this.wbCRMSuperScreen.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(this.wbCRMSuperScreen_Navigated);
  553.             this.tbAccountInfo.Controls.Add(this.wbCRMSuperScreen);
  554.             this.wbCRMSuperScreen.Show();
  555.         }
  556.         void OpenNewCustomerTab()
  557.         {
  558.             _isNewCustomer = true;
  559.             LogWrapper.LogMethodStart("OpenNewCustomerTab()", null, null);
  560.  
  561.             PageLayoutId = ConfigurationManager.AppSettings["NewCustomerPageLayoutId"];
  562.  
  563.             string curDir = Directory.GetCurrentDirectory();
  564.  
  565.             CheckOpenedServiceBookingWindow();
  566.  
  567.             wbCRMSuperScreen.Navigate(String.Format("file:///{0}/progress.htm", curDir));
  568.  
  569.             //Open super screen
  570.             tcRelianceDesktop.SelectedTab = tbAccountInfo;
  571.  
  572.             LogWrapper.LogMethodEnd("OpenNewCustomerTab()", true);
  573.         }
  574.  
  575.         /// <summary>
  576.         /// tarek said: performance fix and resource in use fix
  577.         /// </summary>
  578.         private void CreateNewIEControl()
  579.         {
  580.             wbCRMSuperScreen.Dispose();
  581.             System.GC.Collect();
  582.             this.wbCRMSuperScreen = new System.Windows.Forms.WebBrowser();
  583.             this.wbCRMSuperScreen.Dock = System.Windows.Forms.DockStyle.Fill;
  584.             this.wbCRMSuperScreen.Location = new System.Drawing.Point(3, 3);
  585.             this.wbCRMSuperScreen.Margin = new System.Windows.Forms.Padding(0);
  586.             this.wbCRMSuperScreen.MinimumSize = new System.Drawing.Size(20, 20);
  587.             this.wbCRMSuperScreen.Name = "wbCRMSuperScreen";
  588.             this.wbCRMSuperScreen.Size = new System.Drawing.Size(1006, 899);
  589.             this.wbCRMSuperScreen.TabIndex = 6;
  590.             this.wbCRMSuperScreen.Url = new System.Uri("", System.UriKind.Relative);
  591.             this.tbAccountInfo.Controls.Add(this.wbCRMSuperScreen);
  592.             this.wbCRMSuperScreen.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(this.wbCRMSuperScreen_Navigated);
  593.  
  594.         }
  595.  
  596.         /// <summary>
  597.         /// Handle application exceptions
  598.         /// </summary>
  599.         /// <param name="exception">Exception</param>
  600.         void HandleExceptions(Exception exception)
  601.         {
  602.             //Log method start
  603.             LogWrapper.LogMethodStart("HandleExceptions(Exception exception)", new string[] { "exception" }, new object[] { exception });
  604.  
  605.             LogWrapper.LogError(exception.Message);
  606.  
  607.             //Only validation exceptions(custom exceptions) will be sent to UPSTART
  608.             if (exception.Source == stickyMessage.ExceptionSource)
  609.                 stickyData.SetSticky(stickyMessage.ApplicationID, stickyMessage.Msgkey, stickyMessage.FailureMSG + exception.Message);
  610.  
  611.             if (ConfigurationManager.AppSettings["ThrowExceptions"] == Enums.ThrowExceptions.Yes.ToString())
  612.                 throw exception;
  613.             else
  614.                 MessageBox.Show(Messages.Err0101080001, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  615.  
  616.             //Log method End
  617.             LogWrapper.LogMethodEnd("HandleExceptions(Exception exception)", true);
  618.         }
  619.  
  620.         /// <summary>
  621.         /// Reset application controls
  622.         /// </summary>
  623.         public void ResetCMSDesktopApp()
  624.         {
  625.             //reset search screen controls
  626.             ResetAdvancedSearch(pnlSearchFields);
  627.  
  628.             //clear grid
  629.             var lstCustomer = new List<SearchSrv.respCustomerTable>(); // Empty data source to avoid losing grid columns if we set its data source with null
  630.             dgvSearchResult.DataSource = lstCustomer;
  631.             lblNotMsg.Text = string.Empty;
  632.             lblSearchResults.Text = @"Search Results";
  633.             ddlPreDir.SelectedItem = null;
  634.             ddlSuffix.SelectedItem = null;
  635.             ddlPostDir.SelectedItem = null;
  636.             ddlProvince.SelectedItem = null;
  637.             ddlUnitType.SelectedItem = null;
  638.             validCity = validFirstName = validLastName = ValidPhoneNo = validPostalCode = validPostDir = validPreDir = validProvince = validStreetName = validStreetNo = validSuffix = validUnitNum = validUnitType = true;
  639.         }
  640.  
  641.         /// <summary>
  642.         /// Reset Advanced search tab controls
  643.         /// </summary>
  644.         /// <param name="form">Application Form</param>
  645.         public void ResetAdvancedSearch(Control form)
  646.         {
  647.             //remove recursion and clear controls by their names
  648.             foreach (Control ctrl in form.Controls)
  649.             {
  650.                 if (ctrl.Controls.Count > 0)
  651.                     ResetAdvancedSearch(ctrl);
  652.  
  653.                 //Reset the control
  654.                 Reset(ctrl);
  655.             }
  656.         }
  657.  
  658.         /// <summary>
  659.         /// Reset application control
  660.         /// </summary>
  661.         /// <param name="ctrl">Control to be reset</param>
  662.         public void Reset(Control ctrl)
  663.         {
  664.             TextBox tb = ctrl as TextBox;
  665.             if (tb != null)
  666.             {
  667.                 if (tb != null)
  668.                 {
  669.                     //Clear textbox
  670.                     tb.ResetText();
  671.                 }
  672.             }
  673.             else
  674.             {
  675.                 ComboBox dd = ctrl as ComboBox;
  676.                 if (dd != null)
  677.                 {
  678.  
  679.                     if (dd != null)
  680.                     {
  681.                         //reset dropdown list
  682.                         dd.SelectedIndex = 0;
  683.                     }
  684.                 }
  685.             }
  686.         }
  687.  
  688.         /// <summary>
  689.         /// Validate customer information that user enters in the search fields
  690.         /// </summary>
  691.         /// <returns>true: valid, false: not valid</returns>
  692.         bool ValidateCustomer()
  693.         {
  694.             if (!String.IsNullOrEmpty(txtServiceCallId.Text.Trim()))
  695.             {
  696.                 //check if other search criteria exists
  697.                 if (!string.IsNullOrEmpty(txtCustomerCode.Text.Trim()) || !string.IsNullOrEmpty(txtPremiseCode.Text.Trim()) || !string.IsNullOrEmpty(txtLastName.Text.Trim()) ||
  698.                     !string.IsNullOrEmpty(txtFirstName.Text.Trim()) || !string.IsNullOrEmpty(txtPhoneNo.Text.Trim()) || !string.IsNullOrEmpty(txtStreetNo.Text.Trim()) ||
  699.                     !string.IsNullOrEmpty(txtStreetName.Text.Trim()) || !string.IsNullOrEmpty(txtPostalCode.Text.Trim()) || !string.IsNullOrEmpty(txtUnitNum.Text.Trim()) ||
  700.                     !string.IsNullOrEmpty(txtCity.Text.Trim()))
  701.                 {
  702.                     MessageBox.Show(Messages.Err0102220023);
  703.                     return false;
  704.                 }
  705.                 else
  706.                     return true;
  707.             }
  708.  
  709.             //Validate if all fields are empty
  710.             if (string.IsNullOrEmpty(txtCustomerCode.Text.Trim()) &&
  711.                 string.IsNullOrEmpty(txtPremiseCode.Text.Trim()) &&
  712.                 string.IsNullOrEmpty(txtLastName.Text.Trim()) &&
  713.                 string.IsNullOrEmpty(txtFirstName.Text.Trim()) &&
  714.                 string.IsNullOrEmpty(txtPhoneNo.Text.Trim()) &&
  715.                 string.IsNullOrEmpty(txtStreetNo.Text.Trim()) &&
  716.                 string.IsNullOrEmpty(txtStreetName.Text.Trim()) &&
  717.                 string.IsNullOrEmpty(txtPostalCode.Text.Trim()) &&
  718.                 string.IsNullOrEmpty(txtUnitNum.Text.Trim()) &&
  719.                 string.IsNullOrEmpty(txtCity.Text.Trim()))
  720.             {
  721.                 MessageBox.Show(Messages.Err0101050001);
  722.                 return false;
  723.             }
  724.  
  725.             //Validate if customer types only premise code and selects solomon customer
  726.             if (string.IsNullOrEmpty(txtCustomerCode.Text.Trim()) &&
  727.                 !string.IsNullOrEmpty(txtPremiseCode.Text.Trim()) &&
  728.                 string.IsNullOrEmpty(txtLastName.Text.Trim()) &&
  729.                 string.IsNullOrEmpty(txtFirstName.Text.Trim()) &&
  730.                 string.IsNullOrEmpty(txtPhoneNo.Text.Trim()) &&
  731.                 string.IsNullOrEmpty(txtStreetNo.Text.Trim()) &&
  732.                 string.IsNullOrEmpty(txtStreetName.Text.Trim()) &&
  733.                 string.IsNullOrEmpty(txtPostalCode.Text.Trim()) &&
  734.                 string.IsNullOrEmpty(txtUnitNum.Text.Trim()) &&
  735.                 string.IsNullOrEmpty(txtCity.Text.Trim()) &&
  736.                 ddlCustomerType.SelectedItem == Messages.CustWarranty)
  737.             {
  738.                 MessageBox.Show(Messages.Err0101050006);
  739.                 return false;
  740.             }
  741.  
  742.  
  743.             //Validate existence of first name without last name
  744.             if (!string.IsNullOrEmpty(txtFirstName.Text.Trim()) && string.IsNullOrEmpty(txtLastName.Text.Trim()))
  745.             {
  746.                 MessageBox.Show(Messages.Err0101050002);
  747.                 return false;
  748.             }
  749.  
  750.             /* Cancelled By Client Request //Validate length of premise code 
  751.             if (!string.IsNullOrEmpty(txtPremiseCode.Text.Trim()) && txtPremiseCode.Text.Trim().Length != 7)
  752.             {
  753.                 MessageBox.Show(Messages.Err0101050003);
  754.                 return false;
  755.             }*/
  756.  
  757.             //If there is no street name/number in an Addr1 field, then it is not a valid address that CMS needs to search
  758.             //Validate if there is a street number without street name in the search fields
  759.             if (string.IsNullOrEmpty(txtStreetName.Text.Trim())
  760.                 && (!string.IsNullOrEmpty(txtStreetNo.Text.Trim()) ||
  761.                 !string.IsNullOrEmpty(txtPostalCode.Text.Trim())
  762.  
  763.                 ))
  764.             {
  765.                 MessageBox.Show(Messages.Err0101050004);
  766.                 return false;
  767.             }
  768.  
  769.             //Validate length of phone number
  770.             if (!string.IsNullOrEmpty(txtPhoneNo.Text.Trim()) && txtPhoneNo.Text.Trim().Length < 3)
  771.             {
  772.                 MessageBox.Show(Messages.Err0101050005);
  773.                 return false;
  774.             }
  775.  
  776.  
  777.             //Valid customer info.
  778.             return true;
  779.         }
  780.  
  781.         /// <summary>
  782.         /// Search by service call id
  783.         /// </summary>
  784.         void SearchByServiceCallID()
  785.         {
  786.             LogWrapper.LogMethodStart("SearchByServiceCallID()", null, null);
  787.  
  788.             SearchSrv.SearchByServiceCallIDRequest req = new SearchSrv.SearchByServiceCallIDRequest();
  789.             req.ServiceCallID = txtServiceCallId.Text.Trim();
  790.  
  791.             SearchSrv.WcfService_Reliance_HVAC_CTI_IVRIntegration_OrchestrationsClient ws = new SearchSrv.WcfService_Reliance_HVAC_CTI_IVRIntegration_OrchestrationsClient();
  792.             SearchSrv.SearchByServiceCallIDResponse rsp = ws.SearchByServiceCallIDRequest(req);
  793.  
  794.             List<SearchSrv.respCustomerTable> lstCustomer = null;
  795.             if (rsp.resp.CustomerDataSet != null)
  796.             {
  797.                 lstCustomer = rsp.resp.CustomerDataSet.ToList();
  798.                 _serviceCallParams = new ServiceCallParams();
  799.                 _serviceCallParams.ServiceCallID = req.ServiceCallID;
  800.                 _serviceCallParams.ServiceCallStatus = rsp.ServiceCallStatus;
  801.             }
  802.             //Display message "No data found" if no results returned 
  803.             if (lstCustomer == null || lstCustomer.Count == 0)
  804.                 lblNotMsg.Text = Messages.Inf0101060001;
  805.             else
  806.             {
  807.                 lblNotMsg.Text = string.Empty;
  808.                 BindSearchResults(lstCustomer);
  809.             }
  810.  
  811.             //Log method End
  812.             LogWrapper.LogMethodEnd("SearchByServiceCallID()", true);
  813.         }
  814.  
  815.         void SearchByCustPremCode(Customer cust)
  816.         {
  817.             var rq = new SearchSrv.req();
  818.             rq.CustomerCode = cust.Cust;
  819.             rq.PremiseCode = cust.Prem;
  820.             rq.BackEnd = "";
  821.  
  822.             rq.MaxLimit = "1";
  823.  
  824.             var ws = new SearchSrv.WcfService_Reliance_HVAC_CTI_IVRIntegration_OrchestrationsClient();
  825.  
  826.             var rsp = ws.Request(rq);
  827.  
  828.             List<SearchSrv.respCustomerTable> lstCustomer = null;
  829.             if (rsp.CustomerDataSet != null)
  830.                 lstCustomer = rsp.CustomerDataSet.ToList();
  831.  
  832.             if (lstCustomer == null || lstCustomer.Count == 0)
  833.             {
  834.                 lblNotMsg.Text = Messages.Inf0101060001;
  835.             }
  836.             else
  837.             {
  838.                 if (lstCustomer[0].CustomerType == Messages.CustRental)
  839.                     cust.Bkend = "B";
  840.                 else
  841.                     cust.Bkend = "S";
  842.  
  843.                 cust.CrmGuID = lstCustomer[0].CrmGUID;
  844.  
  845.                 OpenAccountInfoTab(cust);
  846.             }
  847.         }
  848.  
  849.         /// <summary>
  850.         /// search by any other search criteria other than service call id
  851.         /// </summary>
  852.         void SearchByAccountInfo()
  853.         {
  854.             LogWrapper.LogMethodStart("SearchByAccountInfo()", null, null);
  855.             const string rentalCustomer = "B";
  856.             const string warrantyCustomer = "S";
  857.  
  858.             //Fill search results gridview with customers info.
  859.             SearchSrv.req rq = new SearchSrv.req();
  860.  
  861.             rq.CustomerCode = txtCustomerCode.Text.Trim();
  862.             rq.PremiseCode = txtPremiseCode.Text.Trim();
  863.             rq.LastName = txtLastName.Text.Trim();
  864.             rq.FirstName = txtFirstName.Text.Trim();
  865.             rq.PhoneNumber = txtPhoneNo.Text.Trim();
  866.  
  867.             rq.StreetNumber = txtStreetNo.Text.Trim();
  868.             rq.PreDir = ddlPreDir.SelectedItem != null ? ((System.Data.DataRowView)(ddlPreDir.SelectedItem)).Row.ItemArray[1].ToString() : "";
  869.             rq.StreetName = txtStreetName.Text.Trim();
  870.             rq.Suffix = ddlSuffix.SelectedItem != null ? ((System.Data.DataRowView)(ddlSuffix.SelectedItem)).Row.ItemArray[1].ToString() : "";
  871.             rq.PostDir = ddlPostDir.SelectedItem != null ? ((System.Data.DataRowView)(ddlPostDir.SelectedItem)).Row.ItemArray[1].ToString() : "";
  872.  
  873.             rq.UnitType = ddlUnitType.SelectedItem != null ? ((System.Data.DataRowView)(ddlUnitType.SelectedItem)).Row.ItemArray[1].ToString() : "";
  874.             rq.UnitNum = txtUnitNum.Text.Trim();
  875.  
  876.             rq.City = txtCity.Text.Trim();
  877.             rq.Province = ddlProvince.SelectedItem != null ? ((System.Data.DataRowView)(ddlProvince.SelectedItem)).Row.ItemArray[1].ToString() : "";
  878.             rq.PostalCode = txtPostalCode.Text.Trim();
  879.  
  880.             //”Rental”: Returns Banner customers only – “Warranty”: Returns Solomon customers only 
  881.             if (ddlCustomerType.SelectedItem == Messages.CustRental)
  882.                 //Banner customer
  883.                 rq.BackEnd = rentalCustomer;
  884.             else if (ddlCustomerType.SelectedItem == Messages.CustWarranty)
  885.                 //Solomon customer
  886.                 rq.BackEnd = warrantyCustomer;
  887.             else
  888.             {
  889.                 //Both
  890.                 //If user types only premise code and selects both customers
  891.                 if (string.IsNullOrEmpty(txtCustomerCode.Text.Trim()) &&
  892.                 !string.IsNullOrEmpty(txtPremiseCode.Text.Trim()) &&
  893.                 string.IsNullOrEmpty(txtLastName.Text.Trim()) &&
  894.                 string.IsNullOrEmpty(txtFirstName.Text.Trim()) &&
  895.                 string.IsNullOrEmpty(txtPhoneNo.Text.Trim()) &&
  896.                 string.IsNullOrEmpty(txtStreetNo.Text.Trim()) &&
  897.                 string.IsNullOrEmpty(txtStreetName.Text.Trim()) &&
  898.                 string.IsNullOrEmpty(txtPostalCode.Text.Trim()) &&
  899.                 string.IsNullOrEmpty(txtUnitNum.Text.Trim()) &&
  900.                 string.IsNullOrEmpty(txtCity.Text.Trim()))
  901.                     //Search in Banner only 
  902.                     rq.BackEnd = rentalCustomer;
  903.                 else
  904.                     //Search in both Banner and Solomon
  905.                     rq.BackEnd = "";
  906.             }
  907.  
  908.             // Read a configurable integer from config file;
  909.             rq.MaxLimit = ConfigurationManager.AppSettings["MaxDisplayedRecords"];
  910.  
  911.             SearchSrv.WcfService_Reliance_HVAC_CTI_IVRIntegration_OrchestrationsClient ws = new SearchSrv.WcfService_Reliance_HVAC_CTI_IVRIntegration_OrchestrationsClient();
  912.  
  913.             SearchSrv.resp rsp = ws.Request(rq);
  914.  
  915.             //Clear notification message label
  916.             lblNotMsg.Text = string.Empty;
  917.  
  918.             List<SearchSrv.respCustomerTable> lstCustomer = null;
  919.             if (rsp.CustomerDataSet != null)
  920.                 lstCustomer = rsp.CustomerDataSet.ToList();
  921.  
  922.             //Display message "No data found" if no results returned 
  923.             if (lstCustomer == null || lstCustomer.Count == 0)
  924.             {
  925.                 lblNotMsg.Text = Messages.Inf0101060001;
  926.             }
  927.  
  928.             else
  929.             {
  930.                 //Display only configurable no. of records from each type if they exceed the maximum 
  931.                 if (lstCustomer.Count > Convert.ToInt32(ConfigurationManager.AppSettings["MaxDisplayedRecords"]))
  932.                 {
  933.                     //Display message "The number of search results exceeds the display maximum"
  934.                     lblNotMsg.Text = Messages.Inf0101060002;
  935.  
  936.                     //Bind only the configured no. of records from each source
  937.                     lstCustomer =
  938.                         lstCustomer.Take(Convert.ToInt32(ConfigurationManager.AppSettings["MaxDisplayedRecords"])).ToList();
  939.                 }
  940.  
  941.                 BindSearchResults(lstCustomer);
  942.             }
  943.  
  944.             LogWrapper.LogMethodEnd("SearchByAccountInfo()", true);
  945.         }
  946.  
  947.         /// <summary>
  948.         /// Change the accepti button of the form according to the selected index
  949.         /// </summary>
  950.         /// <param name="sender"></param>
  951.         /// <param name="e"></param>
  952.         private void tcRelianceDesktop_SelectedIndexChanged(object sender, EventArgs e)
  953.         {
  954.             if (tcRelianceDesktop.SelectedIndex == 2)
  955.             {
  956.                 this.AcceptButton = btnSearchSitesSearch;
  957.             }
  958.             else
  959.             {
  960.                 this.AcceptButton = btnSearch;
  961.             }
  962.  
  963.             ShowHideNotesIcons(false);
  964.         }
  965.  
  966.         /// <summary>
  967.         /// Bind search results to result grid
  968.         /// </summary>
  969.         /// <param name="resultSet">list of respCustomerTable to bind to result grid</param>
  970.         void BindSearchResults(List<SearchSrv.respCustomerTable> resultSet, ServiceCallParams serviceCall = null)
  971.         {
  972.             LogWrapper.LogMethodStart("BindSearchResults(List<SearchSrv.respCustomerTable> resultSet)", new string[] { "resultSet" }, resultSet.ToArray<object>());
  973.  
  974.             //Display the no. of displayed recoeds as "Search Results ([N])"
  975.             lblSearchResults.Text = "Search Results (" + resultSet.Count() + ")";
  976.  
  977.             //Map data grid colums names with data source table columns names
  978.             dgvSearchResult.Columns["CustomerCode"].DataPropertyName = "CustomerCode";
  979.             dgvSearchResult.Columns["PremiseCode"].DataPropertyName = "PremiseCode";
  980.             dgvSearchResult.Columns["CustomerName"].DataPropertyName = "CustomerName";
  981.             dgvSearchResult.Columns["Address"].DataPropertyName = "Address1";
  982.             dgvSearchResult.Columns["Address2"].DataPropertyName = "Address2";
  983.             dgvSearchResult.Columns["CustomerType"].DataPropertyName = "CustomerType";
  984.             dgvSearchResult.Columns["CustomerStatus"].DataPropertyName = "CustomerStatus";
  985.             dgvSearchResult.Columns["CrmID"].DataPropertyName = "CrmID";
  986.             dgvSearchResult.Columns["CrmGUID"].DataPropertyName = "CrmGUID";
  987.             dgvSearchResult.DataSource = resultSet;
  988.  
  989.             //Log method End
  990.             LogWrapper.LogMethodEnd("BindSearchResults(List<SearchSrv.respCustomerTable> resultSet)", true);
  991.         }
  992.  
  993.         /// <summary>
  994.         /// Bind customers to gridview 
  995.         /// </summary>
  996.         void SearchCustomer()
  997.         {
  998.             //Log method start
  999.             LogWrapper.LogMethodStart("SearchCustomer()", null, null);
  1000.  
  1001.             if (!String.IsNullOrEmpty(txtServiceCallId.Text.Trim()))
  1002.                 SearchByServiceCallID();
  1003.             else
  1004.                 SearchByAccountInfo();
  1005.  
  1006.             //Log method End
  1007.             LogWrapper.LogMethodEnd("SearchCustomer()", true);
  1008.         }
  1009.  
  1010.         private void dgvSearchResult_CellContentClick(object sender, DataGridViewCellEventArgs e)
  1011.         {
  1012.             //Log method start
  1013.             LogWrapper.LogMethodStart("dgvSearchResult_CellContentClick(object sender, DataGridViewCellEventArgs e)", new string[] { "sender", "e" }, new object[] { sender, e });
  1014.  
  1015.             try
  1016.             {
  1017.                 if (e.RowIndex >= 0) //user didn't click on the header 
  1018.                 {
  1019.  
  1020.                     //Check whether user clicked on "Customer Name" column
  1021.                     if (dgvSearchResult.Columns[e.ColumnIndex].Name == "CustomerName")
  1022.                     {
  1023.                         //show progress cursor                    
  1024.                         this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
  1025.  
  1026.                         //Send selected row index
  1027.                         Customer customer = GetSelectedCustomer(e.RowIndex);
  1028.  
  1029.                         //Send customer identifier to UPSTART
  1030.                         SendCustIDToUpStart(customer);
  1031.  
  1032.                         //Open the super screen with customer info
  1033.                         OpenAccountInfoTab(customer);
  1034.  
  1035.                     }
  1036.                 }
  1037.             }
  1038.             catch (Exception exception)
  1039.             {
  1040.                 HandleExceptions(exception);
  1041.             }
  1042.             finally
  1043.             {
  1044.                 //hide progress cursor                    
  1045.                 this.Cursor = System.Windows.Forms.Cursors.Default;
  1046.             }
  1047.  
  1048.             //Log method End
  1049.             LogWrapper.LogMethodEnd("dgvSearchResult_CellContentClick(object sender, DataGridViewCellEventArgs e)", true);
  1050.         }
  1051.  
  1052.         /// <summary>
  1053.         /// Get selected customer info. from grid view 
  1054.         /// </summary>
  1055.         /// <param name="selectedRow">Selected row index</param>
  1056.         /// <returns>Selected customer information</returns>
  1057.         Customer GetSelectedCustomer(int selectedRow)
  1058.         {
  1059.             //Log method start
  1060.             LogWrapper.LogMethodStart("GetSelectedCustomer(int selectedRow)", new string[] { "selectedRow" }, new object[] { selectedRow });
  1061.  
  1062.             var customer = new Customer();
  1063.  
  1064.             if (dgvSearchResult.Rows[selectedRow].Cells["CustomerType"].Value != null
  1065.                 && !string.IsNullOrEmpty(dgvSearchResult.Rows[selectedRow].Cells["CustomerType"].Value.ToString().Trim()))
  1066.             {
  1067.                 string custCode = "";
  1068.                 string premCode = "";
  1069.  
  1070.                 if (dgvSearchResult.Rows[selectedRow].Cells["CustomerCode"].Value != null
  1071.                 && !string.IsNullOrEmpty(dgvSearchResult.Rows[selectedRow].Cells["CustomerCode"].Value.ToString().Trim()))
  1072.                     custCode = dgvSearchResult.Rows[selectedRow].Cells["CustomerCode"].Value.ToString().Trim();
  1073.                 else
  1074.                     //Customer Code is null or empty
  1075.                     throw new System.ArgumentException("0101150001: " + Messages.Err0101150001);
  1076.  
  1077.                 if (dgvSearchResult.Rows[selectedRow].Cells["PremiseCode"].Value != null
  1078.                     && !string.IsNullOrEmpty(dgvSearchResult.Rows[selectedRow].Cells["PremiseCode"].Value.ToString().Trim()))
  1079.                     premCode = dgvSearchResult.Rows[selectedRow].Cells["PremiseCode"].Value.ToString().Trim();
  1080.                 else
  1081.                     //Premise Code is null or emty
  1082.                     throw new System.ArgumentException("0101150002: " + Messages.Err0101150002);
  1083.  
  1084.                 string isBanner = "False";
  1085.  
  1086.                 //Banner customer
  1087.                 if (dgvSearchResult.Rows[selectedRow].Cells["CustomerType"].Value.ToString().ToUpper().Trim() == Messages.CustRental.ToUpper())
  1088.                 {
  1089.                     customer.Cust = custCode;
  1090.                     customer.Prem = premCode;
  1091.                     customer.Bkend = stickyMessage.BannerCust;
  1092.                     isBanner = "True";
  1093.  
  1094.                 }
  1095.  
  1096.                 //Solomon customer
  1097.                 else if (dgvSearchResult.Rows[selectedRow].Cells["CustomerType"].Value.ToString().ToUpper().Trim() == Messages.CustWarranty.ToUpper())
  1098.                 {
  1099.                     customer.SlmnID = custCode;
  1100.                     customer.SlmnSite = premCode;
  1101.                     customer.Bkend = stickyMessage.SolomonCust;
  1102.                     isBanner = "False";
  1103.                 }
  1104.  
  1105.                 if (dgvSearchResult.Rows[selectedRow].Cells["CrmID"].Value != null
  1106.                 && !string.IsNullOrEmpty(dgvSearchResult.Rows[selectedRow].Cells["CrmID"].Value.ToString().Trim()))
  1107.                     customer.CrmID = dgvSearchResult.Rows[selectedRow].Cells["CrmID"].Value.ToString().Trim();
  1108.                 else
  1109.                     //CrmID is null or empty
  1110.                     throw new System.ArgumentException("0101150004: " + Messages.Err0101150004);
  1111.  
  1112.                 if (dgvSearchResult.Rows[selectedRow].Cells["CrmGuID"].Value != null
  1113.                 && !string.IsNullOrEmpty(dgvSearchResult.Rows[selectedRow].Cells["CrmGuID"].Value.ToString().Trim()))
  1114.                     customer.CrmGuID = dgvSearchResult.Rows[selectedRow].Cells["CrmGuID"].Value.ToString().Trim();
  1115.                 else
  1116.                     //CrmGuID is null or empty
  1117.                     throw new System.ArgumentException("0101150005: " + Messages.Err0101150005);
  1118.  
  1119.                 //Sync CRM Record from Solomon or Banner if sync flag is true
  1120.                 if (ConfigurationManager.AppSettings["Sync"] == "true")
  1121.                     Sync(isBanner, ref customer);
  1122.  
  1123.             }
  1124.             else
  1125.                 //Customer Type is null or emty
  1126.                 throw new ArgumentException("0101150003: " + Messages.Err0101150003);
  1127.  
  1128.             //Log method End
  1129.             LogWrapper.LogMethodEnd("GetSelectedCustomer(int selectedRow)", true);
  1130.  
  1131.             return customer;
  1132.         }
  1133.  
  1134.         private bool _firstTime;
  1135.         void Sync(string isBanner, ref Customer customer)
  1136.         {
  1137.             try
  1138.             {
  1139.                 if (_syncServClient == null || (_syncServClient.State != System.ServiceModel.CommunicationState.Opened &&
  1140.                     _syncServClient.State != System.ServiceModel.CommunicationState.Opening))
  1141.                     OpenSyncService();
  1142.                 else if (_syncServClient.State == System.ServiceModel.CommunicationState.Opening)
  1143.                     while (_syncServClient.State == System.ServiceModel.CommunicationState.Opening)
  1144.                     {
  1145.                         // do nothing
  1146.                     }
  1147.  
  1148.                 var objCmsAccount = _syncServClient.Sync(isBanner, "0", customer.Cust, customer.Prem,
  1149.                                                          customer.SlmnID, customer.SlmnSite);
  1150.                 _syncServClient.Close();
  1151.  
  1152.             }
  1153.             catch (Exception ex)
  1154.             {
  1155.                 if (_syncServClient.State == System.ServiceModel.CommunicationState.Faulted && !_firstTime)
  1156.                 {
  1157.                     _syncServClient = null;
  1158.                     Sync(isBanner, ref customer);
  1159.                     _firstTime = true;
  1160.                 }
  1161.                 else
  1162.                 {
  1163.                     HandleExceptions(ex);
  1164.                 }
  1165.             }
  1166.         }
  1167.  
  1168.         /// <summary>
  1169.         /// Send customer identifier to UpStart
  1170.         /// </summary>
  1171.         /// <param name="customer">Customer Information</param>
  1172.         void SendCustIDToUpStart(Customer customer)
  1173.         {
  1174.             //Log method start
  1175.             LogWrapper.LogMethodStart("SendCustIDToUpStart(Customer customer)", new string[] { "customer" }, new object[] { customer });
  1176.  
  1177.             //When the customer has been located, CMS has to send the following update to UpStart:
  1178.             //Example:
  1179.             //ApplicationId: CMS 
  1180.             //Key:UPDATE
  1181.             //Value:PREM=xxxxxxx,CUST=xxxxxxx,CRMID=CRM-31765,CRMGUID=05C0B7BA-C7DF-49C7-A08A-7CB294B3A674 when the customer was found in Banner or
  1182.             //Value:SLMNID=xxxx,SLMNSITE=xxxx,CRMID=CRM-31765,CRMGUID=05C0B7BA-C7DF-49C7-A08A-7CB294B3A674 when the customer was found in Solomon
  1183.             StringBuilder msgValue = new StringBuilder();
  1184.  
  1185.             //Construct the message
  1186.             //Banner customer
  1187.             if (customer.Bkend == stickyMessage.BannerCust)
  1188.             {
  1189.                 msgValue.Append(stickyMessage.PremKey).Append("=").Append(customer.Prem).Append(",");
  1190.                 msgValue.Append(stickyMessage.CustKey).Append("=").Append(customer.Cust).Append(",");
  1191.             }
  1192.             //Solomon customer
  1193.             else if (customer.Bkend == stickyMessage.SolomonCust)
  1194.             {
  1195.                 msgValue.Append(stickyMessage.SlmnIDKey).Append("=").Append(customer.SlmnID).Append(",");
  1196.                 msgValue.Append(stickyMessage.SlmnSiteKey).Append("=").Append(customer.SlmnSite).Append(",");
  1197.             }
  1198.  
  1199.             msgValue.Append(stickyMessage.CrmIDKey).Append("=").Append(customer.CrmID).Append(",");
  1200.             msgValue.Append(stickyMessage.CrmGuIDKey).Append("=").Append(customer.CrmGuID);
  1201.  
  1202.             //Watch for changes in the given Sticky key. By calling this function, you register to receive events of type StickyValueChanged for the key you specify
  1203.             stickyData.WatchStickyValue(ConfigurationManager.AppSettings["CMSAppID"], ConfigurationManager.AppSettings["UPDATEKey"]);
  1204.  
  1205.             //Send the message to UpStart
  1206.             stickyData.SetSticky(ConfigurationManager.AppSettings["CMSAppID"], ConfigurationManager.AppSettings["UPDATEKey"], msgValue.ToString());
  1207.  
  1208.             //Log method End
  1209.             LogWrapper.LogMethodEnd("SendCustIDToUpStart(Customer customer)", true);
  1210.         }
  1211.  
  1212.         /// <summary>
  1213.         /// Fill customer type dropdown list
  1214.         /// </summary>
  1215.         void BindCustomerTypeddl()
  1216.         {
  1217.             //Log method start
  1218.             LogWrapper.LogMethodStart("BindCustomerTypeddl()", null, null);
  1219.  
  1220.             ddlCustomerType.Items.Add(Messages.CustBoth);
  1221.             ddlCustomerType.Items.Add(Messages.CustRental);
  1222.             ddlCustomerType.Items.Add(Messages.CustWarranty);
  1223.             ddlCustomerType.SelectedItem = Messages.CustBoth;
  1224.  
  1225.             //Log method End
  1226.             LogWrapper.LogMethodEnd("BindCustomerTypeddl()", true);
  1227.         }
  1228.  
  1229.         private void btnSearch_Click(object sender, EventArgs e)
  1230.         {
  1231.             try
  1232.             {
  1233.                 //Validate entered customer information
  1234.                 if (!validCity || !validFirstName || !validLastName || !ValidPhoneNo || !validPostalCode || !validPostDir || !validPreDir || !validProvince || !validStreetName || !validStreetNo || !validSuffix || !validUnitNum || !validUnitType)
  1235.                     return;
  1236.                 if (ValidateCustomer())
  1237.                 {
  1238.                     // open sync service connection in a different thread to save time
  1239.                     if (_syncServClient == null || (_syncServClient.State != System.ServiceModel.CommunicationState.Opened && _syncServClient.State != System.ServiceModel.CommunicationState.Opening))
  1240.                     {
  1241.                         _thrSyncSer = new Thread(OpenSyncService);
  1242.                         _thrSyncSer.Start();
  1243.                     }
  1244.  
  1245.                     //show progress cursor                    
  1246.                     this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
  1247.  
  1248.                     //Enable create COD customer and create site buttons
  1249.                     btnCreateCOD.Enabled = true;
  1250.                     btnCreateSite.Enabled = true;
  1251.  
  1252.                     //Bind customers information to search results gridview
  1253.                     _serviceCallParams = null;
  1254.                     SearchCustomer();
  1255.                 }
  1256.             }
  1257.             catch (Exception exception)
  1258.             {
  1259.                 HandleExceptions(exception);
  1260.             }
  1261.             finally
  1262.             {
  1263.                 //hide progress cursor
  1264.                 this.Cursor = System.Windows.Forms.Cursors.Default;
  1265.             }
  1266.         }
  1267.  
  1268.         void OpenSyncService()
  1269.         {
  1270.             try
  1271.             {
  1272.                 LogWrapper.LogMethodStart("OpenSyncService()", null, null);
  1273.  
  1274.                 _syncServClient = new SyncSrv.SynchronizationServiceClient();
  1275.                 if (ConfigurationManager.AppSettings["UserCustomSyncServiceAuth"] == "1")
  1276.                 {
  1277.                     _syncServClient.ClientCredentials.Windows.AllowNtlm = true;
  1278.                     _syncServClient.ClientCredentials.Windows.ClientCredential =
  1279.                         new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SyncServiceAuthUserName"], ConfigurationManager.AppSettings["SyncServiceAuthPassword"]);
  1280.                 }
  1281.                 _syncServClient.Open();
  1282.             }
  1283.             catch (Exception ex)
  1284.             {
  1285.                 HandleExceptions(ex);
  1286.             }
  1287.             finally
  1288.             {
  1289.                 if (_thrSyncSer != null)
  1290.                     _thrSyncSer.Abort();
  1291.  
  1292.                 LogWrapper.LogMethodEnd("OpenSyncService()", true);
  1293.             }
  1294.         }
  1295.  
  1296.         bool refreshed;
  1297.  
  1298.         FrmNotesIcons frmNotesIcons;
  1299.         private void wbCRMSuperScreen_Navigated(object sender, WebBrowserNavigatedEventArgs e)
  1300.         {
  1301.             try
  1302.             {
  1303.                 if (e.Url.AbsoluteUri.ToLower().Contains("progress.htm"))
  1304.                 {
  1305.                     if (!_isNewCustomer)
  1306.                     {
  1307.                         string serviceCallParams = string.Empty;
  1308.  
  1309.                         //Open CRM screen(super screen)
  1310.                         if (_serviceCallParams != null && !string.IsNullOrEmpty(_serviceCallParams.ServiceCallID) && !string.IsNullOrEmpty(_serviceCallParams.ServiceCallStatus))
  1311.                             serviceCallParams = System.Uri.EscapeDataString(string.Format("&servicecallid_1={0}&servicecallstatus_1={1}", _serviceCallParams.ServiceCallID, _serviceCallParams.ServiceCallStatus));
  1312.  
  1313.                         wbCRMSuperScreen.Navigate("http://" + ConfigurationManager.AppSettings["ServerName"] + "/" + ConfigurationManager.AppSettings["OrgName"] + "/main.aspx?etc=2&extraqs=%3fformId%3d" + PageLayoutId + "%26_gridType%3d2%26etc%3d2%26id%3d%257b" + _Customer.CrmGuID + "%257d%26pagemode%3diframe%26preloadcache%3d1350819428384%26rskey%3d251585687" + serviceCallParams + "&pagetype=entityrecord");
  1314.                     }
  1315.                     else
  1316.                     {
  1317.                         wbCRMSuperScreen.Navigate("http://" + ConfigurationManager.AppSettings["ServerName"] + "/" + ConfigurationManager.AppSettings["OrgName"] + "/main.aspx?etc=2&extraqs=%3fformId%3d" + PageLayoutId + "%26pagemode%3diframe%26preloadcache%3d1380621615237" + _creationTypeParam + "&pagetype=entityrecord");
  1318.                     }
  1319.  
  1320.                     ShowHideNotesIcons(true);
  1321.  
  1322.                     return;
  1323.                 }
  1324.  
  1325.                 if (!refreshed && ConfigurationManager.AppSettings["RefreshOption"] == ((int)Enums.RefreshOption.Completely).ToString())
  1326.                     //Remove caching by getting the latest version of the web page
  1327.                     wbCRMSuperScreen.Refresh(WebBrowserRefreshOption.Completely);
  1328.                 else if (!refreshed && ConfigurationManager.AppSettings["RefreshOption"] == ((int)Enums.RefreshOption.IfExpired).ToString())
  1329.                     //Request update only if the current web page has expired
  1330.                     wbCRMSuperScreen.Refresh(WebBrowserRefreshOption.IfExpired);
  1331.             }
  1332.             catch (Exception exception)
  1333.             {
  1334.                 HandleExceptions(exception);
  1335.             }
  1336.  
  1337.             refreshed = true;
  1338.         }
  1339.  
  1340.         private void btnClear_Click(object sender, EventArgs e)
  1341.         {
  1342.             ResetCMSDesktopApp();
  1343.         }
  1344.  
  1345.         private void btnCreateSite_Click(object sender, EventArgs e)
  1346.         {
  1347.             _creationTypeParam = System.Uri.EscapeDataString("&creationtype_1=175650002");
  1348.             OpenNewCustomerTab();
  1349.         }
  1350.  
  1351.         private void btnCreateCOD_Click(object sender, EventArgs e)
  1352.         {
  1353.             _creationTypeParam = System.Uri.EscapeDataString("&creationtype_1=175650001");
  1354.             OpenNewCustomerTab();
  1355.         }
  1356.  
  1357.         #region "Search Sites"
  1358.  
  1359.         #region "Events"
  1360.  
  1361.         /// <summary>
  1362.         /// clear site search button clicked
  1363.         /// </summary>
  1364.         /// <param name="sender"></param>
  1365.         /// <param name="e"></param>
  1366.         private void btnClearSerchSites_Click(object sender, EventArgs e)
  1367.         {
  1368.             try
  1369.             {
  1370.  
  1371.                 //clear grid
  1372.                 var lstCustomer = new List<SearchSrv.respCustomerTable>(); // Empty data source to avoid losing grid columns if we set its data source with null
  1373.                 dgvSearchResultSearchSites.DataSource = lstCustomer;
  1374.                 lblNoteMsgSearchSites.Text = string.Empty;
  1375.                 lblSearchResultsSearchSites.Text = @"Search Results";
  1376.  
  1377.                 //reset the text boxes 
  1378.                 ResetSearchSites((Button)sender);
  1379.             }
  1380.             catch (Exception ex)
  1381.             {
  1382.                 HandleExceptions(ex);
  1383.             }
  1384.  
  1385.  
  1386.         }
  1387.  
  1388.         /// <summary>
  1389.         /// Search sites button clicked
  1390.         /// </summary>
  1391.         /// <param name="sender"></param>
  1392.         /// <param name="e"></param>
  1393.         private void btnSearchSitesSearch_Click(object sender, EventArgs e)
  1394.         {
  1395.             try
  1396.             {
  1397.  
  1398.                 LogWrapper.LogMethodStart("frmReliance_CMS.btnSearchSitesSearch_Click", null, null);
  1399.                 //Validate entered customer information
  1400.                 if (ValidateSearchSites())
  1401.                 {
  1402.  
  1403.                     //show progress cursor                    
  1404.                     this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
  1405.  
  1406.                     //Bind customers information to search results gridview
  1407.                     _SiteSearchserviceCallParams = null;
  1408.                     //search the sites with the given data
  1409.                     searchSites();
  1410.                 }
  1411.                 LogWrapper.LogMethodEnd("frmReliance_CMS.btnSearchSitesSearch_Click", true);
  1412.             }
  1413.             catch (Exception exception)
  1414.             {
  1415.                 HandleExceptions(exception);
  1416.  
  1417.             }
  1418.             finally
  1419.             {
  1420.                 //hide progress cursor
  1421.                 this.Cursor = System.Windows.Forms.Cursors.Default;
  1422.             }
  1423.         }
  1424.  
  1425.         /// <summary>
  1426.         /// Search sites grid cell contetnt clicked
  1427.         /// </summary>
  1428.         /// <param name="sender"></param>
  1429.         /// <param name="e"></param>
  1430.         private void dgvSearchResultSearchSites_CellContentClick(object sender, DataGridViewCellEventArgs e)
  1431.         {
  1432.  
  1433.             try
  1434.             {
  1435.                 if (e.RowIndex >= 0) //user didn't click on the header 
  1436.                 {
  1437.                     //user clicked on the customer name column
  1438.                     if (dgvSearchResultSearchSites.Columns[e.ColumnIndex].DataPropertyName.Equals("CustomerName"))
  1439.                     {
  1440.                         string customerCode = getGridViewCellValueByDataPropertyName(dgvSearchResultSearchSites, e.RowIndex, "CustomerCode");
  1441.                         string premiseCode = getGridViewCellValueByDataPropertyName(dgvSearchResultSearchSites, e.RowIndex, "PremiseCode");
  1442.                         string switchFsmSolomonChar = getGridViewCellValueByDataPropertyName(dgvSearchResultSearchSites, e.RowIndex, "CustomerType").ToLower();
  1443.                         //string placeId = "", addressId="";
  1444.  
  1445.  
  1446.                         // set popup customer information fields
  1447.                         switch (switchFsmSolomonChar)
  1448.                         {
  1449.                             case "f":
  1450.                                 FSMService = new FSMService.CMS_ServiceBookingClient();
  1451.                                 FSMService.Open();
  1452.                                 fsmCustomer = FSMService.GetFSMCustomer(customerCode, premiseCode);
  1453.                                 //var place = FSMService.GetPlaceByCustomerCode(customerCode);
  1454.                                 //placeId= place != null ? place.Place_id : "";
  1455.                                 //var address = FSMService.GetAddressByPremiseCode(premiseCode);
  1456.                                 //addressId= address != null ? address.Address_id : "";
  1457.                                 if (fsmCustomer != null)
  1458.                                 {
  1459.                                     popup.CustomerName = fsmCustomer.Name ?? "";
  1460.                                     popup.Telephone = fsmCustomer.Phone ?? "";
  1461.                                     popup.CityProvPostal = (fsmCustomer.City != null ? fsmCustomer.City.Trim() : "") + ", " + (fsmCustomer.Province != null ? fsmCustomer.Province.Trim() : "") + " " + (fsmCustomer.PostalCode != null ? fsmCustomer.PostalCode.Trim() : "");
  1462.                                     popup.Address = (fsmCustomer.Address1 != null ? fsmCustomer.Address1.Trim() : "") + " " + (fsmCustomer.Address2 != null ? fsmCustomer.Address2.Trim() : "");
  1463.                                 }
  1464.                                 break;
  1465.                             case "s":
  1466.                             default:
  1467.                                 SolomonService = new SolomonService.CMS_ServiceBookingClient();
  1468.                                 SolomonService.Open();
  1469.                                 solomonCustomer = SolomonService.GetSolomonCustomer(customerCode, premiseCode);
  1470.                                 if (solomonCustomer != null)
  1471.                                 {
  1472.                                     popup.CustomerName = solomonCustomer.Name;
  1473.                                     popup.Telephone = solomonCustomer.Phone;
  1474.                                     popup.CityProvPostal = solomonCustomer.City.Trim() + ", " + solomonCustomer.Province.Trim() + " " + solomonCustomer.PostalCode.Trim();
  1475.                                     popup.Address = solomonCustomer.Address1.Trim() + " " + solomonCustomer.Address2.Trim();
  1476.                                 }
  1477.                                 break;
  1478.                         }
  1479.  
  1480.                         popup.FsmSolomonSwitch = switchFsmSolomonChar;
  1481.  
  1482.                         string serviceCallParams = string.Empty;
  1483.                         //Open CRM screen(super screen)
  1484.                         if (_SiteSearchserviceCallParams != null && !string.IsNullOrEmpty(_SiteSearchserviceCallParams.ServiceCallID) && !string.IsNullOrEmpty(_SiteSearchserviceCallParams.ServiceCallStatus))
  1485.                             serviceCallParams = string.Format("&servicecallid={0}&servicecallstatus={1}", _SiteSearchserviceCallParams.ServiceCallID, _SiteSearchserviceCallParams.ServiceCallStatus);
  1486.  
  1487.  
  1488.                         popup.setRibbonTitle("Service Orders");
  1489.                         popup.setURL("http://" + ConfigurationManager.AppSettings["ServerName"] + "/" +
  1490.                                      "ISV/CMS/SB/ServiceOrders.htm?customerid=" + customerCode + "&shiptoid=" +
  1491.                                      premiseCode + "&solomonbannerflag=1&useCrm=no&isSite=1" + serviceCallParams +
  1492.                                      "&SwitchFsmSolomon=" + switchFsmSolomonChar
  1493.                             //+(placeId == "" ? "" : "&PlaceId=" + placeId) +
  1494.                             //(addressId == "" ? "" : "&AddressId=" + addressId)
  1495.                                      );
  1496.  
  1497.                         popup.centerPopup();
  1498.                         popup.ShowDialog();
  1499.                     }
  1500.                 }
  1501.  
  1502.             }
  1503.             catch (Exception ex)
  1504.             {
  1505.                 HandleExceptions(ex);
  1506.             }
  1507.         }
  1508.         #endregion
  1509.  
  1510.         #region "Private Methods"
  1511.  
  1512.  
  1513.         /// <summary>
  1514.         /// validates the search criteria for the site search form 
  1515.         /// </summary>
  1516.         /// <returns></returns>
  1517.         bool ValidateSearchSites()
  1518.         {
  1519.  
  1520.             try
  1521.             {
  1522.                 if (!String.IsNullOrEmpty(txtServiceCallIdSearchSites.Text.Trim()))
  1523.                 {
  1524.                     //check if other search criteria exists
  1525.                     if (!string.IsNullOrEmpty(txtLastNameSearchSites.Text.Trim()) ||
  1526.                         !string.IsNullOrEmpty(txtFirstNameSearchSites.Text.Trim()) || !string.IsNullOrEmpty(txtPhoneNumberSearchSites.Text.Trim()) || !string.IsNullOrEmpty(txtStreetNoSearchSites.Text.Trim()) ||
  1527.                         !string.IsNullOrEmpty(txtStreetNameSearchSites.Text.Trim()) || !string.IsNullOrEmpty(txtPostalCodeSearchSites.Text.Trim()) || !string.IsNullOrEmpty(txtUnitNumSearchSites.Text.Trim()) ||
  1528.                         !string.IsNullOrEmpty(txtCitySearchSites.Text.Trim()))
  1529.                     {
  1530.                         MessageBox.Show(Messages.Err0102220023);
  1531.                         return false;
  1532.                     }
  1533.                     else
  1534.                         return true;
  1535.                 }
  1536.                 //Validate if all fields are empty
  1537.                 if (
  1538.  
  1539.                     string.IsNullOrEmpty(txtLastNameSearchSites.Text.Trim()) &&
  1540.                     string.IsNullOrEmpty(txtFirstNameSearchSites.Text.Trim()) &&
  1541.                     string.IsNullOrEmpty(txtPhoneNumberSearchSites.Text.Trim()) &&
  1542.                     string.IsNullOrEmpty(txtStreetNoSearchSites.Text.Trim()) &&
  1543.                     string.IsNullOrEmpty(txtStreetNameSearchSites.Text.Trim()) &&
  1544.                     string.IsNullOrEmpty(txtPostalCodeSearchSites.Text.Trim()) &&
  1545.                     string.IsNullOrEmpty(txtUnitNumSearchSites.Text.Trim()) &&
  1546.                     string.IsNullOrEmpty(txtCitySearchSites.Text.Trim()))
  1547.                 {
  1548.                     MessageBox.Show(Messages.Err0101050001);
  1549.                     return false;
  1550.                 }
  1551.  
  1552.  
  1553.                 //If there is no street name/number in an Addr1 field, then it is not a valid address that CMS needs to search
  1554.                 //Validate if there is a street number without street name in the search fields
  1555.                 if (string.IsNullOrEmpty(txtStreetNameSearchSites.Text.Trim())
  1556.                     && (!string.IsNullOrEmpty(txtStreetNoSearchSites.Text.Trim()) ||
  1557.                     !string.IsNullOrEmpty(txtPostalCodeSearchSites.Text.Trim())
  1558.                     ))
  1559.                 {
  1560.                     MessageBox.Show(Messages.Err0101050004);
  1561.                     return false;
  1562.                 }
  1563.  
  1564.                 //Validate length of phone number
  1565.                 if (!string.IsNullOrEmpty(txtPhoneNumberSearchSites.Text.Trim()) && txtPhoneNumberSearchSites.Text.Trim().Length < 3)
  1566.                 {
  1567.                     MessageBox.Show(Messages.Err0101050005);
  1568.                     return false;
  1569.                 }
  1570.  
  1571.  
  1572.                 //Valid customer info.
  1573.                 return true;
  1574.             }
  1575.             catch (Exception ex)
  1576.             {
  1577.                 LogWrapper.LogError(ex);
  1578.                 throw;
  1579.             }
  1580.         }
  1581.  
  1582.         /// <summary>
  1583.         /// Clear all text boxes having the same parent as the sent child
  1584.         /// </summary>
  1585.         /// <param name="child"></param>
  1586.         private static void ResetSearchSites(Control child)
  1587.         {
  1588.             try
  1589.             {
  1590.                 //clear all text boxex in the same container as the sent control
  1591.                 foreach (Control c in child.Parent.Controls)
  1592.                 {
  1593.                     if (c.GetType().Equals(typeof(TextBox)))
  1594.                     {
  1595.                         ((TextBox)c).Clear();
  1596.                     }
  1597.                 }
  1598.             }
  1599.             catch (Exception ex)
  1600.             {
  1601.                 LogWrapper.LogError(ex);
  1602.                 throw;
  1603.             }
  1604.         }
  1605.  
  1606.         /// <summary>
  1607.         /// search for a site with the current criteria
  1608.         /// </summary>
  1609.         private void searchSites()
  1610.         {
  1611.             try
  1612.             {
  1613.  
  1614.                 //Log method start
  1615.                 LogWrapper.LogMethodStart("searchSites()", null, null);
  1616.                 if (!String.IsNullOrEmpty(txtServiceCallIdSearchSites.Text.Trim()))
  1617.                     SearchSiteByServiceCallID();
  1618.                 else
  1619.                 {
  1620.  
  1621.                     //Fill search results gridview with customers info.
  1622.  
  1623.                     SiteSearchService.SiteReq rq = new SiteSearchService.SiteReq();
  1624.  
  1625.  
  1626.                     rq.LastName = txtLastNameSearchSites.Text.Trim();
  1627.                     rq.FirstName = txtFirstNameSearchSites.Text.Trim();
  1628.                     rq.PhoneNumber = txtPhoneNumberSearchSites.Text.Trim();
  1629.                     rq.StreetNumber = txtStreetNoSearchSites.Text.Trim();
  1630.                     rq.PostalCode = txtPostalCodeSearchSites.Text.Trim();
  1631.                     rq.StreetName = txtStreetNameSearchSites.Text.Trim();
  1632.                     //rq.SuffixCode = txtSuffixSearchSites.Text.Trim();
  1633.                     //rq.PostDirectionCode = txtPostDirSearchSites.Text.Trim();
  1634.                     rq.UnitNum = txtUnitNumSearchSites.Text.Trim();
  1635.                     rq.City = txtCitySearchSites.Text.Trim();
  1636.  
  1637.  
  1638.  
  1639.                     // Read a configurable integer from config file;
  1640.                     rq.MaxLimit = ConfigurationManager.AppSettings["MaxDisplayedRecords"];
  1641.  
  1642.                     SiteSearchService.WcfService_Reliance_HVAC_CTI_IVRIntegration_OrchestrationsClient ws = new SiteSearchService.WcfService_Reliance_HVAC_CTI_IVRIntegration_OrchestrationsClient();
  1643.  
  1644.                     SiteSearchService.SiteResp rsp = ws.GetSearchResults(rq);
  1645.  
  1646.                     //Clear notification message label
  1647.                     lblNoteMsgSearchSites.Text = string.Empty;
  1648.  
  1649.                     List<SiteSearchService.SiteRespCustomerTable> lstSites = null;
  1650.                     if (rsp.CustomerDataSet != null)
  1651.                         lstSites = rsp.CustomerDataSet.ToList();
  1652.  
  1653.                     //Display message "No data found" if no results returned 
  1654.                     if (lstSites == null || lstSites.Count == 0)
  1655.                     {
  1656.                         lblNoteMsgSearchSites.Text = Messages.Inf0101060001;
  1657.                     }
  1658.  
  1659.                     else
  1660.                     {
  1661.                         //Display only configurable no. of records from each type (Solomon, FSM) if they exceed the maximum 
  1662.                         //count multiplied by 2 because results are coming from both Solomon and FSM
  1663.                         //If Solomon removed from the search results, remove multiplication by 2
  1664.                         if (lstSites.Count() > Convert.ToInt32(ConfigurationManager.AppSettings["MaxDisplayedRecords"]) * 2)
  1665.                         {
  1666.                             //Display message "The number of search results exceeds the display maximum"
  1667.                             lblNoteMsgSearchSites.Text = Messages.Inf0101060002;
  1668.  
  1669.                             //Bind only the configured no. of records from each source
  1670.                             lstSites =
  1671.                                 lstSites.Take(Convert.ToInt32(ConfigurationManager.AppSettings["MaxDisplayedRecords"]) * 2).ToList();
  1672.                         }
  1673.  
  1674.                         //Sort search results by customer name
  1675.                         lstSites = lstSites.OrderBy(c => c.CustomerName).ToList();
  1676.                         BindSearchSitesResults(lstSites);
  1677.                     }
  1678.  
  1679.  
  1680.  
  1681.                     //Log method End
  1682.                     LogWrapper.LogMethodEnd("searchSites()", true);
  1683.                 }
  1684.             }
  1685.             catch (Exception ex)
  1686.             {
  1687.                 LogWrapper.LogError(ex);
  1688.                 throw;
  1689.             }
  1690.         }
  1691.  
  1692.         private void SearchSiteByServiceCallID()
  1693.         {
  1694.             LogWrapper.LogMethodStart("SearchBySiteSearchServiceCallID()", null, null);
  1695.             SiteSearchService.SearchByServiceCallIDRequest req = new SiteSearchService.SearchByServiceCallIDRequest();
  1696.  
  1697.  
  1698.             req.ServiceCallID = txtServiceCallIdSearchSites.Text.Trim();
  1699.  
  1700.             SiteSearchService.WcfService_Reliance_HVAC_CTI_IVRIntegration_OrchestrationsClient ws = new SiteSearchService.WcfService_Reliance_HVAC_CTI_IVRIntegration_OrchestrationsClient();
  1701.             SiteSearchService.SearchByServiceCallIDResponse rsp = ws.SearchByServiceCallIDRequest(req);
  1702.  
  1703.             List<SiteSearchService.respCustomerTable> lstCustomers = null;
  1704.             List<SiteSearchService.SiteRespCustomerTable> lstSites = new List<SiteSearchService.SiteRespCustomerTable>();
  1705.             if (rsp.resp.CustomerDataSet != null)
  1706.             {
  1707.                 lstCustomers = rsp.resp.CustomerDataSet.ToList();
  1708.                 _SiteSearchserviceCallParams = new ServiceCallParams();
  1709.                 _SiteSearchserviceCallParams.ServiceCallID = req.ServiceCallID;
  1710.                 _SiteSearchserviceCallParams.ServiceCallStatus = rsp.ServiceCallStatus;
  1711.             }
  1712.             //Display message "No data found" if no results returned 
  1713.             if (lstCustomers == null || lstCustomers.Count == 0)
  1714.                 lblNoteMsgSearchSites.Text = Messages.Inf0101060001;
  1715.             else
  1716.             {
  1717.                 foreach (var item in lstCustomers)
  1718.                 {
  1719.                     lstSites.Add(new SiteSearchService.SiteRespCustomerTable
  1720.                     {
  1721.                         Address1 = item.Address1,
  1722.                         Address2 = string.IsNullOrEmpty(item.Address2) ? "" : item.Address2,
  1723.                         CustomerCode = item.CustomerCode,
  1724.                         CustomerName = item.CustomerName,
  1725.                         CustomerStatus = item.CustomerStatus,
  1726.                         PremiseCode = item.PremiseCode,
  1727.                         CustomerType = item.CustomerType
  1728.                     });
  1729.  
  1730.                 }
  1731.                 lblNoteMsgSearchSites.Text = string.Empty;
  1732.                 BindSearchSitesResults(lstSites);
  1733.             }
  1734.  
  1735.             //Log method End
  1736.             LogWrapper.LogMethodEnd("SearchByServiceCallID()", true);
  1737.         }
  1738.  
  1739.         /// <summary>
  1740.         /// Bind search sites grid view
  1741.         /// </summary>
  1742.         /// <param name="lstSites"></param>
  1743.         private void BindSearchSitesResults(List<SiteSearchService.SiteRespCustomerTable> lstSites)
  1744.         {
  1745.  
  1746.             try
  1747.             {
  1748.                 LogWrapper.LogMethodStart("BindSearchSitesResults(List<SearchSrv.respCustomerTable> resultSet)", new string[] { "lstSites" }, lstSites.ToArray<object>());
  1749.  
  1750.                 //Display the no. of displayed recoeds as "Search Results ([N])"
  1751.                 lblSearchResultsSearchSites.Text = "Search Results (" + lstSites.Count() + ")";
  1752.  
  1753.                 dgvSearchResultSearchSites.DataSource = lstSites;
  1754.  
  1755.                 //Log method End
  1756.                 LogWrapper.LogMethodEnd("BindSearchSitesResults(List<SearchSrv.respCustomerTable> lstSites)", true);
  1757.             }
  1758.             catch (Exception ex)
  1759.             {
  1760.                 LogWrapper.LogError(ex);
  1761.                 throw;
  1762.             }
  1763.         }
  1764.  
  1765.         /// <summary>
  1766.         /// helper function to get the value of the clicked cell in a grid using it's column data proprty name 
  1767.         /// </summary>
  1768.         /// <param name="grid">
  1769.         /// The grid to search in 
  1770.         /// </param>
  1771.         /// <param name="rowIndex">
  1772.         /// The index of the cell's row
  1773.         /// </param>
  1774.         /// <param name="dataPropertName">
  1775.         /// The data property name of the cell's column
  1776.         /// </param>
  1777.         /// <returns></returns>
  1778.         private static string getGridViewCellValueByDataPropertyName(DataGridView grid, int rowIndex, string dataPropertName)
  1779.         {
  1780.             try
  1781.             {
  1782.                 var cellValue = from DataGridViewColumn c in grid.Columns
  1783.                                 where c.DataPropertyName.Equals(dataPropertName, StringComparison.CurrentCultureIgnoreCase)
  1784.                                 select Convert.ToString(grid.Rows[rowIndex].Cells[c.Index].Value);
  1785.                 return cellValue.FirstOrDefault();
  1786.             }
  1787.             catch (Exception ex)
  1788.             {
  1789.                 LogWrapper.LogError(ex);
  1790.                 throw;
  1791.             }
  1792.  
  1793.         }
  1794.  
  1795.         #endregion
  1796.  
  1797.         private void tbCustomersSearch_Click(object sender, EventArgs e)
  1798.         {
  1799.  
  1800.         }
  1801.  
  1802.  
  1803.         #endregion
  1804.  
  1805.         public class NoFocusCueButton : Button
  1806.         {
  1807.             protected override bool ShowFocusCues
  1808.             {
  1809.                 get
  1810.                 {
  1811.                     return false;
  1812.                 }
  1813.             }
  1814.         }
  1815.  
  1816.         void ShowHideNotesIcons(bool reload)
  1817.         {
  1818.             if (!DBConfigurations.ShowFloatingNotes)
  1819.                 return;
  1820.  
  1821.             if (tcRelianceDesktop.SelectedIndex == 1 && !_isNewCustomer && !string.IsNullOrEmpty(_Customer.CrmGuID))
  1822.             {
  1823.                 if (frmNotesIcons == null)
  1824.                 {
  1825.                     frmNotesIcons = new FrmNotesIcons();
  1826.                     frmNotesIcons.StartPosition = FormStartPosition.Manual;
  1827.                     SetIconsLocation();
  1828.                     frmNotesIcons.CustomerCode = string.IsNullOrEmpty(_Customer.Cust) ? _Customer.SlmnID : _Customer.Cust;
  1829.                     frmNotesIcons.PremiseCode = string.IsNullOrEmpty(_Customer.Cust) ? _Customer.SlmnSite : _Customer.Prem;
  1830.                     frmNotesIcons.AccountId = string.IsNullOrEmpty(_Customer.Cust) ? _Customer.CrmGuID : string.Empty;
  1831.                     frmNotesIcons.LoadData();
  1832.                     frmNotesIcons.Show(this);
  1833.                 }
  1834.                 else
  1835.                 {
  1836.                     if (reload)
  1837.                     {
  1838.                         frmNotesIcons.CustomerCode = string.IsNullOrEmpty(_Customer.Cust) ? _Customer.SlmnID : _Customer.Cust;
  1839.                         frmNotesIcons.PremiseCode = string.IsNullOrEmpty(_Customer.Cust) ? _Customer.SlmnSite : _Customer.Prem;
  1840.                         frmNotesIcons.AccountId = string.IsNullOrEmpty(_Customer.Cust) ? _Customer.CrmGuID : string.Empty;
  1841.                         frmNotesIcons.LoadData();
  1842.                     }
  1843.                     frmNotesIcons.Visible = true;
  1844.                 }
  1845.             }
  1846.             else
  1847.             {
  1848.                 if (frmNotesIcons != null)
  1849.                 {
  1850.                     if (reload)
  1851.                     {
  1852.                         frmNotesIcons.Visible = true;
  1853.                         frmNotesIcons.CustomerCode = _Customer.SlmnID;
  1854.                         frmNotesIcons.PremiseCode = _Customer.SlmnSite;
  1855.                         frmNotesIcons.PremiseCode = _Customer.CrmGuID;
  1856.                         frmNotesIcons.LoadData();
  1857.                     }
  1858.                     frmNotesIcons.Visible = false;
  1859.                     if (frmNotesIcons.frmListing != null && frmNotesIcons.frmListing.Visible)
  1860.                         frmNotesIcons.frmListing.Visible = false;
  1861.                     if (frmNotesIcons.frmAdding != null && frmNotesIcons.frmAdding.Visible)
  1862.                         frmNotesIcons.frmAdding.Visible = false;
  1863.                 }
  1864.             }
  1865.         }
  1866.  
  1867.         private void FrmReliance_CMS_Activated(object sender, EventArgs e)
  1868.         {
  1869.             if (frmNotesIcons != null)
  1870.             {
  1871.                 if (frmNotesIcons.frmListing != null && frmNotesIcons.frmListing.Visible)
  1872.                     frmNotesIcons.frmListing.Visible = false;
  1873.                 if (frmNotesIcons.frmAdding != null && frmNotesIcons.frmAdding.Visible && !frmNotesIcons.frmAdding.pageready)
  1874.                     frmNotesIcons.frmAdding.Visible = false;
  1875.             }
  1876.         }
  1877.  
  1878.         private void FrmReliance_CMS_LocationChanged(object sender, EventArgs e)
  1879.         {
  1880.             SetIconsLocation();
  1881.             //SetIconsLocationOnSizeChange();
  1882.         }
  1883.  
  1884.         void SetIconsLocation()
  1885.         {
  1886.             if (frmNotesIcons != null)
  1887.             {
  1888.                 frmNotesIcons.Location = new Point(this.Right - 88, this.Top + 290);
  1889.             }
  1890.         }
  1891.         void SetIconsLocationOnSizeChange()
  1892.         {
  1893.             if (frmNotesIcons != null)
  1894.             {
  1895.                 frmNotesIcons.Location = new Point(this.Right - 88, frmNotesIcons.Location.Y);
  1896.  
  1897.             }
  1898.         }
  1899.         private void FrmReliance_CMS_SizeChanged(object sender, EventArgs e)
  1900.         {
  1901.             SetIconsLocation();
  1902.             //SetIconsLocationOnSizeChange();
  1903.         }
  1904.  
  1905.         bool hasOpenedSBWin;
  1906.         object openedWindow;
  1907.         private bool CheckOpenedServiceBookingWindow()
  1908.         {
  1909.             try
  1910.             {
  1911.                 openedWindow = null;
  1912.                 hasOpenedSBWin = false;
  1913.  
  1914.                 var ifr1 = wbCRMSuperScreen.Document.GetElementById("contentIFrame");
  1915.                 if (ifr1 != null)
  1916.                 {
  1917.                     if (ifr1.Document.Window.Frames.Count > 0)
  1918.                     {
  1919.                         var ifr2 = ifr1.Document.Window.Frames[0];
  1920.                         if (ifr2 != null && ifr2.Frames != null && ifr2.Frames.Count > 0)
  1921.                         {
  1922.                             foreach (HtmlWindow ifr3 in ifr2.Frames)
  1923.                             {
  1924.                                 if (ifr3.Url.AbsoluteUri.ToLower().Contains("customereligibleservices.htm"))
  1925.                                 {
  1926.                                     var hf = ifr3.Document.GetElementById("hfHasOpenedSBWindow");
  1927.                                     if (hf != null)
  1928.                                     {
  1929.                                         var hasOpenedWindow = hf.GetAttribute("value");
  1930.                                         if (hasOpenedWindow == "1")
  1931.                                         {
  1932.                                             hasOpenedSBWin = true;
  1933.                                             MessageBox.Show("Pending service order exists, please process or cancel");
  1934.  
  1935.                                             var obj = ifr3.Document.InvokeScript("GetSBWin");
  1936.                                             if (obj != null)
  1937.                                             {
  1938.                                                 openedWindow = obj;
  1939.                                             }
  1940.  
  1941.                                             return true;
  1942.                                         }
  1943.                                     }
  1944.                                 }
  1945.                             }
  1946.                         }
  1947.                     }
  1948.                 }
  1949.             }
  1950.             catch
  1951.             {
  1952.             }
  1953.  
  1954.             return false;
  1955.         }
  1956.  
  1957.         private void SetHasOpenedSBWin()
  1958.         {
  1959.             try
  1960.             {
  1961.                 var ifr1 = wbCRMSuperScreen.Document.GetElementById("contentIFrame");
  1962.                 if (ifr1 != null)
  1963.                 {
  1964.                     if (ifr1.Document.Window.Frames.Count > 0)
  1965.                     {
  1966.                         var ifr2 = ifr1.Document.Window.Frames[0];
  1967.                         if (ifr2 != null && ifr2.Frames != null && ifr2.Frames.Count > 0)
  1968.                         {
  1969.                             foreach (HtmlWindow ifr3 in ifr2.Frames)
  1970.                             {
  1971.                                 if (ifr3.Url.AbsoluteUri.ToLower().Contains("customereligibleservices.htm"))
  1972.                                 {
  1973.                                     ifr3.Document.InvokeScript("SetOpenedWindow", new[] { openedWindow });
  1974.                                 }
  1975.                             }
  1976.                         }
  1977.                     }
  1978.                 }
  1979.             }
  1980.             catch
  1981.             {
  1982.             }
  1983.         }
  1984.  
  1985.         private void ActivateOpenedWindow()
  1986.         {
  1987.             try
  1988.             {
  1989.                 var ifr1 = wbCRMSuperScreen.Document.GetElementById("contentIFrame");
  1990.                 if (ifr1 != null)
  1991.                 {
  1992.                     if (ifr1.Document.Window.Frames.Count > 0)
  1993.                     {
  1994.                         var ifr2 = ifr1.Document.Window.Frames[0];
  1995.                         if (ifr2 != null && ifr2.Frames != null && ifr2.Frames.Count > 0)
  1996.                         {
  1997.                             foreach (HtmlWindow ifr3 in ifr2.Frames)
  1998.                             {
  1999.                                 if (ifr3.Url.AbsoluteUri.ToLower().Contains("customereligibleservices.htm"))
  2000.                                 {
  2001.                                     ifr3.Document.InvokeScript("ActivateSBWindow", null);
  2002.                                 }
  2003.                             }
  2004.                         }
  2005.                     }
  2006.                 }
  2007.             }
  2008.             catch
  2009.             {
  2010.             }
  2011.         }
  2012.  
  2013.         private void wbCRMSuperScreen_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  2014.         {
  2015.             if (e.Url.AbsoluteUri.ToLower().Contains("customereligibleservices.htm"))
  2016.             {
  2017.                 if (hasOpenedSBWin)
  2018.                 {
  2019.                     SetHasOpenedSBWin();
  2020.                 }
  2021.             }
  2022.         }
  2023.  
  2024.         private void FrmReliance_CMS_FormClosing(object sender, FormClosingEventArgs e)
  2025.         {
  2026.             if (CheckOpenedServiceBookingWindow())
  2027.             {
  2028.                 if (openedWindow != null)
  2029.                 {
  2030.                     ActivateOpenedWindow();
  2031.                 }
  2032.                 e.Cancel = true;
  2033.                 return;
  2034.             }
  2035.  
  2036.             if (DBConfigurations.ShowFloatingNotes && frmNotesIcons != null)
  2037.             {
  2038.                 frmNotesIcons.CheckUnSavedNote(true);
  2039.             }
  2040.         }
  2041.  
  2042.         private void webQASSearch_Navigated(object sender, WebBrowserNavigatedEventArgs e)
  2043.         {
  2044.             GetQASAddress();
  2045.         }
  2046.  
  2047.         private void GetQASAddress()
  2048.         {
  2049.             //var value = webQASSearch.Document.Url;
  2050.             //if (value != null && value.ToString().Length > 0)
  2051.             //{
  2052.             //    var qry = value.Query;
  2053.             //    var qrys = qry.Split('&');
  2054.             //    foreach (var q in qrys)
  2055.             //    {
  2056.             //        var vs = q.Split('=');
  2057.             //        if (vs.Length > 0)
  2058.             //        {
  2059.             //            if (vs[0] == "txtStreetName")
  2060.             //            {
  2061.             //                txtStreetName.Text = vs[1].Replace("+", " ");
  2062.             //            }
  2063.             //        }
  2064.             //    }
  2065.             //}
  2066.         }
  2067.  
  2068.         private void ddlPreDir_KeyDown(object sender, KeyEventArgs e)
  2069.         {
  2070.             ddlPreDir.DroppedDown = false;
  2071.  
  2072.         }
  2073.  
  2074.         private void ddlSuffix_KeyDown(object sender, KeyEventArgs e)
  2075.         {
  2076.             ddlSuffix.DroppedDown = false;
  2077.  
  2078.         }
  2079.  
  2080.         private void ddlPostDir_KeyDown(object sender, KeyEventArgs e)
  2081.         {
  2082.             ddlPostDir.DroppedDown = false;
  2083.         }
  2084.  
  2085.         private void ddlUnitType_KeyDown(object sender, KeyEventArgs e)
  2086.         {
  2087.             ddlUnitType.DroppedDown = false;
  2088.         }
  2089.  
  2090.         private void ddlProvince_KeyDown(object sender, KeyEventArgs e)
  2091.         {
  2092.             ddlProvince.DroppedDown = false;
  2093.         }
  2094.         bool validFirstName = true, validLastName = true, ValidPhoneNo = true, validStreetNo = true, validPreDir = true, validStreetName = true, validSuffix = true, validPostDir = true, validUnitType = true, validUnitNum = true, validCity = true, validProvince = true, validPostalCode = true;
  2095.         private void ddlPreDir_Leave(object sender, EventArgs e)
  2096.         {
  2097.             if (!String.IsNullOrEmpty(ddlPreDir.Text))
  2098.             {
  2099.                 foreach (var item in ddlPreDir.Items)
  2100.                 {
  2101.                     if (((System.Data.DataRowView)item).Row.ItemArray[0].ToString().ToLower() == ddlPreDir.Text.ToLower())
  2102.                     {
  2103.                         validPreDir = true;
  2104.                         break;
  2105.                     }
  2106.                     else
  2107.                         validPreDir = false;
  2108.                 }
  2109.                 if (!validPreDir)
  2110.                     MessageBox.Show("Invalid Pre Direction.");
  2111.             }
  2112.             else
  2113.                 validPreDir = true;
  2114.  
  2115.         }
  2116.  
  2117.         private void ddlSuffix_Leave(object sender, EventArgs e)
  2118.         {
  2119.  
  2120.             if (!String.IsNullOrEmpty(ddlSuffix.Text))
  2121.             {
  2122.                 foreach (var item in ddlSuffix.Items)
  2123.                 {
  2124.                     if (((System.Data.DataRowView)item).Row.ItemArray[0].ToString().ToLower() == ddlSuffix.Text.ToLower())
  2125.                     {
  2126.                         validSuffix = true;
  2127.                         break;
  2128.                     }
  2129.                     else
  2130.                         validSuffix  = false;
  2131.                 }
  2132.                 if (!validSuffix)
  2133.                     MessageBox.Show("Invalid Suffix.");
  2134.             }
  2135.             else
  2136.                 validSuffix = true;
  2137.         }
  2138.  
  2139.         private void ddlPostDir_Leave(object sender, EventArgs e)
  2140.         {
  2141.  
  2142.             if (!String.IsNullOrEmpty(ddlPostDir.Text))
  2143.             {
  2144.                 foreach (var item in ddlPostDir.Items)
  2145.                 {
  2146.                     if (((System.Data.DataRowView)item).Row.ItemArray[0].ToString().ToLower() == ddlPostDir.Text.ToLower())
  2147.                     {
  2148.                         validPostDir = true;
  2149.                         break;
  2150.                     }
  2151.                     else
  2152.                         validPostDir = false;
  2153.                 }
  2154.                 if (!validPostDir)
  2155.                     MessageBox.Show("Invalid Post Direction.");
  2156.             }
  2157.             else
  2158.                 validPostDir = true;
  2159.         }
  2160.  
  2161.         private void ddlUnitType_Leave(object sender, EventArgs e)
  2162.         {
  2163.             if(!String.IsNullOrEmpty(ddlUnitType.Text))
  2164.             {
  2165.                 foreach (var item in ddlUnitType.Items)
  2166.                 {
  2167.                     if (((System.Data.DataRowView)item).Row.ItemArray[0].ToString().ToLower() == ddlUnitType.Text.ToLower())
  2168.                     {
  2169.                         validUnitType = true;
  2170.                         break;
  2171.                     }
  2172.                     else
  2173.                         validUnitType = false;
  2174.                 }
  2175.                 if(!validUnitType)
  2176.                     MessageBox.Show("Invalid Unit Type.");
  2177.             }
  2178.             else 
  2179.                 validUnitType=true;
  2180.         }
  2181.  
  2182.         private void ddlProvince_Leave(object sender, EventArgs e)
  2183.         {
  2184.             if (!String.IsNullOrEmpty(ddlProvince.Text))
  2185.             {
  2186.                 foreach (var item in ddlProvince.Items)
  2187.                 {
  2188.                     if (((System.Data.DataRowView)item).Row.ItemArray[0].ToString().ToLower() == ddlProvince.Text.ToLower())
  2189.                     {
  2190.                         validProvince = true;
  2191.                         break;
  2192.                     }
  2193.                     else validProvince = false;
  2194.                 }
  2195.  
  2196.                 if (!validProvince)
  2197.                     MessageBox.Show("Invalid Province.");
  2198.             }
  2199.             else
  2200.                 validProvince = true;
  2201.  
  2202.         }
  2203.  
  2204.         private void txtLastName_Leave(object sender, EventArgs e)
  2205.         {
  2206.             if (txtLastName.Text == "*")
  2207.             {
  2208.                 MessageBox.Show("Please provide value with *.");
  2209.                 validLastName = false;
  2210.             }
  2211.             else
  2212.                 validLastName = true;
  2213.         }
  2214.  
  2215.         private void txtFirstName_Leave(object sender, EventArgs e)
  2216.         {
  2217.             if (txtFirstName.Text == "*")
  2218.             {
  2219.                 MessageBox.Show("Please provide value with *.");
  2220.                 validFirstName = false;
  2221.             }
  2222.             else
  2223.                 validFirstName = true;
  2224.         }
  2225.  
  2226.         private void txtPhoneNo_Leave(object sender, EventArgs e)
  2227.         {
  2228.             if (txtPhoneNo.Text == "*")
  2229.             {
  2230.                 MessageBox.Show("Please provide value with *.");
  2231.                 ValidPhoneNo = false;
  2232.             }
  2233.             else
  2234.                 ValidPhoneNo = true;
  2235.         }
  2236.  
  2237.         private void txtStreetNo_Leave(object sender, EventArgs e)
  2238.         {
  2239.             if (txtStreetNo.Text == "*")
  2240.             {
  2241.                 MessageBox.Show("Please provide value with *.");
  2242.                 validStreetNo = false;
  2243.             }
  2244.             else
  2245.                 validStreetNo = true;
  2246.         }
  2247.  
  2248.         private void txtStreetName_Leave(object sender, EventArgs e)
  2249.         {
  2250.             if (txtStreetName.Text == "*")
  2251.             {
  2252.                 MessageBox.Show("Please provide value with *.");
  2253.                 validStreetName = false;
  2254.             }
  2255.             else
  2256.                 validStreetName = true;
  2257.         }
  2258.  
  2259.         private void txtUnitNum_Leave(object sender, EventArgs e)
  2260.         {
  2261.             if (txtUnitNum.Text == "*")
  2262.             {
  2263.                 MessageBox.Show("Please provide value with *.");
  2264.                 validUnitNum = false;
  2265.             }
  2266.             else
  2267.                 validUnitNum = true;
  2268.         }
  2269.  
  2270.         private void txtCity_Leave(object sender, EventArgs e)
  2271.         {
  2272.             if (txtCity.Text == "*")
  2273.             {
  2274.                 MessageBox.Show("Please provide value with *.");
  2275.                 validCity = false;
  2276.             }
  2277.             else
  2278.                 validCity = true;
  2279.         }
  2280.  
  2281.         private void txtPostalCode_Leave(object sender, EventArgs e)
  2282.         {
  2283.             if (txtPostalCode.Text == "*")
  2284.             {
  2285.                 MessageBox.Show("Please provide value with *.");
  2286.                 validPostalCode = false;
  2287.             }
  2288.             else
  2289.                 validPostalCode = true;
  2290.         }
  2291.  
  2292.  
  2293.     }
  2294. }
  2295.  

Editor

You can edit this paste and save as new: