protected void btnSave_Click(object sender, EventArgs e)
        {
            if (txtCategoryName.Text == "")
            {
                txtCategoryName.Focus();
                return;
            }

            CDTO.CategoryName = txtCategoryName.Text.ToString();


            CDTO.CreateDate = System.DateTime.Now;
            CDTO.CreateBy   = "tarun";
            if (btnSave.Text == "Save")
            {
                CBLL.Add(CDTO);
                pagingLoal();
                clearCntrol();
            }
            else
            {
                CDTO.CatId      = Convert.ToInt32(HFUID.Value);
                CDTO.UpdateDate = System.DateTime.Now;
                CDTO.UpdateBy   = "tarun";
                CBLL.Edit(CDTO);
                btnSave.Text = "Save";
                pagingLoal();
                clearCntrol();
            }
        }
Esempio n. 2
0
        public ActionResult Edit(CategoryInfo info)
        {
            CategoryInfo infoExist = CategoryBLL.GetList(p => p.Name == info.Name).FirstOrDefault();

            if (infoExist != null && infoExist.ID != info.ID)
            {
                return(Json(new APIJson(-1, "名称已存在")));
            }
            if (string.IsNullOrEmpty(info.Name))
            {
                return(Json(new APIJson(-1, "名称未填写")));
            }
            if (string.IsNullOrEmpty(info.Name.Trim()))
            {
                return(Json(new APIJson(-1, "名称不能是空格,请正确填写")));
            }
            infoExist = CategoryBLL.GetList(p => p.ID == info.ID).FirstOrDefault();
            if (null == infoExist)
            {
                return(Json(new APIJson(-1, "parms error")));
            }

            infoExist.Name   = info.Name;
            infoExist.Enable = info.Enable;
            if (CategoryBLL.Edit(infoExist))
            {
                return(Json(new APIJson(0, "提交成功", info)));
            }
            return(Json(new APIJson(-1, "提交失败", info)));
        }
Esempio n. 3
0
        public ActionResult EditCate(string CateName, int Sort, int CateId, int ParentId = 0)
        {
            MsgBase msg = new MsgBase();

            try {
                Category model = cateBll.GetById(CateId);
                if (model != null)
                {
                    if (CateName != model.CateName)
                    {
                        Category cate = cateBll.GetByName(CateName.Trim());
                        if (cate != null)
                        {
                            msg.Code    = 2;
                            msg.Message = "分类已经存在";
                            return(Json(msg));
                        }
                    }
                    if (ParentId == model.CateId)
                    {
                        msg.Message = "上级分类不能为自身";
                        msg.Code    = 3;
                        return(Json(msg));
                    }
                    List <Category> lstSubCate = cateBll.GetList(model.CateId);
                    foreach (Category subCate in lstSubCate)
                    {
                        if (ParentId == subCate.CateId)
                        {
                            msg.Message = "上级分类不能为子分类";
                            msg.Code    = 4;
                            return(Json(msg));
                        }
                    }
                    model.CateName = CateName.Trim();
                    model.ParentId = ParentId;
                    model.Sort     = Sort;
                    int i = cateBll.Edit(model);
                    msg.Message = i > 0 ? MsgBase.SuccessMessage : MsgBase.FailMessage;
                    msg.Code    = i > 0 ? 1 : 0;
                }
            }
            catch (Exception) {
                msg.Code    = -1;
                msg.Message = MsgBase.ErrMessage;
            }
            return(Json(msg));
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtCategoryName.Text == "")
                {
                    txtCategoryName.Focus();
                    return;
                }

                CDTO.CategoryName = txtCategoryName.Text.ToString();


                CDTO.CreateDate = System.DateTime.Now;
                CDTO.CreateBy   = HttpContext.Current.User.Identity.Name;
                if (btnSave.Text == "Save")
                {
                    CBLL.Add(CDTO);
                    pagingLoal();
                    clearCntrol();
                }
                else
                {
                    CDTO.CatId      = Convert.ToInt32(HFUID.Value);
                    CDTO.UpdateDate = System.DateTime.Now;
                    CDTO.UpdateBy   = HttpContext.Current.User.Identity.Name;
                    CBLL.Edit(CDTO);
                    btnSave.Text = "Save";
                    pagingLoal();
                    clearCntrol();
                }
            }
            catch (Exception ex)
            {
                Show(ex.Message);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Used to save details to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            string AlertMessage = string.Empty;
            string message      = string.Empty;

            if (ViewState["BGT_CATEGORYID"].ToString() == "0")
            {
                CategoryBLL CategoryBLLobj = new CategoryBLL();

                try
                {
                    string     uID           = Session["USER_ID"].ToString();
                    CategoryBO CategoryBOobj = new CategoryBO();
                    CategoryBOobj.BGT_CATEGORYNAME = CategoryTextBox.Text.ToString().Trim();
                    CategoryBOobj.CREATEDBY        = Convert.ToInt32(uID);

                    CategoryBLL BLLobj = new CategoryBLL();
                    message = BLLobj.Insert(CategoryBOobj);

                    if (string.IsNullOrEmpty(message) || message == "" || message == "null")
                    {
                        message = "Data saved successfully";
                        ClearAll();
                        BindGrid(true, true);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                finally
                {
                    CategoryBLLobj = null;
                }
            }
            else
            {
                CategoryBLL CategoryBLLobj = new CategoryBLL();

                try
                {
                    string     uID           = Session["USER_ID"].ToString();
                    CategoryBO CategoryBOobj = new CategoryBO();
                    CategoryBOobj.BGT_CATEGORYNAME = CategoryTextBox.Text.ToString().Trim();
                    CategoryBOobj.BGT_CATEGORYID   = Convert.ToInt32(ViewState["BGT_CATEGORYID"]);
                    CategoryBOobj.CREATEDBY        = Convert.ToInt32(uID);

                    CategoryBLL BLLobj = new CategoryBLL();
                    message = BLLobj.Edit(CategoryBOobj);

                    if (string.IsNullOrEmpty(message) || message == "" || message == "null")
                    {
                        message = "Data updated successfully";
                        ClearAll();
                        BindGrid(true, true);
                        SetUpdateMode(false);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    CategoryBLLobj = null;
                }
            }
            AlertMessage = "alert('" + message + "');";
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", AlertMessage, true);
        }
Esempio n. 6
0
        //新增、更新和删除时,存盘的工作
        private void btnSave_Click(object sender, EventArgs e)
        {
            switch (op)
            {
            case EnumOperation.Insert:
                _categoryObj = new Category()
                {
                    CategoryName = txtCategoryName.Text.Trim()
                };
                //检测是否有重复的分类
                if (_list.FirstOrDefault(x => x.CategoryName == _categoryObj.CategoryName) != null)
                {
                    MessageBox.Show("不能添加重复的分类");
                    return;
                }
                if (_categoryBll.Add(_categoryObj))
                {
                    //重新查询数据,并对正处理的数据记录进行定位
                    QueryData();
                    var id = _list.FirstOrDefault(x => x.CategoryName == _categoryObj.CategoryName).CategoryID;
                    LocationNewRow(id);
                }
                break;

            case EnumOperation.Update:
                if (_categoryObj != null)
                {
                    _categoryObj.CategoryName = txtCategoryName.Text.Trim();
                    if (_categoryBll.Edit(_categoryObj))
                    {
                        //重新查询数据,并对正处理的数据记录进行定位
                        QueryData();
                        var id = _list.FirstOrDefault(x => x.CategoryName == _categoryObj.CategoryName).CategoryID;
                        LocationNewRow(id);
                    }
                }
                else
                {
                    MessageBox.Show("请先选择一条分类记录");
                    return;
                }
                break;

            case EnumOperation.Delete:
                if (_categoryObj != null)
                {
                    if (_categoryBll.Delete(_categoryObj))
                    {
                        MessageBox.Show("删除成功");
                        QueryData();
                    }
                }
                else
                {
                    MessageBox.Show("请先选择一条分类记录");
                    return;
                }
                break;

            case EnumOperation.None:
            default:
                break;
            }
        }