protected void gviewProductCategory_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Ref_ProductCategory prodCategory = new Ref_ProductCategory();

            prodCategory.CategoryID   = Convert.ToInt32((gviewProductCategory.Rows[e.RowIndex].FindControl("hdnCategoryID") as HiddenField).Value);
            prodCategory.CategoryName = (gviewProductCategory.Rows[e.RowIndex].FindControl("txtCategoryName") as TextBox).Text;
            prodCategory.Description  = (gviewProductCategory.Rows[e.RowIndex].FindControl("txtDescription") as TextBox).Text;
            prodCategory.ModifiedBy   = User.Identity.Name.ToString();

            Ref_ProductCategoryManager.Save(prodCategory);
            gviewProductCategory.EditIndex = -1;

            //enable the save button on the panel above after update
            lnkSaveProductCategory.Enabled  = true;
            lnkSaveProductCategory.CssClass = "linkStyle";

            PopulateGridview();



            //show the edit and delete column
            gviewProductCategory.Columns[3].Visible = true; //edit column
            gviewProductCategory.Columns[4].Visible = true; //delete column

            //hide the update and cancel column
            gviewProductCategory.Columns[5].Visible = false; //update column
            gviewProductCategory.Columns[6].Visible = false; //cancel column
        }
Ejemplo n.º 2
0
        private static Ref_ProductCategory FillDataRecord(IDataRecord dr)
        {
            Ref_ProductCategory prodCategory = new Ref_ProductCategory();

            prodCategory.CategoryID   = dr.GetInt32(dr.GetOrdinal("CategoryID"));
            prodCategory.CategoryName = dr.GetString(dr.GetOrdinal("CategoryName"));
            prodCategory.Description  = dr.GetString(dr.GetOrdinal("Description"));
            prodCategory.CreatedDate  = dr.GetDateTime(dr.GetOrdinal("CreatedDate"));
            prodCategory.ModifiedDate = dr.GetDateTime(dr.GetOrdinal("ModifiedDate"));
            prodCategory.CreatedBy    = dr.GetString(dr.GetOrdinal("CreatedBy"));
            prodCategory.ModifiedBy   = dr.GetString(dr.GetOrdinal("ModifiedBy"));

            return(prodCategory);
        }
        protected void lnkSaveProductCategory_OnCommand(object sender, CommandEventArgs e)
        {
            //clear previous messages
            lblMessage.Text = "";

            Ref_ProductCategory newProdCategory = new Ref_ProductCategory();

            newProdCategory.CategoryName = (fviewProdCategory.FindControl("txtProductCategoryName") as TextBox).Text.Trim().ToUpper();
            newProdCategory.Description  = (fviewProdCategory.FindControl("txtProductCategoryDescription") as TextBox).Text.Trim();
            newProdCategory.CreatedBy    = User.Identity.Name.ToString();

            //check if the category name already exist

            //get existing categories
            Ref_ProductCategoryList existingCategories = Ref_ProductCategoryManager.GetList();

            // find a match
            IEnumerable <Ref_ProductCategory> query =
                from cat in existingCategories
                where cat.CategoryName == newProdCategory.CategoryName
                select cat;

            // if there is no match, then proceed with add
            if (!query.Any())
            {
                //add the new product category
                Ref_ProductCategoryManager.Save(newProdCategory);
                //clear the inputs

                (fviewProdCategory.FindControl("txtProductCategoryName") as TextBox).Text        = "";
                (fviewProdCategory.FindControl("txtProductCategoryDescription") as TextBox).Text = "";
            }
            else
            {
                lblMessage.Text      = "Category name" + newProdCategory.CategoryName + " already exist.";
                lblMessage.ForeColor = System.Drawing.Color.Red;
                (fviewProdCategory.FindControl("txtProductCategoryName") as TextBox).Focus();
            }



            PopulateGridview();

            gviewProductCategory.Focus();
        }
Ejemplo n.º 4
0
        public static int Save(Ref_ProductCategory prodCategory)
        {
            int            result;
            MyDBConnection myConn = new MyDBConnection();
            SqlConnection  conn   = new SqlConnection();

            try
            {
                conn = myConn.OpenDB();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "dbo.[InsertUpdateProductCategory]";

                if (prodCategory.CategoryID == -1)
                {
                    cmd.Parameters.Add("@CategoryID", SqlDbType.Int).Value = DBNull.Value;
                }
                else
                {
                    cmd.Parameters.Add("@CategoryID", SqlDbType.Int).Value = prodCategory.CategoryID;
                }
                cmd.Parameters.Add("@CategoryName", SqlDbType.VarChar).Value  = prodCategory.CategoryName;
                cmd.Parameters.Add("@Description", SqlDbType.VarChar).Value   = prodCategory.Description;
                cmd.Parameters.Add("@CreatedDate", SqlDbType.DateTime).Value  = prodCategory.CreatedDate;
                cmd.Parameters.Add("@ModifiedDate", SqlDbType.DateTime).Value = prodCategory.ModifiedDate;
                cmd.Parameters.Add("@CreatedBy", SqlDbType.VarChar).Value     = prodCategory.CreatedBy;
                cmd.Parameters.Add("@ModifiedBy", SqlDbType.VarChar).Value    = prodCategory.ModifiedBy;

                DbParameter returnValue = cmd.CreateParameter();
                returnValue.Direction = ParameterDirection.ReturnValue;
                cmd.Parameters.Add(returnValue);
                cmd.ExecuteNonQuery();

                result = Convert.ToInt32(returnValue.Value);
            }
            finally
            {
                myConn.CloseDB(conn);
            }

            return(result);
        }
Ejemplo n.º 5
0
        public static Ref_ProductCategory GetByID(int id)
        {
            Ref_ProductCategory prodCategory = new Ref_ProductCategory();
            MyDBConnection      myConn       = new MyDBConnection();
            SqlConnection       conn         = new SqlConnection();
            SqlDataReader       dr;
            SqlCommand          cmd = null;
            string sql = "Select * from AquaOne.dbo.ProductCategory where categoryID = @categoryID";

            // Open the connection
            conn = myConn.OpenDB();
            cmd  = new SqlCommand(sql, conn);
            cmd.Parameters.Add("@Category", SqlDbType.Int).Value = id;
            dr = cmd.ExecuteReader();

            if (dr.Read())
            {
                prodCategory = FillDataRecord(dr);
            }
            cmd.Dispose();
            //close the connection
            myConn.CloseDB(conn);
            return(prodCategory);
        }
 public static int Save(Ref_ProductCategory prodCategory)
 {
     return(Ref_ProductCategoryDB.Save(prodCategory));
 }