public void CalculateNetAmount(SalesDetails details) { float discount = 0; if (details.NoOfUnits <= 5) { discount = 0; } else if (details.NoOfUnits > 5 && details.NoOfUnits <= 10) { discount = .02f; } else if (details.NoOfUnits > 10 && details.NoOfUnits <= 15) { discount = .05f; } else if (details.NoOfUnits > 15 && details.NoOfUnits <= 20) { discount = .08f; } else { discount = .1f; } details.NetAmount = (75350 * details.NoOfUnits) - (75350 * details.NoOfUnits) * discount; }
static void Main(string[] args) { try { Console.WriteLine("SalesId"); int SalesId = Convert.ToInt16(Console.ReadLine()); Console.WriteLine("CustomerName"); string CustomerName = Console.ReadLine(); Console.WriteLine("NoOfUnits"); int NoOfUnit = Convert.ToByte(Console.ReadLine()); if (NoOfUnit < 5) { throw new ArgumentOutOfRangeException("No Sales for units below 5"); } SalesDetails salesDetails = new SalesDetails() { SalesId = SalesId, CustomerName = CustomerName, NoOfUnits = NoOfUnit, NetAmount = 0 }; Metalapps metalapps = new Metalapps(); metalapps.CalculateNetAmount(salesDetails); metalapps.AddSalesDetails(salesDetails); } catch (ArgumentOutOfRangeException obj) { Console.WriteLine(obj.Message); } }
public void AddSalesDetails(SalesDetails sd) { DBHandler dBHandler = new DBHandler(); SqlCon = dBHandler.GetConnection(); SqlCommand sqlCommand = new SqlCommand("Insert into SalesDetails values(@Sales_id, @Customer_name, @No_units, @Net_amount)", SqlCon); sqlCommand.Parameters.AddWithValue("@Sales_id", sd.SalesId); sqlCommand.Parameters.AddWithValue("@Customer_name", sd.CustomerName); sqlCommand.Parameters.AddWithValue("@No_units", sd.NoOfUnits); sqlCommand.Parameters.AddWithValue("@Net_amount", sd.NetAmount); SqlCon.Open(); sqlCommand.ExecuteNonQuery(); SqlCon.Close(); sqlCommand.Dispose(); SqlCon.Dispose(); }