Ejemplo n.º 1
0
        public List <ForecastDateMethod> GetSavedForecastDateCollection(SqlString companyCode, SqlString customerNumber, long rowCount)
        {
            const string RDBConnectionKey = "PWCConnectionString";
            var          pf         = PersistenceFacade.GetInstance();
            var          connection = pf.GetDbConnection(RDBConnectionKey);
            var          command    = connection.CreateCommand();

            command.CommandText = "savedForecastDateCollection_sel";
            command.CommandType = CommandType.StoredProcedure;
            pf.AddCommandParameter(RDBConnectionKey, command, "company_code", companyCode);
            pf.AddCommandParameter(RDBConnectionKey, command, "customer_number", customerNumber);
            pf.AddCommandParameter(RDBConnectionKey, command, "row_count", rowCount);
            var savedForecastDateCollection = new List <ForecastDateMethod>
            {
                new ForecastDateMethod(string.Empty, string.Empty)
            };

            using (var dr = command.ExecuteReader(CommandBehavior.CloseConnection))
            {
                while (dr.Read())
                {
                    savedForecastDateCollection.Add(new ForecastDateMethod(string.Format("{0:MM/dd/yyyy}", dr["POSSalesEndDate"]), dr["ForecastMethod"].ToString()));
                }
            }
            return(savedForecastDateCollection);
        }
Ejemplo n.º 2
0
        public string GetDefaultSqlServerName()
        {
            var connection = PersistenceFacade.GetInstance().GetDbConnection("PWCConnectionString");

            using (connection)
            {
                return(connection.DataSource);
            }
        }
Ejemplo n.º 3
0
 private void dgvProductCategory_DataError(object sender, DataGridViewDataErrorEventArgs e)
 {
     if (e.Exception != null)
     {
         var additionalData = new StringBuilder("Context: ");
         additionalData.Append(e.Context.ToString()).Append("\n");
         additionalData.Append("RowIndex: ").Append(e.RowIndex.ToString()).Append("\n");
         additionalData.Append("ColumnIndex: ").Append(e.ColumnIndex.ToString());
         PersistenceFacade.GetInstance().LogException(e.Exception, Environment.MachineName, additionalData.ToString());
         e.ThrowException = true;
     }
 }
Ejemplo n.º 4
0
 public override void Load()
 {
     if (ParameterCollection != null)
     {
         PersistenceFacade.GetInstance().Get(this, Parent.ObjectKey, ParameterCollection);
     }
     else
     {
         PersistenceFacade.GetInstance().Get(this, Parent.ObjectKey);
     }
     LoadSetVersion();
 }
Ejemplo n.º 5
0
        private void dgvBrand_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            if (e.Exception == null)
            {
                return;
            }
            var additionalData = new StringBuilder("Context: ");

            additionalData.Append(e.Context.ToString()).Append("\n");
            additionalData.Append("RowIndex: ").Append(e.RowIndex.ToString(CultureInfo.InvariantCulture)).Append("\n");
            additionalData.Append("ColumnIndex: ").Append(e.ColumnIndex.ToString(CultureInfo.InvariantCulture));
            PersistenceFacade.GetInstance().LogException(e.Exception, Environment.MachineName, additionalData.ToString());
            e.ThrowException = true;
        }
Ejemplo n.º 6
0
        public void HandleException(Form form, Exception ex, EventArgs e)
        {
            string additionalData        = null;
            var    errorPhrase           = "Unexpected error occured.";
            var    isConcurrencyConflict = false;

            if (ex is SqlException)
            {
                isConcurrencyConflict = ex.Message == "Timestamp mismatched";

                additionalData = string.Format("Class: {0}, LineNumber: {1}, Number: {2}, Procedure: {3}, State: {4}", ((SqlException)ex).Class, ((SqlException)ex).LineNumber, ((SqlException)ex).Number, ((SqlException)ex).Procedure, ((SqlException)ex).State);
                errorPhrase    = "SQL operation error occured.";
            }
            if (isConcurrencyConflict)
            {
                MessageBox.Show("Your changes cannot be saved since your original data has been changed by another user.\n\n1. Please review the refreshed data\n2. Apply your changes\n3. Save again.", "PWC Forecast", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                PersistenceFacade.GetInstance().LogException(ex, Environment.MachineName, additionalData);
                MessageBox.Show(
                    string.Format(
                        "{0}\nThe error has been logged into database.\nPlease notify System Administrator.\n\n{1}",
                        errorPhrase, ex.Message), "PWC Forecast", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            form.Cursor = Cursors.Arrow;

            //if (e is DataGridViewCellCancelEventArgs)
            //    ((DataGridViewCellCancelEventArgs)e).Cancel = true;
            //else if (e is DataGridViewRowCancelEventArgs)
            //    ((DataGridViewRowCancelEventArgs)e).Cancel = true;
            //else if (e is DataGridViewCellValidatingEventArgs)
            //    ((DataGridViewCellValidatingEventArgs)e).Cancel = true;

            // all of the types above are derived from CancelEventArgs, so no need to check individually
            if (e is CancelEventArgs)
            {
                ((CancelEventArgs)e).Cancel = true;
            }
            else if (e is DataGridViewCellParsingEventArgs)
            {
                ((DataGridViewCellParsingEventArgs)e).ParsingApplied = false;
            }
            else if (e is DataGridViewCellFormattingEventArgs)
            {
                ((DataGridViewCellFormattingEventArgs)e).FormattingApplied = false;
            }
        }
Ejemplo n.º 7
0
        public bool DoesForecastSalesRateExist(SqlString companyCode, SqlString customerNumber, SqlDateTime posWeekEndDateEnd)
        {
            const string RDBConnectionKey = "PWCConnectionString";
            var          pf         = PersistenceFacade.GetInstance();
            var          connection = pf.GetDbConnection(RDBConnectionKey);

            using (connection)
            {
                var command = connection.CreateCommand();
                command.CommandText = "doesForecastSalesRateExist_sel";
                command.CommandType = CommandType.StoredProcedure;
                pf.AddCommandParameter(RDBConnectionKey, command, "company_code", companyCode);
                pf.AddCommandParameter(RDBConnectionKey, command, "customer_number", customerNumber);
                pf.AddCommandParameter(RDBConnectionKey, command, "pos_sales_end_date", posWeekEndDateEnd);
                return((int)command.ExecuteScalar() == 1);
            }
        }
Ejemplo n.º 8
0
 public override void Commit(APersistenceObject persistenceObject)
 {
     PersistenceFacade.GetInstance().Delete(persistenceObject);
     persistenceObject.PreviousState = this;
     persistenceObject.State         = DeletedState.GetInstance();
 }
Ejemplo n.º 9
0
        public void Commit()
        {
            if (_transactionObjectCollection.Count == 0)
            {
                return;
            }

            if (IsDistributedTransaction)
            {
                using (var ts = new TransactionScope(TransactionScopeOption.Required))
                {
                    try
                    {
                        _transactionObjectCollection.Sort(new ComparerExecutionSequence());
                        foreach (var obj in _transactionObjectCollection)
                        {
                            obj.IsDelayedCommit = false;
                            obj.Commit();
                        }
                        ts.Complete();
                        _isCommitted = true;
                    }
                    catch (Exception)
                    {
                        foreach (var obj in _transactionObjectCollection)
                        {
                            obj.IsDelayedCommit = false;
                            obj.Refresh();
                        }
                        throw;
                    }
                    finally
                    {
                        ClearEnlistedObjects();
                    }
                }
            }
            else
            {
                try
                {
                    var pf = PersistenceFacade.GetInstance();
                    _localDbTransaction = pf.BeginLocalDbTransaction(_localRdbConnectionKey);
                    _transactionObjectCollection.Sort(new ComparerExecutionSequence());
                    foreach (var obj in _transactionObjectCollection)
                    {
                        obj.IsDelayedCommit = false;
                        obj.Commit();
                    }
                    pf.CommitLocalDbTransacstion(_localRdbConnectionKey);
                    _isCommitted = true;
                }
                catch (Exception)
                {
                    if (_localDbTransaction != null)
                    {
                        _localDbTransaction.Rollback();
                    }
                    foreach (var obj in _transactionObjectCollection)
                    {
                        obj.Refresh();
                    }
                    throw;
                }
                finally
                {
                    ClearEnlistedObjects();
                }
            }
        }
Ejemplo n.º 10
0
 public override void Commit(APersistenceObject persistenceObject)
 {
     PersistenceFacade.GetInstance().Insert(persistenceObject);
     persistenceObject.PreviousState = this;
     persistenceObject.State         = OldCleanState.GetInstance();
 }
Ejemplo n.º 11
0
 public virtual void Load()
 {
     PersistenceFacade.GetInstance().Get(this, ParameterCollection);
     LoadSetVersion();
 }
Ejemplo n.º 12
0
 public virtual void LoadFromObject(object sourceObject)
 {
     PersistenceFacade.GetInstance().GetFromObject(this, sourceObject);
     MarkNew();
 }
Ejemplo n.º 13
0
 public virtual void Load(ObjectMapperType objectMapperType)
 {
     PersistenceFacade.GetInstance().Get(this, objectMapperType);
     MarkOldClean();
 }
Ejemplo n.º 14
0
 public virtual void Load()
 {
     PersistenceFacade.GetInstance().Get(this);
     MarkOldClean();
 }