Отдел компьютерных комплектирующих

Автор работы: Пользователь скрыл имя, 15 Апреля 2012 в 12:10, курсовая работа

Описание

У результаті курсового проектування отримали програму, що дає можливість покупцям замовляти товари, продавцям редагувати інформацію про товари і покупців. У ході проектування була використана СУБД Microsoft Access і мова програмування C#/.

Содержание

Вступ 6
Аналіз предметної області 9
a. Область застосування програмного продукту 9
b. Практичне значення 9
Розробка моделі бази даних 12
a. ER-Діаграмма бази данних 13
b. Приведення до третьої нормальної форми 15
Розробка інтерфейса користувача (GUI) 18
Висновок 24
Перелік посилань 26
Додатки 27

Работа состоит из  1 файл

Мой курсач.doc

— 697.00 Кб (Скачать документ)

 

        private Dictionary<string,TextBox> specifications;

 

        public MainForm()

        {

            factory = DAL.Factories.Factory.GetFactory(DAL.Factories.FactoryType.AccessFactory);

            InitializeComponent();

            foreach (string type in factory.GetOtherRepository().GetHardwareTypes())

            {

                typeBox.Items.Add(type);

            }

            specifications = new Dictionary<string, TextBox>();

        }           

 

        private void tabPage2_Enter(object sender, EventArgs e)

        {

            Console.WriteLine("second tab");

        }

 

        private void tabPage1_Enter(object sender, EventArgs e)

        {

            this.treeView1.Nodes.Clear();

            foreach (BO.Hardware item in factory.GetHardwareRepository().GetAll())

            {

                TreeNode node=new TreeNode();

                node.Text=item.title;

               

                foreach (string buyer in factory.GetOtherRepository().GetHardwareOrders(item))

                {

                    node.Nodes.Add(buyer);

                }

                this.treeView1.Nodes.Add(node);

            }

            typeSelectBox.Items.Clear();

            foreach (string type in factory.GetOtherRepository().GetHardwareTypes())

            {

                typeSelectBox.Items.Add(type);

            }

        }

 

        private void SaveButton_Click(object sender, EventArgs e)

        {

            Dictionary<string,string> itemSpec=new Dictionary<string,string>();

            foreach (string spec in factory.GetOtherRepository().GetTypeFields(typeBox.Text))

            {

                itemSpec[spec]=specifications[spec].Text;

            }

            string title=titleEdit.Text;

            string description=descriptionEdit.Text;

            string cost=costEdit.Text;

            string manufacturer=manufacturerEdit.Text;

            string type = typeBox.Text;

            BO.Hardware item=new BO.Hardware(title,description,cost,manufacturer,type);

            item.specifications=itemSpec;

            factory.GetHardwareRepository().Create(item);

        }

 

        private void resetButton_Click(object sender, EventArgs e) {

            this.titleEdit.ResetText();

            this.typeBox.ResetText();

            this.costEdit.ResetText();

        }

 

        private void typeBox_SelectedIndexChanged(object sender, EventArgs e)

        {

            specifications.Clear();

            tableLayoutPanel2.Controls.Clear();

            int rows = 0;

            foreach (string spec in factory.GetOtherRepository().GetTypeFields(typeBox.Text))

            {

                TextBox edit = new TextBox();

                specifications.Add(spec, edit);

                Label label = new Label();

                label.Text = spec;

                tableLayoutPanel2.Controls.Add(label, 0, rows);

                tableLayoutPanel2.Controls.Add(edit, 1, rows);

                rows += 1;

            }

        }

 

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)

        {

                     

        }

 

        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)

        {

            if (e.Node.Level==0)

            {

                BO.Hardware item = factory.GetHardwareRepository().GetAll()[e.Node.Index];

                new OrderForm(item).ShowDialog(); 

            }

        }

 

        private void button1_Click_1(object sender, EventArgs e)

        {

            this.treeView1.Nodes.Clear();

            foreach (BO.Hardware item in factory.GetHardwareRepository().GetAll())

            {

                TreeNode node = new TreeNode();

                node.Text = item.title;

                foreach (string buyer in factory.GetOtherRepository().GetHardwareOrders(item))

                {

                    node.Nodes.Add(buyer);

                }

                this.treeView1.Nodes.Add(node);

            }

        }

 

        private void filterButton_Click(object sender, EventArgs e)

        {

            string query = queryTextBox.Text;

            string type = typeSelectBox.Text;

            this.treeView1.Nodes.Clear();

            List<BO.Hardware> items = factory.GetHardwareRepository().GetAll();

            List<BO.Hardware> to_remove = new List<BO.Hardware>();

            if (query.Length!=0)

            {

                foreach (BO.Hardware item in items)

                {

                    if (!item.title.Contains(query))

                    {

                        to_remove.Add(item);

                    }

                }

            }

            if (type.Length != 0)

            {

                foreach (BO.Hardware item in items)

                {

                    if (item.type != type)

                    {

                        to_remove.Add(item);

                    }

                }

            }

            treeView1.Nodes.Clear();

            foreach (BO.Hardware item in items)

            {

                if (!to_remove.Contains(item))

                {

                    TreeNode node = new TreeNode();

                    node.Text = item.title;

                    foreach (string buyer in factory.GetOtherRepository().GetHardwareOrders(item))

                    {

                        node.Nodes.Add(buyer);

                    }

                    this.treeView1.Nodes.Add(node);

                }

            }

        }

 

        private void runButton_Click(object sender, EventArgs e)

        {

            bool isok = false;

            listView.Clear();

            foreach (ListViewItem item in factory.CustomQuery(queryBox.Text))

            {

                if (!isok)

                {

                    for (int i=0; i < item.SubItems.Count; i++)

                    {

                        listView.Columns.Add("");

                    }

                    isok = true;

                }

                listView.Items.Add(item);

            }

        }

    }

}

 

5.Вихідний код класу Order Form:

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace WindowsFormsGui

{

    public partial class OrderForm : Form

    {

        bool creatingNew = false;

        DAL.Factories.Factory factory;

        BO.Hardware item;

        public OrderForm(BO.Hardware item)

        {

            this.item = item;

            factory = DAL.Factories.Factory.GetFactory(DAL.Factories.FactoryType.AccessFactory);

            InitializeComponent();

            hideButton.Visible = false;

            tableLayoutPanel2.Visible = false;

            foreach (BO.Buyer buyer in factory.GetBuyerRepository().GetAll())

            {

                buyerBox.Items.Add(buyer.first);

            }

            titleLabel.Text = item.title;

            manufacturerLabel.Text = item.manufacturer;

            costLabel.Text = item.cost;

            typeLabel.Text = item.type;

            factory=DAL.Factories.Factory.GetFactory(DAL.Factories.FactoryType.AccessFactory);

            List<string> labels = factory.GetOtherRepository().GetTypeFields(item.type);

            int i=0;

            int row=tableLayoutPanel1.RowCount-5;

            Dictionary<string, string> specs = factory.GetOtherRepository().GetHardwareSpecs(item.id);

            foreach (string spec in specs.Keys)

            {

                Label label=new Label();

                if (spec != "ID")

                {

                    label.Text = labels[i];

                    tableLayoutPanel1.Controls.Add(label, 0, row);

                    Label label2 = new Label();

                    label2.Text = specs[spec];

                    tableLayoutPanel1.Controls.Add(label2, 1, row);

                    i += 1;

                    row += 1;

                }

                }

           }

      

        private void resetButton_Click(object sender, EventArgs e)

        {

            this.firstEdit.ResetText();

            this.lastEdit.ResetText();

            this.emailEdit.ResetText();

            this.addressEdit.ResetText();

            this.buyerBox.ResetText();

        }

 

        private void saveButon_Click(object sender, EventArgs e)

        {

            if (buyerBox.Items.Contains(buyerBox.Text))

            {

                factory.GetOtherRepository().CreateOrder(item.id, factory.GetOtherRepository().GetBuyer(buyerBox.Text));

                this.Close();

            }

            else if (creatingNew)

            {

                BO.Buyer buyer = new BO.Buyer(firstEdit.Text, lastEdit.Text, emailEdit.Text, addressEdit.Text);

                factory.GetBuyerRepository().Create(buyer);

                factory.GetOtherRepository().CreateOrder(item.id, factory.GetOtherRepository().GetBuyer(firstEdit.Text));

                this.Close();

            }

            else

            {

                MessageBox.Show("Вы делаете что-то не так");

            }

           }

 

        private void newBuyerButton_Click(object sender, EventArgs e)

        {

            creatingNew = true;

            tableLayoutPanel2.Visible = true;

            hideButton.Visible = true;

            newBuyerButton.Visible = false;

            buyerBox.Visible = false;

        }

 

        private void hideButton_Click(object sender, EventArgs e)

        {

            creatingNew = false;

            tableLayoutPanel2.Visible = false;

            hideButton.Visible = false;

            newBuyerButton.Visible = true;

            buyerBox.Visible = true;

        }

 

        private void OrderForm_FormClosed(object sender, FormClosedEventArgs e)

        {

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            new EditForm(item).ShowDialog();

        }

 

        private void deleteButton_Click(object sender, EventArgs e)

        {

            factory.GetHardwareRepository().Delete(item.id);

            Close();

        }

 

    }

}

 

 

6.Вихідний код класу AccessFactory:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data.Odbc;

using System.Windows.Forms;

 

using BO;

 

namespace DAL.Factories

{

    public class AccessFactory : Factory //паттерн програмування абстрактної фабрики     {

        public OdbcConnection connection;

        public AccessFactory()

        {

            connection = new OdbcConnection();

            connection.ConnectionString = Factory.ConnectionString;

        }

 

        public override List<ListViewItem> CustomQuery(string query)

        {

                connection.Close();

                connection.Open();

                OdbcCommand cmd = new OdbcCommand(query, connection);

                List<ListViewItem> items = new List<ListViewItem>();

                try

                {

                    OdbcDataReader r = cmd.ExecuteReader();

                    while (r.Read())

                    {

                        ListViewItem item = new ListViewItem();

                        for (int i = 0; i < r.FieldCount; i++)

                        {

                            item.SubItems.Add(Convert.ToString(r[i]));

                        }

                        items.Add(item);

                    }

                }

                catch { return items; };

                return items;

           

        }

       

        public override Repositories.IRepository<BO.Buyer> GetBuyerRepository()

        {

            return new Repositories.BuyerRepository(connection);

        }

 

        public override Repositories.IRepository<BO.Hardware> GetHardwareRepository()

        {

            return new Repositories.HardwareRepository(connection);

        }

 

        public override Repositories.IOtherReopsitory GetOtherRepository()

        {

            return new Repositories.OtherRepository(connection);

        }

    }

}

 

 

 

 

7.Вихідний код класу AccessRepository:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections.Specialized;

using System.Data.Odbc;

using DAL.Factories;

 

namespace DAL.Repositories

{

    public class OtherRepository : IOtherReopsitory

    {

        OdbcConnection connection;

        public OtherRepository(OdbcConnection con)

        {

            this.connection = con;

        }

 

        public List<string> GetHardwareTypes() // повертає тип обладнання

        {

            List<string> result = new List<string>();

            result.Add("CPU");

            result.Add("Motherboard");

            result.Add("GPU");

            return result;

        }

 

        public List<string> GetTypeFields(string type) // повертає зв'язок з таблицею характеристик

        {

            List<string> result = new List<string>();

            OdbcCommand cmd = connection.CreateCommand();

            cmd.CommandText = "SELECT * FROM SpecificationType WHERE type='" + type + "'";

            connection.Close();

            connection.Open();

            OdbcDataReader reader = cmd.ExecuteReader();

            while (reader.Read())

            {

                result.Add(Convert.ToString(reader["title"]));

            }

            return result;

        }

 

        public Dictionary<string, string> GetHardwareSpecs(int id) // повертає конкретні характеристики конкретного обладнання

        {

            Dictionary<string, string> result = new Dictionary<string, string>();

            OdbcCommand cmd = this.connection.CreateCommand();

            cmd.CommandText = "SELECT Specification.* FROM (Hardware INNER JOIN Specification ON Specification.ID = Hardware.specs) WHERE (Hardware.ID = " + id + ")";

            connection.Close();

            connection.Open();

 

            OdbcDataReader reader = cmd.ExecuteReader();

            while (reader.Read())

            {

                for (int i = 0; i < reader.FieldCount; i++)

                {

                    if (Convert.ToString(reader[i]) != "")

                    {

                        result.Add(Convert.ToString(reader.GetName(i)), Convert.ToString(reader[i]));

                    }

 

                }

            }

            return result;

 

        }

 

      

        public void CreateOrder(int hid, int bid) // створити замовлення

        {

            OdbcCommand cmd = connection.CreateCommand();

            cmd.CommandText = "INSERT INTO [Orders] (hardware,recipient) VALUES (" + hid + "," + bid + ");";

            connection.Close();

            connection.Open();

            cmd.ExecuteNonQuery();

        }

 

        public int GetBuyer(string email) // отримати покупця по емейлу

        {

            OdbcCommand cmd = connection.CreateCommand();

            cmd.CommandText = "SELECT Buyer.ID FROM Buyer WHERE Buyer.first_name='" + email + "';";

            connection.Close();

            connection.Open();

            return Convert.ToInt32(cmd.ExecuteScalar());

        }

 

        public List<string> GetHardwareOrders(BO.Hardware item) // получить заказы конкр обору

        {

            List<string> result = new List<string>();

            OdbcCommand cmd = connection.CreateCommand();

            cmd.CommandText = "SELECT Buyer.* FROM Orders INNER JOIN Buyer ON Buyer.ID=Orders.recipient WHERE hardware=" + item.id;

            connection.Close();

            connection.Open();

            Console.WriteLine(item.id);

            OdbcDataReader reader = cmd.ExecuteReader();

            while (reader.Read())

            {

                result.Add(Convert.ToString(reader["last_name"]) + ", " + Convert.ToString(reader["first_name"]));

            }

            return result;

        }

    }

}

 

8.Вихідний код класу BuyerRepository:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections.Specialized;

using System.Data.Odbc;

using DAL;

using BO;

 

namespace DAL.Repositories

{

    public class BuyerRepository : IRepository<BO.Buyer>

    {

        OdbcConnection connection;

 

        public BuyerRepository(OdbcConnection con)

        {

            connection = con;

        }

       

        public List<BO.Buyer> GetAll() // вивести всіх покупців

        {

Информация о работе Отдел компьютерных комплектирующих