Beispiel #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            //保存文件
            string path = "";
            string filepath = "", filename = "";
            int    Id = 0;

            try
            {
                Id = int.Parse(Request.QueryString["Id"]);
            }
            catch (Exception)
            {
                label1.Text = "操作失败,请重新进入,尝试";
                return;
            }
            if (FileUpload1.HasFile || Maticsoft.Common.FileUp.IsImg(FileUpload1.FileName))
            {
                filepath = Maticsoft.Common.FileUp.GetUploadPath("/Upload/Works");
                filename = Maticsoft.Common.FileUp.GetRandomName();
                path     = Maticsoft.Common.FileUp.uploadfile(FileUpload1.PostedFile, filepath, filename);
            }
            else
            {
                label1.Text = "没有文件,或不支持文件";
                return;
            }
            // 生成缩略图
            string bigPath = Server.MapPath("~/") + filepath + "big_" + filename + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();

            Maticsoft.Common.CutImage.CutImg(Server.MapPath("~/") + path, bigPath, 896, 650, "h");
            string miniPath = Server.MapPath("~/") + filepath + "mini_" + filename + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();

            Maticsoft.Common.CutImage.CutImg(Server.MapPath("~/") + path, miniPath, 100, 75, "h");

            string wPath = Server.MapPath("~/") + filepath + "w_" + filename + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();

            Maticsoft.Common.CutImage.CutImg(Server.MapPath("~/") + path, wPath, 100, 86, "CUT");

            //保存数据到数据库
            Maticsoft.BLL.Works bll = new Maticsoft.BLL.Works();

            Maticsoft.Model.Works model = new Maticsoft.Model.Works();
            model.Title      = txtTitle.Text;
            model.Content    = txtsum.Text;
            model.GroupID    = Id;//
            model.ItemID     = 1;
            model.No         = bll.GetMaxId();
            model.Attachment = path;//图片路径


            if (bll.Add(model) == 0)
            {
                label1.Text = "插入失败";
            }
            else
            {
                label1.Text = "操作成功";
            }
        }
Beispiel #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.Works model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Works set ");
            strSql.Append("Title=@Title,");
            strSql.Append("Content=@Content,");
            strSql.Append("Time=@Time,");
            strSql.Append("Attachment=@Attachment,");
            strSql.Append("ItemID=@ItemID,");
            strSql.Append("GroupID=@GroupID,");
            strSql.Append("IsOpen=@IsOpen,");
            strSql.Append("Click=@Click,");
            strSql.Append("Mark=@Mark,");
            strSql.Append("S1=@S1,");
            strSql.Append("S2=@S2");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Title",      SqlDbType.NVarChar,  100),
                new SqlParameter("@Content",    SqlDbType.NVarChar,   -1),
                new SqlParameter("@Time",       SqlDbType.DateTime),
                new SqlParameter("@Attachment", SqlDbType.NVarChar,  100),
                new SqlParameter("@ItemID",     SqlDbType.Int,         4),
                new SqlParameter("@GroupID",    SqlDbType.Int,         4),
                new SqlParameter("@IsOpen",     SqlDbType.Bit,         1),
                new SqlParameter("@Click",      SqlDbType.Int,         4),
                new SqlParameter("@Mark",       SqlDbType.Int,         4),
                new SqlParameter("@S1",         SqlDbType.NVarChar,  100),
                new SqlParameter("@S2",         SqlDbType.NVarChar,  100),
                new SqlParameter("@ID",         SqlDbType.Int,         4),
                new SqlParameter("@No",         SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.Title;
            parameters[1].Value  = model.Content;
            parameters[2].Value  = model.Time;
            parameters[3].Value  = model.Attachment;
            parameters[4].Value  = model.ItemID;
            parameters[5].Value  = model.GroupID;
            parameters[6].Value  = model.IsOpen;
            parameters[7].Value  = model.Click;
            parameters[8].Value  = model.Mark;
            parameters[9].Value  = model.S1;
            parameters[10].Value = model.S2;
            parameters[11].Value = model.ID;
            parameters[12].Value = model.No;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.Works model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Works(");
            strSql.Append("Title,Content,Time,Attachment,ItemID,GroupID,IsOpen,Click,No,Mark,S1,S2)");
            strSql.Append(" values (");
            strSql.Append("@Title,@Content,@Time,@Attachment,@ItemID,@GroupID,@IsOpen,@Click,@No,@Mark,@S1,@S2)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Title",      SqlDbType.NVarChar,  100),
                new SqlParameter("@Content",    SqlDbType.NVarChar,   -1),
                new SqlParameter("@Time",       SqlDbType.DateTime),
                new SqlParameter("@Attachment", SqlDbType.NVarChar,  100),
                new SqlParameter("@ItemID",     SqlDbType.Int,         4),
                new SqlParameter("@GroupID",    SqlDbType.Int,         4),
                new SqlParameter("@IsOpen",     SqlDbType.Bit,         1),
                new SqlParameter("@Click",      SqlDbType.Int,         4),
                new SqlParameter("@No",         SqlDbType.Int,         4),
                new SqlParameter("@Mark",       SqlDbType.Int,         4),
                new SqlParameter("@S1",         SqlDbType.NVarChar,  100),
                new SqlParameter("@S2",         SqlDbType.NVarChar, 100)
            };
            parameters[0].Value  = model.Title;
            parameters[1].Value  = model.Content;
            parameters[2].Value  = model.Time;
            parameters[3].Value  = model.Attachment;
            parameters[4].Value  = model.ItemID;
            parameters[5].Value  = model.GroupID;
            parameters[6].Value  = model.IsOpen;
            parameters[7].Value  = model.Click;
            parameters[8].Value  = model.No;
            parameters[9].Value  = model.Mark;
            parameters[10].Value = model.S1;
            parameters[11].Value = model.S2;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #4
0
 private void ShowInfo(int ID)
 {
     Maticsoft.BLL.Works   bll   = new Maticsoft.BLL.Works();
     Maticsoft.Model.Works model = bll.GetModel(ID);
     this.lblID.Text         = model.ID.ToString();
     this.lblTitle.Text      = model.Title;
     this.lblContent.Text    = model.Content;
     this.lblTime.Text       = model.Time.ToString();
     this.lblAttachment.Text = model.Attachment;
     this.lblItemID.Text     = model.ItemID.ToString();
     this.lblGroupID.Text    = model.GroupID.ToString();
     this.lblIsOpen.Text     = model.IsOpen?"是":"否";
     this.lblClick.Text      = model.Click.ToString();
     this.lblNo.Text         = model.No.ToString();
     this.lblMark.Text       = model.Mark.ToString();
     this.lblS1.Text         = model.S1;
     this.lblS2.Text         = model.S2;
 }
Beispiel #5
0
 private void ShowInfo(int ID)
 {
     Maticsoft.BLL.Works   bll   = new Maticsoft.BLL.Works();
     Maticsoft.Model.Works model = bll.GetModel(ID);
     this.lblID.Text         = model.ID.ToString();
     this.txtTitle.Text      = model.Title;
     this.txtContent.Text    = model.Content;
     this.txtTime.Text       = model.Time.ToString();
     this.txtAttachment.Text = model.Attachment;
     this.txtItemID.Text     = model.ItemID.ToString();
     this.txtGroupID.Text    = model.GroupID.ToString();
     this.chkIsOpen.Checked  = model.IsOpen;
     this.txtClick.Text      = model.Click.ToString();
     this.lblNo.Text         = model.No.ToString();
     this.txtMark.Text       = model.Mark.ToString();
     this.txtS1.Text         = model.S1;
     this.txtS2.Text         = model.S2;
 }
Beispiel #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.Works GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,Title,Content,Time,Attachment,ItemID,GroupID,IsOpen,Click,No,Mark,S1,S2 from Works ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            Maticsoft.Model.Works model = new Maticsoft.Model.Works();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Beispiel #7
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtTitle.Text.Trim().Length == 0)
            {
                strErr += "标题不能为空!\\n";
            }
            if (this.txtContent.Text.Trim().Length == 0)
            {
                strErr += "内容不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtTime.Text))
            {
                strErr += "发布时间格式错误!\\n";
            }
            if (this.txtAttachment.Text.Trim().Length == 0)
            {
                strErr += "附件不能为空!\\n";
            }
            if (!PageValidate.IsNumber(txtItemID.Text))
            {
                strErr += "分类格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtGroupID.Text))
            {
                strErr += "分组格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtClick.Text))
            {
                strErr += "点击数格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtNo.Text))
            {
                strErr += "No格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtMark.Text))
            {
                strErr += "Mark格式错误!\\n";
            }
            if (this.txtS1.Text.Trim().Length == 0)
            {
                strErr += "备用不能为空!\\n";
            }
            if (this.txtS2.Text.Trim().Length == 0)
            {
                strErr += "备用2不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string   Title      = this.txtTitle.Text;
            string   Content    = this.txtContent.Text;
            DateTime Time       = DateTime.Parse(this.txtTime.Text);
            string   Attachment = this.txtAttachment.Text;
            int      ItemID     = int.Parse(this.txtItemID.Text);
            int      GroupID    = int.Parse(this.txtGroupID.Text);
            bool     IsOpen     = this.chkIsOpen.Checked;
            int      Click      = int.Parse(this.txtClick.Text);
            int      No         = int.Parse(this.txtNo.Text);
            int      Mark       = int.Parse(this.txtMark.Text);
            string   S1         = this.txtS1.Text;
            string   S2         = this.txtS2.Text;

            Maticsoft.Model.Works model = new Maticsoft.Model.Works();
            model.Title      = Title;
            model.Content    = Content;
            model.Time       = Time;
            model.Attachment = Attachment;
            model.ItemID     = ItemID;
            model.GroupID    = GroupID;
            model.IsOpen     = IsOpen;
            model.Click      = Click;
            model.No         = No;
            model.Mark       = Mark;
            model.S1         = S1;
            model.S2         = S2;

            Maticsoft.BLL.Works bll = new Maticsoft.BLL.Works();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }
Beispiel #8
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.Works DataRowToModel(DataRow row)
 {
     Maticsoft.Model.Works model = new Maticsoft.Model.Works();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["Title"] != null)
         {
             model.Title = row["Title"].ToString();
         }
         if (row["Content"] != null)
         {
             model.Content = row["Content"].ToString();
         }
         if (row["Time"] != null && row["Time"].ToString() != "")
         {
             model.Time = DateTime.Parse(row["Time"].ToString());
         }
         if (row["Attachment"] != null)
         {
             model.Attachment = row["Attachment"].ToString();
         }
         if (row["ItemID"] != null && row["ItemID"].ToString() != "")
         {
             model.ItemID = int.Parse(row["ItemID"].ToString());
         }
         if (row["GroupID"] != null && row["GroupID"].ToString() != "")
         {
             model.GroupID = int.Parse(row["GroupID"].ToString());
         }
         if (row["IsOpen"] != null && row["IsOpen"].ToString() != "")
         {
             if ((row["IsOpen"].ToString() == "1") || (row["IsOpen"].ToString().ToLower() == "true"))
             {
                 model.IsOpen = true;
             }
             else
             {
                 model.IsOpen = false;
             }
         }
         if (row["Click"] != null && row["Click"].ToString() != "")
         {
             model.Click = int.Parse(row["Click"].ToString());
         }
         if (row["No"] != null && row["No"].ToString() != "")
         {
             model.No = int.Parse(row["No"].ToString());
         }
         if (row["Mark"] != null && row["Mark"].ToString() != "")
         {
             model.Mark = int.Parse(row["Mark"].ToString());
         }
         if (row["S1"] != null)
         {
             model.S1 = row["S1"].ToString();
         }
         if (row["S2"] != null)
         {
             model.S2 = row["S2"].ToString();
         }
     }
     return(model);
 }