Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Aim.Portal.Web.WebPortalService.CheckLogon();
            }
            catch
            {
                Response.Write("<script> window.parent.location.href = '/Login.aspx';</script>");
                Response.End();
            }
            string    action = Request["action"];
            string    sql    = "";
            DataTable dt     = null;
            string    node   = Request["node"];
            JObject   json   = null;

            if (!string.IsNullOrEmpty(node))
            {
                json = JsonHelper.GetObject <JObject>(node);
            }
            switch (action)
            {
            case "loadtreedata":
                switch (json.Value <string>("level"))
                {
                case "0":
                    sql = @"select GroupID as id,replace(Name,'江西瑞林建设监理有限公司','') as name,GroupID as groupid,'' as projectid,'1' as level,'false' as leaf,
                            '' as firsttypeid,'' as secondtypeid from SysGroup where ParentId='" + json.Value <string>("id") + "' order by Code asc";
                    break;

                case "1":
                    sql = @"select Id as id,projectName as name,'{0}' as groupid,Id as projectid,'' as firsttypeid,'' as secondtypeid,'2' as level,'false' as leaf
                            from NCRL_SP..Project where BelongCmp = 'JL' and BelongDeptId = '{0}'";
                    sql = string.Format(sql, json.Value <string>("id"));
                    break;

                case "2":
                    sql = @"select EnumerationID as id,Name as name,'{0}' as groupid,'{1}' as projectid,EnumerationID as firsttypeid,'' as secondtypeid,'3' as level,'false' as leaf
                            from sysenumeration where parentid='cf38bd7a-79d1-46fb-bf06-640b30f61654' order by SortIndex asc";
                    sql = string.Format(sql, json.Value <string>("groupid"), json.Value <string>("id"));
                    break;

                case "3":
                    sql = @"select EnumerationID as id,Name as name,'{0}' as groupid,'{1}' as projectid,'{2}' as firsttypeid,EnumerationID as secondtypeid,'4' as level,'true' as leaf
                            from sysenumeration where ParentID='{3}'";
                    sql = string.Format(sql, json.Value <string>("groupid"), json.Value <string>("projectid"), json.Value <string>("firsttypeid"), json.Value <string>("id"));
                    break;
                }
                dt = DataHelper.QueryDataTable(sql);
                Response.Write(JsonHelper.GetJsonStringFromDataTable(dt));
                Response.End();
                break;

            case "loadfile":
                switch (json.Value <string>("level"))
                {
                case "0":        //加载所有文档
                    sql = @"select a.Id,a.Name,a.CreatorName as CreateName,a.CreateTime,b.ProjectName,C.Name SecondTypeName,d.Path as FolderName from FileItem a 
                            left join NCRL_SP..Project b on a.ProjectId=b.Id 
                            left join SysEnumeration c on a.SecondTypeId=c.EnumerationId
                            left join FileFolder d on a.FolderId=d.Id where b.BelongCmp='JL'";
                    break;

                case "1":        //加载某一部门的文档
                    sql = @"select a.Id,a.Name,a.CreatorName as CreateName,a.CreateTime,b.ProjectName,C.Name SecondTypeName,d.Path as FolderName from FileItem a 
                            left join NCRL_SP..Project b on a.ProjectId=b.Id 
                            left join SysEnumeration c on a.SecondTypeId=c.EnumerationId
                            left join FileFolder d on a.FolderId=d.Id where  b.BelongCmp='JL' and a.GroupId='" + json.Value <string>("id") + "'";
                    break;

                case "2":        //加载某一项目的文档
                    sql = @"select a.Id,a.Name,a.CreatorName as CreateName,a.CreateTime,b.ProjectName,C.Name SecondTypeName,d.Path as FolderName from FileItem a 
                            left join NCRL_SP..Project b on a.ProjectId=b.Id 
                            left join SysEnumeration c on a.SecondTypeId=c.EnumerationId
                            left join FileFolder d on a.FolderId=d.Id where  a.ProjectId='" + json.Value <string>("projectid") + "'";
                    break;

                case "3":        //加载某一项目某一大类文档
                    sql = @"select a.Id,a.Name,a.CreatorName as CreateName,a.CreateTime,b.ProjectName,C.Name SecondTypeName,d.Path as FolderName from FileItem a 
                            left join NCRL_SP..Project b on a.ProjectId=b.Id 
                            left join SysEnumeration c on a.SecondTypeId=c.EnumerationId
                            left join FileFolder d on a.FolderId=d.Id where a.ProjectId='{0}' and  a.FirstTypeId='{1}'";
                    sql = string.Format(sql, json.Value <string>("projectid"), json.Value <string>("firsttypeid"));
                    break;

                case "4":        //加载某一项目某一大类的某一小类文档
                    sql = @"select a.Id,a.Name,a.CreatorName as CreateName,a.CreateTime,b.ProjectName,C.Name SecondTypeName,d.Path as FolderName from FileItem a 
                            left join NCRL_SP..Project b on a.ProjectId=b.Id 
                            left join SysEnumeration c on a.SecondTypeId=c.EnumerationId
                            left join FileFolder d on a.FolderId=d.Id where a.ProjectId='{0}' and  a.FirstTypeId='{1}' and a.SecondTypeId='{2}'";
                    sql = string.Format(sql, json.Value <string>("projectid"), json.Value <string>("firsttypeid"), json.Value <string>("secondtypeid"));
                    break;

                case "5":
                    string filename        = Request["filename"];
                    string projectnamecode = Request["projectnamecode"];
                    string where = "";
                    if (!string.IsNullOrEmpty(filename))
                    {
                        where += " and a.Name like '%" + filename + "%'";
                    }
                    if (!string.IsNullOrEmpty(projectnamecode))
                    {
                        where += " and (b.ProjectName like '%" + projectnamecode + "%' or b.ProjectCode like '%" + projectnamecode + "%')";
                    }
                    sql = @"select a.Id,a.Name,a.CreatorName as CreateName,a.CreateTime,b.ProjectName,C.Name SecondTypeName,d.Path as FolderName from FileItem a 
                                left join NCRL_SP..Project b on a.ProjectId=b.Id 
                                left join SysEnumeration c on a.SecondTypeId=c.EnumerationId
                                left join FileFolder d on a.FolderId=d.Id where 1=1 " + where;
                    break;
                }
                dt = DataHelper.QueryDataTable(GetPageSql(sql));
                Response.Write("{'rows':" + JsonHelper.GetJsonStringFromDataTable(dt) + ",total:'" + totalProperty + "'}");
                Response.End();
                break;

            case "delete":
                string     fileid = Request["fileid"];
                FileItem   fiEnt  = FileItem.Find(fileid);
                FileFolder ffEnt  = FileFolder.Find(fiEnt.FolderId);
                if (File.Exists(@"D:\RW\Files\AppFiles\Portal\" + ffEnt.Path + @"\" + fiEnt.Id + "_" + fiEnt.Name))
                {
                    File.Delete(@"D:\RW\Files\AppFiles\Portal\" + ffEnt.Path + @"\" + fiEnt.Id + "_" + fiEnt.Name);
                }
                fiEnt.DoDelete();
                Response.Write("{success:true}");
                Response.End();
                break;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Aim.Portal.Web.WebPortalService.CheckLogon();
            }
            catch
            {
                Response.Write("<script> window.parent.location.href = '/Login.aspx';</script>");
                Response.End();
            }
            string     action    = Request["action"];
            string     groupid   = Request["groupid"];
            string     projectId = Request["projectid"];
            FileFolder ffEnt     = null;
            Project    pEnt      = null;

            switch (action)
            {
            case "upload":
                //如果是项目文档  上传项目编号文件夹 如果是部门文档上传到DEFAULT文件夹
                if (!string.IsNullOrEmpty(projectId))
                {
                    pEnt = Project.Find(projectId);
                    IList <FileFolder> ffEnts = FileFolder.FindAllByProperty(FileFolder.Prop_FolderKey, pEnt.ProjectCode);
                    if (ffEnts.Count == 0)
                    {
                        ffEnt            = new FileFolder();
                        ffEnt.Name       = pEnt.ProjectCode;
                        ffEnt.FolderKey  = pEnt.ProjectCode;
                        ffEnt.Path       = pEnt.ProjectCode;
                        ffEnt.ParentId   = "1";
                        ffEnt.CreateTime = DateTime.Now;
                        ffEnt.ModuleId   = "1";
                        ffEnt.DoCreate();
                        ffEnt.FullId = "1." + ffEnt.Id;
                        ffEnt.DoUpdate();
                    }
                    else
                    {
                        ffEnt = ffEnts[0];
                    }
                    if (!Directory.Exists(@"D:\RW\Files\AppFiles\Portal\" + pEnt.ProjectCode))
                    {
                        Directory.CreateDirectory(@"D:\RW\Files\AppFiles\Portal\" + pEnt.ProjectCode);
                    }
                }
                else
                {
                    ffEnt = FileFolder.Find("1");    //如果是非项目文档,上传到默认文件夹
                }
                string   formdata = Request["formdata"];
                JObject  json     = Aim.JsonHelper.GetObject <JObject>(formdata);
                FileItem fiEnt    = new FileItem();
                fiEnt.GroupId      = groupid;
                fiEnt.ProjectId    = projectId;
                fiEnt.FirstTypeId  = json.Value <string>("FirstTypeId");
                fiEnt.SecondTypeId = json.Value <string>("SecondTypeId");
                HttpPostedFile postedFile = Request.Files["projectfile"];    //获取上传信息对象
                string         fileName   = Path.GetFileName(postedFile.FileName);
                fiEnt.Name        = fileName;
                fiEnt.FolderId    = ffEnt.Id;
                fiEnt.CreatorId   = Aim.Portal.Web.WebPortalService.CurrentUserInfo.UserID;
                fiEnt.CreatorName = Aim.Portal.Web.WebPortalService.CurrentUserInfo.Name;
                fiEnt.CreateTime  = DateTime.Now;
                fiEnt.DoCreate();
                // string filename = postedFile.FileName;//获取上传的文件路径
                // string tempPath = System.Configuration.ConfigurationManager.AppSettings["NewsFolderPath"];//获取保存文件夹路径,我是设置在webconfig中了。
                // string savepath = Server.MapPath(@"D:\RW\Files\AppFiles\Portal\" + pEnt.ProjectCode + "\\");//获取保存路径
                // string sExtension = filename.Substring(filename.LastIndexOf('.'));//获取拓展名
                //if (!Directory.Exists(savepath))
                //Directory.CreateDirectory(savepath);
                //string sNewFileName = DateTime.Now.ToString("yyyyMMddhhmmsfff"); + fiEnt.Id + "_"" + seEnt.IsLeaf + "
                postedFile.SaveAs(@"D:\RW\Files\AppFiles\Portal\" + ffEnt.Path + @"/" + fiEnt.Id + "_" + fileName);    //保存
                Response.Write("{success:true}");
                Response.End();
                break;

            case "loadfiletype":
                string id = Request["id"];
                if (string.IsNullOrEmpty(id))
                {
                    id = "cf38bd7a-79d1-46fb-bf06-640b30f61654";
                }
                IList <SysEnumeration> seEnts = SysEnumeration.FindAllByProperty("SortIndex", SysEnumeration.Prop_ParentID, id);
                int    i      = 0;
                string result = "[";
                foreach (SysEnumeration seEnt in seEnts)
                {
                    if (i != seEnts.Count - 1)
                    {
                        result += "{'id':'" + seEnt.EnumerationID + "','text':'" + seEnt.Name + "','leaf':" + (seEnt.IsLeaf.Value ? "true" : "false") + ",'parentid':'" + seEnt.ParentID + "'},";
                    }
                    else
                    {
                        result += "{'id':'" + seEnt.EnumerationID + "','text':'" + seEnt.Name + "','leaf':" + (seEnt.IsLeaf.Value ? "true" : "false") + ",'parentid':'" + seEnt.ParentID + "'}";
                    }
                    i++;
                }
                result += "]";
                Response.Write(result);
                Response.End();
                break;

            case "getprojectname":
                string temp = "{";
                if (!string.IsNullOrEmpty(projectId))
                {
                    pEnt  = Project.Find(projectId);
                    temp += "ProjectName:'" + pEnt.ProjectName + "'";
                }
                if (!string.IsNullOrEmpty(groupid))
                {
                    SysGroup sgEnt = SysGroup.Find(groupid);
                    temp += (temp.Length > 1 ? ",GroupName:'" : "GroupName:'") + sgEnt.Name + "'";
                }
                Response.Write(temp + "}");
                Response.End();
                break;
            }
        }