Exemplo n.º 1
0
        public void CalculateBillsFromFile()
        {
            //sử dụng FileHelper để
            //tính các bill từ file
            //ghi các bill vào database
            //gửi email nhắc nhở đóng tiền
            //làm mới file

            PhoneChargesCalculator calculator = new PhoneChargesCalculator();

            //tính các bill từ file
            IList <FileLine> lineList = FileHelper.ReadFromFile();
            var billDict = new Dictionary <int, Bill>();

            foreach (FileLine line in lineList)
            {
                if (billDict.ContainsKey(line.SIMId))
                {
                    billDict[line.SIMId].Value +=
                        decimal.Parse(calculator.Calculate(line.StartingTime, line.EndingTime).ToString());
                }
                else
                {
                    Bill bill = new Bill
                    {
                        SIMId    = line.SIMId,
                        BillDate = DateTime.Now,
                        Value    = decimal.Parse(calculator.Calculate(line.StartingTime, line.EndingTime).ToString())
                    };
                    billDict[line.SIMId] = bill;
                }
            }

            //làm mới file
            FileHelper.EraseFile();

            //ghi các bill vào database
            //gửi email nhắc nhở đóng tiền
            foreach (var dictItem in billDict)
            {
                AddBill(dictItem.Value);
                string message = "Hãy thanh toán cước điện thoại hàng tháng trị giá " +
                                 dictItem.Value.Value +
                                 " trước 30 ngày kể từ ngày " +
                                 dictItem.Value.BillDate;
                EmailSender.SendMessage(context.SIMs.Find(dictItem.Key).Customer.Email, message);
            }
        }
Exemplo n.º 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            DateTime a, b;

            if (dataGridView1.CurrentCell != null)
            {
                int    id   = int.Parse(dataGridView1.CurrentCell.OwningRow.Cells[0].Value.ToString());
                int    at   = dataGridView1.CurrentCell.RowIndex;
                double tong = 0;
                PhoneChargesCalculator why = new PhoneChargesCalculator();
                Bill biru = BillExtensionMethod.ConvertToBill(billViews[at]);
                PhoneCallsRepository prep      = new PhoneCallsRepository();
                List <PhoneCall>     phonelist = prep.FindSimID(int.Parse(billViews[at].SIMId));
                for (int i = 0; i < phonelist.Count; i++)
                {
                    a     = phonelist[i].StartingTime;
                    b     = phonelist[i].EndingTime;
                    tong += why.Calculate(a, b);
                }
                biru.Value = decimal.Parse(tong.ToString());
            }
        }