Exemple #1
0
        /**
         * Method initContact
         * Takes a Contact ID, fetches it from the DB
         * and poplates the object with the data from the DB
         */
        public bool initContact(int contactId)
        {
            SqlServer sqlsvr = new SqlServer();
            DataSet ds;
            string sql;

            try
            {
                sql = "SELECT * FROM Contact WHERE id = " + contactId;
                ds = sqlsvr.runSqlReturnDataSet(sql);
                if (ds == null)
                {
                    errorMessage = "Sql Server Error in Contact.initContact:" + sqlsvr.errorMessage;
                    return false;
                }

                if (ds.Tables[0].Rows.Count == 0)
                {
                    errorMessage = "No record in Contact.initContact";
                    return false;
                }

                DataRow row = ds.Tables[0].Rows[0];

                id = contactId; ;
                customerId = int.Parse(row["CustomerId"].ToString());
                createDate = DateTime.Parse(row["CreateDate"].ToString());
                note = row["Note"].ToString();

                return true;
            }
            catch (Exception ex)
            {
                errorMessage = "Exception in Contact.initContact:" + ex.Message + ex.StackTrace;
                return false;
            }
        }
Exemple #2
0
        /**
         * method initCustomer
         * fetch from the database the Customer
         * with the supplied id and populate the
         * objects properties
         */
        public bool initCustomer(int customerId)
        {
            SqlServer sqlsvr = new SqlServer();
            DataSet ds;
            string sql;

            try
            {
                sql = "SELECT * FROM Customer WHERE id = " + customerId;
                ds = sqlsvr.runSqlReturnDataSet(sql);

                if (ds == null)
                {
                    errorMessage = "Sql Server Error in Customer.initCustomer:" + sqlsvr.errorMessage;
                    return false;
                }

                if (ds.Tables[0].Rows.Count == 0)
                {
                    errorMessage = "No record in Customer.initCustomer";
                    return false;
                }

                DataRow row = ds.Tables[0].Rows[0];
                id = customerId;
                firstName = row["FirstName"].ToString();
                lastName = row["LastName"].ToString();
                phoneNumber = row["PhoneNumber"].ToString();
                email = row["Email"].ToString();

                // fetch all Contacts for this Customer
                // sorted by newest first
                ContactCollection cc = new ContactCollection();
                if (! cc.getAllContactsForCustomer(id))
                {
                    errorMessage = "Error getting Contacts in in Customer.initCustomer:" + cc.errorMessage;
                    return false;
                }
                contacts = cc;
                lastContact = cc[0].createDate;  //Last Contact

                return true;
            }
            catch (Exception ex)
            {
                errorMessage = "Exception in Customer.initCustomer:" + ex.Message + ex.StackTrace;
                return false;
            }
        }