Пример #1
0
 public void CalculateBill(ElectricityBill ebill)
 {
     if (ebill.UnitsConsumed <= 100)
     {
         ebill.BillAmount = 0;
     }
     else if (ebill.UnitsConsumed > 100 && ebill.UnitsConsumed <= 300)
     {
         ebill.BillAmount = 1.5 * (ebill.UnitsConsumed - 100);
     }
     else if (ebill.UnitsConsumed > 300 && ebill.UnitsConsumed <= 600)
     {
         ebill.BillAmount = 1.5 * (200) +
                            3.5 * (ebill.UnitsConsumed - 300);
     }
     else if (ebill.UnitsConsumed > 600 && ebill.UnitsConsumed <= 1000)
     {
         ebill.BillAmount = 1.5 * (200) +
                            3.5 * (300) +
                            5.5 * (ebill.UnitsConsumed - 600);
     }
     else if (ebill.UnitsConsumed > 1000)
     {
         ebill.BillAmount = 1.5 * (200) +
                            3.5 * (300) +
                            5.5 * (400) +
                            7.5 * (ebill.UnitsConsumed - 1000);
     }
 }
        public void AddBill(ElectricityBill ebill)
        {
            using (MySqlConnection conn = DBHandler.GetConnection())
            {
                using (MySqlCommand command = new MySqlCommand("INSERT INTO electricitybill(consumer_number,consumer_name,units_consumed,bill_amount) VALUES(@consumer_number,@consumer_name,@units_consumed,@bill_amount)", conn))
                {
                    command.Parameters.AddWithValue("consumer_number", ebill.ConsumerNumber);
                    command.Parameters.AddWithValue("consumer_name", ebill.ConsumerName);
                    command.Parameters.AddWithValue("units_consumed", ebill.UnitsConsumed);
                    command.Parameters.AddWithValue("bill_amount", ebill.BillAmount);

                    try
                    {
                        conn.Open();

                        int rowsInserted = command.ExecuteNonQuery();
                    }
                    catch (MySqlException ex)

                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
        public void CalculateBill(ElectricityBill ebill)
        {
            //Console.WriteLine("Units " + ebill.UnitsConsumed);
            if (ebill.UnitsConsumed <= 100)
            {
                ebill.BillAmount = 0;
            }
            else if (ebill.UnitsConsumed > 100 && ebill.UnitsConsumed <= 300)
            {
                int temp = ebill.UnitsConsumed - 100;
                ebill.BillAmount = temp * 1.5;
            }
            else if (ebill.UnitsConsumed > 300 && ebill.UnitsConsumed <= 600)
            {
                int temp200 = ebill.UnitsConsumed - 100;
                int temp300 = temp200 - 200;
                ebill.BillAmount = (200 * 1.5) + (temp300 * 3.5);
            }
            else if (ebill.UnitsConsumed > 600 && ebill.UnitsConsumed <= 1000)
            {
                int temp200 = ebill.UnitsConsumed - 100;
                int temp400 = temp200 - 500;

                ebill.BillAmount = (200 * 1.5) + (300 * 3.5) + (temp400 * 5.5);
            }
            else if (ebill.UnitsConsumed > 1000)
            {
                int temp200 = ebill.UnitsConsumed - 100;
                int temp400 = temp200 - 900;

                ebill.BillAmount = (200 * 1.5) + (300 * 3.5) + (400 * 5.5) + (temp400 * 7.5);
            }
            //Console.WriteLine("Bill Amouont " + ebill.BillAmount);
        }
        public List <ElectricityBill> Generate_N_BillDetails(int num)
        {
            try
            {
                string querystring = "Select TOP " + num + " * from ElectricityBill ORDER BY consumer_number desc";
                SqlCon.Open();
                SqlCommand    cmd    = new SqlCommand(querystring, SqlCon);
                SqlDataReader reader = cmd.ExecuteReader();

                List <ElectricityBill> l1 = new List <ElectricityBill>();

                while (reader.Read())
                {
                    ElectricityBill eb1 = new ElectricityBill();
                    eb1.ConsumerNumber = reader[0].ToString();
                    eb1.ConsumerName   = reader[1].ToString();
                    eb1.UnitsConsumed  = (int)reader[2];
                    eb1.BillAmount     = (double)reader[3];
                    l1.Add(eb1);
                }

                SqlCon.Close();
                //Console.WriteLine("Size "+l1.Count);
                return(l1);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error 1: " + e.Message);
            }
            return(null);
        }
Пример #5
0
        public void CalculateBill(ElectricityBill ebill)
        {
            int    units = ebill.UnitsConsumed;
            double amount;

            if (units <= 100)
            {
                amount = 0;
            }
            else if (units > 100 && units <= 300)
            {
                amount = 100 * 0 + (units - 100) * 1.50;
            }
            else if (units > 300 && units <= 600)
            {
                amount = 100 * 0 + (200 * 1.50) + (units - 300) * 3.50;
            }
            else if (units > 600 && units <= 1000)
            {
                amount = 100 * 0 + (200 * 1.50) + (300 * 3.50) + (units - 600) * 5.50;
            }
            else
            {
                amount = 100 * 0 + (200 * 1.50) + (300 * 3.50) + (600 * 5.50) + (units - 1000) * 7.50;
            }

            ebill.BillAmount = amount;
        }
Пример #6
0
        public void CalculateBill(ElectricityBill ebill)
        {
            int    unitsConsumed = ebill.UnitsConsumed;
            double total         = 0;

            if (unitsConsumed > 1000)
            {
                total        += ((unitsConsumed - 1000) * 7.5);
                unitsConsumed = 1000;
            }
            if (unitsConsumed > 600 && unitsConsumed <= 1000)
            {
                total        += ((unitsConsumed - 600) * 5.5);
                unitsConsumed = 600;
            }
            if (unitsConsumed > 300 && unitsConsumed <= 600)
            {
                total        += ((unitsConsumed - 300) * 3.5);
                unitsConsumed = 300;
            }
            if (unitsConsumed > 100 && unitsConsumed <= 300)
            {
                total += ((unitsConsumed - 100) * 1.5);
            }
            ebill.BillAmount = total;
        }
Пример #7
0
        static void Main(string[] args)
        {
            ElectricityBoard       eb  = null;
            DBHandler              db  = new DBHandler();
            SqlConnection          con = db.GetConnection();
            List <ElectricityBill> l2  = new List <ElectricityBill>();

            Console.WriteLine("Enter Number of Bills To Be Added : ");
            int totBill = Convert.ToInt32(Console.ReadLine());

            for (int cnt = 0; cnt < totBill; cnt++)
            {
                Console.WriteLine("Enter Consumer Numer : ");
                String conNo = Console.ReadLine();
                Console.WriteLine("Enter Consumer Name : ");
                String name = Console.ReadLine();
                Console.WriteLine("Enter Units Consumed : ");
                int units = Convert.ToInt32(Console.ReadLine());

                ElectricityBill ebill = new ElectricityBill();
                try
                {
                    ebill.ConsumerNumber = conNo;
                }
                //catch (InvalidConsumerNumberException e)
                catch (FormatException e)
                {
                    Console.WriteLine(e);
                }
                ebill.ConsumerName  = name;
                ebill.UnitsConsumed = units;

                eb        = new ElectricityBoard();
                eb.SqlCon = con;
                eb.CalculateBill(ebill);
                eb.AddBill(ebill);
                l2.Add(ebill);
            }
            Console.WriteLine();
            Console.Write("Enter Last 'N' Number of Bills To Generate : ");
            int num = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine();
            foreach (var p in l2)
            {
                Console.WriteLine(((ElectricityBill)p).ConsumerNumber);
                Console.WriteLine(((ElectricityBill)p).ConsumerName);
                Console.WriteLine(((ElectricityBill)p).UnitsConsumed);
                Console.WriteLine("Bill Amount: " + ((ElectricityBill)p).BillAmount);
            }

            List <ElectricityBill> l1 = eb.Generate_N_BillDetails(num);

            Console.WriteLine("Details of Bill Generation");
            foreach (var ie in l1)
            {
                Console.WriteLine("EB Bill for " + ((ElectricityBill)ie).ConsumerName + " is " + ((ElectricityBill)ie).BillAmount);
            }
        }
Пример #8
0
        public void AddBill(ElectricityBill ebill)
        {
            SqlCon.Open();

            SqlCommand command = new SqlCommand("insert into ElectricityBill values(@conNumber,@conName,@unitsCon,@billAmount)", SqlCon);

            command.Parameters.AddWithValue("@conNumber", ebill.ConsumerNumber);
            command.Parameters.AddWithValue("@conName", ebill.ConsumerName);
            command.Parameters.AddWithValue("@unitsCon", ebill.UnitsConsumed);
            command.Parameters.AddWithValue("@billAmount", ebill.BillAmount);
            command.ExecuteNonQuery();
        }
Пример #9
0
        //Implement the methods as per the description
        public void AddBill(ElectricityBill ebill)
        {
            DBHandler dBHandler = new DBHandler();

            SqlCon = dBHandler.GetConnection();
            SqlCommand cmd = new SqlCommand("insert into ElectricityBill values(@consumer_number,@consumer_name,@units_consumed,@bill_amount)", SqlCon);

            cmd.Parameters.AddWithValue("@consumer_number", ebill.ConsumerNumber);
            cmd.Parameters.AddWithValue("@consumer_name", ebill.ConsumerName);
            cmd.Parameters.AddWithValue("@units_consumed", ebill.UnitsConsumed);
            cmd.Parameters.AddWithValue("@bill_amount", ebill.BillAmount);
            SqlCon.Open();
            cmd.ExecuteNonQuery();
            SqlCon.Close();
        }
Пример #10
0
        //Implement the property as per the description

        //Implement the methods as per the description
        public void AddBill(ElectricityBill ebill)
        {
            SqlCon = dbhandler.getConnection();
            SqlCon.Open();
            string query = "INSERT INTO ElectricityBill (consumer_number, consumer_name, units_consumed, bill_amount)";

            query += " VALUES (@consumer_number, @consumer_name, @units_consumed, @bill_amount)";
            SqlCommand myCommand = new SqlCommand(query, SqlCon);

            myCommand.Parameters.AddWithValue("@consumer_number", ebill.ConsumerNumber);
            myCommand.Parameters.AddWithValue("@consumer_name", ebill.ConsumerName);
            myCommand.Parameters.AddWithValue("@units_consumed", ebill.UnitsConsumed);
            myCommand.Parameters.AddWithValue("@bill_amount", ebill.BillAmount);
            myCommand.ExecuteNonQuery();
            SqlCon.Close();
        }
 public void AddBill(ElectricityBill eb)
 {
     try
     {
         string querystring = "insert into ElectricityBill values('" + eb.ConsumerNumber + "','" + eb.ConsumerName + "'," + eb.UnitsConsumed + "," + eb.BillAmount + ")";
         //Console.Write("query " + querystring);
         SqlCon.Open();
         SqlCommand    cmd    = new SqlCommand(querystring, SqlCon);
         SqlDataReader reader = cmd.ExecuteReader();
         SqlCon.Close();
     }
     catch (Exception e)
     {
         Console.WriteLine("Error : " + e.Message);
     }
 }
        public void CalculateBill(ElectricityBill ebill)
        {
            int tempUnits = 0, billTotal = 0;


            if (ebill.UnitsConsumed > 1000)
            {
                tempUnits = ebill.UnitsConsumed - 1000;

                billTotal = Convert.ToInt32(tempUnits * 7.5);

                billTotal       += Convert.ToInt32(200 * 1.50);
                billTotal       += Convert.ToInt32(300 * 3.50);
                billTotal       += Convert.ToInt32(400 * 5.50);
                ebill.BillAmount = billTotal;
            }
            if (ebill.UnitsConsumed > 600 && ebill.UnitsConsumed <= 1000)
            {
                tempUnits = ebill.UnitsConsumed - 600;

                billTotal += Convert.ToInt32(tempUnits * 5.5);
                billTotal += Convert.ToInt32(300 * 3.5);
                billTotal += Convert.ToInt32(200 * 1.5);

                ebill.BillAmount = billTotal;
            }
            if (ebill.UnitsConsumed > 300 && ebill.UnitsConsumed <= 600)
            {
                tempUnits = ebill.UnitsConsumed - 300;

                billTotal += Convert.ToInt32(tempUnits * 3.5);
                billTotal += Convert.ToInt32(200 * 1.5);

                ebill.BillAmount = billTotal;
            }
            if (ebill.UnitsConsumed > 100 && ebill.UnitsConsumed <= 300)
            {
                tempUnits = ebill.UnitsConsumed - 100;

                ebill.BillAmount += Convert.ToInt32(tempUnits * 1.5);
            }

            if (ebill.UnitsConsumed <= 100)
            {
                ebill.BillAmount = 0;
            }
        }
Пример #13
0
        public List <ElectricityBill> Generate_N_BillDetails(int num)
        {
            List <ElectricityBill> EBillList = new List <ElectricityBill>();
            string query = "select TOP " + num + " * FROM ElectricityBill order by consumer_number desc";

            SqlCon = dbhandler.getConnection();
            SqlCon.Open();
            SqlCommand    myCommand     = new SqlCommand(query, SqlCon);
            SqlDataReader sqlDataReader = myCommand.ExecuteReader();

            while (sqlDataReader.Read())
            {
                ElectricityBill ebil = new ElectricityBill(sqlDataReader["consumer_number"].ToString(), sqlDataReader["consumer_name"].ToString(), int.Parse(sqlDataReader["units_consumed"].ToString()), double.Parse(sqlDataReader["bill_amount"].ToString()));
                EBillList.Add(ebil);
            }
            return(EBillList);
        }
        public List <ElectricityBill> Generate_N_BillDetails(int num)
        {
            string    lastNBills         = "select TOP " + num + "* from ElectricityBill order by consumer_number desc";
            DataTable dt                 = new DataTable();
            List <ElectricityBill> bills = new List <ElectricityBill>();

            try
            {
                using (SqlCon)
                {
                    using (SqlCommand cmdlastNBills = new SqlCommand(lastNBills, SqlCon))
                    {
                        using (SqlDataAdapter da = new SqlDataAdapter(cmdlastNBills))
                        {
                            da.Fill(dt);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    ElectricityBill ebill = new ElectricityBill()
                    {
                        ConsumerNumber = row["consumer_number"].ToString(),
                        ConsumerName   = row["consumer_name"].ToString(),
                        UnitsConsumed  = int.Parse(row["units_consumed"].ToString()),
                        BillAmount     = double.Parse(row["bill_amount"].ToString())
                    };
                    bills.Add(ebill);
                }
            }
            return(bills);
        }
Пример #15
0
        public List <ElectricityBill> Generate_N_BillDetails(int num)
        {
            SqlCon.Open();
            SqlCommand             command          = new SqlCommand("select * from ElectricityBill", SqlCon);
            SqlDataReader          reader           = command.ExecuteReader();
            List <ElectricityBill> electricityBills = new List <ElectricityBill>();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    ElectricityBill eBill = new ElectricityBill();
                    eBill.ConsumerNumber = reader.GetString(0);
                    eBill.ConsumerName   = reader.GetString(1);
                    eBill.UnitsConsumed  = reader.GetInt32(2);
                    eBill.BillAmount     = reader.GetDouble(3);
                    electricityBills.Add(eBill);
                }
            }
            electricityBills = electricityBills.Skip(electricityBills.Count - num).ToList();
            return(electricityBills);
        }
 //Implement the methods as per the description
 public void AddBill(ElectricityBill ebill)
 {
     try
     {
         string insertBill = "insert into ElectricityBill values(@ConsumerNumber,@ConsumerName,@UnitsConsumed,@BillAmount)";
         using (SqlCon)
         {
             using (SqlCommand cmdinsertBill = new SqlCommand(insertBill, SqlCon))
             {
                 SqlCon.Open();
                 cmdinsertBill.Parameters.AddWithValue("@ConsumerNumber", ebill.ConsumerNumber);
                 cmdinsertBill.Parameters.AddWithValue("@ConsumerName", ebill.ConsumerName);
                 cmdinsertBill.Parameters.AddWithValue("@UnitsConsumed", ebill.UnitsConsumed);
                 cmdinsertBill.Parameters.AddWithValue("@BillAmount", ebill.BillAmount);
                 cmdinsertBill.ExecuteNonQuery();
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Error:" + e.Message);
     }
 }
        public void CalculateBill(ElectricityBill ebill)
        {
            double billAmount = 0;
            int    units      = ebill.UnitsConsumed;
            int    temp       = 0;

            if (units > 1000)
            {
                temp        = units - 1000;
                billAmount += ((temp) * 7.5);
                units       = units - temp;
            }
            if (units > 600 && units <= 1000)
            {
                temp        = units - 600;
                billAmount += ((temp) * 5.5);
                units       = units - temp;
            }
            if (units > 300 && units <= 600)
            {
                temp        = units - 300;
                billAmount += ((temp) * 3.5);
                units       = units - temp;
            }
            if (units > 100 && units <= 300)
            {
                temp        = units - 100;
                billAmount += ((temp) * 1.5);
                units       = units - temp;
            }
            if (units <= 100)
            {
                billAmount += 0;
            }
            ebill.BillAmount = billAmount;
        }
Пример #18
0
        public List <ElectricityBill> Generate_N_BillDetails(int num)
        {
            List <ElectricityBill> ebills = new List <ElectricityBill>();
            DBHandler dBHandler           = new DBHandler();

            SqlCon = dBHandler.GetConnection();
            SqlCon.Open();
            SqlCommand command = new SqlCommand("SELECT * FROM (SELECT TOP " + num + " * FROM ElectricityBill ORDER BY consumer_number DESC)c ORDER BY consumer_number", SqlCon);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    ElectricityBill electricityBill = new ElectricityBill();
                    electricityBill.ConsumerNumber = reader["consumer_number"].ToString();
                    electricityBill.ConsumerName   = reader["consumer_name"].ToString();
                    electricityBill.UnitsConsumed  = (int)reader["units_consumed"];
                    electricityBill.BillAmount     = (double)reader["bill_amount"];
                    ebills.Add(electricityBill);
                }
            }
            SqlCon.Close();
            return(ebills);
        }
Пример #19
0
        static void Main(string[] args) //DO NOT change the 'Main' method signature
        {
            //Implement the code here
            ElectricityBoard eb = null;
            DBHandler        db = new DBHandler();
            int noOfBills;
            List <ElectricityBill> li = new List <ElectricityBill>();

            Console.WriteLine("Enter Number of Bills To Be Added :");
            noOfBills = int.Parse(Console.ReadLine());
            BillValidator b = new BillValidator();

            for (int i = 0; i < noOfBills; i++)
            {
                string consumerNumber, consumerName;
                int    units;
                Console.WriteLine("Enter Consumer Number:");
                consumerNumber = Console.ReadLine();
                Console.WriteLine("Enter Consumer Name:");
                consumerName = Console.ReadLine();
                do
                {
                    Console.WriteLine("Enter Units Consumed:");
                    units = int.Parse(Console.ReadLine());
                    Console.WriteLine(b.ValidateUnitsConsumed(units));
                } while (b.ValidateUnitsConsumed(units) != null);
                ElectricityBill ebill = new ElectricityBill();
                try
                {
                    ebill.ConsumerNumber = consumerNumber;
                    ebill.ConsumerName   = consumerName;
                    ebill.UnitsConsumed  = units;
                }
                catch (FormatException)
                {
                    Console.WriteLine("Invalid Consumer Number");
                    continue;
                }
                eb = new ElectricityBoard();
                eb.CalculateBill(ebill);
                eb.SqlCon = db.GetConnection();
                eb.AddBill(ebill);
                li.Add(ebill);
            }
            eb.SqlCon = db.GetConnection();
            Console.WriteLine();
            Console.WriteLine();
            foreach (var bill in li)
            {
                Console.WriteLine(bill.ConsumerName);
                Console.WriteLine(bill.ConsumerNumber);
                Console.WriteLine(bill.UnitsConsumed);
                Console.WriteLine("Bill Amount:" + bill.BillAmount);
            }
            Console.WriteLine("Enter Last 'N' Number of Bills To Generate:");
            int num = int.Parse(Console.ReadLine());
            List <ElectricityBill> li2 = eb.Generate_N_BillDetails(num);

            Console.WriteLine("Details of last ‘N’ bills:");
            foreach (var j in li2)
            {
                Console.WriteLine("EB Bill for " + j.ConsumerName + " is " + j.BillAmount);
            }
            Console.ReadKey();
        }
Пример #20
0
        static void Main(string[] args) //DO NOT change the 'Main' method signature
        {
            BillValidator          billValidator    = new BillValidator();
            ElectricityBoard       electricityBoard = new ElectricityBoard();
            List <ElectricityBill> tempDisplayList  = new List <ElectricityBill>();

            Console.WriteLine("Enter Number of Bills To Be Added:");
            int numberOfBills = int.Parse(Console.ReadLine());


            for (int i = 1; i <= numberOfBills; i++)
            {
                Console.WriteLine("Enter Consumer Number:");
                string consumerNumber = Console.ReadLine();
                if (Regex.IsMatch(consumerNumber, "EB[0-9]{5}") == false)
                {
                    throw new FormatException("Invalid Consumer Number");
                }
                Console.WriteLine("Enter Consumer Name:");
                string consumerName = Console.ReadLine();

                Console.WriteLine("Enter Units Consumed:");
                int unitsConsumed = int.Parse(Console.ReadLine());

                while (billValidator.ValidateUnitsConsumed(unitsConsumed) != "")
                {
                    Console.WriteLine(billValidator.ValidateUnitsConsumed(unitsConsumed));
                    Console.WriteLine("Enter Units Consumed:");
                    unitsConsumed = int.Parse(Console.ReadLine());
                }

                ElectricityBill electricityBill = new ElectricityBill(consumerNumber, consumerName, unitsConsumed);

                electricityBoard.CalculateBill(electricityBill);
                tempDisplayList.Add(electricityBill);
                electricityBoard.AddBill(electricityBill);
            }

            Console.WriteLine("Enter Last 'N' Number of Bills to Generate");
            int numberofBillsToGenerate = int.Parse(Console.ReadLine());



            foreach (ElectricityBill bill in tempDisplayList)
            {
                Console.WriteLine(bill.ConsumerNumber);
                Console.WriteLine(bill.ConsumerName);
                Console.WriteLine(bill.UnitsConsumed);
                Console.WriteLine("Bill Amount:" + bill.BillAmount);
                Console.WriteLine("");
            }


            List <ElectricityBill> dislpaylist = electricityBoard.Generate_N_BillDetails(numberofBillsToGenerate);

            Console.WriteLine("Details of last 'N' bills:");
            foreach (ElectricityBill bill in dislpaylist)
            {
                Console.WriteLine("EB Bill for " + bill.ConsumerName + " is " + bill.BillAmount);
            }
            Console.ReadKey();
        }
Пример #21
0
        static void Main(string[] args)
        {
            try
            {
                //Implement the code here
                Console.WriteLine("Enter Number of Bills To Be Added : ");
                int           number    = int.Parse(Console.ReadLine());
                string        conNumber = String.Empty;
                string        conName   = String.Empty;
                int           unitsCon;
                string        pattern       = "^EB[0-9]{5}$";
                BillValidator billValidator = new BillValidator();

                for (int i = 0; i < number; i++)
                {
                    Console.WriteLine("Enter Consumer Number:");
                    conNumber = Console.ReadLine();
                    if (!Regex.IsMatch(conNumber, pattern))
                    {
                        throw new FormatException("Invalid Consumer Number");
                    }

                    Console.WriteLine("Enter Consumer Name:");
                    conName = Console.ReadLine();

                    Console.WriteLine("Enter Units Consumed:");
                    unitsCon = int.Parse(Console.ReadLine());

                    while (billValidator.ValidateUnitsConsumed(unitsCon) == "Given units is invalid")
                    {
                        Console.WriteLine("Given units is invalid");
                        Console.WriteLine("Enter Units Consumed:");
                        unitsCon = int.Parse(Console.ReadLine());
                    }

                    ElectricityBill bill = new ElectricityBill(conNumber, conName, unitsCon, 0);

                    ElectricityBoard board = new ElectricityBoard();

                    board.CalculateBill(bill);

                    board.AddBill(bill);
                }
                Console.WriteLine("Enter Last 'N' Number of Bills To Generate:");
                int num = int.Parse(Console.ReadLine());


                ElectricityBoard       electricityBoard = new ElectricityBoard();
                List <ElectricityBill> electricityBills = electricityBoard.Generate_N_BillDetails(num);

                foreach (ElectricityBill bill in electricityBills)
                {
                    Console.WriteLine(bill);
                }

                foreach (ElectricityBill bill in electricityBills)
                {
                    Console.WriteLine($"EB Bill for {bill.ConsumerName} is {bill.BillAmount}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #22
0
        static void Main(string[] args) //DO NOT change the 'Main' method signature
        {
            ElectricityBoard bill      = new ElectricityBoard();
            BillValidator    validator = new BillValidator();

            Console.WriteLine("Enter Number of Bills To Be Added : ");
            int noBills = int.Parse(Console.ReadLine());

            ElectricityBill[] customer = new ElectricityBill[noBills];

            for (int index = 0; index < noBills; index++)
            {
                Console.WriteLine("\nEnter Consumer Number:");
                string number = Console.ReadLine().ToString();
                Regex  regex  = new Regex(@"EB+[0-9]{5}");

                Match match = regex.Match(number);

                if (!(match.Success))
                {
                    throw new FormatException("Invalid Consumer Number");
                }

                Console.WriteLine("Enter Consumer Name:");
                string name = Console.ReadLine().ToString();

                int units = 0;

                while (true)
                {
                    Console.WriteLine("Enter Units Consumed:");
                    units = int.Parse(Console.ReadLine());
                    if (validator.ValidateUnitsConsumed(units) == "1")
                    {
                        break;
                    }
                }
                double amount = 0;

                customer[index] = new ElectricityBill(name, number, units, amount);

                bill.CalculateBill(customer[index]);

                bill.AddBill(customer[index]);
            }

            Console.WriteLine("Enter Last 'N' Number of Bills To Generate:");

            noBills = int.Parse(Console.ReadLine());

            for (int index = 0; index < noBills; index++)
            {
                Console.WriteLine("{0}", customer[index].ConsumerName);
                Console.WriteLine("{0}", customer[index].ConsumerNumber);
                Console.WriteLine("{0}", customer[index].UnitsConsumed);
                Console.WriteLine("{0}", customer[index].BillAmount);
            }

            Console.WriteLine("Details of last ‘N’ bills:");
            List <ElectricityBill> dbPrint = bill.Generate_N_BillDetails(noBills);

            foreach (ElectricityBill item in dbPrint)
            {
                Console.WriteLine("EB Bill for {0} is {1}", item.ConsumerName, item.BillAmount);
            }
        }