Exemplo n.º 1
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            string reportName = "LEMSheetApprovalX.rpt";

            if (File.Exists($"{Application.StartupPath}\\{reportName}"))
            {
                var row = gridView1.GetDataRow(gridView1.FocusedRowHandle);

                try
                {
                    string userName = LoginUser.CurrUser.GetUserName();
                    using (SqlConnection sqlcon = new SqlConnection(MobileDB))
                    {
                        sqlcon.Open();

                        string     sSQL = @"ReportLEMApproval";
                        SqlCommand cmd  = new SqlCommand(sSQL, sqlcon);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@id", row.GetValue <int>(colId)));
                        cmd.Parameters.Add(new SqlParameter("@username", userName));
                        cmd.ExecuteNonQuery();
                    }

                    string[,] para = new string[2, 1];
                    para[0, 0]     = "@username";
                    para[1, 0]     = userName;
                    using (frmHM_Report_Printer frmPrint = new frmHM_Report_Printer(HMCon, HMDevXManager, para, reportName, frmHM_Report_Printer.DBFlavor.TR))
                    {
                        frmPrint.SkipDataBase = true;
                        frmPrint.ReportPath   = Application.StartupPath;
                        frmPrint.ShowDialog();
                    }
                }
                catch (Exception ex)
                {
                    ShowMessage($"Error: {ex.Message}");
                }
            }
            else
            {
                ShowMessage($"The report {reportName} cannot be found.");
            }
        }
Exemplo n.º 2
0
        private void btnPrint_Click(object sender, System.EventArgs e)
        {
            string sSelect = "select count(*) from ap_inv_header where isnull(PAYMENT_HOLD,'F') = 'T' and ap_inv_header_id=" + _AP_INV_HEADER_ID;

            if (Convert.ToInt32(ExecuteScalar(sSelect, TR_Conn)) > 0)
            {
                string sMessage = "Unable to process payment, payment hold currently exists on invoice.";
                Popup.ShowPopup(sMessage);
                this.DialogResult = DialogResult.Cancel;
                this.Close();
                return;
            }

            object oBank = lueBank.EditValue;

            if (oBank != null)
            {
                if (txtCheckNo.Text.Trim() != "")
                {
                    if ((ucAccountingPicker1.SelectedYear < _Year) || (ucAccountingPicker1.SelectedYear == _Year && ucAccountingPicker1.SelectedPeriod < _Period))
                    {
                        Popup.ShowPopup("Selected year and period must be equal to or greater than the invoice accrual year and period.");
                        return;
                    }

                    string ReportName = ExecuteScalar("select isnull(cheque_report,'') from ap_setup", TR_Conn).ToString();
                    if (ReportName == "")
                    {
                        Popup.ShowPopup("No check report has been specified.");
                        return;
                    }


                    string sFirstChkNo = txtCheckNo.EditValue.ToString();
                    string sChkDate    = deChkDate.DateTime.ToShortDateString();

                    string sExec    = "exec sp_APFillQuickChk '" + Connection.MLUser + "', " + _AP_INV_HEADER_ID + ", '" + chkIncludeHB.EditValue + "'";
                    string sMessage = ExecuteScalar(sExec, TR_Conn).ToString();
                    if (sMessage == "OK")
                    {
                        sExec = @"declare @message varchar(max)
                        exec sp_APQuickCheckPrint '" + Connection.MLUser + @"', '" + sChkDate + @"', " + oBank + @", " + sFirstChkNo + @", null, @message output 
                        select @message";
                        object oMessage = Connection.SQLExecutor.ExecuteScalar(sExec, Connection.TRConnection);
                        if (oMessage == null || oMessage == DBNull.Value)
                        {
                            Popup.ShowPopup("Error generating check data.");
                            return;
                        }

                        if (!oMessage.Equals("OK"))
                        {
                            Popup.ShowPopup(oMessage.ToString());
                            return;
                        }

                        string sUpdateMessage = "Update and post manual check to the period: " + ucAccountingPicker1.SelectedYear + " / " +
                                                ucAccountingPicker1.SelectedPeriod + ", " + PeriodName(ucAccountingPicker1.SelectedPeriod) + "?";
                        if (!b_Manual)
                        {
                            CheckElectronicSaving();

                            string[,] saParams = new string[2, 1];
                            saParams[0, 0]     = "@USERNAME";
                            saParams[1, 0]     = Connection.MLUser;
                            frmHM_Report_Printer HMRP = new frmHM_Report_Printer(Connection, myMgr, saParams, ReportName, frmHM_Report_Printer.DBFlavor.TR);

                            sSelect = "select isnull(ALLOW_CHK_PREVIEW,'F') from ap_setup";
                            if (ExecuteScalar(sSelect, TR_Conn).ToString().ToUpper() == "T")
                            {
                                HMRP.ShowPreview = true;
                            }
                            else
                            {
                                HMRP.ShowPreview = false;
                            }
                            HMRP.ElectronicSaving(false, b_ElectronicSaving);
                            HMRP.ElectronicSave += new frmHM_Report_Printer.ElectronicSaveDelegate(HMRP_ElectronicSave);
                            ElectronicSave       = false;

                            HMRP.ShowDialog();
                            IDisposable dispose = HMRP;
                            dispose.Dispose();

                            sUpdateMessage = "Printed OK? Continue with update, and post to the period: " + ucAccountingPicker1.SelectedYear + " / " +
                                             ucAccountingPicker1.SelectedPeriod + ", " + PeriodName(ucAccountingPicker1.SelectedPeriod) + "?";
                        }

                        if (Popup.ShowPopup(this, sUpdateMessage, frmPopup.PopupType.OK_Cancel)
                            == frmPopup.PopupResult.OK)
                        {
                            sMessage = ProcessCheck();
                            if (sMessage == "OK")
                            {
                                if (!b_Manual)
                                {
                                    UpdateChkNo();
                                    if (ElectronicSave)
                                    {
                                        Check_ElectronicSave();
                                    }
                                }
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                            else
                            {
                                Popup.ShowPopup(sMessage);
                            }
                        }
                    }
                    else
                    {
                        if (chkIncludeHB.Enabled)
                        {
                            Popup.ShowPopup(sMessage);
                        }
                        else
                        {
                            Popup.ShowPopup("A holdback balance only remains on this invoice, but the holdback has not been approved yet.");
                        }
                    }
                }
                else
                {
                    Popup.ShowPopup(this, "Please enter a starting check number.");
                }
            }
            else
            {
                Popup.ShowPopup(this, "Please select a bank.");
            }
        }