Exemplo n.º 1
0
        public void CustomerSaveTest()
        {
            Customer customer = new Customer("Ali");
            customer.Email = "*****@*****.**";

            Address address = new Address();
            address.Street = "2534 Lorong 2 Taman India";
            address.Postal = "12345";
            address.State = "Melaka";

            Stock stock = new Stock(3);
            Nisan nisan = new Nisan(stock);
            nisan.Name = "Ramli" + new System.Random().Next(100) + " bin Taib";
            nisan.Death = RandomDate();

            Order target = new Order();
            target.Status = TransactionStage.Submit;
            //target.Agent = new Agent("W002");
            target.Amount = stock.Price;
            target.Quantity = 1;
            target.Stock = nisan;
            target.ShipTo = address;
            target.Parent.CreatedBy = customer;//can be an agent
            Assert.IsTrue(target.Save());
        }
Exemplo n.º 2
0
        public void AgentSaveTest()
        {
            Address address = new Address();
            address.Street = "1234 Lorong 2 Taman Bangla";
            address.Postal = "12345";
            address.State = "Pahang";

            Stock stock = new Stock(3);
            Nisan nisan = new Nisan(stock);
            nisan.Name = "Che Som" + new System.Random().Next(100) + " bin Said";
            nisan.Death = RandomDate();

            Agent agent = new Agent("W002");

            Order target = new Order();
            target.Status = TransactionStage.Submit;
            target.Agent = agent;
            target.Amount = stock.Price;
            target.Quantity = 1;
            target.Stock = nisan;
            target.ShipTo = address;
            Assert.IsTrue(target.Save());
        }
Exemplo n.º 3
0
        protected List<Order> GetSales(string code)
        {
            List<Order> sales = new List<Order>();
            using (DbConnection connection = factory.CreateConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();
                using (DbCommand command = connection.CreateCommand())
                {
                    command.CommandType = System.Data.CommandType.Text;
                    string sql =
            @"SELECT Orders.Status
            ,Orders.AddressId,Addresses.Street,Addresses.Postal,Addresses.State
            ,Orders.Quantity,Stocks.Type
            ,Nisans.*
            ,Users.Id,Users.Code,Users.Name AS Customer
            ,TransactionItems.Id AS TransactionItemId, TransactionItems.Amount
            ,Transactions.Id AS TransactionId,Transactions.No AS No, Transactions.CreatedAt
            FROM Orders JOIN Nisans ON Orders.NisanId=Nisans.Id
            JOIN Addresses ON Orders.AddressId=Addresses.Id
            JOIN Stocks ON Nisans.Type = Stocks.Id
            JOIN TransactionItems ON Orders.ItemId=TransactionItems.Id
            JOIN Transactions ON TransactionItems.Parent=Transactions.Id
            JOIN Users ON Transactions.CreatedBy=Users.Id";
                    if (code != null && code.Length > 0)
                        sql += " WHERE Users.Code=@Code;";
                    command.CommandText = sql;
                    if (code != null && code.Length > 0)
                        command.Parameters.Add(CreateParameter("@Code", this.codeField));

                    using (DbDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Transaction parent = new Transaction();
                            parent.CreatedAt = Convert.ToDateTime(reader["CreatedAt"]);

                            Order order = new Order();
                            order.Parent = parent;
                            order.Status = (TransactionStage)Convert.ToInt32(reader["Status"]);

                            if (reader["Code"] != DBNull.Value && reader["Code"].ToString().Length>0)
                                order.Agent = new Agent(reader["Code"].ToString());
                            order.Id = Convert.ToInt32(reader["TransactionItemId"]);
                            order.Amount = Convert.ToDecimal(reader["Amount"]);
                            order.Quantity = Convert.ToInt32(reader["Quantity"]);

                            Nisan nisan = new Nisan();
                            nisan.Type = reader["Type"].ToString();
                            nisan.Id = Convert.ToInt32(reader["Id"]);
                            nisan.Name = reader["Name"].ToString();
                            nisan.Death = Convert.ToDateTime(reader["Death"]);
                            if (reader["Deathm"] != DBNull.Value)
                                nisan.Deathm = ToMuslimDate(reader["Deathm"].ToString());
                            if (reader["Age"] != DBNull.Value)
                                nisan.Age = Convert.ToInt32(reader["Age"]);
                            if (reader["Born"] != DBNull.Value)
                                nisan.Born = Convert.ToDateTime(reader["Born"]);
                            nisan.Remarks = reader["Remarks"].ToString();
                            nisan.Uri = reader["Uri"].ToString();
                            order.Stock = nisan;

                            Address shipTo = new Address();
                            shipTo.Street = reader["Street"].ToString();
                            shipTo.Postal = reader["Postal"].ToString();
                            shipTo.State = reader["State"].ToString();
                            order.ShipTo = shipTo;
                            //order.ShipTo = new Address((int)reader["AddressId"]);

                            sales.Add(order);
                        }
                    }
                }

                connection.Close();
            }//end

            return sales;
        }
Exemplo n.º 4
0
    private void Submit()
    {
        stockId = Convert.ToInt32(ddlStock.SelectedValue);
        HLGranite.Nisan.Stock stock = new HLGranite.Nisan.Stock(stockId);
        Nisan nisan = new Nisan(stock);
        nisan.Name = txtName.Text.Trim();
        nisan.Jawi = txtJawi.Text.Trim();
        nisan.Death = ToDate(txtDeath.Text);
        nisan.Deathm = new DateTime(Convert.ToInt32(txtYear.Text), ddlMonth.SelectedIndex + 1, Convert.ToInt32(ddlDay.Text));

        Order target = new Order();
        target.Status = TransactionStage.Submit;
        if (user == null)
        {
            Customer customer = new Customer();
            customer.Name = txtCustomer.Text;
            customer.Email = txtEmail.Text;
            customer.Phone = txtPhone.Text;

            target.Customer = customer;
            target.Parent.CreatedBy = customer;
        }
        else
        {
            if (txtCustomer.Text.Trim() != user.Name)
            {
                Customer customer = new Customer();
                customer.Name = txtCustomer.Text;
                customer.Email = txtEmail.Text;
                customer.Phone = txtPhone.Text;

                target.Customer = customer;
                target.Parent.CreatedBy = customer;
            }
            else if (user is Agent)
            {
                target.Agent = (user as Agent);
                target.Parent.CreatedBy = (user as Agent);
            }
        }

        target.Amount = stock.Price;
        target.Quantity = 1;
        target.Stock = nisan;

        Address address = new Address();
        address.Street = txtAddress.Text;
        address.Postal = txtPostal.Text;
        address.State = ddlState.Text;
        target.ShipTo = address;

        bool success = target.Save();
        if (success)
        {
            lblMessage.Text = "Your order has been sent to us and we will contact you shortly.";
            EnableForm(false);
        }
    }