public void CalculateNetAmount(SalesDetails details)
        {
            int units = details.NoOfUnits;


            if (units <= 5)
            {
                details.NetAmount = 75350 * units;
            }
            else if (units > 5 && units <= 10)
            {
                details.NetAmount = 75350 * units * 0.98;
            }
            else if (units > 10 && units <= 15)
            {
                details.NetAmount = 75350 * units * 0.95;
            }
            else if (units > 15 && units <= 20)
            {
                details.NetAmount = 75350 * units * 0.92;
            }
            else if (units > 20)
            {
                details.NetAmount = 75350 * units * 0.90;
            }

            //AddSalesDetails(details);
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            SalesDetails obj = new SalesDetails();

            Console.WriteLine("Enter sales id ");
            obj.SalesId = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter customer name ");
            obj.CustomerName = Console.ReadLine();

            Console.WriteLine("Enter the number of units sold");
            obj.NoOfUnits = int.Parse(Console.ReadLine());



            Metalapps app = new Metalapps();

            app.CalculateNetAmount(obj);
            app.AddSalesDetails(obj);

            Console.WriteLine("Sales Bill ");
            Console.WriteLine("***********");
            Console.WriteLine("Sales Id : " + obj.SalesId);
            Console.WriteLine("Customer Name : " + obj.CustomerName);
            Console.WriteLine("Number of Units Sold : " + obj.NoOfUnits);
            Console.WriteLine("Net Amount : " + obj.NetAmount);
            //List<SalesDetails> l1 = new List<SalesDetails>();
            //l1=app.geList();
            //foreach (var item in l1)
            //{
            //    Console.WriteLine($"Sales Details of ID {((SalesDetails)item).SalesId} with name {((SalesDetails)item).CustomerName} has bought {((SalesDetails)item).NoOfUnits} with total of {((SalesDetails)item).NetAmount}");
            //}
            //Console.ReadKey();
        }
Exemple #3
0
        static void Main(string[] args) //DO NOT change the 'Main' method signature
        {
            //Implement the code here
            int    salesId, NoOfUnits;
            string customerName;

            Console.WriteLine("Enter sales id");
            salesId = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter customer name");
            customerName = Console.ReadLine();
            Console.WriteLine("Enter the number of units sold");
            NoOfUnits = int.Parse(Console.ReadLine());
            try
            {
                SalesDetails sd = new SalesDetails(salesId, customerName, NoOfUnits, 0);
                Metalapps    mp = new Metalapps();
                mp.CalculateNetAmount(sd);
                mp.AddSalesDetails(sd);
                Console.WriteLine("Sales Bill\n***********\n");
                Console.WriteLine("Sales Id:" + sd.SalesId);
                Console.WriteLine("Customer Name :" + sd.CustomerName);
                Console.WriteLine("Number of Units Sold :" + sd.NoOfUnits);
                Console.WriteLine("Net Amount :" + sd.NetAmount);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine(e);
            }
            Console.ReadLine();
        }
Exemple #4
0
        public void CalculateNetAmount(SalesDetails details)
        {
            //((75, 350 * 8) - (75, 350 * 8) * 2 %)
            double dis   = 0;
            int    units = details.NoOfUnits;

            if (units > 20)
            {
                dis = 0.1;
            }
            else if (units > 15 && units <= 20)
            {
                dis = 0.08;
            }
            else if (units > 10 && units <= 15)
            {
                dis = 0.05;
            }
            else if (units > 5 && units <= 10)
            {
                dis = 0.02;
            }
            else
            {
                dis = 0;
            }
            details.NetAmount = ((75350 * units) - (75350 * units) * dis);
        }
Exemple #5
0
        public void AddSalesDetails(SalesDetails sd)
        {
            string insertSales = "insert into SalesDetails values(@SalesId,@Customer_name,@Noof_units,@Net_amount)";

            try
            {
                using (SqlCon = db.GetConnection())
                {
                    using (SqlCommand cmdinsertSales = new SqlCommand(insertSales, SqlCon))
                    {
                        SqlCon.Open();
                        cmdinsertSales.Parameters.AddWithValue("@SalesId", sd.SalesId);
                        cmdinsertSales.Parameters.AddWithValue("@Customer_name", sd.CustomerName);
                        cmdinsertSales.Parameters.AddWithValue("@Noof_units", sd.NoOfUnits);
                        cmdinsertSales.Parameters.AddWithValue("@Net_amount", sd.NetAmount);
                        cmdinsertSales.ExecuteNonQuery();
                        SqlCon.Close();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        /*
         * public List<SalesDetails> geList()
         * {
         *  try
         *  {
         *      SqlCon = db.GetConnection();
         *
         *      SqlCon.Open();
         *      SqlCommand cmd = new SqlCommand("select * from  SalesDetails order by Sales_id", SqlCon);
         *      SqlDataReader reader = cmd.ExecuteReader();
         *      List<SalesDetails> l1 = new List<SalesDetails>();
         *      while (reader.Read())
         *      {
         *          SalesDetails sd1 = new SalesDetails();
         *          sd1.SalesId = Convert.ToInt32(reader[0]);
         *          sd1.CustomerName = reader[1].ToString();
         *          sd1.NoOfUnits = Convert.ToInt32(reader[2]);
         *          sd1.NetAmount = Convert.ToDouble(reader[3]);
         *          l1.Add(sd1);
         *      }
         *
         *
         *      SqlCon.Close();
         *      return l1;
         *  }
         *  catch(Exception e)
         *  {
         *      Console.WriteLine("Error : "+e.Message);
         *  }
         *  return null;
         * }*/
        public void AddSalesDetails(SalesDetails sd)
        {
            SqlCon = db.GetConnection();

            SqlCon.Open();

            SqlCommand cmd = new SqlCommand("insert into SalesDetails values(@Sales_id,@Customer_name,@Noof_units,@Net_amount)", SqlCon);

            cmd.Parameters.AddWithValue("@Sales_id", sd.SalesId);
            cmd.Parameters.AddWithValue("@Customer_name", sd.CustomerName);
            cmd.Parameters.AddWithValue("@Noof_units", sd.NoOfUnits);
            cmd.Parameters.AddWithValue("@Net_amount", Convert.ToInt32(sd.NetAmount));
            cmd.ExecuteNonQuery();


            SqlCon.Close();
        }