public void GetParameter() { SqlType type = new SqlMoney(5.27m, ParameterDirection.Input); TestHelper.AssertSqlParameter(type.GetParameter(), SqlDbType.Money, 5.27m); type = new SqlMoney(null, ParameterDirection.Input); TestHelper.AssertSqlParameter(type.GetParameter(), SqlDbType.Money, DBNull.Value); }
public void GetRawValue() { SqlType type = new SqlMoney(5.27m, ParameterDirection.Input); Assert.AreEqual(5.27m, type.GetRawValue()); type = new SqlMoney(null, ParameterDirection.Input); Assert.Null(type.GetRawValue()); }
public void CreateMetaData() { Assert.Throws<TypeCannotBeUsedAsAClrTypeException>(() => SqlMoney.GetTypeHandler().CreateMetaData(null)); SqlTypeHandler col = new SqlMoney(5.27m, ParameterDirection.Input); var meta = col.CreateMetaData("Test"); Assert.AreEqual(SqlDbType.Money, meta.SqlDbType); Assert.AreEqual("Test", meta.Name); }
public void DecimalToSqlMoney() { decimal TestDecimal = 1e10m; decimal TestDecimal2 = 1e20m; Assert.AreEqual(10000000000.0000M, ((SqlMoney)TestDecimal).Value, "#W01"); try { SqlMoney test = (SqlMoney)TestDecimal2; Assert.Fail("#W02"); } catch (Exception e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "#W03"); } }
public void SendMoneyTo(AClient client, SqlMoney money) { try { WithdrawMoney(money); client.InputMoney(money); MoneySent?.Invoke(this, client, money); } catch (NotEnoughtMoneyExeption) { var msg = $"У Клиента{this}\nНедостаточно средств, \nдля перевода клиенту{client}"; NotEnoughMoney?.Invoke(msg); } }
public int MakePayment(SqlMoney money) { try { var res = WithdrawMoney(money); return(res); } catch (NotEnoughtMoneyExeption) { var msg = $"У Клиента{this}\nНедостаточно средств, \nдля платы по кредиту."; NotEnoughMoney?.Invoke(msg); return(-1); } }
public void SqlSingleToSqlMoney() { SqlSingle TestSingle = new SqlSingle(1e10); SqlSingle TestSingle2 = new SqlSingle(1e20); Assert.AreEqual(10000000000.0000m, ((SqlMoney)TestSingle).Value, "#U01"); try { SqlMoney test = (SqlMoney)TestSingle2; Assert.Fail("#U02"); } catch (Exception e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "#U03"); } }
public void Greaters() { // GreateThan () Assert.IsTrue(!SqlMoney.GreaterThan(Test1, Test2).Value, "#I01"); Assert.IsTrue(SqlMoney.GreaterThan(Test2, Test1).Value, "#I02"); Assert.IsTrue(!SqlMoney.GreaterThan(Test2, Test3).Value, "#I03"); Assert.IsTrue(SqlMoney.GreaterThan(Test2, SqlMoney.Null).IsNull, "#I04"); // GreaterTharOrEqual () Assert.IsTrue(!SqlMoney.GreaterThanOrEqual(Test1, Test2).Value, "#I05"); Assert.IsTrue(SqlMoney.GreaterThanOrEqual(Test2, Test1).Value, "#I06"); Assert.IsTrue(SqlMoney.GreaterThanOrEqual(Test3, Test2).Value, "#I07"); Assert.IsTrue(SqlMoney.GreaterThanOrEqual(Test3, SqlMoney.Null).IsNull, "#I08"); }
public void Lessers() { // LessThan() Assert.IsTrue(!SqlMoney.LessThan(Test2, Test3).Value, "#J01"); Assert.IsTrue(!SqlMoney.LessThan(Test2, Test1).Value, "#J02"); Assert.IsTrue(SqlMoney.LessThan(Test1, Test2).Value, "#J03"); Assert.IsTrue(SqlMoney.LessThan(SqlMoney.Null, Test2).IsNull, "#J04"); // LessThanOrEqual () Assert.IsTrue(SqlMoney.LessThanOrEqual(Test1, Test2).Value, "#J05"); Assert.IsTrue(!SqlMoney.LessThanOrEqual(Test2, Test1).Value, "#J06"); Assert.IsTrue(SqlMoney.LessThanOrEqual(Test2, Test2).Value, "#J07"); Assert.IsTrue(SqlMoney.LessThanOrEqual(Test2, SqlMoney.Null).IsNull, "#J08"); }
public void Greaters() { // GreateThan () Assert.True(!SqlMoney.GreaterThan(_test1, _test2).Value); Assert.True(SqlMoney.GreaterThan(_test2, _test1).Value); Assert.True(!SqlMoney.GreaterThan(_test2, _test3).Value); Assert.True(SqlMoney.GreaterThan(_test2, SqlMoney.Null).IsNull); // GreaterTharOrEqual () Assert.True(!SqlMoney.GreaterThanOrEqual(_test1, _test2).Value); Assert.True(SqlMoney.GreaterThanOrEqual(_test2, _test1).Value); Assert.True(SqlMoney.GreaterThanOrEqual(_test3, _test2).Value); Assert.True(SqlMoney.GreaterThanOrEqual(_test3, SqlMoney.Null).IsNull); }
public void SqlStringToSqlMoney() { SqlString TestString = new SqlString("Test string"); SqlString TestString100 = new SqlString("100"); Assert.AreEqual(100.0000M, ((SqlMoney)TestString100).Value, "#V01"); try { SqlMoney test = (SqlMoney)TestString; Assert.Fail("#V02"); } catch (Exception e) { Assert.AreEqual(typeof(FormatException), e.GetType(), "#V03"); } }
public void Lessers() { // LessThan() Assert.False(SqlMoney.LessThan(_test2, _test3).Value); Assert.False(SqlMoney.LessThan(_test2, _test1).Value); Assert.True(SqlMoney.LessThan(_test1, _test2).Value); Assert.True(SqlMoney.LessThan(SqlMoney.Null, _test2).IsNull); // LessThanOrEqual () Assert.True(SqlMoney.LessThanOrEqual(_test1, _test2).Value); Assert.False(SqlMoney.LessThanOrEqual(_test2, _test1).Value); Assert.True(SqlMoney.LessThanOrEqual(_test2, _test2).Value); Assert.True(SqlMoney.LessThanOrEqual(_test2, SqlMoney.Null).IsNull); }
public void SqlMoneyToSqlInt16() { SqlMoney TestMoney64 = new SqlMoney(64); SqlMoney TestMoney900 = new SqlMoney(90000); Assert.AreEqual((short)64, ((SqlInt16)TestMoney64).Value, "Test#1"); try { SqlInt16 test = (SqlInt16)TestMoney900; Assert.Fail("Test#2"); } catch (OverflowException e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "test#3"); } }
public override object ConvertXmlToObject(string s) { SqlMoney newValue = default; string tempStr = string.Concat("<col>", s, "</col>"); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); IXmlSerializable tmp = newValue; using (XmlTextReader xmlTextReader = new XmlTextReader(strReader)) { tmp.ReadXml(xmlTextReader); } return((SqlMoney)tmp); }
public void SqlMoneyToSqlByte() { SqlMoney TestMoney64 = new SqlMoney(64); SqlMoney TestMoney900 = new SqlMoney(900); Assert.AreEqual((byte)64, ((SqlByte)TestMoney64).Value, "SqlMoneyToByte" + Error); try { SqlByte test = (SqlByte)TestMoney900; Assert.Fail("SqlMoneyToByte 2" + Error); } catch (Exception e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException"); } }
protected void btnSave_Click(object sender, EventArgs e) { try { BillsServices bills = new BillsServices(); bills.Name = txtBillsServicesName.Text; bills.Description = txtDescription.Text; bills.Quantity = int.Parse(txtQty.Text); bills.Price = SqlMoney.Parse(txtPrice.Text); if (bills.Price <= 0) { lblMsg.Text = "Price cannot be 0 or less."; lblMsg.ForeColor = Color.Red; return; } bills.CreatedUser = Utility.GetUserIdFromUserName(HttpContext.Current.User.Identity.Name); bool retval = false; if (Session["Prop_Action"] == "U") { bills.BillsServices_ID = Int32.Parse(hidBillsID.Value); bills.LastModifiedUser = Utility.GetUserIdFromUserName(HttpContext.Current.User.Identity.Name); bills.LastModifiedDate = DateTime.Now; retval = bills.Update(); } else { bills.CreatedUser = Utility.GetUserIdFromUserName(HttpContext.Current.User.Identity.Name);; bills.CreatedDate = Utility.GetSqlDateTimeFromDateTime(DateTime.Now); retval = bills.Insert(); } lblMsg.Text = "Data Saved successfully."; lblMsg.ForeColor = Color.Green; if (retval) { Response.Redirect("BillsServices.aspx", true); } else { lblMsg.Text = bills.ErrorDesc.ToString(); } } catch (Exception ex) { lblMsg.Text = "Data not Saved ."; lblMsg.ForeColor = Color.Red; } }
protected void btnSave_Click(object sender, EventArgs e) { try { Rates rate = new Rates(); rate.RateType = SqlInt32.Parse(drpRateTypesList.SelectedValue); rate.RateDescription_EN = txtRateNameEn.Text; rate.RateDescription_AR = txtRateNameAr.Text; rate.FromDate = SqlDateTime.Parse(txtFromDate.Text); rate.ToDate = SqlDateTime.Parse(txtToDate.Text); rate.Rate = SqlMoney.Parse(txtRate.Text); if (rate.FromDate > rate.ToDate) { lblMsg.Text = "From Date cannot be after To Date "; lblMsg.ForeColor = Color.Red; return; } rate.LastModifiedUser = 1; rate.LastModifiedDate = SqlDateTime.Parse(DateTime.Now.ToString()); bool retval = false; if (Session["Prop_Action"] == "U") { rate.Rate_ID = Int32.Parse(hidRateId.Value); retval = rate.Update(); } else { rate.CreatedUser = 1; rate.CreatedDate = rate.LastModifiedDate; retval = rate.Insert(); } lblMsg.Text = "Data Saved successfully."; lblMsg.ForeColor = Color.Green; if (retval) { Response.Redirect("RatesList.aspx", true); } else { lblMsg.Text = rate.ErrorDesc.ToString(); } } catch (Exception ex) { lblMsg.Text = "Data not Saved ."; lblMsg.ForeColor = Color.Red; } }
protected void roomTypesList_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "BookNow") { this.RoomType_ID = Convert.ToInt32(e.CommandArgument); } SetSearchCriteria(); if (this.AvailableRooms == null) { this.AvailableRooms = new Bookings().SelectAvailableRooms(this.FromDate, this.ToDate, this.RoomType_ID); } this.RoomType = ((HiddenField)e.Item.FindControl("hidRoomType")).Value; this.Room_ID = SqlInt32.Parse(((HiddenField)e.Item.FindControl("hidRoomId")).Value); this.BookingDays = SqlInt32.Parse(((HiddenField)e.Item.FindControl("hidBookingDays")).Value); this.DiscountOffered = SqlMoney.Parse(((HiddenField)e.Item.FindControl("hidDiscountOffered")).Value); this.Discount_ID = SqlInt32.Parse(((HiddenField)e.Item.FindControl("hidDiscountId")).Value); this.TotalCostAfterDiscount = SqlMoney.Parse(((HiddenField)e.Item.FindControl("hidCostAfterDiscount")).Value); this.TotalCost = SqlMoney.Parse(((HiddenField)e.Item.FindControl("hidTotalCost")).Value); this.Rate = SqlMoney.Parse(((HiddenField)e.Item.FindControl("hidRate")).Value); this.Rate_ID = SqlInt32.Parse(((HiddenField)e.Item.FindControl("hidRateId")).Value); this.RateType = SqlInt32.Parse(((HiddenField)e.Item.FindControl("hidRateType")).Value); //Server.Transfer("confirmreservation.aspx", true); DataTable roomTbl = this.AvailableRooms; Session.Add("AvailableRooms", roomTbl); Session.Add("FromDate", this.FromDate); Session.Add("ToDate", this.ToDate); Session.Add("NumAdults", this.NumAdults); Session.Add("NumKids", this.NumKids); Session.Add("NumRooms", this.NumRooms); Session.Add("RoomType_ID", this.RoomType_ID); Session.Add("RoomType", this.RoomType); Session.Add("BookingDays", this.BookingDays); Session.Add("Room_ID", this.Room_ID); Session.Add("Rate", this.Rate); Session.Add("RateType", this.RateType); Session.Add("Rate_ID", this.Rate_ID); Session.Add("TotalCostAfterDiscount", this.TotalCostAfterDiscount); //Session.Add("TotalCostAfterDiscount", this.TotalCostAfterDiscount); Session.Add("DiscountOffered", this.DiscountOffered); Session.Add("TotalCost", this.TotalCost); Session.Add("Discount_ID", this.Discount_ID); Session.Add("CardType", 1); //Server.Transfer("reservation.aspx", true); Response.Redirect("reservation.aspx", true); }
public static void GetProductsWithPriceGreaterThan(SqlMoney price) { // Create the command SqlCommand myCommand = new SqlCommand(); myCommand.CommandText = @"SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued FROM Products WHERE UnitPrice > @MinPrice"; myCommand.Parameters.AddWithValue("@MinPrice", price); // Execute the command and send back the results SqlContext.Pipe.ExecuteAndSend(myCommand); }
public static void StoredProcedure4(out SqlMoney AVG) { SqlPipe Pipe = SqlContext.Pipe; using (SqlConnection Connection = new SqlConnection("context connection = true")) { Connection.Open(); SqlCommand Command = new SqlCommand(@" SELECT AVG(PaymentCredit) FROM tblPayments", Connection); AVG = new SqlMoney((decimal)Command.ExecuteScalar()); } }
/// <summary> /// /// </summary> /// <param name="s"></param> /// <param name="type"></param> /// <returns></returns> public static PMoney Parse(string s, PValueType type) { PMoney sp; if (string.IsNullOrEmpty(s)) { sp = new PMoney(type); } else { sp = SqlMoney.Parse(s); } return(sp); }
public void SendMoneyTo(AClient client, SqlMoney money) { if (Amount >= money) { WithdrawMoney(money); client.InputMoney(money); MoneySent?.Invoke(this, client, money); } else { var msg = $"У Клиента{this}\nНедостаточно средств, \nдля перевода клиенту{client}"; NotEnoughMoney?.Invoke(msg); } }
public void Accumulate(SqlMoney Value) { if (!Value.IsNull) { this.numValues++; this.totalValue += Value; if (Value < this.minValue) { this.minValue = Value; } if (Value > this.maxValue) { this.maxValue = Value; } } }
public void SqlDecimalToSqlMoney() { SqlDecimal TestDecimal = new SqlDecimal(4000); SqlDecimal TestDecimal2 = new SqlDecimal(1E+20); SqlMoney TestMoney = (SqlMoney)TestDecimal; Assert.AreEqual(4000.0000M, TestMoney.Value, "#R01"); try { SqlMoney test = (SqlMoney)TestDecimal2; Assert.Fail("#R02"); } catch (Exception e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "#R03"); } }
public void SqlDoubleToSqlMoney() { SqlDouble TestDouble = new SqlDouble(1E+9); SqlDouble TestDouble2 = new SqlDouble(1E+20); SqlMoney TestMoney = (SqlMoney)TestDouble; Assert.AreEqual(1000000000.0000m, TestMoney.Value, "#S01"); try { SqlMoney test = (SqlMoney)TestDouble2; Assert.Fail("#S02"); } catch (Exception e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "#S03"); } }
public static SqlInt32 CalculateDeposit(SqlMoney start, SqlDouble percent, SqlMoney add, SqlMoney all) { var s = start.Value; var p = Convert.ToDecimal(percent.Value); var a = add.Value; var end = all.Value; int m = 0; while (s < end) { s += s * (p / 1200) + a; m++; } return(new SqlInt32(m)); }
public void Accumulate(SqlMoney Value) { if (!Value.IsNull) { count += 1; total += Value; if (Value < min) { min = Value; } if (Value > max) { max = Value; } } }
public void ArithmeticMethods() { SqlMoney TestMoney2 = new SqlMoney(2); // Add Assert.AreEqual((SqlMoney)96464.6464m, SqlMoney.Add(Test1, Test2), "#D01"); Assert.AreEqual((SqlMoney)180000m, SqlMoney.Add(Test2, Test2), "#D02"); Assert.AreEqual((SqlMoney)45000m, SqlMoney.Add(Test2, Test4), "#D03"); try { SqlMoney test = SqlMoney.Add(SqlMoney.MaxValue, Test2); Assert.Fail("#D04"); } catch (Exception e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "#D05"); } // Divide Assert.AreEqual((SqlMoney)45000m, SqlMoney.Divide(Test2, TestMoney2), "#D06"); try { SqlMoney test = SqlMoney.Divide(Test2, SqlMoney.Zero); Assert.Fail("#D07"); } catch (Exception e) { Assert.AreEqual(typeof(DivideByZeroException), e.GetType(), "#D08"); } // Multiply Assert.AreEqual((SqlMoney)581818176m, SqlMoney.Multiply(Test1, Test2), "#D09"); Assert.AreEqual((SqlMoney)(-4050000000m), SqlMoney.Multiply(Test3, Test4), "#D10"); try { SqlMoney test = SqlMoney.Multiply(SqlMoney.MaxValue, Test2); Assert.Fail("#D11"); } catch (Exception e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "#D12"); } // Subtract Assert.AreEqual((SqlMoney)0m, SqlMoney.Subtract(Test2, Test3), "#D13"); Assert.AreEqual((SqlMoney)83535.3536m, SqlMoney.Subtract(Test2, Test1), "#D14"); try { SqlMoney test = SqlMoney.Subtract(SqlMoney.MinValue, Test2); } catch (Exception e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "#D15"); } }
public void DecimalToSqlMoney() { decimal TestDecimal = 1e10m; decimal TestDecimal2 = 1e20m; Assert.Equal(10000000000.0000M, ((SqlMoney)TestDecimal).Value); try { SqlMoney test = TestDecimal2; Assert.False(true); } catch (Exception e) { Assert.Equal(typeof(OverflowException), e.GetType()); } }
public void SqlStringToSqlMoney() { SqlString TestString = new SqlString("Test string"); SqlString TestString100 = new SqlString("100"); Assert.Equal(100.0000M, ((SqlMoney)TestString100).Value); try { SqlMoney test = (SqlMoney)TestString; Assert.False(true); } catch (Exception e) { Assert.Equal(typeof(FormatException), e.GetType()); } }
public void SqlSingleToSqlMoney() { SqlSingle TestSingle = new SqlSingle(1e10); SqlSingle TestSingle2 = new SqlSingle(1e20); Assert.Equal(10000000000.0000m, ((SqlMoney)TestSingle).Value); try { SqlMoney test = (SqlMoney)TestSingle2; Assert.False(true); } catch (Exception e) { Assert.Equal(typeof(OverflowException), e.GetType()); } }
public void IntsToSqlMoney() { SqlInt16 TestInt16 = new SqlInt16(5000); SqlInt32 TestInt32 = new SqlInt32(5000); SqlInt64 TestInt64 = new SqlInt64(5000); Assert.AreEqual(5000.0000m, ((SqlMoney)TestInt16).Value, "#Y01"); Assert.AreEqual(5000.0000m, ((SqlMoney)TestInt32).Value, "#Y02"); Assert.AreEqual(5000.0000m, ((SqlMoney)TestInt64).Value, "#Y03"); try { SqlMoney test = (SqlMoney)SqlInt64.MaxValue; Assert.Fail("#Y04"); } catch (Exception e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "#Y05"); } }
public void SqlMoneyToSqlInt16() { SqlMoney TestMoney64 = new SqlMoney(64); SqlMoney TestMoney900 = new SqlMoney(90000); Assert.Equal((short)64, ((SqlInt16)TestMoney64).Value); try { SqlInt16 test = (SqlInt16)TestMoney900; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } }
public void SqlTypes_SqlMoney() { NpgsqlParameter parameter; SqlMoney value = new SqlMoney(45m); #if NET_2_0 parameter = new NpgsqlParameter (); parameter.NpgsqlValue = value; Assert.AreEqual (NpgsqlDbType.Money, parameter.NpgsqlDbType, "#A:NpgsqlDbType"); Assert.AreEqual (value, parameter.NpgsqlValue, "#A:NpgsqlValue"); Assert.AreEqual (value, parameter.Value, "#A:Value"); parameter = new NpgsqlParameter (); parameter.NpgsqlValue = SqlMoney.Null; Assert.AreEqual (NpgsqlDbType.Money, parameter.NpgsqlDbType, "#B:NpgsqlDbType"); Assert.AreEqual (SqlMoney.Null, parameter.NpgsqlValue, "#B:NpgsqlValue"); Assert.AreEqual (SqlMoney.Null, parameter.Value, "#B:Value"); #endif parameter = new NpgsqlParameter(); parameter.Value = value; Assert.AreEqual(NpgsqlDbType.Money, parameter.NpgsqlDbType, "#C:NpgsqlDbType"); #if NET_2_0 Assert.AreEqual (value, parameter.NpgsqlValue, "#C:NpgsqlValue"); #endif Assert.AreEqual(value, parameter.Value, "#C:Value"); }
public static SqlBoolean op_Explicit(SqlMoney x) { if (x.IsNull) return SqlBoolean.Null; return SqlMoney.NotEquals(x, SqlMoney.Zero); }