示例#1
0
        /// <summary>
        /// 出国成绩单加载
        /// </summary>
        /// <param name="strTmplName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public FlowDocument loadCGSorceDocument(string strTmplName, JObject data)
        {
            float   num = 0;
            JArray  ja;
            JArray  ja1;
            JObject ja2;

            try
            {
                FileStream xamlFile = new FileStream(strTmplName, FileMode.Open, FileAccess.Read);

                FlowDocument doc = XamlReader.Load(xamlFile) as FlowDocument;

                xamlFile.Dispose();

                JSONBLL jsonbll = new JSONBLL();

                jsonbll.jobjectDisassem(data, "array", out ja);//去一下Json层
                jsonbll.jobjectDisassem(data, "array_transcript", out ja1);
                //string strr = ja1[0].ToString();
                jsonbll.jsonToJobject(ja1[0].ToString(), out ja2);

                ja2.Add("length_of_schooling", data["length_of_schooling"].ToString());

                DateTime dt = DateTime.Parse(ja2["birthday"].ToString());
                ja2["birthday"] = dt.ToString("yyyy-MM-dd");
                dt = DateTime.Parse(ja2["startCollegeTime"].ToString());
                ja2["startCollegeTime"] = dt.ToString("yyyy-MM-dd");
                ja2.Add("UniversityEnglishName", data["UniversityEnglishName"].ToString());

                //jsonbll.jobjectDisassem(data, "array_transcript", out ja2);//去一下Json层

                if (ja2["sex"].ToString() == "男")
                {
                    ja2.Add("sexE", "Male");
                }
                else
                {
                    ja2.Add("sexE", "Female");
                }

                DateTime now = DateTime.Now;

                ja2.Add("printDate", now.ToString("yyyy/MM/dd"));

                TableRowGroup group      = doc.FindName("rowsDetails") as TableRowGroup;
                Style         styleCell  = doc.Resources["BorderedCell"] as Style;
                Style         styleCell1 = doc.Resources["BorderedCell1"] as Style;
                string        preyear    = "";

                //var nimabi = doc.FindName("section") as Section;

                int rowsnum = 0;

                for (int i = 0; i < ja.Count;)
                {
                    //var table= doc.FindName("table") as Table;
                    //table.DataContext = ja;
                    //选择行族
                    if (rowsnum >= 25 && rowsnum < 50)
                    {
                        group = doc.FindName("rowsDetails1") as TableRowGroup;
                    }
                    else if (rowsnum >= 50 && i < 75)
                    {
                        group = doc.FindName("rowsDetails2") as TableRowGroup;
                    }
                    else if (rowsnum >= 100)
                    {
                        group = doc.FindName("rowsDetails3") as TableRowGroup;
                    }
                    else if (i < 25)
                    {
                        group = doc.FindName("rowsDetails") as TableRowGroup;
                    }

                    string  a = ja[i].ToString();
                    JObject aa;
                    jsonbll.jsonToJobject(a, out aa);

                    //判读是否加学年
                    TableRow  row  = new TableRow();
                    TableCell cell = new TableCell(new Paragraph(new Run(" ")));

                    if (preyear == "" || preyear != aa["termYear"].ToString())
                    {
                        preyear    = aa["termYear"].ToString();
                        cell       = new TableCell(new Paragraph(new Run("Academic Year " + aa["termYear"].ToString() + "-" + (int.Parse(aa["termYear"].ToString()) + 1).ToString())));
                        cell.Style = styleCell1;
                        row.Cells.Add(cell);
                        group.Rows.Add(row);
                        rowsnum++;
                    }
                    //添加成绩
                    TableRow row1 = new TableRow();

                    cell       = new TableCell(new Paragraph(new Run(ja[i]["courseName"].ToString() + "\n" + ja[i]["englishName"].ToString())));
                    cell.Style = styleCell1;
                    row1.Cells.Add(cell);

                    cell       = new TableCell(new Paragraph(new Run((ja[i]["creditHour"].ToString()))));
                    num       += float.Parse((ja[i]["creditHourPoint"].ToString()));
                    cell.Style = styleCell;
                    row1.Cells.Add(cell);

                    cell       = new TableCell(new Paragraph(new Run(ja[i]["mark"].ToString())));
                    cell.Style = styleCell;
                    row1.Cells.Add(cell);

                    if ((ja[i]["termName"].ToString()).Length > 13)
                    {
                        cell       = new TableCell(new Paragraph(new Run("Resit")));
                        cell.Style = styleCell;
                        row1.Cells.Add(cell);
                    }
                    else
                    {
                        cell       = new TableCell(new Paragraph(new Run(" ")));
                        cell.Style = styleCell;
                        row1.Cells.Add(cell);
                    }
                    if (i + 1 < ja.Count)
                    {
                        string  a1 = ja[i + 1].ToString();
                        JObject aa1;
                        jsonbll.jsonToJobject(a1, out aa1);

                        if (preyear == "" || preyear != aa1["termYear"].ToString())
                        {
                            group.Rows.Add(row1);
                            rowsnum++;
                            i = i + 1;
                        }
                        else
                        {
                            cell       = new TableCell(new Paragraph(new Run(ja[i + 1]["courseName"].ToString() + "\n" + ja[i + 1]["englishName"].ToString())));
                            cell.Style = styleCell1;
                            row1.Cells.Add(cell);

                            cell       = new TableCell(new Paragraph(new Run((ja[i + 1]["creditHour"].ToString()))));
                            num       += float.Parse((ja[i]["creditHourPoint"].ToString()));
                            cell.Style = styleCell;
                            row1.Cells.Add(cell);

                            cell       = new TableCell(new Paragraph(new Run(ja[i + 1]["mark"].ToString())));
                            cell.Style = styleCell;
                            row1.Cells.Add(cell);

                            if ((ja[i + 1]["termName"].ToString()).Length > 13)
                            {
                                cell       = new TableCell(new Paragraph(new Run("Resit")));
                                cell.Style = styleCell;
                                row1.Cells.Add(cell);
                            }
                            else
                            {
                                cell       = new TableCell(new Paragraph(new Run(" ")));
                                cell.Style = styleCell;
                                row1.Cells.Add(cell);
                            }

                            group.Rows.Add(row1);
                            rowsnum++;
                            i = i + 2;
                        }
                    }
                }

                //分页管理

                if (rowsnum > 25)
                {
                    ja2.Add("pagenum", ja.Count / 50 + 1);
                }
                else
                {
                    ja2.Add("pagenum", 1);
                }
                if (rowsnum / 25 == 2 && rowsnum > 50)
                {
                    doc.Blocks.Remove(doc.FindName("section3") as Section);
                }
                else if (rowsnum / 25 == 1 && rowsnum > 25)
                {
                    doc.Blocks.Remove(doc.FindName("section2") as Section);
                    doc.Blocks.Remove(doc.FindName("section3") as Section);
                }
                else if (rowsnum / 25 == 0 || rowsnum == 25)
                {
                    doc.Blocks.Remove(doc.FindName("section1") as Section);
                    doc.Blocks.Remove(doc.FindName("section2") as Section);
                    doc.Blocks.Remove(doc.FindName("section3") as Section);
                }
                ja2.Add("passedCredits", num);

                doc.DataContext = ja2;

                return(doc);
            }
            catch (Exception ex)
            {
                messgeBoxBll.Show("模板加载出错", ex.Message);
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// 成绩单加载
        /// </summary>
        /// <param name="strTmplName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public FlowDocument loadSorceDocument(string strTmplName, JObject data)
        {
            int    num = 0;
            JArray ja;

            try
            {
                FileStream xamlFile = new FileStream(strTmplName, FileMode.Open, FileAccess.Read);

                FlowDocument doc = XamlReader.Load(xamlFile) as FlowDocument;

                xamlFile.Dispose();

                JSONBLL jsonbll = new JSONBLL();

                string          birth     = data["birthday"].ToString();
                System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
                DateTime        dt        = startTime.AddMilliseconds(long.Parse(birth));
                data["birthday"] = dt.ToString("yyyy/MM/dd");
                jsonbll.jobjectDisassem(data, "scores", out ja);//去一下Json层


                DateTime now = DateTime.Now;

                data.Add("printDate", now.ToString("yyyy/MM/dd"));

                TableRowGroup group      = doc.FindName("rowsDetails") as TableRowGroup;
                Style         styleCell  = doc.Resources["BorderedCell"] as Style;
                Style         styleCell1 = doc.Resources["BorderedCell1"] as Style;

                foreach (var item in ja)
                {
                    if (num >= 45 && num < 90)
                    {
                        group = doc.FindName("rowsDetails1") as TableRowGroup;
                    }
                    else if (num >= 90 && num < 135)
                    {
                        group = doc.FindName("rowsDetails2") as TableRowGroup;
                    }
                    else if (num < 45)
                    {
                        group = doc.FindName("rowsDetails") as TableRowGroup;
                    }

                    string  a = item.ToString();
                    JObject aa;
                    jsonbll.jsonToJobject(a, out aa);

                    TableRow row = new TableRow();

                    TableCell cell = new TableCell(new Paragraph(new Run(" ")));
                    //cell.Style = styleCell1;
                    //row.Cells.Add(cell);
                    cell       = new TableCell(new Paragraph(new Run(aa["year_name"].ToString())));
                    cell.Style = styleCell1;
                    row.Cells.Add(cell);

                    group.Rows.Add(row);

                    num++;

                    JArray ja1;
                    jsonbll.jobjectDisassem(aa, "year_score", out ja1);//去一下Json层
                    for (int i = 0; i < ja1.Count;)
                    {
                        JObject jo1, jo2;
                        string  str1 = ja1[i].ToString();
                        jsonbll.jsonToJobject(str1, out jo1);

                        TableRow row1 = new TableRow();

                        cell       = new TableCell(new Paragraph(new Run(jo1["course_name"].ToString())));
                        cell.Style = styleCell1;
                        row1.Cells.Add(cell);

                        cell       = new TableCell(new Paragraph(new Run(jo1["credit_hour"].ToString())));
                        cell.Style = styleCell;
                        row1.Cells.Add(cell);

                        cell       = new TableCell(new Paragraph(new Run(jo1["course_type"].ToString())));
                        cell.Style = styleCell;
                        row1.Cells.Add(cell);

                        cell       = new TableCell(new Paragraph(new Run(jo1["mark"].ToString())));
                        cell.Style = styleCell;
                        row1.Cells.Add(cell);

                        cell       = new TableCell(new Paragraph(new Run("")));
                        cell.Style = styleCell;
                        row1.Cells.Add(cell);

                        if (i + 1 < ja1.Count)
                        {
                            string str2 = ja1[i + 1].ToString();
                            jsonbll.jsonToJobject(str2, out jo2);

                            cell       = new TableCell(new Paragraph(new Run(jo2["course_name"].ToString())));
                            cell.Style = styleCell1;
                            row1.Cells.Add(cell);

                            cell       = new TableCell(new Paragraph(new Run(jo2["credit_hour"].ToString())));
                            cell.Style = styleCell;
                            row1.Cells.Add(cell);

                            cell       = new TableCell(new Paragraph(new Run(jo2["course_type"].ToString())));
                            cell.Style = styleCell;
                            row1.Cells.Add(cell);

                            cell       = new TableCell(new Paragraph(new Run(jo2["mark"].ToString())));
                            cell.Style = styleCell;
                            row1.Cells.Add(cell);

                            cell       = new TableCell(new Paragraph(new Run("")));
                            cell.Style = styleCell;
                            row1.Cells.Add(cell);
                        }
                        group.Rows.Add(row1);
                        num++;

                        if (num > 45 && num < 90)
                        {
                            group = doc.FindName("rowsDetails1") as TableRowGroup;
                        }
                        else if (num >= 90 && num < 135)
                        {
                            group = doc.FindName("rowsDetails2") as TableRowGroup;
                        }
                        else if (num < 45)
                        {
                            group = doc.FindName("rowsDetails") as TableRowGroup;
                        }

                        i = i + 2;
                    }
                }
                //分页管理

                if (num > 45)
                {
                    data.Add("pagenum", num / 45 + 1);
                }
                else
                {
                    data.Add("pagenum", 1);
                }

                if (num / 45 == 1 && num > 45)
                {
                    doc.Blocks.Remove(doc.FindName("table2") as Section);
                }
                else if (num / 45 == 0 || num == 45)
                {
                    doc.Blocks.Remove(doc.FindName("table1") as Section);
                    doc.Blocks.Remove(doc.FindName("table2") as Section);
                }

                doc.DataContext = data;

                return(doc);
            }
            catch (Exception ex)
            {
                messgeBoxBll.Show("模板加载出错", ex.Message);
                return(null);
            }
        }