コード例 #1
0
ファイル: StuffController.cs プロジェクト: dalinhuang/newcqgj
        /// <summary>
        /// 添加课件
        /// </summary>
        public ActionResult AddCourseware()
        {
            Courseware courseware = new Courseware();
            if (Request.HttpMethod == "POST")
            {
                courseware.Name = GetString("Name");
                courseware.Teacher = GetString("Teacher");
                courseware.Description = GetString("Description");
                courseware.PubDate = DateTime.Now;

                //保存附件用代码
                HttpFileCollectionBase uploadFiles = this.HttpContext.Request.Files;
                // 设置上传目标文件夹
                string savaPath = this.HttpContext.Request.MapPath(@"../Content/uploadfiles/CoursewareFiles/");
                // 上传文件,并返回上传的文件名(由于附件表需要文件名称,所以SaveFiles函数返回了文件名
                List<string> fileNames = FileUpload.SaveFiles(uploadFiles, savaPath);
                Attachment attachment = new Attachment();
                //暂时将Type设置为0
                attachment.TypeID = 0;
                CQGJ.AddToAttachment(attachment);

                CQGJ.SaveChanges();
                foreach (var f in fileNames)
                {
                    AttachmentItem item = new AttachmentItem();
                    item.AddTime = DateTime.Now;
                    item.Attachment = attachment;
                    item.FilePath = "CoursewareFiles";
                    item.FileName = f.Split(',').First();
                    //表示激活
                    item.Status = 1;
                    CQGJ.AddToAttachmentItem(item);
                    courseware.AttachmentID = attachment.AttachmentID;
                    CQGJ.AddToCourseware(courseware);
                }
                CQGJ.SaveChanges();
                return RedirectToAction("coursewarelist", "stuff");
            }
            return View("AddCourseware");
        }
コード例 #2
0
ファイル: DocController.cs プロジェクト: dalinhuang/newcqgj
        public ActionResult DocEditSave()
        {
            int DocID = GetInt("DocID");
            if (DocID != 0)
            {
                Doc doc = (from c in CQGJ.Doc
                           where c.DocID == DocID
                           select c).First();
                doc.DocTitle = GetString("DocTitle");
                doc.DocType = GetInt("DocType");
                doc.TrainType = GetInt("TrainType");
                doc.WordNo = GetString("WordNo");
                doc.YearNo = GetString("YearNo");
                doc.TeamNo = GetString("TeamNo");
                //采用select
                doc.UserID = (int?)GetUserID();
                doc.KeyWord = GetString("KeyWord");
                doc.DocClass = GetInt("DocClass");
                doc.UrgentLevel = GetInt("UrgentLevel");
                doc.SecretLevel = GetInt("SecretLevel");
                //来文单位
                string su = GetOrg().OrgName;
                doc.SourceUnit = su;
                //GetString("SourceUnit")
                //doc.SignMan = GetString("SignMan");
                doc.SignMan = GetOrg().OrgID.ToString();
                doc.ComeCause = GetString("ComeCause");
                doc.Summary = GetString("Summary");
                //不需那个控件了
                doc.DocCaption = GetString("DocCaption");
                doc.DocSource = GetString("DocSource");
                doc.PubDate = DateTime.Now;
                //发布状态
                doc.Status = (int?)DocProcessStatus.Published;
                int attachementID = Convert.ToInt32(doc.AttachmentReference.EntityKey.EntityKeyValues[0].Value);

                if (HttpContext.Request.Files != null)
                {
                    HttpFileCollectionBase uploadFiles = this.HttpContext.Request.Files;
                    // 设置上传目标文件夹
                    string savaPath = this.HttpContext.Request.MapPath(@"../Content/uploadfiles/");
                    // 上传文件,并st返回上传的文件名(由于附件表需要文件名称,所以SaveFiles函数返回了文件名
                    List<string> fileNames = FileUpload.SaveFiles(uploadFiles, savaPath);
                    Attachment attachment = (from a in CQGJ.Attachment
                                             where a.AttachmentID == attachementID
                                             select a).First();
                    foreach (var f in fileNames)
                    {
                        AttachmentItem item = new AttachmentItem();
                        item.AddTime = DateTime.Now;
                        item.Attachment = attachment;
                        item.FileName = f.Split(',').First();
                        //表示激活
                        item.Status = 1;
                        CQGJ.AddToAttachmentItem(item);
                    }
                }
                IEnumerable<DocTreat> lsDoctreat = (from c in CQGJ.Doc
                                                    from dt in c.DocTreat
                                                    where c.DocID == DocID
                                                    select dt);
                foreach (var c in lsDoctreat)
                {
                    c.TreatType = (int?)DocProcessStatus.Published;
                }

                CQGJ.SaveChanges();
                return RedirectToAction("DocEdit/" + DocID);
            }
            return null;
        }
コード例 #3
0
ファイル: DocController.cs プロジェクト: dalinhuang/newcqgj
        ///公文的状态发布就是Published
        /// <summary>
        /// 保存公文函数
        /// </summary>
        public ActionResult DocSave()
        {
            int ot = Convert.ToInt32(HttpContext.Session["OrgType"]);
            Doc doc = new Doc();
            if (GetString("DocTitle") != "")
            {
                doc.DocTitle = GetString("DocTitle");
                doc.DocType = GetInt("DocType");
                doc.TrainType = GetInt("TrainType");
                doc.WordNo = GetString("WordNo");
                doc.YearNo = GetString("YearNo");
                doc.TeamNo = GetString("TeamNo");
                //采用select
                doc.UserID = (int?)GetUserID();
                doc.KeyWord = GetString("KeyWord");
                doc.DocClass = GetInt("DocClass");
                doc.UrgentLevel = GetInt("UrgentLevel");
                doc.SecretLevel = GetInt("SecretLevel");
                //来文单位
                string su = GetOrg().OrgName;
                doc.SourceUnit = su;
                //GetString("SourceUnit")
                //doc.SignMan = GetString("SignMan");
                doc.SignMan = GetOrg().OrgID.ToString();
                doc.ComeCause = GetString("ComeCause");
                doc.Summary = GetString("Summary");
                //不需那个控件了
                doc.DocCaption = GetString("DocCaption");
                doc.DocSource = GetString("DocSource");
                doc.PubDate = DateTime.Now;
                //发布状态
                //为1为草稿
                if (GetInt("token") == 1)
                {
                    doc.Status = (int?)DocStatus.Draft;
                }
                else
                {
                    doc.Status = (int?)DocStatus.Normal;
                }

                doc.ViewCount = 0;
                //取出发送的公文对象
                //b01 currentOrg = (b01)(HttpContext.Session["Org"]);
                //保存附件用代码
                if (HttpContext.Request.Files != null)
                {
                    HttpFileCollectionBase uploadFiles = this.HttpContext.Request.Files;
                    // 设置上传目标文件夹
                    string savaPath = this.HttpContext.Request.MapPath(@"../Content/uploadfiles/");
                    // 上传文件,并返回上传的文件名(由于附件表需要文件名称,所以SaveFiles函数返回了文件名
                    List<string> fileNames = FileUpload.SaveFiles(uploadFiles, savaPath);
                    Attachment attachment = new Attachment();
                    //暂时将Type设置为0
                    attachment.TypeID = 0;
                    CQGJ.AddToAttachment(attachment);
                    doc.Attachment = attachment;
                    foreach (var f in fileNames)
                    {
                        AttachmentItem item = new AttachmentItem();
                        item.AddTime = DateTime.Now;
                        item.Attachment = attachment;
                        item.FileName = f.Split(',').First();
                        //表示激活
                        item.Status = 1;
                        CQGJ.AddToAttachmentItem(item);
                    }
                }

                //如果单位类型为重庆市委组织部
                if (ot == 1)
                {
                    //存储发送对象
                    string ddd = GetString("DocDownUser");
                    string[] strList = GetString("DocDownUser").Split(',');
                    foreach (var c in strList)
                    {
                        DocTreat doctreat = new DocTreat();
                        doctreat.Doc = doc;
                        doctreat.Org = (from o in CQGJ.Org
                                        where o.OrgCode == c
                                        select o).First();
                        if (GetInt("token") == 1)
                        {
                            doctreat.TreatType = (int?)DocProcessStatus.Draft;
                        }
                        else
                        {
                            doctreat.TreatType = (int?)DocProcessStatus.Published;
                        }

                        doctreat.DownCount = 0;
                        doctreat.LastDownTime = DateTime.Now;
                        doctreat.TreatContent = "暂时没有反馈";
                        CQGJ.AddToDocTreat(doctreat);
                    }
                }
                else if (ot == 2 || ot == 3 || ot == 4)
                {
                    var orgList = from o in CQGJ.Org
                                  where o.OrgType == 1
                                  select o;
                    foreach (var c in orgList)
                    {
                        DocTreat docTreat = new DocTreat();
                        docTreat.Doc = doc;
                        docTreat.Org = (from o in CQGJ.Org
                                        where o.OrgID == c.OrgID
                                        select o).First();
                        if (GetInt("token") == 1)
                        {
                            docTreat.TreatType = (int?)DocProcessStatus.Draft;
                        }
                        else
                        {
                            docTreat.TreatType = (int?)DocProcessStatus.Published;
                        }
                        docTreat.DownCount = 0;
                        docTreat.LastDownTime = DateTime.Now;
                        docTreat.TreatContent = "暂时没有反馈";
                        CQGJ.AddToDocTreat(docTreat);
                    }
                }
                CQGJ.AddToDoc(doc);
                CQGJ.SaveChanges();

                //在跳转时提供viewData
                DocActionResultViewData viewData = new DocActionResultViewData();
                viewData.ActionSuccess = true;
                viewData.Message = "公文发送成功";

                viewData.javascriptMessage = "/doc/DocMantainsIndex";
                return View("MessagePage", viewData);
            }
            //注意:组织部和下级单位跳转的页面不一样
            if (ot == 1)
            {
                return RedirectToAction("DocSendedIndex");
            }
            else
            {
                return RedirectToAction("DocSendedSubList/1/1/1");
            }
        }
コード例 #4
0
ファイル: BBSController.cs プロジェクト: dalinhuang/newcqgj
        /// <summary>
        /// 发起一个新的BBS话题
        /// </summary>
        public ActionResult CreateTopicItem()
        {
            BBSItem BBSItem = new BBSItem();
            User user = GetUser();

            string subject = GetString("subject");
            string content = GetString("BBSItemContent");
            // 发起帖parentId为-1
            int parentId = -1;
            //status为备用字段,暂时设置为0
            int status = 0;
            //TypeID暂时设置为0
            int typeId = 0;
            // 取得登陆用户ID,userId
            int userId = user.UserID;
            // 取得用户姓名
            string userName = user.Username;
            int bbsId = GetInt("bbsid");
            // 取得上传附件组的ID, 1表示没有附件
            int attachmentId = 1;

            // 保存文件的路径
            string strAbsolutePath = this.HttpContext.Request.MapPath(@"../Content/UploadFiles/BBSFiles/");

            // 上传附件, 并获取附件组的ID
            try
            {
                // 获取上传附件组
                HttpFileCollectionBase uploadFiles = this.HttpContext.Request.Files;
                // 创建一个附件组
                Attachment at = new Attachment();

                if (uploadFiles.Count > 1)
                {
                    // ?好像数据库中存在数据的情况下才可以使用orderby语句, 否则会报错
                    // 所以需要对Attachment数据库初使化
                    attachmentId = (from attachment in CQGJ.Attachment orderby attachment.AttachmentID descending select attachment.AttachmentID).First() + 1;
                    at.AttachmentID = attachmentId;

                    // 在数据库中加一个附件组信息
                    CQGJ.AddToAttachment(at);
                }

                at.TypeID = 0; // 暂时设为0

                // 获取新建的附件组的ID
                //attachmentId = at.AttachmentID;

                for (int j = 1; j < uploadFiles.Count; j++)
                {
                    // 创建一个附件
                    AttachmentItem ai = new AttachmentItem();

                    ai.AddTime = DateTime.Now;
                    ai.Status = 0; // 暂时设置为0
                    ai.UserID = userId;
                    ai.TotalSize = uploadFiles[j].ContentLength;
                    ai.Attachment = at;
                    // 上传的文件是用原名呢,还是生成一个名字呢?
                    //ai.FileName = uploadFiles[j].FileName;
                    ai.FileName = FileUpload.SaveFile(uploadFiles[j], strAbsolutePath);

                    // 在数据库中加一个附件信息
                    CQGJ.AddToAttachmentItem(ai);

                    CQGJ.SaveChanges();

                }
            }
            catch (HttpException)
            {
                // 网络异常
            }
            catch (InvalidOperationException)
            {
                Response.Write("错误操作!");
            }

            CreateItem(subject, content, parentId, status, typeId, userId, userName, bbsId, attachmentId);

            // count 为数据库中发帖总数
            int count = (from bi in CQGJ.BBSItem where bi.ParentID == -1 && bi.BBS.BBSID == bbsId select bi).Count();

            // page 为当前发帖的页码
            int page = count / 10;

            if (count % 10 != 0)
            {
                page = count / 10 + 1;
            }

            // 返回BBS列表页面
            return RedirectToAction("ListBBSItems/" + bbsId + "/" + page);
        }