/// <summary>
 /// Emails the user a shipment update containing all the information about their shipment.
 /// </summary>
 /// <param name="order">The order.</param>
 /// <param name="args">Dictionary containing the shipmentId.</param>
 /// <returns>{error:0,desc:"error description"}.</returns>
 public static Dictionary<string, object> ShipmentUpdateEmail(Commerce.Order order, ShipmentUpdateArgs args)
 {
     CreateEmailEventArgs emailArgs =
         new CreateEmailEventArgs("shipmentUpdate", Main.Site.site_operator_email, order.User.Email,
         Main.Site.site_log_email, order.User, null, order, null, "", args);
     DefaultEmails.ShipConfirm(ref emailArgs);
     Main.Site.raiseOnCreateEmail(emailArgs);
     Dictionary<string, object> f;
     using(SqlConnection cn = Site.CreateConnection(true, true)) {
         cn.Open();
         f = SendEmailArgResult(emailArgs, cn, null);
     }
     return f;
 }
Exemple #2
0
 /// <summary>
 /// Raises the onshipmentupdate event.
 /// </summary>
 /// <param name="args">The args.</param>
 internal void raiseOnShipmentUpdate( ShipmentUpdateArgs args )
 {
     if( ShipmentUpdated != null ) { ShipmentUpdated( this, args ); };
 }
Exemple #3
0
 /// <summary>
 /// Event handler for shipmentUpdateQueue
 /// </summary>
 private static void emptyShipmentQueue(object sender, EventArgs e)
 {
     SqlTransaction trans = null;
     SqlConnection cn = null;
     List<Guid> completeUpdates = new List<Guid>();
     try {
         cn = Site.CreateConnection(true, true);/* mars on */
         cn.Open();
         trans = cn.BeginTransaction(IsolationLevel.ReadUncommitted, "shipment_update_transaction");
         bool hasRows = false;
         using(SqlCommand cmd = new SqlCommand(@"/* shipment queue check */
             f", cn, trans)) {
             using(SqlDataReader r = cmd.ExecuteReader()) {
                 if(r.HasRows) {
                     hasRows = true;
                 }
             }
         }
         if(hasRows) {
             /* check for shipment to be raised */
             using(SqlCommand cmd = new SqlCommand(@"select addressUpdateId, shipmentNumber, tracking, dateShipped,
             actualWeight, actualService, actualCost, actualBilledWeight, packageLength, packageWidth,
             packageHeight, thirdPartyAccount, voidStatus, emailSent, addDate, VerCol
             from addressUpdate with (nolock) where emailSent is null and not shipmentNumber is null
             and LEN(shipmentNumber) > 0;", cn, trans)) {
                 using(SqlDataReader r = cmd.ExecuteReader()) {
                     if(r.HasRows) {
                         while(r.Read()) {
                             try {
                                 /* HACK: TEMPORARY: THIS IS NOT THE SHIPMENT NUMBER AS IT APPEARS TO BE IN DBO.ADDRESSUPDATE
                                  * This is a TEMPORARY fix for out of sequence shipment numbers
                                  * they are natually out of sequence but a few tools at www.claydesign.com
                                  * were written expecting them to be IN sequence incorrectly
                                  * once they fell out of sequence it was nessessary to create this patch
                                  * further patching will be in the order editor
                                  * */
                                 string orderNumber = r.GetValue(1).ToString();
                                 string trackingNumber = r.GetValue(2).ToString();
                                 Guid addressUpdateId = r.GetGuid(0);
                                 Commerce.Order order = Commerce.Order.GetOrderByOrderNumber(orderNumber, cn, trans);
                                 if(order != null) {
                                     /* THIS IS NOT THE SHIPMENT NUMBER */
                                     ShipmentUpdateArgs args = new ShipmentUpdateArgs(order, addressUpdateId,
                                     order.Shipments[0].ShipmentNumber, trackingNumber, r.GetValue(3).ToString(), r.GetValue(4).ToString(),
                                     r.GetValue(5).ToString(), r.GetValue(6).ToString(), r.GetValue(7).ToString(), r.GetValue(8).ToString(),
                                     r.GetValue(9).ToString(), r.GetValue(10).ToString(), r.GetValue(11).ToString(),
                                     r.GetValue(12).ToString(), r.GetValue(13).ToString());
                                     /* change the status of the order to shipped ? wasn't this done elsewhere?
                                      * I hate it when I forget things, I should have made a note!
                                      * it appears that it _wasn't_ being done so... */
                                     Admin.AddFlag("11", "order", order.OrderId.ToString(), "Automatically added by shipping.");
                                     Site.raiseOnShipmentUpdate(args);
                                     if(!args.AbortDefaultEmail) {
                                         /* if they are retail or they have order.user.sendShipmentUpdates checked then send an email */
                                         if(order.User.SendShipmentUpdates || order.User.WholesaleDealer == false) {
                                             Commerce.ShipmentUpdateEmail(order, args);
                                         }
                                     }
                                 } else {
                                     ("ERROR: No order associated with shipment number:" + orderNumber +
                                     ", tracking:" + trackingNumber + ", PK:" + addressUpdateId.ToString()).Debug(1);
                                 }
                                 completeUpdates.Add(addressUpdateId);
                             } catch(Exception ex) {
                                 ("shipment queue exception error (Rendition.dll):" + ex.Message).Debug(1);
                             }
                         }
                     }
                     /* compile adhoc command */
                     StringBuilder b = new StringBuilder();
                     foreach(Guid id in completeUpdates) {
                         b.Append("update addressUpdate set emailSent = getDate() where addressUpdateId = '" + id.ToString() + "';");
                     }
                     if(b.Length > 0) {
                         using(SqlCommand innerCmd = new SqlCommand(b.ToString(), cn, trans)) {
                             innerCmd.ExecuteNonQuery();
                         }
                     }
                 }
             }
         }
         trans.Commit();
     } catch(Exception ex) {
         String.Format("emptyShipmentQueue Threw an exception ==>{0}", ex.Message).Debug(0);
         if(trans != null) {
             trans.Rollback();
         }
     } finally {
         if(cn != null) {
             cn.Close();
         }
         shipmentUpdateQueue.Start();
     }
 }