//Refresh datagridview in medicine tab private void refreshDataViewMedicine() { try { // Get medicine's datatable DataTable medicineTable = Medicine.GetListMedicine(); // Add Vietnamese column's name medicineTable.Columns.Add("Mã thuốc", typeof(string), "[MEDICINEID]"); medicineTable.Columns.Add("Tên thuốc", typeof(string), "[MEDICINENAME]"); medicineTable.Columns.Add("Số lượng", typeof(string), "[QUANTITY]"); medicineTable.Columns.Add("Đơn giá", typeof(string), "[PRICE]"); // Set data source to dataview for searching dataViewMedicine.DataSource = medicineTable.DefaultView; // Hide English columns'name for (int i = 0; i < 4; i++) { dataViewMedicine.Columns[i].Visible = false; } //Add auto complete datasource to textbox textBoxMedicineSearch.AutoCompleteCustomSource.Clear(); for (int i = 0; i < medicineTable.Rows.Count; i++) { String strMaterialName = medicineTable.Rows[i][1].ToString(); textBoxMedicineSearch.AutoCompleteCustomSource.Add(strMaterialName); } } catch { MessageBox.Show("Lỗi dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void SetPDetailForInsert(int staffID, int patientID) { textBoxPatientID.Text = patientID.ToString(); textBoxStaffID.Text = staffID.ToString(); dateCreate.Value = DateTime.Today; dateCreate.Enabled = false; DataTable dtMedicine = Medicine.GetListMedicine(); for (int i = 0; i < dtMedicine.Rows.Count; i++) { Medicine newMedicine = Medicine.GetMedicine(Convert.ToInt32(dtMedicine.Rows[i][0])); listMedicine.Add(newMedicine); comboBoxMedicine.Items.Add(newMedicine.MedicineName); comboBoxMedicine.AutoCompleteCustomSource.Add(newMedicine.MedicineName); } comboBoxMedicine.SelectedIndex = 0; }
private void SetPDetailForUpdate(Prescription pDetail) { textBoxPrescriptionID.Text = pDetail.PrescriptionID.ToString(); textBoxPatientID.Text = pDetail.PatientID.ToString(); textBoxStaffID.Text = pDetail.StaffID.ToString(); dateCreate.Value = pDetail.Date; DataTable dtMedicine = Medicine.GetListMedicine(); for (int i = 0; i < dtMedicine.Rows.Count; i++) { Medicine newMedicine = Medicine.GetMedicine(Convert.ToInt32(dtMedicine.Rows[i][0])); listMedicine.Add(newMedicine); comboBoxMedicine.Items.Add(newMedicine.MedicineName); comboBoxMedicine.AutoCompleteCustomSource.Add(newMedicine.MedicineName); } comboBoxMedicine.SelectedIndex = 0; DataTable dtPD = PrescriptionDetail.GetListPrescriptionDetail(pDetail.PrescriptionID); for (int i = 0; i < dtPD.Rows.Count; i++) { PrescriptionDetail newDP = new PrescriptionDetail(); newDP.PrescriptionID = Convert.ToInt32(dtPD.Rows[i][0]); newDP.MedicineID = Convert.ToInt32(dtPD.Rows[i][1]); newDP.Quantity = Convert.ToInt16(dtPD.Rows[i][2]); newDP.Instruction = dtPD.Rows[i][3].ToString(); listDP.Add(newDP); Medicine newMedicine = Medicine.GetMedicine(newDP.MedicineID); listSelectedMedicine.Items.Add(newMedicine.MedicineName); } if (listSelectedMedicine.Items.Count > 0) { listSelectedMedicine.SelectedIndex = 0; } }
//public FormBillDetail(string userAction, Bill bill, Staff staff, Patient patient) //{ // InitializeComponent(); // // Set useraction and bill // this.BillDetail = bill; // this.UserAction = userAction; // this.StaffDetail = staff; // this.PatientDetail = patient; // reFreshForm(); //} // Set information to form private void reFreshForm() { try { // Set bill information textBoxPatientID.Text = PatientDetail.PatientID.ToString(); textBoxPatientName.Text = PatientDetail.LastName + ' ' + PatientDetail.FirstName; textBoxStaffID.Text = StaffDetail.StaffID.ToString(); textBoxStaffName.Text = StaffDetail.LastName + ' ' + StaffDetail.FirstName; if (PatientDetail.State == 0) { buttonSave.Enabled = false; } //Check HIC if (HIC.CheckHIC(BillDetail.PatientID)) { HIC newHIC = HIC.GetPatientHIC(BillDetail.PatientID); if (HIC.CheckHICExpiration(newHIC.HICID)) { labelHICID.Text = "Đã hết hạn"; this.HICID = 0; } else { labelHICID.Text = "Còn hạn sử dụng"; this.HICID = newHIC.HICID; } } else { labelHICID.Text = "Không có"; this.HICID = 0; } // Set comboBoxDetail corresponding to bill's type switch (BillDetail.BillTypeID) { case Bill.MEDICINEBILL: labelDetail.Text = "Tên thuốc:"; // Get Medicine list and set it to comboBox comboBoxDetail.DataSource = Medicine.GetListMedicine(); comboBoxDetail.ValueMember = "PRICE"; comboBoxDetail.DisplayMember = "MEDICINENAME"; break; case Bill.SERVICEBILL: labelDetail.Text = "Dịch vụ:"; // Get Service list and set it to comboBox comboBoxDetail.DataSource = Service.GetListService(); comboBoxDetail.ValueMember = "PRICE"; comboBoxDetail.DisplayMember = "SERVICENAME"; break; case Bill.MATERIALBILL: labelDetail.Text = "Đồ dùng:"; // Get Material list and set it to comboBox comboBoxDetail.DataSource = Material.GetListMaterial(); comboBoxDetail.ValueMember = "PRICE"; comboBoxDetail.DisplayMember = "MATERIALNAME"; labelHIC.Visible = false; labelHICID.Visible = false; break; } // If bill was pay then do nothing if (BillDetail.State == Bill.PAY) { buttonAdd.Enabled = false; buttonDelete.Enabled = false; buttonPay.Enabled = false; buttonSave.Enabled = false; dateTimeInputBill.Enabled = false; labelTotalBillPrice.ForeColor = Color.Green; labelBillState.ForeColor = Color.Green; labelBillState.Text = "Đã thanh toán"; } // Set information when user edit bill's detail if ("edit".Equals(UserAction)) { decimal totalPrice = BillDetail.TotalPrice; // Set billID textBoxBillID.Text = BillDetail.BillID.ToString(); dateTimeInputBill.Value = BillDetail.Date; // When update bill, user can only update bill's state buttonAdd.Enabled = false; buttonDelete.Enabled = false; buttonSave.Enabled = false; dateTimeInputBill.Enabled = false; //BillDetail = Bill.GetBill(BillDetail.BillID); if (HICID != 0) { totalPrice = totalPrice / 4; } labelTotalBillPrice.Text = totalPrice.ToString("C", CultureInfo.CreateSpecificCulture("vi")); // Set dataViewBillDetail corresponding bill's type switch (BillDetail.BillTypeID) { case Bill.MEDICINEBILL: BillMedicineTable = MedicineBillDetail.GetListMedicineBillDetail(BillDetail.BillID); BillMedicineTable.Columns.Add("Thuốc", typeof(string), "[MEDICINENAME]"); BillMedicineTable.Columns.Add("Số lượng", typeof(int), "[QUANTITY]"); BillMedicineTable.Columns.Add("Giá", typeof(decimal), "[PRICE]"); dataViewBillDetail.DataSource = BillMedicineTable; for (int i = 0; i < 3; i++) { dataViewBillDetail.Columns[i].Visible = false; } break; case Bill.SERVICEBILL: BillServiceTable = ServiceBillDetail.GetListServiceBillDetail(BillDetail.BillID); BillServiceTable.Columns.Add("Dịch vụ", typeof(string), "[SERVICENAME]"); BillServiceTable.Columns.Add("Số lượng", typeof(int), "[QUANTITY]"); BillServiceTable.Columns.Add("Giá", typeof(decimal), "[PRICE]"); dataViewBillDetail.DataSource = BillServiceTable; for (int i = 0; i < 3; i++) { dataViewBillDetail.Columns[i].Visible = false; } break; case Bill.MATERIALBILL: BillMaterialTable = RentMaterialBillDetail.GetListRentMaterialBillDetail(BillDetail.BillID); BillMaterialTable.Columns.Add("Đồ dùng", typeof(string), "[MATERIALNAME]"); BillMaterialTable.Columns.Add("Số lượng", typeof(int), "[QUANTITY]"); BillMaterialTable.Columns.Add("Giá", typeof(decimal), "[PRICE]"); dataViewBillDetail.DataSource = BillMaterialTable; for (int i = 0; i < 3; i++) { dataViewBillDetail.Columns[i].Visible = false; } break; } } else if ("insert".Equals(UserAction)) /// Set information when user insert bill's detail { // Generate next billID textBoxBillID.Text = Bill.GetNextBillID().ToString(); dateTimeInputBill.Value = DateTime.Today; labelTotalBillPrice.Text = 0.ToString("C", CultureInfo.CreateSpecificCulture("vi")); BillDetail.BillID = Bill.GetNextBillID(); BillDetail.Date = dateTimeInputBill.Value; BillDetail.TotalPrice = 0; BillDetail.State = 0; switch (BillDetail.BillTypeID) { case Bill.MEDICINEBILL: buttonAdd.Enabled = false; buttonDelete.Enabled = false; decimal totalPrice = new Decimal(); BillMedicineTable = PrescriptionDetail.GetListPrescriptionDetailWithMedicine(PrescriptionID); BillMedicineTable.Columns.Add("Thuốc", typeof(string), "[MEDICINENAME]"); BillMedicineTable.Columns.Add("Số lượng", typeof(int), "[QUANTITY]"); BillMedicineTable.Columns.Add("Giá", typeof(decimal), "[PRICE]"); dataViewBillDetail.DataSource = BillMedicineTable; for (int i = 0; i < 4; i++) { dataViewBillDetail.Columns[i].Visible = false; } foreach (DataRow row in BillMedicineTable.Rows) { totalPrice += (decimal)row["Giá"]; } BillDetail.TotalPrice = totalPrice; if (HICID != 0) { totalPrice = totalPrice / 4; } labelTotalBillPrice.Text = totalPrice.ToString("C", CultureInfo.CreateSpecificCulture("vi")); break; case Bill.SERVICEBILL: BillServiceTable = new DataTable(); BillServiceTable.Columns.Add("SERVICEID", typeof(int)); BillServiceTable.Columns.Add("Dịch vụ", typeof(string)); BillServiceTable.Columns.Add("Số lượng", typeof(int)); BillServiceTable.Columns.Add("Giá", typeof(decimal)); dataViewBillDetail.DataSource = BillServiceTable; dataViewBillDetail.Columns["SERVICEID"].Visible = false; break; case Bill.MATERIALBILL: BillMaterialTable = new DataTable(); BillMaterialTable.Columns.Add("MATERIALID", typeof(int)); BillMaterialTable.Columns.Add("Đồ dùng", typeof(string)); BillMaterialTable.Columns.Add("Số lượng", typeof(int)); BillMaterialTable.Columns.Add("Giá", typeof(decimal)); dataViewBillDetail.DataSource = BillMaterialTable; dataViewBillDetail.Columns["MATERIALID"].Visible = false; break; } } else { switch (UserAction) { case "insertExamination": decimal totalPrice = Service.GetServiceExamination().Price; // Only save and pay when create examination buttonAdd.Enabled = false; buttonDelete.Enabled = false; // Set new bill detail for examination BillDetail.BillID = Bill.GetNextBillID(); BillDetail.Date = DateTime.Now; BillDetail.TotalPrice = totalPrice; BillDetail.State = 0; // Create table for datagridview BillServiceTable = new DataTable(); BillServiceTable.Columns.Add("SERVICEID", typeof(int)); BillServiceTable.Columns.Add("Dịch vụ", typeof(string)); BillServiceTable.Columns.Add("Số lượng", typeof(int)); BillServiceTable.Columns.Add("Giá", typeof(decimal)); dataViewBillDetail.DataSource = BillServiceTable; dataViewBillDetail.Columns["SERVICEID"].Visible = false; BillServiceTable.Rows.Add(new object[] { 100, "Khám bệnh", 1, totalPrice }); if (HICID != 0) { totalPrice = totalPrice / 4; //BillDetail.TotalPrice = totalPrice; } // Set form information textBoxBillID.Text = Bill.GetNextBillID().ToString(); dateTimeInputBill.Value = BillDetail.Date; labelTotalBillPrice.Text = totalPrice.ToString("C", CultureInfo.CreateSpecificCulture("vi")); break; case "insertTest": break; case "insertSurgery": break; } UserAction = "insert"; } } catch (SqlException exception) { MessageBox.Show(exception.Message, "Lỗi dữ liệu", MessageBoxButtons.OK, MessageBoxIcon.Error); } }