private void TKBLop_CellBeginEdit(object sender, DevExpress.XtraSpreadsheet.SpreadsheetCellCancelEventArgs e) { Cell cell = e.Cell; if (!cellMap.ContainsKey(cell.GetReferenceA1())) { return; } TietHoc tiet = cellMap[cell.GetReferenceA1()]; if (tiet.ngayNghi != null) { return; } //Nạp xlsx để xem chi tiết using (FileStream stream = new FileStream(@"tietViewer.xlsx", FileMode.Open)) { spreadsheetChiTiet.LoadDocument(stream, DocumentFormat.Xlsx); wbChiTiet = spreadsheetChiTiet.Document; wsChiTiet = wbChiTiet.Worksheets[0]; } Lop lop = new Lop(); lop.giangDuong = "0"; TietHocRendering render = new TietHocRendering(lop, 20); wsChiTiet["A1"].SetRichText(render.tietToRich(tiet, "hocKy", 12)); wsChiTiet.FreezePanes(0, 0); //Khoá ô hiển thị lblThu.Text = dateToThu(tiet.ngay.DayOfWeek.ToString()) + ", "; lblNgay.Text = "ngày " + tiet.ngay.ToString("dd/MM/yyyy"); int x = lblThu.Location.X + lblThu.Width - 10, y = lblNgay.Location.Y; lblNgay.Location = new Point(x, y); lblLop.Text = "Lớp: " + Lop.ten; lblTiet.Text = "Tiết: " + tiet.tiet; string[] arr = tiet.mon.ten.Split(new char[] { '|' }); string bai = tiet.bai == "" ? "Không nhập" : tiet.bai; lblMon.Text = "Môn: " + arr[0]; lblBai.Text = "Bài: " + bai; lblHinhThuc.Text = "Hình thức: " + tiet.hinhThuc; lblGiangDuong.Text = "Địa điểm: " + tiet.diaDiem; lblGiangVien.Text = tiet.giangViens == "" ? "GV: Không nhập" : "GV: " + tiet.giangViens; toolTip.RemoveAll(); toolTip.SetToolTip(lblLop, lblLop.Text); toolTip.SetToolTip(lblMon, "Môn học: " + arr[0]); toolTip.SetToolTip(lblGiangVien, tiet.giangViens == "" ? "Giảng viên: Không nhập" : "Giảng viên: " + tiet.giangViens); grpChiTiet.Visible = true; }
private void xlsxViewer_CellBeginEdit(object sender, DevExpress.XtraSpreadsheet.SpreadsheetCellCancelEventArgs e) { if (!isNewData) { return; } Cell cell = e.Cell; string sheetName = e.Worksheet.Name; Dictionary <string, TietHoc> map = (sheetName == "TKB d2,10,3") ? cellMap[0] : cellMap[1]; if (!map.ContainsKey(cell.GetReferenceA1())) { return; } //Nạp xlsx để xem chi tiết using (FileStream stream = new FileStream(@"tietViewer.xlsx", FileMode.Open)) { spreadsheetChiTiet.LoadDocument(stream, DocumentFormat.Xlsx); wbChiTiet = spreadsheetChiTiet.Document; wsChiTiet = wbChiTiet.Worksheets[0]; } TietHoc tiet = map[cell.GetReferenceA1()]; Lop lop = new Lop(); lop.giangDuong = "0"; TietHocRendering render = new TietHocRendering(lop, 20); wsChiTiet["A1"].SetRichText(render.tietToRich(tiet, "hocKy", 12)); wsChiTiet.FreezePanes(0, 0); //Khoá ô hiển thị lblThu.Text = dateToThu(tiet.ngay.DayOfWeek.ToString()) + ", "; lblNgay.Text = "ngày " + tiet.ngay.ToString("dd/MM/yyyy"); int x = lblThu.Location.X + lblThu.Width - 10, y = lblNgay.Location.Y; lblNgay.Location = new Point(x, y); string lops = "Lớp: " + tiet.lop.ten; int count = cell.GetMergedRanges().Count > 0 ? cell.GetMergedRanges()[0].ColumnCount : 1; if (count > 1) { for (int i = cell.ColumnIndex + 1; i < cell.ColumnIndex + count; i++) { lops += ", " + ws[6, i].Value; } } lblLop.Text = lops; lblTiet.Text = "Tiết: " + tiet.tiet; string[] arr = tiet.mon.ten.Split(new char[] { '|' }); string bai = tiet.bai == "" ? "Không nhập" : tiet.bai; lblMon.Text = "Môn: " + arr[0]; lblBai.Text = "Bài: " + bai; lblHinhThuc.Text = "Hình thức: " + tiet.hinhThuc; lblGiangDuong.Text = "Địa điểm: " + tiet.diaDiem; lblGiangVien.Text = tiet.giangViens == "" ? "Giảng viên: Không nhập" : "Giảng viên: " + tiet.giangViens; toolTip.RemoveAll(); toolTip.ShowAlways = true; toolTip.SetToolTip(lblLop, lops); toolTip.SetToolTip(lblMon, "Môn học: " + arr[0]); toolTip.SetToolTip(lblGiangVien, lblGiangVien.Text); grpChiTiet.Visible = true; }
private void MergeSameCells() { List <int> rows = new List <int>(new int[] { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38 }); int lim = getLimOfSheet(ws); rows.ForEach(r => { for (int c = 2; c < lim - 1; c++) //Kiểm từng ô trong hàng { TietHoc tiet1 = GetTietByCell(ws[r, c].GetReferenceA1()); if (tiet1 == null) { continue; } if (tiet1.ngayNghi != null) { continue; } List <TietHoc> tiets = new List <TietHoc>(); tiets.Add(tiet1); string value1 = tiet1.ToString(); bool khacNhau = false; bool trungGiangDuongGoc = true; for (int cc = c + 1; cc <= lim; cc++) { TietHoc tietSoSanh = GetTietByCell(ws[r, cc].GetReferenceA1()); if (tietSoSanh != null) { if (value1 == tietSoSanh.ToString()) { tiets.Add(tietSoSanh); } else { khacNhau = true; } } else { khacNhau = true; } if (khacNhau) { if (tiets.Count > 0) { //Có tiết trùng liền kề bool showGiangDuong = true; //So sánh giảng đường gốc của từng lớp string gd1 = tiets[0].lop.giangDuong; tiets.ForEach(tiet => { string gd2 = tiet.lop.giangDuong; if (gd1 != gd2) { trungGiangDuongGoc = false; } }); //nếu cả 3 cùng gđ gốc và giảng đường học = gđ gốc thì ko show. Còn lại các case khác thì show if (trungGiangDuongGoc && tiets[0].diaDiem == tiets[0].lop.giangDuong) { showGiangDuong = false; } TietHocRendering render; if (showGiangDuong) { Lop lopTemp = new Lop(); lopTemp.giangDuong = "0"; render = new TietHocRendering(lopTemp, main.sizeTuan); } else { render = new TietHocRendering(tiets[0].lop, main.sizeTuan); } //Gán lại giá trị ws[r, c].SetRichText(render.tietToRich(tiets[0], "tuan", main.sizeTuan)); //Merge ws.MergeCells(ws[ws[r, c].GetReferenceA1() + ":" + ws[r, c + tiets.Count - 1].GetReferenceA1()]); } c = cc - 1; break; } } } }); }