Esempio n. 1
0
        public FormTableViewer getCoursesSumUpViewer(string table)
        {
            SqlCeResultSet r = db.Select(string.Format
                                             ("SELECT [{0}].st_id, students.name, [{0}].mark FROM [{0}], students WHERE [{0}].st_id = students.st_id", table));
            FormTableViewer viewer = new FormTableViewer();

            viewer._MMHostForm = this;
            viewer.MdiParent   = this;
            viewer.Text        = string.Format("{0} {1} {2}", viewer.Text,
                                               table, db.GetTip("co_id", int.Parse(table.Substring(("co_sta_").Length))));
            viewer.grid.DataSource = r;
            FormTableViewerTag tag = new FormTableViewerTag(db, Database.Tables.CoursesSumUp);

            tag.expand                    = table;
            viewer.Tag                    = tag;
            viewer.grid.DataError        += new DataGridViewDataErrorEventHandler(grid_DataError);
            viewer.grid.CellValueChanged += new DataGridViewCellEventHandler(grid_CellValueChanged);
            string[] caption = db.TableCaptions(Database.Tables.CoursesSumUp);
            if (caption.Length == viewer.grid.Columns.Count)
            {
                for (int i = 0; i < viewer.grid.Columns.Count; i++)
                {
                    viewer.grid.Columns[i].HeaderText = caption[i];
                }
            }
            return(viewer);
        }
Esempio n. 2
0
 private void tablesToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     try
     {
         object table = Enum.Parse(MM.Database.Tables.NULL.GetType(), e.ClickedItem.ToolTipText.Substring(1), true);
         if (table is MM.Database.Tables)
         {
             FormTableViewer    viewer = getViewer((MM.Database.Tables)table);
             FormTableViewerTag tag    = new FormTableViewerTag(db, (MM.Database.Tables)table);
             viewer.Tag = tag;
             viewer.Init();
             viewer.Show();
         }
     }
     catch (ArgumentException) { }
     catch (NullReferenceException) { }
 }
Esempio n. 3
0
        public FormTableViewer getViewer(GiangManh.MM.Database.Tables table)
        {
            string sql = "SELECT * FROM {0} ";

            switch (table)
            {
            case Database.Tables.Marks:
                sql += "ORDER BY st_id";
                break;

            case Database.Tables.Students:
                sql += "ORDER BY gr_id ASC, no ASC";
                break;
            }
            SqlCeResultSet  r      = db.Select(string.Format(sql, table));
            FormTableViewer viewer = new FormTableViewer();

            viewer._MMHostForm     = this;
            viewer.MdiParent       = this;
            viewer.Text            = string.Format("{0} {1}", viewer.Text, table);
            viewer.grid.DataSource = r;
            FormTableViewerTag tag = new FormTableViewerTag(db, table);

            tag.expand                    = string.Format("{0}", table);
            viewer.Tag                    = tag;
            viewer.grid.DataError        += new DataGridViewDataErrorEventHandler(grid_DataError);
            viewer.grid.CellValueChanged += new DataGridViewCellEventHandler(grid_CellValueChanged);
            string[] caption = db.TableCaptions(table);
            if (caption.Length == viewer.grid.Columns.Count)
            {
                for (int i = 0; i < viewer.grid.Columns.Count; i++)
                {
                    viewer.grid.Columns[i].HeaderText = caption[i];
                }
            }
            return(viewer);
        }
Esempio n. 4
0
        private void excelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormTableViewer activeViewer = this.ActiveMdiChild as FormTableViewer;

            if (activeViewer == null)
            {
                activeViewer = this._MMActiveForm as FormTableViewer;
            }
            if (activeViewer == null)
            {
                Utility.Miscellaneous.ErrorMessage("Vui lòng mở cửa sổ chứa bảo dữ liệu cần chuyển sang Excel\n" +
                                                   "trước khi vào mục này.\n");
                return;
            }
            FormTableViewerTag tag = activeViewer.Tag as FormTableViewerTag;

            if (tag == null)
            {
                MessageBox.Show("Bảng dữ liệu này chỉ có thể dùng Quick Report để đưa sang Excel");
                return;
            }
            string title = "";

            switch (tag.Table)
            {
            case Database.Tables.CoursesSumUp:
                title = "BẢNG TỔNG KẾT ĐIỂM LỚP " + db.GetTip("co_id", int.Parse(tag.expand.Substring(("co_sta_").Length))); break;

            case Database.Tables.Courses:
                title = "DANH SÁCH PHÂN CÔNG GIẢNG DẠY"; break;

            case Database.Tables.Groups:
                title = "DANH SÁCH CÁC LỚP"; break;

            case Database.Tables.Marks:
                title = "BẢNG ĐIỂM LỚN"; break;

            case Database.Tables.Students:
                title = "DANH SÁCH HỌC SINH"; break;

            case Database.Tables.Teachers:
                title = "DANH SÁCH GIÁO VIÊN"; break;
            }
            SaveFileDialog saveFileDlg = new SaveFileDialog();

            saveFileDlg.Filter   = "Excel XML Document |*.excel.xml";
            saveFileDlg.FileName = string.Format("{0} {1}", tag.Table, DateTime.Today.ToString("dd-MM-yyyy"));
            saveFileDlg.SupportMultiDottedExtensions = true;
            saveFileDlg.Title = "Xuat bang du lieu sang Excel";
            if (saveFileDlg.ShowDialog() == DialogResult.OK)
            {
                StreamWriter sw = null;
                try
                {
                    sw = new StreamWriter(saveFileDlg.OpenFile());
                    if (tag.Table == Database.Tables.CoursesSumUp)
                    {
                        sw.Write(tag.Db.ExportExcelXml(tag.expand,
                                                       string.Format
                                                           ("SELECT [{0}].st_id, students.name, [{0}].mark FROM [{0}],"
                                                           + "students WHERE [{0}].st_id = students.st_id", tag.expand),
                                                       title));
                    }
                    else
                    {
                        sw.Write(tag.Db.ExportExcelXml(tag.Table.ToString(), string.Empty, title));
                    }
                    sw.Flush();
                    if (Utility.Miscellaneous.Confirm
                            ("Đã lưu xong:\n" + saveFileDlg.FileName + "\nBạn có muốn mở xem thử không?"))
                    {
                        System.Diagnostics.Process.Start(saveFileDlg.FileName);
                    }
                }
                catch (Exception ex)
                {
                    Utility.Miscellaneous.ErrorMessage("Có lỗi khi lưu kết quả\n" + ex.Message);
                }
                finally { if (sw != null)
                          {
                              sw.Close();
                          }
                }
            }
        }
Esempio n. 5
0
        private void textInfo_Leave(object sender, EventArgs e)
        {
            if (textInfo.Text == string.Empty)
            {
                return;
            }
            FormTableViewerTag tag = this.Tag as FormTableViewerTag;
            SqlCeCommand       cmd = new SqlCeCommand();

            if (tag == null)
            {
                return;
            }
            string[] p = null;
            if (textInfo.Text.IndexOf(',') == -1)
            {
                p = new string[] { textInfo.Text }
            }
            ;
            else
            {
                p = textInfo.Text.Split(',');
            }
            try
            {
                switch (tag.Table)
                {
                case Database.Tables.Groups:
                    if (p.Length == 2)
                    {
                        tag.Db.SelectNonQuery("INSERT INTO groups (gr_id, name) VALUES(" + p[0] + ",'" + p[1] + "')");
                    }
                    break;

                case Database.Tables.Students:
                    if (p.Length >= 1 && id_selected != -1)
                    {
                        tag.Db.SelectNonQuery
                            (string.Format("INSERT INTO students (name,gr_id,birth) VALUES('{0}',{1},'{2}')",
                                           Utility.Miscellaneous.ValidName(p[0]), id_selected, p.Length == 2 ? p[1] : ""));
                    }
                    break;

                case Database.Tables.Marks:
                    if (p.Length >= 1)
                    {
                        if (id_selected == -1)
                        {
                            MessageBox.Show("Vui lòng chọn một \"mục báo giảng\" trước khi nhập điểm.");
                            return;
                        }
                        double mark = double.Parse(p[0]);
                        if (mark > 10)
                        {
                            mark = mark / 10;
                        }

                        if (p.Length >= 2)
                        {
                            last_no = int.Parse(p[1]) - 1;
                        }
                        else
                        {
                            last_no++;
                        }
                        cmd.Connection  = tag.Db.Connection;
                        cmd.CommandText = "SELECT courses.gr_id FROM courses WHERE courses.co_id = " + id_selected;
                        int gr_id = (int)cmd.ExecuteScalar();
                        int st_id = tag.Db.GetStudentId(gr_id, last_no + 1);
                        cmd.CommandText =
                            string.Format("INSERT INTO marks (co_id,st_id,r,mark,date) VALUES({0},{1},{2},{3},'{4}')",
                                          id_selected,
                                          st_id,
                                          (p.Length == 3) ? last_r = int.Parse(p[2]) : last_r, mark,
                                          DateTime.Today.ToString("dd-MM-yyyy"));
                        ((FormMM)this.MdiParent).statusText.Text = "Bạn vừa vào điểm cho:  " + tag.Db.GetTip("st_id", st_id).TrimEnd();
                        cmd.ExecuteNonQuery();
                    }
                    break;

                case Database.Tables.Teachers:

                    if (p.Length >= 1)
                    {
                        string name    = Utility.Miscellaneous.ValidName(p[0]);
                        string subject = p.Length == 2? p[1]:string.Empty;
                        Database.SUBJECTS_ABBR abbr;
                        try
                        {
                            abbr = (Database.SUBJECTS_ABBR)
                                   Enum.Parse(Database.SUBJECTS_ABBR.NONE.GetType(), subject, true);
                            subject = Database.subjects[(int)abbr];
                        }
                        catch (ArgumentException) { abbr = Database.SUBJECTS_ABBR.NONE; subject = string.Empty; };
                        tag.Db.SelectNonQuery("INSERT INTO teachers(name, subject) VALUES ('"
                                              + name + "','" + subject + "')");
                    }
                    break;

                case Database.Tables.Courses:
                    break;
                }
                textInfo.Text = string.Empty;
                textInfo.Focus();
                grid_refresh();
            }
            catch (Exception ex) { System.Media.SystemSounds.Exclamation.Play(); }
        }
Esempio n. 6
0
        public void Init()
        {
            tag = this.Tag as FormTableViewerTag;
            if (tag == null)
            {
                return;
            }

            switch (tag.Table)
            {
            case Database.Tables.Teachers:
                toolTipText += "Gõ <Họ và tên> <Môn dạy viết tắt>";
                toolTipText += "Bảng các môn viết tắt như sau:\n" +
                               @" Toán      T-TO
  Vật lý    L-LY-LI
  Hóa học   H-HO 
  Ngữ văn   V-VA 
  Lịch sử   S-SU 
  Địa lý    D-DI 
  Công nghệ CO-CN       
  Tin học   TI 
  Tiếng Anh A-AN 
  Mỹ thuật  M-MI-MY
  Âm nhạc   AM 
  GDCD      GD-GI 
  Sinh học  SI-SH 
  Thể dục   TH-TD 
  Ngoại ngữ NN";
                ToolStripMenuItem reportPersonalNotebook = new ToolStripMenuItem("Lập sổ điểm cá nhân");
                reportPersonalNotebook.Click += new EventHandler(reportPersonalNotebook_Click);
                toolMore.DropDownItems.Add(reportPersonalNotebook);
                break;

            case Database.Tables.Groups:
                toolTipText += "Gõ <Lớp ID>, <Tên lớp> ";
                ToolStripMenuItem generateGroupCodeTool = new ToolStripMenuItem();
                generateGroupCodeTool.Text   = "Tạo mã lớp";
                generateGroupCodeTool.Click += new EventHandler(generateGroupCodeTool_Click);
                toolMore.DropDownItems.Add(generateGroupCodeTool);
                break;

            case Database.Tables.Students:
                toolTipText += "Gõ <Họ tên> (không cần viết hoa) hoặc <Họ tên>, <Ngày sinh>";
                object[] _gr   = tag.Db.GetGroupsList();
                string[] gr    = (string[])_gr[0];
                int[]    gr_id = (int[])_gr[1];
                for (int i = 0; i < gr.Length; i++)
                {
                    ToolStripMenuItem item = new ToolStripMenuItem(gr[i]);
                    item.Tag = gr_id[i];
                    dropdown.DropDownItems.Add(item);
                }
                ToolStripMenuItem reorderStudentNo = new ToolStripMenuItem("Sắp xếp HS và điền thứ tự");
                reorderStudentNo.Click += new EventHandler(reorderStudentNo_Click);
                ToolStripMenuItem addStudentFromExcel = new ToolStripMenuItem("Lấy danh sách lớp từ Excel");
                addStudentFromExcel.Click += new EventHandler(addStudentFromExcel_Click);
                toolMore.DropDownItems.Add(reorderStudentNo);
                toolMore.DropDownItems.Add(addStudentFromExcel);
                break;

            case Database.Tables.Marks:
                toolTipText += "Gõ <Điểm>, <Thứ tự>, <Hệ số>\n hoặc <Điểm>, <Thứ tự>,\n " +
                               "hoặc <Điểm>.\n Thứ tự và hệ số của lần trước đó được ghi nhớ.\n" +
                               "Điểm thi có thể nhập dạng số nguyên hoặc như bình thường, VD 85 sẽ hiểu là 8.5\n" +
                               "Dấu phân cách phần thập phân luôn là dấu chấm (.)";
                try
                {
                    object[] _co   = tag.Db.GetCoursesList();
                    string[] co    = (string[])_co[0];
                    int[]    co_id = (int[])_co[1];
                    for (int i = 0; i < co.Length; i++)
                    {
                        ToolStripMenuItem item = new ToolStripMenuItem(co[i]);
                        item.Tag = co_id[i];
                        dropdown.DropDownItems.Add(item);
                    }
                }
                catch (Exception) { }
                ToolStripMenuItem importMark = new ToolStripMenuItem();
                importMark.Text   = "Nhập điểm từ Malyst Scan";
                importMark.Click += new EventHandler(importMark_Click);

                toolMore.DropDownItems.Add(importMark);
                break;

            case Database.Tables.Courses:
                //toolTipText += "Gõ <Lớp>\n hoặc <Lớp>,<GVID>\nHoặc <Lớp>,<GVID>,<Môn>.\nNội dung trước đó luôn được"
                //    + "ghi nhớ một cách tự động. Có thể nhập <Lớp ID> thay cho lớp, <Môn viết tắt> thay cho môn.";
                ToolStripMenuItem itemTeacher = new ToolStripMenuItem("Hiện thầy cô");
                itemTeacher.Tag = 1;
                dropdown.DropDownItems.Add(itemTeacher);
                ToolStripMenuItem itemGroup = new ToolStripMenuItem("Hiện lớp");
                itemGroup.Tag = 2;
                dropdown.DropDownItems.Add(itemGroup);
                ToolStripMenuItem itemSubject = new ToolStripMenuItem("Nhóm theo môn");
                itemSubject.Tag = 3;
                dropdown.DropDownItems.Add(itemSubject);

                ToolStripMenuItem testCoursesCompletion = new ToolStripMenuItem();
                testCoursesCompletion.Text        = "Kiểm tra điểm";
                testCoursesCompletion.ToolTipText = "Chọn các BGID cần kiểm tra";
                testCoursesCompletion.Click      += new EventHandler(testCoursesComplettion_Click);

                ToolStripButton staticsToolStripButton = new ToolStripButton("Tính điểm");
                staticsToolStripButton.Click += new EventHandler(staticsToolStripButton_Click);
                toolStrip1.Items.Add(staticsToolStripButton);
                ToolStripMenuItem importMark1 = new ToolStripMenuItem();
                importMark1.Text   = "Nhập điểm từ Malyst Scan";
                importMark1.Click += new EventHandler(importMark_Click);
                toolMore.DropDownItems.Add(importMark1);
                toolMore.DropDownItems.Add(testCoursesCompletion);

                grid.CellValueChanged += new DataGridViewCellEventHandler(grid_Courses_CellValueChanged);
                break;

            case Database.Tables.CoursesSumUp:
                break;
            }
            dropdown.DropDownItemClicked += new ToolStripItemClickedEventHandler(dropdown_DropDownItemClicked);
            textInfo.ToolTipText          = string.Empty;
        }