public static PersonelGeneralInfo GetPersonelGeneralInfo(Personel personel, ref string message) { var personelGeneralInfo = new PersonelGeneralInfo(personel); var loanIdCommand = string.Format("SELECT * FROM Loan where personelId ={0} and expired<>true", personel.Id); try { string dataBase = Helper.GetConnectionString(); DataTable dataTable = new DataTable(); using (OleDbConnection connection = new OleDbConnection(dataBase)) { OleDbCommand selectCommand = new OleDbCommand(loanIdCommand, connection); connection.Open(); using (OleDbDataReader reader = selectCommand.ExecuteReader()) { while (reader.Read()) { personelGeneralInfo.LoanId = (int)reader["Id"]; personelGeneralInfo.LoanReceiptDate = (string)reader["ReceiptDate"]; personelGeneralInfo.LoanAmount = (Int32)reader["Amount"]; } } connection.Close(); } if (personelGeneralInfo.LoanId >= 0) { //get sabeghe pardakht var lastLoan = new LastLoanGeneralInfo(personelGeneralInfo.LoanId, personelGeneralInfo.LoanAmount); lastLoan = GetLoanDetails(lastLoan); personelGeneralInfo.LoanDebtAmount = lastLoan.DebtAmount.ToString(); if (!string.IsNullOrEmpty(lastLoan.LastPayment)) { personelGeneralInfo.LasPayment = lastLoan.LastPayment.ToString(); } } return(personelGeneralInfo); } catch (Exception ex) { message = ex.ToString(); return(null); } }
public static IEnumerable <Personel> GetPersonels(ref string message) { //var cmd = string.Format("SELECT * FROM Personel where FirstName like '%{0}%' or LastName like '%{0}%' ", txtName.Text); var cmd = "SELECT * FROM Personel "; var list = new List <Personel>(); try { string dataBase = Helper.GetConnectionString(); DataTable dataTable = new DataTable(); using (OleDbConnection connection = new OleDbConnection(dataBase)) { OleDbCommand selectCommand = new OleDbCommand(cmd, connection); connection.Open(); using (OleDbDataReader reader = selectCommand.ExecuteReader()) { while (reader.Read()) { var p = new Personel(); p.FirstName = (string)reader["FirstName"]; p.LastName = (string)reader["LastName"]; p.Id = (int)reader["ID"]; list.Add(p); } } connection.Close(); } if (list.Count == 0) { message = "No Data To Return"; } return(list); } catch (Exception ex) { message = ex.ToString(); return(null); } }