Ejemplo n.º 1
0
        public _Category Add(_Category c)
        {
            string query = @"insert into dbo.Category(CategoryName) values (@CategoryName)";

            cmd = new SqlCommand(query, Connection);
            SqlTransaction transaction = null;

            try
            {
                Connection.Open();
                transaction     = Connection.BeginTransaction();
                cmd.Transaction = transaction;
                cmd.Parameters.AddWithValue("@CategoryName", c.CategoryName);

                cmd.ExecuteNonQuery();
                cmd.CommandText = "select @@identity";
                var id = cmd.ExecuteScalar();
                c.CategoryId = Convert.ToInt32(id);
                transaction.Commit();
                return(c);
            }
            catch (Exception exc)
            {
                transaction.Rollback();
                Console.WriteLine(exc.Message);
            }
            finally
            {
                if (Connection.State == System.Data.ConnectionState.Open)
                {
                    Connection.Close();
                }
            }
            return(null);
        }
        private void btnUpdateCategories_Click(object sender, EventArgs e)
        {
            if (validateInput())
            {
                //Create an object of the Category class.
                var updateExistingCategory = new _Category(int.Parse(txtCategoryID.Text),
                                                           txtCategory.Text);

                using (var conn = ConnectionManager.DatabaseConnection())
                {
                    //Specify the Stored Procedure
                    using (var cmd = new SqlCommand("sp_Categories_UpdateCategory", conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("CategoryID", updateExistingCategory.CategoryID);
                        cmd.Parameters.AddWithValue("Category", updateExistingCategory.Category);

                        cmd.Transaction = conn.BeginTransaction();
                        cmd.ExecuteNonQuery();
                        cmd.Transaction.Commit();
                    }
                }
                this.Close();
            }
        }
        private void DisplayCategories()
        {
            string selectQuery;

            selectQuery = "SELECT * FROM Categories";
            List <_Category> catList = new List <_Category>();

            try
            {
                // Automatically  open and close the connection
                using (var conn = ConnectionManager.DatabaseConnection())
                    using (var cmd = new SqlCommand(selectQuery, conn))
                        using (var rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                //Define the list items
                                var category = new _Category(
                                    int.Parse(rdr["CategoryID"].ToString()),
                                    rdr["Category"].ToString());

                                catList.Add(category);
                            }
                            dgvCategories.DataSource = catList;
                        }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unsuccessful" + ex);
            }
        }
 public frmUpdateCategory(_Category updateCategory)
 {
     InitializeComponent();
     //Fill in the form
     txtCategoryID.Text = updateCategory.CategoryID.ToString();
     txtCategory.Text   = updateCategory.Category;
 }
Ejemplo n.º 5
0
        private void frmUpdateCustomers_Load(object sender, EventArgs e)
        {
            //Populating the combobox from the Category table.
            string           populateCategory = "SELECT * FROM Categories";
            List <_Category> catList          = new List <_Category>();

            try
            {
                // Automatically  open and close the connection
                using (var conn = ConnectionManager.DatabaseConnection())
                    using (var cmd = new SqlCommand(populateCategory, conn))
                        using (var rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                //Define the list items
                                var category = new _Category(
                                    int.Parse(rdr["CategoryID"].ToString()),
                                    rdr["Category"].ToString());

                                catList.Add(category);
                            }
                        }
                cbCategoryID.DataSource    = catList;
                cbCategoryID.DisplayMember = "Category";
                cbCategoryID.ValueMember   = "CategoryID";
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unsuccessful" + ex);
            }
            cbCategoryID.SelectedValue = updateCustomer.CategoryID; //set the Category Box to display nothing when the program starts.
        }
        private void btnAddCategories_Click_1(object sender, EventArgs e)
        {
            if (validateInput())
            {
                //Create the sale object using the Sale Class constructor
                var category = new _Category();

                using (var conn = ConnectionManager.DatabaseConnection())
                    using (var cmd = new SqlCommand("sp_Categories_CreateCategory", conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        SqlParameter ncid = cmd.Parameters.Add("NewCategoryID", SqlDbType.Int); ncid.Direction = ParameterDirection.Output;
                        cmd.Parameters.AddWithValue("Category", txtCategory.Text);

                        cmd.Transaction = conn.BeginTransaction();
                        cmd.ExecuteNonQuery();
                        cmd.Transaction.Commit();
                    }
                if (MessageBox.Show("Would you like to add another Category into the database", "Add another?",
                                    MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    txtCategory.Clear();
                    txtCategoryID.Clear();
                }
                else
                {
                    this.Close();
                }
            }
        }
Ejemplo n.º 7
0
        public ActionResult AddProduct()
        {
            List <_Category> listcate = new List <_Category>();

            foreach (var item in db.categories.ToList())
            {
                _Category c = new _Category();
                c.IDCategory = item.IDCategory;
                c.Name       = item.Name;
                listcate.Add(c);
            }
            ViewBag.IDCategory = new SelectList(listcate, "IDCategory", "Name", null);
            List <ThuongHieu> listth = new List <ThuongHieu>();

            foreach (var item in db.thuongHieus.ToList())
            {
                ThuongHieu th = new ThuongHieu();
                th.ID   = item.ID;
                th.Name = item.Name;
                listth.Add(th);
            }
            ViewBag.IDThuongHieu = new SelectList(listth, "ID", "Name", null);
            List <ChatLieu> listcl = new List <ChatLieu>();

            foreach (var item in db.chatLieus.ToList())
            {
                ChatLieu cl = new ChatLieu();
                cl.ID  = item.ID;
                cl.Ten = item.Ten;
                listcl.Add(cl);
            }
            ViewBag.IDChatLieu = new SelectList(listcl, "ID", "Ten", null);
            return(View());
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Result signifying single formatted <see cref="Models.Torrent"/> for use in presentation layer.
 /// </summary>
 /// <param name="title"></param>
 /// <param name="trusted"></param>
 /// <param name="isHomeSource">Result originating from TorrentCheck index.</param>
 /// <param name="torrentId">Associated TorrentId in database.</param>
 /// <param name="category"></param>
 public Result(string title, bool trusted, bool isHomeSource, int torrentId, _Category category)
 {
     Title        = title;
     Trusted      = trusted;
     IsHomeSource = isHomeSource;
     TorrentId    = torrentId;
     Category     = category;
 }
Ejemplo n.º 9
0
 public Torrent(int id, string title, int size, DateTime uploadDate, string md5Sum, List <File> files, List <Comment> comments, int user_Id, _Category category)
 {
     Id         = id;
     Title      = title;
     Size       = size;
     UploadDate = uploadDate;
     Md5Sum     = md5Sum;
     Files      = files;
     Comments   = comments;
     User_Id    = user_Id;
     Category   = category;
 }
        private void btnSearchCategories_Click(object sender, EventArgs e)
        {
            List <_Category> catList = new List <_Category>();

            try
            {
                // Automatically  open and close the connection
                using (var conn = ConnectionManager.DatabaseConnection())
                {
                    using (var cmd = conn.CreateCommand())
                    {
                        if (rbShowAll.Checked)
                        {
                            cmd.CommandText = "SELECT * FROM Categories";
                        }
                        if (rbSearchCategoryID.Checked)
                        {
                            cmd.CommandText = "SELECT * FROM Categories WHERE CategoryID = @categoryid";
                        }
                        if (rbSearchCategory.Checked)
                        {
                            cmd.CommandText = "SELECT * FROM Categories WHERE Category = @category";
                        }

                        cmd.Parameters.AddWithValue("categoryid", txtSearchCategoryID.Text);
                        cmd.Parameters.AddWithValue("category", txtSearchCategory.Text);

                        cmd.Transaction = conn.BeginTransaction();
                        cmd.ExecuteNonQuery();
                        cmd.Transaction.Commit();
                        using (var rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                //Define the list items
                                var category = new _Category(
                                    int.Parse(rdr["CategoryID"].ToString()),
                                    rdr["Category"].ToString());

                                catList.Add(category);
                            }
                            dgvCategories.DataSource = catList;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unsuccessful" + ex);
            }
        }
Ejemplo n.º 11
0
        public IEnumerable <_Category> GetCategory()
        {
            List <_Category> Categories = new List <_Category>();
            string           query      = "select * from dbo.Category";

            cmd = new SqlCommand(query, Connection);
            try
            {
                Connection.Open();
                var reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        var t = new _Category
                        {
                            CategoryId   = reader.GetInt32(0),
                            CategoryName = reader.GetString(1)
                        };
                        Categories.Add(t);
                    }
                }
                return(Categories);
            }
            catch (Exception ex)
            {
                Ex = ex.Message;
            }
            finally
            {
                if (Connection.State == System.Data.ConnectionState.Open)
                {
                    Connection.Close();
                }
            }
            return(null);
        }
Ejemplo n.º 12
0
        public ActionResult EditProduct(int id)
        {
            var sp1 = db.products.Where(m => m.IDProduct == id).FirstOrDefault();

            Session["sp1"] = sp1;
            List <_Category> listcate = new List <_Category>();

            foreach (var item in db.categories.ToList())
            {
                _Category c = new _Category();
                c.IDCategory = item.IDCategory;
                c.Name       = item.Name;
                listcate.Add(c);
            }
            ViewBag.IDCategory = new SelectList(listcate, "IDCategory", "Name", null);
            List <ThuongHieu> listth = new List <ThuongHieu>();

            foreach (var item in db.thuongHieus.ToList())
            {
                ThuongHieu th = new ThuongHieu();
                th.ID   = item.ID;
                th.Name = item.Name;
                listth.Add(th);
            }
            ViewBag.IDThuongHieu = new SelectList(listth, "ID", "Name", null);
            List <ChatLieu> listcl = new List <ChatLieu>();

            foreach (var item in db.chatLieus.ToList())
            {
                ChatLieu cl = new ChatLieu();
                cl.ID  = item.ID;
                cl.Ten = item.Ten;
                listcl.Add(cl);
            }
            ViewBag.IDChatLieu = new SelectList(listcl, "ID", "Ten", null);
            return(View(db.products.Where(m => m.IDProduct == id).FirstOrDefault()));
        }
Ejemplo n.º 13
0
        public ActionResult EditProduct(Product pro, int id, HttpPostedFileBase Image1, HttpPostedFileBase Image2, HttpPostedFileBase Image3, HttpPostedFileBase Image4, HttpPostedFileBase Image5, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                Product sp1 = Session["sp1"] as Product;
                if (Image1 != null)
                {
                    var filename1 = Path.GetFileName(Image1.FileName);
                    pro.Image1 = filename1;
                    string path1 = Path.Combine(Server.MapPath("~/Content/Images/"), filename1);
                    Image1.SaveAs(path1);
                }
                else
                {
                    pro.Image1 = sp1.Image1;
                }

                if (Image2 != null)
                {
                    var filename2 = Path.GetFileName(Image2.FileName);
                    pro.Image2 = filename2;
                    string path2 = Path.Combine(Server.MapPath("~/Content/Images/"), filename2);
                    Image2.SaveAs(path2);
                }
                else
                {
                    pro.Image2 = sp1.Image2;
                }
                if (Image3 != null)
                {
                    var filename3 = Path.GetFileName(Image3.FileName);
                    pro.Image3 = filename3;
                    string path3 = Path.Combine(Server.MapPath("~/Content/Images/"), filename3);
                    Image3.SaveAs(path3);
                }
                else
                {
                    pro.Image3 = sp1.Image3;
                }
                if (Image4 != null)
                {
                    var filename4 = Path.GetFileName(Image4.FileName);
                    pro.Image4 = filename4;
                    string path4 = Path.Combine(Server.MapPath("~/Content/Images/"), filename4);
                    Image4.SaveAs(path4);
                }
                else
                {
                    pro.Image4 = sp1.Image4;
                }
                if (Image5 != null)
                {
                    var filename5 = Path.GetFileName(Image5.FileName);
                    pro.Image5 = filename5;
                    string path5 = Path.Combine(Server.MapPath("~/Content/Images/"), filename5);
                    Image5.SaveAs(path5);
                }
                else
                {
                    pro.Image5 = sp1.Image5;
                }

                foreach (var item in db.size_Products)
                {
                    if (item.IDPro == pro.IDProduct)
                    {
                        db.size_Products.Remove(item);
                    }
                }
                int quantity = 0;
                for (int i = 1; i <= 10; i++)
                {
                    if (form["size" + i] != null && form["SL" + i] != null && form["SL" + i] != "")
                    {
                        Size_Product sp = new Size_Product();
                        sp.IDPro    = pro.IDProduct;
                        sp.size     = form["size" + i];
                        sp.Quantity = int.Parse(form["SL" + i]);
                        quantity   += sp.Quantity;
                        db.size_Products.Add(sp);
                    }
                }
                pro.QuantityRemaining = quantity;
                db.Entry(pro).State   = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            List <_Category> listcate = new List <_Category>();

            foreach (var item in db.categories.ToList())
            {
                _Category c = new _Category();
                c.IDCategory = item.IDCategory;
                c.Name       = item.Name;
                listcate.Add(c);
            }
            ViewBag.IDCategory = new SelectList(listcate, "IDCategory", "Name", null);
            List <ThuongHieu> listth = new List <ThuongHieu>();

            foreach (var item in db.thuongHieus.ToList())
            {
                ThuongHieu th = new ThuongHieu();
                th.ID   = item.ID;
                th.Name = item.Name;
                listth.Add(th);
            }
            ViewBag.IDThuongHieu = new SelectList(listth, "ID", "Name", null);
            List <ChatLieu> listcl = new List <ChatLieu>();

            foreach (var item in db.chatLieus.ToList())
            {
                ChatLieu cl = new ChatLieu();
                cl.ID  = item.ID;
                cl.Ten = item.Ten;
                listcl.Add(cl);
            }
            ViewBag.IDChatLieu = new SelectList(listcl, "ID", "Ten", null);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 14
0
 internal Category(_Category data)
     : base(data.id)
 {
     Name         = data.name;
     DisplayOrder = data.displayOrder;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Result signifying single formatted HTTP query result for use in presentation layer.
 /// </summary>
 /// <param name="title"></param>
 /// <param name="trusted"></param>
 /// <param name="category"></param>
 public Result(string title, bool trusted, _Category category)
 {
     Title    = title;
     Trusted  = trusted;
     Category = category;
 }