Esempio n. 1
0
 /// <summary>
 /// ��������б�
 /// </summary>
 public List<WebProject.Model.BaseData.ZT_COM_News> DataTableToList(DataTable dt)
 {
     List<WebProject.Model.BaseData.ZT_COM_News> modelList = new List<WebProject.Model.BaseData.ZT_COM_News>();
     int rowsCount = dt.Rows.Count;
     if (rowsCount > 0)
     {
         WebProject.Model.BaseData.ZT_COM_News model;
         for (int n = 0; n < rowsCount; n++)
         {
             model = new WebProject.Model.BaseData.ZT_COM_News();
             if(dt.Rows[n]["NewsID"].ToString()!="")
             {
                 model.NewsID=int.Parse(dt.Rows[n]["NewsID"].ToString());
             }
             model.Title=dt.Rows[n]["Title"].ToString();
             model.ImgUrl=dt.Rows[n]["ImgUrl"].ToString();
             model.Body=dt.Rows[n]["Body"].ToString();
             model.NewsTypeNo=dt.Rows[n]["NewsTypeNo"].ToString();
             model.NewsTypeName=dt.Rows[n]["NewsTypeName"].ToString();
             if(dt.Rows[n]["NewsOrder"].ToString()!="")
             {
                 model.NewsOrder=int.Parse(dt.Rows[n]["NewsOrder"].ToString());
             }
             model.CreateBy=dt.Rows[n]["CreateBy"].ToString();
             if(dt.Rows[n]["CreateDate"].ToString()!="")
             {
                 model.CreateDate=DateTime.Parse(dt.Rows[n]["CreateDate"].ToString());
             }
             model.LastUpdateBy=dt.Rows[n]["LastUpdateBy"].ToString();
             if(dt.Rows[n]["LastUpdateDate"].ToString()!="")
             {
                 model.LastUpdateDate=DateTime.Parse(dt.Rows[n]["LastUpdateDate"].ToString());
             }
             model.Remark=dt.Rows[n]["Remark"].ToString();
             modelList.Add(model);
         }
     }
     return modelList;
 }
Esempio n. 2
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (this.txtTitle.Text.Trim() == "")
        {
            MessageBox.Show(this, "请输入新闻标题!");
            return;
        }
        int NewsOrder;
        if (this.txtNewsOrder.Text.Trim() == "")
        {
            NewsOrder = 1000;
        }
        else
        {
            double u;
            if (!double.TryParse(this.txtNewsOrder.Text.Trim(), out u))
            {
                MessageBox.Show(this, "排序必须为数字!");
                return;
            }
            else
            {
                NewsOrder = Convert.ToInt32(this.txtNewsOrder.Text.Trim());
            }
        }
        if (this.txtBody.Text.Trim() == "")
        {
            MessageBox.Show(this, "请输入新闻内容!");
            return;
        }

        Boolean fileTypeOK = false;
        String path = Server.MapPath("~/SysManage/IMG/");
        if (txtImgUrl.HasFile == false)
        {
            WebProject.Model.BaseData.ZT_COM_News model_News = new WebProject.Model.BaseData.ZT_COM_News();
            model_News.Body = this.txtBody.Text.Trim();
            model_News.NewsTypeName = this.txtNewsType.Items[this.txtNewsType.SelectedIndex].Text.ToString();
            model_News.NewsTypeNo = this.txtNewsType.SelectedValue.ToString();
            model_News.CreateBy = SessionUtil.GetAdminSession().AdminNo;
            model_News.CreateDate = DateTime.Now;
            model_News.ImgUrl = "onlinenone.jpg";
            model_News.NewsOrder = Int32.Parse(this.txtNewsOrder.Text.Trim());
            model_News.Title = this.txtTitle.Text.Trim();
            WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
            bll_News.Add(model_News);
            LogManage.WriteLog(Request.UserHostAddress, "新闻管理", "添加新闻", "成功", "新闻标题:" + model_News.Title + ", 创建人:" + SessionUtil.GetAdminSession().AdminNo);
            MessageBox.ShowAndRedirect(this, "添加信息成功!", "NewsList.aspx");
        }
        if (txtImgUrl.HasFile == true)
        {
            String fileExtension = System.IO.Path.GetExtension(txtImgUrl.FileName).ToLower();
            String[] allowedExtensions = { ".bmp", ".jpg", ".jpeg", ".png", ".gif" };
            for (int i = 0; i < allowedExtensions.Length; i++)
            {
                if (fileExtension == allowedExtensions[i])
                {
                    fileTypeOK = true;
                    break;
                }
            }
            if (fileTypeOK == false)
            {
                MessageBox.Show(this, "你要上传的文件类型不符合要求!");
                return;
            }
            if (fileTypeOK == true)
            {
                if (txtImgUrl.PostedFile.ContentLength > 10240000)
                {
                    MessageBox.Show(this, "你选择上传的文件不能大于10M,请重新选择!");
                    return;
                }
                if (txtImgUrl.PostedFile.ContentLength <= 10240000)
                {
                    try
                    {
                        string SaveFileName = DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + fileExtension;
                        txtImgUrl.PostedFile.SaveAs(path + SaveFileName);
                        WebProject.Model.BaseData.ZT_COM_News model_News = new WebProject.Model.BaseData.ZT_COM_News();
                        model_News.Body = this.txtBody.Text.Trim();
                        model_News.NewsTypeName = this.txtNewsType.Items[this.txtNewsType.SelectedIndex].Text.ToString();
                        model_News.NewsTypeNo = this.txtNewsType.SelectedValue.ToString();
                        model_News.CreateBy = SessionUtil.GetAdminSession().AdminNo;
                        model_News.CreateDate = DateTime.Now;
                        model_News.ImgUrl = SaveFileName;
                        model_News.NewsOrder = Int32.Parse(this.txtNewsOrder.Text.Trim());
                        model_News.Title = this.txtTitle.Text.Trim();
                        WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
                        bll_News.Add(model_News);
                        LogManage.WriteLog(Request.UserHostAddress, "新闻管理", "添加新闻", "成功", "新闻标题:" + model_News.Title + ", 创建人:" + SessionUtil.GetAdminSession().AdminNo);
                        MessageBox.ShowAndRedirect(this, "添加信息成功!", "NewsList.aspx");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show(this, "文件上传失败!");
                        return;
                    }
                }
            }
        }
    }