protected void btnSave_Click(object sender, EventArgs e)
        {
            //do insert or update
            using (InoviceConnection db = new InoviceConnection())
            {
                supplier_information objC = new supplier_information();

                if (!String.IsNullOrEmpty(Request.QueryString["SUPPLIER_ID"]))
                {
                    Int32 SUPPLIER_ID = Convert.ToInt32(Request.QueryString["SUPPLIER_ID"]);
                    objC = (from c in db.supplier_information
                            where c.SUPPLIER_ID == SUPPLIER_ID
                            select c).FirstOrDefault();
                }

                //populate the supplier from the input form
                objC.SUPPLIER_NAME= txtName.Text;
                objC.ADDRESS = txtAddress.Text;
                objC.CITY = txtCity.Text;
                objC.STATE = txtState.Text;
                objC.POSTAL_CODE = txtPostalCode.Text;

                if (String.IsNullOrEmpty(Request.QueryString["SUPPLIER_ID"]))
                {
                    //add
                    db.supplier_information.Add(objC);
                }

                //save and redirect
                db.SaveChanges();
                Response.Redirect("SupplierList.aspx");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //do insert or update
            using (InoviceConnection db = new InoviceConnection())
            {
                category_information objC = new category_information();

                if (!String.IsNullOrEmpty(Request.QueryString["ID"]))
                {
                    Int32 ID = Convert.ToInt32(Request.QueryString["ID"]);
                    objC = (from c in db.category_information
                            where c.ID == ID
                            select c).FirstOrDefault();
                }

                //populate the product category from the input form
                objC.CATEGORY_NAME = txtName.Text;

                if (String.IsNullOrEmpty(Request.QueryString["ID"]))
                {
                    //add product category
                    db.category_information.Add(objC);
                }

                //save and redirect
                db.SaveChanges();
                Response.Redirect("categoryList.aspx");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //do insert or update
            using (InoviceConnection db = new InoviceConnection())
            {
                product_information objC = new product_information();

                if (!String.IsNullOrEmpty(Request.QueryString["PRODUCT_ID"]))
                {
                    Int32 PRODUCT_ID = Convert.ToInt32(Request.QueryString["PRODUCT_ID"]);
                    objC = (from p in db.product_information
                            where p.PRODUCT_ID == PRODUCT_ID
                            select p).FirstOrDefault();
                }

                //populate the product details from the input form
                objC.NAME = txtName.Text;
                objC.QUANTITY = Convert.ToInt32(txtQuantity.Text);
                objC.UNIT_PRICE = Convert.ToDecimal(txtPrice.Text);
                objC.SUPPLIER_ID = Convert.ToInt32(ddlSupplier.SelectedValue);
                objC.CATEGORY_ID = Convert.ToInt32(ddlCategory.SelectedValue);

                if (String.IsNullOrEmpty(Request.QueryString["PRODUCT_ID"]))
                {
                    //add
                    db.product_information.Add(objC);
                }

                //save and redirect
                db.SaveChanges();
                Response.Redirect("productList.aspx");
            }
        }
        protected void GetCategory()
        {
            using (InoviceConnection db = new InoviceConnection())
            {
                var cate = (from c in db.category_information
                            orderby c.CATEGORY_NAME
                            select c);

                ddlCategory.DataSource = cate.ToList();
                ddlCategory.DataBind();
            }
        }
        protected void GetCategory()
        {
            //populate the existing product category for editing
            using (InoviceConnection db = new InoviceConnection())
            {
                Int32 ID = Convert.ToInt32(Request.QueryString["ID"]);

                category_information objC = (from c in db.category_information
                               where c.ID == ID
                               select c).FirstOrDefault();

                //populate the form
                txtName.Text = objC.CATEGORY_NAME;
            }
        }
        protected void GetProduct()
        {
            using (InoviceConnection db = new InoviceConnection())
            {

                //append the current direction to the Sort Column
                String sortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                //Get the Product Details
                var supp = (from p in db.product_information
                           select new { p.PRODUCT_ID, p.NAME, p.category_information.CATEGORY_NAME, p.supplier_information.SUPPLIER_NAME,p.QUANTITY, p.UNIT_PRICE});

                //bind the Product GridView
                grdProduct.DataSource = supp.AsQueryable().OrderBy(sortString).ToList();
                grdProduct.DataBind();
            }
        }
        protected void GetSupplier()
        {
            using (InoviceConnection db = new InoviceConnection())
            {

                //append the current direction to the Sort Column
                String sortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                //Get the Product Supplier Details
                var supp = from s in db.supplier_information
                               select new { s.SUPPLIER_ID, s.SUPPLIER_NAME , s.ADDRESS ,s.CITY , s.STATE , s.POSTAL_CODE};

                //bind the Supplier GridView
                grdSupplier.DataSource = supp.AsQueryable().OrderBy(sortString).ToList();
                grdSupplier.DataBind();
            }
        }
        protected void GetCategories()
        {
            using (InoviceConnection db = new InoviceConnection())
            {

                //append the current direction to the Sort Column
                String sortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                //Get the Product Category Details
                var category = from c in db.category_information
                                select new { c.ID, c.CATEGORY_NAME };

                //bind the Category GridView
                grdCategory.DataSource = category.AsQueryable().OrderBy(sortString).ToList();
                grdCategory.DataBind();
            }
        }
        protected void GetOrder()
        {
            //Getting Authenticated User
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                if (HttpContext.Current.User.IsInRole("admin"))
                {
                    using (InoviceConnection db = new InoviceConnection())
                    {

                        //append the current direction to the Sort Column
                        String sortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                        //Get the Product Details
                        var order = (from o in db.order_master
                                     select new { o.ORDER_ID, o.AspNetUser.UserName, o.ORDER_DATE, o.category_information.CATEGORY_NAME, o.product_information.NAME, o.QUANTITY, o.UNIT_PRICE, total = o.UNIT_PRICE * o.QUANTITY });

                        //bind the Product GridView
                        grdOrder.DataSource = order.AsQueryable().OrderBy(sortString).ToList();
                        grdOrder.DataBind();
                    }
                }
                else
                {
                    using (InoviceConnection db = new InoviceConnection())
                    {
                        //Get Loggedin UserId
                        String USER_ID = HttpContext.Current.User.Identity.GetUserId();

                        //append the current direction to the Sort Column
                        String sortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                        //Get the Product Details
                        var order = (from o in db.order_master
                                     where o.USER_ID == USER_ID
                                     select new { o.ORDER_ID, o.AspNetUser.UserName, o.ORDER_DATE, o.category_information.CATEGORY_NAME, o.product_information.NAME, o.QUANTITY, o.UNIT_PRICE, total = o.UNIT_PRICE * o.QUANTITY });

                        //bind the Product GridView
                        grdOrder.DataSource = order.AsQueryable().OrderBy(sortString).ToList();
                        grdOrder.DataBind();
                    }
                }
            }
        }
        protected void GetProduct()
        {
            //populate the existing product for editing
            using (InoviceConnection db = new InoviceConnection())
            {
                Int32 PRODUCT_ID = Convert.ToInt32(Request.QueryString["PRODUCT_ID"]);

                product_information objC = (from p in db.product_information
                                             where p.PRODUCT_ID == PRODUCT_ID
                                             select p).FirstOrDefault();

                //populate the form
                txtName.Text = objC.NAME;
                txtPrice.Text = objC.UNIT_PRICE.ToString();
                txtQuantity.Text = objC.QUANTITY.ToString();
                ddlCategory.SelectedValue = objC.CATEGORY_ID.ToString();
                ddlSupplier.SelectedValue = objC.SUPPLIER_ID.ToString();
            }
        }
        protected void grdProduct_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //get selected Product ID
            Int32 PRODUCT_ID = Convert.ToInt32(grdProduct.DataKeys[e.RowIndex].Values["PRODUCT_ID"]);

            using (InoviceConnection db = new InoviceConnection())
            {
                //get selected Product
                product_information objC = (from p in db.product_information
                                             where p.PRODUCT_ID== PRODUCT_ID
                                             select p).FirstOrDefault();

                //delete
                db.product_information.Remove(objC);
                db.SaveChanges();

                //refresh grid
                GetProduct();
            }
        }
        protected void GetSupplier()
        {
            //populate the existing product supplier for editing
            using (InoviceConnection db = new InoviceConnection())
            {
                Int32 SUPPLIER_ID = Convert.ToInt32(Request.QueryString["SUPPLIER_ID"]);

                supplier_information objC = (from s in db.supplier_information
                                             where s.SUPPLIER_ID == SUPPLIER_ID
                                             select s).FirstOrDefault();

                //populate the form
                txtName.Text = objC.SUPPLIER_NAME;
                txtAddress.Text = objC.ADDRESS;
                txtCity.Text = objC.CITY;
                txtState.Text = objC.STATE;
                txtPostalCode.Text = objC.POSTAL_CODE;

            }
        }
        protected void grdCategory_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //get selected category ID
            Int32 ID = Convert.ToInt32(grdCategory.DataKeys[e.RowIndex].Values["ID"]);

            using (InoviceConnection db = new InoviceConnection())
            {
                //get selected Category
                category_information objC = (from c in db.category_information
                               where c.ID == ID
                               select c).FirstOrDefault();

                //delete
                db.category_information.Remove(objC);
                db.SaveChanges();

                //refresh grid
                GetCategories();
            }
        }
        protected void grdSupplier_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //get selected Supplier ID
            Int32 SUPPLIER_ID = Convert.ToInt32(grdSupplier.DataKeys[e.RowIndex].Values["SUPPLIER_ID"]);

            using (InoviceConnection db = new InoviceConnection())
            {
                //get selected Supplier
                supplier_information objC = (from s in db.supplier_information
                                             where s.SUPPLIER_ID == SUPPLIER_ID
                                             select s).FirstOrDefault();

                //delete
                db.supplier_information.Remove(objC);
                db.SaveChanges();

                //refresh grid
                GetSupplier();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //do insert or update
            using (InoviceConnection db = new InoviceConnection())
            {
                order_master objC = new order_master();

                if (!String.IsNullOrEmpty(Request.QueryString["ORDER_ID"]))
                {
                    Int32 ORDER_ID = Convert.ToInt32(Request.QueryString["ORDER_ID"]);
                    objC = (from p in db.order_master
                            where p.ORDER_ID == ORDER_ID
                            select p).FirstOrDefault();
                }

                //populate the product details from the input form
                objC.ORDER_DATE = Convert.ToDateTime(txtOrderDate.Text);
                objC.QUANTITY = Convert.ToInt32(txtQuantity.Text);
                objC.UNIT_PRICE = Convert.ToDecimal(lblPrice.Text);
                objC.PRODUCT_ID = Convert.ToInt32(ddlProduct.SelectedValue);
                objC.CATEGORY_ID = Convert.ToInt32(ddlCategory.SelectedValue);

                if (String.IsNullOrEmpty(Request.QueryString["ORDER_ID"]))
                {
                    if (HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        objC.USER_ID = HttpContext.Current.User.Identity.GetUserId();
                    }

                    //add
                    db.order_master.Add(objC);
                }

                //save and redirect
                db.SaveChanges();
                Response.Redirect("orderList.aspx");
            }
        }
        protected void GetOrder()
        {
            //populate the existing product for editing
            using (InoviceConnection db = new InoviceConnection())
            {
                Int32 ORDER_ID = Convert.ToInt32(Request.QueryString["ORDER_ID"]);

                order_master objC = (from o in db.order_master
                                     where o.ORDER_ID == ORDER_ID
                                            select o).FirstOrDefault();

                //populate the form
                txtOrderDate.Text = String.Format("{0:MM-dd-yyyy}",objC.ORDER_DATE);
                txtQuantity.Text = objC.QUANTITY.ToString();
                ddlCategory.SelectedValue = objC.CATEGORY_ID.ToString();
                GetProduct();
                ddlProduct.SelectedValue = objC.PRODUCT_ID.ToString();
                lblPrice.Text = String.Format("{0:n2}" ,objC.UNIT_PRICE);
                lblTotal.Text = String.Format("{0:n2}" ,(objC.UNIT_PRICE * objC.QUANTITY));
            }
        }
        protected void GetProduct()
        {
            using (InoviceConnection db = new InoviceConnection())
            {
                //Store the selected DepartmentID
                Int32 CATEGORY_ID = Convert.ToInt32(ddlCategory.SelectedValue);

                var ObjC = from c in db.product_information
                           where c.CATEGORY_ID == CATEGORY_ID
                           orderby c.NAME
                           select c;

                //bind to the course dropdown
                ddlProduct.DataSource = ObjC.ToList();
                ddlProduct.DataBind();

                //add default options to the 2 dropdowns
                ListItem newItem = new ListItem("-Select-", "0");
                ddlProduct.Items.Insert(0, newItem);
            }
        }
        protected void GetPrice()
        {
            using (InoviceConnection db = new InoviceConnection())
            {
                //Store the selected DepartmentID
                Int32 PRODUCT_ID = Convert.ToInt32(ddlProduct.SelectedValue);

                product_information objC = (from o in db.product_information
                                     where o.PRODUCT_ID == PRODUCT_ID
                                            select o).FirstOrDefault();

                lblPrice.Text = objC.UNIT_PRICE.ToString();
            }
        }
        protected void grdOrder_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //get selected Product ID
            Int32 ORDER_ID = Convert.ToInt32(grdOrder.DataKeys[e.RowIndex].Values["ORDER_ID"]);

            using (InoviceConnection db = new InoviceConnection())
            {
                //get selected Product
                order_master objC = (from o in db.order_master
                                            where o.ORDER_ID == ORDER_ID
                                            select o).FirstOrDefault();

                //delete
                db.order_master.Remove(objC);
                db.SaveChanges();

                //refresh grid
                GetOrder();
            }
        }
        protected void GetSupplier()
        {
            using (InoviceConnection db = new InoviceConnection())
            {
                var supp = (from s in db.supplier_information
                            orderby s.SUPPLIER_NAME
                            select s);

                ddlSupplier.DataSource = supp.ToList();
                ddlSupplier.DataBind();
            }
        }