Exemplo n.º 1
0
        void grdResourceManifestAddJobs_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            Facade.ResourceManifest facade = new Facade.ResourceManifest();

            DateTime startDate = (DateTime)dteStartdate.SelectedDate;
            DateTime endDate   = (DateTime)dteEndDate.SelectedDate;

            List <int> depots = new List <int>();

            if (cboDepot.SelectedValue != "0")
            {
                depots.Add(int.Parse(cboDepot.SelectedValue));
            }
            else
            {
                depots.Clear();
            }

            DataSet   dsDrivers = new DataSet();
            DataTable dt        = new DataTable();

            dt.Columns.Add(new DataColumn("JobID", typeof(int)));
            dt.Columns.Add(new DataColumn("DriverType", typeof(string)));
            dt.Columns.Add(new DataColumn("DriverResourceID", typeof(int)));
            dt.Columns.Add(new DataColumn("DriverName", typeof(string)));
            dt.Columns.Add(new DataColumn("Instructions", typeof(string)));
            dt.Columns.Add(new DataColumn("EarliestDateTime", typeof(DateTime)));
            dt.Columns.Add(new DataColumn("OrderIDs", typeof(string)));
            //dt.Columns.Add(new DataColumn("ResourceManifestId", typeof(int)));
            dsDrivers.Tables.Add(dt);

            DataSet ds = facade.GetResourceManifestJobsToAddForDriverManifest(Convert.ToInt32(this.SavedResourceManifest.ResourceId), this.ResourceManifestId, startDate, endDate, cboDepot.SelectedValue);

            int  currentJobID  = -1;
            int  currentDriver = -1;
            bool rowAdded      = true;

            string InstructionText  = string.Empty;
            string myOrderIds       = String.Empty;
            bool   hasDriverChanged = false;

            DataRow row = null;

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string   orderIDs = String.Empty;
                DateTime plannedArrivalDateTime = chkUsePlannedTimes.Checked ? Convert.ToDateTime(dr["PlannedArrivalDateTime"]) : Convert.ToDateTime(dr["OrderDateTime"]);

                // Get the OrderIDs for the PIL Production.
                orderIDs = GetOrderIDs(dr);

                if (((int)dr["DriverResourceID"] != currentDriver))
                {
                    if (row != null)
                    {
                        if (InstructionText.Length > 0)
                        {
                            row["Instructions"] = InstructionText;
                            row["OrderIDs"]     = myOrderIds;
                        }
                        // Add the row to the table
                        dt.Rows.Add(row);
                        rowAdded = true;
                    }
                    currentDriver    = (int)dr["DriverResourceID"];
                    InstructionText  = String.Empty;
                    myOrderIds       = String.Empty;
                    hasDriverChanged = true;
                }
                if (dr["JobID"] != DBNull.Value && (((int)dr["JobID"] != currentJobID) || hasDriverChanged))
                {
                    if (row != null && rowAdded == false)
                    {
                        if (InstructionText.Length > 0)
                        {
                            row["Instructions"] = InstructionText;
                            row["OrderIDs"]     = myOrderIds;
                            // Add the row to the table
                            dt.Rows.Add(row);
                        }
                    }
                    hasDriverChanged = false;
                    currentJobID     = (int)dr["JobID"];
                    InstructionText  = String.Empty;
                    myOrderIds       = String.Empty;

                    // Add a New Row
                    row = dt.NewRow();
                    row["DriverType"]       = dr["DriverType"];
                    row["DriverName"]       = dr["FullName"];
                    row["JobID"]            = dr["JobID"];
                    row["EarliestDateTime"] = plannedArrivalDateTime;
                    row["DriverResourceID"] = dr["DriverResourceID"];
                    rowAdded = false;
                    // Add the First Instruction to the Text
                    InstructionText     = GetInstructionText(dr);
                    myOrderIds          = GetOrderIDs(dr);
                    row["Instructions"] = InstructionText;
                    row["OrderIDs"]     = myOrderIds;
                    //row["ResourceManifestId"] = dr["ResourceManifestId"];
                }
                else if (dr["JobID"] != DBNull.Value && (int)dr["JobID"] == currentJobID)
                {
                    if (plannedArrivalDateTime < ((DateTime)row["EarliestDateTime"]))
                    {
                        row["EarliestDateTime"] = plannedArrivalDateTime;
                    }
                    //Add the instruction
                    InstructionText += "<br/>" + GetInstructionText(dr);
                    myOrderIds      += ("," + GetOrderIDs(dr));
                }
                else
                {
                    // Not assigned
                    if (row != null && rowAdded == false)
                    {
                        if (InstructionText.Length > 0)
                        {
                            row["Instructions"] = InstructionText;
                            row["OrderIDs"]     = myOrderIds;
                            // Add the row to the table
                            dt.Rows.Add(row);
                        }
                    }

                    // Add a New Row
                    row = dt.NewRow();
                    row["DriverType"]       = dr["DriverType"];
                    row["DriverName"]       = dr["FullName"];
                    row["DriverResourceID"] = dr["DriverResourceID"];
                    row["JobID"]            = dr["JobID"];
                    rowAdded        = false;
                    InstructionText = String.Empty;
                    myOrderIds      = String.Empty;
                    //row["ResourceManifestId"] = dr["ResourceManifestId"];
                }
            }
            if (rowAdded == false && row != null && row["DriverType"] != DBNull.Value)
            {
                dt.Rows.Add(row);
            }

            this.grdResourceManifestAddJobs.DataSource = dsDrivers;
            //this.grdResourceManifestAddJobs.DataBind();
        }
Exemplo n.º 2
0
        private void CombinePDFs()
        {
            Response.Buffer = true;
            Facade.ResourceManifest facMan      = new Facade.ResourceManifest();
            PdfDocument             combinedPDF = new PdfDocument();



            foreach (int resourceManifestID in ManifestIDs)
            {
                // Retrieve the resource manifest
                NameValueCollection reportParams = new NameValueCollection();

                var     manifest  = facMan.GetResourceManifest(resourceManifestID);
                DataSet manifests = new DataSet();

                if (manifest.SubcontractorId == null)
                {
                    manifests.Tables.Add(ManifestGeneration.GetDriverManifest(resourceManifestID, manifest.ResourceId, true, false, false, true));
                }
                else
                {
                    manifests.Tables.Add(ManifestGeneration.GetSubbyManifest(resourceManifestID, manifest.ResourceId, true, false, false, true));
                }

                if (manifests.Tables[0].Rows.Count > 0)
                {
                    // Add blank rows if applicable
                    int extraRows = 0;
                    if (extraRows > 0)
                    {
                        for (int i = 0; i < extraRows; i++)
                        {
                            DataRow newRow = manifests.Tables[0].NewRow();
                            manifests.Tables[0].Rows.Add(newRow);
                        }
                    }

                    //-------------------------------------------------------------------------------------
                    //									Load Report Section
                    //-------------------------------------------------------------------------------------
                    reportParams.Add("ManifestName", manifest.Description);
                    reportParams.Add("ManifestID", manifest.ResourceManifestId.ToString());
                    reportParams.Add("UsePlannedTimes", "false");

                    Session[Orchestrator.Globals.Constants.ReportTypeSessionVariable]       = eReportType.RunSheet;
                    Session[Orchestrator.Globals.Constants.ReportParamsSessionVariable]     = reportParams;
                    Session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable]  = manifests;
                    Session[Orchestrator.Globals.Constants.ReportDataSessionSortVariable]   = "";
                    Session[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable] = "Table";

                    MemoryStream mem = ExecuteReport1();
                    PdfDocument  pdf = PdfReader.Open(mem, PdfDocumentOpenMode.Import);
                    foreach (PdfPage page in pdf.Pages)
                    {
                        combinedPDF.AddPage(page);
                    }
                }
            }


            //string[] pdfs = Directory.GetFiles(PDFPath);
            //foreach (string file in pdfs)
            //{
            //    PdfDocument pdf = PdfReader.Open(file, PdfDocumentOpenMode.Import);

            //    foreach (PdfPage page in pdf.Pages)
            //        combinedPDF.AddPage(page);
            //}


            // Show the user control
            // Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", "<script language=\"javascript\">window.open('" + Page.ResolveClientUrl("../reports/reportviewer.aspx?wiz=true") + "');</script>");



            // Combine the PDFS into a single document
            //foreach (var invoice in invoices)
            //{
            //    using (FileStream fs = File.OpenRead(Server.MapPath(invoice.PDFLocation)))
            //    {
            //        pdf = PdfReader.Open(fs, PdfDocumentOpenMode.Import);
            //    }
            //}

            // Stream this to the IFrame
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.Buffer      = true;
            Response.ContentType = "application/pdf";

            // this makes a new window appear:
            //Response.AddHeader("content-disposition","attachment; filename=MyPDF.PDF");
            Response.AddHeader("content-disposition", "inline; filename=Manifests.PDF");

            MemoryStream binaryData = new MemoryStream();

            combinedPDF.Save(binaryData);

            Response.BinaryWrite(binaryData.ToArray());

            //Directory.Delete(PDFPath);
        }