Example #1
0
        private void sendEMail(rptInfo rpti, string Caption, XtraReport xr, string eMails, string eMailSubject, string eMailBody)
        {
            try
            {
                MainDataSet.SMTPRow SMTP = Program.MF.SMTP();

                MemoryStream mem = new MemoryStream();
                xr.ExportToHtml(mem);

                // Create a new attachment and put the PDF report into it.
                mem.Seek(0, System.IO.SeekOrigin.Begin);
                var aaa = Encoding.UTF8.GetString(mem.ToArray());

                // Create a new message and attach the PDF report to it.
                MailMessage mail = new MailMessage();
                //mail.Attachments.Add(att);

                mail.To.Add(eMails);
                mail.Subject    = string.Format("{0} {1}{2}", eMailSubject, rpti.refTO, rpti.refID);
                mail.Body       = aaa; // eMailBody;
                mail.IsBodyHtml = true;

                mail.From = new MailAddress(SMTP.MAIL_FROM_ADDRESS, SMTP.MAIL_FROM_DISPLAY_NAME);
                SmtpClient smtp = new SmtpClient(SMTP.CLIENT_HOST);
                smtp.Credentials = new System.Net.NetworkCredential(SMTP.CREDENTIALS_USER_NAME, SMTP.CREDENTIALS_USER_PASSWORD);
                smtp.EnableSsl   = SMTP.ENABLE_SSL == "T" ? true : false;
                smtp.Port        = SMTP.PORT;

                smtp.Send(mail);
                mem.Close();    // Close the memory stream.

                Program.MF.reportDone(rpti, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Error sending eMail.\n" + ex.ToString());
            }
        }
Example #2
0
        private void exportSatis(string dil, bool eMail = false)
        {
            int tstID = (int)tstGridView.GetFocusedRowCellValue(colTSTIDt);

            rprTklfTableAdapter.Fill(teklifDataSet.RPR_TKLF, tstID, dil);
            TeklifDataSet.RPR_TKLFRow rprTklfRow = (TeklifDataSet.RPR_TKLFRow)teklifDataSet.RPR_TKLF.Rows[0];
            string tklfTE = "Teklif";

            if (dil == "T")
            {
                colORGf.Caption     = "Çıkış";
                colDSTf.Caption     = "Varış";
                colBRMf.Caption     = "Birim";
                colTRNTIMEf.Caption = "Transit Süre";

                colSKDY.Caption  = "KDV%";
                colSDVZf.Caption = "Para Birim";

                colSFYTf.Caption  = "Fiyat";
                colSFYT1f.Caption = "Min";
                colSFYT2f.Caption = "-45";
                colSFYT3f.Caption = "+45";
                colSFYT4f.Caption = "+100";
                colSFYT5f.Caption = "+250";
                colSFYT6f.Caption = "+300";
                colSFYT7f.Caption = "+500";
                colSFYT8f.Caption = "+1000";

                colSFYTE.Caption  = "Fiyat";
                colSFYT1E.Caption = "Min";
                colSFYT2E.Caption = "-45";
                colSFYT3E.Caption = "+45";
                colSFYT4E.Caption = "+100";
                colSFYT5E.Caption = "+250";
                colSFYT6E.Caption = "+300";
                colSFYT7E.Caption = "+500";
                colSFYT8E.Caption = "+1000";
            }
            else
            {
                tklfTE              = "Tender";
                colORGf.Caption     = "Origin";
                colDSTf.Caption     = "Destination";
                colBRMf.Caption     = "Unit";
                colTRNTIMEf.Caption = "Transit Time";

                colSKDY.Caption  = "%VAT";
                colSDVZf.Caption = "Currency";

                colSFYTf.Caption  = "Rate";
                colSFYT1f.Caption = "Min";
                colSFYT2f.Caption = "-45";
                colSFYT3f.Caption = "+45";
                colSFYT4f.Caption = "+100";
                colSFYT5f.Caption = "+250";
                colSFYT6f.Caption = "+300";
                colSFYT7f.Caption = "+500";
                colSFYT8f.Caption = "+1000";

                colSFYTE.Caption  = "Rate";
                colSFYT1E.Caption = "Min";
                colSFYT2E.Caption = "-45";
                colSFYT3E.Caption = "+45";
                colSFYT4E.Caption = "+100";
                colSFYT5E.Caption = "+250";
                colSFYT6E.Caption = "+300";
                colSFYT7E.Caption = "+500";
                colSFYT8E.Caption = "+1000";
            }

            if (colG9.GroupIndex == 0)
            {
                tsfGridView.CollapseAllGroups();
                //tsfGridView.OptionsView.ShowFooter = true;
                tsfGridView.OptionsPrint.ExpandAllGroups = false;
                tsfGridView.OptionsPrint.PrintFooter     = true;
                //tsfGridView.OptionsPrint.AutoWidth = false;
                tsfGridView.OptionsPrint.AutoWidth = true;
            }
            else
            {
                tsfGridView.ExpandAllGroups();
                //tsfGridView.OptionsView.ShowFooter = false;
                tsfGridView.OptionsPrint.ExpandAllGroups = true;
                tsfGridView.OptionsPrint.PrintFooter     = false;
                //tsfGridView.OptionsPrint.AutoWidth = false;
                tsfGridView.OptionsPrint.AutoWidth = true;
                //tsfGridView.BestFitColumns();
            }

            RichEditDocumentServer richServer = new RichEditDocumentServer();

            richServer.RtfText = rprTklfRow.ALTNOT;
            //richServer.Document.AppendText(" SENER");
            if (!rprTklfRow.IsDTYNOTNull())
            {
                if (string.IsNullOrEmpty(richServer.Text))
                {
                    richServer.RtfText = rprTklfRow.DTYNOT;
                }
                else
                {
                    richServer.Document.AppendRtfText(rprTklfRow.DTYNOT);
                }
            }

            tsfGridView.OptionsPrint.RtfReportFooter = richServer.RtfText;
            tsfGridView.OptionsPrint.RtfPageFooter   = rprTklfRow.FOOTER;


            PrintingSystem         ps   = new PrintingSystem();
            PrintableComponentLink link = new PrintableComponentLink(ps);

            link.Component = tsfGridControl;

            link.PaperKind      = System.Drawing.Printing.PaperKind.A4;
            link.Landscape      = false;
            link.Margins.Left   = 10;
            link.Margins.Right  = 10;
            link.Margins.Top    = 10;
            link.Margins.Bottom = 10;

//            tsfGridView.OptionsPrint.RtfPageHeader =
            tsfGridView.OptionsPrint.RtfReportHeader =
                rprTklfRow.USTNOT
                .Replace("@TSTID@", rprTklfRow.TSTID.ToString())
                .Replace("@FIRMA@", rprTklfRow.FIRMA)
                .Replace("@TLPTRH@", rprTklfRow.TLPTRHS)
                .Replace("@TKLTRH@", rprTklfRow.TKLTRHS)
                .Replace("@GCRTRH@", rprTklfRow.GCRTRHS)
                .Replace("@ROT@", rprTklfRow.ROT)
                .Replace("@MOT@", rprTklfRow.MOT)
                .Replace("@PTM@", rprTklfRow.PTM)
                .Replace("@DTM@", rprTklfRow.DTM)

                .Replace("@HORGS@", rprTklfRow.HORGS)
                .Replace("@HDSTS@", rprTklfRow.HDSTS)
                .Replace("@MORGS@", rprTklfRow.MORGS)
                .Replace("@MDSTS@", rprTklfRow.MDSTS)

                .Replace("@MALCINSI@", rprTklfRow["MALCINSI"].ToString())
                .Replace("@INFO@", rprTklfRow.INFO);

            link.CreateDocument();

            if (eMail)
            {
                if (string.IsNullOrWhiteSpace(rprTklfRow.EMAILS))
                {
                    XtraMessageBox.Show("eMail adresi bulunamadı", "eMail Teklif", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }

                Cursor = Cursors.WaitCursor;
                try
                {
                    MainDataSet.SMTPRow SMTP = Program.MF.SMTP();
                    MailMessage         mail = new MailMessage();

                    // Create a new memory stream and export the report into it as PDF.
                    MemoryStream ms = new MemoryStream();
                    link.ExportToPdf(ms);

                    // Create a new attachment and put the PDF report into it.
                    ms.Seek(0, System.IO.SeekOrigin.Begin);
                    Attachment att = new Attachment(ms, string.Format("{0}-{1}.pdf", tklfTE, tstID), "application/pdf");
                    mail.Attachments.Add(att);

                    mail.To.Add(rprTklfRow.EMAILS);

                    mail.Subject    = rprTklfRow.EMAILSUBJECT;
                    mail.Body       = rprTklfRow.EMAILBODY;
                    mail.IsBodyHtml = true;

                    mail.From = new MailAddress(SMTP.MAIL_FROM_ADDRESS, SMTP.MAIL_FROM_DISPLAY_NAME);
                    SmtpClient smtp = new SmtpClient(SMTP.CLIENT_HOST);
                    smtp.Credentials = new System.Net.NetworkCredential(SMTP.CREDENTIALS_USER_NAME, SMTP.CREDENTIALS_USER_PASSWORD);
                    smtp.EnableSsl   = SMTP.ENABLE_SSL == "T" ? true : false;
                    smtp.Port        = SMTP.PORT;

                    smtp.Send(mail);

                    int    len = (int)ms.Length;
                    byte[] img = new byte[len];
                    ms.Read(img, 0, len);
                    //teklifQueriesTableAdapter.DOC_INS2("TST", tstID, "Teklif", ".pdf", "TKLF", Program.USR, len, img);
                    teklifQueriesTableAdapter.DOC_INS2("TST", tstID, string.Format("Teklif {0}", tstGridView.GetFocusedRowCellValue(colRVSNOt)), ".pdf", "TKLF", Program.USR, len, img);

                    // Close the memory stream.
                    ms.Close();
                    ms.Flush();

                    rptInfo rpti = new rptInfo();
                    rpti.put("TKLF", "TST", tstID, Program.USR, "F", "eMail Teklif");
                    Program.MF.reportDone(rpti, false);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "Error sending eMail.\n" + ex.ToString());
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
            }
            else
            {
                link.ShowPreviewDialog();

                if (XtraMessageBox.Show("İşlem tamamlandı mı?", "Print", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    MemoryStream ms = new MemoryStream();
                    link.ExportToPdf(ms);
                    ms.Seek(0, System.IO.SeekOrigin.Begin);
                    int    len = (int)ms.Length;
                    byte[] img = new byte[len];
                    ms.Read(img, 0, len);
                    ms.Close();

                    teklifQueriesTableAdapter.DOC_INS2("TST", tstID, string.Format("Teklif {0}", tstGridView.GetFocusedRowCellValue(colRVSNOt)), ".pdf", "TKLF", Program.USR, len, img);
                    rptInfo rpti = new rptInfo();
                    rpti.put("TKLF", "TST", tstID, Program.USR, "F", "eMail Teklif");
                    Program.MF.reportDone(rpti, false);
                }
            }
        }