Пример #1
0
        protected String DoSaveStudentListAsExcel()
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);

            String prefix = "students_";
            int    numDel = DeleteOldReportFile(prefix);

            log.StampLine(Logger.INFO, "Delete old " + prefix + " " + numDel + " files");

            DateTime now     = DateTime.Now;
            String   dateStr = StringUtil.FillString(now.Ticks.ToString(), "0", 20, true) + "_"
                               + StringUtil.FillString(Session.GetHashCode().ToString(), "0", 10, true);

            String filename = prefix + dateStr + ".csv";
            String physPath = Config.PATH_APP_ROOT + "\\file\\" + filename;
            String urlPath  = "file/" + filename;

            FileStream fs     = File.Open(physPath, FileMode.OpenOrCreate, FileAccess.Write);
            TextWriter writer = new StreamWriter(fs, System.Text.Encoding.UTF8);

            StringBuilder stdTxt = new StringBuilder();

            //stdTxt.Append(StringUtil.GetExcelEncodingPrefix());

            stdTxt.Append("รหัส,ชื่อ-นามสกุล, ชื่อเล่น,เพศ,วันเกิด,รหัสบัตรประชาชน,ที่อยู่,อีเมล์,โทร., โรงเรียน, ชั้น, วันที่สร้าง, สถานะ \n");

            String[,] students = LoadStudentList(db);
            for (int i = 0; i < students.Length / 14; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    stdTxt.Append(StringUtil.AddCSVDQuote(students[i, j]) + ",");
                }
                stdTxt.AppendLine("");

                if (i % 100 == 99)
                {
                    writer.Write(stdTxt);
                    stdTxt = new StringBuilder();
                }
            }
            if (stdTxt.Length > 0)
            {
                writer.Write(stdTxt);
            }

            writer.Close();

            return(urlPath);
        }
Пример #2
0
        protected String DoSaveStudentListAsExcel(string courseID)
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);

            theCourse           = new Course();
            theCourse._courseID = Int32.Parse(courseID);
            theCourse.LoadFromDB(db);

            String prefix = "course_students_";
            int    numDel = DeleteOldReportFile(prefix);

            log.StampLine(Logger.INFO, "Delete old " + prefix + " " + numDel + " files");

            DateTime now     = DateTime.Now;
            String   dateStr = StringUtil.FillString(now.Ticks.ToString(), "0", 20, true) + "_"
                               + StringUtil.FillString(Session.GetHashCode().ToString(), "0", 10, true);

            String filename = prefix + dateStr + ".csv";
            String physPath = Config.PATH_APP_ROOT + "\\file\\" + filename;
            String urlPath  = "file/" + filename;

            FileStream fs     = File.Open(physPath, FileMode.OpenOrCreate, FileAccess.Write);
            TextWriter writer = new StreamWriter(fs, System.Text.Encoding.UTF8);

            StringBuilder stdTxt = new StringBuilder();

            /*
             *
             * Encoding tis620 = Encoding.GetEncoding("tis-620");
             * Encoding utf8 = Encoding.UTF8;
             *
             * Encoding encFrom = Encoding.Unicode;
             * Encoding encTo = Encoding.UTF8;
             *
             *
             * String unicodeString = "รหัสชีวิต";
             * // Convert the string into a byte[].
             * byte[] unicodeBytes = encFrom.GetBytes(unicodeString);
             *
             * // Perform the conversion from one encoding to the other.
             * byte[] asciiBytes = Encoding.Convert(encFrom, encTo, unicodeBytes);
             *
             * // Convert the new byte[] into a char[] and then into a string.
             * // This is a slightly different approach to converting to illustrate
             * // the use of GetCharCount/GetChars.
             * char[] asciiChars = new char[encTo.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
             * encTo.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
             *
             * //         char[] unicodeChars = new char[encFrom.GetCharCount(unicodeBytes, 0, unicodeBytes.Length)];
             * //         encFrom.GetChars(unicodeBytes, 0, unicodeBytes.Length, unicodeChars, 0);
             *
             * //stdTxt.Append("ก");
             */
            /*
             * stdTxt.Append(asciiChars + "\n");
             * stdTxt.Append(unicodeString + "\n");
             * // stdTxt.Append(unicodeChars+"\n");
             * stdTxt.Append("คิดถึงจัง");*/

            //stdTxt.AppendLine((asciiString);
            //stdTxt.AppendLine(unicodeString);
            // รหัส,ชื่อ-นามสกุล,โรงเรียน,โทร.,อีเมล์,จำนวนเงิน,หมายเหตุ


            //stdTxt.Append(StringUtil.GetExcelEncodingPrefix());

            stdTxt.Append("รายชิ้อนักเรียนที่ลงทะเบียนคอร์ส " + theCourse._btsCourseID + " " + theCourse._courseName + "\n");
            stdTxt.Append("วันที่สมัคร,ชื่อ-นามสกุล,โรงเรียน,โทร.,อีเมล์,จำนวนเงิน, สถานะ, หมายเหตุ \n");

            String[,] students = LoadStudentList(db, courseID);
            for (int i = 0; i < students.Length / 9; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    stdTxt.Append(StringUtil.AddCSVDQuote(students[i, j]) + ",");
                }
                stdTxt.AppendLine("");

                if (i % 100 == 99)
                {
                    writer.Write(stdTxt);
                    stdTxt = new StringBuilder();
                }
            }
            if (stdTxt.Length > 0)
            {
                writer.Write(stdTxt);
            }

            writer.Close();

            return(urlPath);
        }
Пример #3
0
        protected String DoSaveDailyAsExcel()
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);

            String prefix = "registration_report_";
            int    numDel = DeleteOldReportFile(prefix);

            log.StampLine(Logger.INFO, "Delete old " + prefix + " " + numDel + " files");

            DateTime now     = DateTime.Now;
            String   dateStr = StringUtil.FillString(now.Ticks.ToString(), "0", 20, true) + "_"
                               + StringUtil.FillString(Session.GetHashCode().ToString(), "0", 10, true);

            String filename = prefix + dateStr + ".csv";
            String physPath = Config.PATH_APP_ROOT + "\\file\\" + filename;
            String urlPath  = "file/" + filename;

            FileStream fs     = File.Open(physPath, FileMode.OpenOrCreate, FileAccess.Write);
            TextWriter writer = new StreamWriter(fs, System.Text.Encoding.UTF8);

            StringBuilder stdTxt = new StringBuilder();

            //stdTxt.Append(StringUtil.GetExcelEncodingPrefix());
            //ลำดับ วันที่ เลขที่ใบเสร็จ นักเรียน โรงเรียน ระดับชั้น รหัสคอร์ส ชื่อคอร์ส ราคา วิธีการชำระ สถานะ หมายเหตุ ชื่อผู้สมัคร
            stdTxt.Append("รายงานสรุปยอดการลงทะเบียนประจำวันของสาขา " + branchName + "ตั้งแต่วันที่ " + StringUtil.ConvertYearToEng(startDate, "dd/MM/yyyy") + " ถึง " + StringUtil.ConvertYearToEng(startDate, "dd/MM/yyyy") + "\n");
            stdTxt.Append("ลำดับ, วันที่รับชำระเงิน, วันที่สมัคร, รหัสใบเสร็จ, รหัสนักเรียน, ชื่อ-นามสกุล, โรงเรียน, ระดับชั้น,รหัสคอร์ส, ชื่อคอร์ส,วันที่เริ่ม, วันที่สิ้นสุด, ราคาจ่าย, วิธีชำระเงิน, สถานะ, ผู้รับสมัคร, ประเภท  \n");

            // content
            for (int i = 0; i < reg.Length; i++)
            {
                //numPaidMethod[reg[i]._paidMethod]++;
                //sumCostByPaidMethod[reg[i]._paidMethod] += reg[i]._discountedCost;
                //sumAllCost += reg[i]._discountedCost;

                AppUser theUser = userAllMap[reg[i]._username];

                String courseStart = "-";
                String courseEnd   = "-";
                if (reg[i]._courseType == "คอร์สสด")
                {
                    courseStart = reg[i]._courseStart.ToString("dd/MM/yyyy", ci);
                    courseEnd   = reg[i]._courseEnd.ToString("dd/MM/yyyy", ci);
                }

                stdTxt.Append(i + 1);
                stdTxt.Append(", " + reg[i]._paiddate.ToString("dd/MM/yyyy", ci));
                stdTxt.Append(", " + reg[i]._regisdate.ToString("dd/MM/yyyy HH:mm", ci));
                stdTxt.Append(", " + reg[i].GetRegisTransactionID());
                stdTxt.Append(", " + Student.GetStudentID(reg[i]._studentID));
                stdTxt.Append(", " + StringUtil.AddCSVDQuote(reg[i]._studentFirstname + " " + reg[i]._studentSurname));
                stdTxt.Append(", " + StringUtil.AddCSVDQuote(reg[i]._studentSchool));
                stdTxt.Append(", " + StringUtil.AddCSVDQuote(StringUtil.ConvertEducateLevel(reg[i]._studentLevel)));
                stdTxt.Append(", " + reg[i]._btsCourseID);
                stdTxt.Append(", " + StringUtil.AddCSVDQuote(reg[i]._courseName));
                stdTxt.Append(", " + courseStart);
                stdTxt.Append(", " + courseEnd);
                stdTxt.Append(", " + reg[i]._discountedCost);
                stdTxt.Append(", " + Registration.GetPaidMethodText(reg[i]._paidMethod.ToString()));
                stdTxt.Append(", " + Registration.GetStatusText(reg[i]._status));
                stdTxt.Append(", " + StringUtil.AddCSVDQuote(theUser._firstname + " " + theUser._surname));
                stdTxt.Append(", " + reg[i]._courseType);
                stdTxt.Append("\n");

                if (i % 100 == 99)
                {
                    writer.Write(stdTxt);
                    stdTxt = new StringBuilder();
                }
            }
            if (stdTxt.Length > 0)
            {
                writer.Write(stdTxt);
            }

            writer.Close();

            return(urlPath);
        }