Beispiel #1
0
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    using (IFMPDBContext db = new IFMPDBContext())
                    {
                        ResourcePath        ResourcePath         = db.ResourcePath.FirstOrDefault(t => t.ID == ResourcePathID);
                        List <ResourcePath> FullResourcePathList = db.ResourcePath.ToList();
                        if (ResourcePath == null)
                        {
                            ResourcePath            = new ResourcePath();
                            ResourcePath.CreateDate = DateTime.Now;
                            ResourcePath.IsDel      = false;
                            ResourcePath.Name       = txt_Name.Text;
                            ResourcePath.ParentID   = ParentPathID;

                            db.ResourcePath.Add(ResourcePath);
                            db.SaveChanges();

                            //在这个位置添加一个文件夹
                            //string path = "../Resource";
                            string subPath = System.Web.HttpContext.Current.Server.MapPath(ResourceDAO.GetPathByPathID(ParentPathID, FullResourcePathList)) + "/" + ResourcePath.Name + "/";
                            if (false == System.IO.Directory.Exists(subPath))
                            {
                                //创建pic文件夹
                                System.IO.Directory.CreateDirectory(subPath);
                            }

                            new SysLogDAO().AddLog(LogType.操作日志_添加, "添加资源路径", UserID);
                        }
                        else
                        {
                            ResourcePath.Name = txt_Name.Text;
                            db.SaveChanges();
                            new SysLogDAO().AddLog(LogType.操作日志_修改, "修改资源路径", UserID);
                        }

                        ShowMessage();

                        ts.Complete();
                    }
                }
                catch (Exception ex)
                {
                    ShowMessage(ex.Message);
                    new SysLogDAO().AddLog(LogType.系统日志, ex.Message, UserID);
                    ts.Dispose();
                    return;
                }
            }
        }
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    using (IFMPDBContext db = new IFMPDBContext())
                    {
                        //这里应该有权限,很重要
                        ResourceData        ResourceData         = db.ResourceData.FirstOrDefault(t => t.ID == ResourceDataID && t.IsDel != true);
                        List <ResourcePath> FullResourcePathList = db.ResourcePath.ToList();
                        string message = "";
                        if (ResourceData == null)
                        {
                            ResourceData = new ResourceData();

                            //ResourceData.Name = txt_Name.Text;
                            ResourceData.CreateDate     = DateTime.Now;
                            ResourceData.IsCarousel     = (ddl_IsCarousel.SelectedValue == "0" ? false : true);
                            ResourceData.IsDel          = false;
                            ResourceData.ResourcePathID = ResourcePathID;
                            //ResourceData.ResourcePathID
                            #region   图片
                            if (this.fl_UpFile.HasFile)
                            {
                                int upsize = 4000000;
                                try
                                {
                                    upsize = Convert.ToInt32(ConfigurationManager.AppSettings["upsize"].ToString());
                                }
                                catch (Exception) { }


                                string path = System.Web.HttpContext.Current.Server.MapPath(ResourceDAO.GetPathByPathID(ResourcePathID, FullResourcePathList));
                                if (!Directory.Exists(path))
                                {
                                    Directory.CreateDirectory(path);
                                }
                                string name = this.fl_UpFile.PostedFile.FileName.ToString();

                                string filepath = path + "\\" + name;

                                if (this.fl_UpFile.PostedFile.ContentLength < upsize)
                                {
                                    this.fl_UpFile.SaveAs(filepath);
                                }

                                ResourceData.Name = name;
                                db.ResourceData.Add(ResourceData);
                                db.SaveChanges();
                                new SysLogDAO().AddLog(LogType.操作日志_添加, "添加资源图片", UserID);
                            }
                            else
                            {
                                ShowMessage("请添加图片");
                                return;
                            }
                            #endregion
                        }
                        else
                        {
                            ResourceData.IsCarousel = Convert.ToBoolean(ddl_IsCarousel.SelectedValue);
                            ResourceData.IsDel      = false;
                            //ResourceData.ResourcePathID = ResourcePathID;
                            //若和原图相同则不替换
                        }
                        ShowMessage();

                        ts.Complete();
                    }
                }
                catch (Exception ex)
                {
                    ShowMessage(ex.Message);
                    new SysLogDAO().AddLog(LogType.系统日志, ex.Message, UserID);
                    ts.Dispose();
                    return;
                }
            }
        }