Esempio n. 1
0
        //[OperationBehavior(TransactionScopeRequired=true,TransactionAutoComplete=true)]
        public bool UpdateTemplate(ShipScheduleTemplate template)
        {
            //
            bool updated = false;

            if (template != null)
            {
                SqlConnection sqlConn = null;
                try {
                    sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings[SQL_CONNID].ConnectionString);
                    sqlConn.Open();
                    using (SqlTransaction sqlTrans = sqlConn.BeginTransaction()) {
                        try {
                            //Trip
                            object[] trip = new object[] { template.TemplateID, template.DayOfTheWeek, template.CarrierServiceID, template.ScheduledCloseDateOffset,
                                                           template.ScheduledCloseTime, template.ScheduledDepartureDateOffset, template.ScheduledDepartureTime,
                                                           template.IsMandatory, template.IsActive, DateTime.Now, template.TemplateUser, template.TemplateRowVersion };
                            executeNonQuery(sqlTrans, USP_TEMPLATES_UPDATE, trip);

                            //Stop 1
                            object[] stop1 = new object[] { template.StopID, template.AgentTerminalID, template.Tag, template.Notes, template.ScheduledArrivalDateOffset,
                                                            template.ScheduledArrivalTime, template.ScheduledOFD1Offset, DateTime.Now, template.Stop1User, template.Stop1RowVersion };
                            executeNonQuery(sqlTrans, USP_TEMPLATESSTOP_UPDATE, stop1);

                            //Stop 2
                            if (template.S2MainZone != null && template.S2MainZone.Trim().Length > 0)
                            {
                                //New or update?
                                if (template.S2StopID.Trim().Length == 0)
                                {
                                    object[] stop2 = new object[] { null, template.TemplateID, template.S2StopNumber, template.S2AgentTerminalID, template.S2Tag, template.S2Notes,
                                                                    template.S2ScheduledArrivalDateOffset, template.S2ScheduledArrivalTime, template.S2ScheduledOFD1Offset, DateTime.Now, template.Stop2User, null };
                                    executeNonQuery(sqlTrans, USP_TEMPLATESSTOP_NEW, stop2);
                                }
                                else
                                {
                                    object[] stop2 = new object[] { template.S2StopID, template.S2AgentTerminalID, template.S2Tag, template.S2Notes, template.S2ScheduledArrivalDateOffset,
                                                                    template.S2ScheduledArrivalTime, template.S2ScheduledOFD1Offset, DateTime.Now, template.Stop2User, template.Stop2RowVersion };
                                    executeNonQuery(sqlTrans, USP_TEMPLATESSTOP_UPDATE, stop2);
                                }
                            }
                            sqlTrans.Commit();
                            updated = true;
                        }
                        catch (Exception ex) {
                            sqlTrans.Rollback();
                            //System.Transactions.Transaction.Current.Rollback(ex);
                            throw new FaultException <ShipScheduleFault>(new ShipScheduleFault(ex.ToString()), new FaultReason("Unexpected error updating ship schedule template: " + ex.Message));
                        }
                    }
                }
                finally { if (sqlConn != null)
                          {
                              sqlConn.Dispose();
                          }
                }
            }
            return(updated);
        }
Esempio n. 2
0
        public bool UpdateTemplate(ShipScheduleTemplate template)
        {
            //
            bool updated = false;

            try {
                //Apply simple business rules
                if (template == null)
                {
                    return(false);
                }

                //Create the TransactionScope to execute the commands, guaranteeing that both commands can commit or roll back as a single unit of work
                using (TransactionScope scope = new TransactionScope()) {
                    //Trip
                    new ShipScheduleTemplatesGateway().UpdateShipScheduleTemplate(template);

                    //Stop 1
                    new ShipScheduleTemplatesGateway().UpdateShipScheduleTemplateStop(template.StopID, template.AgentTerminalID, template.Tag,
                                                                                      template.Notes, template.ScheduledArrivalDateOffset,
                                                                                      template.ScheduledArrivalTime, template.ScheduledOFD1Offset,
                                                                                      DateTime.Now, template.Stop1User, template.Stop1RowVersion);

                    //Stop 2
                    if (template.S2MainZone != null && template.S2MainZone.Trim().Length > 0)
                    {
                        //New or update?
                        if (template.S2StopID.Trim().Length == 0)
                        {
                            new ShipScheduleTemplatesGateway().CreateShipScheduleTemplateStop(template.TemplateID, template.S2StopNumber, template.S2AgentTerminalID,
                                                                                              template.S2Tag, template.S2Notes, template.S2ScheduledArrivalDateOffset,
                                                                                              template.S2ScheduledArrivalTime, template.S2ScheduledOFD1Offset,
                                                                                              DateTime.Now, template.Stop2User);
                        }
                        else
                        {
                            new ShipScheduleTemplatesGateway().UpdateShipScheduleTemplateStop(template.S2StopID, template.S2AgentTerminalID, template.S2Tag, template.S2Notes,
                                                                                              template.S2ScheduledArrivalDateOffset, template.S2ScheduledArrivalTime,
                                                                                              template.S2ScheduledOFD1Offset, DateTime.Now, template.Stop2User, template.Stop2RowVersion);
                        }
                    }
                    updated = true;

                    //Commits the transaction; if an exception is thrown, Complete is not called and the transaction is rolled back
                    scope.Complete();
                }
            }
            catch (Exception ex) { throw new FaultException <ShipScheduleFault>(new ShipScheduleFault(ex.Message), "Service Error"); }
            return(updated);
        }
Esempio n. 3
0
        public bool UpdateShipScheduleTemplate(ShipScheduleTemplate template)
        {
            //
            bool updated = false;

            try {
                updated = new DataService().ExecuteNonQuery(SQL_CONNID, USP_TEMPLATES_UPDATE,
                                                            new object[] { template.TemplateID, template.DayOfTheWeek, template.CarrierServiceID, template.ScheduledCloseDateOffset,
                                                                           template.ScheduledCloseTime, template.ScheduledDepartureDateOffset, template.ScheduledDepartureTime,
                                                                           template.IsMandatory, template.IsActive, DateTime.Now, template.TemplateUser, template.TemplateRowVersion });
            }
            catch (Exception ex) { throw new ApplicationException(ex.Message, ex); }
            return(updated);
        }
Esempio n. 4
0
        public string CreateShipScheduleTemplate(ShipScheduleTemplate template)
        {
            //
            string templateID = "";

            try {
                //Trip
                templateID = (string)new DataService().ExecuteNonQueryWithReturn(SQL_CONNID, USP_TEMPLATES_NEW,
                                                                                 new object[] { null, template.SortCenterID, template.DayOfTheWeek, template.CarrierServiceID, template.ScheduledCloseDateOffset,
                                                                                                template.ScheduledCloseTime, template.ScheduledDepartureDateOffset, template.ScheduledDepartureTime,
                                                                                                template.IsMandatory, template.IsActive, DateTime.Now, template.TemplateUser, null });
            }
            catch (Exception ex) { throw new ApplicationException(ex.Message, ex); }
            return(templateID);
        }
Esempio n. 5
0
        public static bool UpdateTemplate(ShipScheduleTemplate template)
        {
            //
            bool ret = false;

            try {
                _Client = new ShipScheduleServiceClient();
                ret     = _Client.UpdateTemplate(template);
                _Client.Close();
            }
            catch (TimeoutException te) { _Client.Abort(); throw new ApplicationException(te.Message, te.InnerException); }
            catch (FaultException <ShipScheduleFault> ssf) { throw new ApplicationException(ssf.Reason.ToString(), ssf.InnerException); }
            catch (FaultException fe) { throw new ApplicationException(fe.Message, fe.InnerException); }
            catch (CommunicationException ce) { _Client.Abort(); throw new ApplicationException(ce.Message, ce.InnerException); }
            return(ret);
        }
        public static bool UpdateTemplate(ShipScheduleTemplate template)
        {
            //
            bool ret = false;
            ShipScheduleTemplatesServiceClient client = new ShipScheduleTemplatesServiceClient();

            try {
                ret = client.UpdateTemplate(template);
                client.Close();
            }
            catch (TimeoutException te) { client.Abort(); throw new ApplicationException(te.Message, te.InnerException); }
            catch (FaultException <ShipScheduleFault> ssf) { client.Abort(); throw new ApplicationException(ssf.Detail.Message); }
            catch (FaultException fe) { client.Abort(); throw new ApplicationException(fe.Message); }
            catch (CommunicationException ce) { client.Abort(); throw new ApplicationException(ce.Message); }
            return(ret);
        }
        public static string AddTemplate(ShipScheduleTemplate template)
        {
            //
            string templateID = "";
            ShipScheduleTemplatesServiceClient client = new ShipScheduleTemplatesServiceClient();

            try {
                templateID = client.AddTemplate(template);
                client.Close();
            }
            catch (TimeoutException te) { client.Abort(); throw new ApplicationException(te.Message, te.InnerException); }
            catch (FaultException <ShipScheduleFault> ssf) { client.Abort(); throw new ApplicationException(ssf.Detail.Message); }
            catch (FaultException fe) { client.Abort(); throw new ApplicationException(fe.Message); }
            catch (CommunicationException ce) { client.Abort(); throw new ApplicationException(ce.Message); }
            return(templateID);
        }
Esempio n. 8
0
        //[OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=true)]
        public string AddTemplate(ShipScheduleTemplate template)
        {
            //
            string templateID = "";

            if (template != null)
            {
                SqlConnection sqlConn = null;
                try {
                    sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings[SQL_CONNID].ConnectionString);
                    sqlConn.Open();
                    using (SqlTransaction sqlTrans = sqlConn.BeginTransaction()) {
                        try {
                            //Trip
                            object[] trip = new object[] { null, template.SortCenterID, template.DayOfTheWeek, template.CarrierServiceID, template.ScheduledCloseDateOffset,
                                                           template.ScheduledCloseTime, template.ScheduledDepartureDateOffset, template.ScheduledDepartureTime,
                                                           template.IsMandatory, template.IsActive, DateTime.Now, template.TemplateUser, null };
                            templateID = (string)executeNonQueryWithReturn(sqlTrans, USP_TEMPLATES_NEW, trip);

                            //Stop 1
                            object[] stop1 = new object[] { null, templateID, template.StopNumber, template.AgentTerminalID, template.Tag, template.Notes,
                                                            template.ScheduledArrivalDateOffset, template.ScheduledArrivalTime, template.ScheduledOFD1Offset, DateTime.Now, template.Stop1User, null };
                            executeNonQuery(sqlTrans, USP_TEMPLATESSTOP_NEW, stop1);

                            //Stop 2
                            if (template.S2MainZone.Trim().Length > 0)
                            {
                                object[] stop2 = new object[] { null, templateID, template.S2StopNumber, template.S2AgentTerminalID, template.S2Tag, template.S2Notes,
                                                                template.S2ScheduledArrivalDateOffset, template.S2ScheduledArrivalTime, template.S2ScheduledOFD1Offset, DateTime.Now, template.Stop2User, null };
                                executeNonQuery(sqlTrans, USP_TEMPLATESSTOP_NEW, stop2);
                            }
                            sqlTrans.Commit();
                        }
                        catch (Exception ex) {
                            sqlTrans.Rollback();
                            throw new FaultException <ShipScheduleFault>(new ShipScheduleFault(ex.ToString()), new FaultReason("Unexpected error adding ship schedule template: " + ex.Message));
                        }
                    }
                }
                finally { if (sqlConn != null)
                          {
                              sqlConn.Dispose();
                          }
                }
            }
            return(templateID);
        }