Example #1
0
        // Insert bill detail after insert bill
        private void insertBillDetail()
        {
            switch (BillDetail.BillTypeID)
            {
            case Bill.MEDICINEBILL:

                MedicineBillDetail newMedicineBillDetail = new MedicineBillDetail();

                foreach (DataRow record in ((DataTable)dataViewBillDetail.DataSource).Rows)
                {
                    newMedicineBillDetail.BillID     = BillDetail.BillID;
                    newMedicineBillDetail.MedicineID = Convert.ToInt32(record["MEDICINEID"]);
                    newMedicineBillDetail.Quantity   = Convert.ToInt32(record["Số lượng"]);
                    newMedicineBillDetail.Price      = Convert.ToDecimal(record["Giá"]);

                    MedicineBillDetail.InsertMedicineBillDetail(newMedicineBillDetail);
                }
                break;

            case Bill.SERVICEBILL:

                ServiceBillDetail newServiceBillDetail = new ServiceBillDetail();

                foreach (DataRow record in ((DataTable)dataViewBillDetail.DataSource).Rows)
                {
                    newServiceBillDetail.BillID    = BillDetail.BillID;
                    newServiceBillDetail.ServiceID = Convert.ToInt32(record["SERVICEID"]);
                    newServiceBillDetail.Quantity  = Convert.ToInt32(record["Số lượng"]);
                    newServiceBillDetail.Price     = Convert.ToDecimal(record["Giá"]);

                    ServiceBillDetail.InsertServiceBillDetail(newServiceBillDetail);
                }
                break;

            case Bill.MATERIALBILL:

                RentMaterialBillDetail newRentMaterialBillDetail = new RentMaterialBillDetail();

                foreach (DataRow record in ((DataTable)dataViewBillDetail.DataSource).Rows)
                {
                    newRentMaterialBillDetail.BillID     = BillDetail.BillID;
                    newRentMaterialBillDetail.MaterialID = Convert.ToInt32(record["MATERIALID"]);
                    newRentMaterialBillDetail.Quantity   = Convert.ToInt32(record["Số lượng"]);
                    newRentMaterialBillDetail.Price      = Convert.ToDecimal(record["Giá"]);

                    RentMaterialBillDetail.InsertRentMaterialBillDetail(newRentMaterialBillDetail);
                }
                break;
            }
        }
Example #2
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);
            }
        }