public bool RutTien(double SoThe, double SoTien) { try { AccountDTO account = AccountDAO.Account.getByAccountNo(SoThe); // lấy thông tin account theo số thẻ cardDTO Card = cardDAO.Card.getByAccountID(account.AcountID); // lấy thông tin thẻ theo accoutID LogDTO model = new LogDTO(); model.Amount = SoTien; // số tiền giao dịch model.CardNo = Card.CardNo; // số thẻ chuyển tiền = số thẻ rút tiền model.CardToNo = Card.CardNo; // số thẻ nhận tiền = số thẻ rút tiền model.LogDate = DateTime.Now; // thời gian giao dịch (lấy ngày giờ hiện tại) model.LogTypeID = 4; // gán kiểu giao dịch là rút tiền tại cây atm Random rnd = new Random(); // khởi tạo hàm random model.ATMID = rnd.Next(1, 11); // random ID máy atm model.Details = "Rút tiền từ cây ATM với số tiền là: " + SoThe.ToString("0,000"); //nội dung rút tiền // tạo cậu sql command để insert object ghi log bên trên vào DB var query = "insert into tbl_Log (LogTypeID,CardNo,ATMID,LogDate,Amount,Details,CardToNo) values(" + model.LogTypeID + "," + model.CardNo + "," + model.ATMID + ",'" + model.LogDate + "'," + model.Amount + ",'" + model.Details + "'," + model.CardToNo + ")"; //thực hiện cậu query insert vào Database SQLConnect.Instance.ExecuteNonQuery(query); return(true); } catch (Exception) { return(false); } }
public bool ChuyenTien(double fromthe, double tothe, double sotien, string details) { try { AccountDTO account = AccountDAO.Account.getByAccountNo(fromthe); // lấy thông tin account theo số thẻ cardDTO Card = cardDAO.Card.getByAccountID(account.AcountID); // lấy thông tin thẻ theo accoutID //tạo object để ghi log LogDTO model = new LogDTO(); model.Amount = sotien; // số tiền giao dịch model.CardNo = Card.CardNo; // số thẻ chuyển tiền đi model.CardToNo = tothe; // số thẻ nhận tiền model.LogDate = DateTime.Now; // thời gian giao dịch (lấy ngày giờ hiện tại) model.LogTypeID = 1; // gán kiểu giao dịch là giao dịch tại cây atm Random rnd = new Random(); // khởi tạo hàm random model.ATMID = rnd.Next(1, 11); // random ID máy atm model.Details = fromthe + " to " + tothe + ": " + details; // nội dung giao dịch // tạo cậu sql command để insert object ghi log bên trên vào DB var query = "insert into tbl_Log (LogTypeID,CardNo,ATMID,LogDate,Amount,Details,CardToNo) values(" + model.LogTypeID + "," + model.CardNo + "," + model.ATMID + ",'" + model.LogDate + "'," + model.Amount + ",'" + model.Details + "'," + model.CardToNo + ")"; //thực hiện cậu query insert vào Database SQLConnect.Instance.ExecuteNonQuery(query); return(true); } catch (Exception) { return(false); } }
public cardDTO getByAccountID(int AccountID) { //lấy thông tin account theo accountID DataTable data = SQLConnect.Instance.ExecuteQuery("select * from tbl_Card where AcountID ='" + AccountID + "'"); cardDTO model = new cardDTO(); //object trả ra if (data.Rows.Count > 0) { model = convertToObject(data).FirstOrDefault();//convert về dạng object } return(model); }
public DataTable get5Row(double sothe) { //lấy ra 5 giao dịch gần nhất AccountDTO account = AccountDAO.Account.getByAccountNo(sothe); // lấy thông tin account theo số thẻ cardDTO card = cardDAO.Card.getByAccountID(account.AcountID); // lấy thông tin thẻ theo accoutID //câu sql lấy ra toàn bộ giao dịch theo số thẻ được sắp xếp ngược theo LogDate var query = "select * from tbl_Log where Cardno = " + card.CardNo + " order by LogDate desc"; //thực hiện câu lênh query bên trên DataTable data = SQLConnect.Instance.ExecuteQuery(query); return(data); }
public List <cardDTO> convertToObject(DataTable input) { //hàm convert từ DataTable sang list<object> List <cardDTO> output = new List <cardDTO>(); foreach (DataRow dr in input.Rows) { cardDTO obj = new cardDTO(); obj.CardNo = Convert.ToInt32(dr["CardNo"]); obj.AcountID = Convert.ToInt32(dr["AcountID"]); obj.PIN = Convert.ToInt32(dr["PIN"]); obj.StartDate = Convert.ToDateTime(dr["StartDate"]); obj.ExpiredDate = Convert.ToDateTime(dr["ExpiredDate"]); obj.Attempt = Convert.ToInt32(dr["Attempt"]); obj.Status = Convert.ToInt32(dr["Status"]); output.Add(obj); } return(output); }
public List <LogDTO> get5Rows(double sothe) { //lấy ra 5 giao dịch gần nhất AccountDTO account = AccountDAO.Account.getByAccountNo(sothe); // lấy thông tin account theo số thẻ cardDTO card = cardDAO.Card.getByAccountID(account.AcountID); // lấy thông tin thẻ theo accoutID //câu sql lấy ra toàn bộ giao dịch theo số thẻ được sắp xếp ngược theo LogDate var query = "select * from tbl_Log where Cardno = " + card.CardNo + " order by LogDate desc"; //thực hiện câu lênh query bên trên DataTable data = SQLConnect.Instance.ExecuteQuery(query); //tạo list<object> để trả ra List <LogDTO> model = new List <LogDTO>(); //check nếu có bản ghi trả ra thì convert từ DataTable về list<object> if (data.Rows.Count > 0) { model = convertToObject(data).Take(5).OrderBy(x => x.LogDate).ToList();// lấy ra 5 bản ghi và sắp xếp lại theo LogDate } return(model); }