Exemple #1
0
        private void buttonPrint_Click(object sender, EventArgs e)
        {
            int Selection = this.dataGridViewJournel.CurrentCell.RowIndex;

            Warranties = DataProvider.GetWarrenties(0, 10, null,
                                                    this.dataGridViewJournel.CurrentRow.Cells["WarrentyNumber"].Value.ToString(),
                                                    null, null, null);
            Warranty TempWarrenties = (Warranty)Warranties.Clone();

            var errorMessage = this.dataGridViewJournel.CurrentRow.Cells["ErrorMessage"].Value.ToString();

            if (errorMessage.Length > 0)
            {
                DialogResult result =
                    MessageBox.Show(this, "Warranty Slip Has Errors."
                                    + Environment.NewLine + errorMessage +
                                    Environment.NewLine +
                                    "Still Need the Warranty Slip.", "Cannot Generate",
                                    MessageBoxButtons.YesNoCancel);

                if (result == DialogResult.Yes)
                {
                    result = new Authorize().ShowDialog(this);
                }
                if (result != DialogResult.Yes)
                {
                    return;
                }
            }
            #region PrintExtended
            TempWarrenties.Clear();
            TempWarrenties.Add(Warranties[0]);
            TempWarrenties.Reciept = Warranties[0].Reciept;

            const string ReportPath     = @"LSExtendedWarrenty.WarrentySlip.rdlc";
            const string DataSourceName = @"WarrentyItem";
            String       PrinterName    = SettingsProvider.GetDefaultPrinter();
            try
            {
                Microsoft.Reporting.WinForms.ReportParameter[] ReportParameter =
                    new Microsoft.Reporting.WinForms.ReportParameter[] {
                    new Microsoft.Reporting.WinForms.ReportParameter(@"PrintDateTime", DateTime.Now.ToString()),
                    new Microsoft.Reporting.WinForms.ReportParameter(@"IssueDateTime", TempWarrenties[0].IssuedDate.ToString()),
                    new Microsoft.Reporting.WinForms.ReportParameter(@"CashMemo", TempWarrenties[0].Reciept.RecieptID),
                    new Microsoft.Reporting.WinForms.ReportParameter(@"CashMemoDate", TempWarrenties[0].Reciept.TransactionDate.ToString()),
                    new Microsoft.Reporting.WinForms.ReportParameter(@"CustomerName", TempWarrenties[0].CustomerName),
                    new Microsoft.Reporting.WinForms.ReportParameter(@"CustomerPhone", TempWarrenties[0].Phone),
                    new Microsoft.Reporting.WinForms.ReportParameter(@"CustomerEmail", TempWarrenties[0].Email),
                    new Microsoft.Reporting.WinForms.ReportParameter(@"StaffCode", TempWarrenties[0].Reciept.Staff),
                    new Microsoft.Reporting.WinForms.ReportParameter(@"StaffName", TempWarrenties[0].Reciept.StaffName)
                };


                Microsoft.Reporting.WinForms.ReportDataSource DataSource = new Microsoft.Reporting.WinForms.ReportDataSource
                                                                               (DataSourceName, TempWarrenties);
                using (ReportPriner Printer = new ReportPriner(ReportPath, DataSource, ReportParameter))
                {
                    this.Hide();
                    this.Cursor = Cursors.WaitCursor;
                    FormReciept window = new FormReciept();
                    window.Report          = Printer.LocalReport;
                    window.ReportParameter = ReportParameter;
                    window.DataSource      = DataSource;
                    this.Cursor            = Cursors.Default;
                    window.ShowDialog(this);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Error Processing the Warranty Slip. "
                                + Environment.NewLine
                                + "Please Check the Error Message." + Environment.NewLine
                                + "Please take a screen shot and send to System Administrator" + Environment.NewLine + Environment.NewLine
                                + ex.Message, "Error Occurred");
            }
            #endregion
        }