Beispiel #1
0
        /// <summary>
        /// 添加事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            string spic = "";

            if (this.FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
            {
                if (!Directory.Exists(Server.MapPath(Global_Upload.NewsImgPath)))         //判断目录是否存在
                {
                    Directory.CreateDirectory(Server.MapPath(Global_Upload.NewsImgPath)); //创建目录
                }
                spic = DoClass.UploadFile(FileUpload1.PostedFile, Global_Upload.Imgsize, Global_Upload.ImgType, Global_Upload.NewsImgPath);

                if (spic == "-1")
                {
                    return;
                }
                else if (spic == "0")
                {
                    return;
                }
                else
                {
                    spic             = Global_Upload.NewsImgPath + spic;
                    this.lblUrl.Text = spic;
                }
            }
            if (txtOrder.Text.Trim() != "")
            {
                if (!RegExp.IsNumeric(txtOrder.Text.Trim()))
                {
                    lblError.Text = "顺序号输入有误!";
                    return;
                }
            }
            NewsType item = new NewsType();

            item.name = txtTitle.Text.Trim();
            if (item.name.Length == 0)
            {
                lblError.Text = "分类名称不能为空!";
                return;
            }
            item.parentId = Convert.ToInt32(ddlParent.SelectedValue);

            item.status = 0;
            if (txtOrder.Text.Trim() != "")
            {
                item.status = Convert.ToInt32(txtOrder.Text.Trim());
            }
            item.remark   = lblUrl.Text;
            item.typedesc = "";
            item.pagename = "";
            string hidId = this.hidId.Value;

            if (hidId != "")
            {
                item.id = Convert.ToInt32(hidId);
                NewsTypeService.UpdateModel(item);
            }
            else
            {
                if (NewsTypeService.Exists(item))
                {
                    lblError.Text = "该分类以及存在";
                    return;
                }
                NewsTypeService.Add(item);
                txtTitle.Text = "";
                lblUrl.Text   = "";
                txtOrder.Text = "";
            }
            this.hidId.Value = "";
            sp.InitBindData(this.repInfo, pager1, "NewsType", "id", sear());
        }