Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("AddressId,Street,HouseNumber,FlatNumber,PostalCode,City")] TAddress tAddress)
        {
            if (id != tAddress.AddressId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tAddress);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TAddressExists(tAddress.AddressId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tAddress));
        }
Example #2
0
            /// <summary>
            /// Tries to get the innermost symbol containing the specified scalar. If no symbol contains the scalar the trial fails.
            /// </summary>
            /// <returns><c>true</c>, if the interval was found, <c>false</c> when such interval does not exist.</returns>
            /// <param name="scalar">Scalar.</param>
            /// <param name="interval">Found interval.</param>
            public bool TryGet(TAddress scalar, out Symbol interval)
            {
                interval = default(Symbol);
                var marker = new MarkerSymbol(scalar);
                var index  = Array.BinarySearch <Symbol>(symbols, marker, comparer);

                if (index < 0)
                {
                    index = ~index;
                    //we are behind last element or before 1st
                    if (index == 0)
                    {
                        return(false);
                    }
                    //move back one element because search will always point to the 1st larger element than the marker
                    index--;
                }

                /***
                 * We might be between two towers, that lie on the commond ground (we will be between the top of the left tower and
                 * before the base of the next one). `index` points to the left top symbol, we check if any enclosing symbol also contains the
                 * scalar. If not, there is no such symbol (the common ground) and scalar just lies between two towers. If it exists scalar
                 * Is between two symbol lying on the same base.
                 ****/
                index = FindEnclosingInterval(index, scalar);
                if (index != NoEnclosingInterval)
                {
                    interval = symbols[index];
                    return(true);
                }

                return(false);
            }
Example #3
0
        private void InitializeTapi()
        {
            try
            {
                if (tTapi.Initialize() == 0)
                {
                    MessageBox.Show("No TAPI devices available.");
                    this.Close();
                }

                tTapi.TE_CALLSTATE += new EventHandler <TapiCallStateEventArgs>(tapi_TE_CALLSTATE);

                // Add all the voice-capable lines.
                comboBox1.Items.AddRange(
                    Array.FindAll(tTapi.Addresses,
                                  delegate(TAddress addr)
                {
                    return((addr.MediaTypes & TAPIMEDIATYPES.AUDIO) != 0);
                }));

                if (comboBox1.Items.Count > 0)
                {
                    comboBox1.SelectedIndex = 0;
                    selectedAddress         = (TAddress)comboBox1.SelectedItem;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Example #4
0
 public void DeleteAddress(TAddress address)
 {
     if (address == null)
     {
         throw new ArgumentNullException(nameof(address));
     }
     _context.TAddresses.Remove(address);
 }
Example #5
0
 /// <summary>
 /// Checks if the given <paramref name="scalar"/> is enclosed by the one under <paramref name="index"/> or one of it's "parents".
 /// </summary>
 /// <returns>The enclosing interval index or NoEnclosingInterval.</returns>
 /// <param name="index">Index of the input interval.</param>
 /// <param name = "scalar"></param>
 private int FindEnclosingInterval(int index, TAddress scalar)
 {
     while (index != NoEnclosingInterval && !symbols[index].Contains(scalar))
     {
         index = indexOfEnclosingInterval[index];
     }
     return(index);
 }
 /// <summary>
 /// Tries to get the innermost symbol which contains the specified address.
 /// </summary>
 /// <returns><c>true</c>, if a symbol was found, <c>false</c> when no symbol contains specified address.</returns>
 /// <param name="offset">Offset.</param>
 /// <param name="symbol">Symbol.</param>
 public bool TryGetSymbolByAddress(TAddress offset, out Symbol symbol)
 {
     if (offset > maxLoadAddress)
     {
         symbol = default(Symbol);
         return(false);
     }
     return(symbols.TryGet(offset, out symbol));
 }
Example #7
0
        public void Init()
        {
            serviceClient = new UserServiceClient();

            // create test users that can be used with the create and update methods
            User_in.Alias                       = alias;
            User_in.Password                    = "******";
            User_in.Name                        = "Klaus Klaussen";
            User_in.EMail                       = "*****@*****.**";
            User_in.DeleteConfirmation          = false;
            User_in.DeleteConfirmationSpecified = true;

            User_update.DeleteConfirmation          = true;
            User_update.DeleteConfirmationSpecified = true;

            TAddress bill = new TAddress();

            bill.FirstName          = "Klaus";
            bill.LastName           = "Klaussen";
            bill.Street             = "Musterstraße 2";
            bill.EMail              = "*****@*****.**";
            bill.Birthday           = new DateTime(1976, 9, 25, 11, 33, 0);
            User_in.BillingAddress  = bill;
            User_in.ShippingAddress = bill;

            TAttribute attr = new TAttribute();

            attr.Name          = "ChallengePhrase";
            attr.Value         = "my challenge phrase";
            User_in.Attributes = new TAttribute[] { attr };

            User_update.Path     = path + alias;
            User_update.Password = "******";
            User_update.Name     = "Hans Hanssen";
            User_update.EMail    = "*****@*****.**";

            // IMPORTANT!!!
            // .NET has the terrible behavior, to set all boolean and numeric value that are not
            // defined to "false" resp. "0"
            // So if you update an object and do not set the "IsVisible" flag, it will set the object to
            // invisible!!!
            User_update.DeleteConfirmation = true;

            TAddress bill_update = new TAddress();

            bill_update.FirstName      = "Hans";
            bill_update.LastName       = "Hanssen";
            bill_update.Street         = "Musterstraße 2b";
            bill_update.Birthday       = new DateTime(1976, 9, 25, 11, 33, 0);
            User_update.BillingAddress = bill_update;

            TAttribute attr_update = new TAttribute();

            attr_update.Name       = "ChallengePhrase";
            attr_update.Value      = "my updated challenge phrase";
            User_update.Attributes = new TAttribute[] { attr_update };
        }
        /// <summary>
        /// Gets the innermost symbol which contains the specified address.
        /// </summary>
        /// <returns>The symbol by address.</returns>
        /// <param name="offset">Offset.</param>
        public Symbol GetSymbolByAddress(TAddress offset)
        {
            Symbol symbol;

            if (!TryGetSymbolByAddress(offset, out symbol))
            {
                throw new KeyNotFoundException("No symbol for given address [" + offset + "] found.");
            }
            return(symbol);
        }
Example #9
0
            /// <summary>
            /// Gets the innermost interval containing the specified scalar.
            /// </summary>
            /// <param name="scalar">Scalar.</param>
            /// <returns>The innermost interval containing the specified scalar, if such exists.</returns>
            public Symbol Get(TAddress scalar)
            {
                Symbol interval;

                if (TryGet(scalar, out interval))
                {
                    return(interval);
                }
                throw new KeyNotFoundException("No symbol for given address [" + scalar + "] found.");
            }
Example #10
0
        public void CreateAddress(TAddress address)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            _context.TAddresses.Add(address);
            _context.SaveChanges();
        }
Example #11
0
        public async Task <IActionResult> Create([Bind("AddressId,Street,HouseNumber,FlatNumber,PostalCode,City")] TAddress tAddress)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tAddress);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tAddress));
        }
Example #12
0
        public void Init()
        {
            serviceClient = new CustomerServiceClient();

            // create test customers that can be used with the create and update methods
            customer_in.Alias = alias;
            TAddress bill = new TAddress();

            bill.FirstName             = "Klaus";
            bill.LastName              = "Klaussen";
            bill.Street                = "Musterstraße 2";
            bill.EMail                 = "*****@*****.**";
            bill.Birthday              = new DateTime(1976, 9, 25, 11, 33, 0, DateTimeKind.Local);
            bill.BirthdaySpecified     = true;
            bill.VerifiedOn            = new DateTime(2005, 1, 1);
            bill.VerifiedOnSpecified   = true;
            customer_in.BillingAddress = bill;

            TAttribute attr = new TAttribute();

            attr.Name                             = "Comment";
            attr.Value                            = "my customer comment";
            customer_in.Attributes                = new TAttribute[] { attr };
            customer_in.IsDoOrderAllowed          = true;
            customer_in.IsDoOrderAllowedSpecified = true;


            customer_update.Path = path + alias;
            TAddress bill_update = new TAddress();

            bill_update.FirstName           = "Hans";
            bill_update.LastName            = "Hanssen";
            bill_update.Street              = "Musterstraße 2b";
            bill_update.Birthday            = new DateTime(1976, 9, 25, 11, 33, 0, DateTimeKind.Local);
            bill_update.BirthdaySpecified   = true;
            bill_update.VerifiedOn          = new DateTime(2005, 1, 1);
            bill_update.VerifiedOnSpecified = true;
            customer_update.BillingAddress  = bill_update;

            TAttribute attr_update = new TAttribute();

            attr_update.Name                 = "Comment";
            attr_update.Value                = "my updated customer comment";
            customer_update.Attributes       = new TAttribute[] { attr_update };
            customer_update.IsDoOrderAllowed = true; customer_update.IsDoOrderAllowedSpecified = true;
        }
Example #13
0
        private void CheckControls()
        {
            btnDisconnect.Enabled = currCall != null;

            if (cbDestinationType.SelectedIndex >= 0 &&
                textDestination.Text.Length > 0 &&
                cbAddress.SelectedIndex >= 0)
            {
                TAddress         addr     = (TAddress)cbAddress.SelectedItem;
                LINEADDRESSTYPES addrType = (LINEADDRESSTYPES)cbDestinationType.SelectedItem;

                btnDial.Enabled = (currCall == null && (addr.get_AddressCapability(ADDRESS_CAPABILITY.AC_ADDRESSTYPES) & (int)addrType) != 0);
            }
            else
            {
                btnDial.Enabled = false;
            }
        }
Example #14
0
        private static void InitiateCall(string phoneNumber)
        {
            string lineToUse = Configuration.Container.lineToUse;

            log.Info(String.Format("Creating call via line '{0}'.", lineToUse));
            TAddress line = tapi.Addresses.SingleOrDefault(a => a.AddressName == lineToUse);

            // Always assumes 0 prefix is needed to dial out.
            TCall call = line.CreateCall("0" + phoneNumber, LINEADDRESSTYPES.PhoneNumber, TAPIMEDIATYPES.AUDIO);

            try {
                call.Connect(false);
            }
            catch (TapiException ex) {
                log.Error("TapiException: ", ex);
                return;
            }

            log.Info(String.Format("Calling '{0}'...", phoneNumber));
        }
            /// <summary>
            /// Checks if the given <paramref name="scalar"/> is enclosed by the one under <paramref name="index"/> or one of it's "parents".
            /// </summary>
            /// <returns>The enclosing interval index or NoEnclosingInterval.</returns>
            /// <param name="index">Index of the input interval.</param>
            /// <param name = "scalar"></param>
            private int FindEnclosingInterval(int index, TAddress scalar)
            {
                var original = index;

                while (index != NoEnclosingInterval && !symbols[index].Contains(scalar))
                {
                    index = indexOfEnclosingInterval[index];
                }
                // A special case when we hit after a 0-length symbol thas does not have any parent.
                // We do not need to check it in the loop, as such a symbol would never enclose other symbols.
                // This gives an approximate result.
                if (index == NoEnclosingInterval)
                {
                    if (symbols[original].Start <= scalar && symbols[original].End == symbols[original].Start && (symbols.Length == original + 1 || symbols[original + 1].Start > scalar))
                    {
                        index = original;
                    }
                }
                return(index);
            }
Example #16
0
        private static void CheckForTAPILineErrors()
        {
            if (string.IsNullOrEmpty(Configuration.Container.lineToUse))
            {
                log.Info("No line configuration value set. Starting settings application...");
                CallTAPILineConfiguration();
                return;
            }

            string lineToUse = Configuration.Container.lineToUse;

            if (string.IsNullOrEmpty(lineToUse))
            {
                log.Error("No TAPI line selected!");
                if (MessageBox.Show("No TAPI line selected!\nDo you wish to select a new TAPI line?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    CallTAPILineConfiguration();
                }
                else
                {
                    Environment.Exit(0);
                }
                return;
            }

            TAddress line = tapi.Addresses.SingleOrDefault(a => a.AddressName == lineToUse);

            if (null == line)
            {
                log.Error(String.Format("Unable to find TAPI line with name '{0}'!", lineToUse));
                if (MessageBox.Show(String.Format("Unable to find TAPI line with name '{0}'!\nDo you wish to select another TAPI line?", lineToUse), "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    CallTAPILineConfiguration();
                    return;
                }
                else
                {
                    Environment.Exit(0);
                }
            }
        }
Example #17
0
        //saves Address data TAddress table
        public JsonResult SaveAddress(TAddress AddressData)
        {
            bool result = false;

            try
            {
                if (AddressData != null)
                {
                    using (DatabaseEntities db = new DatabaseEntities())
                    {
                        db.TAddresses.Add(AddressData);
                        db.SaveChanges();
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #18
0
 public MarkerSymbol(TAddress value) : base(value, MarkerComparer <TAddress> .GetMarkerValue())
 {
 }
 public ActionResult <TAddress> Post(TAddress address)
 {
     _address.CreateAddress(address);
     return(Ok());
 }
Example #20
0
        /// <summary>
        /// Inserts a new symbol with defined parameters into the lookup structure.
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="start">Start.</param>
        /// <param name="size">Size.</param>
        /// <param name="type">SymbolType.</param>
        /// <param name="binding">Symbol binding</param>
        /// <param name="isThumb">If set to <c>true</c>, symbol is marked as a thumb symbol.</param>
        public void InsertSymbol(string name, TAddress start, TAddress size, SymbolType type = SymbolType.NotSpecified, SymbolBinding binding = SymbolBinding.Global, bool isThumb = false)
        {
            var symbol = new Symbol(start, start + size, name, type, binding, isThumb);

            InsertSymbol(symbol);
        }
Example #21
0
        static void Main(string[] args)
        {
            TTapi tapi = new JulMar.Tapi3.TTapi();
            TCall call = null; TAddress modemAddr = null;

            Console.WriteLine("{0} found", tapi.Initialize());

            tapi.TE_CALLNOTIFICATION += delegate(object sender, TapiCallNotificationEventArgs e)
            {
                Console.WriteLine("New call {0} detected from {1}", e.Call.ToString(), e.Event);
            };
            tapi.TE_CALLSTATE += delegate(object sender, TapiCallStateEventArgs e)
            {
                Console.WriteLine("{0}:{4} has changed state to {1} due to {2} - current={3}:{5}", e.Call, e.State, e.Cause, e.Call == call, e.Call.GetHashCode(), (call != null) ? call.GetHashCode() : 0);

                if (e.State == CALL_STATE.CS_INPROGRESS && e.Call == call)
                {
                    Console.WriteLine("Dropping call");
                    e.Call.Disconnect(DISCONNECT_CODE.DC_NORMAL);
                }
            };

            foreach (TPhone phone in tapi.Phones)
            {
                using (phone)
                {
                    phone.Open(PHONE_PRIVILEGE.PP_MONITOR);
                    Console.WriteLine("{0}\nTotal buttons: {1}", phone.Display, phone.get_PhoneCapability(PHONECAPS_LONG.PCL_NUMBUTTONLAMPS));
                }
            }

            foreach (TAddress addr in tapi.Addresses)
            {
                if (String.Compare(addr.ServiceProviderName, "unimdm.tsp", true) == 0 && addr.QueryMediaType(TAPIMEDIATYPES.AUDIO))
                {
                    modemAddr = addr;
                }
            }

            if (modemAddr != null)
            {
                Console.WriteLine("{0} = {1} ({3}) [{2}]", modemAddr.AddressName, modemAddr.State, modemAddr.ServiceProviderName, modemAddr.DialableAddress);
                modemAddr.Monitor(TAPIMEDIATYPES.AUDIO);

                ConsoleKey ki = ConsoleKey.A;
                while (ki != ConsoleKey.Q)
                {
                    // Flip the auto-destroy flag
                    if (ki == ConsoleKey.D)
                    {
                        tapi.AutoDestroyCalls = !tapi.AutoDestroyCalls;
                        Console.WriteLine("Set AutoDestroy to {0}", tapi.AutoDestroyCalls);
                    }

                    // List existing calls
                    if (ki == ConsoleKey.L)
                    {
                        foreach (TCall _call in modemAddr.Calls)
                        {
                            Console.WriteLine("Existing call found: {0}:{1}", _call, _call.GetHashCode());
                            _call.Dispose(); // Go ahead and dump it
                        }
                    }

                    // Create a new call
                    else
                    {
                        call = modemAddr.CreateCall("5551213", LINEADDRESSTYPES.PhoneNumber, TAPIMEDIATYPES.DATAMODEM);
                        Console.WriteLine("Created new call {0}:{1}", call, call.GetHashCode());
                        try
                        {
                            // This will fail if existing call interface is still around (i.e. not disposed)
                            call.Connect(false);
                        }
                        catch (TapiException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    Console.WriteLine("Press a key to try another call.. Q to quit");
                    ki = Console.ReadKey().Key;
                }
            }

            tapi.Shutdown();

            // Call should be disposed here.. state will be CS_UNKNOWN
            if (call != null)
            {
                Console.WriteLine("{0} {1}", call, call.CallState);
            }
        }
Example #22
0
 /// <summary>
 /// Gets the innermost symbol which contains the specified address.
 /// </summary>
 /// <returns>The symbol by address.</returns>
 /// <param name="offset">Offset.</param>
 public Symbol GetSymbolByAddress(TAddress offset)
 {
     return(symbols.Get(offset));
 }
Example #23
0
        public void Init()
        {
            serviceClient = new OrderServiceClient();

            // create test Orders that can be used with the create and update methods
            Order_in.Alias             = alias;
            Order_in.Customer          = "/Shops/DemoShop/Customers/1001";
            Order_in.CreationDate      = new DateTime(2006, 1, 1, 12, 0, 0, DateTimeKind.Local);
            Order_in.ViewedOn          = new DateTime(2006, 1, 1, 23, 59, 0, DateTimeKind.Local);
            Order_in.ViewedOnSpecified = true;

            TProductLineItemIn productLineItem = new TProductLineItemIn();

            productLineItem.Product           = "/Shops/DemoShop/Products/ho_1112105010";
            productLineItem.Quantity          = 10;
            productLineItem.QuantitySpecified = true;
            TLineItemContainerIn lineItemContainer = new TLineItemContainerIn();

            lineItemContainer.CurrencyID       = "EUR";
            lineItemContainer.PaymentMethod    = "/Shops/DemoShop/PaymentMethods/Invoice";
            lineItemContainer.ShippingMethod   = "/Shops/DemoShop/ShippingMethods/Express";
            lineItemContainer.TaxArea          = "/TaxMatrixGermany/EU";
            lineItemContainer.TaxModel         = "gross";
            lineItemContainer.ProductLineItems = new TProductLineItemIn[] { productLineItem };
            Order_in.LineItemContainer         = lineItemContainer;

            TAddress bill = new TAddress();

            bill.FirstName           = "Klaus";
            bill.LastName            = "Klaussen";
            bill.Street              = "Musterstraße 2";
            bill.EMail               = "*****@*****.**";
            bill.Birthday            = new DateTime(1976, 9, 25, 11, 33, 0, DateTimeKind.Local);
            bill.BirthdaySpecified   = true;
            bill.VerifiedOn          = new DateTime(2005, 1, 1, 0, 0, 0, DateTimeKind.Local);
            bill.VerifiedOnSpecified = true;
            Order_in.BillingAddress  = bill;

            TAttribute attr = new TAttribute();

            attr.Name           = "Comment";
            attr.Value          = "my Order comment";
            Order_in.Attributes = new TAttribute[] { attr };



            Order_update.Path                  = path + alias;
            Order_update.CreationDate          = new DateTime(2006, 1, 1, 2, 2, 2, DateTimeKind.Local);
            Order_update.CreationDateSpecified = true;
            Order_update.ViewedOn              = new DateTime(2006, 1, 2, 0, 0, 0, DateTimeKind.Local);
            Order_update.ViewedOnSpecified     = true;

            TAddress bill_update = new TAddress();

            bill_update.FirstName           = "Hans";
            bill_update.LastName            = "Hanssen";
            bill_update.Street              = "Musterstraße 2b";
            bill_update.Birthday            = new DateTime(1976, 9, 25, 11, 33, 0, DateTimeKind.Local);
            bill_update.BirthdaySpecified   = true;
            bill_update.VerifiedOn          = new DateTime(2005, 1, 1, 0, 0, 0, DateTimeKind.Local);
            bill_update.VerifiedOnSpecified = true;
            Order_update.BillingAddress     = bill_update;

            TAttribute attr_update = new TAttribute();

            attr_update.Name        = "Comment";
            attr_update.Value       = "my updated Order comment";
            Order_update.Attributes = new TAttribute[] { attr_update };
        }
Example #24
0
 /// <summary>
 /// Tries to get the innermost symbol which contains the specified address.
 /// </summary>
 /// <returns><c>true</c>, if a symbol was found, <c>false</c> when no symbol contains specified address.</returns>
 /// <param name="offset">Offset.</param>
 /// <param name="symbol">Symbol.</param>
 public bool TryGetSymbolByAddress(TAddress offset, out Symbol symbol)
 {
     return(symbols.TryGet(offset, out symbol));
 }
Example #25
0
        public override ReturnValue GetMailContent(int orderId, int releaseID, TProgram_Email mi)
        {
            ReturnValue _result = new ReturnValue();


            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;

            #region getCustomerInfo
            TOrderTF _tOrder = new TOrderTF();
            _result = _tOrder.getOrderById(orderId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tOrder = _result.Object as TOrderTF;

            if (_tOrder.SourceId == 19)
            {
                _result.Code = 19;
                return(_result);
            }


            TCustomer _tCustomer = new TCustomer();
            _result = _tCustomer.getCustomerById(_tOrder.PWPCustomerId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tCustomer = _result.Object as TCustomer;



            TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
            _result = _tOrder_Line_Item.getOrderDetailsByOrderId(_tOrder.OrderId, releaseID);
            if (!_result.Success)
            {
                return(_result);
            }
            EntityList _list = _result.ObjectList;

            if (_list.Count == 0)
            {
                return(_result);
            }

            _tOrder_Line_Item = _list[0] as TOrder_Line_Item;

            TShipMethod _tShipMethod = new TShipMethod();
            _result = _tShipMethod.getShipMethodById(_tOrder_Line_Item.ShipMethodId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tShipMethod = _result.Object as TShipMethod;


            TAddress _tBillAddress = new TAddress();
            _result = _tBillAddress.getAddressById(_tOrder.CustomerAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tBillAddress = _result.Object as TAddress;



            TAddress _tShipAddress = new TAddress();
            _result = _tBillAddress.getAddressById(_tOrder.ShipToAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tShipAddress = _result.Object as TAddress;


            TPaymentArrangement _tPaymentArrangement = new TPaymentArrangement();
            _result = _tPaymentArrangement.getPaymentArrangementList(orderId);
            if (!_result.Success)
            {
                return(_result);
            }
            EntityList _paymentList = _result.ObjectList;


            double _paymentApplied     = 0;
            double _estimatedAmountDue = 0;

            foreach (TPaymentArrangement _item in _paymentList)
            {
                if (_item.PayMethodId == 4)
                {
                    _estimatedAmountDue += _item.Amount;
                }
                else
                {
                    _paymentApplied += _item.Amount;
                }
            }



            #endregion


            try
            {
                #region setup EmailMessage

                EmailMessage _mail = new EmailMessage();

                string MailContent = HttpUtility.HtmlDecode(mi.FullHtml);

                #region filter the email content
                MailContent = MailContent.Replace("[CustomerName]", _tCustomer.FirstName == null ? "" : _tCustomer.FirstName.ToString());
                MailContent = MailContent.Replace("[OrderDate]", _tOrder.OrderDate.ToString("MM/dd/yyyy"));

                string siteURL = "http://admin.tecnifibreusa.com/";
                MailContent = MailContent.Replace("[WebSite]", siteURL);
                MailContent = MailContent.Replace("[OrderNumber]", _tOrder.AltOrderNum);
                MailContent = MailContent.Replace("[PONumber]", _tOrder.PONumber);
                MailContent = MailContent.Replace("[CustomerAcct]", _tCustomer.AltCustNum);
                MailContent = MailContent.Replace("[ShipMethod]", _tShipMethod.Description);

                MailContent = MailContent.Replace("[BillingAddress]", _tBillAddress.Company + "<br> " + _tBillAddress.Address1 + " " + _tBillAddress.Address2 + "<br>" + _tBillAddress.City + ", " + _tBillAddress.StateCode + " " + _tBillAddress.PostalCode);
                MailContent = MailContent.Replace("[ShippingAddress]", _tShipAddress.Company + "<br> " + _tShipAddress.Address1 + " " + _tShipAddress.Address2 + "<br>" + _tShipAddress.City + ", " + _tShipAddress.StateCode + " " + _tShipAddress.PostalCode);

                MailContent = MailContent.Replace("[SubTotal]", (_tOrder.TotalWholeSaleAmount - _tOrder.CompProductAmount).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Tax]", "(" + Utilities.Round(_tOrder.TaxRate * 100, 2).ToString() + "%)" + (_tOrder.TotalTax - _tOrder.CompTax).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Shipping]", (_tOrder.TotalShipping - _tOrder.CompShipingCost).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Discount]", (_tOrder.TotalDiscountAmount + _tOrder.CompProductAmount).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[OrderTotal]", _tOrder.TotalOrderAmount.ToString("C", Utilities.CurrentNumberFormat));

                MailContent = MailContent.Replace("[PaymentApplied]", _paymentApplied.ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[EstimatedAmountDue]", _estimatedAmountDue.ToString("C", Utilities.CurrentNumberFormat));

                MailContent = MailContent.Replace("[BFirstName]", _tBillAddress.FirstName);
                MailContent = MailContent.Replace("[BLastName]", _tBillAddress.LastName);
                MailContent = MailContent.Replace("[SFirstName]", _tShipAddress.FirstName);
                MailContent = MailContent.Replace("[SLastName]", _tShipAddress.LastName);


                StringBuilder OrderItemHTML = new StringBuilder();

                foreach (TOrder_Line_Item _item in _list)
                {
                    OrderItemHTML.Append("<tr>");
                    OrderItemHTML.Append("  <td>" + _item.LineNum + "</td>");
                    OrderItemHTML.Append("<td>" + _item.PartNumber + "</td>");
                    OrderItemHTML.Append("<td>" + _item.ProductName + "</td>");
                    OrderItemHTML.Append("<td>" + _item.Quantity + "</td>");
                    if (_item.ShippedDate != null)
                    {
                        OrderItemHTML.Append("<td>" + _item.ShippedDate.Value.ToString("MM/dd/yyyy") + "</td>");
                    }
                    else
                    {
                        OrderItemHTML.Append("<td></td>");
                    }
                    OrderItemHTML.Append("<td>" + _item.TrackingNumber + "</td>");
                    OrderItemHTML.Append("<td>" + _item.Price.ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + (_item.DiscountAmount + _item.ComAmount).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + ((_item.ActualPrice - _item.ComAmount) / _item.Quantity).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + (_item.ActualPrice - _item.ComAmount).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("</tr>");
                }
                #endregion


                MailContent = MailContent.Replace("[Items]", OrderItemHTML.ToString());


                _mail.HtmlPart = new HtmlAttachment(MailContent);


                _mail.FromAddress = new EmailAddress(mi.RespondTo);
                _mail.Subject     = mi.Subject;

                if (Common.IsTest == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _result.Table = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_tCustomer.Email) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        _mail.AddToAddress(new EmailAddress(_tCustomer.Email));
                    }

                    _result.Table = _tCustomer.Email;
                }


                if (string.IsNullOrEmpty(mi.BccAddress) == false)
                {
                    string[] bcclist = mi.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddBccAddress(new EmailAddress(_item));
                        }
                    }
                }
                if (string.IsNullOrEmpty(mi.CCAddress) == false)
                {
                    string[] bcclist = mi.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddCcAddress(new EmailAddress(_item));
                        }
                    }
                }


                if (string.IsNullOrEmpty(_tCustomer.OrderEmail) == false)
                {
                    _mail.AddCcAddress(new EmailAddress(_tCustomer.OrderEmail));
                }
                if (string.IsNullOrEmpty(_tCustomer.SecondaryEmail) == false)
                {
                    _mail.AddCcAddress(new EmailAddress(_tCustomer.SecondaryEmail));
                }

                if (string.IsNullOrEmpty(_tCustomer.SalesRepEmail) == false)
                {
                    _mail.AddBccAddress(new EmailAddress(_tCustomer.SalesRepEmail));
                }


                _result.ObjectValue = _mail;

                #endregion
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }


            return(_result);
        }
Example #26
0
        private void OnDial(object sender, EventArgs e)
        {
            TAddress         addr     = (TAddress)cbAddress.SelectedItem;
            LINEADDRESSTYPES addrType = (LINEADDRESSTYPES)cbDestinationType.SelectedItem;

            TAPIMEDIATYPES mediaType = TAPIMEDIATYPES.AUDIO;

            if (addr.QueryMediaType(TAPIMEDIATYPES.VIDEO))
            {
                mediaType |= TAPIMEDIATYPES.VIDEO;
            }

            try
            {
                addr.Open(mediaType);
            }
            catch (TapiException ex)
            {
                // Invalid media mode? Try just datamodem for unimodem.
                if (ex.ErrorCode == unchecked ((int)0x80040004))
                {
                    try
                    {
                        addr.Open(TAPIMEDIATYPES.DATAMODEM);
                    }
                    catch
                    {
                        toolStripStatusLabel1.Text = ex.Message;
                    }
                }
                else
                {
                    toolStripStatusLabel1.Text = ex.Message;
                }
            }

            // Create a call -- this should always succeed
            currCall = addr.CreateCall(textDestination.Text, addrType, mediaType);
            if (currCall != null)
            {
                // Get the playback terminal from the call
                try
                {
                    playbackTerminal = currCall.RequestTerminal(
                        TTerminal.FilePlaybackTerminal,
                        TAPIMEDIATYPES.AUDIO, TERMINAL_DIRECTION.TD_CAPTURE);
                    if (playbackTerminal != null)
                    {
                        playbackTerminal.MediaPlayList = new string[] { PLAY_FILENAME };
                        //string[] names = playbackTerminal.MediaPlayList;
                        //playbackTerminal.Name;
                        //currCall.SelectTerminalOnCall(playbackTerminal);
                    }
                    else
                    {
                        MessageBox.Show("Failed to retrieve playback terminal.");
                    }
                }
                catch (TapiException ex)
                {
                    MessageBox.Show(ex.Message);
                }


                //// If the address supports media streams, then select terminals on it.
                //if (addr.SupportsMediaStreams)
                //{
                //    // This walks through the streams of the call and selects the default terminal
                //    // for each one.
                //    currCall.SelectDefaultTerminals();
                //}

                try
                {
                    // Connect the call
                    currCall.Connect(false);
                    toolStripStatusLabel1.Text = "Placing call...";
                }
                catch (TapiException ex)
                {
                    toolStripStatusLabel1.Text = ex.Message;
                }
            }
        }
Example #27
0
        public ReturnValue PrintInvoice(int invoiceId)
        {
            #region Get Order and Customer Info

            ReturnValue _result = new ReturnValue();

            TOrderTF      _TOrder        = new TOrderTF();
            TCustomer     _TCustomer     = new TCustomer();
            TUser         _TUser         = new TUser();
            TInvoice      _TInvoice      = new TInvoice();
            TPaymentTerms _TPaymentTerms = new TPaymentTerms();

            _result = _TInvoice.getInvoiceById(invoiceId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TInvoice = _result.Object as TInvoice;

            if (string.IsNullOrEmpty(_TPaymentTerms.Description) == true)
            {
                _TPaymentTerms.Description = "Credit Card";
            }

            _result = _TOrder.getOrderById(_TInvoice.OrderId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TOrder = _result.Object as TOrderTF;

            _result = _TCustomer.getCustomerById(_TOrder.PWPCustomerId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TCustomer = _result.Object as TCustomer;

            _result = _TUser.getUserById(_TCustomer.SalesRepId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TUser = _result.Object as TUser;

            _result = _TPaymentTerms.getPaymentTermsById(_TCustomer.PaymentTermsId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TPaymentTerms = _result.Object as TPaymentTerms;
            #endregion

            #region Get Address Info

            TAddress _TAddressBillTo = new TAddress();
            _result = _TAddressBillTo.getAddressById(_TCustomer.BillToAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TAddressBillTo = _result.Object as TAddress;



            TAddress _TAddressShipTo = new TAddress();
            _result = _TAddressShipTo.getAddressById(_TOrder.ShipToAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TAddressShipTo = _result.Object as TAddress;

            #endregion

            #region Get OrderLineItem, Invoice

            _result = _result = new TInvoice_Line_Item().getInvoice_Line_ItemListByInvoiceId(_TInvoice.InvoiceId);
            if (!_result.Success)
            {
                return(_result);
            }

            EntityList oliList = _result.ObjectList;
            oliList.Sort("OrderLineItemId", true);



            #endregion

            MemoryStream m = new MemoryStream();

            string _path = System.Configuration.ConfigurationSettings.AppSettings["InvoiceImagePath"].ToString();

            try
            {
                #region Print Order and Customer Info

                Document  document = new Document(PageSize.A4, -10, 10, 50, 60);
                PdfWriter writer   = PdfWriter.GetInstance(document, m);

                document.Open();
                Font font       = new Font(Font.FontFamily.UNDEFINED, this.PrintInvoiceSize);
                Font font7      = new Font(Font.FontFamily.UNDEFINED, 6);
                Font fontBold   = new Font(Font.FontFamily.UNDEFINED, this.PrintInvoiceSize, Font.BOLD);
                Font fontBold14 = new Font(Font.FontFamily.UNDEFINED, 12, Font.BOLD);



                PdfPTable             _PdfPTable = new PdfPTable(2);
                iTextSharp.text.Image _Image     = iTextSharp.text.Image.GetInstance(new Uri(_path + "\\Images\\tflogo.JPG"));
                _Image.ScalePercent(11.0f);
                PdfPCell _PdfPCell = new PdfPCell(_Image);
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell                     = new PdfPCell(new Paragraph("Customer Invoice", fontBold14));
                _PdfPCell.BorderWidth         = 0.0f;
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPTable.AddCell(_PdfPCell);


                Phrase _Phrase = new Phrase();
                _Phrase.Add(new Phrase("                 Waterford at Blue Lagoon\r\n\r\n", font));
                _Phrase.Add(new Phrase("                 5775 Blue Lagoon Drive, Suite 110 \r\n\r\n", font));
                _Phrase.Add(new Phrase("                 Miami, Florida 33126  \r\n\r\n", font));
                _Phrase.Add(new Phrase("                 Please make Checks/Money orders payable to:\r\n\r\n", fontBold));
                _Phrase.Add(new Phrase("                 Tecnifibre USA, INC\r\n", font));
                _PdfPCell             = new PdfPCell(_Phrase);
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell             = new PdfPCell(new Paragraph("   ", font));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                document.Add(_PdfPTable);



                _PdfPTable = new PdfPTable(new float[] { 47f, 12, 12f, 9f, 11f, 11f });
                _Phrase    = new Phrase();
                _Phrase.Add(new Paragraph("\r\n\r\nBill to Address:\r\n\r\n", fontBold14));
                _Phrase.Add(new Paragraph(
                                _TAddressBillTo.FirstName + " " + _TAddressBillTo.LastName + "\r\n\r\n" +
                                _TAddressBillTo.Address1 + "\r\n\r\n" +
                                _TAddressBillTo.City + ", " + _TAddressBillTo.StateCode + ", " + _TAddressBillTo.PostalCode
                                , font));

                _PdfPCell                   = new PdfPCell(_Phrase);
                _PdfPCell.BorderWidth       = 0.0f;
                _PdfPCell.Rowspan           = 8;
                _PdfPCell.VerticalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_MIDDLE;
                _PdfPTable.AddCell(_PdfPCell);


                fontBold.Size                 = this.PrintInvoiceSize;
                _PdfPCell                     = new PdfPCell(new Paragraph("Customer Acct", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Sales Rep", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Order #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Order Date", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("PO #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                font.Size = this.PrintInvoiceSize;
                _PdfPCell = new PdfPCell(new Paragraph(_TCustomer.AltCustNum, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TUser.FirstName + " " + _TUser.LastName, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TOrder.AltOrderNum, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TOrder.OrderDate.Year == 1 ? "" : _TOrder.OrderDate.ToString("MM/dd/yy"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TOrder.PONumber, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Invoice #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Invoice Date", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Due Date", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Terms", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Ship Date", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.InvoiceId.ToString(), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.InvoiceDate.Year == 1 ? "" : _TInvoice.InvoiceDate.ToString("MM/dd/yy"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.DueDate.Year == 1 ? "" : _TInvoice.DueDate.ToString("MM/dd/yy"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TPaymentTerms.Description, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.ShippedDate.Year == 1 ? "" : _TInvoice.ShippedDate.ToString("MM/dd/yy"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("    ", font));
                _PdfPCell.BorderWidthTop    = 0.5f;
                _PdfPCell.BorderWidthBottom = 0f;
                _PdfPCell.BorderWidthLeft   = 0.5f;
                _PdfPCell.BorderWidthRight  = 0.5f;
                _PdfPCell.Colspan           = 5;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Invoice Balance (If Paid within " + _TPaymentTerms.DiscountIfPaidInDays.ToString() + " Days)", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.Colspan             = 3;
                _PdfPTable.AddCell(_PdfPCell);

                decimal balanceInDays = Convert.ToDecimal(_TInvoice.InvoiceAmount - _TInvoice.PaiedAmount);
                if (_TInvoice.DueDate > DateTime.Now)
                {
                    balanceInDays = balanceInDays - Convert.ToDecimal(_TInvoice.InvoiceAmount * _TPaymentTerms.Discount / 100);
                }

                if (balanceInDays < 0)
                {
                    balanceInDays = 0;
                }
                _PdfPCell = new PdfPCell(new Paragraph(balanceInDays.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.Colspan             = 2;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("    ", font));
                _PdfPCell.BorderWidthTop    = 0.5f;
                _PdfPCell.BorderWidthBottom = 0f;
                _PdfPCell.BorderWidthLeft   = 0.5f;
                _PdfPCell.BorderWidthRight  = 0.5f;
                _PdfPCell.Colspan           = 5;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Invoice Balance (IF Paid after " + _TPaymentTerms.DiscountIfPaidInDays.ToString() + " Days)", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.Colspan             = 3;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph((_TInvoice.InvoiceAmount - _TInvoice.PaiedAmount).ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.Colspan             = 2;
                _PdfPTable.AddCell(_PdfPCell);

                document.Add(_PdfPTable);


                _PdfPTable            = new PdfPTable(1);
                _PdfPCell             = new PdfPCell(new Paragraph("    ", new Font(Font.FontFamily.UNDEFINED, 1)));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                fontBold.Size               = 7;
                _PdfPCell                   = new PdfPCell(new Paragraph("                                                                                                                  PLEASE DETACH AND RETURN TOP PORTION WITH YOUR PAYMENT", fontBold));
                _PdfPCell.BorderWidthTop    = 0.5f;
                _PdfPCell.BorderWidthLeft   = 0.0f;
                _PdfPCell.BorderWidthRight  = 0.0f;
                _PdfPCell.BorderWidthBottom = 0.0f;
                _PdfPCell.BorderColorTop    = new BaseColor(System.Drawing.Color.SteelBlue);
                _PdfPTable.AddCell(_PdfPCell);

                document.Add(_PdfPTable);



                fontBold.Size         = this.PrintInvoiceSize;
                _PdfPTable            = new PdfPTable(1);
                _PdfPCell             = new PdfPCell(new Paragraph("    ", font));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                _Phrase = new Phrase();
                _Phrase.Add(new Paragraph("Ship to Address:\r\n", fontBold));
                _Phrase.Add(new Paragraph(
                                _TAddressShipTo.FirstName + " " + _TAddressShipTo.LastName + "\r\n" +
                                _TAddressShipTo.Address1 + "\r\n" +
                                _TAddressShipTo.City + ", " + _TAddressShipTo.StateCode + ", " + _TAddressShipTo.PostalCode
                                , font));
                _PdfPCell             = new PdfPCell(_Phrase);
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell             = new PdfPCell(new Paragraph("    ", font));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                document.Add(_PdfPTable);


                #endregion

                #region Print Order Line Item and Order Total

                _PdfPTable = new PdfPTable(new float[] { 10f, 25f, 9f, 28f, 20f, 15f, 21f, 18f, 17f, 20f });

                _PdfPCell             = new PdfPCell(new Paragraph("", fontBold));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPCell.Colspan     = 3;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Customer Account", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Sales Rep", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Order #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Invoice #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Invoice Date", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("PO #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Terms", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell             = new PdfPCell(new Paragraph("", fontBold));
                _PdfPCell.Colspan     = 3;
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TCustomer.AltCustNum, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TUser.FirstName + " " + _TUser.LastName, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TOrder.AltOrderNum, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.InvoiceId.ToString(), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.InvoiceDate.Year == 1 ? "" : _TInvoice.InvoiceDate.ToString("MM/dd/yy"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TOrder.PONumber, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TPaymentTerms.Description, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Line #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Stock Number", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Description", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.Colspan             = 3;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Qty", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Standard Price", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Discount", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Sale Price", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Total Cost", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                StringBuilder sb = new StringBuilder();

                int index = 0;
                int count = oliList.Count;

                font.Size = this.PrintInvoiceSize;

                foreach (TInvoice_Line_Item oliItem in oliList)
                {
                    _PdfPCell = new PdfPCell(new Paragraph((++index).ToString(), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                    _PdfPCell.BorderWidthLeft     = 0.5f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.PartNumber, font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.ProductName, font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPCell.Colspan             = 3;
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.Quantity.ToString(), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.StandardPrice.ToString("c"), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.DiscountAmount.ToString("c"), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.WholeSalePrice.ToString("c"), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.TotalCost.ToString("c"), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);
                }


                //font.Size = 7;
                _Phrase = new Phrase();
                _Phrase.Add(new Phrase("\r\n\r\nA 1.5% interest will be assessed on all unpaid balances 60 days past due.", font7));
                _Phrase.Add(new Phrase("\r\n\r\nFor billing or order inquiries, please call : 888-301-7878", font7));
                _Phrase.Add(new Phrase("\r\n\r\nThank you for your business!\r\n", font7));

                _PdfPCell             = new PdfPCell(_Phrase);
                _PdfPCell.Colspan     = 6;
                _PdfPCell.Rowspan     = 5;
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);


                font.Size = this.PrintInvoiceSize;
                _PdfPCell = new PdfPCell(new Paragraph("Sub Total", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.Subtotal.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Tax", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.Colspan             = 3;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.Tax.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Shipping", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.Shipping.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);



                //font = new Font(Font.FontFamily.UNDEFINED, 9, Font.BOLD);
                _PdfPCell = new PdfPCell(new Paragraph("Invoice Total", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.InvoiceAmount.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                //font = new Font(Font.FontFamily.UNDEFINED, 9);
                _PdfPCell = new PdfPCell(new Paragraph("Payment Applies/Credit memo", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.PaiedAmount.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell             = new PdfPCell(_Image);
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPCell.Colspan     = 6;
                _PdfPCell.Rowspan     = 3;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Invoice Balance (If Paid within " + _TPaymentTerms.DiscountIfPaidInDays.ToString() + " Days)", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(balanceInDays.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Invoice Balance (IF Paid after " + _TPaymentTerms.DiscountIfPaidInDays.ToString() + " Days)", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph((_TInvoice.InvoiceAmount - _TInvoice.PaiedAmount).ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell             = new PdfPCell(new Paragraph("    ", font));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPCell.Colspan     = 4;
                _PdfPTable.AddCell(_PdfPCell);


                document.Add(_PdfPTable);

                #endregion
                document.Close();
            }
            catch (DocumentException ex)
            {
                _result            = new ReturnValue();
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();


                return(_result);
            }



            try
            {
                byte[] bytes    = m.GetBuffer();
                string filename = "Invoice/TFInvoice_" + invoiceId.ToString() + ".pdf";
                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    fs.Write(bytes, 0, bytes.Length);
                }
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }



            return(_result);
        }
Example #28
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     // Get newly selected address.
     selectedAddress = (TAddress)comboBox1.SelectedItem;
 }
Example #29
0
        private ReturnValue createZOrder(ShipStationResponseOrder order)
        {
            ReturnValue _result = new ReturnValue();

            int _sourceId = int.Parse(ConfigurationSettings.AppSettings["SourceId"]);
            int programID = int.Parse(order.advancedOptions.customField1);


            TOrder _tOrder = new TOrder();

            #region get OrderTypeId

            if (string.IsNullOrWhiteSpace(order.advancedOptions.customField3) == true)
            {
                _result.ErrMessage = string.Format("OrderType({0}) is empty. ", order.advancedOptions.customField3);
                _result.Success    = false;
                return(_result);
            }

            var itemType = Types.Find(s => s.Code.Equals(order.advancedOptions.customField3, StringComparison.OrdinalIgnoreCase));
            if (itemType == null)
            {
                if (Common.AutoCreateProduct == true)
                {
                    TType _tType = new TType();
                    _tType.Code            = order.advancedOptions.customField3;
                    _tType.ContentStatusId = 1;
                    _tType.Description     = order.advancedOptions.customField3;
                    _tType.GroupBy         = "ORDER";
                    _tType.CreatedOn       = System.DateTime.Now;
                    _result = _tType.Save();

                    _tType.TypeId = _result.IdentityId;
                    itemType      = _tType;

                    Types.Add(_tType);
                }
                else
                {
                    _result.ErrMessage = string.Format("OrderType({0}) can not be found. ", order.advancedOptions.customField3);
                    _result.Success    = false;
                    return(_result);
                }
            }

            _tOrder.OrderTypeId = itemType.TypeId;

            #endregion

            #region get ShipMethod

            if (string.IsNullOrWhiteSpace(order.advancedOptions.customField2) == true)
            {
                _result.ErrMessage = string.Format("ShipMethod({0}) is empty. ", order.advancedOptions.customField2);
                _result.Success    = false;
                return(_result);
            }

            var method = ShipMethods.Find(s => s.Code.Equals(order.advancedOptions.customField2, StringComparison.OrdinalIgnoreCase));
            if (method == null)
            {
                _result.ErrMessage = string.Format("ShipMethod({0}) can not be found. ", order.advancedOptions.customField2);
                _result.Success    = false;
                return(_result);
            }

            int shipMethodId = method.ShipMethodId;

            #endregion

            #region Address

            if (order.shipTo.phone != null)
            {
                order.shipTo.phone = order.shipTo.phone.Replace("+", "");
                if (order.shipTo.phone.Length > 13)
                {
                    order.shipTo.phone = "0000000000";
                }
            }
            if (string.IsNullOrWhiteSpace(order.shipTo.state) && order.shipTo.country != "US" && order.shipTo.country != "CA")
            {
                order.shipTo.state = "XX";
            }

            var address = new TAddress();

            var country = Countrys.Find(c => c.ISO2.Equals(order.shipTo.country, StringComparison.OrdinalIgnoreCase));
            if (country == null)
            {
                _result.ErrMessage = string.Format("Country({0}) can not be found. ", order.shipTo.country);
                _result.Success    = false;
                return(_result);
            }
            address.CountryId = country.CountryId;

            var state = States.Find(c => c.Code.Equals(order.shipTo.state, StringComparison.OrdinalIgnoreCase));
            if (state == null && order.shipTo.country != "US" && order.shipTo.country != "CA")
            {
                order.shipTo.state = "XX";
                state = States.Find(c => c.Code.Equals(order.shipTo.state, StringComparison.OrdinalIgnoreCase));
            }

            if (state == null)
            {
                _result.ErrMessage = string.Format("State({0}) can not be found. ", order.shipTo.state);
                _result.Success    = false;
                return(_result);
            }
            address.StateId = state.StateId;



            address.Address1 = order.shipTo.street1;
            address.Address2 = order.shipTo.street2;
            address.Address3 = order.shipTo.street3;
            if (address.Address1 == null)
            {
                address.Address1 = "";
            }
            if (address.Address2 == null)
            {
                address.Address2 = "";
            }
            if (address.Address3 == null)
            {
                address.Address3 = "";
            }

            if (address.Address1.Length > 35 || address.Address2.Length > 35 || address.Address3.Length > 35)
            {
                var temp = address.Address1 + " " + address.Address2 + " " + address.Address3;
                address.Address1 = temp.Substring(0, 35);
                temp             = temp.Substring(35);
                if (temp.Length > 35)
                {
                    address.Address2 = temp.Substring(0, 35);
                    temp             = temp.Substring(35);
                }
                else
                {
                    address.Address2 = temp;
                    temp             = "";
                }
                if (temp.Length > 35)
                {
                    address.Address3 = temp.Substring(0, 35);
                }
                else
                {
                    address.Address3 = temp;
                }
            }

            address.City       = order.shipTo.city;
            address.PostalCode = order.shipTo.postalCode;
            address.UpdatedOn  = DateTime.Now;
            address.ProgramId  = programID;

            _tOrder.Address = address;


            #endregion

            #region Customer

            var customer = new TCustomer();
            customer.SourceId  = _sourceId;
            customer.ProgramId = programID;
            customer.FirstName = order.shipTo.fname;
            customer.LastName  = order.shipTo.lname;
            customer.Email     = order.customerEmail;
            customer.Company   = order.shipTo.company;
            customer.CreatedOn = System.DateTime.Now;

            if (programID == 463)
            {
                customer.AltCustNum = "ONL" + order.orderNumber.ToString();
            }

            _tOrder.Customer = customer;

            #endregion

            #region Item Line

            #region   skip the SKU when importing if the SKU=’’ and fulfillmentsku=null and name like ‘coupon%’

            var query = order.items.Where(u =>
                                          (!string.IsNullOrEmpty(u.sku) || !string.IsNullOrEmpty(u.fulfillmentSku) || !u.name.ToLower().StartsWith("coupon"))
                                          );

            order.items = query.ToList <ShipStationResponseItem>();

            foreach (ShipStationResponseItem sitem in order.items)
            {
                if (sitem.sku == "" && string.IsNullOrEmpty(sitem.fulfillmentSku) && sitem.name.ToLower().IndexOf("coupon") == 0)
                {
                    order.items.Remove(sitem);
                }
            }

            #endregion


            var lineNum = 1;

            foreach (var lineItem in order.items)
            {
                var sku = string.IsNullOrEmpty(lineItem.fulfillmentSku) ? lineItem.sku : lineItem.fulfillmentSku;
                if (string.IsNullOrWhiteSpace(sku) == true)
                {
                    _result.ErrMessage = string.Format("SKU({0}) is empty.", sku);
                    _result.Success    = false;
                    return(_result);
                }



                var productItem = Products.Find(s => s.PartNumber != null && s.PartNumber.Equals(sku, StringComparison.OrdinalIgnoreCase) && s.ProgramId == programID);
                if (productItem == null)
                {
                    if (Common.AutoCreateProduct == true)
                    {
                        TProduct _tProduct = new TProduct();
                        _tProduct.PartNumber = sku;
                        _tProduct.Name       = lineItem.name;
                        _tProduct.ProgramID  = programID;

                        _result             = _tProduct.Save();
                        _tProduct.ProductId = _result.IdentityId;

                        TProgram_Product _tProgram_Product = new TProgram_Product();
                        _tProgram_Product.PartNumber      = sku;
                        _tProgram_Product.Name            = sku;
                        _tProgram_Product.ProgramId       = programID;
                        _tProgram_Product.ContentStatusId = 1;
                        _tProgram_Product.ProductId       = _tProduct.ProductId;

                        _result = _tProgram_Product.Save();

                        _tProgram_Product.ProgramProductId = _result.IdentityId;
                        productItem = _tProgram_Product;

                        Products.Add(_tProgram_Product);
                    }
                    else
                    {
                        _result.ErrMessage = string.Format("SKU({0}) can not be found. ", sku);
                        _result.Success    = false;
                        return(_result);
                    }
                }

                TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
                _tOrder_Line_Item.ProgramProductId  = productItem.ProgramProductId;
                _tOrder_Line_Item.PartNumber        = productItem.PartNumber;
                _tOrder_Line_Item.ProductName       = lineItem.name;
                _tOrder_Line_Item.Quantity          = lineItem.quantity;
                _tOrder_Line_Item.Price             = Convert.ToDouble(lineItem.unitPrice);
                _tOrder_Line_Item.ActualPrice       = _tOrder_Line_Item.Quantity * _tOrder_Line_Item.Price;
                _tOrder_Line_Item.OrderLineItemDate = lineItem.createDate;

                _tOrder_Line_Item.ShipToCustomerId = _tOrder.CustomerId;
                _tOrder_Line_Item.ShipToAddressId  = _tOrder.CustomerAddressId;
                _tOrder_Line_Item.ShipMethodId     = shipMethodId;
                _tOrder_Line_Item.LineNum          = lineNum;
                lineNum++;

                _tOrder.OrderLines.Add(_tOrder_Line_Item);
            }



            #endregion

            #region Order level

            _tOrder.AltOrderNum        = order.orderNumber.ToString();
            _tOrder.OrderDate          = order.orderDate;
            _tOrder.TotalOrderAmount   = Convert.ToDouble(order.orderTotal);
            _tOrder.TotalTax           = Convert.ToDouble(order.taxAmount);
            _tOrder.TotalShipping      = Convert.ToDouble(order.shippingAmount);
            _tOrder.TotalProductAmount = Convert.ToDouble(order.orderTotal - order.taxAmount - order.shippingAmount);
            _tOrder.ProgramId          = programID;
            _tOrder.SourceId           = _sourceId;
            _tOrder.StatusCode         = "AS";

            #endregion

            _result.Object = _tOrder;

            return(_result);
        }