protected void btnAddNew_Click(object sender, EventArgs e)
    {
        Cmn.uploadFile upF             = new Cmn.uploadFile();
        string[]       allowExtensions = { ".jpg", ".gif", ".png" };
        int            maxSize         = Convert.ToInt32(Cmn.WebConfig.getApp("app_MaxSizeUpload"));
        string         savePath        = Request.MapPath("~/upload/Article/");
        string         fileName        = myFileUpload.FileName;

        try
        {
            upF.Upload(this.myFileUpload, allowExtensions, maxSize, savePath, fileName);
        }
        catch (Exception exp)
        {
            Cmn.Js.ShowAlert(exp.Message);
            return;
        }

        DBEntity.Tab_Article ent = new DBEntity.Tab_Article();
        ent.Title          = this.Title.Text;
        ent.PreviewPicture = fileName;
        ent.Content        = this.fck.Text;
        ent.ReleaseDate    = DateTime.Parse(this.ReleaseDate.Text);
        ent.HomeShowsBool  = this.HomeShowsBool.SelectedValue;
        string idx = ent.AddNew(ent).ToString();

        if (this.HomeShowsBool.SelectedValue == "Yes")
        {
            string strSql = string.Format("update Tab_Article set HomeShowsBool='Yes' where Idx={0};update Tab_Article set HomeShowsBool='No' where Idx<>{0}", idx);
            SqlHelper.ExecuteNonQuery(CommandType.Text, strSql);
        }

        Cmn.Js.ShowAlert("操作成功!");
        Cmn.Js.ExeScript("location.href='ArticleSisleyManage.aspx'");
    }
Exemple #2
0
    private void GetArticleSisleyDetail()
    {
        string Idx = Request["Idx"];

        if (string.IsNullOrEmpty(Idx))
        {
            Response.Redirect("KOL-share.aspx");
        }
        DBEntity.Tab_Article ent = new DBEntity.Tab_Article();
        ent               = ent.Get(Idx);
        this.Title.Text   = ent.Title;
        this.Content.Text = ent.Content;
    }
        private static Tab_Article ToModel(DataRow row)
        {
            Tab_Article model = new Tab_Article();

            model.Idx            = row.IsNull("Idx")?null:(System.Int32?)row["Idx"];
            model.Title          = row.IsNull("Title")?null:(System.String)row["Title"];
            model.PreviewPicture = row.IsNull("PreviewPicture")?null:(System.String)row["PreviewPicture"];
            model.Content        = row.IsNull("Content")?null:(System.String)row["Content"];
            model.CreatedDate    = row.IsNull("CreatedDate")?null:(System.DateTime?)row["CreatedDate"];
            model.ReleaseDate    = row.IsNull("ReleaseDate")?null:(System.DateTime?)row["ReleaseDate"];
            model.HomeShowsBool  = row.IsNull("HomeShowsBool")?null:(System.String)row["HomeShowsBool"];
            return(model);
        }
        public bool Update(Tab_Article model)
        {
            string sql  = "update Tab_Article set Title=@Title,PreviewPicture=@PreviewPicture,Content=@Content,ReleaseDate=@ReleaseDate,HomeShowsBool=@HomeShowsBool where Idx=@Idx";
            int    rows = SqlHelper.ExecuteNonQuery(CommandType.Text, sql
                                                    , new SqlParameter("@Title", model.Title)
                                                    , new SqlParameter("@PreviewPicture", model.PreviewPicture)
                                                    , new SqlParameter("@Content", model.Content)
                                                    , new SqlParameter("@ReleaseDate", model.ReleaseDate)
                                                    , new SqlParameter("@HomeShowsBool", model.HomeShowsBool)
                                                    , new SqlParameter("Idx", model.Idx)
                                                    );

            return(rows > 0);
        }
        public int AddNew(Tab_Article model)
        {
            string sql = "insert into Tab_Article(Title,PreviewPicture,Content,CreatedDate,ReleaseDate,HomeShowsBool)  values(@Title,@PreviewPicture,@Content,getdate(),@ReleaseDate,@HomeShowsBool); select @@identity ;";
            int    Idx = Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, sql
                                                                 , new SqlParameter("@Title", model.Title)
                                                                 , new SqlParameter("@PreviewPicture", model.PreviewPicture)
                                                                 , new SqlParameter("@Content", model.Content)

                                                                 , new SqlParameter("@ReleaseDate", model.ReleaseDate)
                                                                 , new SqlParameter("@HomeShowsBool", model.HomeShowsBool)
                                                                 ));

            return(Idx);
        }
        public Tab_Article Get(string Idx)
        {
            DataTable dt = SqlHelper.ExecuteDataset(CommandType.Text, "select * from Tab_Article  where Idx=@Idx",
                                                    new SqlParameter("Idx", Idx)).Tables[0];

            if (dt.Rows.Count > 1)
            {
                throw new Exception("more than 1 row was found");
            }

            if (dt.Rows.Count <= 0)
            {
                return(null);
            }

            DataRow     row   = dt.Rows[0];
            Tab_Article model = ToModel(row);

            return(model);
        }
Exemple #7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!this.IsPostBack)
     {
         string idx = Request["Idx"];
         if (!String.IsNullOrEmpty(idx))
         {
             DBEntity.Tab_Article ent = new DBEntity.Tab_Article();
             ent                   = ent.Get(idx);
             this.Title.Text       = ent.Title;
             this.Image1.ImageUrl  = string.Format("~/upload/Article/{0}", ent.PreviewPicture);
             this.fck.Text         = ent.Content;
             this.ReleaseDate.Text = ent.ReleaseDate.ToString();
             for (int i = 0; i < this.HomeShowsBool.Items.Count; i++)
             {
                 if (this.HomeShowsBool.Items[i].Value == ent.HomeShowsBool)
                 {
                     this.HomeShowsBool.Items[i].Selected = true;
                 }
             }
             this.hiddenFileName.Value = ent.PreviewPicture;
         }
     }
 }