Exemplo n.º 1
0
        public static ProductionResult Calculate(Product product, List <RawMaterial> materials, int batchSize = BatchSize)
        {
            if (materials.Count < 2)
            {
                throw new InvalidOperationException("At least two raw materials needed for every product");
            }

            ProductionResult result = new ProductionResult();

            result.InputQuantities = MapInputQuantities(materials, batchSize);
            result.OutputQuantity  = product.OutputBatchSize * batchSize;
            result.InputQuantity   = GetInputQuantities(result);
            result.SaleCost        = product.Price * result.OutputQuantity;

            var productionExpense = (result.InputQuantities[materials[0].InputLevel] * materials[0].ImportCost) +
                                    (result.InputQuantities[materials[1].InputLevel] * materials[1].ImportCost) +
                                    (result.OutputQuantity * product.ExportCost);

            var purchaseCost = (materials[0].Price * result.InputQuantities[materials[0].InputLevel]) +
                               (materials[1].Price * result.InputQuantities[materials[1].InputLevel]);

            if (materials.Count > 2)
            {
                productionExpense += (result.InputQuantities[materials[2].InputLevel] * materials[2].ImportCost);
                purchaseCost      += (materials[2].Price * result.InputQuantities[materials[2].InputLevel]);
            }

            result.Expenses     = productionExpense;
            result.PurchaseCost = purchaseCost;
            result.ProfitMargin = result.SaleCost - (result.PurchaseCost + result.Expenses);

            return(result);
        }
Exemplo n.º 2
0
        public IList <ProductionResult> GetProductionResults(int productionID)
        {
            var result = new List <ProductionResult>();

            using (DBClass = new MSSQLDatabase())
            {
                var cmd = DBClass.GetStoredProcedureCommand("APP_GET_PRODUCTION_OUTPUTS") as SqlCommand;
                DBClass.AddSimpleParameter(cmd, "@ProductionId", productionID);
                var reader = DBClass.ExecuteReader(cmd);
                while (reader.Read())
                {
                    var item = new ProductionResult
                    {
                        ProductionID = productionID,
                        ProductID    = int.Parse(reader[0].ToString()),
                        ProductCode  = reader[1].ToString(),
                        ProductName  = reader[2].ToString(),
                        Qty          = decimal.Parse(reader[3].ToString()),
                        UnitName     = reader[4].ToString(),
                        LogObject    = new StockLogObject
                        {
                            DepartementID     = int.Parse(reader[5].ToString()),
                            ProductID         = int.Parse(reader[0].ToString()),
                            ProductionVoucher = reader[6].ToString()
                        }
                    };
                    result.Add(item);
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        public string CreateSummaryMessage(ProductionResult production, string defaultResponse)
        {
            if (production == null)
            {
                return(defaultResponse);
            }

            var result = new StringBuilder();

            if (!string.IsNullOrEmpty(production.Stars))
            {
                result.Append($"<b>[{production.Stars}]</b>");
            }

            if (!string.IsNullOrEmpty(production.Category))
            {
                result.Append($"<b>[{production.Category}]</b>");
            }

            if (!string.IsNullOrEmpty(production.Name))
            {
                result.Append($"<b>[{production.Name}]</b>");
            }

            if (production.Alias != null && production.Alias.Any())
            {
                result.Append($"{Environment.NewLine}{_alsoKnowAs}{string.Join(",", production.Alias)}");
            }

            if (!string.IsNullOrEmpty(production.Time))
            {
                result.Append($"{Environment.NewLine}{_timer}{Utils.DeNormalizeTime(production.Time)}");
            }

            if (!string.IsNullOrEmpty(production.Advantages))
            {
                result.Append($"{Environment.NewLine}{_advantages}{Environment.NewLine}{production.Advantages}");
            }

            if (!string.IsNullOrEmpty(production.Disadvantages))
            {
                result.Append($"{Environment.NewLine}{_disadvantages}{Environment.NewLine}{production.Disadvantages}");
            }

            if (!string.IsNullOrEmpty(production.Summary))
            {
                result.Append($"{Environment.NewLine}{_summary}{Environment.NewLine}{production.Summary}");
            }

            if (result.Length == 0)
            {
                return(defaultResponse);
            }

            return(result.ToString());
        }
Exemplo n.º 4
0
        private static string GetInputQuantities(ProductionResult result)
        {
            StringBuilder builder = new StringBuilder();
            int           index   = 0;

            foreach (var key in result.InputQuantities.Keys)
            {
                if (index == 0)
                {
                    builder.AppendFormat("{0}", result.InputQuantities[key]);
                }
                else
                {
                    builder.AppendFormat(" /{0}", result.InputQuantities[key]);
                }

                index++;
            }

            return(builder.ToString());
        }
Exemplo n.º 5
0
 private void SaveResult(int id, ProductionResult result)
 {
     using (DBClass = new MSSQLDatabase())
     {
         using (DbTransaction txn = DBClass.BeginTransaction())
         {
             try
             {
                 var cmd = DBClass.GetStoredProcedureCommand("APP_SAVE_NEW_PRODUCTION_OUTPUT") as SqlCommand;
                 DBClass.AddSimpleParameter(cmd, "@ProductionId", id);
                 DBClass.AddSimpleParameter(cmd, "@ProductId", result.ProductID);
                 DBClass.AddSimpleParameter(cmd, "@Qty", result.Qty);
                 DBClass.ExecuteNonQuery(cmd, txn);
                 txn.Commit();
             }
             catch (Exception)
             {
                 txn.Rollback();
                 throw;
             }
         }
     }
 }
Exemplo n.º 6
0
        public string CreateInfoMessage(ProductionResult production, string defaultResponse)
        {
            if (production == null)
            {
                return(defaultResponse);
            }

            var result = new StringBuilder();

            if (!string.IsNullOrEmpty(production.Stars))
            {
                result.Append($"<b>[{production.Stars}]</b>");
            }

            if (!string.IsNullOrEmpty(production.Category))
            {
                result.Append($"<b>[{production.Category}]</b>");
            }

            if (!string.IsNullOrEmpty(production.Name))
            {
                result.Append($"<b>[{production.Name}]</b>");
            }

            if (production.Alias != null && production.Alias.Any())
            {
                result.Append($"{Environment.NewLine}{_alsoKnowAs}{string.Join(",", production.Alias)}");
            }

            if (production.Extension?.Skill != null)
            {
                if (!string.IsNullOrEmpty(production.Extension.Skill.Name))
                {
                    result.Append($"{Environment.NewLine}{_skill} {production.Extension.Skill.Name}");

                    if (production.Extension.Skill.InitCooldown.HasValue)
                    {
                        result.Append($"{Environment.NewLine}{_initCooldown}{production.Extension.Skill.InitCooldown} seconds. ");
                    }

                    if (production.Extension.Skill.Cooldown.HasValue)
                    {
                        result.Append($"  {_cooldown}{production.Extension.Skill.Cooldown} seconds.");
                    }

                    if (!string.IsNullOrEmpty(production.Extension?.Skill?.Description))
                    {
                        result.Append($"{Environment.NewLine}{production.Extension.Skill.Description}");
                    }
                }
            }
            if (production.Extension?.BuffFull != null)
            {
                if (!string.IsNullOrEmpty(production.Extension.BuffFull.Target))
                {
                    result.Append($"{Environment.NewLine}{_buffs}<b>{production.Extension.BuffFull.Target}</b>");

                    if (production.Extension.BuffFull.Effects.Any())
                    {
                        result.Append($"{Environment.NewLine}{string.Join(", ", production.Extension.BuffFull.Effects.Select(x => $"{x.Key} {x.Value}%"))}");
                    }
                }
            }

            return(result.ToString());
        }