Exemplo n.º 1
0
        public static void LogException(string errMessage, System.Exception e, HttpContext context)
        {
            // ignore logging warnings
            if (CException.FindWarning(e) != null)
            {
                return;
            }

            string errMsg = null;

            if (errMessage != null)
            {
                errMsg = "Error Msg: " + errMessage + System.Environment.NewLine +
                         CException.GetErrorMessages(e) +
                         System.Environment.NewLine +
                         "Stack Trace: " + e.StackTrace;
            }
            else
            {
                errMsg = "Error Msg: " + " Null " + System.Environment.NewLine +
                         CException.GetErrorMessages(e) +
                         System.Environment.NewLine +
                         "Stack Trace: " + e.StackTrace;
            }

            LogException(errMsg, context);
        }
Exemplo n.º 2
0
        public static void ShowWarning(System.Web.UI.WebControls.Label lbl, System.Exception ex)
        {
            // Show the original warning exception
            Exception warn = CException.FindWarning(ex);

            if (warn != null)
            {
                //div.InnerHtml = "";
                ShowWarning(lbl, warn.Message);
                return;
            }
            else
            {
                string msg = "";
                while (ex != null)
                {
                    msg += "Source: " + ex.Source + LF + "Description: " + ex.Message + LF + LF;
                    ex   = ex.InnerException;
                }

                lbl.Attributes.Add("class", "WarningOn");
                if (lbl.Text.Length > 0)
                {
                    lbl.Text += "  " + msg;
                }
                else
                {
                    lbl.Text += msg;
                }
            }
        }
Exemplo n.º 3
0
        public static void ShowWarning(HtmlGenericControl div, System.Exception ex)
        {
            // Show the original warning exception
            Exception warn = CException.FindWarning(ex);

            if (warn != null)
            {
                // Given a warning, only show the first true warning.
                if (div.InnerHtml.Length == 0)
                {
                    ShowWarning(div, warn.Message);
                }
                return;
            }
            else
            {
                string msg = "";
                while (ex != null)
                {
                    msg += "Source: " + ex.Source + LF + "Description: " + ex.Message + LF + LF;
                    ex   = ex.InnerException;
                }

                div.Attributes.Add("class", "WarningOn");
                if (div.InnerHtml.Length > 0)
                {
                    div.InnerHtml += "  " + msg;
                }
                else
                {
                    div.InnerHtml += msg;
                }
            }
        }
Exemplo n.º 4
0
        public static void SendEmail(string smtpServer, string smtpPort,
                                     string emailMessage, string userName, string password,
                                     string toAddress, string fromAddress, string ccAddress, string subject, bool isBodyHtml)
        {
            try {
                // Matched shid and email to a user.  Send them their password
                MailMessage mail = new MailMessage();

                mail.From = new MailAddress(fromAddress);
                foreach (string recip in toAddress.Split(new char[] { ';' }))
                {
                    mail.To.Add(new MailAddress(recip));
                }
                if (!String.IsNullOrEmpty(ccAddress))
                {
                    foreach (string recip in ccAddress.Split(new char[] { ';' }))
                    {
                        mail.CC.Add(new MailAddress(recip));
                    }
                }

                mail.Subject    = subject;
                mail.Body       = emailMessage;
                mail.IsBodyHtml = isBodyHtml;

                SmtpClient smtp = new SmtpClient(smtpServer, int.Parse(smtpPort));
                if (!String.IsNullOrEmpty(userName))
                {
                    if (userName == "INTEGRATED" && String.IsNullOrEmpty(password))
                    {
                        // INTEGRATED Authentication
                        smtp.UseDefaultCredentials = true;
                    }
                    else
                    {
                        // Basic Authentication
                        smtp.UseDefaultCredentials = false;
                        smtp.Credentials           = new System.Net.NetworkCredential(userName, password);
                    }
                }

                smtp.Send(mail);
            }
            catch (Exception MailEx) {
                string errMsg = "Error in SendEmail" + LF +
                                "To Address: " + toAddress + LF +
                                "Subject: " + subject;
                CException wscEx = new CException(errMsg, MailEx);
                throw (wscEx);
            }
        }
Exemplo n.º 5
0
        public static string ReportPackager(int cropYear, DateTime fromDate, DateTime toDate, string factoryList, string stationList,
                                            string contractList, bool isPosted, bool isPreview, bool isHardCopy, bool isEmail, bool isFax, string fileName, string logoUrl, string pdfTempfolder)
        {
            const string  METHOD_NAME = "ReportPackager: ";
            DirectoryInfo pdfDir      = null;

            FileInfo[] pdfFiles = null;
            string     filePath = "";

            try {
                pdfDir = new DirectoryInfo(pdfTempfolder);

                // Build the output file name by getting a list of all PDF files
                // that begin with this session ID: use this as a name incrementer.
                pdfFiles  = pdfDir.GetFiles(fileName + "*.pdf");
                fileName += "_" + Convert.ToString(pdfFiles.Length + 1) + ".pdf";

                filePath = pdfDir.FullName + @"\" + fileName;

                try {
                    List <ListGrowerTareItem> hdrList = WSCReportsExec.GrowerDetailReportMasterHdr(cropYear, fromDate, toDate, factoryList,
                                                                                                   stationList, contractList, isPosted, isHardCopy, isEmail, isFax);

                    if (hdrList.Count == 0)
                    {
                        CWarning warn = new CWarning("No results matched your search criteria.");
                        throw (warn);
                    }


                    using (FileStream fsHardCopy = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read)) {
                        ReportBuilder(hdrList, cropYear, isPosted, isPreview, isHardCopy, isEmail, isFax, fsHardCopy, filePath);
                    }
                }
                catch (System.Exception ex) {
                    string errMsg = "cropYear: " + cropYear.ToString();

                    WSCIEMP.Common.CException wscEx = new WSCIEMP.Common.CException(MOD_NAME + "." + METHOD_NAME + ": " + errMsg, ex);
                    throw (wscEx);
                }

                return(filePath);
            }
            catch (System.Exception ex) {
                string errMsg = "cropYear: " + cropYear.ToString();

                WSCIEMP.Common.CException wscEx = new WSCIEMP.Common.CException(MOD_NAME + "." + METHOD_NAME + ": " + errMsg, ex);
                throw (wscEx);
            }
        }
Exemplo n.º 6
0
        public static void ShowWarning(System.Web.UI.WebControls.Label lbl, string warnMsg, System.Exception ex)
        {
            // Show the original warning exception
            Exception warn = CException.FindWarning(ex);

            if (warn != null)
            {
                ShowWarning(lbl, warn.Message);
            }
            else
            {
                // Otherwise, show default
                ShowWarning(lbl, warnMsg);
            }
        }
Exemplo n.º 7
0
        protected void btnFind_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = "btnFind_Click";

            try {
                FindSHID(txtSHID.Text);

                if (ShidChange != null)
                {
                    ShidChange(this, new CommandEventArgs(txtSHID.Text, MemberID.ToString()));
                }
            }
            catch (System.Exception ex) {
                Common.CException wex = new Common.CException(MOD_NAME + METHOD_NAME, ex);
                ShowWarning(ex);
            }
        }
Exemplo n.º 8
0
        public static void ShowWarning(HtmlGenericControl div, string warnMsg, System.Exception ex)
        {
            // Show the original warning exception
            Exception warn = CException.FindWarning(ex);

            if (warn != null)
            {
                // Given a warning, only show the first true warning.
                if (div.InnerHtml.Length == 0)
                {
                    ShowWarning(div, warn.Message);
                }
            }
            else
            {
                // Otherwise, show default
                ShowWarning(div, warnMsg);
            }
        }
Exemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            const string METHOD_NAME = "Page_Load";

            try {
                //_shs = Globals.ShsData;

                HtmlGenericControl script = new HtmlGenericControl("script");
                script.Attributes.Add("type", "text/javascript");
                script.Attributes.Add("src", Page.ResolveUrl("~/Script/Common.js"));
                Page.Header.Controls.Add(script);

                // ** ** **  Add JQuery.js to page Head tag  ** ** **
                //script = new HtmlGenericControl("script");
                //script.Attributes.Add("type", "text/javascript");
                //script.Attributes.Add("src", Page.ResolveUrl("~/Script/JQuery.js"));
                //Page.Header.Controls.Add(script);

                // ** ** **  Add MyJQuery.js extensions to page Head tag  ** ** **
                script = new HtmlGenericControl("script");
                script.Attributes.Add("type", "text/javascript");
                script.Attributes.Add("src", Page.ResolveUrl("~/Script/MyJQuery.js"));
                Page.Header.Controls.Add(script);

                // ** ** **  Add JQueryUI.css (custom version) to page Head tag  ** ** **
                //HtmlLink linkBlock = new HtmlLink();
                //linkBlock.Href = Page.ResolveUrl("~/Script/JQueryUI/css/blitzer/jquery-ui.css");
                //linkBlock.Attributes.Add("rel", "stylesheet");
                //linkBlock.Attributes.Add("type", "text/css");
                //Page.Header.Controls.Add(linkBlock);

                // ** ** **  Add JQueryUI.js to page Head tag  ** ** **
                //script = new HtmlGenericControl("script");
                //script.Attributes.Add("type", "text/javascript");
                //script.Attributes.Add("src", Page.ResolveUrl("~/Script/JQueryUI/js/jquery-ui.js"));
                //Page.Header.Controls.Add(script);

                lblDateStamp.Text = DateTime.Now.ToString("MMMM dd, yyyy");
                litYear.Text      = DateTime.Now.Year.ToString();

                ddlReports.Attributes.Add("onchange", "PopReport(this)");

                if (!Page.IsPostBack)
                {
                    if (ddlCropYear.Items.Count == 0)
                    {
                        string cy = WSCField.GetCropYears()[0].ToString();
                        WSCField.FillCropYear(ddlCropYear, cy);
                        CropYear = cy;
                    }

                    ResetMemberInfo(SHID.ToString());
                    ShowMemberInfo();
                }
                else
                {
                    string newShid = txtSHID.Text;
                    if (!Common.CodeLib.IsValidSHID(newShid))
                    {
                        newShid = "";
                    }

                    string newCropYear = Common.UILib.GetDropDownText(ddlCropYear);

                    if (newShid != SHID.ToString() || newCropYear != CropYear.ToString())
                    {
                        CropYear = newCropYear;
                        FindSHID(newShid);
                    }
                }
            }
            catch (System.Exception ex) {
                Common.CException wex = new Common.CException(MOD_NAME + METHOD_NAME, ex);
                ShowWarning(ex);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            const string METHOD_NAME = "Page_Load";

            try {

                //_shs = Globals.ShsData;

                HtmlGenericControl script = new HtmlGenericControl("script");
                script.Attributes.Add("type", "text/javascript");
                script.Attributes.Add("src", Page.ResolveUrl("~/Script/Common.js"));
                Page.Header.Controls.Add(script);

                // ** ** **  Add JQuery.js to page Head tag  ** ** **
                //script = new HtmlGenericControl("script");
                //script.Attributes.Add("type", "text/javascript");
                //script.Attributes.Add("src", Page.ResolveUrl("~/Script/JQuery.js"));
                //Page.Header.Controls.Add(script);

                // ** ** **  Add MyJQuery.js extensions to page Head tag  ** ** **
                script = new HtmlGenericControl("script");
                script.Attributes.Add("type", "text/javascript");
                script.Attributes.Add("src", Page.ResolveUrl("~/Script/MyJQuery.js"));
                Page.Header.Controls.Add(script);

                // ** ** **  Add JQueryUI.css (custom version) to page Head tag  ** ** **
                //HtmlLink linkBlock = new HtmlLink();
                //linkBlock.Href = Page.ResolveUrl("~/Script/JQueryUI/css/blitzer/jquery-ui.css");
                //linkBlock.Attributes.Add("rel", "stylesheet");
                //linkBlock.Attributes.Add("type", "text/css");
                //Page.Header.Controls.Add(linkBlock);

                // ** ** **  Add JQueryUI.js to page Head tag  ** ** **
                //script = new HtmlGenericControl("script");
                //script.Attributes.Add("type", "text/javascript");
                //script.Attributes.Add("src", Page.ResolveUrl("~/Script/JQueryUI/js/jquery-ui.js"));
                //Page.Header.Controls.Add(script);

                lblDateStamp.Text = DateTime.Now.ToString("MMMM dd, yyyy");
                litYear.Text = DateTime.Now.Year.ToString();

                ddlReports.Attributes.Add("onchange", "PopReport(this)");

                if (!Page.IsPostBack) {

                    if (ddlCropYear.Items.Count == 0) {

                        string cy = WSCField.GetCropYears()[0].ToString();
                        WSCField.FillCropYear(ddlCropYear, cy);
                        CropYear = cy;
                    }

                    ResetMemberInfo(SHID.ToString());
                    ShowMemberInfo();

                } else {

                    string newShid = txtSHID.Text;
                    if (!Common.CodeLib.IsValidSHID(newShid)) {
                        newShid = "";
                    }

                    string newCropYear = Common.UILib.GetDropDownText(ddlCropYear);

                    if (newShid != SHID.ToString() || newCropYear != CropYear.ToString()) {
                        CropYear = newCropYear;
                        FindSHID(newShid);
                    }
                }
            }
            catch (System.Exception ex) {
                Common.CException wex = new Common.CException(MOD_NAME + METHOD_NAME, ex);
                ShowWarning(ex);
            }
        }
        protected void btnFind_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = "btnFind_Click";

            try {

                FindSHID(txtSHID.Text);

                if (ShidChange != null) {
                    ShidChange(this, new CommandEventArgs(txtSHID.Text, MemberID.ToString()));
                }
            }
            catch (System.Exception ex) {
                Common.CException wex = new Common.CException(MOD_NAME + METHOD_NAME, ex);
                ShowWarning(ex);
            }
        }
        public static void ReportBuilder(List<ListGrowerTareItem> hdrList, int cropYear, bool isPosted, bool isPreview, bool isHardCopy, bool isEmail,
			bool isFax, FileStream fs, string filePath)
        {
            const string METHOD_NAME = "ReportBuilder";
            const int RESET_FLAG = 0;

            Document document = null;
            PdfWriter writer = null;
            DailyGrowerTareDetailEvent pgEvent = null;
            List<ListGrowerTareItem> emailFaxList = null;
            List<ListGrowerTareItem> hardCopyList = null;

            int lastContractID = 0, lastStationID = 0;
            int index = 0;
            string firstDeliveryDate = "", busName = "", address1 = "", address2 = "", CSZ = "", emailAddress = "", faxNumber = "";

            string rptTitle = "Western Sugar Cooperative\nDaily Grower Tare Detail Report";

            try {

                if (!isPreview) {
                    emailFaxList = hdrList.FindAll(item => item.RptType == "E" || item.RptType == "F");
                    hardCopyList = hdrList.FindAll(item => item.RptType == "M");
                }
                else {
                    // In preview mode we're going to lump these all together and print them.
                    hardCopyList = hdrList;
                }

                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BeetConn"].ToString())) {

                    if (emailFaxList != null && emailFaxList.Count > 0) {
                        GrowerTareReportEmailFax(conn, filePath, ref emailFaxList, rptTitle, cropYear);
                    }

                    for (index = 0; index < hardCopyList.Count; index++) {

                        ListGrowerTareItem hdrItem = hardCopyList[index];

                        //----------------------------------------------------------------
                        // Changed contract or station, start a new print out.
                        //----------------------------------------------------------------
                        if (hdrItem.ContractID != lastContractID || hdrItem.Delivery_Station_ID != lastStationID) {

                            if (document == null) {

                                GetAddressInfo(conn, hdrItem.ContractID, out busName, out address1, out address2, out CSZ,
                                               out emailAddress, out faxNumber);

                                // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                                //  ***  US LETTER: 612 X 792  ***
                                document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                        PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin,
                                                        PortraitPageSize.PgBottomMargin);

                                // we create a writer that listens to the document
                                // and directs a PDF-stream to a file
                                writer = PdfWriter.GetInstance(document, fs);

                                // Attach my override event handler(s)
                                pgEvent = new DailyGrowerTareDetailEvent();
                                pgEvent.FillEvent(hdrItem.Contract_No, busName, hdrItem.Delivery_Factory_No, address1, address2, CSZ,
                                                  RESET_FLAG, rptTitle + (!isPreview ? "" : " - " + hdrItem.RptType));
                                writer.PageEvent = pgEvent;

                                // Open the document
                                document.Open();
                            }

                            if (lastContractID != 0) {

                                //--------------------------------------------------------------------------
                                // Display Truck information for the first delivery day.
                                //--------------------------------------------------------------------------
                                int loadCount = 0;
                                //if (nextDeliveryDate == firstDeliveryDate) {

                                try {
                                    // Get the truck data.
                                    SqlParameter[] spParams = null;
                                    using (
                                        SqlDataReader drTrucks = WSCReportsExec.GrowerDetailReportASH(conn,
                                        lastContractID, lastStationID, firstDeliveryDate, ref spParams)) {

                                        rptDailyGrowerTareDetail.AddTruckDetail(ref document, drTrucks, pgEvent);
                                        drTrucks.Close();

                                        loadCount = Convert.ToInt32(spParams[3].Value);

                                        if (loadCount > 0) {

                                            rptDailyGrowerTareDetail.AddTruckTotals(ref document, loadCount.ToString(),
                                                Convert.ToInt32(spParams[4].Value).ToString("#,##0"),
                                                Convert.ToInt32(spParams[5].Value).ToString("#,##0"), pgEvent);
                                        }
                                    }
                                }
                                catch {
                                    hardCopyList[index-1].Success += "Fail: Truck Detail ";
                                }
                                GetAddressInfo(conn, hdrItem.ContractID, out busName, out address1, out address2, out CSZ,
                                               out emailAddress, out faxNumber);

                                // New Page !: in Preview mode, append the report type to the title of the report.
                                pgEvent.FillEvent(hdrItem.Contract_No, busName, hdrItem.Delivery_Factory_No, address1, address2, CSZ,
                                                  RESET_FLAG, rptTitle + (!isPreview ? "" : " - " + hdrItem.RptType));
                                document.NewPage();

                            }

                            firstDeliveryDate = hdrItem.Delivery_Date;
                            lastStationID = hdrItem.Delivery_Station_ID;
                            lastContractID = hdrItem.ContractID;
                        }

                        try {
                            AddSampleHdr(ref document, hdrItem, cropYear, pgEvent);

                            using (
                                SqlDataReader drSamples = WSCReportsExec.GrowerDetailReportTares(conn, hdrItem.ContractID, hdrItem.Delivery_Date)) {
                                rptDailyGrowerTareDetail.AddSampleDetail(ref document, drSamples, pgEvent);
                            }
                        }
                        catch {
                            hardCopyList[index].Success += "Fail: Sample Detail ";
                        }
                    }

                    if (lastContractID != 0) {

                        //--------------------------------------------------------------------------
                        // Display Truck information for the first delivery day.
                        //--------------------------------------------------------------------------
                        int loadCount = 0;

                        try {
                            // Get the truck data.
                            SqlParameter[] spParams = null;
                            using (SqlDataReader drTrucks = WSCReportsExec.GrowerDetailReportASH(conn,
                                lastContractID, lastStationID, firstDeliveryDate, ref spParams)) {

                                rptDailyGrowerTareDetail.AddTruckDetail(ref document, drTrucks, pgEvent);
                                drTrucks.Close();

                                loadCount = Convert.ToInt32(spParams[3].Value);

                                if (loadCount > 0) {

                                    rptDailyGrowerTareDetail.AddTruckTotals(ref document, loadCount.ToString(),
                                        Convert.ToInt32(spParams[4].Value).ToString("#,##0"), Convert.ToInt32(spParams[5].Value).ToString("#,##0"),
                                        pgEvent);
                                }
                            }
                        }
                        catch {
                            hardCopyList[index-1].Success += "Fail: Truck Detail ";
                        }
                    }
                }

                //------------------------------------
                // Print a Process Summary
                //------------------------------------
                if (document != null && writer != null) {

                    pgEvent.IsSummary = true;
                    document.NewPage();

                    PdfPTable procSumTab = null;
                    PrintSummary(document, ref procSumTab, hdrList, isPreview);
                    PdfReports.AddTableNoSplit(document, pgEvent, procSumTab);

                } else {

                    document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                            PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin,
                                            PortraitPageSize.PgBottomMargin);

                    // we create a writer that listens to the document
                    // and directs a PDF-stream to a file
                    writer = PdfWriter.GetInstance(document, fs);

                    // Attach my override event handler(s)
                    pgEvent = new DailyGrowerTareDetailEvent();
                    pgEvent.IsSummary = true;
                    writer.PageEvent = pgEvent;

                    // Open the document
                    document.Open();

                    PdfPTable procSumTab = null;
                    PrintSummary(document, ref procSumTab, hdrList, isPreview);
                    PdfReports.AddTableNoSplit(document, pgEvent, procSumTab);
                }

            // ======================================================
                // Close document
                // ======================================================
                if (document != null) {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                    "writer is null: " + (writer == null).ToString();
                CException wscex = new CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {

                if (document != null) {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null) {
                    writer.Close();
                }
            }
        }
        private static void GrowerTareReportEmailFax(SqlConnection conn, string filePath, ref List<ListGrowerTareItem> emailList, string rptTitle, int cropYear )
        {
            const string METHOD_NAME = "GrowerTareReportEmailFax";
            const string SEND_RPT_SUBJECT = "WESTERN SUGAR COOPERATIVE - Daily Grower Tare Detail Report";
            const int RESET_FLAG = 0;

            FileStream fs = null;
            Document document = null;
            PdfWriter writer = null;
            DailyGrowerTareDetailEvent pgEvent = null;

            int lastContractID = 0, lastStationID = 0;
            int index = 0;
            string destinationFile = "", lastRptType = "";
            string firstDeliveryDate = "", busName = "", address1 = "", address2 = "", CSZ = "", emailAddress = "", faxNumber = "";

            try {

                for (index = 0; index < emailList.Count; index++) {

                    ListGrowerTareItem hdrItem = emailList[index];

                    //----------------------------------------------------------------
                    // Changed contract or station, start a new print out.
                    //----------------------------------------------------------------
                    if (hdrItem.ContractID != lastContractID || hdrItem.Delivery_Station_ID != lastStationID) {

                        if (document == null) {

                            GetAddressInfo(conn, hdrItem.ContractID, out busName, out address1, out address2, out CSZ,
                                            out emailAddress, out faxNumber);

                            // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                            //  ***  US LETTER: 612 X 792  ***
                            document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                    PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin,
                                                    PortraitPageSize.PgBottomMargin);

                            destinationFile = filePath.Substring(0, filePath.Length - 4) + "_" + hdrItem.Delivery_Station_No + "_" + hdrItem.Contract_No.ToString() + ".pdf";

                            // we create a writer that listens to the document
                            // and directs a PDF-stream to a file
                            if (File.Exists(destinationFile)) {
                                File.Delete(destinationFile);
                            }
                            fs = new FileStream(destinationFile, FileMode.Create, FileAccess.Write, FileShare.Read);
                            writer = PdfWriter.GetInstance(document, fs);

                            // Attach my override event handler(s)
                            pgEvent = new DailyGrowerTareDetailEvent();
                            pgEvent.FillEvent(hdrItem.Contract_No, busName, hdrItem.Delivery_Factory_No, address1, address2, CSZ,
                                                RESET_FLAG, rptTitle);
                            writer.PageEvent = pgEvent;

                            // Open the document
                            document.Open();
                        }

                        if (lastContractID != 0) {

                            //--------------------------------------------------------------------------
                            // Display Truck information for the first delivery day.
                            //--------------------------------------------------------------------------
                            int loadCount = 0;

                            try {
                                // Get the truck data.
                                SqlParameter[] spParams = null;
                                using (
                                    SqlDataReader drTrucks = WSCReportsExec.GrowerDetailReportASH(conn,
                                        lastContractID, lastStationID, firstDeliveryDate, ref spParams)) {

                                    rptDailyGrowerTareDetail.AddTruckDetail(ref document, drTrucks, pgEvent);
                                    drTrucks.Close();

                                    loadCount = Convert.ToInt32(spParams[3].Value);

                                    if (loadCount > 0) {

                                        rptDailyGrowerTareDetail.AddTruckTotals(ref document, loadCount.ToString(),
                                            Convert.ToInt32(spParams[4].Value).ToString("#,##0"),
                                            Convert.ToInt32(spParams[5].Value).ToString("#,##0"), pgEvent);
                                    }
                                }
                            }
                            catch {
                                emailList[index - 1].Success += "Fail: Truck Detail ";
                            }

                            // Save File & Send File
                            // ======================================================
                            // Close document and write effectively saves the file
                            // ======================================================
                            if (document != null) {
                                if (pgEvent != null) {
                                    pgEvent.IsDocumentClosing = true;
                                }
                                document.Close();
                                document = null;
                            }
                            if (writer != null) {
                                writer.Close();
                                writer = null;
                            }
                            fs.Close();
                            fs = null;

                            // Send Report File
                            if (lastRptType == "E") {

                                if (!SendEmailReport(SEND_RPT_SUBJECT,
                                    ConfigurationManager.AppSettings["email.target.employeeServiceFrom"].ToString(), emailAddress, destinationFile)) {

                                    emailList[index - 1].Success += "Fail: Email ";
                                }
                            } else {

                                // Send FAX
                                if (!SendFaxReport(SEND_RPT_SUBJECT,
                                    ConfigurationManager.AppSettings["email.target.employeeServiceFrom"].ToString(),
                                    "", faxNumber, busName, "", busName, destinationFile)) {

                                    emailList[index - 1].Success += "Fail: Fax ";
                                }

                            }

                            GetAddressInfo(conn, hdrItem.ContractID, out busName, out address1, out address2, out CSZ,
                                            out emailAddress, out faxNumber);

                            // New document needed.
                            document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                    PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin,
                                                    PortraitPageSize.PgBottomMargin);

                            destinationFile = filePath.Substring(0, filePath.Length - 4) + "_" + hdrItem.Delivery_Station_No + "_" + hdrItem.Contract_No.ToString() + ".pdf";

                            // we create a writer that listens to the document
                            // and directs a PDF-stream to a file
                            if (File.Exists(destinationFile)) {
                                File.Delete(destinationFile);
                            }
                            fs = new FileStream(destinationFile, FileMode.Create, FileAccess.Write, FileShare.Read);
                            writer = PdfWriter.GetInstance(document, fs);

                            // Attach my override event handler(s)
                            pgEvent = new DailyGrowerTareDetailEvent();
                            pgEvent.FillEvent(hdrItem.Contract_No, busName, hdrItem.Delivery_Factory_No, address1, address2, CSZ,
                                                RESET_FLAG, rptTitle);
                            writer.PageEvent = pgEvent;

                            // Open the document
                            document.Open();

                        }

                        firstDeliveryDate = hdrItem.Delivery_Date;
                        lastStationID = hdrItem.Delivery_Station_ID;
                        lastContractID = hdrItem.ContractID;
                        lastRptType = hdrItem.RptType;
                    }

                    try {
                        AddSampleHdr(ref document, hdrItem, cropYear, pgEvent);

                        using (
                            SqlDataReader drSamples = WSCReportsExec.GrowerDetailReportTares(conn, hdrItem.ContractID, hdrItem.Delivery_Date)) {
                            rptDailyGrowerTareDetail.AddSampleDetail(ref document, drSamples, pgEvent);
                        }
                    }
                    catch {
                        emailList[index].Success += "Fail: Sample Detail ";
                    }
                }

                if (lastContractID != 0) {

                    //--------------------------------------------------------------------------
                    // Display Truck information for the first delivery day.
                    //--------------------------------------------------------------------------
                    int loadCount = 0;

                    try {
                        // Get the truck data.
                        SqlParameter[] spParams = null;
                        using (SqlDataReader drTrucks = WSCReportsExec.GrowerDetailReportASH(conn,
                            lastContractID, lastStationID, firstDeliveryDate, ref spParams)) {

                            rptDailyGrowerTareDetail.AddTruckDetail(ref document, drTrucks, pgEvent);
                            drTrucks.Close();

                            loadCount = Convert.ToInt32(spParams[3].Value);

                            if (loadCount > 0) {

                                rptDailyGrowerTareDetail.AddTruckTotals(ref document, loadCount.ToString(),
                                    Convert.ToInt32(spParams[4].Value).ToString("#,##0"), Convert.ToInt32(spParams[5].Value).ToString("#,##0"),
                                    pgEvent);
                            }
                        }
                    }
                    catch {
                        emailList[index - 1].Success += "Fail: Truck Detail ";
                    }
                }

                // Save File & Send File
                // ======================================================
                // Close document and write effectively saves the file
                // ======================================================
                if (document != null) {
                    if (pgEvent != null) {
                        pgEvent.IsDocumentClosing = true;
                    }
                    document.Close();
                    document = null;
                }
                if (writer != null) {
                    writer.Close();
                    writer = null;
                }
                fs.Close();
                fs = null;

                // Send Report File
                if (lastRptType == "E") {

                    if (!SendEmailReport(SEND_RPT_SUBJECT,
                        ConfigurationManager.AppSettings["email.target.employeeServiceFrom"].ToString(), emailAddress, destinationFile)) {

                        emailList[index - 1].Success += "Fail: Email ";
                    }
                } else {

                    // Send FAX
                    if (!SendFaxReport(SEND_RPT_SUBJECT,
                        ConfigurationManager.AppSettings["email.target.employeeServiceFrom"].ToString(),
                        "", faxNumber, busName, "", busName, destinationFile)) {

                        emailList[index - 1].Success += "Fail: FAx ";
                    }

                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                    "writer is null: " + (writer == null).ToString();
                CException wscex = new CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {

                if (document != null) {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null) {
                    writer.Close();
                }
            }
        }
        public static string ReportPackager(int cropYear, DateTime fromDate, DateTime toDate, string factoryList, string stationList,
			string contractList, bool isPosted, bool isPreview, bool isHardCopy, bool isEmail, bool isFax, string fileName, string logoUrl, string pdfTempfolder)
        {
            const string METHOD_NAME = "ReportPackager: ";
            DirectoryInfo pdfDir = null;
            FileInfo[] pdfFiles = null;
            string filePath = "";

            try {

                pdfDir = new DirectoryInfo(pdfTempfolder);

                // Build the output file name by getting a list of all PDF files
                // that begin with this session ID: use this as a name incrementer.
                pdfFiles = pdfDir.GetFiles(fileName + "*.pdf");
                fileName += "_" + Convert.ToString(pdfFiles.Length + 1) + ".pdf";

                filePath = pdfDir.FullName + @"\" + fileName;

                try {

                        List<ListGrowerTareItem> hdrList = WSCReportsExec.GrowerDetailReportMasterHdr(cropYear, fromDate, toDate, factoryList,
                            stationList, contractList, isPosted, isHardCopy, isEmail, isFax);

                        if (hdrList.Count == 0) {
                            CWarning warn = new CWarning("No results matched your search criteria.");
                            throw (warn);
                        }

                    using (FileStream fsHardCopy = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read)) {

                            ReportBuilder(hdrList, cropYear, isPosted, isPreview, isHardCopy, isEmail, isFax, fsHardCopy, filePath);
                        }
                }
                catch (System.Exception ex) {
                    string errMsg = "cropYear: " + cropYear.ToString();

                    WSCIEMP.Common.CException wscEx = new WSCIEMP.Common.CException(MOD_NAME + "." + METHOD_NAME + ": " + errMsg, ex);
                    throw (wscEx);
                }

                return filePath;
            }
            catch (System.Exception ex) {
                string errMsg = "cropYear: " + cropYear.ToString();

                WSCIEMP.Common.CException wscEx = new WSCIEMP.Common.CException(MOD_NAME + "." + METHOD_NAME + ": " + errMsg, ex);
                throw (wscEx);
            }
        }
Exemplo n.º 15
0
        public static void SendFax(string faxServerName, string toFaxName, string toFaxNumber,
                                   string toVoiceNumber, string toFaxBusName, string fromFaxName, string fromFaxVoiceNumber,
                                   string faxAttachPath, string subject)
        {
            int lineNum = 0;

            try {
                //lineNum = 1;
                //RFCOMAPILib.FaxServerClass faxserver = new RFCOMAPILib.FaxServerClass();
                //lineNum = 2;
                //faxserver.ServerName = faxServerName;
                //lineNum = 3;
                //faxserver.UseNTAuthentication = RFCOMAPILib.BoolType.True;
                //lineNum = 4;
                //faxserver.Protocol = RFCOMAPILib.CommunicationProtocolType.cpSecTCPIP;
                //lineNum = 5;
                //faxserver.OpenServer();
                //lineNum = 6;


//If (m_rfxServer Is Nothing) Then

//    ' Create the Server object -- early bind.
//    Set m_rfxServer = New RFCOMAPILib.FaxServer

//    ' Set Server Name, Authentication, and Protocol.  This is the
//    ' minimum property set to send a fax.  When not using NTAuth, you
//    ' must supply user name and password.
//    m_rfxServer.ServerName = g_strFAXServer
//    m_rfxServer.UseNTAuthentication = True
//    m_rfxServer.Protocol = cpSecTCPIP

//End If

//' Create the Fax object and set minimal properties
//Set objFax = m_rfxServer.CreateObject(coFax)
//With objFax

//    .Owner = m_rfxServer.User ' Equate Owner to current user.
//    .FromName = strFromName
//    .ToName = strToName
//    .ToFaxNumber = strFaxNumber

//    ' Add the attachment via the Attachments.Add method.
//    ' DO NOT CREATE ATTACHMENT OBJECT.  Bug in software
//    ' does not allow you to add the object to the collection.
//    ' this is the workaround.
//    .Attachments.Add strFileName, False

//    ' Send the fax
//    .Send
//    DoEvents

//End With

//Set objFax = Nothing



                ////RFCOMAPILib.Fax fax = (RFCOMAPILib.Fax)faxserver.CreateObject(RFCOMAPILib.CreateObjectType.coFax);
                //RFCOMAPILib.Fax fax = (RFCOMAPILib.Fax)faxserver.CreateObject[RFCOMAPILib.CreateObjectType.coFax];
                //lineNum = 7;

                //fax.Owner = faxserver.User;

                //if (!String.IsNullOrEmpty(toFaxName)) {
                //    fax.ToName = toFaxName;
                //    lineNum = 8;
                //}
                //if (!String.IsNullOrEmpty(toFaxNumber)) {
                //    fax.ToFaxNumber = toFaxNumber;
                //    lineNum = 9;
                //}
                //if (!String.IsNullOrEmpty(toVoiceNumber)) {
                //    fax.ToVoiceNumber = toVoiceNumber;
                //    lineNum = 10;
                //}
                //if (!String.IsNullOrEmpty(toFaxBusName)) {
                //    fax.ToCompany = toFaxBusName;
                //    lineNum = 11;
                //}
                //if (!String.IsNullOrEmpty(fromFaxVoiceNumber)) {
                //    fax.FromName = fromFaxName;
                //    lineNum = 12;
                //}
                //if (!String.IsNullOrEmpty(fromFaxVoiceNumber)) {
                //    fax.FromVoiceNumber = fromFaxVoiceNumber;
                //    lineNum = 13;
                //}
                //fax.EmailSubject = subject;
                //lineNum = 14;

                //faxserver.AuthorizationUser.SendNotifyOnIncompleteFirstTime = RFCOMAPILib.BoolType.False;
                //lineNum = 15;
                //faxserver.AuthorizationUser.SendNotifyOnIncompletePeriodically = RFCOMAPILib.BoolType.False;
                //lineNum = 16;
                //faxserver.AuthorizationUser.SendNotifyOnNoHoldForPreview = RFCOMAPILib.BoolType.False;
                //lineNum = 17;
                //faxserver.AuthorizationUser.SendNotifyOnSendFailedWillRetry = RFCOMAPILib.BoolType.False;
                //lineNum = 18;
                ////faxserver.AuthorizationUser.SendNotifyOnSendFailure = RFCOMAPILib.BoolType.False;
                //faxserver.AuthorizationUser.SendNotifyOnSendHeldForApproval = RFCOMAPILib.BoolType.False;
                //lineNum = 19;
                //faxserver.AuthorizationUser.SendNotifyOnSendingFirstTime = RFCOMAPILib.BoolType.False;
                //lineNum = 20;
                //faxserver.AuthorizationUser.SendNotifyOnSendingPeriodically = RFCOMAPILib.BoolType.False;
                //lineNum = 21;
                ////faxserver.AuthorizationUser.SendNotifyOnSentSuccessfully = RFCOMAPILib.BoolType.False;

                //fax.Attachments.Add(faxAttachPath, RFCOMAPILib.BoolType.False);
                //lineNum = 22;
                //Thread.Sleep(2000);
                //lineNum = 23;

                //fax.Send();

                //lineNum = 24;
                //Thread.Sleep(2000);
                //lineNum = 25;

                //faxserver.CloseServer();
                //lineNum = 26;

//                RFXServ.OpenServer()
//                RFXDoc = RFXServ.CreateObject(RFCOMAPILib.CreateObjectType.coFax)
//                With RFXDoc
//                    'Populate the basic data... we already know that we have a non-null fax number,
//                    'so no need to check again...
//                    .ToFaxNumber = dr.FaxNumber
//                    With RFXServ.AuthorizationUser
                //'Effectively, we do not want any feedback coming back from the fax server telling
                //'us anything about the sending status...
//                        .SendNotifyOnIncompleteFirstTime = False
                //.SendNotifyOnIncompletePeriodically = False
                //.SendNotifyOnNoHoldForPreview = False
                //.SendNotifyOnSendFailedWillRetry = False
                //.SendNotifyOnSendFailure = False
                //.SendNotifyOnSendHeldForApproval = False
                //.SendNotifyOnSendingFirstTime = False
                //.SendNotifyOnSendingPeriodically = False
                //    .SendNotifyOnSentSuccessfully = False
                //End With

//                    For Each tblDocumentsToIncludeRow In mr.GetChildRows("MessageDocumentsToInclude")
//                        'This line attaches the document to the fax... we do not delete on sending
//                        'because we may send to multiple recipients.
//                        .Attachments.Add(tblDocumentsToIncludeRow.DocumentName, RFCOMAPILib.BoolType.False)
//                        Thread.Sleep(cGeneralParametersRow.SleepMilisecondsAfterFaxing)
//                    Next
                //    .Send()
                //    'We need to give the fax server time to pickup and convert the documents before we delete them...
                //    Thread.Sleep(cGeneralParametersRow.SleepMilisecondsAfterFaxing)
                //    RFXServ.CloseServer()
                //End With
                //Return True



                //RFCOMAPILib.Fax fax = (RFCOMAPILib.Fax)faxserver.get_CreateObject(RFCOMAPILib.CreateObjectType.coFax);

                // set up your 'fax' object the way you want it, below is just some sample options
                //fax.ToName = toFaxName;
                //fax.ToFaxNumber = toFaxNumber;
                //if (!String.IsNullOrEmpty(toVoiceNumber)) {
                //    fax.ToVoiceNumber = toVoiceNumber;
                //}
                //fax.ToCompany = toFaxBusName;
                //fax.FromName = fromFaxName;
                //if (!String.IsNullOrEmpty(fromFaxVoiceNumber)) {
                //    fax.FromVoiceNumber = fromFaxVoiceNumber;
                //}

                //fax.Attachments.Add(faxAttachPath, RFCOMAPILib.BoolType.False);
                //fax.EmailSubject = subject;

                //fax.Send();
            }
            catch (System.Runtime.InteropServices.COMException cex) {
                string comErrorInfo = "";
                foreach (string key in cex.Data.Keys)
                {
                    comErrorInfo += "Key: " + key + "; definition: " + cex.Data[key].ToString() + "\n";
                }

                string errMsg = "Error in SendFax\n" +
                                "faxServerName: " + faxServerName + "\n" +
                                "toFaNamex: " + toFaxName + "\n" +
                                "To toFaxNumber: " + toFaxNumber + "\n" +
                                "TfaxAttachPath: " + faxAttachPath + "\n" +
                                "Subject: " + subject + "\n" +
                                "Line Num: " + lineNum.ToString() + "\n" +
                                "COM Error Info: " + (comErrorInfo.Length > 0? comErrorInfo: "interop: " + cex.Message);

                CException wscEx = new CException(errMsg, cex);
                LogException(wscEx, HttpContext.Current);
                throw (wscEx);
            }
            catch (Exception MailEx) {
                string errMsg = "Error in SendFax\n" +
                                "faxServerName: " + faxServerName + "\n" +
                                "toFaNamex: " + toFaxName + "\n" +
                                "To toFaxNumber: " + toFaxNumber + "\n" +
                                "TfaxAttachPath: " + faxAttachPath + "\n" +
                                "Line Num: " + lineNum.ToString() + "\n" +
                                "Subject: " + subject;
                CException wscEx = new CException(errMsg, MailEx);
                LogException(wscEx, HttpContext.Current);
                throw (wscEx);
            }
        }
Exemplo n.º 16
0
        public static void SendEmailWithAttach(string smtpServer, string smtpPort,
                                               string userName, string password, string fromEmail, string toEmail, string cc, string bcc, string subject,
                                               string message, string pathAttach)
        {
            try {
                //const string cdoSchema = "http://schemas.microsoft.com/cdo/configuration/";

                // Matched shid and email to a user.  Send them their password
                MailMessage mail = new MailMessage();

                mail.From = new MailAddress(fromEmail.Trim());
                foreach (string recip in toEmail.Split(new char[] { ';' }))
                {
                    mail.To.Add(new MailAddress(recip.Trim()));
                }

                if (!String.IsNullOrEmpty(cc))
                {
                    foreach (string recip in cc.Split(new char[] { ';' }))
                    {
                        mail.CC.Add(new MailAddress(recip.Trim()));
                    }
                }

                if (!String.IsNullOrEmpty(bcc))
                {
                    foreach (string recip in bcc.Split(new char[] { ';' }))
                    {
                        mail.Bcc.Add(new MailAddress(recip.Trim()));
                    }
                }

                mail.Subject = subject;
                mail.Body    = message;

                if (pathAttach.Length > 0)
                {
                    foreach (string path in pathAttach.Split(new char[] { ';' }))
                    {
                        mail.Attachments.Add(new Attachment(path));
                    }
                }

                SmtpClient smtp = new SmtpClient(smtpServer, int.Parse(smtpPort));
                if (!String.IsNullOrEmpty(userName))
                {
                    if (userName == "INTEGRATED" && String.IsNullOrEmpty(password))
                    {
                        // INTEGRATED Authentication
                        smtp.UseDefaultCredentials = true;
                    }
                    else
                    {
                        // Basic Authentication
                        smtp.UseDefaultCredentials = false;
                        smtp.Credentials           = new System.Net.NetworkCredential(userName, password);
                    }
                }

                smtp.Send(mail);
            }
            catch (System.Net.Mail.SmtpException smtpEx) {
                string errMsg = "Error in SendEmail\n" +
                                "Status Code: " + smtpEx.StatusCode.ToString("G") + "\n" +
                                "To Address: " + toEmail + "\n" +
                                "Subject: " + subject;
                CException wscEx = new CException(errMsg, smtpEx);
                LogException(wscEx, HttpContext.Current);
                throw (wscEx);
            }
            catch (Exception MailEx) {
                string errMsg = "Error in SendEmail\n" +
                                "To Address: " + toEmail + "\n" +
                                "Subject: " + subject;
                CException wscEx = new CException(errMsg, MailEx);
                LogException(wscEx, HttpContext.Current);
                throw (wscEx);
            }
        }