Exemplo n.º 1
0
        /// <summary>
        /// 输出模板到文件
        /// </summary>
        /// <param name="type"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static bool GetTemplate(string type, string filename)
        {
            var dt = GetTemplate(type);

            //new Thread(() => { CsvHelper.dt2csv(filename, dt); }).Start();
            return(CsvHelper.dt2csv(filename, dt));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取UUID列表
        /// </summary>
        /// <param name="type">类型:class,dept,major</param>
        /// <param name="filename">文件名</param>
        public static bool GetUUID(string type, string filename)
        {
            var dt = new DataTable();

            dt.Columns.Add("名称");
            dt.Columns.Add("UUID");
            switch (type)
            {
            case "class":    //班级UUID
                var bll_class = new BLL.t_class();
                var c_dt      = bll_class.GetAllList().Tables[0];
                if (c_dt == null)
                {
                    break;
                }
                foreach (DataRow item in c_dt.Rows)
                {
                    var dr = dt.NewRow();
                    dr["名称"]   = item["class_name"];
                    dr["UUID"] = item["class_id"];
                    dt.Rows.Add(dr);
                }
                break;

            case "dept":    //系别UUID
                var bll_dept = new BLL.t_dept();
                var d_dt     = bll_dept.GetAllList().Tables[0];
                if (d_dt == null)
                {
                    break;
                }
                foreach (DataRow item in d_dt.Rows)
                {
                    var dr = dt.NewRow();
                    dr["名称"]   = item["dept_name"];
                    dr["UUID"] = item["dept_id"];
                    dt.Rows.Add(dr);
                }
                break;

            case "major":    //专业UUID
                var bll_major = new BLL.t_major();
                var m_dt      = bll_major.GetAllList().Tables[0];
                if (m_dt == null)
                {
                    break;
                }
                foreach (DataRow item in m_dt.Rows)
                {
                    var dr = dt.NewRow();
                    dr["名称"]   = item["major_name"];
                    dr["UUID"] = item["major_id"];
                    dt.Rows.Add(dr);
                }
                break;
            }
            //new Thread(() => { CsvHelper.dt2csv(filename, dt); }).Start();
            return(CsvHelper.dt2csv(filename, dt));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 导出选题结果
        /// </summary>
        /// <param name="type">按条件导出:dept,major,class,teacher,select</param>
        /// <param name="parms">*id</param>
        /// <param name="filename">文件路径</param>
        public static bool ExportSelectResult(string type, string parms, string filename)
        {
            var bll = new BLL.v_select();
            var dt  = new DataTable();

            /// 获取数据
            switch (type)
            {
            case "dept":

                #region  系别导出

                dt.Columns.Add(new DataColumn("专业"));
                dt.Columns.Add(new DataColumn("班级"));
                dt.Columns.Add(new DataColumn("姓名"));
                dt.Columns.Add(new DataColumn("学号"));
                dt.Columns.Add(new DataColumn("导师"));
                dt.Columns.Add(new DataColumn("导师工号"));
                dt.Columns.Add(new DataColumn("所选题目"));
                var list_dept = bll.GetModelList(" select_stat=5 AND dept_id='" + parms + "'");
                if (list_dept.Count == 0)
                {
                    break;
                }
                foreach (var item in list_dept)
                {
                    var dr = dt.NewRow();
                    dr["专业"]   = item.major_name;
                    dr["班级"]   = item.class_name;
                    dr["姓名"]   = item.student_name;
                    dr["学号"]   = item.select_student_xh;
                    dr["导师"]   = item.teacher_name;
                    dr["导师工号"] = item.topic_teacher_gh;
                    dr["所选题目"] = item.topic_name;
                    dt.Rows.Add(dr);
                }

                #endregion  系别导出

                break;

            case "major":

                #region  专业导出

                dt.Columns.Add(new DataColumn("班级"));
                dt.Columns.Add(new DataColumn("姓名"));
                dt.Columns.Add(new DataColumn("学号"));
                dt.Columns.Add(new DataColumn("导师"));
                dt.Columns.Add(new DataColumn("导师工号"));
                dt.Columns.Add(new DataColumn("所选题目"));

                var list_major = bll.GetModelList(" select_stat=5 AND class_major_id='" + parms + "'");
                if (list_major.Count == 0)
                {
                    break;
                }
                foreach (var item in list_major)
                {
                    var dr = dt.NewRow();
                    dr["班级"]   = item.class_name;
                    dr["姓名"]   = item.student_name;
                    dr["学号"]   = item.select_student_xh;
                    dr["导师"]   = item.teacher_name;
                    dr["导师工号"] = item.topic_teacher_gh;
                    dr["所选题目"] = item.topic_name;
                    dt.Rows.Add(dr);
                }

                #endregion  专业导出

                break;

            case "class":

                #region  班级

                dt.Columns.Add(new DataColumn("姓名"));
                dt.Columns.Add(new DataColumn("学号"));
                dt.Columns.Add(new DataColumn("导师"));
                dt.Columns.Add(new DataColumn("导师工号"));
                dt.Columns.Add(new DataColumn("所选题目"));

                var list_class = bll.GetModelList(" select_stat=5 AND class_id='" + parms + "'");
                if (list_class.Count == 0)
                {
                    break;
                }
                foreach (var item in list_class)
                {
                    var dr = dt.NewRow();
                    dr["姓名"]   = item.student_name;
                    dr["学号"]   = item.select_student_xh;
                    dr["导师"]   = item.teacher_name;
                    dr["导师工号"] = item.topic_teacher_gh;
                    dr["所选题目"] = item.topic_name;
                    dt.Rows.Add(dr);
                }

                #endregion  班级

                break;

            case "teacher":

                #region  导师

                dt.Columns.Add(new DataColumn("专业"));
                dt.Columns.Add(new DataColumn("班级"));
                dt.Columns.Add(new DataColumn("姓名"));
                dt.Columns.Add(new DataColumn("学号"));
                dt.Columns.Add(new DataColumn("所选题目"));

                var list_teacher = bll.GetModelList(" select_stat=5 AND topic_teacher_gh='" + parms + "'");
                if (list_teacher.Count == 0)
                {
                    break;
                }
                foreach (var item in list_teacher)
                {
                    var dr = dt.NewRow();
                    dr["专业"]   = item.major_name;
                    dr["班级"]   = item.class_name;
                    dr["姓名"]   = item.student_name;
                    dr["学号"]   = item.select_student_xh;
                    dr["所选题目"] = item.topic_name;
                    dt.Rows.Add(dr);
                }

                #endregion  导师

                break;

            case "select":

                #region   题导出

                dt.Columns.Add(new DataColumn("专业"));
                dt.Columns.Add(new DataColumn("班级"));
                dt.Columns.Add(new DataColumn("姓名"));
                dt.Columns.Add(new DataColumn("学号"));

                var list_topic = bll.GetModelList(" select_stat=5 AND select_topic_id='" + parms + "'");
                if (list_topic.Count == 0)
                {
                    break;
                }
                foreach (var item in list_topic)
                {
                    var dr = dt.NewRow();
                    dr["专业"] = item.major_name;
                    dr["班级"] = item.class_name;
                    dr["姓名"] = item.student_name;
                    dr["学号"] = item.select_student_xh;
                    dt.Rows.Add(dr);
                }

                #endregion   题导出

                break;
            }

            /// 没有数据,添加提示信息
            if (dt.Rows.Count == 0)
            {
                var dr = dt.NewRow();
                dr[0] = "没有相关数据!";
                dt.Rows.Add(dr);
            }
            /// 写入文件
            return(CsvHelper.dt2csv(filename, dt));
        }