private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            index = e.RowIndex;
            int SumMoney = 0;
            int length   = dataGridView2.Rows.Count;

            try
            {
                if (e.ColumnIndex == dataGridView1.Columns["add"].Index)
                {
                    dpn.ID_Medicine    = int.Parse(dataGridView1.Rows[index].Cells[0].Value.ToString());
                    dpn.Name           = dataGridView1.Rows[index].Cells[1].Value.ToString();
                    dpn.Price          = int.Parse(dataGridView1.Rows[index].Cells[3].Value.ToString());
                    dpn.ID_InputCoupon = int.Parse(textBoxMaPN.Text);
                    ctrdpn.Insert(dpn);

                    dataGridView2.DataSource = ctrdpn.Load(textBoxMaPN.Text);
                    //gán lại độ dài sau khi thêm
                    length = dataGridView2.Rows.Count;
                    for (int i = 0; i < length - 1; i++)
                    {
                        SumMoney += int.Parse(dataGridView2.Rows[i].Cells["intoMoney"].Value.ToString());
                    }

                    textBoxTongTienSo.Text  = SumMoney.ToString();
                    textBoxTongTienChu.Text = ConvertFromNumToText.Convert(textBoxTongTienSo.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Thêm Phiếu mới trước khi thêm thuốc!", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void btn_DeleteFromList_Click(object sender, EventArgs e)
        {
            int count = dataGridView2.Rows.Count - 1;

            foreach (DataGridViewRow item in this.dataGridView2.SelectedRows)
            {
                if (item.Index < count)
                {
                    tempIntoMoney = Convert.ToInt32(item.Cells["_thanhtien"].Value);
                    dataGridView2.Rows.RemoveAt(item.Index);
                    totalMoney = Convert.ToInt32(textBox_TotalMoney_ByNum.Text) - tempIntoMoney;

                    if (totalMoney != 0)
                    {
                        textBox_TotalMoney_ByNum.Text  = totalMoney.ToString();
                        textBox_TotalMoney_ByText.Text = ConvertFromNumToText.Convert(textBox_TotalMoney_ByNum.Text);
                    }
                    else
                    {
                        textBox_TotalMoney_ByNum.ResetText();
                        textBox_TotalMoney_ByText.ResetText();
                    }
                }
            }

            putSTT();
        }
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            int          length = dataGridView2.Rows.Count - 1;
            DialogResult dlr    = MessageBox.Show("Bạn có Chắc Chắn Xóa ?", "Thông Báo!", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            try
            {
                foreach (DataGridViewRow item in this.dataGridView2.SelectedRows)
                {
                    if (item.Index < length && dlr == DialogResult.Yes)
                    {
                        ctrdpn.Delete(dataGridView2.Rows[item.Index].Cells["maDPN"].Value.ToString());
                    }
                }
                dataGridView2.DataSource = ctrdpn.Load(textBoxMaPN.Text);

                int SumMoney = 0;
                //gán lại độ dài sau khi load xong
                length = dataGridView2.Rows.Count - 1;
                for (int i = 0; i < length; i++)
                {
                    SumMoney += int.Parse(dataGridView2.Rows[i].Cells["intoMoney"].Value.ToString());
                }

                textBoxTongTienSo.Text  = SumMoney.ToString();
                textBoxTongTienChu.Text = ConvertFromNumToText.Convert(textBoxTongTienSo.Text);

                MessageBox.Show("Xoá Thành Công!", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("Xoá Thất Bại!", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void dataGridView2_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            int price  = Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells["_dongia"].Value);
            int amount = Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells["_soluong"].Value);
            int bhyt   = price * amount / 2; // BHYT 50%

            // cap nhat bhyt
            dataGridView2.Rows[e.RowIndex].Cells["_bhyt"].Value = bhyt;
            // cap nhat thanh tien
            dataGridView2.Rows[e.RowIndex].Cells["_thanhtien"].Value = price * amount - bhyt;

            // cap nhat tong tien don thuoc
            textBox_TotalMoney_ByNum.Text  = (Convert.ToInt32(textBox_TotalMoney_ByNum.Text) + Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells["_thanhtien"].Value) - tempIntoMoney).ToString();
            textBox_TotalMoney_ByText.Text = ConvertFromNumToText.Convert(textBox_TotalMoney_ByNum.Text);
        }
Exemple #5
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < dataGridView1.Rows.Count - 1)
            {
                int    index = e.RowIndex;
                string id    = dataGridView1.Rows[index].Cells[0].Value.ToString();
                dataGridView2.DataSource = ctr2.Load(id);

                textBoxMaPN.Text  = dataGridView1.Rows[index].Cells[0].Value.ToString();
                textBoxMaNCC.Text = dataGridView1.Rows[index].Cells[1].Value.ToString();
                DateTime date = (DateTime)dataGridView1.Rows[index].Cells[2].Value;
                dateTimePicker1.Value   = date;
                textBoxTongTienSo.Text  = dataGridView1.Rows[index].Cells[3].Value.ToString();
                textBoxTongTienChu.Text = ConvertFromNumToText.Convert(textBoxTongTienSo.Text);
            }
        }
Exemple #6
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            int SumMoney = 0;
            int length   = dataGridView2.Rows.Count;

            try
            {
                for (int i = 0; i < dataGridView2.Rows.Count - 1; i++)
                {
                    dpn.ID_InputCoupon     = int.Parse(textBoxMaPN.Text);
                    dpn.ID_InputCouponLine = int.Parse(dataGridView2.Rows[i].Cells["maDPN"].Value.ToString());
                    dpn.ID_Medicine        = int.Parse(dataGridView2.Rows[i].Cells["maThuoc"].Value.ToString());
                    dpn.Name       = dataGridView2.Rows[i].Cells["tenThuoc"].Value.ToString();
                    dpn.UnitInput  = dataGridView2.Rows[i].Cells["donViNhap"].Value.ToString();
                    dpn.Amount     = int.Parse(dataGridView2.Rows[i].Cells["soLuong"].Value.ToString());
                    dpn.Price      = decimal.Parse(dataGridView2.Rows[i].Cells["donGia"].Value.ToString());
                    dpn.ExpiryDate = (DateTime)dataGridView2.Rows[i].Cells["hanSD"].Value;
                    ctr2.Update(dpn);
                }
                dataGridView2.DataSource = ctr2.Load(textBoxMaPN.Text);

                for (int i = 0; i < length - 1; i++)
                {
                    SumMoney += int.Parse(dataGridView2.Rows[i].Cells["intoMoney"].Value.ToString());
                }

                textBoxTongTienSo.Text  = SumMoney.ToString();
                textBoxTongTienChu.Text = ConvertFromNumToText.Convert(textBoxTongTienSo.Text);

                pn.ID_InputCoupon = int.Parse(textBoxMaPN.Text);
                pn.ID_Supplier    = int.Parse(textBoxMaNCC.Text);
                pn.CreateDate     = dateTimePicker1.Value.Date;
                pn.TotalMoney     = decimal.Parse(textBoxTongTienSo.Text);
                ctr1.Update(pn);

                dataGridView1.DataSource = ctr1.Load();

                MessageBox.Show("Sửa Thành Công!", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("Sửa Thất Bại!", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void dataGridView2_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            int price  = Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells[10].Value);
            int amount = Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells[11].Value);
            //int bhyt = Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells[12].Value);

            int bhyt = price * amount / 2; // BHYT 50%

            // cap nhat bhyt
            dataGridView2.Rows[e.RowIndex].Cells[12].Value = bhyt;
            // cap nhat thanh tien
            dataGridView2.Rows[e.RowIndex].Cells[13].Value = price * amount - bhyt;
            // cap nhat trang thai row (1:can cap nhat | #1:khong can cap nhat)
            dataGridView2.Rows[e.RowIndex].Cells["_status"].Value = 1;

            // cap nhat tong tien don thuoc
            textBox_TotalMoney_ByNum.Text  = (Convert.ToInt32(textBox_TotalMoney_ByNum.Text) + Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells[13].Value) - tempIntoMoney).ToString();
            textBox_TotalMoney_ByText.Text = ConvertFromNumToText.Convert(textBox_TotalMoney_ByNum.Text);
        }
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                // Lay ID cua ban ghi duoc chon --> chuan bi cho Xem, Tem
                string strID = dataGridView1.SelectedCells[0].OwningRow.Cells[0].Value.ToString();
                int    id    = -1;
                if (!strID.Equals(""))
                {
                    id = Convert.ToInt32(strID);
                }

                // Xu ly cac truong hop Xem(detail), Them(add)
                if (e.ColumnIndex == dataGridView1.Columns["detail"].Index)
                {
                    if (id != -1)
                    {
                        // Code xu ly lay du lieu tu ban ghi chuyen sang FormDetailMedicine
                        medicineID    = dataGridView1.SelectedCells[0].OwningRow.Cells["_id"].Value.ToString();
                        medicineName  = dataGridView1.SelectedCells[0].OwningRow.Cells["_name"].Value.ToString();
                        medicineGroup = dataGridView1.SelectedCells[0].OwningRow.Cells["_group"].Value.ToString();
                        uses          = dataGridView1.SelectedCells[0].OwningRow.Cells["_uses"].Value.ToString();
                        unit          = dataGridView1.SelectedCells[0].OwningRow.Cells["_unit"].Value.ToString();
                        price         = dataGridView1.SelectedCells[0].OwningRow.Cells["_price"].Value.ToString();
                        inventory     = dataGridView1.SelectedCells[0].OwningRow.Cells["_inventory"].Value.ToString();
                        note          = dataGridView1.SelectedCells[0].OwningRow.Cells["_note"].Value.ToString();
                        mostUsedMonth = dataGridView1.SelectedCells[0].OwningRow.Cells["_mostUsed"].Value.ToString();

                        // Hien thi FormDetailMedicine
                        Form form = new BanThuoc.FormDetailMedicine();
                        form.ShowDialog();
                        LoadData();
                    }
                }

                else if (e.ColumnIndex == dataGridView1.Columns["add"].Index)
                {
                    if (id != -1)
                    {
                        // Them thuoc vao don thuoc
                        medicineID   = dataGridView1.SelectedCells[0].OwningRow.Cells["_id"].Value.ToString();
                        medicineName = dataGridView1.SelectedCells[0].OwningRow.Cells["_name"].Value.ToString();
                        price        = dataGridView1.SelectedCells[0].OwningRow.Cells["_price"].Value.ToString();
                        amount       = 1;

                        // Create a new row first as it will include the columns you've created at design-time.

                        int rowId = dataGridView2.Rows.Add();

                        // Grab the new row!
                        DataGridViewRow row = dataGridView2.Rows[rowId];

                        // Add the data
                        row.Cells["_stt"].Value       = getSTT();
                        row.Cells["_mathuoc"].Value   = medicineID;
                        row.Cells["_tenthuoc"].Value  = medicineName;
                        row.Cells["_dongia"].Value    = price;
                        row.Cells["_soluong"].Value   = amount;
                        row.Cells["_bhyt"].Value      = (Convert.ToInt32(price) * Convert.ToInt32(amount) * 0.5);
                        row.Cells["_thanhtien"].Value = (Convert.ToInt32(price) * Convert.ToInt32(amount) - Convert.ToInt32(row.Cells["_bhyt"].Value));

                        // cap nhat tong tien
                        totalMoney = totalMoney + Convert.ToInt32(row.Cells["_thanhtien"].Value);
                        textBox_TotalMoney_ByNum.Text  = totalMoney.ToString();
                        textBox_TotalMoney_ByText.Text = ConvertFromNumToText.Convert(totalMoney.ToString());
                    }
                }
            }
        }
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            btn_Save.Visible = false;
            if (e.RowIndex >= 0)
            {
                // Lay ID cua ban ghi duoc chon --> chuan bi cho Xem, Sua, Xoa
                string strID = dataGridView1.SelectedCells[0].OwningRow.Cells[0].Value.ToString();

                // Xu ly cac truong hop Xem(detail), Sua(edit), Xoa(delete)
                if (e.ColumnIndex == dataGridView1.Columns["detail"].Index)
                {
                    RenewPersciption();
                    SetVisibleVirtualColumns(false);
                    SetEnableEditPrescription(false);
                    dataGridView2.DataSource = ctrlPL.Load(strID);
                    dataGridView2.Columns["Mã đơn thuốc"].Visible = false;
                    dataGridView2.Columns["Mã thuốc"].Visible     = false;

                    int numRows = dataGridView2.Rows.Count;
                    for (int i = 1; i < numRows; i++)
                    {
                        dataGridView2.Rows[i - 1].Cells["_stt"].Value = i;
                    }

                    btn_Save.Visible = false;

                    textBox_ID.Text                = dataGridView1.SelectedCells[0].OwningRow.Cells["_id"].Value.ToString();
                    textBox_Doctor.Text            = dataGridView1.SelectedCells[0].OwningRow.Cells["_doctor"].Value.ToString();
                    dateTimePicker_CreateDate.Text = dataGridView1.SelectedCells[0].OwningRow.Cells["_createDate"].Value.ToString();
                    textBox_MedicalRecord.Text     = dataGridView1.SelectedCells[0].OwningRow.Cells["_medicalRecord"].Value.ToString();
                    textBox_TotalMoney_ByNum.Text  = dataGridView1.SelectedCells[0].OwningRow.Cells["_totalMoney"].Value.ToString();
                    if (textBox_TotalMoney_ByNum.Text != "")
                    {
                        textBox_TotalMoney_ByText.Text = ConvertFromNumToText.Convert(textBox_TotalMoney_ByNum.Text);
                    }
                }
                else if (e.ColumnIndex == dataGridView1.Columns["edit"].Index)
                {
                    RenewPersciption();
                    SetVisibleVirtualColumns(false);
                    SetEnableEditPrescription(true);
                    dataGridView2.DataSource = ctrlPL.Load(strID);
                    dataGridView2.Columns["Mã đơn thuốc"].Visible = false;
                    dataGridView2.Columns["Mã thuốc"].Visible     = false;

                    int numRows = dataGridView2.Rows.Count;
                    for (int i = 1; i < numRows; i++)
                    {
                        dataGridView2.Rows[i - 1].Cells["_stt"].Value = i;
                    }

                    btn_Save.Visible = true;

                    textBox_ID.Text                = dataGridView1.SelectedCells[0].OwningRow.Cells["_id"].Value.ToString();
                    textBox_Doctor.Text            = dataGridView1.SelectedCells[0].OwningRow.Cells["_doctor"].Value.ToString();
                    dateTimePicker_CreateDate.Text = dataGridView1.SelectedCells[0].OwningRow.Cells["_createDate"].Value.ToString();
                    textBox_MedicalRecord.Text     = dataGridView1.SelectedCells[0].OwningRow.Cells["_medicalRecord"].Value.ToString();
                    textBox_TotalMoney_ByNum.Text  = dataGridView1.SelectedCells[0].OwningRow.Cells["_totalMoney"].Value.ToString();
                    if (textBox_TotalMoney_ByNum.Text != "")
                    {
                        textBox_TotalMoney_ByText.Text = ConvertFromNumToText.Convert(textBox_TotalMoney_ByNum.Text);
                    }

                    // cho phep sua so luong thuoc
                    dataGridView2.Columns["Số lượng"].ReadOnly = false;
                }
                else if (e.ColumnIndex == dataGridView1.Columns["delete"].Index)
                {
                    DialogResult dlr = MessageBox.Show("Chắc chắn xoá ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dlr == DialogResult.Yes)
                    {
                        // Code xu ly xoa don thuoc
                        ctrlP.Delete(strID);
                        MessageBox.Show("Xoá thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadDataPrescription();
                    }
                }
            }
        }
        private void btn_Save_Click(object sender, EventArgs e)
        {
            dataGridView2.Columns["Số lượng"].ReadOnly = true; // khong cho phep sua nua

            string strTotalMoney = textBox_TotalMoney_ByNum.Text;

            //Prescription psc = new Prescription();
            //Prescriptionline pscl = new Prescriptionline();

            int numRows = dataGridView2.Rows.Count;

            // update dong don thhuoc
            for (int i = 1; i < numRows; i++)
            {
                if (Convert.ToInt32(dataGridView2.Rows[i - 1].Cells["_status"].Value) == 1)
                {
                    pscl.ID_Prescription = Convert.ToInt32(dataGridView2.Rows[i - 1].Cells["Mã đơn thuốc"].Value);;
                    pscl.ID_Medicine     = Convert.ToInt32(dataGridView2.Rows[i - 1].Cells["Mã thuốc"].Value);;
                    pscl.Amount          = Convert.ToInt32(dataGridView2.Rows[i - 1].Cells["Số lượng"].Value);
                    pscl.HealthInsurance = Convert.ToInt32(dataGridView2.Rows[i - 1].Cells["BHYT"].Value);

                    ctrlPL.Update(pscl);
                }
            }

            // update don thuoc
            psc.ID_Prescription = Convert.ToInt32(textBox_ID.Text);
            psc.Doctor          = textBox_Doctor.Text;
            psc.MedicalRecord   = Convert.ToInt32(textBox_MedicalRecord.Text);
            psc.CreateDate      = dateTimePicker_CreateDate.Value;
            psc.TotalMoney      = Convert.ToInt32(textBox_TotalMoney_ByNum.Text);

            ctrlP.Update(psc);

            // thong bao thanh cong
            MessageBox.Show("Lưu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

            // Load lai thong tin don thuoc sau khi chinh sua

            // reload DS don thuoc
            LoadDataPrescription();
            // reload DS thuoc trong don thuoc
            RenewPersciption();
            SetVisibleVirtualColumns(false);
            SetEnableEditPrescription(false);
            dataGridView2.DataSource = ctrlPL.Load(psc.ID_Prescription.ToString());
            dataGridView2.Columns["Mã đơn thuốc"].Visible = false;
            dataGridView2.Columns["Mã thuốc"].Visible     = false;

            int num = dataGridView2.Rows.Count;

            for (int j = 1; j < num; j++)
            {
                dataGridView2.Rows[j - 1].Cells["_stt"].Value = j;
            }
            // reload thong tin don thuoc
            textBox_ID.Text                 = psc.ID_Prescription.ToString();
            textBox_Doctor.Text             = psc.Doctor;
            dateTimePicker_CreateDate.Value = psc.CreateDate;
            textBox_MedicalRecord.Text      = psc.MedicalRecord.ToString();
            textBox_TotalMoney_ByNum.Text   = strTotalMoney;
            if (textBox_TotalMoney_ByNum.Text != "")
            {
                textBox_TotalMoney_ByText.Text = ConvertFromNumToText.Convert(strTotalMoney);
            }


            btn_Save.Visible = false;
        }