private void btnSave_Click(object sender, EventArgs e) { bool blnServerDatabaseConverted = false; try { if (this.dgvChosenPayCategoryDataGridView.Rows.Count == 0) { CustomClientMessageBox.Show("There are NO Selected Cost Centres.\nFix to Continue.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult dlgResult = CustomClientMessageBox.Show("Are you absolutely sure you want to Convert the Selected Cost Centre/s to '" + dgvConvertToPayrollTypeDataGridView[0, pvtintConvertToPayrollTypeDataGridViewRowIndex].Value.ToString() + "'", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dlgResult == DialogResult.Yes) { DataSet DataSet = new DataSet(); DataTable myDataTable = this.pvtDataSet.Tables["PayCategory"].Clone(); for (int intRow = 0; intRow < this.dgvChosenPayCategoryDataGridView.Rows.Count; intRow++) { DataRow drDataRow = myDataTable.NewRow(); drDataRow["COMPANY_NO"] = pvtInt64CompanyNo; drDataRow["PAY_CATEGORY_NO"] = Convert.ToInt32(this.dgvChosenPayCategoryDataGridView[2, intRow].Value); drDataRow["PAY_CATEGORY_TYPE"] = this.dgvChosenPayCategoryDataGridView[1, intRow].Value.ToString(); myDataTable.Rows.Add(drDataRow); } DataSet.Tables.Add(myDataTable); //Compress DataSet pvtbytCompress = clsISClientUtilities.Compress_DataSet(DataSet); object[] objParm = new object[3]; objParm[0] = pvtInt64CompanyNo; objParm[1] = pvtstrToPayCategoryType; objParm[2] = pvtbytCompress; //Backup Internet Database int intReturnCode = (int)clsISUtilities.DynamicFunction("Check_Run", objParm, false); if (intReturnCode == 9) { CustomClientMessageBox.Show("You do NOT have permission to perform this operation.\nSpeak to System Administrator.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); goto btnSave_Click_Continue; } else { if (intReturnCode == 1) { this.tmrProcess.Enabled = false; this.picDatabaseConvertInternet.Image = global::ConvertCostCentre.Properties.Resources.Error; CustomClientMessageBox.Show("There is Currently a Payroll/Time Attendance Run Date Open.\nFix to Continue.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); goto btnSave_Click_Continue; } } pvtintProcessNo = 0; pvtblnShowImage = false; this.picDatabaseBackupInternet.Image = null; this.picDatabaseBackupLocal.Image = null; this.picDatabaseConvertInternet.Image = null; this.picDatabaseConvertLocal.Image = null; this.grbConversionProcess.Visible = true; this.Refresh(); this.tmrProcess.Enabled = true; DateTime dtDateTimeNext = DateTime.Now.AddSeconds(pvtintTimeDelaySeconds); clsISUtilities.Set_New_BusinessObjectName("busBackupRestoreDatabase"); objParm = new object[2]; objParm[0] = pvtInt64CompanyNo; objParm[1] = "_Backup_Before_CostCentre_Conversion"; //Backup Internet Database intReturnCode = (int)clsISUtilities.DynamicFunction("Backup_DataBase_New", objParm, false); if (intReturnCode != 0) { this.tmrProcess.Enabled = false; this.picDatabaseBackupInternet.Image = global::ConvertCostCentre.Properties.Resources.Error; CustomClientMessageBox.Show("Error Backing up Internet Database.\nFix to Continue.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); goto btnSave_Click_Continue; } while (DateTime.Now < dtDateTimeNext) { Application.DoEvents(); } this.picDatabaseBackupInternet.Image = global::ConvertCostCentre.Properties.Resources.Ok; this.pvtintProcessNo += 1; dtDateTimeNext = DateTime.Now.AddSeconds(pvtintTimeDelaySeconds); //Reset Class clsISUtilities.Set_New_BusinessObjectName("busConvertCostCentre"); this.pnlDatabaseLocalBackup.Visible = true; this.Refresh(); clsISClientUtilities.Set_New_BusinessObjectName("busBackupRestoreClientDatabase"); objParm = new object[1]; objParm[0] = "_Backup_Before_CostCentre_Conversion"; //Backup Client Database intReturnCode = (int)clsISClientUtilities.DynamicFunction("Backup_DataBase_New", objParm, false); if (intReturnCode != 0) { this.tmrProcess.Enabled = false; this.picDatabaseBackupLocal.Image = global::ConvertCostCentre.Properties.Resources.Error; CustomClientMessageBox.Show("Error Backing up Client Database.\nFix to Continue.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); goto btnSave_Click_Continue; } while (DateTime.Now < dtDateTimeNext) { Application.DoEvents(); } this.picDatabaseBackupLocal.Image = global::ConvertCostCentre.Properties.Resources.Ok; this.pvtintProcessNo += 1; dtDateTimeNext = DateTime.Now.AddSeconds(pvtintTimeDelaySeconds); //Reset Class clsISClientUtilities.Set_New_BusinessObjectName("busClientConvertCostCentre"); objParm = new object[3]; objParm[0] = pvtInt64CompanyNo; objParm[1] = pvtstrToPayCategoryType; objParm[2] = pvtbytCompress; //Convert Server intReturnCode = (int)clsISUtilities.DynamicFunction("Convert_Records", objParm, false); if (intReturnCode == 0) { blnServerDatabaseConverted = true; while (DateTime.Now < dtDateTimeNext) { Application.DoEvents(); } this.picDatabaseConvertInternet.Image = global::ConvertCostCentre.Properties.Resources.Ok; this.pvtintProcessNo += 1; dtDateTimeNext = DateTime.Now.AddSeconds(pvtintTimeDelaySeconds); //Convert Client Databases clsISClientUtilities.DynamicFunction("Convert_Client_Records", objParm, true); while (DateTime.Now < dtDateTimeNext) { Application.DoEvents(); } this.tmrProcess.Enabled = false; this.picDatabaseConvertLocal.Image = global::ConvertCostCentre.Properties.Resources.Ok; CustomClientMessageBox.Show("Conversion Successful.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } btnSave_Click_Continue: btnCancel_Click(sender, e); } } catch (Exception eException) { this.tmrProcess.Enabled = false; if (pvtintProcessNo == 0) { this.picDatabaseBackupInternet.Image = global::ConvertCostCentre.Properties.Resources.Error; } else { if (pvtintProcessNo == 1) { this.picDatabaseBackupLocal.Image = global::ConvertCostCentre.Properties.Resources.Error; } else { if (pvtintProcessNo == 2) { this.picDatabaseConvertInternet.Image = global::ConvertCostCentre.Properties.Resources.Error; } else { if (pvtintProcessNo == 3) { this.picDatabaseConvertLocal.Image = global::ConvertCostCentre.Properties.Resources.Error; } } } } if (blnServerDatabaseConverted == true) { CustomClientMessageBox.Show("Server Database Converted. / Local Database CONVERT FAILURE.\nURGENT - Speak to System Administrator.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } clsISClientUtilities.ErrorHandler(eException); } }
private void ToolStripMenuItem_Click(object sender, EventArgs e) { string strPath = ""; object lateBoundObj = null; Form myForm; if (pvtDateTimeLast > DateTime.Now.AddSeconds(-1)) { return; } else { pvtDateTimeLast = DateTime.Now; } ToolStripMenuItem tsMenuItem = (ToolStripMenuItem)sender; AppDomain.CurrentDomain.SetData("LinkedMenuItem", tsMenuItem); try { switch (tsMenuItem.Name) { case "convertCostCenterToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "ClientConvertCostCentre.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmClientConvertCostCentre"); break; case "fileDownloadToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "FileDownload.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayroll.frmFileDownload"); break; case "fileUploadToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "FileUpload.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayroll.frmFileUpload"); break; case "databaseBackupToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "BackupRestoreClientDatabase.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmBackupDatabase"); break; case "databaseRestoreToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "BackupRestoreClientDatabase.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmRestoreDatabase"); break; case "fingerPrintReadertoolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "ChooseFingerprintReader.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayroll.frmChooseFingerprintReader"); break; case "clockReaderEmployeesLinkToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "ClockToEmployeeLink.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmClockToEmployeeLink"); break; case "dataDownloadToolStripMenuItem": case "dataUploadTimeSheetsToolStripMenuItem": DateTime dtDownloadMessage = DateTime.Now.AddSeconds(3); frmMessage = new InteractPayrollClient.frmMessage(); frmMessage.Show(); tsMenuItem.Enabled = false; object[] objParm = null; DataSet DataSet = new DataSet(); pvtstrWebServerBeenUsed = "L"; clsISClientUtilities.Set_New_BusinessObjectName("busClientPayrollLogon"); //Check Client Databse ia Available / Check Tables are Correct byte[] pvtbytCompress = (byte[])clsISClientUtilities.DynamicFunction("Logon_Client_DataBase", objParm, false); if (pvtbytCompress == null) { frmMessage.Close(); frmMessage = null; return; } DataSet = clsISUtilities.DeCompress_Array_To_DataSet(pvtbytCompress); object[] obj = new object[1]; obj[0] = Convert.ToInt64(AppDomain.CurrentDomain.GetData("UserNo")); pvtstrWebServerBeenUsed = "W"; byte[] bytCompress = (byte[])clsISUtilities.DynamicFunction("Get_New_Client_Download_Files", obj, false); if (pvtbytCompress == null) { frmMessage.Close(); frmMessage = null; return; } else { //Wait 3 Seconds while (dtDownloadMessage > DateTime.Now) { } frmMessage.Close(); frmMessage = null; } DataSet pvtDataSet = clsISUtilities.DeCompress_Array_To_DataSet(bytCompress); if (pvtDataSet.Tables["Files"].Rows.Count > 0) { bool blnLogoff = false; int intReturnCode = clsFileDownLoad.DownLoad_Files_From_TimeAttendance(ref pvtDataSet, ref DataSet, ref blnLogoff, "Y"); if (intReturnCode != 0) { if (AppDomain.CurrentDomain.GetData("KillApp").ToString() == "Y") { } else { System.Windows.Forms.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 (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); obj = new object[1]; obj[0] = mybytCompress; clsISClientUtilities.DynamicFunction("Cleanup_Client_DataBase_Files", obj, false); } if (blnLogoff == true) { System.Windows.Forms.MessageBox.Show("Changes Have been Made to the Main Program.\nYou need to Restart the Program.", "Program Changes", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); AppDomain.CurrentDomain.SetData("Logoff", true); this.Close(); return; } } //Reset Back To busTimeAttendanceMain - What It was Initially clsISClientUtilities.Set_New_BusinessObjectName("busTimeAttendanceMain"); if (tsMenuItem.Name == "dataDownloadToolStripMenuItem") { strPath = AppDomain.CurrentDomain.BaseDirectory + "TimeAttendanceDataDownload.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmTimeAttendanceDataDownload"); } else { strPath = AppDomain.CurrentDomain.BaseDirectory + "TimeAttendanceDataUpload.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmTimeAttendanceDataUpload"); } break; case "employeeOverrideMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "EmployeeOverride.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmEmployeeOverride"); break; case "usertoolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "UserClient.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmUserClient"); break; case "fingerprintWebServerIPandPort": strPath = AppDomain.CurrentDomain.BaseDirectory + "SetupInternetWebServerIP.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmSetupInternetWebServerIP"); break; case "clockToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "Clock.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmClock"); break; case "clockInBoundarytoolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "ClockInBoundary.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmClockInBoundary"); break; case "employeeToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "EmployeeClient.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmEmployeeClient"); break; case "employeeGroupToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "EmployeeGroup.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmEmployeeGroup"); break; case "employeeLinkToClockReaderToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "EmployeeLinkDevice.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmEmployeeLinkDevice"); break; case "timeSheetsToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "TimeSheetClient.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmTimeSheetClient"); break; case "timesheetBatchToolStripMenuItem": strPath = AppDomain.CurrentDomain.BaseDirectory + "TimeSheetBatchClient.dll"; myAssembly = System.Reflection.Assembly.LoadFile(strPath); lateBoundObj = myAssembly.CreateInstance("InteractPayrollClient.frmTimeSheetBatchClient"); break; default: //Window - Dynamic Add/Delete of Forms foreach (Form form in this.MdiChildren) { if (tsMenuItem.Tag != null) { if (tsMenuItem.Tag == form.Tag) { if (this.ActiveMdiChild == form) { } else { form.Activate(); } break; } } else { if (tsMenuItem.Text.IndexOf(form.Text) > -1) { if (this.ActiveMdiChild == form) { } else { form.Activate(); } break; } } } return; } myForm = (Form)lateBoundObj; myForm.MdiParent = this; myForm.Tag = tsMenuItem.Tag; if (myForm.FormBorderStyle == FormBorderStyle.None) { if (myForm.Name != "frmPasswordChange") { myForm.Height += intHeight; } } else { myForm.Icon = this.Icon; myForm.MaximizeBox = false; myForm.MinimizeBox = false; } foreach (Control myControl in myForm.Controls) { //ELR-2018-08-18 if (myForm.FormBorderStyle == FormBorderStyle.None && myForm.Name != "frmPasswordChange") { myControl.Top += intHeight; } if (myControl is Button) { Button button = (Button)myControl; #if (DEBUG) if (button.FlatStyle != FlatStyle.Flat) { System.Windows.Forms.MessageBox.Show(button.Name + " Not FlatStyle"); } #endif button.FlatStyle = FlatStyle.Flat; if (button.Text.ToUpper().IndexOf("CLOSE") > -1) { button.FlatAppearance.MouseOverBackColor = Color.Red; } //switch (myControl.Text.Replace("&", "")) //{ // case "New": // case "Update": // case "Delete": // case "Save": // case "Cancel": // myControl.EnabledChanged += new System.EventHandler(this.MdiChild_Edit_Button_EnabledChanged); // break; //} } } //ELR-2018-08-18 if (myForm.FormBorderStyle == FormBorderStyle.None && myForm.Name != "frmPasswordChange") { Label lblHeader = new Label(); lblHeader.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; lblHeader.BackColor = System.Drawing.Color.DimGray; lblHeader.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); lblHeader.ForeColor = System.Drawing.Color.Black; lblHeader.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; lblHeader.Location = new System.Drawing.Point(1, 1); lblHeader.Name = "lblHeader"; lblHeader.Size = new System.Drawing.Size(myForm.Width - (2 * intHeight), intHeight - 2); lblHeader.Text = tsMenuItem.Text; lblHeader.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lblHeader_MouseDown); lblHeader.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lblHeader_MouseMove); lblHeader.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lblHeader_MouseUp); myForm.Text = lblHeader.Text; myForm.Controls.Add(lblHeader); Button btnHeaderClose = new Button(); btnHeaderClose.BackColor = System.Drawing.Color.DimGray; btnHeaderClose.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Red; btnHeaderClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat; btnHeaderClose.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); btnHeaderClose.ForeColor = System.Drawing.Color.Black; btnHeaderClose.Location = new System.Drawing.Point(myForm.Width - intHeight, 0); btnHeaderClose.Name = "btnHeaderClose"; btnHeaderClose.Size = new System.Drawing.Size(intHeight, intHeight); btnHeaderClose.TabStop = false; btnHeaderClose.Text = "X"; btnHeaderClose.Click += new System.EventHandler(MdiChild_ButtonClose_Click); myForm.Controls.Add(btnHeaderClose); Button btnHeaderMinimize = new Button(); btnHeaderMinimize.BackColor = System.Drawing.Color.DimGray; btnHeaderMinimize.FlatStyle = System.Windows.Forms.FlatStyle.Flat; btnHeaderMinimize.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); btnHeaderMinimize.ForeColor = System.Drawing.Color.Black; btnHeaderMinimize.Location = new System.Drawing.Point(myForm.Width - (2 * intHeight) + 1, 0); btnHeaderMinimize.Name = "btnHeaderMinimize"; btnHeaderMinimize.Size = new System.Drawing.Size(intHeight, intHeight); btnHeaderMinimize.TabStop = false; btnHeaderMinimize.Text = "_"; btnHeaderMinimize.Click += new System.EventHandler(MdiChild_ButtonMinimize_Click); myForm.Controls.Add(btnHeaderMinimize); } if (myForm.FormBorderStyle == FormBorderStyle.None) { myForm.Paint += new System.Windows.Forms.PaintEventHandler(MdiChild_Paint); } System.Drawing.Rectangle rect = Screen.GetWorkingArea(this); int intX = (rect.Width - myForm.Width) / 2; int intY = (rect.Height - myForm.Height + this.pnlHeader.Height) / 2; if (AppDomain.CurrentDomain.GetData("FormSmallest") != null) { //Errol Use For Screenshots Program intY = this.pnlHeader.Height + 10; } myForm.StartPosition = FormStartPosition.Manual; myForm.Location = new Point(intX, intY); //Hook Up so That Menu Item Can br Enabled On Close myForm.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MdiChild_FormClosing); myForm.TextChanged += new System.EventHandler(MdiChild_TextChanged); myForm.Leave += new System.EventHandler(MdiChild_Leave); ToolStripMenuItem newToolStripMenuItem = new ToolStripMenuItem(myForm.Text); if (tsMenuItem.Tag != null) { myForm.Tag = tsMenuItem.Tag; newToolStripMenuItem.Tag = tsMenuItem.Tag; } windowToolStripMenuItem.DropDownItems.Add(newToolStripMenuItem); newToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click); myForm.Show(); tsMenuItem.Enabled = false; } catch (Exception ex) { tsMenuItem.Enabled = true; if (pvtstrWebServerBeenUsed == "L") { clsISClientUtilities.ErrorHandler(ex); } else { clsISUtilities.ErrorHandler(ex); } if (frmMessage != null) { frmMessage.Close(); frmMessage = null; } } }