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())
            {
                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())
            {
                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 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 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 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 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 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();
            }
        }