public IHttpActionResult PutRollType(int id, RollType rollType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != rollType.UserID) { return(BadRequest()); } db.Entry(rollType).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RollTypeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public static int Roll(int DiceSize, RollType rollType) { byte diceSize = (byte)DiceSize; int firstRoll = RollDice(diceSize); switch (rollType) { default: case RollType.Normal: return(firstRoll); case RollType.Advantage: int advRoll = RollDice(diceSize); if (advRoll > firstRoll) { return(advRoll); } return(firstRoll); case RollType.Disadvantage: int disadvRoll = RollDice(diceSize); if (disadvRoll < firstRoll) { return(disadvRoll); } return(firstRoll); } }
public Stats(RollType rollType) { this.rollType = rollType; if (rollType == RollType.Attack) { dieFaces.Add(DieFace.Blank); dieFaces.Add(DieFace.Blank); dieFaces.Add(DieFace.Focus); dieFaces.Add(DieFace.Focus); dieFaces.Add(DieFace.Hit); dieFaces.Add(DieFace.Hit); dieFaces.Add(DieFace.Hit); dieFaces.Add(DieFace.Crit); } else { dieFaces.Add(DieFace.Blank); dieFaces.Add(DieFace.Blank); dieFaces.Add(DieFace.Blank); dieFaces.Add(DieFace.Focus); dieFaces.Add(DieFace.Focus); dieFaces.Add(DieFace.Evade); dieFaces.Add(DieFace.Evade); dieFaces.Add(DieFace.Evade); } numberOfDice = 3; }
private void RollReiniti() { _localVector3S.Clear(); if (_rotateIndex <= 0) { _rollType = RollType.SpreadReady; return; } if (_rotateIndex + 1 < _cutPoints.Count) { var t1 = _originPoints[_rotateIndex + 1] - _originPoints[_rotateIndex]; var t2 = _originPoints[_rotateIndex] - _originPoints[_rotateIndex - 1]; _length = t1.magnitude; _curTime = 0; _angle = Vector3.Angle(t1, t2); _totalTime = _angle / _moveSpeed; } if (_rotateIndex != _cutPoints.Count - 2) { for (int i = _rotateIndex + 2; i < _cutPoints.Count; i++) { Vector3 offset = _cutPoints[i] - _cutPoints[_rotateIndex + 1]; _localVector3S.Add(offset); } } }
public static void Roll(int rollId, WAEItem itemToRoll, string reason, RollType rollType) { int waitTime = 1000 + new Random().Next(1, 3000); string adjustedReason = reason == "" ? "" : $"[{reason}]"; if (rollType == RollType.PASS) { Logger.Log($"Rolling PASS in {waitTime}ms for {itemToRoll.Name} {adjustedReason}"); Thread.Sleep(waitTime); Lua.LuaDoString($"ConfirmLootRoll({rollId}, 0)"); } if (rollType == RollType.GREED) { Logger.Log($"Rolling GREED in {waitTime}ms for {itemToRoll.Name} {adjustedReason}"); Thread.Sleep(waitTime); Lua.LuaDoString($"ConfirmLootRoll({rollId}, 2)"); } if (rollType == RollType.NEED) { Logger.Log($"Rolling NEED in {waitTime}ms for {itemToRoll.Name} ({itemToRoll.WeightScore}) {adjustedReason}"); Thread.Sleep(waitTime); Lua.LuaDoString($"ConfirmLootRoll({rollId}, 1)"); } }
private int MaxValue(RollType roll, int val) { int maxRollValue = RollTypeToDieMap[roll]; return((val > maxRollValue) ? maxRollValue : val); }
public virtual int Roll(RollType roll) { ValidateInput(roll); return IsConstant() ? constant : GetRngRoll(roll); }
/// <summary> /// Returns a date equal to the input date plus the specified period, adjusted for holidays /// </summary> /// <param name="date">Input date</param> /// <param name="rollType">RollType enum</param> /// <param name="calendar">Calendar</param> /// <param name="datePeriod">Period to add in the form of a Frequency object</param> /// <returns></returns> public static DateTime AddPeriod(this DateTime date, RollType rollType, Calendar calendar, Frequency datePeriod) { date = date.Date; if (datePeriod.PeriodCount == 0) { return(IfHolidayRoll(date, rollType, calendar)); } if (datePeriod.PeriodType == DatePeriodType.B) { //Business day jumping so we need to do something different var d = date; for (var i = 0; i < datePeriod.PeriodCount; i++) { d = d.AddDays(1); d = IfHolidayRoll(d, rollType, calendar); } return(d); } DateTime dt; switch (datePeriod.PeriodType) { case DatePeriodType.D: dt = date.AddDays(datePeriod.PeriodCount); break; case DatePeriodType.M: dt = date.AddMonths(datePeriod.PeriodCount); break; case DatePeriodType.W: dt = date.AddDays(datePeriod.PeriodCount * 7); break; default: dt = date.AddYears(datePeriod.PeriodCount); break; } if ((rollType == RollType.MF_LIBOR) && (date == date.LastBusinessDayOfMonth(calendar))) { dt = date.LastBusinessDayOfMonth(calendar); } if (rollType == RollType.ShortFLongMF) { if (datePeriod.PeriodType == DatePeriodType.B || datePeriod.PeriodType == DatePeriodType.D || datePeriod.PeriodType == DatePeriodType.W) { return(IfHolidayRoll(dt, RollType.F, calendar)); } else { return(IfHolidayRoll(dt, RollType.MF, calendar)); } } return(IfHolidayRoll(dt, rollType, calendar)); }
public IHttpActionResult GetRollType(int id) { RollType rollType = db.RollTypes.Find(id); if (rollType == null) { return(NotFound()); } return(Ok(rollType)); }
internal SortedDictionary <int, List <string> > BuildDiceBucket(string roll, RollType rollType, List <int> throwAwayRolls) { SortedDictionary <int, List <string> > diceBucket = new SortedDictionary <int, List <string> >(Comparer <int> .Create((x, y) => y.CompareTo(x))); const string pattern = @"([+|-]?\s?\d*df)|([+|-]?\s?\d*\/?d\d+)|([+|-]?\s?\d+)"; string modifiedRoll = roll; // Alias a roll for Fate if (roll.Contains("fate", StringComparison.CurrentCultureIgnoreCase)) { modifiedRoll = roll.Replace("fate", "4df", StringComparison.OrdinalIgnoreCase); } var regExp = new Regex(pattern, RegexOptions.IgnoreCase); foreach (Match m in regExp.Matches(modifiedRoll)) { string expression; bool isFudgeDice = false; int sides = 0; var diceMatch = Regex.Match(m.Value, @"(?<posneg>[+|-]?)\s?\/?(?<multiplier>[\d]+)?d(?<sides>\d+|f)", RegexOptions.IgnoreCase); if (diceMatch.Length > 0) { string posneg = diceMatch.Groups["posneg"].Value == "-" ? "-" : "+"; int multiplier = String.IsNullOrWhiteSpace(diceMatch.Groups["multiplier"].Value) ? 1 : Int32.Parse(diceMatch.Groups["multiplier"].Value); if (diceMatch.Groups["sides"].Value.ToLower() == "f") { isFudgeDice = true; sides = 3; } else { sides = Int32.Parse(diceMatch.Groups["sides"].Value); } for (var i = 0; i < multiplier; i++) { expression = $@"{posneg}{RollDice(sides, rollType, throwAwayRolls)}"; AddToDiceBucket(diceBucket, sides, expression, isFudgeDice); } } else { expression = m.Value; var rollValue = ExpressionToInt(expression); AddToDiceBucket(diceBucket, 0, IntToExpression(rollValue), isFudgeDice: false); } } return(diceBucket); }
public void AddAlteration(RollType rollType, IHasTurn hasTurn, IRollDataAlteration alteration) { RollDictID rollDictID = new RollDictID(hasTurn, rollType); if (!RollAlterationDict.ContainsKey(rollDictID)) { RollAlterationDict[rollDictID] = new List <IRollDataAlteration>(); } RollAlterationDict[rollDictID].Add(alteration); }
public IHttpActionResult PostRollType(RollType rollType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.RollTypes.Add(rollType); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = rollType.UserID }, rollType)); }
internal RollNode(RollType rollType, DiceAST numDice, DiceAST numSides) { RollType = rollType; _values = new List <DieResult>(); NumDice = numDice ?? throw new ArgumentNullException(nameof(numDice)); NumSides = numSides; if (numSides == null && rollType != RollType.Fudge) { throw new ArgumentNullException(nameof(numSides)); } }
public NewStats(RollType rollType) { this.rollType = rollType; dieFaces.Add(DieFace.Blank); dieFaces.Add(DieFace.Blank); dieFaces.Add(DieFace.Focus); dieFaces.Add(DieFace.Focus); dieFaces.Add(DieFace.Hit); dieFaces.Add(DieFace.Hit); dieFaces.Add(DieFace.Hit); dieFaces.Add(DieFace.Crit); }
public IHttpActionResult DeleteRollType(int id) { RollType rollType = db.RollTypes.Find(id); if (rollType == null) { return(NotFound()); } db.RollTypes.Remove(rollType); db.SaveChanges(); return(Ok(rollType)); }
public void Roll(RollType rollType, IHasTurn hasTurn, IRollData rollData) { RollDictID rollDictID = new RollDictID(hasTurn, rollType); if (RollAlterationDict.ContainsKey(rollDictID)) { foreach (IRollDataAlteration rollDataAlteration in RollAlterationDict[rollDictID]) { rollDataAlteration.Alter(rollData); } } int rollInt = MyAdvantageRoller.Roll(rollData.MyAdvantageSetter); rollData.SetRoll(rollInt); }
public void OnIniti(List <Vector3> drawPoints, Vector3 edgePoint1, Vector3 edgePoint2) { _rollType = RollType.RollReady; _localVector3S = new List <Vector3>(); _offsetsCache = new Dictionary <int, List <Vector3> >(); _originPoints = new List <Vector3>(); _normalCache = new Dictionary <int, Vector3>(); _cutTopCache = new Dictionary <int, List <V3> >(); _cutIntersectionCache = new Dictionary <int, List <Vector2> >(); _leftInts = new List <int>(); _rightInts = new List <int>(); GeneratorMesh(drawPoints, edgePoint1, edgePoint2); }
private RollResult RollHelper(RollType rollType) { var result = new RollResult(); foreach (var entry in m_Counts) { var die = entry.Key; for (var i = 0; i < entry.Value; ++i) { var type = s_DieTypeByDie[die]; Symbol symbol; switch (rollType) { default: // normal symbol = die.Roll(); break; case RollType.Best: symbol = die.RollBest(); break; case RollType.Worst: symbol = die.RollWorst(); break; } result.AddDieResult(type, symbol); var outcome = s_SymbolToList[symbol]; foreach (var outcomeSymbol in outcome) { result.Add(outcomeSymbol); } } } result.Finish(); return(result); }
public IHttpActionResult PostApproveFarmerRegi(dynamic id) { try { int ID = Convert.ToInt32(id); RollType rollType = (from r in Db.RollTypes where r.UserID == ID select r).First(); rollType.ApprovedStatus = true; Db.Entry(rollType).State = EntityState.Modified; //Db.RollTypes.Add(roll); Db.SaveChanges(); return(Ok("Farmer Approved")); } catch (Exception e) { return(BadRequest(e.Message)); } }
private int RollDice(int sides, RollType rollType, List <int> throwAwayRolls) { int roll = this.numberGenerator.Generate(1, sides + 1); if (sides == 20 && rollType != RollType.normalRoll) { int secondRoll = this.numberGenerator.Generate(1, sides + 1); if (rollType == RollType.withAdvantage) { throwAwayRolls.Add((secondRoll > roll) ? roll : secondRoll); roll = (secondRoll > roll) ? secondRoll : roll; } else { throwAwayRolls.Add((secondRoll < roll) ? roll : secondRoll); roll = (secondRoll < roll) ? secondRoll : roll; } } return(roll); }
/// <summary> /// Returns a date equal to the input date minus the specified period, adjusted for holidays /// </summary> /// <param name="date">Input date</param> /// <param name="rollType">RollType enum</param> /// <param name="calendar">Calendar</param> /// <param name="datePeriod">Period to add in the form of a Frequency object</param> /// <returns></returns> public static DateTime SubtractPeriod(this DateTime date, RollType rollType, Calendar calendar, Frequency datePeriod) { date = date.Date; if (datePeriod.PeriodCount == 0) { return(IfHolidayRoll(date, rollType, calendar)); } if (datePeriod.PeriodType == DatePeriodType.B) { //Business day jumping so we need to do something different var d = date; for (var i = 0; i < datePeriod.PeriodCount; i++) { d = d.AddDays(-1); d = IfHolidayRoll(d, rollType, calendar); } return(d); } return(AddPeriod(date, rollType, calendar, new Frequency(0 - datePeriod.PeriodCount, datePeriod.PeriodType))); }
private void SpreadReiniti() { _localVector3S.Clear(); if (_rotateIndex >= _cutPoints.Count - 1) { _rollType = RollType.RollReady; return; } if (_rotateIndex + 1 < _cutPoints.Count) { _targetVector3 = _cutPoints[_rotateIndex + 1] - _cutPoints[_rotateIndex]; _length = _targetVector3.magnitude; _curTime = 0; _angle = Vector3.Angle(_targetVector3, _moveVector3); _totalTime = _angle / _moveSpeed; } for (int i = _rotateIndex + 2; i < _cutPoints.Count; i++) { Vector3 offset = _cutPoints[i] - _cutPoints[_rotateIndex + 1]; _localVector3S.Add(offset); } }
public void OnUpdate() { if (Input.GetMouseButtonDown(0)) { switch (_rollType) { case RollType.RollReady: _rollType = RollType.Rolling; _rotateIndex = _cutPoints.Count - 2; RollReiniti(); break; case RollType.SpreadReady: _rollType = RollType.Spreading; _rotateIndex = 0; SpreadReiniti(); break; } } RollUpdate(); SpreadUpdate(); }
private void RollItem(int rollId, RollType type) { WoWScript.ExecuteNoResults("RollOnLoot(" + rollId + "," + (int)type + ")"); }
public static DateTime[] AddPeriod(this DateTime[] dates, RollType rollType, Calendar calendar, Frequency datePeriod) => dates.Select(d => d.AddPeriod(rollType, calendar, datePeriod)).ToArray();
/// <summary> /// Returns the input date, adjusted by rolling if the input date falls on a holiday according to the specified calendar. /// The type of roll is specfied in the input. /// </summary> /// <param name="date">Input date</param> /// <param name="rollType">RollType enum</param> /// <param name="calendar">Calendar</param> /// <returns></returns> public static DateTime IfHolidayRoll(this DateTime date, RollType rollType, Calendar calendar) { if (calendar == null) { return(date); } date = date.Date; DateTime d, d1, d2; double distFwd, distBack; switch (rollType) { case RollType.F: return(date.IfHolidayRollForward(calendar)); case RollType.MF: default: d = date.IfHolidayRollForward(calendar); if (d.Month == date.Month) { return(d); } else { return(date.IfHolidayRollBack(calendar)); } case RollType.P: return(date.IfHolidayRollBack(calendar)); case RollType.MP: d = date.IfHolidayRollBack(calendar); if (d.Month == date.Month) { return(d); } else { return(date.IfHolidayRollForward(calendar)); } case RollType.NearestFollow: d1 = date.IfHolidayRollForward(calendar); d2 = date.IfHolidayRollBack(calendar); distFwd = (d1 - date).TotalDays; distBack = (date - d2).TotalDays; if (distBack < distFwd) { return(d2); } else { return(d1); } case RollType.NearestPrev: d1 = date.IfHolidayRollForward(calendar); d2 = date.IfHolidayRollBack(calendar); distFwd = (d1 - date).TotalDays; distBack = (date - d2).TotalDays; if (distFwd < distBack) { return(d1); } else { return(d2); } case RollType.LME: d1 = date.IfHolidayRollForward(calendar); if (d1.Month != date.Month) { return(date.IfHolidayRollBack(calendar)); } d2 = date.IfHolidayRollBack(calendar); if (d2.Month != date.Month) { return(d1); } distFwd = (d1 - date).TotalDays; distBack = (date - d2).TotalDays; if (distBack < distFwd) { return(d2); } else { return(d1); } case RollType.None: return(date); } }
private IEnumerable<string> EnumerateProductNames(int plantCode, RollType rollType, AlloyType alloyType) { if (plantCode == 1) { if (rollType == RollType.Hot) { return new[] { "150х100х", "100х100х", "120х80х", "120х120х", "140х100х", "160х80х", "140х140х", "160х120х", "150х150х", "160х140х", "180х100х", "200х100х", "160х160х", "180х140х", "200х120х", "180х180х", "200х160х", "240х120х", "200х200х", "240х160х", "250х150х", "300х100х", "250х250х", "300х200х", "300х300х", "159х", "219х", "273х", "325 - 377х", "426х", }; } } if (plantCode == 2) { if (rollType == RollType.Hot) { return new[] { "г/к 15х15х", "г/к 20х10х", "г/к 20х20х", "г/к 25х25х", "г/к 30х20х", "г/к 30х30х", "г/к 40х20х", "г/к 40х25х", "г/к 40х40х", "г/к 50х25х", "г/к 50х30х", "г/к 50х50х", "г/к 60х30х", "г/к 60х40х", "г/к 60х60х", "г/к 80х40х", "г/к 16х", "г/к 20х", "г/к 25х", "г/к 28х", "г/к 30х", "г/к 32х", "г/к 38х", "г/к 40х", "г/к 42х", "г/к 48х", "г/к 51х", "г/к 57х", "г/к 60х", "г/к 76х", }; } if (rollType == RollType.Cold) { return new[] { "х/к 15х15х", "х/к 20х10х", "х/к 25х25х", "х/к 30х15х", "х/к 30х30х", "х/к 40х20х", "х/к 50х25х", "х/к 60х30х", "х/к 16х", "х/к 18х", "х/к 22х", "х/к 25х", "х/к 30х", "х/к 40х", "х/к 51х", "х/к 76х", }; } } return Enumerable.Empty<string>(); }
public override void OnInitialize(ConfigsReader configs) { base.OnInitialize(configs); string fileName = configs.GetString("fileName", null); if (fileName == null) { fileName = FILE_NAME; } if (Path.IsPathRooted(fileName)) { //absolute path this._filePath = fileName; } else { //relative path #if UNITY_EDITOR this._filePath = fileName; #else this._filePath = Path.Combine(Application.persistentDataPath, fileName); #endif } this._maxFileCount = Mathf.Max(1, configs.GetInt("maxBackups", DEFAULT_MAX_BACK_UPS)); this._maxFileSize = Mathf.Max(10 * 1024, configs.GetInt("maxFileSize", DEFAULT_MAX_FILE_SIZE)); _flushIntervalMillSeconds = Mathf.Max(0, configs.GetInt("flushInterval", 1000)); bool keepExt = configs.GetBool("keepExt", DEFAULT_KEEP_EXT); RollType rollType = RollType.Session; var rollTypeStr = configs.GetString("rollType", null); if (rollTypeStr != null) { if (!System.Enum.TryParse <RollType>(rollTypeStr, out rollType)) { UnityEngine.Debug.LogWarning($"bad rollType:{rollTypeStr}"); rollType = RollType.Session; } } AppTrack.handleAppEvent += HandleAppEvent; if (rollType == RollType.Session) { _rollingFS = new IndexedRollingFileStream(_filePath, new IndexedRollingFileStream.Options() { maxFileSize = _maxFileSize, maxBackups = _maxFileCount, keepExts = keepExt }); _rollingFS.Roll(); } else if (rollType == RollType.Date) { _rollingFS = new DateRollingFileStream(_filePath, new DateRollingFileStream.Options() { maxBackups = _maxFileCount, maxFileSize = _maxFileSize, keepExt = keepExt }); } else if (rollType == RollType.Size) { _rollingFS = new IndexedRollingFileStream(_filePath, new IndexedRollingFileStream.Options() { maxFileSize = _maxFileSize, maxBackups = _maxFileCount, keepExts = keepExt }); } }
private static RollSettings BuildDefaultRollSetting(RollType rollType) { switch (rollType) { case RollType.CT: return new RollSettings { RollType = RollType.CT, DataSource = RollDataSource.DirectDB, GenerationSettings = GenerationSettings, IsTopup = IsTopup, }; case RollType.Future: return new RollSettings { RollType = RollType.Future, DataSource = RollDataSource.CarbonEod, GenerationSettings = GenerationSettings, IsTopup = IsTopup, }; case RollType.CTD: return new RollSettings { RollType = RollType.CTD, DataSource = RollDataSource.DirectDB, DataSource2 = RollDataSource.CarbonEod, // 2nd data source is used for futture source when computing forward data. CTDSource = CTDGeneratorType.Bloomberg, //todo! use JB's ctd pick method in place of this GenerationSettings = GenerationSettings, Ctdoverrides = GetCTDOverrideFromFile(), IsTopup = IsTopup, }; default: throw new ArgumentOutOfRangeException("rollType", rollType, null); } }
public BulkMaterialParseResult ParseMaterialPricesBulk( int manufacturerId, int supplierId, DateTime date, AlloyType alloyType, RollType rollType, bool remove, string raw) { var materials = new List <RawMaterial>(); var errors = new List <string>(); try { using (var storage = new Storage()) { if (remove) { var allThickness = storage.RawMaterials .Where( rm => rm.ManufacturerId == supplierId && (alloyType == AlloyType.Undefined || rm.RawMaterialType.AlloyType == alloyType) && (rollType == RollType.Undefined || rm.RawMaterialType.RollType == rollType) ) .Select(rm => rm.RawMaterialType.Thickness.ToString(CultureInfo.InvariantCulture)) .ToList(); raw = string.Join("\t", allThickness) + "\n" + string.Join("\t", allThickness.Select(p => "")); } var lines = raw.Split('\n'); var headers = lines[0].Split('\t'); var prices = lines[1].Split('\t'); for (int i = 0; i < headers.Length; i++) { var thickness = Convert.ToDecimal(headers[i].FixDecimalSeparator()); if (!string.IsNullOrEmpty(prices[i])) { var rawMaterial = storage .RawMaterials .Where( rm => rm.ManufacturerId == supplierId && rm.RawMaterialType.AlloyType == alloyType && rm.RawMaterialType.RollType == rollType && rm.RawMaterialType.Thickness == thickness) .ToList(); if (!rawMaterial.Any()) { errors.Add($"Выбранный поставщик не производит материала с такими параметрами и толщиной {thickness}"); continue; } if (rawMaterial.Count > 1) { errors.Add( $"Выбранный поставщик производит более 1 материала с такими параметрами и толщиной {thickness}, невозможно определить нужный."); continue; } var priceItem = new PriceItem { RawMaterialId = rawMaterial[0].RawMaterialId, OwnerId = manufacturerId, Date = date, Price = remove ? null : (decimal?)Convert.ToDecimal(prices[i].FixDecimalSeparator()) }; rawMaterial[0].PriceItems = new[] { priceItem }; materials.Add(rawMaterial[0]); } } } } catch (Exception ex) { _logger.Error(ex); errors.Add("Ошибка синтаксического разбора строки."); } return(new BulkMaterialParseResult { Errors = errors.ToArray(), Materials = errors.Any() ? new RawMaterial[0] : materials.ToArray() }); }
public Roller(RollType rollType){ _rollType = rollType; }
public BulkProductParseResult ParseExtraPricesBulk( int manufacturerId, int supplierId, DateTime date, AlloyType alloyType, RollType rollType, int priceExtraCategoryId, bool remove, string raw) { var products = new List<Product>(); var errors = new List<string>(); if (remove) { raw = "0"; } try { var lines = raw.Split(new [] {'\n'}, StringSplitOptions.RemoveEmptyEntries); var headers = lines[0].Split('\t'); using (var storage = new Storage()) { if (lines.Length == 1 && headers.Length == 1) { var price = Convert.ToDecimal(raw.Trim().FixDecimalSeparator()); return new BulkProductParseResult { Errors = new string[0], Products = storage .Products .Where( p => p.ManufacturerId == manufacturerId && p.RawMaterial.ManufacturerId == supplierId && (alloyType == AlloyType.Undefined || p.RawMaterial.RawMaterialType.AlloyType == alloyType) && (rollType == RollType.Undefined || p.RawMaterial.RawMaterialType.RollType == rollType) ) .ToList() .Select( p => { p.PriceExtras = new[] { new PriceExtra { PriceExtraCategoryId = priceExtraCategoryId, PriceItems = new[] { new PriceItem { Date = date, OwnerId = manufacturerId, Price = price, } } } }; return p; }) .ToArray() }; } for (int lineId = 1; lineId < lines.Length; lineId++) { var prices = lines[lineId].Split('\t'); var productName = prices[0].Trim(); for (int colId = 1; colId < headers.Length; colId++) { var thickness = Convert.ToDecimal(headers[colId].FixDecimalSeparator()); var query = storage .RawMaterials .LoadWith(rm => rm.RawMaterialType) .Where( rm => rm.ManufacturerId == supplierId && rm.RawMaterialType.Thickness == thickness); if (alloyType != AlloyType.Undefined) { query = query.Where(rm => rm.RawMaterialType.AlloyType == alloyType); } if (rollType != RollType.Undefined) { query = query.Where(rm => rm.RawMaterialType.RollType == rollType); } var rawMaterials = query.ToList(); if (!rawMaterials.Any()) { errors.Add($"Выбранный поставщик не производит материала с такими параметрами и толщиной {thickness}"); continue; } foreach (var rawMaterial in rawMaterials) { var product = storage .Products .SingleOrDefault( p => p.ManufacturerId == manufacturerId && p.RawMaterialId == rawMaterial.RawMaterialId && p.Name == productName); if (null == product) { product = new Product { ManufacturerId = manufacturerId, RawMaterialId = rawMaterial.RawMaterialId, Thickness = rawMaterial.RawMaterialType.Thickness, Name = productName, }; } var priceExtra = new PriceExtra { PriceExtraCategoryId = priceExtraCategoryId, ProductId = product.ProductId, }; var price = string.IsNullOrEmpty(prices[colId]) ? null : (decimal?)Convert.ToDecimal(prices[colId].FixDecimalSeparator()); var priceItem = new PriceItem { OwnerId = manufacturerId, Date = date, Price = remove ? null : price, }; priceExtra.PriceItems = new[] { priceItem }; product.PriceExtras = new[] { priceExtra }; products.Add(product); if (!string.IsNullOrEmpty(prices[colId])) { } } } } } } catch (Exception ex) { _logger.Error(ex); errors.Add("Ошибка синтаксического разбора строки."); } return new BulkProductParseResult { Errors = errors.ToArray(), Products = errors.Any() ? new Product[0] : products.ToArray() }; }
public BulkMaterialParseResult ParseMaterialPricesBulk( int manufacturerId, int supplierId, DateTime date, AlloyType alloyType, RollType rollType, bool remove, string raw) { var materials = new List<RawMaterial>(); var errors = new List<string>(); try { using (var storage = new Storage()) { if (remove) { var allThickness = storage.RawMaterials .Where( rm => rm.ManufacturerId == supplierId && (alloyType == AlloyType.Undefined || rm.RawMaterialType.AlloyType == alloyType) && (rollType == RollType.Undefined || rm.RawMaterialType.RollType == rollType) ) .Select(rm => rm.RawMaterialType.Thickness.ToString(CultureInfo.InvariantCulture)) .ToList(); raw = string.Join("\t", allThickness) + "\n" + string.Join("\t", allThickness.Select(p => "")); } var lines = raw.Split('\n'); var headers = lines[0].Split('\t'); var prices = lines[1].Split('\t'); for (int i = 0; i < headers.Length; i++) { var thickness = Convert.ToDecimal(headers[i].FixDecimalSeparator()); if (!string.IsNullOrEmpty(prices[i])) { var rawMaterial = storage .RawMaterials .Where( rm => rm.ManufacturerId == supplierId && rm.RawMaterialType.AlloyType == alloyType && rm.RawMaterialType.RollType == rollType && rm.RawMaterialType.Thickness == thickness) .ToList(); if (!rawMaterial.Any()) { errors.Add($"Выбранный поставщик не производит материала с такими параметрами и толщиной {thickness}"); continue; } if (rawMaterial.Count > 1) { errors.Add( $"Выбранный поставщик производит более 1 материала с такими параметрами и толщиной {thickness}, невозможно определить нужный."); continue; } var priceItem = new PriceItem { RawMaterialId = rawMaterial[0].RawMaterialId, OwnerId = manufacturerId, Date = date, Price = remove ? null : (decimal?)Convert.ToDecimal(prices[i].FixDecimalSeparator()) }; rawMaterial[0].PriceItems = new[] { priceItem }; materials.Add(rawMaterial[0]); } } } } catch (Exception ex) { _logger.Error(ex); errors.Add("Ошибка синтаксического разбора строки."); } return new BulkMaterialParseResult { Errors = errors.ToArray(), Materials = errors.Any() ? new RawMaterial[0] : materials.ToArray() }; }
public RollDictID(IHasTurn hasTurn, RollType rollType) { MyHasTurn = hasTurn; MyRollType = rollType; }
private void GetPPAndOSRollData(ref string PPBranch, ref string OSBranch, ref RollType rt, ref bool cancel){ const string PP_CVS_BRANCH = "PP CVS Branch"; const string OS_CVS_BRANCH = "OS CVS Branch"; const string ROLL_CODE_TO = "Roll code to:"; const string REMOTE_UAT_ROLL = "Remote UAT Site"; const string LOCAL_UAT_ROLL = "Local UAT Site"; string rollType = ""; rt = RollType.Local_UAT; // Compiler wants a default ComboBox cbo = new ComboBox(); cbo.Name = ROLL_CODE_TO; cbo.DropDownStyle = ComboBoxStyle.DropDownList; cbo.Items.Add(LOCAL_UAT_ROLL); cbo.Items.Add(REMOTE_UAT_ROLL); InputModal im = new InputModal("Enter Branches for this roll", PP_CVS_BRANCH, OS_CVS_BRANCH); im.AddToPanel(cbo); ((TextBox)im.AnswerTable[PP_CVS_BRANCH]).Text = "HEAD"; ((TextBox)im.AnswerTable[OS_CVS_BRANCH]).Text = "HEAD"; if (im.ShowDialog(this) == DialogResult.OK){ PPBranch = im.Answer(PP_CVS_BRANCH); OSBranch = im.Answer(OS_CVS_BRANCH); rollType = im.Answer(ROLL_CODE_TO); if (rollType == REMOTE_UAT_ROLL) rt = RollType.Remote_UAT; else if (rollType == LOCAL_UAT_ROLL) rt = RollType.Local_UAT; cancel = false; }else{ cancel = true; } }
public BulkProductParseResult ParseExtraPricesBulk( int manufacturerId, int supplierId, DateTime date, AlloyType alloyType, RollType rollType, int priceExtraCategoryId, bool remove, string raw) { var products = new List <Product>(); var errors = new List <string>(); if (remove) { raw = "0"; } try { var lines = raw.Split(new [] { '\n' }, StringSplitOptions.RemoveEmptyEntries); var headers = lines[0].Split('\t'); using (var storage = new Storage()) { if (lines.Length == 1 && headers.Length == 1) { var price = Convert.ToDecimal(raw.Trim().FixDecimalSeparator()); return(new BulkProductParseResult { Errors = new string[0], Products = storage .Products .Where( p => p.ManufacturerId == manufacturerId && p.RawMaterial.ManufacturerId == supplierId && (alloyType == AlloyType.Undefined || p.RawMaterial.RawMaterialType.AlloyType == alloyType) && (rollType == RollType.Undefined || p.RawMaterial.RawMaterialType.RollType == rollType) ) .ToList() .Select( p => { p.PriceExtras = new[] { new PriceExtra { PriceExtraCategoryId = priceExtraCategoryId, PriceItems = new[] { new PriceItem { Date = date, OwnerId = manufacturerId, Price = price, } } } }; return p; }) .ToArray() }); } for (int lineId = 1; lineId < lines.Length; lineId++) { var prices = lines[lineId].Split('\t'); var productName = prices[0].Trim(); for (int colId = 1; colId < headers.Length; colId++) { var thickness = Convert.ToDecimal(headers[colId].FixDecimalSeparator()); var query = storage .RawMaterials .LoadWith(rm => rm.RawMaterialType) .Where( rm => rm.ManufacturerId == supplierId && rm.RawMaterialType.Thickness == thickness); if (alloyType != AlloyType.Undefined) { query = query.Where(rm => rm.RawMaterialType.AlloyType == alloyType); } if (rollType != RollType.Undefined) { query = query.Where(rm => rm.RawMaterialType.RollType == rollType); } var rawMaterials = query.ToList(); if (!rawMaterials.Any()) { errors.Add($"Выбранный поставщик не производит материала с такими параметрами и толщиной {thickness}"); continue; } foreach (var rawMaterial in rawMaterials) { var product = storage .Products .SingleOrDefault( p => p.ManufacturerId == manufacturerId && p.RawMaterialId == rawMaterial.RawMaterialId && p.Name == productName); if (null == product) { product = new Product { ManufacturerId = manufacturerId, RawMaterialId = rawMaterial.RawMaterialId, Thickness = rawMaterial.RawMaterialType.Thickness, Name = productName, }; } var priceExtra = new PriceExtra { PriceExtraCategoryId = priceExtraCategoryId, ProductId = product.ProductId, }; var price = string.IsNullOrEmpty(prices[colId]) ? null : (decimal?)Convert.ToDecimal(prices[colId].FixDecimalSeparator()); var priceItem = new PriceItem { OwnerId = manufacturerId, Date = date, Price = remove ? null : price, }; priceExtra.PriceItems = new[] { priceItem }; product.PriceExtras = new[] { priceExtra }; products.Add(product); if (!string.IsNullOrEmpty(prices[colId])) { } } } } } } catch (Exception ex) { _logger.Error(ex); errors.Add("Ошибка синтаксического разбора строки."); } return(new BulkProductParseResult { Errors = errors.ToArray(), Products = errors.Any() ? new Product[0] : products.ToArray() }); }
public void Load(MySqlDataReader dr) { Setup(); SetId(Convert.ToInt32(dr["Id"])); if (dr.GetSchemaTable().Select("ColumnName = 'text'").Length == 1) // Check the schema to determine if the "text" column is in it. this._text = Convert.ToString(dr["text"]); this._userEmail = Convert.ToString(dr["userEmail"]); this._rollClass = Convert.ToString(dr["rollClass"]); this._rollType = (RollType)Enum.Parse(Type.GetType("QED.Business.CodePromotion.RollType"), Convert.ToString(dr["rollType"])); if (dr["ts"] != DBNull.Value) this._dateTime = Convert.ToDateTime(dr["ts"]); MarkOld(); }
public IEnumerable<ProductExt> FindProducts(int? manufacturerId, string name, decimal? thickness, AlloyType? alloyType, RollType? rollType) { using (var storage = new Storage()) { var query = storage .Products .LoadWith(p => p.Manufacturer) .LoadWith(p => p.RawMaterial.RawMaterialType) .Where(product => true); if (null != manufacturerId) { query = query.Where(product => product.ManufacturerId == manufacturerId.Value); } if (!string.IsNullOrEmpty(name)) { query = query.Where(product => product.Name == name); } if (null != thickness) { query = query.Where(product => product.Thickness == thickness.Value); } if (null != alloyType) { query = query.Where(product => product.RawMaterial.RawMaterialType.AlloyType == alloyType.Value); } if (null != rollType) { query = query.Where(product => product.RawMaterial.RawMaterialType.RollType == rollType.Value); } return query .ToList() .Select(p => new ProductExt { ProductId = p.ProductId, ManufacturerId = p.ManufacturerId, ManufacturerName = p.Manufacturer.Name, RawMaterialTypeId = p.RawMaterial.RawMaterialType.RawMaterialTypeId, RawMaterialTypeName = p.RawMaterial.RawMaterialType.Name, AlloyType = p.RawMaterial.RawMaterialType.AlloyType, RollType = p.RawMaterial.RawMaterialType.RollType, Thickness = p.Thickness, Name = p.Name, }); } }