private void tbAccessoryName_Click(object sender, RoutedEventArgs e)
        {
            string notTitle = ss.downloadLink(notId);


            SaveFileDialog sfd = new SaveFileDialog();

            //设置默认要保存文件的文件名(文件名.扩展名)
            sfd.FileName = tbAccessoryName.Content.ToString();//这个名字也是原本服务器上保存文件的文件名
            //初始化提示保存文件的路径地址,默认保存在D盘中
            sfd.InitialDirectory = @"D:\";

            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string errorinfo;
                //获取要保存文件名的本地完整路径
                string localpath = sfd.FileName; // System.IO.Path.GetFullPath(sfd.FileName);
                                                 //调用下载文件函数,将教师作业公告附件从服务器上下载下来,其中localpath是本地路径,NotURL是数据库中存放的文件路径(文件在服务器上的路径)
                string NotURL = classId + "/" + notTitle + "/作业附件/" + tbAccessoryName.Content.ToString();
                bool   flag   = FtpUpDown.download(localpath, NotURL, out errorinfo);

                if (flag == true)
                {
                    System.Windows.MessageBox.Show("下载成功");
                }
                else
                {
                    System.Windows.MessageBox.Show("下载失败:" + errorinfo + "");
                }
            }
        }
Example #2
0
        //修改作业公告函数
        public String modifyNotice(DateTime truDeadline, String content, String notTitle, String classSpecId, String teacherSpecId, String localpath = "", String notURLName = "")
        {
            Notice notice = new Notice();

            notice.TruDeadLine = truDeadline;
            notice.Content     = content;


            //查询该真实的课堂号在数据库中课堂表对应自增主键ClassId
            DataTable tbClassId = td.getClassId(classSpecId);

            int result;

            if (!int.TryParse(tbClassId.Rows[0][0].ToString(), out result))//table[0][0]就是查到的classId
            {
                return("classSpecId转换为classId失败");
            }
            notice.ClassId = result;


            notice.NoteTitle = notTitle;

            bool flag;

            //上传作业公告附件
            if (localpath != "")//存在作业公告附件,根据路径插入FTP服务器中(已经有存放作业附件的目录了)
            {
                //具体上传作业附件
                string dirFullNotFile = classSpecId + "/" + notTitle + "/" + "作业附件";
                flag = FtpUpDown.upload(localpath, dirFullNotFile);
                if (!flag)
                {
                    return("在文件服务器中指定目录上传作业附件失败");
                }
                notice.NoteURL     = dirFullNotFile;
                notice.NoteURLName = notURLName;
            }
            else
            {
                notice.NoteURL = "";
            }
            //notice.NoteURL = notURL;

            //查询待修改作业公告的notId
            DataTable tbNotId = td.getNotIdByClassIdAndNotTitle(notice.NoteTitle, notice.ClassId);
            int       notId;

            if (!int.TryParse(tbNotId.Rows[0][0].ToString(), out notId))//table[0][0]就是查到的classId
            {
                return("获取待修改公告的notId并转换为int失败");
            }

            //调用更新作业公告函数,更新数据库notice表中该公告信息
            flag = td.updateNotice(truDeadline, content, notURLName, notId);
            if (!flag)
            {
                return("无法更新作业公告");
            }
            return("更新公告成功");
        }
Example #3
0
        //下载作业
        private void btnDownload_Click(object sender, RoutedEventArgs e)
        {
            //1、从数据库中查出homURL,然后获取文件名并能够鼠标放上去时在旁边显示文件名
            //从上一界面获取notId,根据notId+stuId访问到homId

            SaveFileDialog sfd = new SaveFileDialog();

            //设置默认要保存文件的文件名(文件名.扩展名)
            sfd.FileName = homName;//这个名字也是原本服务器上保存文件的文件名
            //初始化提示保存文件的路径地址
            sfd.InitialDirectory = @"D:\";

            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string errorinfo;
                //获取要保存文件名的本地完整路径
                string localpath = sfd.FileName; // System.IO.Path.GetFullPath(sfd.FileName);
                                                 //调用下载文件函数,将学生作业从服务器上下载下来,其中localpath是本地路径,homURL是数据库中存放的文件路径(文件在服务器上的路径)
                string homFullURL = homURL + "/" + homName;
                bool   flag       = FtpUpDown.download(localpath, homFullURL, out errorinfo);

                if (flag == true)
                {
                    System.Windows.MessageBox.Show("下载成功");
                }
                else
                {
                    System.Windows.MessageBox.Show("下载失败:" + errorinfo + "");
                }
            }
        }
Example #4
0
    public void OnClick_ShowFtpFileList()
    {
        ftpServerIP = _ServerIP.text;
        if (string.IsNullOrEmpty(ftpServerIP))
        {
            Debug.LogError("ftpServerIP Input is Error !!!");
            return;
        }

        ftpUserID = _UserID.text;
        if (string.IsNullOrEmpty(ftpUserID))
        {
            Debug.LogError("ftpUserID Input is Error !!!");
            return;
        }

        ftpPassword = _Password.text;
        if (string.IsNullOrEmpty(ftpPassword))
        {
            Debug.LogError("ftpPassword Input is Error !!!");
            return;
        }

        ConvertData.FtpUpDown _ftp = new FtpUpDown(ftpServerIP, ftpUserID, ftpPassword);
        if (_ftp == null)
        {
            return;
        }

        string[] _list = _ftp.GetFileList();
        for (int i = 0; i < _list.Length; ++i)
        {
            _ShowResult.text += _list[i] + " \n";
        }
    }
Example #5
0
        ////删除作业公告附件URL,用于实现上传新的作业附件
        public bool deleteNotURL(string classSpecId, string notTitle, string notFileName)
        {
            //删除作业公告附件URL,用于实现上传新的作业附件
            //作业附件文件夹->classSpecId/notTitle/作业附件
            string errorinfo;
            string FileFullPath = classSpecId + "/" + notTitle + "/" + "作业附件/" + notFileName;

            //MessageBox.Show(dirName);
            return(FtpUpDown.delFile(FileFullPath, out errorinfo));
        }
Example #6
0
        //删除作业公告
        public String deleteHomeworkNotice(String classSpecId, String homeworkTitle)
        {
            DataTable tbClassId = td.getClassId(classSpecId);
            int       classId   = Convert.ToInt32(tbClassId.Rows[0][0]); //获取classId
            DataTable tbNotId   = td.getNotIdByClassIdAndNotTitle(homeworkTitle, classId);
            string    notId     = tbNotId.Rows[0][0].ToString();         //获取notId

            //第一步:删除远程服务器上文件
            //根据notId找notURL
            DataTable tbNotURL = td.getNotURLByNotId(notId);
            //把作业公告文件夹进行改名
            string notURL = tbNotURL.Rows[0][0].ToString();//课堂号/作业公告号/作业附件

            string[] notURLs            = notURL.Split('/');
            string   currentDirFullPath = notURLs[0] + "/" + notURLs[1];
            string   newDirName         = "已被删除的作业公告" + notURLs[1];

            FtpUpDown.rename(currentDirFullPath, newDirName);

            //第二步:在数据库comment表中删除作业答疑
            //当数据库中存在答疑的时候才需要删除,否则不需要删除答疑
            if (td.getCommentNumByNotId(notId) != 0)//此时才需要删除答疑
            {
                bool flagComm = td.deleteComment(notId);
                if (flagComm != true)
                {
                    return("删除作业答疑失败");
                }
            }

            //第三步:在数据库homework表中删除作业
            bool flagHomework = td.deleteHomework(tbNotId.Rows[0][0].ToString());

            if (flagHomework != true)
            {
                return("删除学生作业记录失败");
            }

            //第四步:在数据库notice表中删除作业公告
            bool flagNotice = td.deleteNotice(notId);

            if (flagNotice != true)
            {
                return("删除该作业公告失败");
            }

            return("删除该作业公告成功");
        }
Example #7
0
    void Start()
    {
        _ShowResult      = GameObject.Find("ShowResult").GetComponent <Text>();
        _ShowResult.text = "";

        _ServerIP      = GameObject.Find("FtpServerPath").GetComponent <InputField>();
        _ServerIP.text = "";
        _UserID        = GameObject.Find("UserID").GetComponent <InputField>();
        _UserID.text   = "";
        _Password      = GameObject.Find("Password").GetComponent <InputField>();
        _Password.text = "";

        FtpUpDown _ftp = new FtpUpDown(ftpServerIP, ftpUserID, ftpPassword);

        if (_ftp == null)
        {
            Debug.LogError("Ftp Init Error !!!");
            return;
        }
    }
Example #8
0
 private void gridView_MouseDown(object sender, MouseEventArgs e)
 {
     try
     {
         this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
         GridHitInfo hInfo = gridView.CalcHitInfo(new Point(e.X, e.Y));
         //双击左键
         if (e.Button == System.Windows.Forms.MouseButtons.Left && e.Clicks == 2)
         {
             //判断光标是否在行范围内
             if (hInfo.InRow)
             {
                 //currentObj = gridView.GetRow(hInfo.RowHandle);
                 //NavMenu(currentObj);
                 if (gridView.FocusedColumn == colPic && gridView.GetFocusedValue() != null)  //双击图片单元格打开图片
                 {
                     //ImageHelper.WindowsPhotoViewer(ImageHelper.BinaryToImage((Binary)gridView.GetFocusedValue()));
                     //ImageHelper.WindowsPhotoViewer(Image.FromFile(gridView.GetFocusedRowCellValue("colPicPath").ToString()));
                     if (!System.IO.Directory.Exists(MainForm.DownloadFilePath))
                     {
                         System.IO.Directory.CreateDirectory(MainForm.DownloadFilePath);
                     }
                     string downloadFileName = MainForm.DownloadFilePath + String.Format("{0}.jpg", gridView.GetFocusedRowCellDisplayText("GoodsID").ToString());
                     //FileHelper.DownloadFile(downloadFileName, MainForm.ServerUserName, MainForm.ServerPassword, MainForm.ServerDomain);
                     string    strErrorinfo = string.Empty;
                     FtpUpDown ftpUpDown    = new FtpUpDown(MainForm.ServerUrl, MainForm.ServerUserName, MainForm.ServerPassword);
                     ftpUpDown.Download(MainForm.DownloadFilePath, String.Format("{0}.jpg", gridView.GetFocusedRowCellDisplayText("GoodsID").ToString()), out strErrorinfo);
                     ImageHelper.WindowsPhotoViewer(Image.FromFile(downloadFileName));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         CommonServices.ErrorTrace.SetErrorInfo(this.FindForm(), ex.Message);
     }
     finally
     {
         this.Cursor = System.Windows.Forms.Cursors.Default;
     }
 }
Example #9
0
        private void lueGoods_EditValueChanged(object sender, EventArgs e)
        {
            Goods goods = ((LookUpEdit)sender).GetSelectedDataRow() as Goods;

            if (goods != null)
            {
                goodsName      = goods.Name;
                tbSubject.Text = goods.Name;
                //txtNWeight.EditValue = goods.NWeight;
                //txtCycle.EditValue = goods.Cycle;
                #region 处理图片
                if (!string.IsNullOrEmpty(lueGoods.Text))
                {
                    //将图片缩略图转为原图
                    if (!System.IO.Directory.Exists(MainForm.DownloadFilePath))
                    {
                        System.IO.Directory.CreateDirectory(MainForm.DownloadFilePath);
                    }
                    string fileName = MainForm.DownloadFilePath + String.Format("{0}.jpg", goods.Code);
                    if (!File.Exists(fileName))
                    {
                        string    strErrorinfo = string.Empty;
                        FtpUpDown ftpUpDown    = new FtpUpDown(MainForm.ServerUrl, MainForm.ServerUserName, MainForm.ServerPassword);
                        ftpUpDown.Download(MainForm.DownloadFilePath, String.Format("{0}.jpg", goods.Code), out strErrorinfo);
                    }
                    pePic.EditValue    = ImageHelper.MakeBuff(Image.FromFile(fileName));
                    txtWeight.Enabled  = true;
                    txtNWeight.Enabled = true;
                    txtCycle.Enabled   = true;
                }
                else
                {
                    txtWeight.Enabled  = false;
                    txtNWeight.Enabled = false;
                    txtCycle.Enabled   = false;
                }
                #endregion
                GetTotal();
            }
        }
Example #10
0
        //DateTime baseDate = new DateTime(1970, 1, 1);
        //DateTime result = temp.AddSeconds(timeStamp);
        //对truDeadline用datetime

        //发布作业公告函数
        public String announceNotice(DateTime truDeadline, String content, String notTitle, String classSpecId, String teacherSpecId, String localpath = "", String notURLName = "")
        {
            Notice notice = new Notice();

            notice.TruDeadLine = truDeadline;
            notice.Content     = content;


            //查询该真实的课堂号在数据库中课堂表对应自增主键ClassId
            DataTable tbClassId = td.getClassId(classSpecId);

            int result;

            if (!int.TryParse(tbClassId.Rows[0][0].ToString(), out result))//table[0][0]就是查到的classId
            {
                return("classSpecId转换为classId失败");
            }
            notice.ClassId = result;

            //根据ClassId获取notice表中所有作业公告标题,比对是否重复
            DataTable tbNoteTitles = td.getNoteTitle(notice.ClassId);

            int count = tbNoteTitles.Rows.Count;                         //获得该课堂号所发布的所有作业公告的标题

            for (int x = 0; x < count; x++)                              //判断是否和已布置的作业公告标题存在重复
            {
                string tbNoteTitle = tbNoteTitles.Rows[x][0].ToString(); //获取该课堂某次作业公告的标题
                if (notTitle == tbNoteTitle)
                {
                    return("此次布置的作业公告标题和该堂课之前的作业公告标题重复");
                }
            }
            notice.NoteTitle = notTitle;//说明没有重复,该作业公告标题合法

            bool   flag;
            string errorinfo;

            //创建作业公告目录
            string dirNotTitle = notTitle;                                   //课堂真实号/作业公告标题/
            string orginPath   = classSpecId;                                //原始目录或起始目录,即在哪个目录下创建

            flag = FtpUpDown.makeDir(dirNotTitle, out errorinfo, orginPath); //创建目录的静态方法,可以直接通过类名访问
            if (flag == false)
            {
                return("在文件服务器中创建对应作业公告的目录失败");
            }

            //此处注意:不管有没有作业附件,都先建好作业附件的目录
            //创建作业附件目录
            string dirNotFile = "作业附件";

            orginPath += "/" + dirNotTitle;
            flag       = FtpUpDown.makeDir(dirNotFile, out errorinfo, orginPath);//创建目录的静态方法,可以直接通过类名访问
            if (flag == false)
            {
                return("在文件服务器中创建存放作业附件的目录失败");
            }
            string dirFullNotFile = orginPath + "/" + dirNotFile;

            notice.NoteURL = dirFullNotFile;

            //上传作业公告附件
            if (localpath != "")//存在作业公告附件,根据路径插入FTP服务器中
            {
                flag = FtpUpDown.upload(localpath, dirFullNotFile);
                if (!flag)
                {
                    return("在文件服务器中指定目录上传作业附件失败");
                }

                notice.NoteURLName = notURLName;
            }

            //notice.NoteURL = notURL;
            //调用插入作业公告函数,将公告插入数据库notice表
            flag = td.insertNotice(notice);
            if (!flag)
            {
                return("无法将新增的作业公告插入到notice表");
            }

            //查询该教师工号在数据库中教师表对应的教师自增主键teacherId
            DataTable tbTeacherId = td.getTeacherId(teacherSpecId);           //tbTeacherSpecId.Text是教师工号

            if (!int.TryParse(tbTeacherId.Rows[0][0].ToString(), out result)) //table[0][0]就是查到的classId
            {
                return("teacherSpecId转换为teacherId失败");
            }
            int teacherId = result;
            //查询刚刚发布作业公告的notId
            DataTable tbNotId = td.getNotIdByClassIdAndNotTitle(notice.NoteTitle, notice.ClassId);
            int       notId;

            if (!int.TryParse(tbNotId.Rows[0][0].ToString(), out notId))//table[0][0]就是查到的classId
            {
                return("获取新增公告的notId并转换为int失败");
            }


            int classId = notice.ClassId;
            //调用添加作业函数,该函数负责调用Dao层将作业插入数据库homework表
            //[studentDao文件夹下某Dao文件的一个对象].insertHomework(classId,teacherId,notId);
            //该函数还需要根据classId,获得每个选课学生的stuId,然后依次在作业表中根据(stuId,classId,teacherId,notId)进行插入
            DataTable tbStuId  = td.getStuIdFromClassId(notice.ClassId);
            int       stuidNum = tbStuId.Rows.Count; //获取所有选课学生的数量

            //插入作业
            for (int i = 0; i < stuidNum; i++)
            {
                string   stuId    = tbStuId.Rows[i][0].ToString(); //获取每一个学生的id号
                Homework homework = new Homework();                //新建一个homework实体
                homework.ClassId = notice.ClassId;
                int sid;
                if (int.TryParse(stuId, out sid))
                {
                    homework.StuId = sid;
                }
                homework.TeacherId = teacherId;
                homework.NotId     = notId;
                //stuId, classId, teacherId, notId
                bool flag1 = td.insertHomework(homework);
                if (!flag1)
                {
                    return("发布失败,请重试");
                }
            }


            return("发布公告成功");
        }
Example #11
0
        //学生提交作业时需要调用该函数对作业表中的字段进行修改
        public String submitHomework(string name, string classId, string account, string postil, string homUrlName, string notId, string localpath)
        {
            //可以直接从前端界面取值,就不需要查库了
            //通过账号来获取到姓名
            //DataTable sdName = sd.GetStuName(account);
            //string name = sdName.Rows[0][0].ToString();
            //System.Windows.MessageBox.Show(name);

            //通过作业公告Id获取作业公告名
            DataTable sdNotName = sd.getNotName(notId);
            string    notName   = sdNotName.Rows[0][0].ToString();


            //进行服务器文件夹和文件的上传操作
            //数据库中数据的更新
            //update homework  set postil = @postil, homUrl = @homUrl, homUrlName = @homUrlName , submitTime = @submitTime where notId  = @notId  and  stuId = @stuId;";
            //学生提交作业的时间
            DateTime submitTime = DateTime.Now;
            //查询该真实的学号在数据库中课堂表对应自增主键stuId
            DataTable sdStuId = sd.getStuIdByAccount(account);

            int result;

            if (!int.TryParse(sdStuId.Rows[0][0].ToString(), out result))//table[0][0]就是查到的stuId
            {
                return("account转换为stuId失败");
            }
            string stuId = result.ToString();
            bool   flag;
            string errorinfo;

            //根据stuId和notId获取homework表中该作业的作业名,判断是否交过作业
            DataTable sdHomName = sd.getHomeUrlNameByStuIdAndNotId(stuId, notId);

            String homName = sdHomName.Rows[0][0].ToString();//获得该作业的作业名

            //作业名为空,表示是第一次交作业,需要创建目录并添加文件到服务器
            if (homName == "")
            {
                string dirNameAc = account + name;                             //课堂真实号/作业公告标题/学生学号+姓名
                string orginPath = classId + "/" + notName;                    //原始目录或起始目录,即在哪个目录下创建
                flag = FtpUpDown.makeDir(dirNameAc, out errorinfo, orginPath); //创建目录的静态方法,可以直接通过类名访问
                //创建作业目录
                if (flag == false)
                {
                    return("在文件服务器中创建对应作业目录失败");
                }
                //上传作业
                string dirFullNotFile = orginPath + "/" + dirNameAc;
                if (localpath != "")
                {
                    flag = FtpUpDown.upload(localpath, dirFullNotFile);
                    if (!flag)
                    {
                        return("在文件服务器中指定目录上传作业失败");
                    }
                }
            }
            //作业名不为空,表示已经交过一次作业了,不需要创建文件夹,只需要更改文件名并上传至服务器即可
            else
            {
                string dirNameAc      = account + name;          //课堂真实号/作业公告标题/学生学号+姓名
                string orginPath      = classId + "/" + notName; //原始目录或起始目录,即在哪个目录下创建
                string dirFullNotFile = orginPath + "/" + dirNameAc;
                if (localpath != "")
                {
                    DataTable normalName   = sd.getHomeUrlNameByStuIdAndNotId(stuId, notId); //寻找到当前文件服务器和数据库中存储的作业文件名
                    string    Name         = normalName.Rows[0][0].ToString();
                    string    fileFullPath = dirFullNotFile + "/" + Name;                    //寻找到在文件服务器中当前作业的路径
                    flag = FtpUpDown.delFile(fileFullPath, out errorinfo);                   //将文件服务器中已有的作业删除
                    if (!flag)
                    {
                        return("修改时,源文件删除失败,请重试");                      //表示修改失败
                    }
                    flag = FtpUpDown.upload(localpath, dirFullNotFile); //删除原文件之后,将新的文件添加到文件服务器中
                    if (!flag)
                    {
                        return("在文件服务器中指定目录修改作业失败");
                    }
                }
            }
            string homUrl = classId + "/" + notName + "/" + account + name;

            //进行数据库中表的更新
            //调用函数,更新数据库homework表
            flag = sd.updateHomework(submitTime, notId, stuId, postil, homUrl, homUrlName);
            if (!flag)
            {
                return("无法将更新homework表");
            }
            return("上传作业成功");
        }