コード例 #1
0
        public object DynamicFunction(string FunctionName, object[] objParm)
        {
            try
            {
                pvtReturnObject = null;
#if (DEBUG)
                if (AppDomain.CurrentDomain.GetData("URLClientPath").ToString() == "")
                {
                    MethodInfo mi = typObjectType.GetMethod(FunctionName);
                    pvtReturnObject = mi.Invoke(busDynamicService, objParm);

                    goto DynamicFunction_Continue;
                }
#endif
                DateTime dtTimeWait = DateTime.Now.AddMilliseconds(500);

                UriRequest = new Uri(UriHeader, FunctionName);

                respondMessage = null;
                respondMessage = HttpClient.Get(UriRequest);

                while (DateTime.Now < dtTimeWait)
                {
                    System.Threading.Thread.Sleep(50);
                }

                if (HttpClient.blnConnectionFailure == true
                    | HttpClient.blnTimeoutFailure == true
                    | HttpClient.blnOtherFailure == true)
                {
                    if (HttpClient.blnConnectionFailure == true)
                    {
                        pubblnErrorHasBeenHandled = true;
                    }
                    else
                    {
                        if (HttpClient.blnTimeoutFailure == true)
                        {
                            pubblnErrorHasBeenHandled = true;
                        }
                        else
                        {
                            pubblnErrorHasBeenHandled = true;
                        }
                    }
                }
                else
                {
                    Restart myReturnObject = respondMessage.GetBody <Restart>();

                    pvtReturnObject = myReturnObject;
                }

                return(pvtReturnObject);
            }
            catch (Exception ex)
            {
                if (ex.Message.IndexOf("Communication Error") > -1
                    | ex.Message.IndexOf("Timeout Error") > -1
                    | ex.Message.IndexOf("Bad Request") > -1)
                {
                    throw ex;
                }
                else
                {
                    if (ex.Message.IndexOf("has exceeded the allotted timeout") > -1)
                    {
                        pubblnErrorHasBeenHandled = true;
                    }
                    else
                    {
                        if (ex.Message.IndexOf("was no endpoint listening") > -1)
                        {
                            pubblnErrorHasBeenHandled = true;
                        }
                        else
                        {
                            pubblnErrorHasBeenHandled = true;
                        }
                    }
                }
            }

DynamicFunction_Continue:

            return(pvtReturnObject);
        }
コード例 #2
0
        private void btnOK_Click(object sender, System.EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.AppStarting;

                this.txtUserId.Enabled     = false;
                this.txtPassword.Enabled   = false;
                this.btnOK.Enabled         = false;
                this.btnConnection.Enabled = false;

                object[] objParm = null;
                string   strClientDBConnected = "Y";

                DataSet DataSet = new DataSet();

                try
                {
                    //Check Client Databse ia Available / Check Tables are Correct
                    pvtblnInternetBeingUsed = false;
                    pvtbytCompress          = (byte[])clsISClientUtilities.DynamicFunction("Logon_Client_DataBase", objParm, false);

                    DataSet = clsISUtilities.DeCompress_Array_To_DataSet(pvtbytCompress);
                }
                catch (Exception ex)
                {
                    strClientDBConnected = "N";
                }

                if (pvtDataSet.Tables["ReturnValues"] != null)
                {
                    pvtDataSet.Tables.Remove("ReturnValues");
                }

                if (this.txtUserId.Text.Trim() == "")
                {
                    this.Cursor = Cursors.Default;

                    this.txtUserId.Enabled     = true;
                    this.txtPassword.Enabled   = true;
                    this.btnOK.Enabled         = true;
                    this.btnConnection.Enabled = true;

                    MessageBox.Show("Enter " + this.lblUserEmployee.Text + ".", this.Text,
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    this.txtUserId.Focus();
                }
                else
                {
                    if (this.txtPassword.Text.Trim() == "")
                    {
                        this.Cursor = Cursors.Default;

                        this.txtUserId.Enabled     = true;
                        this.txtPassword.Enabled   = true;
                        this.btnOK.Enabled         = true;
                        this.btnConnection.Enabled = true;

                        MessageBox.Show("Enter Password.", this.Text,
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        this.txtPassword.Focus();
                    }
                    else
                    {
                        pvtstrUserInformation = this.txtUserId.Text.Trim().ToUpper() + "|" + this.txtPassword.Text.Trim().ToUpper();

                        objParm    = new object[2];
                        objParm[0] = pvtstrUserInformation;
                        objParm[1] = strClientDBConnected;

                        pvtblnInternetBeingUsed = true;
                        //"Logon_User_New" Changed to "Logon_New_User"
                        pvtbytCompress = (byte[])clsISUtilities.DynamicFunction("Logon_New_User", objParm);

                        pvtTempDataSet = clsISUtilities.DeCompress_Array_To_DataSet(pvtbytCompress);
                        pvtDataSet.Merge(pvtTempDataSet);

                        pvtint64UserNo        = Convert.ToInt64(pvtDataSet.Tables["ReturnValues"].Rows[0]["USER_NO"]);
                        pvtstrResetInd        = pvtDataSet.Tables["ReturnValues"].Rows[0]["RESET_IND"].ToString();
                        pvtstrAccessInd       = pvtDataSet.Tables["ReturnValues"].Rows[0]["ACCESS_IND"].ToString();
                        pvtint64LastCompanyNo = Convert.ToInt64(pvtDataSet.Tables["ReturnValues"].Rows[0]["LAST_COMPANY_NO"]);
                        pvtstrPayCategoryType = pvtDataSet.Tables["ReturnValues"].Rows[0]["LAST_PAY_CATEGORY_TYPE"].ToString();

                        if (pvtint64UserNo == -1)
                        {
                            MessageBox.Show(this.lblUserEmployee.Text + " Id / Password NOT Found.", this.Text,
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);

                            this.txtUserId.Enabled   = true;
                            this.txtPassword.Enabled = true;

                            this.btnOK.Enabled         = true;
                            this.btnConnection.Enabled = true;

                            return;
                        }
                        else
                        {
                            if (pvtDataSet.Tables["ReturnValues"].Rows[0]["LOCK_IND"].ToString() == "Y")
                            {
                                frmLock frmLock = new frmLock();
                                frmLock.ShowDialog();

                                //Set so That Lower Down in Program it Closes in exe
                                AppDomain.CurrentDomain.SetData("UserNo", -1);

                                this.Close();
                                return;
                            }
                            else
                            {
                                bool           blnCompanyLocked = false;
                                frmCompanyLock frmLock          = new frmCompanyLock();

                                for (int intRow = 0; intRow < pvtDataSet.Tables["Company"].Rows.Count; intRow++)
                                {
                                    if (pvtDataSet.Tables["Company"].Rows[intRow]["LOCK_IND"].ToString() == "Y")
                                    {
                                        frmLock.dgvCompanyDataGridView.Rows.Add(pvtDataSet.Tables["Company"].Rows[intRow]["COMPANY_DESC"].ToString());
                                        blnCompanyLocked = true;
                                    }
                                }

                                if (blnCompanyLocked == true)
                                {
                                    frmLock.ShowDialog();
                                }

                                if (pvtstrResetInd == "Y")
                                {
                                    AppDomain.CurrentDomain.SetData("UserNo", pvtint64UserNo);

                                    //Password Change
                                    frmPasswordChange = new frmPasswordChange();
                                    frmPasswordChange.ShowDialog();

                                    if (AppDomain.CurrentDomain.GetData("PasswordChanged").ToString() != "Y")
                                    {
                                        //Set so That Lower Down in Program it Closes in exe
                                        AppDomain.CurrentDomain.SetData("UserNo", -1);
                                        this.Close();
                                        return;
                                    }

                                    frmPasswordChange = null;
                                }

                                this.btnOK.Enabled         = false;
                                this.btnConnection.Enabled = false;

                                AppDomain.CurrentDomain.SetData("Logoff", false);
#if (DEBUG)
                                pvtDataSet.Tables["Files"].Clear();
#endif
                                //SET ALL GLOBAL VARIABLES HERE
                                AppDomain.CurrentDomain.SetData("UserNo", pvtint64UserNo);
                                AppDomain.CurrentDomain.SetData("AccessInd", pvtstrAccessInd);
                                AppDomain.CurrentDomain.SetData("LastCompanyNo", pvtint64LastCompanyNo);

                                string strUserCompanyToLoad = "N";

                                if (pvtDataSet.Tables["UserCompanyToLoad"].Rows.Count > 0)
                                {
                                    strUserCompanyToLoad = "Y";
                                }

                                AppDomain.CurrentDomain.SetData("UserCompanyToLoad", strUserCompanyToLoad);

                                if (pvtDataSet.Tables["Files"].Rows.Count > 0)
                                {
                                    //Check for any Downloads
                                    bool blnLogoff = false;

                                    int intReturnCode = clsFileDownLoad.DownLoad_Files(ref pvtDataSet, ref DataSet, ref blnLogoff, strClientDBConnected);

                                    if (intReturnCode == 99)
                                    {
                                        //Restart Windows Service
                                        frmRestartService frmRestartService = new frmRestartService(DataSet.Tables["ReturnValues"].Rows[0]["MACHINE_NAME"].ToString(), DataSet.Tables["ReturnValues"].Rows[0]["MACHINE_IP"].ToString());

                                        frmRestartService.Show();

                                        try
                                        {
                                            clsRestartFingerPrintClockTimeAttendanceService clsRestartFingerPrintClockTimeAttendanceService;

                                            if (AppDomain.CurrentDomain.GetData("URLClientPath").ToString() != "")
                                            {
                                                //Calls Web Service Internally
                                                clsRestartFingerPrintClockTimeAttendanceService = new clsRestartFingerPrintClockTimeAttendanceService("");

                                                InteractPayrollClient.Restart Restart = (InteractPayrollClient.Restart)clsRestartFingerPrintClockTimeAttendanceService.DynamicFunction("RestartFingerPrintClockTimeAttendanceService", null);

                                                if (Restart.OK == "Y")
                                                {
                                                }
                                                else
                                                {
                                                    MessageBox.Show("Failed to Restart 'FingerPrintClockTimeAttendanceService' Service.\n\nSpeak to System Administrator.\n\nReboot of Machine '" + DataSet.Tables["ReturnValues"].Rows[0]["MACHINE_NAME"].ToString() + "' (IP = " + DataSet.Tables["ReturnValues"].Rows[0]["MACHINE_IP"].ToString() + ")\n will Allow you to Continue.",
                                                                    "Program Changes",
                                                                    MessageBoxButtons.OK,
                                                                    MessageBoxIcon.Exclamation);
                                                }
                                            }
                                            else
                                            {
                                                clsRestartFingerPrintClockTimeAttendanceService = new clsRestartFingerPrintClockTimeAttendanceService("FingerPrintClockServiceStartStop");

                                                object Restart = clsRestartFingerPrintClockTimeAttendanceService.DynamicFunction("RestartFingerPrintClockTimeAttendanceService", null);

                                                string strRestart = Restart.ToString();

                                                if (strRestart.IndexOf("FingerPrintClockServer.Restart") > -1)
                                                {
                                                    //Not Really True
                                                }
                                                else
                                                {
                                                    MessageBox.Show("Failed to Restart 'FingerPrintClockTimeAttendanceService' Service.\n\nSpeak to System Administrator.\n\nReboot of Machine '" + DataSet.Tables["ReturnValues"].Rows[0]["MACHINE_NAME"].ToString() + "' (IP = " + DataSet.Tables["ReturnValues"].Rows[0]["MACHINE_IP"].ToString() + ")\n will Allow you to Continue.",
                                                                    "Program Changes",
                                                                    MessageBoxButtons.OK,
                                                                    MessageBoxIcon.Exclamation);
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show("Failed to Restart 'FingerPrintClockTimeAttendanceService' Service.\n\nSpeak to System Administrator.\n\nReboot of Machine '" + DataSet.Tables["ReturnValues"].Rows[0]["MACHINE_NAME"].ToString() + "' (IP = " + DataSet.Tables["ReturnValues"].Rows[0]["MACHINE_IP"].ToString() + ")\n will Allow you to Continue.",
                                                            "Program Changes",
                                                            MessageBoxButtons.OK,
                                                            MessageBoxIcon.Exclamation);
                                        }

                                        frmRestartService.Close();
                                    }
                                    else
                                    {
                                        if (intReturnCode != 0)
                                        {
                                            if (AppDomain.CurrentDomain.GetData("KillApp").ToString() == "Y")
                                            {
                                            }
                                            else
                                            {
                                                MessageBox.Show("Error In Download of File.\nProgram Closing.", this.Text,
                                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                                            }

                                            //Force Program To Close
                                            AppDomain.CurrentDomain.SetData("UserNo", -1);

                                            this.Close();
                                            return;
                                        }


                                        if (blnLogoff == true)
                                        {
                                            AppDomain.CurrentDomain.SetData("Logoff", true);
                                        }
                                    }

                                    if (strClientDBConnected == "Y")
                                    {
                                        if (DataSet.Tables["FileToDelete"].Rows.Count > 0)
                                        {
                                            DataSet myDataSet = new System.Data.DataSet();

                                            DataTable myDataTable = DataSet.Tables["FileToDelete"].Copy();
                                            myDataSet.Tables.Add(myDataTable);

                                            byte[] mybytCompress = clsISClientUtilities.Compress_DataSet(DataSet);

                                            object[] obj = new object[1];
                                            obj[0] = mybytCompress;

                                            pvtblnInternetBeingUsed = false;
                                            clsISClientUtilities.DynamicFunction("Cleanup_Client_DataBase_Files", obj, false);
                                        }
                                    }
                                }
                                else
                                {
                                    //Delete Any Version Sub Directories
                                    string strDirectory = "";

                                    for (int intRow = 0; intRow < pvtDataTable.Rows.Count; intRow++)
                                    {
                                        strDirectory = AppDomain.CurrentDomain.BaseDirectory + pvtDataTable.Rows[intRow]["PROJECT_VERSION"].ToString();

                                        if (Directory.Exists(strDirectory) == true)
                                        {
                                            // Delete the target to ensure it is not there.
                                            Directory.Delete(strDirectory, true);
                                        }
                                    }
                                }

                                pvtDataSet.Tables.Remove(pvtDataSet.Tables["Files"]);

                                clsFileDownLoad = null;

                                if (pvtstrPayCategoryType == "")
                                {
                                    pvtstrPayCategoryType = "W";
                                }

                                AppDomain.CurrentDomain.SetData("LastPayCategoryType", pvtstrPayCategoryType);

                                if (pvtstrAccessInd == "S")
                                {
                                    if (pvtstrEditHelpInd == null)
                                    {
                                        //Initial Communication Failure (Reset via Connection Button)
                                        AppDomain.CurrentDomain.SetData("EditHelpInd", "N");
                                    }
                                    else
                                    {
                                        AppDomain.CurrentDomain.SetData("EditHelpInd", pvtstrEditHelpInd.Substring(0, 1));
                                    }
                                }
                                else
                                {
                                    AppDomain.CurrentDomain.SetData("EditHelpInd", "N");
                                }

                                //Used in Employee Form to Show Tax Rate
                                if (pvtstrEditHelpInd == null)
                                {
                                    AppDomain.CurrentDomain.SetData("TaxCasual", 25);
                                }
                                else
                                {
                                    AppDomain.CurrentDomain.SetData("TaxCasual", pvtstrEditHelpInd.Substring(pvtstrEditHelpInd.IndexOf(",") + 1));
                                }

                                AppDomain.CurrentDomain.SetData("CurrentForm", "");
                                AppDomain.CurrentDomain.SetData("DataSet", this.pvtDataSet);

                                string strPath = "";

                                //if (this.lstVersions.Visible == true)
                                //{
                                //    if (this.lstVersions.SelectedItem.ToString() == "Current")
                                //    {
                                //        strPath = AppDomain.CurrentDomain.BaseDirectory + "PayrollMain.dll";
                                //    }
                                //    else
                                //    {
                                //        strPath = AppDomain.CurrentDomain.BaseDirectory + this.lstVersions.SelectedItem.ToString() + "\\PayrollMain.dll";

                                //        string strPathExists = strPath.Substring(0, strPath.LastIndexOf("\\"));

                                //        if (Directory.Exists(strPathExists) == false)
                                //        {
                                //            MessageBox.Show(this.lstVersions.SelectedItem.ToString() + " has been Removed from your profile - Logon will continue with 'Current' Version.",
                                //            this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

                                //            strPath = AppDomain.CurrentDomain.BaseDirectory + "PayrollMain.dll";
                                //        }
                                //    }
                                //}
                                //else
                                //{
                                strPath = AppDomain.CurrentDomain.BaseDirectory + "PayrollMain.dll";
                                //}

                                AppDomain.CurrentDomain.SetData("StartUpFile", strPath);

                                this.Close();
                            }
                        }
                    }
                }
            }
            catch (Exception eException)
            {
                this.txtUserId.Enabled   = true;
                this.txtPassword.Enabled = true;

                this.btnOK.Enabled         = true;
                this.btnConnection.Enabled = true;

                if (pvtblnInternetBeingUsed == true)
                {
                    clsISUtilities.ErrorHandler(eException);
                }
                else
                {
                    this.clsISClientUtilities.ErrorHandler(eException);
                }
            }
        }