Example #1
0
 public static void GetAddressInfo(SqlConnection conn, int contractID, out string busName, out string address1, out string address2,
                                   out string CSZ, out string emailAddress, out string faxNumber)
 {
     using (SqlDataReader drAddr = WSCReportsExec.GrowerDetailReportAddr(conn, contractID)) {
         if (drAddr.Read())
         {
             busName  = drAddr.GetString(drAddr.GetOrdinal("Business_Name"));
             address1 = drAddr.GetString(drAddr.GetOrdinal("Address_1"));
             address2 = drAddr.GetString(drAddr.GetOrdinal("Address_2"));
             CSZ      = drAddr.GetString(drAddr.GetOrdinal("City")) + ", " +
                        drAddr.GetString(drAddr.GetOrdinal("State")) + " " +
                        drAddr.GetString(drAddr.GetOrdinal("Zip"));
             emailAddress = drAddr.GetString(drAddr.GetOrdinal("EmailAddress"));
             faxNumber    = drAddr.GetString(drAddr.GetOrdinal("FaxNumber"));
         }
         else
         {
             busName      = "";
             address1     = "";
             address2     = "";
             CSZ          = "";
             emailAddress = "";
             faxNumber    = "";
         }
     }
 }
        public static void ReportBuilder(SqlDataReader drHdr, int cropYear, int contractNumber, string deliveryDates, FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilder";
            Document     document    = null;
            PdfWriter    writer      = null;

            DailyGrowerTareDetailEvent pgEvent = null;

            int    resetFlag         = 0;
            string dates             = null;
            int    contractID        = 0;
            string factoryNo         = "";
            string firstDeliveryDate = null;
            string nextDeliveryDate  = null;
            string lastDeliveryDate  = null;
            string busName           = "";
            string address1          = "";
            string address2          = "";
            string CSZ = "";

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

            try {
                if (drHdr.Read())
                {
                    contractID        = drHdr.GetInt32(drHdr.GetOrdinal("ContractID"));
                    factoryNo         = drHdr.GetString(drHdr.GetOrdinal("Delivery_Factory_No"));
                    firstDeliveryDate = drHdr.GetString(drHdr.GetOrdinal("Delivery_Date"));
                    nextDeliveryDate  = firstDeliveryDate;
                }
                else
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }

                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BeetConn"].ToString())) {
                    // Header Address Info
                    if (contractID > 0)
                    {
                        using (SqlDataReader drAddr = WSCReportsExec.GrowerDetailReportAddr(conn, contractID)) {
                            if (drAddr.Read())
                            {
                                busName  = drAddr.GetString(drAddr.GetOrdinal("Business_Name"));
                                address1 = drAddr.GetString(drAddr.GetOrdinal("Address_1"));
                                address2 = drAddr.GetString(drAddr.GetOrdinal("Address_2"));
                                CSZ      = drAddr.GetString(drAddr.GetOrdinal("City")) + ", " +
                                           drAddr.GetString(drAddr.GetOrdinal("State")) + " " +
                                           drAddr.GetString(drAddr.GetOrdinal("Zip"));
                            }
                        }
                    }

                    // Sample / Tare information
                    // I use nextDeliveryDate as a trick to allow reading drHdr.  Initially,
                    // nextDeliveryDate is loaded and we skip reading drHdr.  Subsequently,
                    // the bottom of each iteration will null nextDeliveryDate and force reading drHdr.
                    int loadCount = 0;

                    while (nextDeliveryDate != null || drHdr.Read())
                    {
                        if (document == null)
                        {
                            // 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(contractNumber, busName, factoryNo, address1, address2, CSZ, resetFlag, rptTitle);
                            writer.PageEvent = pgEvent;

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

                        // load the delivery date.
                        nextDeliveryDate = drHdr.GetString(drHdr.GetOrdinal("Delivery_Date"));

                        // Acquire the sample details for the first station on a given day
                        if (lastDeliveryDate != nextDeliveryDate)
                        {
                            AddSampleHdr(ref document, drHdr, cropYear, pgEvent);
                            lastDeliveryDate = nextDeliveryDate;
                            using (SqlDataReader drSamples = WSCReportsExec.GrowerDetailReportTares(conn, contractID, nextDeliveryDate)) {
                                AddSampleDetail(ref document, drSamples, pgEvent);
                            }
                        }

                        loadCount = 0;

                        // Display Truck information for each station
                        // on the first delivery day.
                        if (nextDeliveryDate == firstDeliveryDate)
                        {
                            // Get the truck data.
                            SqlParameter[] spParams = null;
                            using (SqlDataReader drTrucks = WSCReportsExec.GrowerDetailReportASH(conn, contractID,
                                                                                                 drHdr.GetInt32(drHdr.GetOrdinal("Delivery_Station_ID")),
                                                                                                 firstDeliveryDate, ref spParams)) {
                                AddTruckDetail(ref document, drTrucks, pgEvent);

                                drTrucks.Close();
                                loadCount = Convert.ToInt32(spParams[3].Value);
                                if (loadCount > 0)
                                {
                                    AddTruckTotals(ref document, loadCount.ToString(),
                                                   Convert.ToInt32(spParams[4].Value).ToString("#,##0"),
                                                   Convert.ToInt32(spParams[5].Value).ToString("#,##0"), pgEvent);
                                }
                            }
                        }

                        // clear date to force read in top of loop
                        nextDeliveryDate = null;
                    }
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }