示例#1
0
        private ReportHeaderFormat ProcessHeader(Document document)
        {
            ReportHeaderFormat header = new ReportHeaderFormat();

            #region Map Document Header

            header.DocumentName = document.DocType.Name;
            header.DocumentNumber = document.DocNumber;
            header.OrigNumber = document.QuoteNumber; //document.ErpMaster.ToString();
            header.CustPONumber = document.CustPONumber;
            header.Reference = document.Reference;
            header.UserDef1 = document.UserDef1;
            header.UserDef2 = document.UserDef2;
            header.UserDef3 = document.UserDef3;


            // Data Section
            header.Date1 = (document.Date1 == null) ? "" : document.Date1.Value.ToShortDateString();
            header.Date2 = (document.Date2 == null) ? "" : document.Date2.Value.ToString();
            header.Date3 = (document.Date3 == null) ? "" : document.Date3.Value.ToShortDateString();
            header.Date4 = (document.Date4 == null) ? "" : document.Date4.Value.ToShortDateString(); 


            try
            {
                header.Warehouse = string.IsNullOrEmpty(document.Location.ErpCode)
                    ? document.Location.Name
                    : document.Location.ErpCode;
            }
            catch { }

            header.Vendor = document.Vendor.Name;
            header.VendorAccount = document.Vendor.AccountCode;
            header.Customer = document.Customer.Name;
            header.CustomerAccount = document.Customer.AccountCode;
            header.FilterBy = document.CreatedBy; //document.User.UserName;
            header.Notes = document.Comment;
            header.Comment = document.Notes;
            header.Printed = DateTime.Today.ToString("MM/dd/yyyy hh:mm:ss");
            
            

            header.Corporate_Name = document.Company.Name;
            header.Corporate_Line1 = document.Company.AddressLine1;
            header.Corporate_Line2 = document.Company.AddressLine2;
            header.Corporate_Line3 = document.Company.AddressLine3;
            header.Corporate_Line4 = document.Company.City + ", " + document.Company.State + " " + document.Company.ZipCode;
            header.Corporate_Line5 = document.Company.Country;
            header.Corporate_Line6 = document.Company.ContactPerson;
            header.CreatedBy = document.CreatedBy;
            header.PickMethod = (document.PickMethod != null) ? document.PickMethod.Name : "";

            //Company Logo
            IList<ImageEntityRelation> img = null;

            try
            {
                img = Factory.DaoImageEntityRelation().Select(new ImageEntityRelation
                    {
                        EntityRowID = document.Company.CompanyID,
                        ImageName = "LOGO",
                        Entity = new ClassEntity { ClassEntityID = EntityID.Company }
                    });
            }
            catch { }

            header.Image1 = (img != null && img.Count > 0) ? img.First().Image : null;

            header.Barcode = document.DocNumber;


            DocumentAddress BillTo_address = null, ShipTo_address = null;


            #region Addresses 

            try
            {
                // BillTo Section
                Document addDoc;
                // header.BillTo_Name = document.Customer.AccountAddresses.ElementAt(0).Name;
                if (document.DocType.DocTypeID == SDocType.SalesShipment)
                {
                    addDoc = Factory.DaoDocument().Select(
                        new Document { DocNumber = document.CustPONumber, Company = document.Company }).First();

                    header.ShipVia = (addDoc.ShippingMethod != null) ? addDoc.ShippingMethod.ErpCode : "";
                }
                else
                {
                    addDoc = document;
                    header.ShipVia = (document.ShippingMethod != null) ? document.ShippingMethod.ErpCode : "";
                }


                BillTo_address = Factory.DaoDocumentAddress().Select(
                        new DocumentAddress
                        {
                            Document = addDoc,
                            AddressType = AddressType.Billing
                        })
                        .Where(f => f.DocumentLine == null).OrderByDescending(f=>f.RowID).First();

                header.BillTo_Name = BillTo_address.Name;
                
                header.BillTo_Line1 = BillTo_address.AddressLine1 + "\n" + BillTo_address.AddressLine2;
                if (!string.IsNullOrEmpty(BillTo_address.AddressLine3))
                    header.BillTo_Line1 += "\n" + BillTo_address.AddressLine3;


                header.BillTo_Line2 = BillTo_address.City + ", " + BillTo_address.State + " " + BillTo_address.ZipCode;
                header.BillTo_Line3 = BillTo_address.Country;
                header.BillTo_Line4 = BillTo_address.Phone1 + " " + BillTo_address.Phone2 + " " + BillTo_address.Phone3 
                    + " " + (BillTo_address.Email == null ? "" : BillTo_address.Email);

            }
            catch { }

            try
            {
                try
                {

                    Document saddDoc;
                    if (document.DocType.DocTypeID == SDocType.SalesShipment)
                    {
                        saddDoc = Factory.DaoDocument().Select(
                                 new Document { DocNumber = document.CustPONumber, Company = document.Company }).First();
                    }
                    else
                        saddDoc = document;



                    ShipTo_address = Factory.DaoDocumentAddress().Select(
                        new DocumentAddress
                        {
                            Document = saddDoc,
                            AddressType = AddressType.Shipping
                        })
                        .Where(f => f.DocumentLine == null).OrderByDescending(f => f.RowID).First();
                }
                catch { ShipTo_address = BillTo_address; }

                header.ShipTo_Name = ShipTo_address.Name;
                
                header.ShipTo_Line1 = ShipTo_address.AddressLine1 + "\n" + ShipTo_address.AddressLine2;
                if (!string.IsNullOrEmpty(ShipTo_address.AddressLine3))
                    header.ShipTo_Line1 += "\n" + ShipTo_address.AddressLine3;
                
                
                header.ShipTo_Line2 = ShipTo_address.City + ", " + ShipTo_address.State + " " + ShipTo_address.ZipCode;
                
                header.ShipTo_Line3 = ShipTo_address.Country;
                header.ShipTo_Line4 = ShipTo_address.Phone1 + " " + ShipTo_address.Phone2 + " " +  ShipTo_address.Phone3 
                    + " "+ (ShipTo_address.Email == null ? "" : ShipTo_address.Email);

            }
            catch { }


            #endregion




            return header;

            #endregion End Header Section

        }
示例#2
0
        //Entrega el dataset de un ReportHeader
        public DataSet GetReportDataset(ReportHeaderFormat header)
        {
            //Add Header to DataSet
            DataSet dh = new DataSet("Header");
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(ReportHeaderFormat));
            StringWriter writer = new StringWriter();
            xmlSerializer.Serialize(writer, header);
            StringReader reader = new StringReader(writer.ToString());
            dh.ReadXml(reader);
            //dh.Tables[0].TableName = "Header";
            //dh.Tables[2].TableName = "Details";


            ////Add Detail List to DataSet
            //DataSet dd = new DataSet("Details");
            //xmlSerializer = new XmlSerializer(header.ReportDetails.ToArray().GetType()); 
            //writer = new StringWriter();
            //xmlSerializer.Serialize(writer, header.ReportDetails.ToArray());
            //reader = new StringReader(writer.ToString());
            //dd.ReadXml(reader);
            //dd.Tables[0].TableName = "Details";

            //dd.Tables.Add(dh.Tables[0].Copy()); //Adicionamos el header a los details
            return dh;
        }