Пример #1
0
        private static Customer CreateCustomerFromRow(DataRow row)
        {
            string firstName;

            if (row.IsNull("first_name"))
            {
                return(null);
            }
            firstName = row["first_name"].ToString();

            string lastName;

            if (row.IsNull("last_name"))
            {
                return(null);
            }
            lastName = row["last_name"].ToString();

            string suite = "";

            if (!row.IsNull("suite_number"))
            {
                suite = row["suite_number"].ToString();
            }

            string street = "";

            if (!row.IsNull("street_number"))
            {
                street = row["street_number"].ToString();
            }

            string house = "";

            if (!row.IsNull("house_number"))
            {
                house = row["house_number"].ToString();
            }

            string city = "";

            if (!row.IsNull("city"))
            {
                city = row["city"].ToString();
            }

            string province = "";

            if (!row.IsNull("province"))
            {
                province = row["province"].ToString();
            }

            string postalCode = "";

            if (!row.IsNull("postalcode"))
            {
                postalCode = row["postalcode"].ToString();
            }

            string email = "";

            if (!row.IsNull("email"))
            {
                email = row["email"].ToString();
            }

            string phone = "";

            if (!row.IsNull("phone_number"))
            {
                phone = row["phone_number"].ToString();
            }

            DateTime creationDate;

            if (row.IsNull("creation_date"))
            {
                return(null);
            }
            creationDate = (DateTime)row["creation_date"];

            string creditCard = "";

            if (!row.IsNull("credit_card"))
            {
                creditCard = row["credit_card"].ToString();
            }

            Customer.AccountType account = Customer.AccountType.Limited;
            switch (row["account_type"].ToString())
            {
            case "Disabled":
                account = Customer.AccountType.Disabled;
                break;

            case "Limited":
                account = Customer.AccountType.Limited;
                break;

            case "Bronze":
                account = Customer.AccountType.Bronze;
                break;

            case "Silver":
                account = Customer.AccountType.Silver;
                break;

            case "Gold":
                account = Customer.AccountType.Gold;
                break;

            default:
                return(null);
            }

            UserName name    = new UserName(firstName, lastName);
            Address  address = new Address(suite, street, house, city, province, postalCode);

            ContactInformation newContact = new ContactInformation(email, phone);

            Credentials credentials = new Credentials(row["username"].ToString(), row["passhash"].ToString());

            Customer customer = new Customer(name, address, newContact, account)
            {
                CreationDate = creationDate,
                CreditCard   = creditCard,
                Id           = (int)row["cid"],
                Rating       = (int)row["rating"],
                Credentials  = credentials,
            };

            return(customer);
        }
Пример #2
0
        private static Employee CreateEmployeeFromRow(DataRow row)
        {
            string firstName;

            if (row.IsNull("first_name"))
            {
                return(null);
            }
            firstName = row["first_name"].ToString();

            string lastName;

            if (row.IsNull("last_name"))
            {
                return(null);
            }
            lastName = row["last_name"].ToString();

            string suite = "";

            if (!row.IsNull("suite_number"))
            {
                suite = row["suite_number"].ToString();
            }

            string street = "";

            if (!row.IsNull("street_number"))
            {
                street = row["street_number"].ToString();
            }

            string house = "";

            if (!row.IsNull("house_number"))
            {
                house = row["house_number"].ToString();
            }

            string city = "";

            if (!row.IsNull("city"))
            {
                city = row["city"].ToString();
            }

            string province = "";

            if (!row.IsNull("province"))
            {
                province = row["province"].ToString();
            }

            string postalCode = "";

            if (!row.IsNull("postalcode"))
            {
                postalCode = row["postalcode"].ToString();
            }

            string phone = "";

            if (!row.IsNull("phone_number"))
            {
                phone = row["phone_number"].ToString();
            }

            Employee.Position position;
            if (row.IsNull("position"))
            {
                return(null);
            }
            position = Employee.Position.Employee;
            if (row["position"].ToString() == "manager")
            {
                position = Employee.Position.Manager;
            }

            float wage;

            if (row.IsNull("wage"))
            {
                return(null);
            }
            wage = float.Parse(row["wage"].ToString(), CultureInfo.InvariantCulture.NumberFormat);

            DateTime startDate;

            if (row.IsNull("start"))
            {
                return(null);
            }
            startDate = (DateTime)row["start"];

            string sin = "";

            if (row.IsNull("social_insurance_num"))
            {
                sin = row["social_insurance_num"].ToString();
            }

            UserName           name        = new UserName(firstName, lastName);
            Address            address     = new Address(suite, street, house, city, province, postalCode);
            ContactInformation contactInfo = new ContactInformation("", phone);
            Credentials        credentials = new Credentials(row["username"].ToString(), row["passhash"].ToString());
            Employee           employee    = new Employee(name, address, contactInfo, wage, startDate, sin, position)
            {
                Id          = (int)row["eid"],
                Credentials = credentials
            };

            return(employee);
        }