Ejemplo n.º 1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string strErr = "";
            string heading = this.txtHeading.Text.Trim();
            string focus = this.txtFocus.Text.Trim();
            string content = this.FreeTextBox1.Text.Trim();
            string classid = this.dropNewsClass.SelectedValue;
            bool dormancy = this.chkDormancy.Checked;



            if (heading == "")
            {
                strErr += "标题不能为空\\n";
            }
            if (content == "")
            {
                strErr += "内容不能为空\\n";
            }
            if ((this.dropNewsClass.Items.Count == 0) || (classid.Trim() == ""))
            {
                strErr += "没有可以选择的类别!\\n";
            }
            if (strErr != "")
            {
                LTP.Common.MessageBox.Show(this, strErr);
                return;
            }
            if (Session["UserInfo"] == null)
                return;
            LTP.Accounts.Bus.User currentUser = (LTP.Accounts.Bus.User)Session["UserInfo"];
            Maticsoft.Model.NewsManage.News news = new Maticsoft.Model.NewsManage.News();
            news.ClassId = int.Parse(classid);
            news.Heading = heading;
            news.Focus = focus;
            news.Content = content;
            if (dormancy==true)
            {
                news.Dormancy = "false";                
            }
            else 
            {                
                news.Dormancy = "true";
            }
           // news.Dormancy = dormancy.ToString();
            //news.Opened = opened;
            news.Frequency = 0;
            news.IssueDate = DateTime.Now;
            //news.ParentId = 0;
            news.Priority = 0;
            news.UserId = currentUser.UserID;
            //news.DepartmentID = int.Parse(currentUser.DepartmentID);
            if (chkIsTop.Checked)
            {
                news.IsTop = 1;
            }
            else
            {
                news.IsTop = 0;
            }

            if (chkIsLimited.Checked)
            {
                news.IsLimited = 1;
            }
            else
            {
                news.IsLimited= 0;
            }

            int newsid = 0;
            Maticsoft.BLL.NewsManage.News n = new Maticsoft.BLL.NewsManage.News();
           newsid=  n.Add(news);

            //处理新闻图片
          if (Session["NewsImages_tempId"] != null)
          {
              int NewsImages_tempId = (int)Session["NewsImages_tempId"];
              Maticsoft.BLL.NewsManage.NewsImages bll = new Maticsoft.BLL.NewsManage.NewsImages();
              DataSet Dset =(DataSet) Session["FileList"]; // bll.GetNewsImagesList(-1, NewsImages_tempId, false);
              if (Dset != null && Dset.Tables[0].Rows.Count > 0)
              {
                  string Sourcepath = Server.MapPath("~/upload/Temp/");
                  string Despath = Server.MapPath("~/upload/img/");               
                  for (int i = 0; i < Dset.Tables[0].Rows.Count; i++)
                  {                   
                      try
                      {
                          string FileName = Dset.Tables[0].Rows[i]["linkurl"].ToString();
                          if (File.Exists(Sourcepath + FileName))
                              File.Copy(Sourcepath + FileName, Despath + FileName);
                          if (File.Exists(Sourcepath + FileName))
                              File.Delete(Sourcepath + FileName);
                      }
                      catch
                      {
                          //this.Label_Msg.Text = "文件复制出错:" + Ex.Message.ToString();
                      }
                  }
                  //修改图片
                  string strupdatestring = "newsid=" + newsid.ToString();
                  bll.Update(strupdatestring, NewsImages_tempId);
              }
          }


          //处理新闻附件
          if (Session["NewsAffix_tempId"] != null)
          {
              int NewsAffix_tempId = (int)Session["NewsAffix_tempId"];
              Maticsoft.BLL.NewsManage.NewsAffix bll = new Maticsoft.BLL.NewsManage.NewsAffix();
              DataSet Dset = (DataSet)Session["FileList_Affix"];              
              if (Dset != null && Dset.Tables[0].Rows.Count > 0)
              {
                  string Sourcepath = Server.MapPath("~/upload/Temp/");
                  string Despath = Server.MapPath("~/upload/affix/");   
                  for (int i = 0; i < Dset.Tables[0].Rows.Count; i++)
                  {
                      try
                      {
                          string FileName = Dset.Tables[0].Rows[i]["linkurl"].ToString();
                          if (File.Exists(Sourcepath + FileName))
                              File.Copy(Sourcepath + FileName, Despath + FileName);
                          if (File.Exists(Sourcepath + FileName))
                              File.Delete(Sourcepath + FileName);
                      }
                      catch
                      {
                          //this.Label_Msg.Text = "文件复制出错:" + Ex.Message.ToString();
                      }
                  }
                  //修改附件
                  string strupdatestring = "newsid=" + newsid.ToString();
                  bll.Update(strupdatestring, NewsAffix_tempId);
              }
          }



            if (chkAddContinue.Checked)
            {
                Session["news"] = news;
                Response.Redirect("Add.aspx");
            }
            else
            {
                Session["news"] = null;
                Response.Redirect("index.aspx");
            }

        }
Ejemplo n.º 2
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string strErr   = "";
            string heading  = this.txtHeading.Text.Trim();
            string focus    = this.txtFocus.Text.Trim();
            string content  = this.ck.Text.Trim();
            string classid  = this.dropNewsClass.SelectedValue;
            bool   dormancy = this.chkDormancy.Checked;



            if (heading == "")
            {
                strErr += "标题不能为空\\n";
            }
            if (content == "")
            {
                strErr += "内容不能为空\\n";
            }
            if ((this.dropNewsClass.Items.Count == 0) || (classid.Trim() == ""))
            {
                strErr += "没有可以选择的类别!\\n";
            }
            if (strErr != "")
            {
                LTP.Common.MessageBox.Show(this, strErr);
                return;
            }
            if (Session["UserInfo"] == null)
            {
                return;
            }
            LTP.Accounts.Bus.User           currentUser = (LTP.Accounts.Bus.User)Session["UserInfo"];
            Maticsoft.Model.NewsManage.News news        = new Maticsoft.Model.NewsManage.News();
            news.ClassId = int.Parse(classid);
            news.Heading = heading;
            news.Focus   = focus;
            news.Content = content;
            if (dormancy == true)
            {
                news.Dormancy = "false";
            }
            else
            {
                news.Dormancy = "true";
            }
            // news.Dormancy = dormancy.ToString();
            //news.Opened = opened;
            news.Frequency = 0;
            news.IssueDate = DateTime.Now;
            //news.ParentId = 0;
            news.Priority = 0;
            news.UserId   = currentUser.UserID;
            //news.DepartmentID = int.Parse(currentUser.DepartmentID);
            if (chkIsTop.Checked)
            {
                news.IsTop = 1;
            }
            else
            {
                news.IsTop = 0;
            }

            if (chkIsLimited.Checked)
            {
                news.IsLimited = 1;
            }
            else
            {
                news.IsLimited = 0;
            }

            int newsid = 0;

            Maticsoft.BLL.NewsManage.News n = new Maticsoft.BLL.NewsManage.News();
            newsid = n.Add(news);

            //处理新闻图片
            if (Session["NewsImages_tempId"] != null)
            {
                int NewsImages_tempId = (int)Session["NewsImages_tempId"];
                Maticsoft.BLL.NewsManage.NewsImages bll = new Maticsoft.BLL.NewsManage.NewsImages();
                DataSet Dset = (DataSet)Session["FileList"]; // bll.GetNewsImagesList(-1, NewsImages_tempId, false);
                if (Dset != null && Dset.Tables[0].Rows.Count > 0)
                {
                    string Sourcepath = Server.MapPath("~/upload/Temp/");
                    string Despath    = Server.MapPath("~/upload/img/");
                    for (int i = 0; i < Dset.Tables[0].Rows.Count; i++)
                    {
                        try
                        {
                            string FileName = Dset.Tables[0].Rows[i]["linkurl"].ToString();
                            if (File.Exists(Sourcepath + FileName))
                            {
                                File.Copy(Sourcepath + FileName, Despath + FileName);
                            }
                            if (File.Exists(Sourcepath + FileName))
                            {
                                File.Delete(Sourcepath + FileName);
                            }
                        }
                        catch
                        {
                            //this.Label_Msg.Text = "文件复制出错:" + Ex.Message.ToString();
                        }
                    }
                    //修改图片
                    string strupdatestring = "newsid=" + newsid.ToString();
                    bll.Update(strupdatestring, NewsImages_tempId);
                }
            }


            //处理新闻附件
            if (Session["NewsAffix_tempId"] != null)
            {
                int NewsAffix_tempId = (int)Session["NewsAffix_tempId"];
                Maticsoft.BLL.NewsManage.NewsAffix bll = new Maticsoft.BLL.NewsManage.NewsAffix();
                DataSet Dset = (DataSet)Session["FileList_Affix"];
                if (Dset != null && Dset.Tables[0].Rows.Count > 0)
                {
                    string Sourcepath = Server.MapPath("~/upload/Temp/");
                    string Despath    = Server.MapPath("~/upload/affix/");
                    for (int i = 0; i < Dset.Tables[0].Rows.Count; i++)
                    {
                        try
                        {
                            string FileName = Dset.Tables[0].Rows[i]["linkurl"].ToString();
                            if (File.Exists(Sourcepath + FileName))
                            {
                                File.Copy(Sourcepath + FileName, Despath + FileName);
                            }
                            if (File.Exists(Sourcepath + FileName))
                            {
                                File.Delete(Sourcepath + FileName);
                            }
                        }
                        catch
                        {
                            //this.Label_Msg.Text = "文件复制出错:" + Ex.Message.ToString();
                        }
                    }
                    //修改附件
                    string strupdatestring = "newsid=" + newsid.ToString();
                    bll.Update(strupdatestring, NewsAffix_tempId);
                }
            }



            if (chkAddContinue.Checked)
            {
                Session["news"] = news;
                Response.Redirect("Add.aspx");
            }
            else
            {
                Session["news"] = null;
                Response.Redirect("index.aspx");
            }
        }