Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    pvtblnFromWindowsService = false;
                }

                if (pvtblnFromWindowsService == false)
                {
                    Console.WriteLine("Entered ValiditeClockingsSyncViaDB");
                }

                Check_Log_For_Archiving();

                string strConfig = AppDomain.CurrentDomain.BaseDirectory + "URLClientConfig.txt";

                FileInfo fiFileInfo = new FileInfo(strConfig);

                if (fiFileInfo.Exists == true)
                {
                    StreamReader srStreamReader = File.OpenText(strConfig);

                    string strURLPath = srStreamReader.ReadLine();

                    srStreamReader.Close();

                    AppDomain.CurrentDomain.SetData("URLClientPath", strURLPath);
                }
                else
                {
                    AppDomain.CurrentDomain.SetData("URLClientPath", "");
                }

                clsISClientUtilities = new clsISClientUtilities(null, "busValiditeClockingsSyncViaDB");

                pvtDataSet = new DataSet();

                object[] objParm = new object[1];
                objParm[0] = "Hullo";
                byte[] bytCompress = (byte[])clsISClientUtilities.DynamicFunction("Insert_Records", objParm, false);

                pvtDataSet = clsISClientUtilities.DeCompress_Array_To_DataSet(bytCompress);

                if (pvtDataSet.Tables["LinksMissing"].Rows.Count > 0)
                {
                    if (pvtblnFromWindowsService == false)
                    {
                        Console.WriteLine("EMPLOYEES NOT LINKED START*********");
                    }

                    WriteLog("EMPLOYEES NOT LINKED START*********");

                    for (int intCount = 0; intCount < pvtDataSet.Tables["LinksMissing"].Rows.Count; intCount++)
                    {
                        if (pvtblnFromWindowsService == false)
                        {
                            Console.WriteLine("Employee " + pvtDataSet.Tables["LinksMissing"].Rows[intCount]["EMPLOYEE_NO"].ToString());
                        }

                        WriteLog("Employee " + pvtDataSet.Tables["LinksMissing"].Rows[intCount]["EMPLOYEE_NO"].ToString());
                    }

                    if (pvtblnFromWindowsService == false)
                    {
                        Console.WriteLine("EMPLOYEES NOT LINKED END*********");
                    }

                    WriteLog("EMPLOYEES NOT LINKED END*********");
                }

                if (pvtblnFromWindowsService == false)
                {
                    Console.WriteLine("Number of Records Inserted = " + pvtDataSet.Tables["Clockings"].Rows.Count);
                }

                WriteLog("Number of Records Inserted = " + pvtDataSet.Tables["Clockings"].Rows.Count);

                if (pvtblnFromWindowsService == false)
                {
                    Console.WriteLine("Exit ValiditeClockingsSyncViaDB");
                }
            }
            catch (Exception ex)
            {
                string strException = ex.Message;

                if (ex.InnerException != null)
                {
                    strException = strException + " " + ex.InnerException.Message;
                }

                if (pvtblnFromWindowsService == false)
                {
                    Console.WriteLine("Exception = " + strException);
                }

                WriteExceptionLog("ClockingsService", ex);
            }
            finally
            {
                if (pvtblnFromWindowsService == false)
                {
                    Console.ReadLine();
                }
            }
        }
        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);
                }
            }
        }
Esempio n. 3
0
        public int DownLoad_Files_From_Database(DataTable parDataTable)
        {
            try
            {
                this.Show();

                this.Refresh();

                int    intProgressBarMaxValue         = 0;
                int    intProgressBarCombinedMaxValue = 0;
                string strCRC32Value = "";

                string   strFileLayerInd     = "";
                string   strFileName         = "";
                string   strFileDownloadName = "";
                string   strFilePathName     = "";
                string   strProjectVersion   = "";
                object[] objParm             = null;
                bool     blnRestartService   = false;

                bool blnComplete = false;

                pvtlngDestinationFileStartIndex = 0;

                for (int intRow = 0; intRow < parDataTable.Rows.Count; intRow++)
                {
                    //strFileName = parDataTable.Rows[intRow]["FILE_NAME"].ToString();
                    intProgressBarCombinedMaxValue += Convert.ToInt32(parDataTable.Rows[intRow]["MAX_FILE_CHUNK_NO"]);
                }

                this.prbAllFileProgress.Maximum = intProgressBarCombinedMaxValue;
                this.prbAllFileProgress.Value   = 0;

                //Download Files
                for (int intRow = 0; intRow < parDataTable.Rows.Count; intRow++)
                {
                    strProjectVersion = parDataTable.Rows[intRow]["PROJECT_VERSION"].ToString();
                    strFileLayerInd   = parDataTable.Rows[intRow]["FILE_LAYER_IND"].ToString();
                    strFileName       = parDataTable.Rows[intRow]["FILE_NAME"].ToString();

                    strFilePathName = AppDomain.CurrentDomain.BaseDirectory + parDataTable.Rows[intRow]["FILE_NAME"].ToString();
#if (DEBUG)
                    strFilePathName = AppDomain.CurrentDomain.BaseDirectory + "bin\\" + parDataTable.Rows[intRow]["FILE_NAME"].ToString();

                    if (strFileName == "URLConfig.txt")
                    {
                        string strStop = "";
                    }
#endif
                    pvtlngDestinationFileStartIndex = 0;

                    intProgressBarMaxValue = Convert.ToInt32(parDataTable.Rows[intRow]["MAX_FILE_CHUNK_NO"]);

                    this.prbFileProgress.Maximum = intProgressBarMaxValue;
                    this.prbFileProgress.Value   = 0;

                    pvtbytBytes = null;
                    pvtbytBytes = new byte[Convert.ToInt32(parDataTable.Rows[intRow]["FILE_SIZE_COMPRESSED"])];

                    this.lblFileName.Text = parDataTable.Rows[intRow]["FILE_NAME"].ToString();

                    if (strFileName.Substring(strFileName.Length - 1) == "_")
                    {
                        strFileDownloadName = strFileName.Substring(0, strFileName.Length - 1);
                    }
                    else
                    {
                        strFileDownloadName = strFileName;
                    }

                    for (int intRow1 = 1; intRow1 <= Convert.ToInt32(parDataTable.Rows[intRow]["MAX_FILE_CHUNK_NO"]); intRow1++)
                    {
                        objParm    = new object[6];
                        objParm[0] = Convert.ToInt64(parDataTable.Rows[intRow]["COMPANY_NO"]);
                        objParm[1] = strProjectVersion;
                        objParm[2] = parDataTable.Rows[intRow]["FROM_IND"].ToString();
                        objParm[3] = parDataTable.Rows[intRow]["FILE_LAYER_IND"].ToString();
                        objParm[4] = strFileDownloadName;
                        objParm[5] = intRow1;

                        pvtbytTempBytes = (byte[])clsISUtilities.DynamicFunction("Get_New_File_Chunk", objParm);

                        if (AppDomain.CurrentDomain.GetData("KillApp").ToString() == "Y")
                        {
                            break;
                        }

                        //0=Client Database 1=Presentation Layer
                        if (parDataTable.Rows[intRow]["FROM_IND"].ToString() == "0")
                        {
                            if (intRow1 == Convert.ToInt32(parDataTable.Rows[intRow]["MAX_FILE_CHUNK_NO"]))
                            {
                                blnComplete = true;
                            }
                            else
                            {
                                blnComplete = false;
                            }

                            objParm    = new object[10];
                            objParm[0] = strFileDownloadName;
                            objParm[1] = parDataTable.Rows[intRow]["FILE_LAYER_IND"].ToString();
                            objParm[2] = intRow1;
                            objParm[3] = pvtbytTempBytes;
                            objParm[4] = blnComplete;
                            objParm[5] = parDataTable.Rows[intRow]["FILE_CRC_VALUE"].ToString();
                            objParm[6] = Convert.ToInt32(parDataTable.Rows[intRow]["FILE_SIZE_COMPRESSED"]);
                            objParm[7] = Convert.ToInt32(parDataTable.Rows[intRow]["FILE_SIZE"]);
                            objParm[8] = Convert.ToDateTime(parDataTable.Rows[intRow]["FILE_LAST_UPDATED_DATE"]);
                            objParm[9] = parDataTable.Rows[intRow]["FILE_VERSION_NO"].ToString();

                            //Client Database
                            int intReturnCode = (int)clsISClientUtilities.DynamicFunction("Insert_New_File_Chunk", objParm, false);

                            if (intReturnCode == 1)
                            {
                                System.Windows.Forms.MessageBox.Show("File CRC Error",
                                                                     "Error",
                                                                     MessageBoxButtons.OK,
                                                                     MessageBoxIcon.Error);

                                return(1);
                            }
                            else
                            {
                                if (intReturnCode == 9)
                                {
                                    blnRestartService = true;
                                }
                            }
                        }
                        else
                        {
                            Array.Copy(pvtbytTempBytes, 0, pvtbytBytes, pvtlngDestinationFileStartIndex, pvtbytTempBytes.Length);
                            pvtlngDestinationFileStartIndex += pvtbytTempBytes.Length;
                        }

                        this.prbAllFileProgress.Value += 1;
                        this.prbFileProgress.Value    += 1;
                        this.Refresh();
                        Application.DoEvents();
                    }

                    if (AppDomain.CurrentDomain.GetData("KillApp").ToString() == "Y")
                    {
                        this.Hide();

                        this.Refresh();

                        return(1);
                    }

                    if (parDataTable.Rows[intRow]["FROM_IND"].ToString() != "0")
                    {
                        pvtbytDecompressedBytes = null;
                        pvtbytDecompressedBytes = new byte[Convert.ToInt32(parDataTable.Rows[intRow]["FILE_SIZE"])];

                        //Open Memory Stream with Compressed Data
                        MemoryStream msMemoryStream = new MemoryStream(pvtbytBytes);

                        System.IO.Compression.GZipStream GZipStreamDecompress = new GZipStream(msMemoryStream, CompressionMode.Decompress);

                        //Decompress Bytes
                        pvtbrBinaryReader       = new BinaryReader(GZipStreamDecompress);
                        pvtbytDecompressedBytes = pvtbrBinaryReader.ReadBytes(Convert.ToInt32(parDataTable.Rows[intRow]["FILE_SIZE"]));

                        if (parDataTable.Rows[intRow]["FILE_CRC_VALUE"].ToString() != "")
                        {
                            //CRC32 Value
                            strCRC32Value = "";

                            foreach (byte b in clsCrc32.ComputeHash(pvtbytDecompressedBytes))
                            {
                                strCRC32Value += b.ToString("x2").ToLower();
                            }

                            if (strCRC32Value != parDataTable.Rows[intRow]["FILE_CRC_VALUE"].ToString())
                            {
                                //Error
                                return(1);
                            }
                        }

                        pvtfsFileStream   = null;
                        pvtbwBinaryWriter = null;

                        pvtfsFileStream   = new FileStream(strFilePathName, FileMode.Create);
                        pvtbwBinaryWriter = new BinaryWriter(pvtfsFileStream);

                        pvtbwBinaryWriter.Write(pvtbytDecompressedBytes);

                        //Write Memory Portion To Disk
                        pvtbwBinaryWriter.Close();

                        File.SetLastWriteTime(strFilePathName, Convert.ToDateTime(parDataTable.Rows[intRow]["FILE_LAST_UPDATED_DATE"]));
                    }
                }

                this.Hide();

                this.Refresh();

                if (blnRestartService == true)
                {
                    return(99);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception eException)
            {
                ErrorHandler(eException);
                return(-1);
            }
        }
Esempio n. 4
0
        private void Load_CurrentForm_Records()
        {
            try
            {
                this.btnOK.Enabled = false;

                this.Clear_DataGridView(this.dgvCostCentreDataGridView);
                this.Clear_DataGridView(this.dgvCostCentreChosenDataGridView);
                this.Clear_DataGridView(this.dgvCostCentreDeletedDataGridView);

                this.dgvCostCentreDataGridView.Height = 516;

                this.lblCostCentreDelete.Visible = false;
                this.dgvCostCentreDeletedDataGridView.Visible = false;
                this.btnAddDeleted.Visible = false;

                object[] objParm = new object[2];
                objParm[0] = Convert.ToInt64(AppDomain.CurrentDomain.GetData("CompanyNo"));
                objParm[1] = AppDomain.CurrentDomain.GetData("FromProgramInd").ToString();

                pvtbytCompress = (byte[])clsISClientUtilities.DynamicFunction("Get_PayCategory_Records_New", objParm, false);

                pvtDataSetClient = clsISUtilities.DeCompress_Array_To_DataSet(pvtbytCompress);

                if (pvtDataSetClient == null)
                {
                    CustomMessageBox.Show("Connection to Local Database Could not be Established.",
                                          this.Text,
                                          MessageBoxButtons.OK,
                                          MessageBoxIcon.Error);

                    this.Close();
                }

                string strPayCategoryTypeDesc              = "";
                string strLastDownloadDateTime             = "";
                string strLastDownloadDateTimeYYMMDDHHMMSS = "";

                pvtPayCategoryDataView = new DataView(this.pvtDataSet.Tables["PayCategory"]
                                                      , ""
                                                      , "PAY_CATEGORY_DESC,PAY_CATEGORY_TYPE DESC"
                                                      , DataViewRowState.CurrentRows);

                for (int intIndex = 0; intIndex < pvtPayCategoryDataView.Count; intIndex++)
                {
                    if (pvtPayCategoryDataView[intIndex]["PAY_CATEGORY_TYPE"].ToString() == "W")
                    {
                        strPayCategoryTypeDesc = "Wages";
                    }
                    else
                    {
                        if (pvtPayCategoryDataView[intIndex]["PAY_CATEGORY_TYPE"].ToString() == "S")
                        {
                            strPayCategoryTypeDesc = "Salaries";
                        }
                        else
                        {
                            strPayCategoryTypeDesc = "Time Attendance";
                        }
                    }

                    DataView PayCategoryClientDataView = new DataView(pvtDataSetClient.Tables["PayCategoryClient"]
                                                                      , "PAY_CATEGORY_NO = " + pvtPayCategoryDataView[intIndex]["PAY_CATEGORY_NO"].ToString() + " AND PAY_CATEGORY_TYPE = '" + pvtPayCategoryDataView[intIndex]["PAY_CATEGORY_TYPE"].ToString() + "'"
                                                                      , ""
                                                                      , DataViewRowState.CurrentRows);

                    if (PayCategoryClientDataView.Count == 0)
                    {
                        this.dgvCostCentreDataGridView.Rows.Add(pvtPayCategoryDataView[intIndex]["PAY_CATEGORY_DESC"].ToString(),
                                                                "",
                                                                strPayCategoryTypeDesc,
                                                                pvtPayCategoryDataView[intIndex]["PAY_CATEGORY_NO"].ToString(),
                                                                "");
                    }
                    else
                    {
                        this.btnOK.Enabled = true;

                        if (PayCategoryClientDataView[0]["LAST_DOWNLOAD_DATETIME"] != System.DBNull.Value)
                        {
                            strLastDownloadDateTime             = Convert.ToDateTime(PayCategoryClientDataView[0]["LAST_DOWNLOAD_DATETIME"]).ToString("dd MMM yyyy - HH:mm:ss");
                            strLastDownloadDateTimeYYMMDDHHMMSS = Convert.ToDateTime(PayCategoryClientDataView[0]["LAST_DOWNLOAD_DATETIME"]).ToString("yyyyMMddHHmmss");
                        }
                        else
                        {
                            strLastDownloadDateTime             = "";
                            strLastDownloadDateTimeYYMMDDHHMMSS = "";
                        }

                        this.dgvCostCentreChosenDataGridView.Rows.Add(pvtPayCategoryDataView[intIndex]["PAY_CATEGORY_DESC"].ToString(),
                                                                      strLastDownloadDateTime,
                                                                      strPayCategoryTypeDesc,
                                                                      pvtPayCategoryDataView[intIndex]["PAY_CATEGORY_NO"].ToString(),
                                                                      strLastDownloadDateTimeYYMMDDHHMMSS);
                    }
                }
            }
            catch (Exception eException)
            {
                clsISClientUtilities.ErrorHandler(eException);
            }
        }
Esempio n. 5
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                string strUsers = "";

                if (this.dgvSelectedUserDataGridView.Rows.Count > 0)
                {
                    for (int intRow = 0; intRow < this.dgvSelectedUserDataGridView.Rows.Count; intRow++)
                    {
                        if (strUsers == "")
                        {
                            strUsers = this.dgvSelectedUserDataGridView[3, intRow].Value.ToString();
                        }
                        else
                        {
                            strUsers += "," + this.dgvSelectedUserDataGridView[3, intRow].Value.ToString();
                        }
                    }
                }
                else
                {
                    CustomMessageBox.Show("You need to Select User/s to Upload File to.", "File Upload", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }

                if (this.txtFilePath.Text != "")
                {
                    DialogResult dlgResult = CustomMessageBox.Show("Are you sure you want to Upload this File?",
                                                                   this.Text,
                                                                   MessageBoxButtons.YesNo,
                                                                   MessageBoxIcon.Question);

                    if (dlgResult == DialogResult.Yes)
                    {
                        this.dgvUserDataGridView.Enabled         = false;
                        this.dgvSelectedUserDataGridView.Enabled = false;
                        this.dgvFilesDataGridView.Enabled        = false;

                        this.btnAdd.Enabled       = false;
                        this.btnAddAll.Enabled    = false;
                        this.btnRemove.Enabled    = false;
                        this.btnRemoveAll.Enabled = false;

                        this.btnUpload.Enabled = false;

                        DateTime dtUploadDateTime = DateTime.Now;

                        if (this.rbnFile.Checked == true)
                        {
                            FileInfo        fi = new FileInfo(this.txtFilePath.Text);
                            FileVersionInfo fivFileVersionInfo = FileVersionInfo.GetVersionInfo(this.txtFilePath.Text);

                            string strCRC32Value          = "";
                            int    intNumberOfBytesToRead = 50000;

                            byte[] pvtbytes = new byte[intNumberOfBytesToRead];

                            DateTime dtFileLastUpdated = fi.LastWriteTime;
                            int      intFileSize       = Convert.ToInt32(fi.Length);
                            int      intCompressedSize;
                            string   strVersionNumber = fivFileVersionInfo.FileMajorPart.ToString() + "." + fivFileVersionInfo.FileMinorPart.ToString("00");
                            bool     blnComplete      = false;

                            FileStream pvtfsFileStream = new FileStream(this.txtFilePath.Text, FileMode.Open, FileAccess.Read);

                            //Read FileStream To Bytes Array
                            byte[] ByteArray = new byte[pvtfsFileStream.Length];
                            pvtfsFileStream.Read(ByteArray, 0, Convert.ToInt32(pvtfsFileStream.Length));

                            //New CRC32 Value
                            strCRC32Value = "";

                            foreach (byte b in clsCrc32.ComputeHash(ByteArray))
                            {
                                strCRC32Value += b.ToString("x2").ToLower();
                            }

                            //Open memory stream (Compressed)
                            MemoryStream msMemoryStream = new MemoryStream();

                            System.IO.Compression.GZipStream GZipStreamCompressed = new GZipStream(msMemoryStream, CompressionMode.Compress, true);
                            GZipStreamCompressed.Write(ByteArray, 0, (int)ByteArray.Length);
                            GZipStreamCompressed.Flush();
                            GZipStreamCompressed.Close();

                            //This is The File Length
                            int intNumberBlocks           = Convert.ToInt32(msMemoryStream.Length / intNumberOfBytesToRead);
                            int intNumberBytesAlreadyRead = 0;
                            int intNumberBytesRead        = 0;

                            if (intNumberBlocks * intNumberOfBytesToRead != msMemoryStream.Length)
                            {
                                intNumberBlocks += 1;
                            }

                            this.prgProgressBar.Maximum = intNumberBlocks;
                            this.prgProgressBar.Minimum = 0;
                            this.prgProgressBar.Value   = 0;
                            this.prgProgressBar.Visible = true;

                            BinaryReader pvtbrBinaryReader = new BinaryReader(msMemoryStream);

                            intCompressedSize = Convert.ToInt32(msMemoryStream.Length);

                            for (int intBlockNumber = 1; intBlockNumber <= intNumberBlocks; intBlockNumber++)
                            {
                                if (intBlockNumber == intNumberBlocks)
                                {
                                    intNumberOfBytesToRead = Convert.ToInt32(msMemoryStream.Length - intNumberBytesAlreadyRead);

                                    pvtbytes = null;
                                    pvtbytes = new byte[intNumberOfBytesToRead];

                                    blnComplete = true;
                                }

                                pvtbrBinaryReader.BaseStream.Position = intNumberBytesAlreadyRead;

                                intNumberBytesRead = pvtbrBinaryReader.Read(pvtbytes, 0, intNumberOfBytesToRead);

                                object[] objParm = new object[12];
                                objParm[0]  = Convert.ToInt64(AppDomain.CurrentDomain.GetData("UserNo"));
                                objParm[1]  = dtUploadDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                                objParm[2]  = intBlockNumber;
                                objParm[3]  = pvtstrFileName;
                                objParm[4]  = pvtbytes;
                                objParm[5]  = dtFileLastUpdated.ToString("yyyy-MM-dd HH:mm:ss");
                                objParm[6]  = intFileSize;
                                objParm[7]  = intCompressedSize;
                                objParm[8]  = strVersionNumber;
                                objParm[9]  = blnComplete;
                                objParm[10] = strCRC32Value;
                                objParm[11] = strUsers;

                                bool blnSuccessful = (bool)clsISUtilities.DynamicFunction("Upload_File", objParm);

                                if (blnSuccessful == true)
                                {
                                    intNumberBytesAlreadyRead += intNumberBytesRead;

                                    this.prgProgressBar.Value += 1;
                                    this.prgProgressBar.Refresh();
                                }
                                else
                                {
                                    CustomMessageBox.Show("Upload Error", "File Upload", MessageBoxButtons.OK, MessageBoxIcon.Error);

                                    this.prgProgressBar.Visible = false;

                                    this.dgvUserDataGridView.Enabled         = true;
                                    this.dgvSelectedUserDataGridView.Enabled = true;
                                    this.dgvFilesDataGridView.Enabled        = true;

                                    this.btnAdd.Enabled       = true;
                                    this.btnAddAll.Enabled    = true;
                                    this.btnRemove.Enabled    = true;
                                    this.btnRemoveAll.Enabled = true;

                                    this.btnUpload.Enabled = true;

                                    return;
                                }
                            }

                            pvtfsFileStream.Close();
                            msMemoryStream.Close();
                            pvtbrBinaryReader.Close();

                            pvtfsFileStream   = null;
                            msMemoryStream    = null;
                            pvtbrBinaryReader = null;
                        }
                        else
                        {
                            bool blnComplete = false;

                            object[] objParm = new object[1];
                            objParm[0] = this.txtFilePath.Text;

                            byte[]  bytCompress = (byte[])clsISClientUtilities.DynamicFunction("Load_File_Into_Database", objParm, false);
                            DataSet myDataSet   = clsISUtilities.DeCompress_Array_To_DataSet(bytCompress);

                            int intNumberBlocks = Convert.ToInt32(myDataSet.Tables["FileUploaded"].Rows[0]["FILE_NUMBER_BLOCKS"]);

                            this.prgProgressBar.Maximum = intNumberBlocks;
                            this.prgProgressBar.Minimum = 0;
                            this.prgProgressBar.Value   = 0;
                            this.prgProgressBar.Visible = true;

                            if (intNumberBlocks != -1)
                            {
                                for (int intBlockNumber = 1; intBlockNumber <= intNumberBlocks; intBlockNumber++)
                                {
                                    objParm    = new object[2];
                                    objParm[0] = myDataSet.Tables["FileUploaded"].Rows[0]["FILE_NAME"].ToString();
                                    objParm[1] = intBlockNumber;

                                    byte[] bytArray = (byte[])clsISClientUtilities.DynamicFunction("Get_File_Chunk", objParm, false);

                                    if (intBlockNumber == intNumberBlocks)
                                    {
                                        blnComplete = true;
                                    }

                                    objParm     = new object[12];
                                    objParm[0]  = Convert.ToInt64(AppDomain.CurrentDomain.GetData("UserNo"));
                                    objParm[1]  = dtUploadDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                                    objParm[2]  = intBlockNumber;
                                    objParm[3]  = myDataSet.Tables["FileUploaded"].Rows[0]["FILE_NAME"].ToString();;
                                    objParm[4]  = bytArray;
                                    objParm[5]  = Convert.ToDateTime(myDataSet.Tables["FileUploaded"].Rows[0]["FILE_LAST_UPDATED_DATE"]).ToString("yyyy-MM-dd HH:mm:ss");
                                    objParm[6]  = Convert.ToInt32(myDataSet.Tables["FileUploaded"].Rows[0]["FILE_SIZE"]);
                                    objParm[7]  = Convert.ToInt32(myDataSet.Tables["FileUploaded"].Rows[0]["FILE_SIZE_COMPRESSED"]);
                                    objParm[8]  = myDataSet.Tables["FileUploaded"].Rows[0]["FILE_VERSION_NO"].ToString();;
                                    objParm[9]  = blnComplete;
                                    objParm[10] = myDataSet.Tables["FileUploaded"].Rows[0]["FILE_CRC_VALUE"].ToString();
                                    objParm[11] = strUsers;

                                    bool blnSuccessful = (bool)clsISUtilities.DynamicFunction("Upload_File", objParm);

                                    if (blnSuccessful == true)
                                    {
                                        this.prgProgressBar.Value += 1;
                                        this.prgProgressBar.Refresh();
                                    }
                                    else
                                    {
                                        CustomMessageBox.Show("Upload Error", "File Upload", MessageBoxButtons.OK, MessageBoxIcon.Error);

                                        this.prgProgressBar.Visible = false;

                                        this.dgvUserDataGridView.Enabled         = true;
                                        this.dgvSelectedUserDataGridView.Enabled = true;
                                        this.dgvFilesDataGridView.Enabled        = true;

                                        this.btnAdd.Enabled       = true;
                                        this.btnAddAll.Enabled    = true;
                                        this.btnRemove.Enabled    = true;
                                        this.btnRemoveAll.Enabled = true;

                                        this.btnUpload.Enabled = true;

                                        return;
                                    }
                                }
                            }
                            else
                            {
                                //Error
                            }
                        }

                        CustomMessageBox.Show("File Upload Successful.", "File Upload", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        this.prgProgressBar.Visible = false;

                        this.dgvUserDataGridView.Enabled         = true;
                        this.dgvSelectedUserDataGridView.Enabled = true;
                        this.dgvFilesDataGridView.Enabled        = true;

                        this.btnAdd.Enabled       = true;
                        this.btnAddAll.Enabled    = true;
                        this.btnRemove.Enabled    = true;
                        this.btnRemoveAll.Enabled = true;

                        this.btnUpload.Enabled = true;
                    }
                }
                else
                {
                    CustomMessageBox.Show("Choose a File to Upload.", "File Upload", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception eException)
            {
                clsISUtilities.ErrorHandler(eException);

                this.dgvUserDataGridView.Enabled         = true;
                this.dgvSelectedUserDataGridView.Enabled = true;

                this.btnAdd.Enabled       = true;
                this.btnAddAll.Enabled    = true;
                this.btnRemove.Enabled    = true;
                this.btnRemoveAll.Enabled = true;

                this.btnUpload.Enabled = true;
            }
        }