Example #1
0
    public static Result SetSessionByCategoryList()
    {
        CategoryBO oCategoryBO = new CategoryBO();
        Result oResult = new Result();

        List<Category> oListCategory = new List<Category>();

        try
        {
            oResult = oCategoryBO.CategoryGetFromDatabaseForSetSession();

            if (oResult.ResultIsSuccess)
            {
                oListCategory = (List<Category>)oResult.ResultObject;

                Utils.SetSession(SessionManager.csStoredCategory, oListCategory);
            }
        }
        catch (Exception oEx)
        {
            oResult.ResultIsSuccess = false;
            oResult.ResultException = oEx;
            oResult.ResultMessage = "Exception occured during Set Session By CategoryList.";
        }

        return oResult;
    }
 public void LoadCategory(int catID)
 {
     CategoryBO catBO = new CategoryBO();
     catBO = cardBUS.GetOneCategory(catID);
     CatImage.ImageUrl = catBO.Image;
     CatnameLabel.Text = catBO.CatName;
     CatDesciptionTxt.Text = catBO.Description;
 }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        Category oCategory = new Category();
        Result oResult = new Result();
        CategoryBO oCategoryBO = new CategoryBO();

        try
        {
            if (IsValidCategoryName(txt_CategoryName.Text))
            {
                oCategory.CategoryName = txt_CategoryName.Text;

                oResult = oCategoryBO.CategoryEntry(oCategory);

                if (oResult.ResultIsSuccess)
                {
                    lbl_error.ForeColor = Color.Green;
                    lbl_error.Text = oResult.ResultMessage;

                    clearControlValue();

                    Utils.SetSessionByCategoryList();
                    //LoadCategoryfromSession();
                }
                else
                {
                    lbl_error.ForeColor = Color.Red;
                    lbl_error.Text = oResult.ResultMessage;
                }
            }
            else
            {
                if (txt_CategoryName.Text.Trim().ToLower().Equals("objective") || txt_CategoryName.Text.Trim().ToLower().Equals("descriptive"))
                {
                    lbl_error.ForeColor = Color.Red;
                    lbl_error.Text = "[objective/descriptive] can not be Category Name.";
                }
                else
                {
                    lbl_error.ForeColor = Color.Red;
                    lbl_error.Text = "Category name can not be empty( -, ' not allowed).";
                }
            }
        }
        catch (Exception oEx)
        {
            lbl_error.ForeColor = Color.Red;
            lbl_error.Text = "Exception occured during Category Entry.";
        }
    }
Example #4
0
 public bool AddCategory(string catname,string image,string description)
 {
     try
     {
         CategoryBO catBO = new CategoryBO();
         catBO.CatName = catname;
         catBO.Image = image;
         catBO.Description = description;
         bool hasimage = true;
         if (image == "") 
             hasimage=false;
         cardDAO.InsertCategory(catBO,hasimage);
         return true;
     }
     catch
     {
         return false;
     }
 }
Example #5
0
 public CategoryCollection SelectCategory()
 {
     CategoryCollection catColl= new CategoryCollection();
     SqlCommand cmd= new SqlCommand("SELECT * FROM Category Order BY CatName",cnn);
     cnn.Open();
     SqlDataReader dr= cmd.ExecuteReader();         
     while(dr.Read())
     {
         CategoryBO catBO= new CategoryBO();
         catBO.CatID=Convert.ToInt32(dr["CategoryID"].ToString());
         catBO.CatName=dr["CatName"].ToString();
         catBO.CardCount = Convert.ToInt32(dr["CardCount"].ToString());
         catBO.Image = dr["Image"].ToString();
         catBO.Description = dr["Description"].ToString();   
         catColl.Add(catBO);
     }
     cnn.Close();
     return catColl;
 }
Example #6
0
 public CategoryBO SelectOneCategory(int catid)
 {
     CategoryBO catBO = new CategoryBO();
     SqlCommand cmd = new SqlCommand("SELECT * FROM Category WHERE CategoryID=@catid", cnn);
     cmd.Parameters.AddWithValue("@catid",catid);
     cnn.Open();
     SqlDataReader dr = cmd.ExecuteReader();
     while (dr.Read())
     {               
         catBO.CatID = Convert.ToInt32(dr["CategoryID"].ToString());
         catBO.CatName = dr["CatName"].ToString();
         catBO.CardCount = Convert.ToInt32(dr["CardCount"].ToString());
         catBO.Image = dr["Image"].ToString();
         catBO.Description = dr["Description"].ToString();               
         break;
     }
     cnn.Close();
     return catBO;
 }
Example #7
0
 public bool EditCategory(string catid, string catname,string image,string description)
 {
     try
     {
         CategoryBO catBO = new CategoryBO();
         catBO.CatID =Convert.ToInt32(catid);
         catBO.CatName = catname;
         catBO.Image = image;
         catBO.Description = description;
         bool hasimage = true;
         if (image == "")
             hasimage = false;
         cardDAO.UpdateCategory(catBO,hasimage);
         return true;
     }
     catch
     {
         return false;
     }
 }
Example #8
0
 public void UpdateCategory(CategoryBO catBO,bool hasimage)
 {    SqlCommand cmd = null;
     if (hasimage == true)
     {
         cmd = new SqlCommand("UPDATE Category SET CatName=@catname,Image=@image,Description=@description WHERE CategoryID=@catID", cnn);
         cmd.Parameters.AddWithValue("@catID",catBO.CatID );
         cmd.Parameters.AddWithValue("@catname", catBO.CatName);
         cmd.Parameters.AddWithValue("@image", catBO.Image);
         cmd.Parameters.AddWithValue("@description", catBO.Description);              
     }
     else
     {
         cmd = new SqlCommand("UPDATE Category SET CatName=@catname,Description=@description WHERE CategoryID=@catID", cnn);
         cmd.Parameters.AddWithValue("@catID", catBO.CatID);
         cmd.Parameters.AddWithValue("@catname", catBO.CatName);
         cmd.Parameters.AddWithValue("@description", catBO.Description);    
     }
     cnn.Open();
     cmd.ExecuteNonQuery();
     cnn.Close();
 }
Example #9
0
        public void InsertCategory(CategoryBO catBO,bool hasimage)
        {
            SqlCommand cmd= null;
            if (hasimage == true)
            {
                cmd = new SqlCommand("INSERT INTO Category(catname,image,description) VALUES(@catname,@image,@description)", cnn);
                cmd.Parameters.AddWithValue("@catname", catBO.CatName);
                cmd.Parameters.AddWithValue("@image", catBO.Image);
                cmd.Parameters.AddWithValue("@description", catBO.Description);
            }
            else
            {
                cmd = new SqlCommand("INSERT INTO Category(catname,description) VALUES(@catname,@description)", cnn);
                cmd.Parameters.AddWithValue("@catname", catBO.CatName);
                cmd.Parameters.AddWithValue("@description", catBO.Description);
            }

            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
    protected void btn_Update_Click(object sender, EventArgs e)
    {
        List<Category> oListCategory = new List<Category>();

        CategoryBO oCategoryBO = new CategoryBO();
        Result oResult = new Result();

        Boolean bAnyChecked = false;

        try
        {
            oListCategory = (List<Category>)Utils.GetSession(SessionManager.csStoredCategory);

            int[] iArrCheck = new int[oListCategory.Count];

            for (int i = 0; i < iArrCheck.Length; i++)
            {
                iArrCheck[i] = 0;
            }

            foreach (GridViewRow oGridRow in Grid_Categories.Rows)
            {
                CheckBox oCheckBox = oGridRow.FindControl("deleteRec") as CheckBox;
                TextBox oTxtName = oGridRow.FindControl("txtCategoryName") as TextBox;

                if (oCheckBox.Checked)
                {
                    bAnyChecked = true;

                    iArrCheck[Grid_Categories.PageIndex * Grid_Categories.PageSize + oGridRow.RowIndex] = 1;

                    if (IsValidCategoryName(oTxtName.Text, oListCategory))
                    {
                        oListCategory[Grid_Categories.PageIndex * Grid_Categories.PageSize + oGridRow.RowIndex].CategoryName = oTxtName.Text;
                    }
                }
                //else
                //{
                //    iArrCheck[oGridRow.RowIndex] = 0;
                //}
            }

            if (bAnyChecked)
            {
                oResult = oCategoryBO.CategoryUpdate(oListCategory, iArrCheck);

                if (oResult.ResultIsSuccess)
                {
                    oListCategory = (List<Category>)oResult.ResultObject;

                    Utils.SetSession(SessionManager.csStoredCategory, oListCategory);

                    //if (oListCategory.Count <= 0)
                    //{
                    //    lbl_error.ForeColor = Color.Red;
                    //    lbl_error.Text = "No Category Found.";
                    //}

                    //Grid_Categories.DataSource = oListCategory;
                    //Grid_Categories.DataBind();

                    LoadCategoriesToGrid();

                    lbl_error.ForeColor = Color.Green;
                    lbl_error.Text = oResult.ResultMessage;
                }
                else
                {
                    lbl_error.ForeColor = Color.Red;
                    lbl_error.Text = oResult.ResultMessage;
                }

            }
            else
            {
                lbl_error.ForeColor = Color.Red;
                lbl_error.Text = "Please Select a Category.";
            }
        }
        catch (Exception oEx)
        {
            lbl_error.ForeColor = Color.Red;
            lbl_error.Text = "Category Update Exception.";
        }
    }
    private void LoadCategoriesToGrid()
    {
        CategoryBO oCategoryBO = new CategoryBO();
        Result oResult = new Result();
        List<Category> oListCategory = new List<Category>();

        try
        {
            oListCategory = (List<Category>)Utils.GetSession(SessionManager.csStoredCategory);

            if (oListCategory.Count <= 0)
            {
                tblCategory.Visible = false;

                lbl_error.ForeColor = Color.Red;
                lbl_error.Text = "No Category Found.";
            }
            else
            {
                tblCategory.Visible = true;

                Grid_Categories.DataSource = oListCategory;
                Grid_Categories.DataBind();
            }

        }
        catch (Exception oEx)
        {
            lbl_error.ForeColor = Color.Red;
            lbl_error.Text = "Grid Load Exception.";
        }
    }
Example #12
0
 public void Add(CategoryBO catBO)
 {
     List.Add(catBO);
 }