Ejemplo n.º 1
0
    //取类别ID
    private int GetCategoryTypeId(string catName)
    {
        catTypeList = cat_bll.GetUserCategoryList(userId);
        foreach (DataRow dr in catTypeList.Rows)
        {
            if (catName == dr["CategoryTypeName"].ToString())
            {
                return(Convert.ToInt32(dr["CategoryTypeID"]));
            }
        }

        UserCategoryInfo category = new UserCategoryInfo();

        category.CategoryTypeID    = cat_bll.GetMaxCategoryTypeId(userId);
        category.CategoryTypeName  = catName;
        category.CategoryTypePrice = 0m;
        category.UserID            = userId;
        category.CategoryTypeLive  = 1;
        category.Synchronize       = 1;
        category.ModifyDate        = DateTime.Now;

        bool success = cat_bll.InsertUserCategory(category);

        if (success)
        {
            return(category.CategoryTypeID);
        }
        else
        {
            throw new Exception();
        }
    }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int    catId    = Convert.ToInt32(Request.Form["catid"]);
        string catName  = Request.Form["catname"].ToString();
        string catPrice = Request.Form["catprice"] ?? "";
        byte   catLive  = Convert.ToByte(Request.Form["catlive"]);
        int    userId   = Convert.ToInt32(Request.Form["userid"]);

        UserCategoryInfo category = new UserCategoryInfo();

        category.CategoryTypeID   = catId;
        category.CategoryTypeName = catName;
        if (catPrice != "")
        {
            category.CategoryTypePrice = Convert.ToInt32(catPrice);
        }
        category.UserID           = userId;
        category.CategoryTypeLive = catLive;
        category.Synchronize      = 0;

        bool success = bll.UserCategoryExistsWithSync(userId, catId);

        if (success)
        {
            success = bll.UpdateUserCategory(category);
        }
        else
        {
            success = bll.InsertUserCategory(category);
        }

        string result = "{";

        if (success)
        {
            result += "\"result\":\"ok\"";
        }
        else
        {
            result += "\"result\":\"error\"";
        }
        result += "}";

        Response.Write(result);
        Response.End();
    }
Ejemplo n.º 3
0
        //类别更新操作
        protected void CatTypeList_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int    catTypeId      = Convert.ToInt32(CatTypeList.DataKeys[e.RowIndex].Value);
            string catTypeName    = ((TextBox)CatTypeList.Rows[e.RowIndex].FindControl("CatTypeNameBox")).Text.Trim();
            string catTypeNameHid = ((HiddenField)CatTypeList.Rows[e.RowIndex].FindControl("CatTypeNameHid")).Value;
            string catTypePrice   = ((TextBox)CatTypeList.Rows[e.RowIndex].FindControl("CatTypePriceBox")).Text.Trim();

            if (catTypeName == "")
            {
                Utility.Alert(this, "类别名称未填写!");
                return;
            }

            if (catTypePrice != "")
            {
                if (!ValidHelper.CheckNumber(catTypePrice))
                {
                    Utility.Alert(this, "类别预算填写错误!");
                    return;
                }
            }
            else
            {
                catTypePrice = "0";
            }

            bool             success  = false;
            UserCategoryInfo category = new UserCategoryInfo();

            if (catTypeName != catTypeNameHid)
            {
                category = bll.GetUserCategoryByName(userId, catTypeName);
                if (category.CategoryTypeID > 0)
                {
                    Utility.Alert(this, "类别已存在,不能重复添加!");
                    return;
                }
            }

            category.CategoryTypeID    = catTypeId;
            category.CategoryTypeName  = catTypeName;
            category.CategoryTypePrice = Convert.ToInt32(catTypePrice);
            category.UserID            = userId;
            category.CategoryTypeLive  = 1;
            category.Synchronize       = 1;
            category.ModifyDate        = DateTime.Now;

            using (TransactionScope ts = new TransactionScope())
            {
                success = bll.DeleteUserCategory(userId, catTypeId);
                success = bll.InsertUserCategory(category);

                ts.Complete();
            }

            if (success)
            {
                CacheHelper.RemoveCache(string.Format("cattype_{0}", userId));
                Utility.Alert(this, "更新成功。");

                CatTypeList.EditIndex = -1;
                BindGrid();
            }
            else
            {
                Utility.Alert(this, "更新失败!");
            }
        }