private void textBoxRealReceived_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { double total = salesList.TotalMoney; double paied = 0; if (!double.TryParse(this.textBoxRealReceived.Text.Trim(), out paied)) { SetNewTip("提示:请在实收款栏输入数字!", this.toolStripStatusLabelTip.Text); return; } paied = Convert.ToDouble(this.textBoxRealReceived.Text); double shouldreturn = paied - total; if (paied >= total) { this.textBoxRealReceived.Text = NumericUtility.ToMoneyFormat(paied); this.textBoxReturnChange.Text = NumericUtility.ToMoneyFormat(shouldreturn); if (this.textBoxVIPCardNo.Text.Trim().Length > 0) { salesList.VipCardNo = Convert.ToInt32(this.textBoxVIPCardNo.Text.Trim()); } salesList.RealReceive = paied; salesList.ReturnMoney = shouldreturn; bComplete = true; } } else if ((e.KeyCode == Keys.F4) || (e.KeyCode == Keys.F5)) { FormBalance_KeyDown(sender, e); } }
public static WordInfo Parse ( [NotNull] JProperty property ) { Code.NotNull(property, "property"); string text = property.Name; string[] parts = text.Split('_'); if (parts.Length != 2) { throw new Exception(); } WordInfo result = new WordInfo { Word = parts[0], PartOfSpeech = parts[1], #if WINMOBILE || PocketPC Value = (float)NumericUtility.ParseDecimal(property.Value) #else Value = property.Value.ToObject <float>() #endif }; return(result); } #endregion #region Object members #endregion }
public static RecordField ParseLine ( [NotNull] string line ) { Sure.NotNullNorEmpty(line, "line"); StringReader reader = new StringReader(line); RecordField result = new RecordField { Tag = NumericUtility.ParseInt32(_ReadTo(reader, '#')), Value = _ReadTo(reader, '^') }; while (true) { int next = reader.Read(); if (next < 0) { break; } char code = char.ToLower((char)next); string text = _ReadTo(reader, '^'); SubField subField = new SubField { Code = code, Value = text }; result.SubFields.Add(subField); } return(result); }
public void NumericUtility_CompressRange_1() { int[] array = { 1, 2, 3, 5, 6, 7 }; Assert.AreEqual("1-3, 5-7", NumericUtility.CompressRange(array)); Assert.AreEqual(string.Empty, NumericUtility.CompressRange(null)); }
public void NumericUtility_SafeToInt32_2() { Assert.AreEqual(123, NumericUtility.SafeToInt32("hello", 123)); Assert.AreEqual(123, NumericUtility.SafeToInt32(null, 123)); Assert.AreEqual(132, NumericUtility.SafeToInt32("132", 123)); Assert.AreEqual(32, NumericUtility.SafeToInt32("32", 123)); }
public void NumericUtility_SafeToDouble_1() { Assert.AreEqual(1.23, NumericUtility.SafeToDouble("hello", 1.23)); Assert.AreEqual(1.23, NumericUtility.SafeToDouble(null, 1.23)); Assert.AreEqual(1.23, NumericUtility.SafeToDouble("hello", 1.23)); Assert.AreEqual(1.32, NumericUtility.SafeToDouble("1.32", 1.23)); }
public void NumericUtility_SafeToDecimal_1() { Assert.AreEqual(1.23m, NumericUtility.SafeToDecimal("hello", 1.23m)); Assert.AreEqual(1.23m, NumericUtility.SafeToDecimal(null, 1.23m)); Assert.AreEqual(1.23m, NumericUtility.SafeToDecimal("hello", 1.23m)); Assert.AreEqual(1.32m, NumericUtility.SafeToDecimal("1.32", 1.23m)); }
protected void SaveSection(int section) { // Clear the section in chunk if it is cleared in this snapshot if (_palette[section] == null || _palette[section].Count == 0) { _chunk._palette[section]?.Clear(); _chunk._palette[section] = null; _chunk._blockStates[section] = null; return; } // It's possible the section has not been created in chunk var oldCellSize = _chunk._blockStates[section] == null ? -1 : _chunk._blockStates[section].CellSize; // Only update the palette when it is changed if (_paletteChanged[section]) { _chunk._palette[section]?.Clear(); _chunk._palette[section] = _palette[section].Clone(); } var newCellSize = Math.Max(4, NumericUtility.GetRequiredBitLength(_palette[section].Count)); if ((newCellSize == oldCellSize) || (!CompactBlockBitsIfPossible && (newCellSize < oldCellSize))) { // Do not create new DynArray if the cellSize doesn't change to improve performance. var dyn = _chunk._blockStates[section]; for (var i = 0; i < 4096; i++) { dyn[i] = _blocks[section][i]; } } else { // Create new DynArray when cellSize is changed var dyn = DynBitArray.CreateEmpty(newCellSize, 4096); for (var i = 0; i < 4096; i++) { // Because the assignment of dynArray[i] can be time-consuming, // index(0) is skipped because DynBitArray.CreateEmpty is guaranteed to create a zero-filled array if (_blocks[section][i] == 0) { continue; } dyn[i] = _blocks[section][i]; } _chunk._blockStates[section]?.Clear(); _chunk._blockStates[section] = dyn; } }
public void NumericUtility_TryParseUInt64_1() { ulong value; Assert.IsTrue(NumericUtility.TryParseUInt64("123", out value)); Assert.AreEqual(123u, value); Assert.IsFalse(NumericUtility.TryParseUInt64("hello", out value)); Assert.IsFalse(NumericUtility.TryParseUInt64(string.Empty, out value)); Assert.IsFalse(NumericUtility.TryParseUInt64(null, out value)); }
public void NumericUtility_TryParseUInt16_1() { ushort value; Assert.IsTrue(NumericUtility.TryParseUInt16("123", out value)); Assert.AreEqual(123, value); Assert.IsFalse(NumericUtility.TryParseUInt16("hello", out value)); Assert.IsFalse(NumericUtility.TryParseUInt16(string.Empty, out value)); Assert.IsFalse(NumericUtility.TryParseUInt16(null, out value)); }
public void NumericUtility_TryParseInt32_1() { int value; Assert.IsTrue(NumericUtility.TryParseInt32("123", out value)); Assert.AreEqual(123, value); Assert.IsFalse(NumericUtility.TryParseInt32("hello", out value)); Assert.IsFalse(NumericUtility.TryParseInt32(string.Empty, out value)); Assert.IsFalse(NumericUtility.TryParseInt32(null, out value)); }
public void NumericUtility_TryParseDecimal_1() { decimal value; Assert.IsTrue(NumericUtility.TryParseDecimal("1.23", out value)); Assert.AreEqual(1.23m, value); Assert.IsFalse(NumericUtility.TryParseDecimal("hello", out value)); Assert.IsFalse(NumericUtility.TryParseDecimal(string.Empty, out value)); Assert.IsFalse(NumericUtility.TryParseDecimal(null, out value)); }
public void NumericTest() { Assert.AreEqual(NumericUtility.GetRequiredBitLength(2), 1); Assert.AreEqual(NumericUtility.GetRequiredBitLength(4), 2); Assert.AreEqual(NumericUtility.GetRequiredBitLength(8), 3); Assert.AreEqual(NumericUtility.GetRequiredBitLength(7), 3); Assert.AreEqual(NumericUtility.GetRequiredBitLength(9), 4); Assert.AreEqual(NumericUtility.GetLeastMultiplication(4096, 4096), 4096); Assert.AreEqual(NumericUtility.GetLeastMultiplication(8192, 4096), 8192); Assert.AreEqual(NumericUtility.GetLeastMultiplication(8191, 4096), 8192); }
private void ResetForm() { // 清空原来的 this.bs.Clear(); // 重新生成一个流水号 this.textBoxSerialNumber.Text = GetNewSerialNumber(); // 清空商品条码、数量、单价、折扣 this.textBoxProductId.Text = string.Empty; this.textBoxCount.Text = "0"; this.textBoxPrice.Text = NumericUtility.ToMoneyFormat(0); this.textBoxDiscount.Text = "0"; }
public void NumericUtility_TryParseFloat_1() { float value; Assert.IsTrue(NumericUtility.TryParseFloat("1.23", out value)); Assert.AreEqual(1.23f, value); Assert.IsTrue(NumericUtility.TryParseFloat("1,23", out value)); Assert.AreEqual(1.23f, value); Assert.IsFalse(NumericUtility.TryParseFloat("hello", out value)); Assert.IsFalse(NumericUtility.TryParseFloat(string.Empty, out value)); Assert.IsFalse(NumericUtility.TryParseFloat(null, out value)); }
public void NumericUtility_TryParseDouble_1() { double value; Assert.IsTrue(NumericUtility.TryParseDouble("1.23", out value)); Assert.AreEqual(1.23, value); Assert.IsTrue(NumericUtility.TryParseDouble("1,23", out value)); Assert.AreEqual(1.23, value); Assert.IsFalse(NumericUtility.TryParseDouble("hello", out value)); Assert.IsFalse(NumericUtility.TryParseDouble(string.Empty, out value)); Assert.IsFalse(NumericUtility.TryParseDouble(null, out value)); }
/// <summary> /// Get 32-bit integer value. /// </summary> public int GetInt32 ( int defaultValue ) { string line = GetAnsiString(); if (!NumericUtility.TryParseInt32(line, out int result)) { result = defaultValue; } return(result); }
/// <summary> /// Get 64-bit integer value /// from application configuration. /// </summary> public static long GetInt64 ( [NotNull] string key, long defaultValue = 0L ) { string setting = CM.AppSettings[key]; if (!NumericUtility.TryParseInt64(setting, out long result)) { result = defaultValue; } return(result); }
/// <summary> /// Get 16-bit integer value from application configuration. /// </summary> public static short GetInt16 ( [NotNull] string key, short defaultValue = 0 ) { string setting = CM.AppSettings[key]; if (!NumericUtility.TryParseInt16(setting, out short result)) { result = defaultValue; } return(result); }
/// <summary> /// Get decimal value from application configuration. /// </summary> public static decimal GetDecimal ( [NotNull] string key, decimal defaultValue = 0.0m ) { string setting = CM.AppSettings[key]; if (!NumericUtility.TryParseDecimal(setting, out decimal result)) { result = defaultValue; } return(result); }
/// <summary> /// Get double-precision float value from application configuration. /// </summary> public static double GetDouble ( [NotNull] string key, double defaultValue = 0.0 ) { string setting = CM.AppSettings[key]; if (!NumericUtility.TryParseDouble(setting, out double result)) { result = defaultValue; } return(result); }
/// <summary> /// Get single-precision float value from application configuration. /// </summary> public static float GetSingle ( [NotNull] string key, float defaultValue = 0.0f ) { string setting = CM.AppSettings[key]; if (!NumericUtility.TryParseFloat(setting, out float result)) { result = defaultValue; } return(result); }
public static ulong GetUInt64 ( [NotNull] string key, ulong defaultValue ) { string s = CM.AppSettings[key]; if (!NumericUtility.TryParseUInt64(s, out ulong result)) { result = defaultValue; } return(result); }
public static uint GetUInt32 ( [NotNull] string key, uint defaultValue = 0 ) { string setting = CM.AppSettings[key]; if (!NumericUtility.TryParseUInt32(setting, out uint result)) { result = defaultValue; } return(result); }
private static string CompressIfPossible ( [NotNull] IEnumerable <string> numbers ) { string[] array1 = numbers.ToArray(); if (array1.All(n => n.IsPositiveInteger())) { int[] array2 = array1.Select(NumericUtility.ParseInt32).ToArray(); Array.Sort(array2); return(NumericUtility.CompressRange(array2)); } return(StringUtility.Join(", ", array1)); }
/// <summary> /// Parse server answer. /// </summary> public static RecordState ParseServerAnswer ( [NotNull] string line ) { Sure.NotNullNorEmpty(line, "line"); // // &uf('G0$',&uf('+0')) // // 0 MFN#STATUS 0#VERSION OTHER // 0 161608#0 0#1 101# // RecordState result = new RecordState(); string[] parts; #if WINMOBILE parts = line.Split(_delimiters); #else parts = line.Split ( _delimiters, StringSplitOptions.RemoveEmptyEntries ); #endif if (parts.Length < 5) { Log.Error ( "RecordState::ParseServerAnswer: " + "bad line format: " + line ); throw new IrbisException("bad line format"); } result.Mfn = NumericUtility.ParseInt32(parts[1]); result.Status = (RecordStatus)NumericUtility.ParseInt32(parts[2]); result.Version = NumericUtility.ParseInt32(parts[4]); return(result); }
public static MagazineInfo FromRecord ( MarcRecord record ) { int marsCode = NumericUtility.ParseInt32(CM.AppSettings["mars-code"]); int marsFlag = NumericUtility.ParseInt32(CM.AppSettings["mars-flag"]); MagazineInfo result = new MagazineInfo { Title = record.FM(200, 'a'), Index = record.FM(903), MarsCode = record.FM(marsCode), Flag = record.FM(marsFlag), Mfn = record.Mfn }; return(result); }
/// <summary> /// Require 32-bit integer. /// </summary> public int RequireInt32() { string line = GetAnsiString(); int result; if (!NumericUtility.TryParseInt32(line, out result)) { Log.Error ( "ServerResponse::RequireInt32: " + "bad format=" + line.ToVisibleString() ); throw new IrbisNetworkException(); } return(result); }
/// <summary> /// Convert string to time. /// </summary> public static TimeSpan ConvertStringToTime ( [CanBeNull] string time ) { if (string.IsNullOrEmpty(time) || time.Length < 4) { return(new TimeSpan()); } int hours = NumericUtility.ParseInt32(time.Substring(0, 2)); int minutes = NumericUtility.ParseInt32(time.Substring(2, 2)); int seconds = time.Length < 6 ? 0 : NumericUtility.ParseInt32(time.Substring(4, 2)); TimeSpan result = new TimeSpan(hours, minutes, seconds); return(result); }
/// <summary> /// Get decimal value from application configuration. /// </summary> public static decimal GetDecimal ( [NotNull] string key, decimal defaultValue ) { #if DROID || ANDROID || UAP return(defaultValue); #else decimal result; string s = CM.AppSettings[key]; if (!NumericUtility.TryParseDecimal(s, out result)) { result = defaultValue; } return(result); #endif }