예제 #1
0
        public static GiftCard CreateGiftCard(int PurchasedByCustomerID, string SerialNumber, object OrderNumber, int ShoppingCartRecID, object ProductID, object VariantID, object InitialAmount, object ExpirationDate, object Balance, object GiftCardTypeID, string EMailName, string EMailTo, string EMailMessage, string ValidForCustomers, string ValidForProducts, string ValidForManufacturers, string ValidForCategories, string ValidForSections, string ExtensionData)
        {
            var GiftCardID = 0;

            using (var cn = new SqlConnection(DB.GetDBConn()))
            {
                cn.Open();
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection  = cn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "dbo.aspdnsf_CreateGiftCard";

                    cmd.Parameters.Add(new SqlParameter("@SerialNumber", SqlDbType.NVarChar, 200));
                    cmd.Parameters.Add(new SqlParameter("@PurchasedByCustomerID", SqlDbType.Int, 4));
                    cmd.Parameters.Add(new SqlParameter("@OrderNumber", SqlDbType.Int, 4));
                    cmd.Parameters.Add(new SqlParameter("@ShoppingCartRecID", SqlDbType.Int, 4));
                    cmd.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.Int, 4));
                    cmd.Parameters.Add(new SqlParameter("@VariantID", SqlDbType.Int, 4));
                    cmd.Parameters.Add(new SqlParameter("@InitialAmount", SqlDbType.Decimal, 8));
                    cmd.Parameters.Add(new SqlParameter("@Balance", SqlDbType.Decimal, 8));
                    cmd.Parameters.Add(new SqlParameter("@ExpirationDate", SqlDbType.DateTime, 8));
                    cmd.Parameters.Add(new SqlParameter("@GiftCardTypeID", SqlDbType.Int, 4));
                    cmd.Parameters.Add(new SqlParameter("@EMailName", SqlDbType.NVarChar, 200));
                    cmd.Parameters.Add(new SqlParameter("@EMailTo", SqlDbType.NVarChar, 200));
                    cmd.Parameters.Add(new SqlParameter("@EMailMessage", SqlDbType.NText));
                    cmd.Parameters.Add(new SqlParameter("@ValidForCustomers", SqlDbType.NText));
                    cmd.Parameters.Add(new SqlParameter("@ValidForProducts", SqlDbType.NText));
                    cmd.Parameters.Add(new SqlParameter("@ValidForManufacturers", SqlDbType.NText));
                    cmd.Parameters.Add(new SqlParameter("@ValidForCategories", SqlDbType.NText));
                    cmd.Parameters.Add(new SqlParameter("@ValidForSections", SqlDbType.NText));
                    cmd.Parameters.Add(new SqlParameter("@ExtensionData", SqlDbType.NText));
                    cmd.Parameters.Add(new SqlParameter("@GiftCardID", SqlDbType.Int, 4)).Direction = ParameterDirection.Output;

                    cmd.Parameters["@PurchasedByCustomerID"].Value = PurchasedByCustomerID;

                    if (SerialNumber == null)
                    {
                        cmd.Parameters["@SerialNumber"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@SerialNumber"].Value = SerialNumber;
                    }

                    if (OrderNumber == null)
                    {
                        cmd.Parameters["@OrderNumber"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@OrderNumber"].Value = OrderNumber;
                    }

                    cmd.Parameters["@ShoppingCartRecID"].Value = ShoppingCartRecID;

                    if (ProductID == null)
                    {
                        cmd.Parameters["@ProductID"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@ProductID"].Value = ProductID;
                    }

                    if (VariantID == null)
                    {
                        cmd.Parameters["@VariantID"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@VariantID"].Value = VariantID;
                    }

                    if (InitialAmount == null)
                    {
                        cmd.Parameters["@InitialAmount"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@InitialAmount"].Value = InitialAmount;
                    }

                    if (Balance == null)
                    {
                        cmd.Parameters["@Balance"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@Balance"].Value = Balance;
                    }

                    if (ExpirationDate == null || !CommonLogic.IsDate(ExpirationDate.ToString()))
                    {
                        cmd.Parameters["@ExpirationDate"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@ExpirationDate"].Value = DateTime.Parse(ExpirationDate.ToString());
                    }

                    if (GiftCardTypeID == null)
                    {
                        cmd.Parameters["@GiftCardTypeID"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@GiftCardTypeID"].Value = GiftCardTypeID;
                    }

                    if (EMailName == null)
                    {
                        cmd.Parameters["@EMailName"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@EMailName"].Value = EMailName;
                    }

                    if (EMailTo == null)
                    {
                        cmd.Parameters["@EMailTo"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@EMailTo"].Value = EMailTo;
                    }

                    if (EMailMessage == null)
                    {
                        cmd.Parameters["@EMailMessage"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@EMailMessage"].Value = EMailMessage;
                    }

                    if (ValidForCustomers == null)
                    {
                        cmd.Parameters["@ValidForCustomers"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@ValidForCustomers"].Value = ValidForCustomers;
                    }

                    if (ValidForProducts == null)
                    {
                        cmd.Parameters["@ValidForProducts"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@ValidForProducts"].Value = ValidForProducts;
                    }

                    if (ValidForManufacturers == null)
                    {
                        cmd.Parameters["@ValidForManufacturers"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@ValidForManufacturers"].Value = ValidForManufacturers;
                    }

                    if (ValidForCategories == null)
                    {
                        cmd.Parameters["@ValidForCategories"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@ValidForCategories"].Value = ValidForCategories;
                    }

                    if (ValidForSections == null)
                    {
                        cmd.Parameters["@ValidForSections"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@ValidForSections"].Value = ValidForSections;
                    }

                    if (ExtensionData == null)
                    {
                        cmd.Parameters["@ExtensionData"].Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters["@ExtensionData"].Value = ExtensionData;
                    }


                    try
                    {
                        cmd.ExecuteNonQuery();
                        GiftCardID = Int32.Parse(cmd.Parameters["@GiftCardID"].Value.ToString());
                    }
                    catch (Exception ex)
                    {
                        SysLog.LogException(ex, MessageTypeEnum.DatabaseException, MessageSeverityEnum.Error);
                    }
                }
            }

            if (GiftCardID > 0)
            {
                return(new GiftCard(GiftCardID));
            }

            return(null);
        }