protected void btnOK_Click(object sender, EventArgs e)
        {
            if (Request.QueryString.Get("TrainTypeID") != null)
            {
                int bookID      = Convert.ToInt32(Request.QueryString.Get("CoursewareID"));
                int trainTypeID = Convert.ToInt32(Request.QueryString.Get("TrainTypeID"));
                CoursewareTrainTypeBLL objBll = new CoursewareTrainTypeBLL();
                CoursewareTrainType    obj    = objBll.GetCoursewareTrainType(bookID, trainTypeID);
                int order = Convert.ToInt32(txtOrderIndex.Text);
                int max   = Convert.ToInt32(Request.QueryString.Get("MaxOrder"));
                if (order > max)
                {
                    obj.OrderIndex = max;
                }
                else
                {
                    obj.OrderIndex = order;
                }
                objBll.UpdateCoursewareTrainType(obj);
            }
            else
            {
                CoursewareBLL             objBll = new CoursewareBLL();
                RailExam.Model.Courseware obj    = objBll.GetCourseware(Convert.ToInt32(Request.QueryString.Get("CoursewareID")));
                int order = Convert.ToInt32(txtOrderIndex.Text);
                int max   = Convert.ToInt32(Request.QueryString.Get("MaxOrder"));
                if (order > max)
                {
                    obj.OrderIndex = max;
                }
                else
                {
                    obj.OrderIndex = order;
                }
                objBll.UpdateCourseware(obj);
            }

            Response.Write("<script>top.returnValue='true';window.close();</script>");
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (PrjPub.CurrentLoginUser == null)
                {
                    Response.Redirect("/RailExamBao/Common/Error.aspx?error=Session过期请重新登录本系统!");
                    return;
                }

                if (PrjPub.HasEditRight("课件管理") && PrjPub.IsServerCenter)                //&& PrjPub.CurrentLoginUser.SuitRange == 1
                {
                    HfUpdateRight.Value = "True";
                }
                else
                {
                    HfUpdateRight.Value = "False";
                }
                if (PrjPub.HasDeleteRight("课件管理") && PrjPub.IsServerCenter)                //&& PrjPub.CurrentLoginUser.SuitRange == 1
                {
                    HfDeleteRight.Value = "True";
                }
                else
                {
                    HfDeleteRight.Value = "False";
                }

                OrganizationBLL orgBll = new OrganizationBLL();
                int             orgID  = orgBll.GetStationOrgID(PrjPub.CurrentLoginUser.OrgID);
                HfOrgId.Value = orgID.ToString();

                BindGrid();
            }
            else
            {
                string strDeleteID = Request.Form.Get("DeleteID");
                if (!string.IsNullOrEmpty(strDeleteID))
                {
                    DeleteData(int.Parse(strDeleteID));
                    BindGrid();
                }

                if (Request.Form.Get("Refresh") == "true")
                {
                    BindGrid();
                }
            }

            string strUpID = Request.Form.Get("UpID");

            if (strUpID != null && strUpID != "")
            {
                if (Request.QueryString.Get("type") == "Courseware")
                {
                    CoursewareBLL             objBll = new CoursewareBLL();
                    RailExam.Model.Courseware obj    = objBll.GetCourseware(Convert.ToInt32(strUpID));
                    obj.OrderIndex = obj.OrderIndex - 1;
                    objBll.UpdateCourseware(obj);
                }

                if (Request.QueryString.Get("type") == "TrainType")
                {
                    int trainTypeID = Convert.ToInt32(Request.QueryString.Get("id"));
                    CoursewareTrainTypeBLL objTrainTypeBll = new CoursewareTrainTypeBLL();
                    CoursewareTrainType    objTrainType    =
                        objTrainTypeBll.GetCoursewareTrainType(Convert.ToInt32(strUpID), trainTypeID);
                    objTrainType.OrderIndex = objTrainType.OrderIndex - 1;
                    objTrainTypeBll.UpdateCoursewareTrainType(objTrainType);
                }
                BindGrid();
            }

            string strDownID = Request.Form.Get("DownID");

            if (strDownID != null && strDownID != "")
            {
                if (Request.QueryString.Get("type") == "Courseware")
                {
                    CoursewareBLL             objBll = new CoursewareBLL();
                    RailExam.Model.Courseware obj    = objBll.GetCourseware(Convert.ToInt32(strDownID));
                    obj.OrderIndex = obj.OrderIndex + 1;
                    objBll.UpdateCourseware(obj);
                }

                if (Request.QueryString.Get("type") == "TrainType")
                {
                    int trainTypeID = Convert.ToInt32(Request.QueryString.Get("id"));
                    CoursewareTrainTypeBLL objTrainTypeBll = new CoursewareTrainTypeBLL();
                    CoursewareTrainType    objTrainType    =
                        objTrainTypeBll.GetCoursewareTrainType(Convert.ToInt32(strDownID), trainTypeID);
                    objTrainType.OrderIndex = objTrainType.OrderIndex + 1;
                    objTrainTypeBll.UpdateCoursewareTrainType(objTrainType);
                }
                BindGrid();
            }
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            string strFullName = string.Empty;            //, strUrl, strContentType, strSize

            CoursewareBLL coursewareBLL = new CoursewareBLL();


            if (ViewState["AddFlag"].ToString() == "1")      //新增
            {
                strFullName = File1.FileName;                //直接取得文件名



                if (!string.IsNullOrEmpty(strFullName))
                {
                    FileInfo fi = new FileInfo(File1.FileName);

                    //判断只能上传.flv与.swf格式

                    //if (fi.Extension.ToLower() != ".flv" && fi.Extension.ToLower() != ".swf")
                    //{
                    //    SessionSet.PageMessage = "文件格式应为FLV或SWF视频! 现在格式为:" + fi.Extension.ToLower();
                    //    return;
                    //}

                    if (fi.Name.Replace(fi.Extension, "") != txtCoursewareName.Text)
                    {
                        SessionSet.PageMessage = "上传文件名与课件名不一致,请确认上传文件名!";
                        return;
                    }
                }
                RailExam.Model.Courseware courseware = new RailExam.Model.Courseware();

                courseware.CoursewareName   = txtCoursewareName.Text;
                courseware.CoursewareTypeID = int.Parse(hfCoursewareTypeID.Value);
                courseware.ProvideOrg       = SessionSet.OrganizationID;
                courseware.PublishDate      = DateTime.Parse(datePublishDate.DateValue.ToString());
                courseware.Authors          = txtAuthors.Text;
                courseware.Revisers         = txtRevisers.Text;
                courseware.KeyWord          = txtKeyWord.Text;
                courseware.Description      = txtDescription.Text;
                courseware.Memo             = txtMemo.Text;
                courseware.IsGroupLearder   = Convert.ToInt32(ddlIsGroup.SelectedValue);
                courseware.TechnicianTypeID = Convert.ToInt32(ddlTech.SelectedValue);

                ArrayList al = new ArrayList();
                courseware.OrgIDAL = GetOrg(tvOrg.Nodes, al);

                ArrayList al1 = new ArrayList();

                foreach (TreeViewNode tn in tvPost.Nodes)
                {
                    if (tn.Checked)
                    {
                        al1.Add(tn.ID);
                    }

                    if (tn.Nodes.Count > 0)
                    {
                        foreach (TreeViewNode tns in tn.Nodes)
                        {
                            if (tns.Checked)
                            {
                                al1.Add(tns.ID);
                            }

                            if (tns.Nodes.Count > 0)
                            {
                                foreach (TreeViewNode tnss in tns.Nodes)
                                {
                                    if (tnss.Checked)
                                    {
                                        al1.Add(tnss.ID);
                                    }
                                }
                            }
                        }
                    }
                }
                courseware.PostIDAL = al1;

                ArrayList trainTypeIDList = new ArrayList();
                string[]  strType         = hfTrainTypeID.Value.Split(',');
                for (int i = 0; i < strType.Length; i++)
                {
                    if (!string.IsNullOrEmpty(strType[i]))
                    {
                        trainTypeIDList.Add(strType[i]);
                    }
                }
                courseware.TrainTypeIDAL = trainTypeIDList;

                int nCoursewareID = coursewareBLL.AddCourseware(courseware);

                if (!string.IsNullOrEmpty(strFullName))
                {
                    //strUrl = File1.PostedFile.FileName;//先取得全部的上传文件路径个名字,然后再利用SubString方法来得到用户名,现在看来是没有必要了


                    //strContentType = File1.PostedFile.ContentType;//获取文件MIME内容类型
                    //strFileType = strFullName.Substring(strFullName.LastIndexOf(".") + 1);//获取文件名字 . 后面的字符作为文件类型


                    //strSize = File1.PostedFile.ContentLength.ToString();


                    Directory.CreateDirectory(Server.MapPath("../Online/Courseware/" + nCoursewareID));
                    File1.SaveAs(Server.MapPath("../Online/Courseware/" + nCoursewareID + "/") + strFullName);                    //将文件保存在跟目录的UP文件夹下

                    courseware.CoursewareID = nCoursewareID;
                    courseware.Url          = "/RailExamBao/Online/Courseware/" + nCoursewareID + "/" + strFullName;

                    coursewareBLL.UpdateCourseware(courseware);
                }
                Response.Write("<script>window.opener.form1.Refresh.value='true';window.opener.form1.submit();window.close();</script>");
            }
            else                //修改
            {
                string strCoursewareID = Request.QueryString.Get("id");

                RailExam.Model.Courseware courseware = coursewareBLL.GetCourseware(Convert.ToInt32(strCoursewareID));
                courseware.CoursewareID     = int.Parse(strCoursewareID);
                courseware.CoursewareName   = txtCoursewareName.Text;
                courseware.CoursewareTypeID = int.Parse(hfCoursewareTypeID.Value);
                courseware.ProvideOrg       = int.Parse(hfProvideOrgID.Value);
                courseware.PublishDate      = DateTime.Parse(datePublishDate.DateValue.ToString());
                courseware.Authors          = txtAuthors.Text;
                courseware.Revisers         = txtRevisers.Text;
                courseware.KeyWord          = txtKeyWord.Text;
                courseware.Description      = txtDescription.Text;
                courseware.IsGroupLearder   = Convert.ToInt32(ddlIsGroup.SelectedValue);
                courseware.TechnicianTypeID = Convert.ToInt32(ddlTech.SelectedValue);
                courseware.OrderIndex       = Convert.ToInt32(hfOrderIndex.Value);

                strFullName = File1.FileName;                //直接取得文件名



                //strUrl = File1.PostedFile.FileName;//先取得全部的上传文件路径个名字,然后再利用SubString方法来得到用户名,现在看来是没有必要了


                //strContentType = File1.PostedFile.ContentType;//获取文件MIME内容类型
                //strFileType = strFullName.Substring(strFullName.LastIndexOf(".") + 1);//获取文件名字 . 后面的字符作为文件类型


                //strSize = File1.PostedFile.ContentLength.ToString();

                if (!string.IsNullOrEmpty(strFullName))
                {
                    FileInfo fi = new FileInfo(File1.FileName);

                    //如果是武汉,就判断只能上传.flv与.swf格式

                    //if (fi.Extension.ToLower() != ".flv" && fi.Extension.ToLower() != ".swf")
                    //{
                    //    SessionSet.PageMessage = "文件格式应为FLV或SWF视频! 现在格式为:" + fi.Extension.ToLower();
                    //    return;
                    //}

                    if (fi.Name.Replace(fi.Extension, "") != txtCoursewareName.Text)
                    {
                        SessionSet.PageMessage = "上传文件名与课件名不一致,请确认上传文件名!";
                        return;
                    }

                    if (File.Exists(Server.MapPath(courseware.Url)))
                    {
                        //string[] filelist = Directory.GetFileSystemEntries(Server.MapPath("../Online/Courseware/" + courseware.CoursewareID + "/"));
                        //foreach (string file in filelist)
                        //{
                        //    if(!Directory.Exists(file))
                        //    {
                        //        File.Delete(file);
                        //    }
                        //}
                        File.Delete(Server.MapPath(courseware.Url));
                    }

                    if (!Directory.Exists(Server.MapPath("../Online/Courseware/" + strCoursewareID)))
                    {
                        Directory.CreateDirectory(Server.MapPath("../Online/Courseware/" + strCoursewareID));
                    }

                    File1.SaveAs(Server.MapPath("../Online/Courseware/" + strCoursewareID + "/") + strFullName);                    //将文件保存在跟目录的UP文件夹下

                    courseware.Url = "/RailExamBao/Online/Courseware/" + strCoursewareID + "/" + strFullName;
                }
                courseware.Memo = txtMemo.Text;

                ArrayList al = new ArrayList();
                courseware.OrgIDAL = GetOrg(tvOrg.Nodes, al);

                ArrayList al1 = new ArrayList();

                foreach (TreeViewNode tn in tvPost.Nodes)
                {
                    if (tn.Checked)
                    {
                        al1.Add(tn.ID);
                    }

                    if (tn.Nodes.Count > 0)
                    {
                        foreach (TreeViewNode tns in tn.Nodes)
                        {
                            if (tns.Checked)
                            {
                                al1.Add(tns.ID);
                            }

                            if (tns.Nodes.Count > 0)
                            {
                                foreach (TreeViewNode tnss in tns.Nodes)
                                {
                                    if (tnss.Checked)
                                    {
                                        al1.Add(tnss.ID);
                                    }
                                }
                            }
                        }
                    }
                }
                courseware.PostIDAL = al1;

                ArrayList trainTypeIDList = new ArrayList();
                string[]  strType         = hfTrainTypeID.Value.Split(',');
                for (int i = 0; i < strType.Length; i++)
                {
                    if (!string.IsNullOrEmpty(strType[i]))
                    {
                        trainTypeIDList.Add(strType[i]);
                    }
                }
                courseware.TrainTypeIDAL = trainTypeIDList;

                coursewareBLL.UpdateCourseware(courseware);

                Response.Write("<script>window.opener.form1.Refresh.value='true';window.opener.form1.submit();window.close();</script>");
            }
        }
        private void FillPage(int nCoursewareID)
        {
            CoursewareBLL coursewareBLL = new CoursewareBLL();

            ArrayList trainTypeIDAL = new ArrayList();
            ArrayList orgIDAL       = new ArrayList();
            ArrayList postIDAL      = new ArrayList();

            RailExam.Model.Courseware courseware = coursewareBLL.GetCourseware(nCoursewareID);

            if (courseware != null)
            {
                txtCoursewareName.Text     = courseware.CoursewareName;
                txtCoursewareTypeName.Text = courseware.CoursewareTypeNames;
                hfCoursewareTypeID.Value   = courseware.CoursewareTypeID.ToString();

                txtTrainTypeName.Text = courseware.TrainTypeNames;

                txtProvideOrgName.Text = courseware.ProvideOrgName;
                hfProvideOrgID.Value   = courseware.ProvideOrg.ToString();

                datePublishDate.DateValue = courseware.PublishDate.ToString("yyyy-MM-dd");
                txtAuthors.Text           = courseware.Authors;
                txtRevisers.Text          = courseware.Revisers;
                txtKeyWord.Text           = courseware.KeyWord;
                txtDescription.Text       = courseware.Description;
                string strUrl = string.Empty;
                strUrl                   = "ViewCourseware.aspx?id=" + courseware.CoursewareID;
                hlUrl.Text               = strUrl;
                hlUrl.NavigateUrl        = strUrl;
                ddlIsGroup.SelectedValue = courseware.IsGroupLearder.ToString();
                ddlTech.SelectedValue    = courseware.TechnicianTypeID.ToString();
                hfOrderIndex.Value       = courseware.OrderIndex.ToString();

                txtMemo.Text = courseware.Memo;

                trainTypeIDAL = courseware.TrainTypeIDAL;
                orgIDAL       = courseware.OrgIDAL;
                postIDAL      = courseware.PostIDAL;
            }
            //tvOrg.Nodes.Clear();
            //tvPost.Nodes.Clear();

            BindOrganizationTree(orgIDAL);
            BindPostTree(postIDAL);

            string strUpdate = PrjPub.HasEditRight("课件管理").ToString();
            string strOrgID  = PrjPub.CurrentLoginUser.OrgID.ToString();

            if (courseware != null)
            {
                //if (strUpdate == "True" && strOrgID == courseware.ProvideOrg.ToString())
                if (strUpdate == "True" && PrjPub.CurrentLoginUser.SuitRange == 1)
                {
                    SaveButton.Visible   = true;
                    CancelButton.Visible = false;
                }
                else
                {
                    SaveButton.Visible   = false;
                    CancelButton.Visible = true;
                }
            }

            string strMode = Request.QueryString.Get("mode");

            if (strMode == "ReadOnly")
            {
                SaveButton.Visible   = false;
                CancelButton.Visible = true;

                //隐藏图片

                txtCoursewareName.ReadOnly = true;
                txtAuthors.ReadOnly        = true;
                txtRevisers.ReadOnly       = true;
                txtKeyWord.ReadOnly        = true;
                txtDescription.ReadOnly    = true;
                txtMemo.ReadOnly           = true;
            }
            else
            {
                SaveButton.Visible   = true;
                CancelButton.Visible = false;

                for (int i = 0; i < trainTypeIDAL.Count; i++)
                {
                    if (i == 0)
                    {
                        hfTrainTypeID.Value = trainTypeIDAL[0].ToString();
                    }
                    else
                    {
                        hfTrainTypeID.Value += "," + trainTypeIDAL[i].ToString();
                    }
                }
            }

            ViewState["AddFlag"] = 0;
        }