Example #1
0
 public void GetPromotionDiscount(ShoppingCartInfo cartInfo)
 {
     SqlParameter[] sqlParam = new SqlParameter[] { new SqlParameter("@promotion_code", SqlDbType.NVarChar, 20) };
     sqlParam[0].Value = cartInfo.PromotionCode;
     using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONNECTION_STRING,
                                                           CommandType.StoredProcedure, SQLHelper.GetSQLStatement("ShoppingCart", "SP_GET_PROMOTIONDISCOUNT"),
                                                           sqlParam))
     {
         while (reader.Read())
         {
             cartInfo.Discount = Convert.ToDecimal(reader["percentage"]);
         }
     }
 }
Example #2
0
        /// <summary>
        /// Get the list of orders for the specified user.
        /// </summary>
        /// <param name="userId">Internal identifier of the user.</param>
        /// <returns>List of orders for the specified user.</returns>
        public List <InventoryItemReportInfo> GetSearchInventory(int userId, DateTime startDate, DateTime endDate)
        {
            List <InventoryItemReportInfo> items         = new List <InventoryItemReportInfo>();
            InventoryItemReportInfo        inventoryInfo = new InventoryItemReportInfo();


            SqlParameter[] parameters = SQLHelper.GetCachedParameters("SQL_GET_SEARCH_INVENTORY");

            if (parameters == null)
            {
                parameters = new SqlParameter[] {
                    new SqlParameter("@UserId", SqlDbType.Int)
                };

                SQLHelper.CacheParameters("SQL_GET_SEARCH_INVENTORY", parameters);
            }

            parameters[0].Value = userId;
            string sql = SQLHelper.GetSQLStatement(MODULE_NAME, "SQL_GET_INVETORY");

            if (startDate != DateTime.MinValue)
            {
                sql += " AND convert(datetime,order_date) >= '" + startDate.ToString() + "'";
            }
            if (endDate != DateTime.MinValue)
            {
                sql += " AND convert(datetime,order_date) <= '" + endDate.AddDays(1).ToString() + "'";
            }
            sql += " order by order_date";
            int sumQuantityPK = 0;

            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONNECTION_STRING,
                                                                  CommandType.Text, sql, parameters))
            {
                while (reader.Read())
                {
                    if (reader["quantity"] != DBNull.Value)
                    {
                        bool isExists = false;
                        foreach (InventoryItemReportInfo inventoryAddedInfo in items)
                        {
                            if (inventoryAddedInfo.TransactionDate == Convert.ToDateTime(reader["order_date"]))
                            {
                                if (inventoryAddedInfo.OrderTransactionType == (TransactionType)Convert.ToInt32(reader["order_type"]))
                                {
                                    isExists = true;
                                    if (((ProductCategory)(Convert.ToInt32(reader["category_code"]))) == ProductCategory.PowerKard)
                                    {
                                        inventoryAddedInfo.QuantityPK += Convert.ToInt32(reader["Quantity"]);
                                    }
                                    else if (((ProductCategory)(Convert.ToInt32(reader["category_code"]))) == ProductCategory.Brochure)
                                    {
                                        inventoryAddedInfo.QuantityBR += Convert.ToInt32(reader["Quantity"]);
                                    }
                                    else if (((ProductCategory)(Convert.ToInt32(reader["category_code"]))) == ProductCategory.Envelope)
                                    {
                                        inventoryAddedInfo.QuantityEN += Convert.ToInt32(reader["Quantity"]);
                                    }
                                    break;
                                }
                            }
                        }

                        if (!isExists)
                        {
                            inventoryInfo = new InventoryItemReportInfo();
                            inventoryInfo.TransactionDate      = Convert.ToDateTime(reader["order_date"]);
                            inventoryInfo.OrderTransactionType = (TransactionType)Convert.ToInt32(reader["order_type"]);
                            if (((ProductCategory)(Convert.ToInt32(reader["category_code"]))) == ProductCategory.PowerKard)
                            {
                                inventoryInfo.QuantityPK = Convert.ToInt32(reader["Quantity"]);
                            }
                            else if (((ProductCategory)(Convert.ToInt32(reader["category_code"]))) == ProductCategory.Brochure)
                            {
                                inventoryInfo.QuantityBR = Convert.ToInt32(reader["Quantity"]);
                            }
                            else if (((ProductCategory)(Convert.ToInt32(reader["category_code"]))) == ProductCategory.Envelope)
                            {
                                inventoryInfo.QuantityEN = Convert.ToInt32(reader["Quantity"]);
                            }
                            items.Add(inventoryInfo);
                        }
                    }
                }
            }
            if (items.Count > 0)
            {
                int rowCount = 0;
                items[rowCount].SumQuantityPK = items[rowCount].QuantityPK;
                items[rowCount].SumQuantityBR = items[rowCount].QuantityBR;
                items[rowCount].SumQuantityEN = items[rowCount].QuantityEN;
                rowCount++;
                while (rowCount < items.Count)
                {
                    if (items[rowCount].OrderTransactionType == TransactionType.Purchased)
                    {
                        items[rowCount].SumQuantityPK = items[rowCount - 1].SumQuantityPK + items[rowCount].QuantityPK;
                        items[rowCount].SumQuantityBR = items[rowCount - 1].SumQuantityBR + items[rowCount].QuantityBR;
                        items[rowCount].SumQuantityEN = items[rowCount - 1].SumQuantityEN + items[rowCount].QuantityEN;
                    }
                    else
                    {
                        items[rowCount].SumQuantityPK = items[rowCount - 1].SumQuantityPK - items[rowCount].QuantityPK;
                        items[rowCount].SumQuantityBR = items[rowCount - 1].SumQuantityBR - items[rowCount].QuantityBR;
                        items[rowCount].SumQuantityEN = items[rowCount - 1].SumQuantityEN - items[rowCount].QuantityEN;
                    }
                    rowCount++;
                }
            }
            return(items);
        }
Example #3
0
        public ShoppingCartInfo GetCartLineItems(int userId, IProduct product)
        {
            ShoppingCartInfo            cartInfo  = new ShoppingCartInfo();
            List <ShoppingCartItemInfo> cartItems = new List <ShoppingCartItemInfo>();
            ShoppingCartItemInfo        cartItem;

            SqlParameter[] sqlParam = new SqlParameter[] { new SqlParameter("@user_id", SqlDbType.Int) };
            sqlParam[0].Value = userId;
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONNECTION_STRING,
                                                                  CommandType.StoredProcedure, SQLHelper.GetSQLStatement("ShoppingCart", "SP_GET_CARTITEMS"),
                                                                  sqlParam))
            {
                while (reader.Read())
                {
                    cartItem             = new ShoppingCartItemInfo();
                    cartItem.ProductId   = (string)reader["product_id"];
                    cartItem.Price       = Math.Round((decimal)reader["price"], 2);
                    cartItem.Quantity    = (int)reader["quantity"];
                    cartItem.Description = product.GetProductDetails(cartItem.ProductId).BriefDescWithQuantity;
                    cartItem.TotalPrice  = cartItem.Quantity * cartItem.Price;
                    cartItem.UserId      = userId;
                    cartItems.Add(cartItem);
                    cartInfo.Tax = Math.Round(Convert.ToDecimal(reader["Tax"]), 2);
                }
            }
            cartInfo.CartItems = cartItems;

            return(cartInfo);
        }
Example #4
0
        public List <InventoryInfo> GetInventoryList(int userId)
        {
            List <InventoryInfo> items         = new List <InventoryInfo>();
            InventoryInfo        inventoryInfo = new InventoryInfo();
            InventoryItemInfo    inventoryItemInfo;

            SqlParameter[] parameters = SQLHelper.GetCachedParameters("SQL_GET_INVENTORY_DETAILS");

            if (parameters == null)
            {
                parameters = new SqlParameter[] {
                    new SqlParameter("@user_id", SqlDbType.Int)
                };

                SQLHelper.CacheParameters("SQL_GET_INVENTORY_DETAILS", parameters);
            }

            parameters[0].Value = userId;

            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONNECTION_STRING,
                                                                  CommandType.StoredProcedure, SQLHelper.GetSQLStatement(MODULE_NAME, "SP_GET_INVENTORY_DETAILS"),
                                                                  parameters))
            {
                while (reader.Read())
                {
                    bool isExists = false;
                    foreach (InventoryInfo inventoryAddedInfo in items)
                    {
                        if ((int)inventoryAddedInfo.CategoryType == (int)reader["category_code"])
                        {
                            isExists      = true;
                            inventoryInfo = inventoryAddedInfo;
                            break;
                        }
                    }
                    if (!isExists)
                    {
                        inventoryInfo = new InventoryInfo();
                        inventoryInfo.CategoryType   = (ProductCategory)(Convert.ToInt32(reader["category_code"]));
                        inventoryInfo.InventoryItems = new List <InventoryItemInfo>();
                    }
                    inventoryItemInfo = new InventoryItemInfo();
                    inventoryItemInfo.OrderTransactionType = (TransactionType)(Convert.ToInt32(reader["order_type"]));
                    inventoryItemInfo.Quantity             = Convert.ToInt32(reader["Quantity"]);
                    inventoryItemInfo.Remarks         = (string)reader["cc_trxn_message"];
                    inventoryItemInfo.TransactionDate = Convert.ToDateTime(reader["order_date"]);
                    inventoryItemInfo.TransactionId   = Convert.ToInt32(reader["cc_trxn_code"]);
                    inventoryInfo.InventoryItems.Add(inventoryItemInfo);
                    if (!isExists)
                    {
                        items.Add(inventoryInfo);
                    }
                }
            }
            Product product = new Product();
            List <ProductItemInfo> products = product.GetInventoryTotalCount(userId);

            foreach (ProductItemInfo itemInfo in products)
            {
                foreach (InventoryInfo inventoryInfoItem in items)
                {
                    if (itemInfo.ProductType == inventoryInfoItem.CategoryType.ToString().Replace("_", " "))
                    {
                        inventoryInfoItem.QuantityOnHand = itemInfo.Quantity;
                    }
                }
            }
            return(items);
        }
Example #5
0
        /// <summary>
        /// Get the list of orders for the specified user.
        /// </summary>
        /// <param name="userId">Internal identifier of the user.</param>
        /// <returns>List of orders for the specified user.</returns>
        public List <OrderInfo> GetSearchOrders(int userId, int orderId, int cardType, DateTime startDate, DateTime endDate)
        {
            List <OrderInfo> orders = new List <OrderInfo>();

            SqlParameter[] parameters = SQLHelper.GetCachedParameters("SQL_GET_SEARCH_ORDERS");

            if (parameters == null)
            {
                parameters = new SqlParameter[] {
                    new SqlParameter("@UserId", SqlDbType.Int)
                };

                SQLHelper.CacheParameters("SQL_GET_SEARCH_ORDERS", parameters);
            }

            parameters[0].Value = userId;
            string sql = SQLHelper.GetSQLStatement(MODULE_NAME, "SQL_GET_SEARCH_ORDERS");

            if (userId != Int32.MinValue)
            {
                sql += " AND TBL_ORDER_HEADER.user_id = '" + userId.ToString() + "'";
            }
            if (orderId != Int32.MinValue)
            {
                sql += " AND TBL_ORDER_HEADER.order_id like '" + orderId.ToString() + "%'";
            }
            if (cardType != Int32.MinValue)
            {
                sql += " AND TBL_ORDER_HEADER.card_type = " + cardType.ToString();
            }
            if (startDate != DateTime.MinValue)
            {
                sql += " AND TBL_ORDER_HEADER.order_date >= '" + startDate.ToString() + "'";
            }
            if (endDate != DateTime.MinValue)
            {
                sql += " AND TBL_ORDER_HEADER.order_date <= '" + endDate.AddDays(1).ToString() + "'";
            }

            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONNECTION_STRING,
                                                                  CommandType.Text, sql, parameters))
            {
                while (reader.Read())
                {
                    List <OrderItemInfo> orderItems = GetItems(reader.GetInt32(1));
                    CreditCardInfo       cardInfo   = new CreditCardInfo(new LookupInfo(reader.GetInt32(3), reader.GetString(4)), reader.GetString(5), string.Empty, string.Empty, Int32.MinValue, Int32.MinValue,
                                                                         new AddressInfo(reader.GetString(8), reader.GetString(9), reader.GetString(10), new CountryInfo(reader.GetInt32(13), reader.GetString(14), false),
                                                                                         new StateInfo(reader.GetInt32(11), reader.GetString(12)), reader.GetString(15), null, null, null));

                    OrderInfo order = new OrderInfo(reader.GetInt32(1), null,
                                                    (OrderType)reader.GetInt32(16), reader.GetDateTime(2), Math.Round(reader.GetDecimal(6), 2),
                                                    reader.GetInt32(7), null, cardInfo, orderItems);
                    order.UserName = reader.GetString(0);

                    if (reader[17] != DBNull.Value)
                    {
                        order.RefundAmount = reader.GetDecimal(17);
                    }
                    orders.Add(order);
                }
            }

            return(orders);
        }
Example #6
0
        /// <summary>
        /// Inserts an order for the specified user.
        /// </summary>
        /// <param name="userId">Internal identifier of the user.</param>
        /// <param name="order">Order Information for the user.</param>
        public int Insert(int userId, OrderInfo order, int ownerId)
        {
            int orderId = 0;

            using (SqlConnection connection = new SqlConnection(SQLHelper.CONNECTION_STRING))
            {
                connection.Open();

                using (SqlTransaction transaction = connection.BeginTransaction())
                {
                    try
                    {
                        // Get the  details of the credit card.
                        Registration registration = new DAL.Registration();

                        // Insert Order Details.
                        SqlParameter[] parameters = SQLHelper.GetCachedParameters("SQL_INSERT_ORDER");

                        if (parameters == null)
                        {
                            parameters = new SqlParameter[] {
                                new SqlParameter("@OrderId", SqlDbType.Int),
                                new SqlParameter("@OrderNumber", SqlDbType.Int),
                                new SqlParameter("@OrderType", SqlDbType.Int),
                                new SqlParameter("@OrderDate", SqlDbType.DateTime),
                                new SqlParameter("@Amount", SqlDbType.Decimal),
                                new SqlParameter("@TransactionCode", SqlDbType.Int),
                                new SqlParameter("@TransactionMessage", SqlDbType.NVarChar, 255),
                                new SqlParameter("@CreditCardTypeId", SqlDbType.Int),
                                new SqlParameter("@CreditCardNo", SqlDbType.NVarChar, 20),
                                new SqlParameter("@CVVNo", SqlDbType.NVarChar, 4),
                                new SqlParameter("@HolderName", SqlDbType.NVarChar, 50),
                                new SqlParameter("@ExpirationMonth", SqlDbType.Int),
                                new SqlParameter("@ExpirationYear", SqlDbType.Int),
                                new SqlParameter("@BillingAddress1", SqlDbType.NVarChar, 255),
                                new SqlParameter("@BillingAddress2", SqlDbType.NVarChar, 255),
                                new SqlParameter("@BillingCity", SqlDbType.NVarChar, 100),
                                new SqlParameter("@BillingStateId", SqlDbType.Int),
                                new SqlParameter("@BillingZip", SqlDbType.NVarChar, 15),
                                new SqlParameter("@BillingCountryId", SqlDbType.Int),
                                new SqlParameter("@UserId", SqlDbType.Int)
                            };

                            SQLHelper.CacheParameters("SQL_INSERT_ORDER", parameters);
                        }

                        parameters[0].Direction = ParameterDirection.Output;
                        parameters[1].Value     = order.Number;
                        parameters[2].Value     = order.Type;
                        parameters[3].Value     = order.Date;
                        parameters[4].Value     = order.Amount;
                        parameters[5].Value     = order.TransactionCode;
                        parameters[6].Value     = order.TransactionMessage;
                        parameters[7].Value     = order.CreditCard.Type.LookupId;
                        parameters[8].Value     = order.CreditCard.Number;
                        parameters[9].Value     = order.CreditCard.CvvNumber;
                        parameters[10].Value    = order.CreditCard.HolderName;
                        parameters[11].Value    = order.CreditCard.ExpirationMonth;
                        parameters[12].Value    = order.CreditCard.ExpirationYear;
                        parameters[13].Value    = order.CreditCard.Address.Address1;
                        parameters[14].Value    = order.CreditCard.Address.Address2;
                        parameters[15].Value    = order.CreditCard.Address.City;
                        parameters[16].Value    = order.CreditCard.Address.State.StateId;
                        parameters[17].Value    = order.CreditCard.Address.Zip;
                        parameters[18].Value    = order.CreditCard.Address.Country.CountryId;
                        parameters[19].Value    = userId;

                        SQLHelper.ExecuteNonQuery(transaction, CommandType.Text,
                                                  SQLHelper.GetSQLStatement(MODULE_NAME, "SQL_INSERT_ORDER"),
                                                  parameters);
                        orderId = (int)parameters[0].Value;

                        AuditEntryInfo auditEntry = new AuditEntryInfo(Module.OrderManagement, orderId.ToString(), "Inserted order header",
                                                                       userId, ownerId);
                        AuditTrail.WriteEntry(auditEntry, transaction);

                        if (order.Items != null)
                        {
                            parameters = SQLHelper.GetCachedParameters("SQL_INSERT_ORDER_DETAIL");

                            if (parameters == null)
                            {
                                parameters = new SqlParameter[] {
                                    new SqlParameter("@OrderId", SqlDbType.Int),
                                    new SqlParameter("@line_number", SqlDbType.Int),
                                    new SqlParameter("@ItemId", SqlDbType.NVarChar, 30),
                                    new SqlParameter("@Quantity", SqlDbType.Int),
                                    new SqlParameter("@Rate", SqlDbType.Decimal)
                                };

                                SQLHelper.CacheParameters("SQL_INSERT_ORDER_DETAIL", parameters);
                            }
                            int lineNumber = 1;
                            foreach (OrderItemInfo orderItem in order.Items)
                            {
                                parameters[0].Value = orderId;
                                parameters[1].Value = lineNumber;
                                parameters[2].Value = orderItem.ItemId;
                                parameters[3].Value = orderItem.Quantity;
                                parameters[4].Value = orderItem.Rate;

                                SQLHelper.ExecuteNonQuery(transaction, CommandType.Text,
                                                          SQLHelper.GetSQLStatement(MODULE_NAME, "SQL_INSERT_ORDER_DETAIL"),
                                                          parameters);

                                auditEntry = new AuditEntryInfo(Module.OrderManagement, orderId.ToString(), "Inserted order detail",
                                                                userId, ownerId);
                                AuditTrail.WriteEntry(auditEntry, transaction);

                                Product product = new Product();
                                if (order.Type == OrderType.ShoppingCart && order.TransactionStatus)
                                {
                                    ProductInfo productInfo = product.GetProductDetails(orderItem.ItemId);
                                    foreach (ProductItemInfo productItemInfo in productInfo.ProductItems)
                                    {
                                        SqlParameter[] messageParameters = GetCartItemParams();
                                        messageParameters[0].Value = userId;
                                        messageParameters[1].Value = productItemInfo.ProductTypeId;
                                        messageParameters[2].Value = orderItem.Quantity * productItemInfo.Quantity;
                                        SQLHelper.ExecuteNonQuery(transaction, CommandType.StoredProcedure,
                                                                  SQLHelper.GetSQLStatement(MODULE_NAME, "SP_INSERT_UPDATE_INVENTORY"), messageParameters);
                                        auditEntry = new AuditEntryInfo(Module.OrderManagement, productItemInfo.ProductTypeId.ToString(),
                                                                        "Updated inventory", userId, ownerId);
                                        AuditTrail.WriteEntry(auditEntry, transaction);
                                    }
                                }
                            }
                        }

                        // Update the user status if the type of payment is Membership Fees.
                        if (order.Type == OrderType.MembershipFee)
                        {
                            //registration.UpdateStatus(userId,
                            //    RegistrationStatus.MembershipPaid, transaction);
                        }
                        if (order.Type == OrderType.ShoppingCart)
                        {
                            ShoppingCart cart = new ShoppingCart();
                            cart.DeleteCartItem(userId, string.Empty, new Product(), ownerId);
                        }
                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();

                        throw;
                    }
                }
            }
            return(orderId);
        }
Example #7
0
        /// <summary>
        /// Gets the design details of the specified design.
        /// </summary>
        /// <param name="designId">Internal identifier of the design.</param>
        /// <returns>Design details of the specified design.</returns>
        public DesignInfo Get(int designId)
        {
            DesignInfo design = null;

            SqlParameter[] parameters = SQLHelper.GetCachedParameters("SQL_GET_DESIGN");

            if (parameters == null)
            {
                parameters = new SqlParameter[] {
                    new SqlParameter("@design_id", SqlDbType.Int)
                };

                SQLHelper.CacheParameters("SQL_GET_DESIGN", parameters);
            }

            parameters[0].Value = designId;

            using (SqlDataReader reader =
                       SQLHelper.ExecuteReader(SQLHelper.CONNECTION_STRING,
                                               CommandType.Text,
                                               SQLHelper.GetSQLStatement(MODULE_NAME, "SQL_GET_DESIGN"),
                                               parameters))
            {
                if (reader.Read())
                {
                    DesignUsed used = DesignUsed.Never;

                    if (reader.GetInt32(27) > 0)
                    {
                        used = DesignUsed.FoundActive;
                    }
                    else if (reader.GetInt32(26) > 0)
                    {
                        used = DesignUsed.Found;
                    }

                    design = new DesignInfo(reader.GetInt32(0), reader.GetInt32(1),
                                            new LookupInfo(reader.GetInt32(2), reader.GetString(3)),
                                            new LookupInfo(reader.GetInt32(4), reader.GetString(5)),
                                            new SizeF((float)reader.GetDecimal(6), (float)reader.GetDecimal(7)),
                                            reader.GetString(8), reader.GetString(9),
                                            (JustificationType)reader.GetInt32(10), reader.GetString(11),
                                            new RectangleF((float)reader.GetDecimal(12), (float)reader.GetDecimal(13), (float)reader.GetDecimal(14), (float)reader.GetDecimal(15)),
                                            reader.GetString(16), reader.GetString(17), reader.GetString(18),
                                            new LookupInfo(reader.GetInt32(19), reader.GetString(20)),
                                            reader.GetDateTime(21), reader.GetDateTime(22), reader.GetInt32(23),
                                            reader.GetDateTime(24), reader.GetInt32(25),
                                            string.Empty, string.Empty, used);
                }
            }

            using (SqlDataReader reader =
                       SQLHelper.ExecuteReader(SQLHelper.CONNECTION_STRING,
                                               CommandType.Text,
                                               SQLHelper.GetSQLStatement(MODULE_NAME, "SQL_GET_DESIGN_HISTORY"),
                                               parameters))
            {
                string eventDetails = string.Empty;

                while (reader.Read())
                {
                    eventDetails += reader.GetDateTime(4).ToString("MM/dd/yyyy");
                    eventDetails += ": ";
                    eventDetails += reader.GetString(1);
                    eventDetails += " [" + reader.GetString(2) + "]";
                    eventDetails += Environment.NewLine;

                    eventDetails += (reader.GetString(3) == "" ? "---" : reader.GetString(3));
                    eventDetails += Environment.NewLine;

                    eventDetails += Environment.NewLine;
                }

                design.History = eventDetails;
            }

            return(design);
        }
Example #8
0
        /// <summary>
        /// Updates the design of the specified user.
        /// </summary>
        /// <param name="userId">Internal identifier of the user.</param>
        /// <param name="design">Design of the user.</param>
        public void Update(int userId, DesignInfo design)
        {
            SqlParameter[] parameters = SQLHelper.GetCachedParameters("SP_UPDATE_DESIGN");

            if (parameters == null)
            {
                parameters = new SqlParameter[] {
                    new SqlParameter("@design_id", SqlDbType.Int),
                    new SqlParameter("@user_id", SqlDbType.Int),
                    new SqlParameter("@category", SqlDbType.Int),
                    new SqlParameter("@type", SqlDbType.Int),
                    new SqlParameter("@length", SqlDbType.Decimal),
                    new SqlParameter("@width", SqlDbType.Decimal),
                    new SqlParameter("@gender", SqlDbType.NVarChar, 50),
                    new SqlParameter("@on_design_name", SqlDbType.NVarChar, 50),
                    new SqlParameter("@justification", SqlDbType.Int),
                    new SqlParameter("@gutter", SqlDbType.NVarChar, 50),
                    new SqlParameter("@msg_locn_x", SqlDbType.Decimal),
                    new SqlParameter("@msg_locn_y", SqlDbType.Decimal),
                    new SqlParameter("@msg_size_length", SqlDbType.Decimal),
                    new SqlParameter("@msg_size_width", SqlDbType.Decimal),
                    new SqlParameter("@low_res_file", SqlDbType.NVarChar, 255),
                    new SqlParameter("@high_res_file", SqlDbType.NVarChar, 255),
                    new SqlParameter("@extra_file", SqlDbType.NVarChar, 255),
                    new SqlParameter("@status", SqlDbType.Int),
                    new SqlParameter("@last_modify_by", SqlDbType.Int),
                    new SqlParameter("@approve_by", SqlDbType.Int),
                    new SqlParameter("@comments", SqlDbType.Text)
                };

                SQLHelper.CacheParameters("SP_UPDATE_DESIGN", parameters);
            }

            parameters[0].Value  = design.DesignId;
            parameters[1].Value  = design.UserId;
            parameters[2].Value  = design.Category.LookupId;
            parameters[3].Value  = design.Type.LookupId;
            parameters[4].Value  = design.Size.Width;
            parameters[5].Value  = design.Size.Height;
            parameters[6].Value  = design.Gender;
            parameters[7].Value  = design.OnDesignName;
            parameters[8].Value  = design.Justification;
            parameters[9].Value  = design.Gutter;
            parameters[10].Value = design.MessageRectangle.X;
            parameters[11].Value = design.MessageRectangle.Y;
            parameters[12].Value = design.MessageRectangle.Width;
            parameters[13].Value = design.MessageRectangle.Height;
            parameters[14].Value = design.LowResolutionFile;
            parameters[15].Value = design.HighResolutionFile;
            parameters[16].Value = design.ExtraFile;
            parameters[17].Value = design.Status.LookupId;
            parameters[18].Value = design.LastModifyBy;
            parameters[19].Value = design.ApproveBy;
            parameters[20].Value = design.Comments;

            using (SqlConnection connection = new SqlConnection(SQLHelper.CONNECTION_STRING))
            {
                connection.Open();

                using (SqlTransaction transaction = connection.BeginTransaction())
                {
                    try
                    {
                        SQLHelper.ExecuteNonQuery(transaction,
                                                  CommandType.StoredProcedure,
                                                  SQLHelper.GetSQLStatement(MODULE_NAME, "SP_UPDATE_DESIGN"),
                                                  parameters);

                        // Write entry into audit trail.
                        string action = string.Empty;

                        if (design.DesignId == 0)
                        {
                            if (design.Status.LookupId == 23)
                            {
                                action = "Submitted design";
                            }
                            else
                            {
                                action = "Added design";
                            }
                        }
                        else
                        {
                            if (design.Status.LookupId == 23)
                            {
                                if (design.UserId == design.LastModifyBy)
                                {
                                    action = "Submitted design";
                                }
                                else
                                {
                                    action = "Modified design";
                                }
                            }
                            else if (design.Status.LookupId == 25)
                            {
                                action = "Archived design";
                            }
                            else if (design.Status.LookupId == 26)
                            {
                                action = "Approved design";
                            }
                            else
                            {
                                action = "Modified design";
                            }
                        }

                        AuditEntryInfo auditEntry = new AuditEntryInfo(
                            Module.DesignManagement, design.Category.Name,
                            action, design.UserId, design.LastModifyBy);
                        AuditTrail.WriteEntry(auditEntry, transaction);

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();

                        throw;
                    }
                }
            }
        }