Exemple #1
0
        protected void Form_Save(object sender, DirectEventArgs e)
        {
            using (DataEntities ent = new DataEntities())
            {
                var n = new Voodoo.Basement.Product();
                try
                {
                    int id = ID.Text.ToInt32();
                    n = (from l in ent.Product where l.ID == id select l).First();
                }
                catch { }

                n.AddTime = AddTime.Value.ToDateTime();
                n.ClassID = ClassID.SelectedItem.Value.ToInt32();
                n.ClassName = ClassID.SelectedItem.Text;
                n.ClickCount = ClickCount.Value.ToInt32();
                n.Contact = Contact.Text;
                n.Enable = Enable.Checked;
                //n.FaceImage = "";

                n.Intro = Intro.Text;
                n.Name = Name.Text;
                n.OrderIndex = OrderIndex.Value.ToInt32();
                n.Price = Price.Value.ToDecimal();
                n.ProduceLocation = ProduceLocation.Text;
                n.SetTop = SetTop.Checked;
                n.Specification = Specification.Text;
                n.Tel = Tel.Text;
                n.Units = Units.Text;
                if (n.ID <= 0)
                {
                    ent.AddToProduct(n);
                }
                ent.SaveChanges();

                if (FaceImage.HasFile)
                {
                    Class cls = (from l in ent.Class where l.ID == n.ClassID select l).First();
                    string fileName = string.Format("/u/products/{0}.jpg", n.ID);
                    Voodoo.Basement.BasePage.UpLoadImage(FaceImage.PostedFile, fileName, cls.ImageWidth.ToInt32(), cls.ImageHeight.ToInt32());//194, 204
                    n.FaceImage = fileName;
                    ent.SaveChanges();
                }

                if (UpFile.HasFile)
                {
                    var files = from l in ent.File where l.ItemID == n.ID select l;
                    foreach (var f in files)
                    {
                        ent.DeleteObject(f);
                    }

                    string ext = UpFile.FileName.GetFileExtNameFromPath();
                    string fileName = string.Format("/u/products/{0}", UpFile.FileName);
                    Voodoo.Basement.BasePage.UpLoadFile(UpFile.PostedFile, fileName);

                    Voodoo.Basement.File file = new Voodoo.Basement.File();
                    file.ClassID = n.ClassID;
                    file.FileDirectory = "/u/products/";
                    file.FileExtName = ext;
                    file.FileName = UpFile.FileName;
                    file.FilePath = fileName;
                    file.FileSize = UpFile.PostedFile.ContentLength;
                    file.FileType = 0;
                    file.ItemID = n.ID;
                    file.SmallPath = "";
                    file.UpTime = DateTime.Now;
                    ent.AddToFile(file);
                    ent.SaveChanges();
                }

                this.GridPanel1.Store.Primary.CommitChanges();
                this.BindData();
                TabPanel1.SetActiveTab(0);
                FormPanel1.Title = "新增";
                FormPanel1.Reset();
                X.Msg.Notify("消息", "保存成功!").Show();

            }
        }
Exemple #2
0
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            DataEntities ent = new DataEntities();
            User u=UserAction.opuser;
            UserGroup g = //UserGroupView.GetModelByID(u.Group.ToS());
                (from l in ent.UserGroup where l.ID == u.Group select l).FirstOrDefault();
            if (FileUpload1.FileName.IsNullOrEmpty())
            {
                Js.AlertAndGoback("为提高您文章的排名,请选择一张标题图片");
                return;
            }

            #region  上传图片
            SysSetting ss = BasePage.SystemSetting;

            HttpPostedFile file = Request.Files["FileUpload1"];
            string FileName = file.FileName.GetFileNameFromPath();//文件名
            string ExtName = file.FileName.GetFileExtNameFromPath();//扩展名
            string NewName = @string.GetGuid() + ExtName;//新文件名

            if (!ExtName.Replace(".", "").IsInArray(ss.FileExtNameFilter.Split(',')))
            {
                Js.AlertAndGoback("不允许上传此类文件");
                return;
            }
            if (file.ContentLength > ss.MaxPostFileSize)
            {
                Js.AlertAndGoback("文件太大");
                return;
            }

            string Folder = ss.FileDir + "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";//文件目录
            string FolderShotCut = Folder + "ShortCut/";//缩略图目录

            string FilePath = Folder + NewName;//文件路径
            string FilePath_ShortCut = FolderShotCut + NewName;//缩略图路径

            file.SaveAs(Server.MapPath(FilePath), true);
            ImageHelper.MakeThumbnail(Server.MapPath(FilePath), Server.MapPath(FilePath_ShortCut), 105, 118, "Cut");

            FileInfo savedFile = new FileInfo(Server.MapPath(FilePath));

            Voodoo.Basement.File f = new Voodoo.Basement.File();

            f.FileDirectory = ss.FileDir;
            f.FileExtName = ExtName;
            f.FilePath = FilePath;
            f.FileSize = (savedFile.Length / 1024).ToInt32();
            //f.FileType=
            f.SmallPath = FilePath_ShortCut;
            f.UpTime = DateTime.Now;

            ent.AddToFile(f);
            ent.SaveChanges();
            #endregion

            News n = new News();
            n.Author = txt_Author.Text.TrimDbDangerousChar();
            n.AutorID = UserAction.opuser.ID;
            n.ClassID = ddl_Class.SelectedValue.ToInt32();
            n.ClickCount = 0;
            n.Content = txt_Content.Text.TrimDbDangerousChar();
            n.Description = txt_Description.Text.TrimDbDangerousChar();
            n.DownCount = 0;
            n.EnableReply = false;
            n.FTitle = txtFtitle.Text.TrimDbDangerousChar();
            n.KeyWords = txt_Keyword.Text.TrimDbDangerousChar();
            n.ModelID = 0;
            n.NavUrl = "";
            n.NewsTime = DateTime.Now;
            n.SetTop = false;
            n.Source = txt_Source.Text.TrimDbDangerousChar();
            n.Title = txt_Title.Text.TrimDbDangerousChar();
            n.TitleColor = "000";
            n.TitleImage = FilePath;//上传图片
            n.ZtID = 0;
            n.Audit = g.PostAotuAudit;
            n.FileForder = DateTime.Now.ToString("yyyy-MM-dd");

            n.ID = WS.RequestInt("id");

            Result r=NewsAction.UserPost(n, UserAction.opuser);

            if (r.Success)
            {
                Js.AlertAndChangUrl(r.Text, "PostList.aspx");
            }
            else
            {
                Js.AlertAndGoback(r.Text);
            }
            ent.Dispose();
        }