Exemple #1
0
 /// <summary>
 /// Add stock to the database Get the new stock with the new stock Id
 /// </summary>
 /// <param name="stock"></param>
 /// <returns></returns>
 public static StockModel AddStockToTheDatabase(StockModel stock, string db)
 {
     if (stock.ExpirationDate < new DateTime(1999, 1, 1))
     {
         stock.ExpirationDate = new DateTime(1999, 1, 1);
     }
     if (stock.NotificationDate < new DateTime(1999, 1, 1))
     {
         stock.NotificationDate = new DateTime(1999, 1, 1);
     }
     using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db)))
     {
         var p = new DynamicParameters();
         p.Add("@SBarCode", stock.SBarCode);
         p.Add("@StoreId", stock.Store.Id);
         p.Add("@ProductId", stock.Product.Id);
         p.Add("@IncomePrice", stock.IncomePrice);
         p.Add("@SalePrice", stock.SalePrice);
         p.Add("@Date", stock.Date);
         p.Add("@ExpirationDate", stock.ExpirationDate);
         p.Add("@NotificationDate", stock.NotificationDate);
         p.Add("@ExpirationAlarmEnabled", stock.ExpirationAlarmEnabled);
         p.Add("@Quantity", stock.Quantity);
         p.Add("@AlarmQuantity", stock.AlarmQuantity);
         p.Add("@QuantityAlarmEnabled", stock.QuantityAlarmEnabled);
         p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
         connection.Execute("dbo.spStock_Create", p, commandType: CommandType.StoredProcedure);
         stock.Id = p.Get <int>("@Id");
     }
     return(stock);
 }
Exemple #2
0
        /// <summary>
        /// Get the profit of single of this OrderProduct
        /// </summary>
        /// <param name="stock">The stock</param>
        /// <param name="salePrice"> The sale price that the customer will pay for a single</param>
        /// <returns></returns>
        public static decimal GetProfit(StockModel stock, decimal salePrice)
        {
            decimal profit = new decimal();

            profit = salePrice - stock.IncomePrice;
            return(profit);
        }
Exemple #3
0
        /// <summary>
        /// Resuce the quantity of stock in the database
        /// If the quantity  = stock.quantity => remove the stock from the database
        /// </summary>
        /// <param name="stock"></param>
        /// <param name="quantity"> the number that u want to decreace </param>
        /// <param name="db"></param>
        public static void ReduseStock(StockModel stock, float quantity, string db)
        {
            if (stock.Quantity > quantity)
            {
                using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db)))
                {
                    var p = new DynamicParameters();
                    p.Add("@StockId", stock.Id);
                    p.Add("@Quantity", quantity);
                    connection.Execute("dbo.spStock_ReduseStock", p, commandType: CommandType.StoredProcedure);
                }
                stock.Quantity -= quantity;
            }
            else
            {
                using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db)))
                {
                    var p = new DynamicParameters();
                    p.Add("@Id", stock.Id);

                    connection.Execute("dbo.spStock_Delete", p, commandType: CommandType.StoredProcedure);
                }
                PublicVariables.Stocks.Remove(stock);
            }
        }
Exemple #4
0
        /// <summary>
        /// Remove stock from the database
        /// </summary>
        /// <param name="stock"></param>
        /// <param name="db"></param>
        public static void RemoveStockFromTheDatabase(StockModel stock, string db)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db)))
            {
                var p = new DynamicParameters();
                p.Add("@Id", stock.Id);

                connection.Execute("dbo.spStock_Delete", p, commandType: CommandType.StoredProcedure);
            }
        }
Exemple #5
0
 /// <summary>
 /// Increace the quantity of stock in the database
 /// </summary>
 /// <param name="stock"></param>
 /// <param name="quantity"> the number that u want to increase </param>
 /// <param name="db"></param>
 public static void IncreaseStock(StockModel stock, float quantity, string db)
 {
     using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db)))
     {
         var p = new DynamicParameters();
         p.Add("@StockId", stock.Id);
         p.Add("@Quantity", quantity);
         connection.Execute("dbo.spStock_IncreaseStock", p, commandType: CommandType.StoredProcedure);
     }
 }
Exemple #6
0
        /// <summary>
        /// -OLD-Update the stock Date If the stock exist
        /// </summary>
        /// <param name="updatedStock"></param>
        /// <param name="db"></param>
        public static void UpdateStockData(StockModel updatedStock, string db)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db)))
            {
                var p = new DynamicParameters();
                p.Add("@Id", updatedStock.Id);
                p.Add("Quantity", updatedStock.Quantity);

                connection.Execute("dbo.spStock_Update", p, commandType: CommandType.StoredProcedure);
            }
        }
Exemple #7
0
        /// <summary>
        /// ExpirationAlarmEnabeled = ture , return Null
        /// if  x.ExpirationAlarmEnabled == false && x.Store == stock.Store && x.Product == stock.Product && x.IncomePrice == stock.IncomePrice && x.SalePrice == stock.SalePrice
        /// Return the stockModel
        /// </summary>
        /// <returns></returns>
        public static StockModel FindSimilarStock(StockModel stock)
        {
            if (stock.ExpirationAlarmEnabled == true)
            {
                return(null);
            }
            StockModel stockModel = PublicVariables.Stocks.Find(x => x.ExpirationAlarmEnabled == false && x.Store == stock.Store && x.Product == stock.Product && x.IncomePrice == stock.IncomePrice && x.SalePrice == stock.SalePrice);

            if (stockModel != null)
            {
                return(stockModel);
            }
            return(null);
        }
Exemple #8
0
        /// <summary>
        /// Generate a unique SBarcode for the stock
        /// Based on StoreID + First char of the productName + Number
        /// </summary>
        /// <param name="stock"></param>
        /// <returns></returns>
        public static string GenerateNewSBarCode(StockModel stock)
        {
            string startOfTheSBarCode = stock.Product.Name.Substring(0, 1) + stock.Store.Id.ToString();

            startOfTheSBarCode = startOfTheSBarCode.ToUpper();
            int number = 1;

            while (CheckIfTheSBarCodeUnique(startOfTheSBarCode + number) == false)
            {
                number++;
            }



            return(startOfTheSBarCode + number);
        }
Exemple #9
0
 /// <summary>
 /// Get the Expiration state (The days and hours left OR expired !! OR Don't Expire )
 /// </summary>
 /// <param name="stock"></param>
 /// <returns></returns>
 public static string ExpirationState(StockModel stock)
 {
     if (stock.ExpirationAlarmEnabled == true)
     {
         if (stock.GetExpirationPeriod > new TimeSpan(0, 0, 0, 0))
         {
             return("Days: " + stock.GetExpirationPeriod.Days + " ,Hours: " + stock.GetExpirationPeriod.Hours);
         }
         else
         {
             return("Expired !!");
         }
     }
     else
     {
         return("Don't Expire");
     }
 }
Exemple #10
0
        /// <summary>
        /// Update a SimilarStock With new stock
        /// </summary>
        /// <param name="similarStock"></param>
        /// <param name="newStock"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static StockModel AddStockToSimilarStockToTheDatabase(StockModel similarStock, StockModel newStock, string db)
        {
            similarStock.Quantity            += newStock.Quantity;
            similarStock.Date                 = newStock.Date;
            similarStock.AlarmQuantity        = newStock.AlarmQuantity;
            similarStock.QuantityAlarmEnabled = newStock.QuantityAlarmEnabled;
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db)))
            {
                var p = new DynamicParameters();
                p.Add("@Id", similarStock.Id);
                p.Add("@Date", similarStock.Date);
                p.Add("@AlarmQuantity", similarStock.AlarmQuantity);
                p.Add("@QuantityAlarmEnabled", similarStock.QuantityAlarmEnabled);
                p.Add("@Quantity", similarStock.Quantity);

                connection.Execute("dbo.spStock_Update", p, commandType: CommandType.StoredProcedure);
            }

            return(similarStock);
        }
Exemple #11
0
        /// <summary>
        /// Get The Expiration period by Expiration Date
        /// </summary>
        /// <param name="stock"></param>
        /// <returns></returns>
        public static TimeSpan GetExpirationPeriod(StockModel stock)
        {
            TimeSpan expirationPeriod = stock.ExpirationDate - DateTime.Now;

            return(expirationPeriod);
        }