コード例 #1
0
        /// <summary>
        /// This method is used for closing all the child form
        /// </summary>
        /// <param name="formNumber"></param>
        private void CloseAllChildForm(int formNumber)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Dispose();
                frm.Close();
            }
            switch (formNumber)
            {
            case 1:
                FormDetail.OpenWelcomeForm();
                break;

            case 2:
                FormDetail.OpenCustomerShortCodeForm();
                break;

            case 3:
                FormDetail.OpenUserDetailsForm();
                break;

            case 4:
                FormDetail.OpenSyncOptionForm();
                break;

            case 5:
                FormDetail.OpenLDAPPathForm();
                break;

            case 6:
                FormDetail.OpenCustomerEmailForm();
                break;

            case 7:
                FormDetail.OpenInstallationPathForm();
                break;

            case 8:
                FormDetail.OpenInstallForm();
                break;
            }
            if (formNumber == 1)
            {
                btnBack.Enabled = false;
            }
            else
            {
                btnBack.Enabled = true;
            }

            if (formNumber == 8)
            {
                btnNext.Text = Common.GetResourceKeyValue("CommonInstall");
            }
            else
            {
                btnNext.Text = Common.GetResourceKeyValue("CommonNext");
            }
        }
コード例 #2
0
        /// <summary>
        /// Next button click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNext_Click(object sender, EventArgs e)
        {
            //Disabling the back button if the form is start form
            if (GlobalData.NextFormName == "StartForm")
            {
                btnBack.Enabled = false;
            }
            else
            {
                btnBack.Enabled = true;
            }

            if (btnNext.Text == Common.GetResourceKeyValue("CommonInstall"))
            {
                EnableDsableLinks(false);
                BackgroundWorker bgWorker = new BackgroundWorker();
                bgWorker.DoWork += bgWorker_Install;
                bgWorker.RunWorkerAsync();
                bgWorker.RunWorkerCompleted += bgWorker_InstallationCompleted;
                ((Install)this.MdiChildren[0]).lblWait.Text       = Common.GetResourceKeyValue("InstallWaitMessage");
                ((Install)this.MdiChildren[0]).picLoad.Visible    = true;
                ((Install)this.MdiChildren[0]).lblWait.Visible    = true;
                ((Install)this.MdiChildren[0]).txtMessage.Visible = false;
                btnNext.Enabled   = false;
                btnCancel.Enabled = false;
                btnBack.Enabled   = false;
            }
            else if (btnNext.Text == Common.GetResourceKeyValue("CommonFinish"))
            {
                GlobalData.IsBtnClose = true;
                Application.Exit();
            }
            else
            {
                if (GlobalData.NextFormName == "Install")
                {
                    btnNext.Text = Common.GetResourceKeyValue("CommonInstall");
                }
                else
                {
                    btnNext.Text = Common.GetResourceKeyValue("CommonNext");
                }
                Dictionary <TextBox, string> dictionaryTextbox = null;

                switch (GlobalData.NextFormName)
                {
                case "CustomerValidation":
                    Common.AddAppSettingData("ApiBaseUrl", ConfigurationManager.AppSettings["ApiBaseUrl"]);
                    ((frmWelcome)this.MdiChildren[0]).Close();
                    lnkLblCustomerCode.Links[0].Enabled = true;
                    FormDetail.OpenCustomerShortCodeForm();
                    break;

                case "UserDetails":
                    //Customer name validation
                    dictionaryTextbox = new Dictionary <TextBox, string>();
                    dictionaryTextbox.Add(((CustomerValidation)this.MdiChildren[0]).txtCustomerName, Common.GetResourceKeyValue("CustomerShortCodeValidationMsg"));
                    dictionaryTextbox.Add(((CustomerValidation)this.MdiChildren[0]).txtApiKey, Common.GetResourceKeyValue("ApiKeyValidationMsg"));
                    if (!IsControlRequiredFieldValidated(dictionaryTextbox))
                    {
                        return;
                    }

                    HttpWebResponse apiResponse = null;
                    try
                    {
                        apiResponse = (HttpWebResponse)Common.GetApiResponse(((CustomerValidation)this.MdiChildren[0]).txtCustomerName.Text.Trim(), ((CustomerValidation)this.MdiChildren[0]).txtApiKey.Text.Trim(), "/api/customer/validatekey", "GET", "application/json", "");
                    }
                    catch
                    {
                        MessageBox.Show(Common.GetResourceKeyValue("CustomerApiKeyValidation"), Common.GetResourceKeyValue("Error"), MessageBoxButtons.OK);
                        return;
                    }
                    if (apiResponse == null || apiResponse.StatusCode != HttpStatusCode.OK)
                    {
                        MessageBox.Show(Common.GetResourceKeyValue("CustomerApiKeyValidation"), Common.GetResourceKeyValue("Message"), MessageBoxButtons.OK);
                        return;
                    }
                    //Storing the customer name into global variable
                    Common.AddAppSettingData("CustomerShortCode", ((CustomerValidation)this.MdiChildren[0]).txtCustomerName.Text.Trim());

                    //Storing api key
                    Common.AddAppSettingData("ApiKey", ((CustomerValidation)this.MdiChildren[0]).txtApiKey.Text.Trim());
                    //Closing the current form and opening the new one
                    ((CustomerValidation)this.MdiChildren[0]).Close();
                    lnkLblUserDetails.Links[0].Enabled = true;
                    FormDetail.OpenUserDetailsForm();
                    break;

                case "SyncOption":
                    dictionaryTextbox = new Dictionary <TextBox, string>();
                    dictionaryTextbox.Add(((UserDetails)this.MdiChildren[0]).txtUserName, Common.GetResourceKeyValue("UsernameValidationMsg"));
                    dictionaryTextbox.Add(((UserDetails)this.MdiChildren[0]).txtPassword, Common.GetResourceKeyValue("PasswordValidationMsg"));
                    if (!IsControlRequiredFieldValidated(dictionaryTextbox))
                    {
                        return;
                    }
                    var streamProperties = new
                    {
                        CustomerShortCode = Common.GetAppSettingdataValue("CustomerShortCode"),
                        ApiUserName       = ((UserDetails)this.MdiChildren[0]).txtUserName.Text.Trim(),
                        ApiPassWord       = ((UserDetails)this.MdiChildren[0]).txtPassword.Text.Trim()
                    };

                    var             content  = Json.Encode(streamProperties);
                    HttpWebResponse response = null;
                    try
                    {
                        response = (HttpWebResponse)Common.GetApiResponse(Common.GetAppSettingdataValue("CustomerShortCode"), Common.GetAppSettingdataValue("ApiKey"), "/api/customer/validate", "POST", "application/json", content);
                        if (response == null || response.StatusCode != HttpStatusCode.OK)
                        {
                            MessageBox.Show(Common.GetResourceKeyValue("AuthenticationValidationMsg"), Common.GetResourceKeyValue("Message"), MessageBoxButtons.OK);
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show(Common.GetResourceKeyValue("AuthenticationValidationMsg"), Common.GetResourceKeyValue("Error"), MessageBoxButtons.OK);
                        return;
                    }
                    //Temporary store username and password to be updated in config file later on
                    Common.AddAppSettingData("UserName", ((UserDetails)this.MdiChildren[0]).txtUserName.Text.Trim());
                    Common.AddAppSettingData("Password", ((UserDetails)this.MdiChildren[0]).txtPassword.Text.Trim());
                    //Open the new form
                    ((UserDetails)this.MdiChildren[0]).Close();
                    lnkLblSyncOption.Links[0].Enabled = true;
                    FormDetail.OpenSyncOptionForm();
                    break;

                case "LDAPPath":
                    if (((SyncOption)this.MdiChildren[0]).rbtnUPN.Checked)
                    {
                        Common.AddAppSettingData("SyncOption", "userPrincipalName");
                    }
                    else
                    {
                        Common.AddAppSettingData("SyncOption", "mail");
                    }
                    ((SyncOption)this.MdiChildren[0]).Close();
                    lnkLblLDAPConfiguration.Links[0].Enabled = true;
                    FormDetail.OpenLDAPPathForm();
                    break;

                case "CustomerEmail":
                    dictionaryTextbox = new Dictionary <TextBox, string>();

                    if (((LDAPPath)this.MdiChildren[0]).chkEnableADServerName.Checked)
                    {
                        dictionaryTextbox.Add(((LDAPPath)this.MdiChildren[0]).txtLdapPathServerName, Common.GetResourceKeyValue("ServerNameRequired"));
                        dictionaryTextbox.Add(((LDAPPath)this.MdiChildren[0]).txtOuPathServerName, Common.GetResourceKeyValue("ServerNameRequired"));
                        dictionaryTextbox.Add(((LDAPPath)this.MdiChildren[0]).txtAdServerUsername, Common.GetResourceKeyValue("ServerUserNameRequired"));
                        dictionaryTextbox.Add(((LDAPPath)this.MdiChildren[0]).txtAdServerPassword, Common.GetResourceKeyValue("ServerPassweordRequired"));
                    }
                    dictionaryTextbox.Add(((LDAPPath)this.MdiChildren[0]).txtLDAPPath, Common.GetResourceKeyValue("LDAPPathRequired"));
                    dictionaryTextbox.Add(((LDAPPath)this.MdiChildren[0]).txtLDAPSecurityGroup, Common.GetResourceKeyValue("LDAPSecurityGroupRequired"));

                    if (!IsControlRequiredFieldValidated(dictionaryTextbox))
                    {
                        return;
                    }

                    if (((LDAPPath)this.MdiChildren[0]).chkEnableADServerName.Checked)
                    {
                        //Check whether ldap server validity
                        try
                        {
                            //Checks the validity of LDAP path
                            string ldapPath    = "LDAP://" + ((LDAPPath)this.MdiChildren[0]).txtLdapPathServerName.Text.Trim() + "/" + ((LDAPPath)this.MdiChildren[0]).txtLDAPPath.Text.Trim();
                            bool   isValidLDAP = Authenticate(ldapPath, ((LDAPPath)this.MdiChildren[0]).txtAdServerUsername.Text, ((LDAPPath)this.MdiChildren[0]).txtAdServerPassword.Text);
                            if (isValidLDAP)
                            {
                                //Checks the validity of OU path
                                string ouPath        = "LDAP://" + ((LDAPPath)this.MdiChildren[0]).txtLdapPathServerName.Text.Trim() + "/" + ((LDAPPath)this.MdiChildren[0]).txtLDAPSecurityGroup.Text.Trim();
                                bool   isValidOUPath = Authenticate(ouPath, ((LDAPPath)this.MdiChildren[0]).txtAdServerUsername.Text, ((LDAPPath)this.MdiChildren[0]).txtAdServerPassword.Text);
                                if (!isValidOUPath)
                                {
                                    MessageBox.Show(Common.GetResourceKeyValue("LDAPSecurityGroupValidation"), Common.GetResourceKeyValue("Message"), MessageBoxButtons.OK);
                                    return;
                                }
                            }
                            else
                            {
                                MessageBox.Show(Common.GetResourceKeyValue("LDAPPathValidation"), Common.GetResourceKeyValue("Message"), MessageBoxButtons.OK);
                                return;
                            }
                            Common.AddAppSettingData("ADServerName", ((LDAPPath)this.MdiChildren[0]).txtLdapPathServerName.Text.Trim());
                            Common.AddAppSettingData("ADServerUserName", ((LDAPPath)this.MdiChildren[0]).txtAdServerUsername.Text.Trim());
                            Common.AddAppSettingData("ADServerPassword", ((LDAPPath)this.MdiChildren[0]).txtAdServerPassword.Text.Trim());
                            Common.AddAppSettingData("LDAPPath", "LDAP://" + ((LDAPPath)this.MdiChildren[0]).txtLdapPathServerName.Text.Trim() + "/" + ((LDAPPath)this.MdiChildren[0]).txtLDAPPath.Text.Trim());
                            GlobalData.OUPath            = "LDAP://" + ((LDAPPath)this.MdiChildren[0]).txtLdapPathServerName.Text.Trim() + "/" + ((LDAPPath)this.MdiChildren[0]).txtLDAPSecurityGroup.Text.Trim();
                            GlobalData.IsCheckBoxChecked = true;
                        }
                        catch (LdapException ldapException)
                        {
                            MessageBox.Show("Error - " + ldapException.Message);
                            return;
                        }
                    }
                    else
                    {
                        try
                        {
                            bool isLDAPPath = false;
                            isLDAPPath = DirectoryEntry.Exists("LDAP://" + ((LDAPPath)this.MdiChildren[0]).txtLDAPPath.Text.Trim());
                            if (!isLDAPPath)
                            {
                                MessageBox.Show(Common.GetResourceKeyValue("LDAPPathValidation"), Common.GetResourceKeyValue("Message"), MessageBoxButtons.OK);
                                return;
                            }
                            else
                            {
                                bool isValidOUGroup = false;
                                isValidOUGroup = DirectoryEntry.Exists("LDAP://" + ((LDAPPath)this.MdiChildren[0]).txtLDAPSecurityGroup.Text.Trim());
                                if (!isValidOUGroup)
                                {
                                    MessageBox.Show(Common.GetResourceKeyValue("LDAPSecurityGroupValidation"), Common.GetResourceKeyValue("Message"), MessageBoxButtons.OK);
                                    return;
                                }
                            }
                            Common.AddAppSettingData("LDAPPath", "LDAP://" + ((LDAPPath)this.MdiChildren[0]).txtLDAPPath.Text.Trim());
                            GlobalData.OUPath            = "LDAP://" + ((LDAPPath)this.MdiChildren[0]).txtLDAPSecurityGroup.Text.Trim();
                            GlobalData.IsCheckBoxChecked = false;
                        }
                        catch
                        {
                            MessageBox.Show(Common.GetResourceKeyValue("LDAPPathValidation"), Common.GetResourceKeyValue("Message"), MessageBoxButtons.OK);
                            return;
                        }
                    }
                    GlobalData.LdapString = ((LDAPPath)this.MdiChildren[0]).txtLDAPPath.Text.Trim();
                    GlobalData.OUString   = ((LDAPPath)this.MdiChildren[0]).txtLDAPSecurityGroup.Text.Trim();
                    //Open the new form
                    ((LDAPPath)this.MdiChildren[0]).Close();
                    lnkLblCustomerEmail.Links[0].Enabled = true;
                    FormDetail.OpenCustomerEmailForm();
                    break;

                case "InstallationPath":
                    dictionaryTextbox = new Dictionary <TextBox, string>();
                    dictionaryTextbox.Add(((CustomerEmail)this.MdiChildren[0]).txtCustomerEmail, Common.GetResourceKeyValue("CustomerEmailRequired"));
                    if (!IsControlRequiredFieldValidated(dictionaryTextbox))
                    {
                        return;
                    }

                    if (!Regex.IsMatch(((CustomerEmail)this.MdiChildren[0]).txtCustomerEmail.Text.Trim(), @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                                       @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$", RegexOptions.IgnoreCase))
                    {
                        MessageBox.Show(Common.GetResourceKeyValue("CustomerEmailValidation"), Common.GetResourceKeyValue("Message"), MessageBoxButtons.OK);
                        return;
                    }
                    Common.AddAppSettingData("NotificationEmail", ((CustomerEmail)this.MdiChildren[0]).txtCustomerEmail.Text.Trim());
                    ((CustomerEmail)this.MdiChildren[0]).Close();
                    lnkLblInstallationPath.Links[0].Enabled = true;
                    FormDetail.OpenInstallationPathForm();
                    break;

                case "Install":
                    if (Common.GetPreviousAppSettings() == null)
                    {
                        string path = ((InstallationPath)this.MdiChildren[0]).txtInstallationPath.Text;
                        if (System.IO.Directory.Exists(path))
                        {
                            GlobalData.InstallationPath = path;
                        }
                        else
                        {
                            MessageBox.Show(Common.GetResourceKeyValue("PathValidationMsg"), Common.GetResourceKeyValue("Message"), MessageBoxButtons.OK);
                            return;
                        }
                        ((InstallationPath)this.MdiChildren[0]).Close();
                        lnkLblInstall.Links[0].Enabled = true;
                    }
                    else
                    {
                        ((frmWelcome)this.MdiChildren[0]).Close();
                    }
                    FormDetail.OpenInstallForm();
                    break;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Back button click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBack_Click(object sender, EventArgs e)
        {
            //Disabling the back button if it is a start form
            if (GlobalData.BackFormName == "StartForm")
            {
                btnBack.Enabled = false;
            }
            else
            {
                btnBack.Enabled = true;
            }

            btnNext.Text = Common.GetResourceKeyValue("CommonNext");

            if (!string.IsNullOrEmpty(GlobalData.BackFormName))
            {
                //loading the appropriate form based on the form name
                switch (GlobalData.BackFormName)
                {
                case "StartForm":
                    if (Common.GetPreviousAppSettings() != null)
                    {
                        ((Install)this.MdiChildren[0]).Close();
                    }
                    else
                    {
                        ((CustomerValidation)this.MdiChildren[0]).Close();
                    }
                    FormDetail.OpenWelcomeForm();
                    break;

                case "CustomerValidation":
                    ((UserDetails)this.MdiChildren[0]).Close();
                    FormDetail.OpenCustomerShortCodeForm();
                    break;

                case "UserDetails":
                    ((SyncOption)this.MdiChildren[0]).Close();
                    FormDetail.OpenUserDetailsForm();
                    break;

                case "SyncOption":
                    ((LDAPPath)this.MdiChildren[0]).Close();
                    FormDetail.OpenSyncOptionForm();
                    break;

                case "LDAPPath":
                    ((CustomerEmail)this.MdiChildren[0]).Close();
                    FormDetail.OpenLDAPPathForm();
                    break;

                case "CustomerEmail":
                    ((InstallationPath)this.MdiChildren[0]).Close();
                    FormDetail.OpenCustomerEmailForm();
                    break;

                case "InstallationPath":
                    ((Install)this.MdiChildren[0]).Close();
                    FormDetail.OpenInstallationPathForm();
                    break;

                case "Install":
                    FormDetail.OpenInstallForm();
                    break;
                }
            }
        }