예제 #1
0
        private void btnOK_Click(object sender, System.EventArgs e)
        {
            try
            {
                DialogResult dlgResult = CustomMessageBox.Show("Are you sure you want to Upload this Data?",
                                                               this.Text,
                                                               MessageBoxButtons.YesNo,
                                                               MessageBoxIcon.Warning);

                if (dlgResult == DialogResult.Yes)
                {
                    string strPayCategoryWhere = "";

                    //DataSetClient = null;
                    //DataSetClient = new DataSet();

                    for (int intRow = 0; intRow < this.dgvPayCategoryDataGridView.Rows.Count; intRow++)
                    {
                        if (intRow == 0)
                        {
                            strPayCategoryWhere = " AND EPC.PAY_CATEGORY_NO IN (" + this.dgvPayCategoryDataGridView[5, intRow].Value.ToString();
                        }
                        else
                        {
                            strPayCategoryWhere += "," + this.dgvPayCategoryDataGridView[5, intRow].Value.ToString();
                        }
                    }

                    strPayCategoryWhere += ")";

                    pvtTempDataSet = null;
                    pvtTempDataSet = new DataSet();

                    DataTable myEmployeeDataTable;
                    myEmployeeDataTable = pvtDataSet.Tables["Employee"].Copy();
                    pvtTempDataSet.Tables.Add(myEmployeeDataTable);

                    DataTable myEmployeePayCategoryDataTable;
                    myEmployeePayCategoryDataTable = pvtDataSet.Tables["EmployeePayCategory"].Copy();
                    pvtTempDataSet.Tables.Add(myEmployeePayCategoryDataTable);

                    //Compress DataSet
                    pvtbytCompress = clsISUtilities.Compress_DataSet(pvtTempDataSet);

                    object[] objParm = new object[5];
                    objParm[0] = Convert.ToInt64(AppDomain.CurrentDomain.GetData("CompanyNo"));
                    objParm[1] = pvtstrPayrollType;
                    objParm[2] = strPayCategoryWhere;
                    objParm[3] = Convert.ToDateTime(this.pvtPayCategoryDataView[0]["TIMESHEET_UPLOAD_DATETIME"]).ToString("yyyy-MM-dd");
                    objParm[4] = pvtbytCompress;

                    blnclsISClientUtilities = true;
                    pvtbytCompress          = (byte[])this.clsISClientUtilities.DynamicFunction("Get_Upload_Data", objParm, false);

                    DataSet DataSetClient = clsISClientUtilities.DeCompress_Array_To_DataSet(pvtbytCompress);

                    if (DataSetClient.Tables["ErrorCount"].Rows.Count > 0)
                    {
                        if (DataSetClient.Tables["ErrorCount"].Rows[0]["INDICATOR"].ToString() == "X")
                        {
                            CustomMessageBox.Show("There are Time Sheets with Errors on the Client Database.\n\nYou Need to Fix these TimeSheets on (Interact Time & Attendance Program) to Proceed.\n\nProcess Cancelled.",
                                                  this.Text,
                                                  MessageBoxButtons.OK,
                                                  MessageBoxIcon.Error);

                            return;
                        }
                    }

                    if (DataSetClient.Tables["Dates"].Rows.Count > 0)
                    {
                        this.grbUploadProgress.Visible = true;
                        this.pgbProgressBar.Maximum    = DataSetClient.Tables["Dates"].Rows.Count + 1;

                        for (int intRow = 0; intRow < DataSetClient.Tables["Dates"].Rows.Count; intRow++)
                        {
                            //From Clint Database
                            objParm    = new object[4];
                            objParm[0] = Convert.ToInt64(AppDomain.CurrentDomain.GetData("CompanyNo"));
                            objParm[1] = pvtstrPayrollType;
                            objParm[2] = strPayCategoryWhere;
                            objParm[3] = Convert.ToDateTime(DataSetClient.Tables["Dates"].Rows[intRow]["TIMESHEET_DATE"]).ToString("yyyy-MM-dd");

                            blnclsISClientUtilities = true;
                            pvtbytCompress          = (byte[])this.clsISClientUtilities.DynamicFunction("Get_Upload_Data_For_Day", objParm, false);

                            //Internet Database Insert
                            objParm    = new object[6];
                            objParm[0] = Convert.ToInt64(AppDomain.CurrentDomain.GetData("CompanyNo"));
                            objParm[1] = Convert.ToDateTime(DataSetClient.Tables["Dates"].Rows[intRow]["TIMESHEET_DATE"]);
                            objParm[2] = pvtbytCompress;
                            objParm[3] = pvtstrPayrollType;
                            objParm[4] = Convert.ToDateTime(this.pvtPayCategoryDataView[0]["PAY_PERIOD_DATE"]).ToString("yyyy-MM-dd");
                            objParm[5] = Convert.ToDateTime(this.pvtPayCategoryDataView[0]["TIMESHEET_UPLOAD_DATETIME"]).ToString("yyyy-MM-dd");


                            blnclsISClientUtilities = false;
                            string strUploadDateTime = (string)clsISUtilities.DynamicFunction("Insert_TimeSheet_Records", objParm, false);

                            //Update Client PAYCATEGORY Records with Date TimeStamp
                            objParm    = new object[3];
                            objParm[0] = Convert.ToInt64(AppDomain.CurrentDomain.GetData("CompanyNo"));
                            objParm[1] = strUploadDateTime;
                            objParm[2] = pvtbytCompress;

                            blnclsISClientUtilities = true;
                            this.clsISClientUtilities.DynamicFunction("Update_PayCategory_Last_Upload_DateTime", objParm, false);

                            this.pgbProgressBar.Value += 1;
                        }

                        this.Refresh();

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

                        blnclsISClientUtilities = true;
                        this.clsISClientUtilities.DynamicFunction("Move_Data_To_History_And_Cleanup", objParm, false);

                        this.pgbProgressBar.Value += 1;
                        this.Refresh();

                        CustomMessageBox.Show("Upload Successful.",
                                              this.Text,
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Information);
                    }
                    else
                    {
                        CustomMessageBox.Show("There is NO Data to Upload",
                                              this.Text,
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Information);
                    }

                    this.grbUploadProgress.Visible = false;
                }
            }
            catch (Exception eException)
            {
                if (blnclsISClientUtilities == true)
                {
                    clsISClientUtilities.ErrorHandler(eException);
                }
                else
                {
                    clsISUtilities.ErrorHandler(eException);
                }
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime dtFromDate         = DateTime.Now;
                DateTime dtToDate           = DateTime.Now;
                string   strReportType      = "";
                string   strEmployeeNoIN    = "";
                string   strPayCategoryNoIN = "";

                string strOrder           = "E";
                string strGroupCostCentre = "N";

                if (this.rbnEmployeeSelected.Checked == true)
                {
                    if (this.dgvChosenEmployeeDataGridView.Rows.Count == 0)
                    {
                        this.tabControl.SelectedIndex = 0;

                        CustomMessageBox.Show("Select Employee/s.",
                                              this.Text,
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Information);

                        this.btnEmployeeAdd.Focus();

                        return;
                    }
                    else
                    {
                        for (int intRow = 0; intRow < this.dgvChosenEmployeeDataGridView.Rows.Count; intRow++)
                        {
                            if (intRow == 0)
                            {
                                strEmployeeNoIN = "(" + this.dgvChosenEmployeeDataGridView[3, intRow].Value.ToString();
                            }
                            else
                            {
                                strEmployeeNoIN += "," + this.dgvChosenEmployeeDataGridView[3, intRow].Value.ToString();
                            }
                        }

                        strEmployeeNoIN += ") ";
                    }
                }

                if (this.rbnCostCentreSelected.Checked == true)
                {
                    if (this.dgvChosenCostCentreDataGridView.Rows.Count == 0)
                    {
                        this.tabControl.SelectedIndex = 1;

                        CustomMessageBox.Show("Select Cost Centre/s.",
                                              this.Text,
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Information);

                        this.btnEmployeeAdd.Focus();

                        return;
                    }
                    else
                    {
                        for (int intRow = 0; intRow < this.dgvChosenCostCentreDataGridView.Rows.Count; intRow++)
                        {
                            if (intRow == 0)
                            {
                                strPayCategoryNoIN = "(" + this.dgvChosenCostCentreDataGridView[1, intRow].Value.ToString();
                            }
                            else
                            {
                                strPayCategoryNoIN += "," + this.dgvChosenCostCentreDataGridView[1, intRow].Value.ToString();
                            }
                        }

                        strPayCategoryNoIN += ") ";
                    }
                }

                if (this.rbnPrintName.Checked == true)
                {
                    strOrder = "N";
                }
                else
                {
                    if (this.rbnPrintSurname.Checked == true)
                    {
                        strOrder = "S";
                    }
                }

                if (this.chkByPayParameter.Checked == true)
                {
                    strGroupCostCentre = "Y";
                }

                this.reportViewer.Clear();
                this.reportViewer.Refresh();
                this.tabMainControl.SelectedIndex = 1;

                object[] objParm = new object[11];
                objParm[0]  = Convert.ToInt64(AppDomain.CurrentDomain.GetData("CompanyNo"));
                objParm[1]  = pvtstrPayrollType;
                objParm[2]  = strReportType;
                objParm[3]  = strEmployeeNoIN;
                objParm[4]  = strPayCategoryNoIN;
                objParm[5]  = this.dgvRunDateDataGridView[1, this.Get_DataGridView_SelectedRowIndex(this.dgvRunDateDataGridView)].Value.ToString();
                objParm[6]  = AppDomain.CurrentDomain.GetData("FromProgramInd").ToString();
                objParm[7]  = strOrder;
                objParm[8]  = strGroupCostCentre;
                objParm[9]  = Convert.ToInt64(AppDomain.CurrentDomain.GetData("UserNo"));
                objParm[10] = AppDomain.CurrentDomain.GetData("AccessInd").ToString();

                pvtbytCompress = (byte[])clsISUtilities.DynamicFunction("Print_Report", objParm);

                pvtTempDataSet = clsISUtilities.DeCompress_Array_To_DataSet(pvtbytCompress);

                DataView EmployeeDataView = new DataView(this.pvtDataSet.Tables["Employee"],
                                                         "",
                                                         "EMPLOYEE_NO",
                                                         DataViewRowState.CurrentRows);

                DataView PayCategoryDataView = new DataView(this.pvtDataSet.Tables["PayCategory"],
                                                            "",
                                                            "PAY_CATEGORY_NO",
                                                            DataViewRowState.CurrentRows);

                if (pvtTempDataSet.Tables["Report"].Rows.Count == 0)
                {
                    CustomMessageBox.Show("Empty Result Set.",
                                          this.Text,
                                          MessageBoxButtons.OK,
                                          MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    this.tabPage2.Cursor = Cursors.WaitCursor;

                    pvtTempDataSet.Tables["Report"].Columns.Add("COMPANY_DESC", typeof(String));
                    pvtTempDataSet.Tables["Report"].Columns.Add("MAIN_REPORT_HEADER_DESC", typeof(String));
                    pvtTempDataSet.Tables["Report"].Columns.Add("REPORT_HEADER_DESC", typeof(String));
                    pvtTempDataSet.Tables["Report"].Columns.Add("REPORT_DATETIME", typeof(String));

                    pvtTempDataSet.Tables["Report"].Columns.Add("PAY_CATEGORY_DESC", typeof(String));
                    pvtTempDataSet.Tables["Report"].Columns.Add("EMPLOYEE_CODE", typeof(String));
                    pvtTempDataSet.Tables["Report"].Columns.Add("EMPLOYEE_SURNAME", typeof(String));
                    pvtTempDataSet.Tables["Report"].Columns.Add("EMPLOYEE_NAME", typeof(String));

                    int intFindRow = -1;

                    for (int intRow = 0; intRow < this.pvtTempDataSet.Tables["Report"].Rows.Count; intRow++)
                    {
                        intFindRow = EmployeeDataView.Find(pvtTempDataSet.Tables["Report"].Rows[intRow]["EMPLOYEE_NO"].ToString());
                        pvtTempDataSet.Tables["Report"].Rows[intRow]["EMPLOYEE_CODE"]    = EmployeeDataView[intFindRow]["EMPLOYEE_CODE"].ToString();
                        pvtTempDataSet.Tables["Report"].Rows[intRow]["EMPLOYEE_SURNAME"] = EmployeeDataView[intFindRow]["EMPLOYEE_SURNAME"].ToString();
                        pvtTempDataSet.Tables["Report"].Rows[intRow]["EMPLOYEE_NAME"]    = EmployeeDataView[intFindRow]["EMPLOYEE_NAME"].ToString();

                        if (Convert.ToInt32(pvtTempDataSet.Tables["Report"].Rows[intRow]["PAY_CATEGORY_NO"]) != 0)
                        {
                            intFindRow = PayCategoryDataView.Find(this.pvtTempDataSet.Tables["Report"].Rows[intRow]["PAY_CATEGORY_NO"].ToString());
                            pvtTempDataSet.Tables["Report"].Rows[intRow]["PAY_CATEGORY_DESC"] = PayCategoryDataView[intFindRow]["PAY_CATEGORY_DESC"].ToString();
                        }

                        if (intRow == 0)
                        {
                            pvtTempDataSet.Tables["Report"].Rows[0]["COMPANY_DESC"] = pvtTempDataSet.Tables["ReportHeader"].Rows[0]["COMPANY_DESC"].ToString();

                            if (AppDomain.CurrentDomain.GetData("FromProgramInd").ToString() == "P")
                            {
                                pvtTempDataSet.Tables["Report"].Rows[0]["MAIN_REPORT_HEADER_DESC"] = "Timesheet Totals";
                            }
                            else
                            {
                                pvtTempDataSet.Tables["Report"].Rows[0]["MAIN_REPORT_HEADER_DESC"] = "Timesheet Totals";
                            }

                            pvtTempDataSet.Tables["Report"].Rows[0]["REPORT_HEADER_DESC"] = "Pay Period Date - " + this.dgvRunDateDataGridView[0, this.Get_DataGridView_SelectedRowIndex(this.dgvRunDateDataGridView)].Value.ToString();
                            pvtTempDataSet.Tables["Report"].Rows[0]["REPORT_DATETIME"]    = pvtTempDataSet.Tables["ReportHeader"].Rows[0]["REPORT_DATETIME"].ToString();

                            //pvtTempDataSet.Tables["Report"].Rows[intRow]["EMPLOYEE_CODE"] = "ZZZZZZZZ";
                            //pvtTempDataSet.Tables["Report"].Rows[intRow]["EMPLOYEE_SURNAME"] = "ZZZZZZZZZZZZZZZZZZZZ";
                            //pvtTempDataSet.Tables["Report"].Rows[intRow]["EMPLOYEE_NAME"] = "ZZZZZZZZZZZZZZZZZZZZ";
                        }
                    }

                    this.tabPage2.Cursor = Cursors.Default;

                    pvtTempDataSet.AcceptChanges();

                    Microsoft.Reporting.WinForms.ReportDataSource myReportDataSource = new Microsoft.Reporting.WinForms.ReportDataSource("Report", pvtTempDataSet.Tables["Report"]);

                    this.reportViewer.LocalReport.ReportEmbeddedResource = "RptTimeSheetTotals.Report.rdlc";

                    this.reportViewer.LocalReport.DataSources.Clear();
                    this.reportViewer.LocalReport.DataSources.Add(myReportDataSource);

                    this.tabMainControl.SelectedIndex = 1;

                    this.reportViewer.RefreshReport();
                    this.reportViewer.Focus();
                }
            }
            catch (Exception eException)
            {
                this.tabPage2.Cursor = Cursors.Default;
                clsISUtilities.ErrorHandler(eException);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string strEmployeeIn = "";

                if (this.dgvChosenEmployeeDataGridView.Rows.Count == 0)
                {
                    CustomMessageBox.Show("Select Employees.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    return;
                }
                else
                {
                    for (int intRow = 0; intRow < this.dgvChosenEmployeeDataGridView.Rows.Count; intRow++)
                    {
                        if (intRow == 0)
                        {
                            strEmployeeIn = "(" + this.dgvChosenEmployeeDataGridView[3, intRow].Value.ToString();
                        }
                        else
                        {
                            strEmployeeIn += "," + this.dgvChosenEmployeeDataGridView[3, intRow].Value.ToString();
                        }
                    }

                    strEmployeeIn += ")";
                }

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

                int intReturnCode = (int)clsISUtilities.DynamicFunction("Backup_DataBase", objParm);

                if (intReturnCode == 0)
                {
                    objParm    = new object[3];
                    objParm[0] = Convert.ToInt64(AppDomain.CurrentDomain.GetData("CompanyNo"));
                    objParm[1] = pvtstrPayrollType;
                    objParm[2] = strEmployeeIn;

                    pvtbytCompress = (byte[])clsISUtilities.DynamicFunction("Reset_Employee_TakeOn", objParm, true);

                    pvtDataSet = clsISUtilities.DeCompress_Array_To_DataSet(pvtbytCompress);
                }
                else
                {
                    CustomMessageBox.Show("Backup of Database Failed.\n\nAction Cancelled.",
                                          this.Text,
                                          MessageBoxButtons.OK,
                                          MessageBoxIcon.Error);
                }

                this.btnCancel_Click(sender, e);

                //this.Set_DataGridView_SelectedRowIndex(this.dgvPayrollTypeDataGridView, this.Get_DataGridView_SelectedRowIndex(this.dgvPayrollTypeDataGridView));
            }
            catch (Exception eException)
            {
                clsISUtilities.ErrorHandler(eException);
            }
        }