private void btnOK_Click(object sender, EventArgs e) { DentalClinicDataContext dataContext = new DentalClinicDataContext(); Staff staff = new Staff(); staff.StaffId = txtMaNVBS.Text; staff.fullName = txtTenNVBS.Text; staff.dateOfBirth = dtpkNgaySinh.Value; staff.PositionId = int.Parse(cbViTri.SelectedValue.ToString()); if (radioButton_Nam.Checked) { staff.gender = true; } if (radioButton_Nu.Checked) { staff.gender = true; } staff.address = txtDiaChi.Text; staff.phone = txtSoDienThoai.Text; staff.identityNumber = txtCMT.Text; staff.experience = txtKinhNghiem.Text; staff.email = txtEmail.Text; staff.certificateId = txtBangCap.Text; staff.note = txtGhiChu.Text; dataContext.Staffs.InsertOnSubmit(staff); dataContext.SubmitChanges(); click_CloseForm(sender, e); this.Close(); }
public Frm_AddThuoc() { InitializeComponent(); DentalClinicDataContext dental = new DentalClinicDataContext(); var type = from a in dental.TypeMedicines select new { a.TypeMedicineId, a.nameTypeOfMedicine }; cbLoaiThuoc.DataSource = type.ToList(); cbLoaiThuoc.DisplayMember = "nameTypeOfMedicine"; cbLoaiThuoc.ValueMember = "TypeMedicineId"; }
private void btnOk_Click(object sender, EventArgs e) { try { DentalClinicDataContext dentalClinic = new DentalClinicDataContext(); Service service = new Service(); service.ServiceId = txtDichVu.Text; service.nameService = txtTenDichVu.Text; service.price = decimal.Parse(txtGiaTien.Text); service.note = txtMoTa.Text; dentalClinic.Services.InsertOnSubmit(service); dentalClinic.SubmitChanges(); click_CloseForm(sender, e); this.Close(); } catch (Exception) { MessageBox.Show("Yêu cầu nhập đúng định dạng và không trùng !"); } }
private void button1_Click_1(object sender, EventArgs e) { try { DentalClinicDataContext dental = new DentalClinicDataContext(); Medicine medicine = new Medicine(); medicine.MedicineId = txtMaThuoc.Text; medicine.nameMedicine = txtTenThuoc.Text; medicine.quantity = int.Parse(txtSoLuong.Text); medicine.expirationDate = dtpkHanSuDung.Value; medicine.unit = txtDonViTinh.Text; medicine.TypeMedicineId = cbLoaiThuoc.SelectedValue.ToString(); medicine.price = decimal.Parse(txtDonGia.Text); dental.Medicines.InsertOnSubmit(medicine); dental.SubmitChanges(); click_CloseForm(sender, e); this.Close(); } catch (Exception) { MessageBox.Show("Yêu cầu nhập dúng định dạng!"); } }
public void XuatFile() { try { FolderBrowserDialog fl = new FolderBrowserDialog(); fl.SelectedPath = "c:\\windows\\system32";//co the lay duong dan tu file fl.ShowNewFolderButton = true; string saveExcelFile = ""; if (fl.ShowDialog() == DialogResult.OK) { saveExcelFile = fl.SelectedPath + "\\excel_report_Staff.xlsx"; } //string saveExcelFile = @"F:\excel_report_Staff.xlsx"; Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); if (xlApp == null) { MessageBox.Show("Lỗi không thể sử dụng được thư viện EXCEL"); return; } xlApp.Visible = false; object misValue = System.Reflection.Missing.Value; Workbook wb = xlApp.Workbooks.Add(misValue); Worksheet ws = (Worksheet)wb.Worksheets[1]; if (ws == null) { MessageBox.Show("Không thể tạo được WorkSheet"); return; } int row = 1; string fontName = "Times New Roman"; int fontSizeTieuDe = 18; int fontSizeTenTruong = 14; int fontSizeNoiDung = 12; //Xuất dòng Tiêu đề của File báo cáo: Lưu ý Range row1_TieuDe_NhanVien = ws.get_Range("A1", "L1"); row1_TieuDe_NhanVien.Merge(); row1_TieuDe_NhanVien.Font.Size = fontSizeTieuDe; row1_TieuDe_NhanVien.Font.Name = fontName; row1_TieuDe_NhanVien.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row1_TieuDe_NhanVien.Value2 = "Thống kê danh sách nhân viên/bác sĩ"; row1_TieuDe_NhanVien.RowHeight = 30; //Tạo Ô Số Thứ Tự (STT) Range row23_STT = ws.get_Range("A2", "A3");//Cột A dòng 2 và dòng 3 row23_STT.Merge(); row23_STT.Font.Size = fontSizeTenTruong; row23_STT.Font.Name = fontName; row23_STT.Cells.HorizontalAlignment = XlHAlign.xlHAlignCenter; row23_STT.Value2 = "STT"; //Tạo Ô Mã bệnh nhân : Range row23_MaNhanVien = ws.get_Range("B2", "B3");//Cột B dòng 2 và dòng 3 row23_MaNhanVien.Merge(); row23_MaNhanVien.Font.Size = fontSizeTenTruong; row23_MaNhanVien.Font.Name = fontName; row23_MaNhanVien.Cells.HorizontalAlignment = XlHAlign.xlHAlignCenter; row23_MaNhanVien.Value2 = "Mã Nhân Viên"; row23_MaNhanVien.ColumnWidth = 20; //Tạo Ô Tên bệnh nhân : Range row23_CMND = ws.get_Range("C2", "C3");//Cột C dòng 2 và dòng 3 row23_CMND.Merge(); row23_CMND.Font.Size = fontSizeTenTruong; row23_CMND.Font.Name = fontName; row23_CMND.Cells.HorizontalAlignment = XlHAlign.xlHAlignCenter; row23_CMND.ColumnWidth = 30; row23_CMND.Value2 = "Chứng Minh Nhân Dân"; Range row23_TenNhanVien = ws.get_Range("D2", "D3");//Cột C dòng 2 và dòng 3 row23_TenNhanVien.Merge(); row23_TenNhanVien.Font.Size = fontSizeTenTruong; row23_TenNhanVien.Font.Name = fontName; row23_TenNhanVien.Cells.HorizontalAlignment = XlHAlign.xlHAlignCenter; row23_TenNhanVien.ColumnWidth = 25; row23_TenNhanVien.Value2 = "Họ Và Tên"; //Tạo Ô Giới tính: Range row23_NgaySinh = ws.get_Range("E2", "E3");//Ô D3 row23_NgaySinh.Merge(); row23_NgaySinh.Font.Size = fontSizeTenTruong; row23_NgaySinh.Font.Name = fontName; row23_NgaySinh.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row23_NgaySinh.Value2 = "Ngày Sinh"; row23_NgaySinh.ColumnWidth = 26; //Tạo Ô SDT: Range row23_GioiTinh = ws.get_Range("F2", "F3");//Ô E3 row23_GioiTinh.Merge(); row23_GioiTinh.Font.Size = fontSizeTenTruong; row23_GioiTinh.Font.Name = fontName; row23_GioiTinh.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row23_GioiTinh.Value2 = "Giới Tính"; row23_GioiTinh.ColumnWidth = 12; //Tạo Ô Địa chỉ Range row23_DiaChi = ws.get_Range("G2", "G3");//Ô E3 row23_DiaChi.Merge(); row23_DiaChi.Font.Size = fontSizeTenTruong; row23_DiaChi.Font.Name = fontName; row23_DiaChi.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row23_DiaChi.Value2 = "Địa Chỉ"; row23_DiaChi.ColumnWidth = 50; //Tạo Ô ghi chú Range row23_SDT = ws.get_Range("H2", "H3");//Ô E3 row23_SDT.Merge(); row23_SDT.Font.Size = fontSizeTenTruong; row23_SDT.Font.Name = fontName; row23_SDT.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row23_SDT.Value2 = "Số Điện Thoại"; row23_SDT.ColumnWidth = 16; Range row23_KinhNghiem = ws.get_Range("I2", "I3");//Ô E3 row23_KinhNghiem.Merge(); row23_KinhNghiem.Font.Size = fontSizeTenTruong; row23_KinhNghiem.Font.Name = fontName; row23_KinhNghiem.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row23_KinhNghiem.Value2 = "Kinh Nghiệm"; row23_KinhNghiem.ColumnWidth = 20; //Tạo Ô email Range row23_Email = ws.get_Range("J2", "J3");//Ô E3 row23_Email.Merge(); row23_Email.Font.Size = fontSizeTenTruong; row23_Email.Font.Name = fontName; row23_Email.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row23_Email.Value2 = "Email"; row23_Email.ColumnWidth = 35; Range row23_Note = ws.get_Range("K2", "K3");//Ô E3 row23_Note.Merge(); row23_Note.Font.Size = fontSizeTenTruong; row23_Note.Font.Name = fontName; row23_Note.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row23_Note.Value2 = "Ghi Chú"; row23_Note.ColumnWidth = 50; Range row23_TrinhDo = ws.get_Range("L2", "L3");//Ô E3 row23_TrinhDo.Merge(); row23_TrinhDo.Font.Size = fontSizeTenTruong; row23_TrinhDo.Font.Name = fontName; row23_TrinhDo.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row23_TrinhDo.Value2 = "Trình Độ"; row23_TrinhDo.ColumnWidth = 25; //Tô nền vàng các cột tiêu đề: Range row23_CotTieuDe = ws.get_Range("A2", "L3"); //nền xám trắng row23_CotTieuDe.Interior.Color = ColorTranslator.ToOle(System.Drawing.Color.LightGray); //in đậm row23_CotTieuDe.Font.Bold = true; //chữ đen row23_CotTieuDe.Font.Color = ColorTranslator.ToOle(System.Drawing.Color.Black); int stt = 0; row = 3;//dữ liệu xuất bắt đầu từ dòng số 4 trong file Excel (khai báo 3 để vào vòng lặp nó ++ thành 4) DentalClinicDataContext context = new DentalClinicDataContext(); foreach (var sp in Cons.dataContext.Staffs) { stt++; row++; dynamic[] arr = { stt, sp.StaffId, sp.identityNumber, sp.fullName, sp.dateOfBirth.ToString(), sp.gender == true ? "Nam" : "Nữ", sp.address, sp.phone.ToString(), sp.experience, sp.email, sp.note, sp.certificateId }; Range rowData = ws.get_Range("A" + row, "L" + row);//Lấy dòng thứ row ra để đổ dữ liệu rowData.Font.Size = fontSizeNoiDung; rowData.Font.Name = fontName; rowData.Value2 = arr; } //Kẻ khung toàn bộ BorderAround(ws.get_Range("A2", "L" + row)); //Lưu file excel xuống Ổ cứng wb.SaveAs(saveExcelFile); //đóng file để hoàn tất quá trình lưu trữ wb.Close(true, misValue, misValue); //thoát và thu hồi bộ nhớ cho COM xlApp.Quit(); releaseObject(ws); releaseObject(wb); releaseObject(xlApp); //Mở File excel sau khi Xuất thành công System.Diagnostics.Process.Start(saveExcelFile); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void XuatFile() { try { FolderBrowserDialog fl = new FolderBrowserDialog(); fl.SelectedPath = "c:\\windows\\system32";//co the lay duong dan tu file fl.ShowNewFolderButton = true; string saveExcelFile = ""; if (fl.ShowDialog() == DialogResult.OK) { saveExcelFile = fl.SelectedPath + "\\Thống kê thuốc.xlsx"; } //string saveExcelFile = @"F:\"; Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); if (xlApp == null) { MessageBox.Show("Lỗi không thể sử dụng được thư viện EXCEL"); return; } xlApp.Visible = false; object misValue = System.Reflection.Missing.Value; Workbook wb = xlApp.Workbooks.Add(misValue); Worksheet ws = (Worksheet)wb.Worksheets[1]; if (ws == null) { MessageBox.Show("Không thể tạo được WorkSheet"); return; } int row = 1; string fontName = "Times New Roman"; int fontSizeTieuDe = 18; int fontSizeTenTruong = 14; int fontSizeNoiDung = 12; //Xuất dòng Tiêu đề của File báo cáo: Lưu ý Range row1_TieuDe_BenhNhan = ws.get_Range("A1", "I1"); row1_TieuDe_BenhNhan.Merge(); row1_TieuDe_BenhNhan.Font.Size = fontSizeTieuDe; row1_TieuDe_BenhNhan.Font.Name = fontName; row1_TieuDe_BenhNhan.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row1_TieuDe_BenhNhan.Value2 = "Thống kê danh sách thuốc"; row1_TieuDe_BenhNhan.RowHeight = 30; //Tạo Ô Số Thứ Tự (STT) Range row23_STT = ws.get_Range("A2", "A3");//Cột A dòng 2 và dòng 3 row23_STT.Merge(); row23_STT.Font.Size = fontSizeTenTruong; row23_STT.Font.Name = fontName; row23_STT.Cells.HorizontalAlignment = XlHAlign.xlHAlignCenter; row23_STT.Value2 = "STT"; //Tạo Ô Mã bệnh nhân : Range row23_MaBenhNhan = ws.get_Range("B2", "B3");//Cột B dòng 2 và dòng 3 row23_MaBenhNhan.Merge(); row23_MaBenhNhan.Font.Size = fontSizeTenTruong; row23_MaBenhNhan.Font.Name = fontName; row23_MaBenhNhan.Cells.HorizontalAlignment = XlHAlign.xlHAlignCenter; row23_MaBenhNhan.Value2 = "Mã Thuốc"; row23_MaBenhNhan.ColumnWidth = 15; //Tạo Ô Tên bệnh nhân : Range row23_TenBenhNhan = ws.get_Range("C2", "C3");//Cột C dòng 2 và dòng 3 row23_TenBenhNhan.Merge(); row23_TenBenhNhan.Font.Size = fontSizeTenTruong; row23_TenBenhNhan.Font.Name = fontName; row23_TenBenhNhan.Cells.HorizontalAlignment = XlHAlign.xlHAlignCenter; row23_TenBenhNhan.ColumnWidth = 30; row23_TenBenhNhan.Value2 = "Tên Thuốc"; Range row23_NgaySinh = ws.get_Range("D2", "D3");//Cột C dòng 2 và dòng 3 row23_NgaySinh.Merge(); row23_NgaySinh.Font.Size = fontSizeTenTruong; row23_NgaySinh.Font.Name = fontName; row23_NgaySinh.Cells.HorizontalAlignment = XlHAlign.xlHAlignCenter; row23_NgaySinh.ColumnWidth = 20; row23_NgaySinh.Value2 = "Số Lượng"; //Tạo Ô Giới tính: Range row23_GioiTinh = ws.get_Range("E2", "E3");//Ô D3 row23_GioiTinh.Merge(); row23_GioiTinh.Font.Size = fontSizeTenTruong; row23_GioiTinh.Font.Name = fontName; row23_GioiTinh.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row23_GioiTinh.Value2 = "Hạn Sử Dụng"; row23_GioiTinh.ColumnWidth = 20; //Tạo Ô SDT: Range row23_SDT = ws.get_Range("F2", "F3");//Ô E3 row23_SDT.Merge(); row23_SDT.Font.Size = fontSizeTenTruong; row23_SDT.Font.Name = fontName; row23_SDT.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; row23_SDT.Value2 = "Đơn Vị Tính"; row23_SDT.ColumnWidth = 10; //Tô nền vàng các cột tiêu đề: Range row23_CotTieuDe = ws.get_Range("A2", "F3"); //nền xám trắng row23_CotTieuDe.Interior.Color = ColorTranslator.ToOle(System.Drawing.Color.LightGray); //in đậm row23_CotTieuDe.Font.Bold = true; //chữ đen row23_CotTieuDe.Font.Color = ColorTranslator.ToOle(System.Drawing.Color.Black); int stt = 0; row = 3;//dữ liệu xuất bắt đầu từ dòng số 4 trong file Excel (khai báo 3 để vào vòng lặp nó ++ thành 4) DentalClinicDataContext context = new DentalClinicDataContext(); foreach (var sp in Cons.dataContext.Medicines) { stt++; row++; dynamic[] arr = { stt, sp.MedicineId, sp.nameMedicine, sp.quantity, sp.expirationDate.ToString(), sp.unit }; Range rowData = ws.get_Range("A" + row, "F" + row);//Lấy dòng thứ row ra để đổ dữ liệu rowData.Font.Size = fontSizeNoiDung; rowData.Font.Name = fontName; rowData.Value2 = arr; } //Kẻ khung toàn bộ BorderAround(ws.get_Range("A2", "F" + row)); //Lưu file excel xuống Ổ cứng wb.SaveAs(saveExcelFile); //đóng file để hoàn tất quá trình lưu trữ wb.Close(true, misValue, misValue); //thoát và thu hồi bộ nhớ cho COM xlApp.Quit(); releaseObject(ws); releaseObject(wb); releaseObject(xlApp); //Mở File excel sau khi Xuất thành công System.Diagnostics.Process.Start(saveExcelFile); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnLogin_Click(object sender, EventArgs e) { DentalClinicDataContext dataContext = new DentalClinicDataContext(); var query = from a in dataContext.Accounts join s in dataContext.Staffs on a.StaffId equals s.StaffId join p in dataContext.Positions on s.PositionId equals p.PositionId select new { a.AccountId, a.userName, a.passWord, p.PositionId }; string username = txtUsername.Text; string password = txtPassword.Text; /*if (Login(username, password)) * {*/ if (txtUsername.Text != "" && txtPassword.Text != "") { foreach (var item in query.ToList()) { if (item.userName == txtUsername.Text && item.passWord == txtPassword.Text) { Cons.permission = item.PositionId; //gắn quyền. if (item.PositionId == 1) { // Chèn dữ liệu login Cons.AccountID = item.AccountId; WorkingStatus workingStatus = new WorkingStatus(); workingStatus.WorkingStatusId = Cons.ranDomId(); workingStatus.AccountId = item.AccountId; workingStatus.timeBegin = DateTime.Now; Cons.WorkingStatusId = workingStatus.WorkingStatusId; // luư lại. dataContext.WorkingStatus.InsertOnSubmit(workingStatus); dataContext.SubmitChanges(); CreateFormMain_Staff(); } if (item.PositionId == 2) { // Chèn dữ liệu login Cons.AccountID = item.AccountId; WorkingStatus workingStatus = new WorkingStatus(); workingStatus.WorkingStatusId = Cons.ranDomId(); workingStatus.AccountId = item.AccountId; workingStatus.timeBegin = DateTime.Now; Cons.WorkingStatusId = workingStatus.WorkingStatusId; // luư lại. dataContext.WorkingStatus.InsertOnSubmit(workingStatus); dataContext.SubmitChanges(); CreateFormMain_Doctor(); } if (item.PositionId == 3) { // Chèn dữ liệu login Cons.AccountID = item.AccountId; WorkingStatus workingStatus = new WorkingStatus(); workingStatus.WorkingStatusId = Cons.ranDomId(); workingStatus.AccountId = item.AccountId; workingStatus.timeBegin = DateTime.Now; Cons.WorkingStatusId = workingStatus.WorkingStatusId; // luư lại. dataContext.WorkingStatus.InsertOnSubmit(workingStatus); dataContext.SubmitChanges(); CreateFormMain_Manager(); } return; } else { error_transition.Show(lbl_Error); } } } /*}*/ }