Esempio n. 1
0
        /// <summary>
        /// 把点名表转成list 再转换成Datatable 然后再存.
        /// </summary>
        /// <param name="classBriefcase">要存的那门课对应的briefcase</param>
        /// <param name="dmTable">要保存的点名表</param>
        public static void SaveDmTable(FileBriefcase classBriefcase, DataTable dmTable)
        {
            var listToSave = dmTable.ToList <DMTABLE_08_NOPIC_VIEW>();                                // 将Dmtable转成list

            var datatableToSave = EnumerableExtension.ListToDataTable(listToSave, dmTable.TableName); // 从list再转回来

            classBriefcase.AddTable(datatableToSave);                                                 //把转完的Datatable放到Briefcase中.

            classBriefcase.WriteBriefcase();                                                          //保存
        }
Esempio n. 2
0
        /// <summary>
        /// 获取propertiesBriefcase,其中包含该 1.该平板中所有的课程 2.班级表
        /// 第一次在哪下载的课程 就得在哪里用.学院之间不能混用.
        /// 若briefcase不存在 则创建一个briefcase
        /// </summary>
        /// <returns></returns>
        public static FileBriefcase InitPropertiesBriefcase(long collageNo)
        {
            if (File.Exists(GlobalParams.BriefcasePath + @"Properties.daBriefcase"))   //does properties briefcase exists?

            {
                var propertiesBriefcase = new  FileBriefcase(GlobalParams.BriefcasePath + @"Properties.daBriefcase", true); //if yes ,return that briefcase(侯晨琛非要让我用英语注释)

                var fDataModule = new DataModule();                                                                         //新建briefcase的时候要下载班级表咯

                var bjTable = from c in fDataModule.GetBjTable()                                                            //获取数据
                              where c.XYID == collageNo
                              select c;

                var bjDataTable = EnumerableExtension.ListToDataTable(bjTable.ToList(), "BJTABLE"); //将班级表转换成datatable

                propertiesBriefcase.AddTable(bjDataTable);                                          //将班级表添加到briefcase中

                propertiesBriefcase.WriteBriefcase();

                return(propertiesBriefcase);//返回该briefcase
            }
            else
            {
                var propertiesBriefcase = new FileBriefcase(GlobalParams.BriefcasePath + @"Properties.daBriefcase"); //如果没有的话 那就新建一个briefcase

                var courseInfoTable = new DataTable("CourseInfo");                                                   //

                courseInfoTable.Columns.Add("课程名称", typeof(string));

                courseInfoTable.Columns.Add("课程编号", typeof(string));

                propertiesBriefcase.AddTable(courseInfoTable);   //新建一张表 表中存的是该平板中所有课程的信息 但表是空的.

                var fDataModule = new DataModule();              //新建briefcase的时候要下载班级表咯

                var bjTable = from c in fDataModule.GetBjTable() //获取班级表数据
                              where c.XYID == collageNo
                              select c;

                var bjDataTable = EnumerableExtension.ListToDataTable(bjTable.ToList(), "BJTABLE"); //将班级表转换成datatable

                propertiesBriefcase.AddTable(bjDataTable);                                          //将班级表添加到briefcase中

                propertiesBriefcase.WriteBriefcase();

                return(propertiesBriefcase);//返回该briefcase
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 刷新上课表 可用于下载数据时的操作.
        /// </summary>
        /// <param name="courseBriefcase">skno对应的Briefcase</param>
        /// <param name="sktableList">上课表对应的List</param>
        public static void RefreshClassInfoTable(FileBriefcase courseBriefcase, IEnumerable <SKTABLE_07_VIEW> sktableList)
        {
            var classInfoTable = courseBriefcase.FindTable("ClassInfo");

            classInfoTable.Rows.Clear();

            //以下注释的代码作为参考用.
            //courseInfoTable.Columns.Add ("上课编号", typeof (string));

            //courseInfoTable.Columns.Add ("上课日期", typeof (string));

            //courseInfoTable.Columns.Add ("上课状态", typeof (string));

            foreach (var sktable07Viewro in sktableList)
            {
                var viewro = sktable07Viewro;                                              //resharper说要这么写

                var classInfoRow = classInfoTable.NewRow();                                //新建一行

                classInfoRow["上课编号"] = viewro.SKNO.ToString(CultureInfo.InvariantCulture); //指定这一行的上课编号

                classInfoRow["上课日期"] = viewro.YDSKDATE.ToString();                         //指定这一行的上课日期

                if (viewro.SKZT == 0)                                                      //将上课状态转换成文字

                {
                    classInfoRow["上课状态"] = "未签到";
                }
                else
                {
                    classInfoRow["上课状态"] = "已签到";
                }

                classInfoTable.Rows.Add(classInfoRow); //将这一行加到datatable里
            }

            courseBriefcase.AddTable(classInfoTable); //将datatable加到briefcase里

            courseBriefcase.WriteBriefcase();
        }
Esempio n. 4
0
        private bool StartDownloadData(JSANDKKVIEWRO kktable05, string offlinePasswd) // 一门开课课程
        {
            ProgressHelper.StartProgressThread();                                     // 开始显示进度条
            Briefcase newBriefcase = new FileBriefcase(string.Format(
                                                           GlobalParams.CurrentOfflineDataFile,
                                                           kktable05.KKNO.ToString())); // 在内存中新建一个Briefcase 名字为该课程的开课编号

            ProgressHelper.SetProgress(5);                                              // 进度 百分之5
            DataTable classRecordTable = null;                                          // 一张上课表 对应每一节课
            DataRow   classRecordRow   = null;

            classRecordTable = new DataTable("ClassStatus");
            if (!classRecordTable.Columns.Contains("Table编号")) //这里算是一个BUG. 需要重新写.
            {
                classRecordTable.Columns.Add("Table编号", type: Type.GetType("System.String"));
                classRecordTable.Columns.Add("课次", type: Type.GetType("System.String"));
                classRecordTable.Columns.Add("签到情况", type: Type.GetType("System.String"));
                classRecordTable.Columns.Add("离线数据提交情况", type: Type.GetType("System.String"));
            }
            newBriefcase.Properties.Add(GlobalParams.PropertiesLastModified,
                                        DateTime.Now.ToString()); // 在briefcase中增加一个属性 用于记录最后一次更改的日期

            newBriefcase.Properties.Add(GlobalParams.PropertiesTeacherName,
                                        Properties.Settings.Default.UserName); //增加一个属性 用于记录教师姓名

            ProgressHelper.SetProgress(6);                                     // 进度 百分之6

            newBriefcase.Properties.Add(GlobalParams.PropertiesTeacherID,
                                        Properties.Settings.Default.UserId); // 增加一个属性 用于记录教师工号

            newBriefcase.Properties.Add(GlobalParams.PropertiesPasswd,
                                        offlinePasswd);//用于记录离线密码.

            newBriefcase.Properties.Add(GlobalParams.PropertiesClassName,
                                        kktable05.KKNAME);//增加一个属性 用于记录开课名称

            newBriefcase.Properties.Add(GlobalParams.PropertiesLastCheckin,
                                        "1");                       //用于记录最后一次考勤的节次

            ProgressHelper.SetProgress(10);                         //进度 百分之10
            newBriefcase.Properties.Add(GlobalParams.PropertiesTotalStudentNumber,
                                        kktable05.XXRS.ToString()); //增加一个属性 用于记录选学人数

            IQueryable <XKTABLE_VIEWRO> xktableView1s =
                from c in
                remoteDataAdapter.GetTable <XKTABLE_VIEWRO>() where c.KKNO == kktable05.KKNO
                select c;                   //构造LINQ语句 (选课表 XKTABLE_VIEWRO 学生信息)

            ProgressHelper.SetProgress(20); //进度 百分之15

            newBriefcase.AddTable(
                OfflineHelper.TableListToDataTable
                    (xktableView1s.ToList(), "XKTABLE_VIEW1"));
            // 将XKTABLE_VIEWRO(学生信息)放在briefcase里

            IQueryable <SKTABLE_07_VIEW> sktableView1s =
                from c in
                remoteDataAdapter.GetTable <SKTABLE_07_VIEW>()
                where c.KKNO == kktable05.KKNO && c.SKDATE > new DateTime(2014, 10, 14)
                select c;//SKTABLE_07_view为教师的上课表.教师选择完课程之后需要选择节次.

            //节次的来源即为该表. 一节课一条记录

            //将大于10月14号的数据下载下来 10月14日之后的数据都是正常的数据.
            //进度 百分之二十
            newBriefcase.AddTable(OfflineHelper.TableListToDataTable(sktableView1s.ToList(),
                                                                     "SKTABLE")); // 下载SKTABLE_07_VIEW 并将其添加进briefcase中 里面包含了课程的信息
            //百分之20
            ProgressHelper.SetProgress(20);

            foreach (var sktableView1 in sktableView1s)
            {                                                   //开始遍历上课表,并根据SKNO(上课编号) 获取每一节课对应的DMTABLE_08_NOPIC_VIEW
                Properties.Settings.Default.ProgressValue += 2; // 进度指示

                IQueryable <DMTABLE_08_NOPIC_VIEW> dmtable08S = // 构造LINQ语句 此处算法应改进
                                                                from c in
                                                                remoteDataAdapter.GetTable <DMTABLE_08_NOPIC_VIEW>() where  c.SKNO == sktableView1.SKNO
                                                                select c;//每一节课对应一张点名表

                newBriefcase.AddTable(
                    OfflineHelper.TableListToDataTable(dmtable08S.ToList(),
                                                       sktableView1.SKNO.ToString()));//将点名表加入briefcase

                classRecordRow = classRecordTable.NewRow();
                //在课程记录表中新建一行记录. 包含该节课是否已经签到的标记

                classRecordRow[0] = sktableView1.SKNO.ToString();   //上课编号
                classRecordRow[1] = sktableView1.SKDATE.ToString(); //上课时间
                if (sktableView1.SKZT == 0)                         //判断考勤状态 若已经完成考勤,则该堂课不能进行考勤工作.
                {
                    classRecordRow[2] = GlobalParams.DidNotSigned;
                    classRecordRow[3] = GlobalParams.NotSubmitYet;
                }
                else
                {
                    classRecordRow[2] = GlobalParams.Signed;
                    classRecordRow[3] = GlobalParams.Submitted;
                }
                classRecordTable.Rows.Add(classRecordRow); //将刚创建的这一行添加到表中.
            }
            ProgressHelper.SetProgress(80);                // 进度条

            newBriefcase.AddTable(classRecordTable);       // 将用于记录每节课的表放在briefcase中

            newBriefcase.WriteBriefcase();                 //保存briefcase到硬盘上

            Briefcase propertiesBriefcase =
                new FileBriefcase(GlobalParams.PropertiesBriefcaseName, true);//true代表提前读取数据

            DataTable propertiesTable =
                propertiesBriefcase.FindTable("PropertiesTable");
            //本地的打开properties表 向其中添加一条记录 properties表中包含了所有的已经离线的开课记录

            DataRow propertiesRow = null;                            //创建一个记录变量

            propertiesRow = propertiesTable.NewRow();                //new出来一条记录

            propertiesRow[0] = kktable05.KKNO.ToString();            //开课编号

            propertiesRow[1] = Properties.Settings.Default.UserName; //用户名

            propertiesRow[2] = kktable05.KKNAME;                     //开课名称

            DataRow[] dataRows =
                propertiesTable.Select("开课编号 = '" + kktable05.KKNO.ToString() + "'");
            //判断该课程是否已经添加进propertiestable中

            if (dataRows.Length >= 1) // propertiestable已经有了该课程
            {
                foreach (var dataRow in dataRows)
                {
                    dataRow.Delete();//删除该课程
                }

                propertiesTable.Rows.Add(propertiesRow);//添加该课程(更新)
            }
            else
            {
                propertiesTable.Rows.Add(propertiesRow);        //添加该课程(新增)
            }
            ProgressHelper.SetProgress(90);                     //设置进度条
            propertiesBriefcase.RemoveTable("PropertiesTable"); //移除propertiestable(必要的操作)

            propertiesBriefcase.AddTable(propertiesTable);      //添加propertiestable

            propertiesBriefcase.WriteBriefcase();               //写入更改

            ProgressHelper.SetProgress(100);                    //进度条显示100%

            ProgressHelper.StopProgressThread();                //停止显示进度条窗口

            ProgressHelper.SetProgress(0);                      //重置进度条窗口

            MessageBox.Show(string.Format("操作成功 课程 【{0}】 已被下载 ",
                                          kktable05.KKNAME));//弹窗提示

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// 将服务器的数据离线至本地
        /// todo:老版本函数 需要重点测试
        /// </summary>
        /// <param name="offlinePasswd"></param>
        /// <param name="checkedItem"></param>
        public void ServerToBriefcase
            (string offlinePasswd, CheckedListBox.SelectedObjectCollection checkedItem)
        {
            //int i = 0;// 用于显示进度条 已废弃

            foreach (var jsandkktable05S in this.Context.JSANDKKVIEWRO)
            {
                try
                {
                    bool flag = false;
                    foreach (JSANDKKVIEWRO jsandkkItem in checkedItem)
                    {
                        flag = (jsandkktable05S.KKNO == jsandkkItem.KKNO);
                    }
                    if (!flag)
                    {
                        continue;        // 判断该课程是否选中
                    }
                    if (
                        !File.Exists(
                            string.Format(GlobalParams.CurrentOfflineDataFile, jsandkktable05S.KKNO.ToString()) +
                            ".daBriefcase"))
                    {
                                             // 判断当前下载课程是否存在
                        {
                            StartDownloadData(jsandkktable05S, offlinePasswd);
                            //i++;
                        }
                    }
                    else
                    {
                        DialogResult dr =
                            MessageBox.Show("课程“" + jsandkktable05S.KKNAME + "”的离线数据存在,要刷新离线数据吗?\n未提交的更改将会被删除",
                                            "刷新本地离线数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                        if (dr != DialogResult.OK)
                        {
                            continue;
                        }
                        DialogResult dr2 = MessageBox.Show("真的确定吗,未提交的数据将被永久删除", "刷新本地离线数据", MessageBoxButtons.OKCancel,
                                                           MessageBoxIcon.Question);
                        if (dr2 != DialogResult.OK)
                        {
                            continue;
                        }
                        File.Delete(
                            string.Format(GlobalParams.CurrentOfflineDataFile, jsandkktable05S.KKNO.ToString()) +
                            ".daBriefcase");
                        StartDownloadData(jsandkktable05S, offlinePasswd); // 开始下载课程
                        //i++;
                    }
                }
                catch (Exception exception)
                {
                    ProgressHelper.StopProgressThread();
                    ProgressHelper.SetProgress(0);
                    MessageBox.Show(exception.Message);
                }
                finally
                {
                    ProgressHelper.StopProgressThread();
                }
            }
            //判断班级表是否被下载 如果没下载 下载之
            Briefcase propertiesBriefcase = new FileBriefcase(GlobalParams.PropertiesBriefcaseName, true);
            DataTable classNameTable      = null;


            IQueryable <BJTABLE_09_VIEWRO> bjtable09Viewros =
                from c in this.remoteDataAdapter.GetTable <BJTABLE_09_VIEWRO>() select c;

            this.Context.BJTABLE_09_VIEWRO = bjtable09Viewros.ToList();

            classNameTable = OfflineHelper.TableListToDataTable(bjtable09Viewros.ToList(), "ClassNameTable");

            propertiesBriefcase.AddTable(classNameTable);
            propertiesBriefcase.WriteBriefcase();

            //return i;
        }
Esempio n. 6
0
        /// <summary>
        /// 用于下载数据时 briefcase的创建
        /// 在确认下载数据后, 该函数会自动在properties briefcase中创建一条记录.
        /// </summary>
        /// <param name="kkrecord">一条开课记录</param>
        /// <returns></returns>
        public static FileBriefcase CreateBriefcase(JSANDKKVIEWRO kkrecord)
        {
            DialogResult dialogresault;

            if (File.Exists(GlobalParams.BriefcasePath + kkrecord.KKNO + @".daBriefcase"))   // 判断briefcase是否存在

            {
                dialogresault = new ConfirmBox("选定的课程 " + kkrecord.KKNAME + " 已经存在,\n还要下载该课程吗?").ShowDialog();

                if (dialogresault == DialogResult.Cancel)
                {
                    return(null);
                }

                dialogresault = new ConfirmBox("真的要下载该课程吗? \n未保存的数据将会被删除.").ShowDialog();

                if (dialogresault == DialogResult.Cancel)
                {
                    return(null);
                }

                dialogresault = new SetOfflinePasswdForm().ShowDialog(); // 显示离线密码框 指定离线密码

                if (dialogresault == DialogResult.Cancel)                // 如果用户点击取消的话

                {
                    return(null);//返回null 在调用的位置需要进行判定.如果为null 则不下载课程
                }//离线密码存在 Properties.Settings.Default.OffliePassword 里面.

                File.Move(GlobalParams.BriefcasePath + kkrecord.KKNO + @".daBriefcase",
                          GlobalParams.BriefcasePath + kkrecord.KKNO + @".daBriefcase" + DateTime.Now.ToString("yyyymmmmddhhmmss")); // 若存在 则重命名该briefcase.
            }
            else
            {
                dialogresault = new SetOfflinePasswdForm().ShowDialog(); // 显示离线密码框 指定离线密码

                if (dialogresault == DialogResult.Cancel)                // 如果用户点击取消的话

                {
                    return(null);//返回null 在调用的位置需要进行判定.如果为null 则不下载课程
                }//离线密码存在 Properties.Settings.Default.OffliePassword 里面.
            }



            var briefcaseToReturn = new FileBriefcase(GlobalParams.BriefcasePath + kkrecord.KKNO + @".daBriefcase");

            //返回的briefcase内为该门课程所有的数据 包括点名表 上课表 学生信息(选课表) 还有一个每节课信息(ClassStatus)

            //指定Briefcase的属性
            briefcaseToReturn.Properties.Add(GlobalParams.BpkCourseName, kkrecord.KKNAME);                                     // 开课课程名称

            briefcaseToReturn.Properties.Add(GlobalParams.BpkCourseNo, kkrecord.KKNO.ToString(CultureInfo.InvariantCulture));  //课程编号

            briefcaseToReturn.Properties.Add(GlobalParams.BpkLastModifiedDate, "N/A");                                         //最后一次签到时间

            briefcaseToReturn.Properties.Add(GlobalParams.BpkTeacherName, kkrecord.JSNAME);                                    //教师姓名

            briefcaseToReturn.Properties.Add(GlobalParams.BpkTeacherNo, kkrecord.JSID.ToString(CultureInfo.InvariantCulture)); // 教师编号

            briefcaseToReturn.Properties.Add(GlobalParams.BpkPassword, Properties.Settings.Default.OffliePassword);            //离线密码

            var classInfoTable = new DataTable("ClassInfo");

            // 里面应该存放每节课的信息. 该datatable应该放在对应课程的briefcase中 这个表是空的.将会在DataDownloadControl中对此表进行填充.

            classInfoTable.Columns.Add("上课编号", typeof(string));

            classInfoTable.Columns.Add("上课日期", typeof(string));

            classInfoTable.Columns.Add("上课状态", typeof(string));

            briefcaseToReturn.AddTable(classInfoTable); //添加上面创建的datatable

            briefcaseToReturn.WriteBriefcase();         //写入硬盘

            long xyid = Convert.ToInt64(kkrecord.XYID);

            var propertiesBriefcase = InitPropertiesBriefcase(xyid);
            //找出 properties briefcase 若properties不存在 该函数会自动创建一个propertiesbriefcase
            //xyid用于下载班级定义表用的.因此

            var courseInfoDataTable = propertiesBriefcase.FindTable("CourseInfo");            // 找到course info 表

            if (!courseInfoDataTable.Select("课程编号='" + kkrecord.KKNO.ToString() + "'").Any()) //如果之前没下载过该课程的话

            {
                var courseInfoTableRow = courseInfoDataTable.NewRow();                             //新建一行记录

                courseInfoTableRow["课程名称"] = kkrecord.KKNAME;                                      //添加课程名称

                courseInfoTableRow["课程编号"] = kkrecord.KKNO.ToString(CultureInfo.InvariantCulture); //添加课程编号

                courseInfoDataTable.Rows.Add(courseInfoTableRow);                                  //将新创建的一行加入课程信息表中

                propertiesBriefcase.AddTable(courseInfoDataTable);                                 //将课程信息存到Properties Briefcase中

                propertiesBriefcase.WriteBriefcase();                                              //写入更改
            }



            return(briefcaseToReturn);
        }