예제 #1
0
 public static CustomerCache GetInstance()
 {
     if (instance == null)
     {
         instance = new CustomerCache();
     }
     return(instance);
 }
예제 #2
0
 public void Clear()
 {
     if (customers != null)
     {
         customers.Clear();
     }
     instance = null;
 }
예제 #3
0
        public List <Transaction> GetTransactionsByProjectId(int p)
        {
            List <Transaction> transactions = new List <Transaction>();
            DateTime           timeVar;
            int         intVar;
            double      doubleVar;
            Transaction tx = new Transaction();

            DBFunctions.GetInstance().OpenConnection();
            OleDbCommand command = DBFunctions.GetInstance().GetCommand("Select ID, TransactionTime, Customer, Remarks, TransactionSum, SaleOrPurchase, Project From Transactions " +
                                                                        "Where Project=?");

            command.Parameters.Clear();
            command.Parameters.AddWithValue("Project", p);
            OleDbDataReader reader = DBFunctions.GetInstance().GetReader(command);

            while (reader.Read())
            {
                tx    = new Transaction();
                tx.ID = int.Parse(reader[0].ToString());
                if (DateTime.TryParse(reader[1].ToString(), out timeVar))
                {
                    tx.TransactionTime = timeVar;
                }
                if (int.TryParse(reader[2].ToString(), out intVar))
                {
                    tx.Customer    = new Customer();
                    tx.Customer.ID = intVar;
                }
                tx.Remark = reader[3].ToString();

                if (double.TryParse(reader[4].ToString(), out doubleVar))
                {
                    tx.TransactionSum = doubleVar;
                }
                if (int.TryParse(reader[5].ToString(), out intVar))
                {
                    tx.IsPurchase = (intVar == Properties.Settings.Default.PurchaseVar);
                }
                if (int.TryParse(reader[6].ToString(), out intVar))
                {
                    tx.ParentProject    = new Project();
                    tx.ParentProject.ID = intVar;
                }

                tx.Customer      = CustomerCache.GetInstance().GetCustomerById(tx.Customer.ID);
                tx.ParentProject = ProjectCache.GetInstance().GetProjectById(tx.ParentProject.ID);
                transactions.Add(tx);
            }

            return(transactions);
        }
예제 #4
0
        public Transaction GetTransactionById(int transactionID)
        {
            DateTime    timeVar;
            int         intVar;
            double      doubleVar;
            Transaction tx = new Transaction();

            DBFunctions.GetInstance().OpenConnection();
            OleDbCommand command = DBFunctions.GetInstance().GetCommand("Select TransactionTime, Customer, Remarks, TransactionSum From Transactions " +
                                                                        "Where ID=?");

            command.Parameters.Clear();
            command.Parameters.AddWithValue("ID", transactionID);
            OleDbDataReader reader = DBFunctions.GetInstance().GetReader(command);

            if (reader.Read())
            {
                tx.ID = transactionID;
                if (DateTime.TryParse(reader[0].ToString(), out timeVar))
                {
                    tx.TransactionTime = timeVar;
                }
                if (int.TryParse(reader[1].ToString(), out intVar))
                {
                    tx.Customer    = new Customer();
                    tx.Customer.ID = intVar;
                }
                tx.Remark = reader[2].ToString();

                if (double.TryParse(reader[3].ToString(), out doubleVar))
                {
                    tx.TransactionSum = doubleVar;
                }
                tx.Customer = CustomerCache.GetInstance().GetCustomerById(tx.Customer.ID);
                return(tx);
            }
            else
            {
                return(null);
            }
        }