private string TaoMaTuDong(string key)
        {
            DataTable dt = new DataTable();

            pkbus = new PhieuKhamBUS();
            dt    = pkbus.loadToDataTable();
            int coso = 0;

            if (dt.Rows.Count == 0)
            {
                coso = 1;
            }
            else if (dt.Rows.Count == 1 && int.Parse(dt.Rows[0][0].ToString().Substring(2, 3)) == 1)
            {
                coso = 2;
            }
            else if (dt.Rows.Count == 1 && int.Parse(dt.Rows[0][0].ToString().Substring(2, 3)) > 1)
            {
                coso = 1;
            }
            else
            {
                for (int i = 0; i < dt.Rows.Count - 1; i++)
                {
                    if (int.Parse(dt.Rows[i + 1][0].ToString().Substring(2, 3)) - int.Parse(dt.Rows[i][0].ToString().Substring(2, 3)) > 1)
                    {
                        coso = int.Parse(dt.Rows[i][0].ToString().Substring(2, 3)) + 1;
                        break;
                    }
                }
                coso = int.Parse(dt.Rows[dt.Rows.Count - 1][0].ToString().Substring(2, 3)) + 1;
            }

            //Sau khi lấy được cơ số thứ tự của thuốc, ta gắn thêm tiền tố T vào

            string ma = "";

            if (coso < 10)
            {
                return(ma = key + "00" + coso);
            }
            else if (coso < 100)
            {
                return(ma = key + "0" + coso);
            }
            else
            {
                return(ma = key + coso);
            }
        }
Esempio n. 2
0
        private void bt_luu_Click(object sender, EventArgs e)
        {
            if (flag == "Sửa")
            {
                LapPhieuKhamDTO pk = new LapPhieuKhamDTO();
                pk.MaPK1 = tB_MaPK.Text;
                pk.MaLB1 = comboBox_LoaiBenh.Text.Substring(1, 4);

                pk.MaBS1 = comboBox_TenBS.Text.Substring(1, 5);
                DateTime a = (DateTime)dateTimePicker1.Value;
                pk.NgayKham1 = (DateTime)dateTimePicker1.Value;


                LapPhieuKhamBUS pkbus = new LapPhieuKhamBUS();
                bool            kq    = pkbus.sua(pk);
                if (kq == true)
                {
                    MessageBox.Show("Thêm bệnh nhân thành công");
                    pkbus = new LapPhieuKhamBUS();
                    List <LapPhieuKhamDTO> listdanhsach = pkbus.select();
                    loadDsPK(listdanhsach);
                }
                else
                {
                    MessageBox.Show("Thêm bệnh nhân thất bại");
                }
            }
            else if (flag == "Xóa")
            {
                LapPhieuKhamDTO pk = new LapPhieuKhamDTO();
                pk.MaPK1 = tB_MaPK.Text;



                LapPhieuKhamBUS pkbus = new LapPhieuKhamBUS();
                bool            kq    = pkbus.xoa(pk);
                if (kq == true)
                {
                    MessageBox.Show("Xóa  thành công");
                    pkbus = new LapPhieuKhamBUS();
                    List <LapPhieuKhamDTO> listdanhsach = pkbus.select();
                    loadDsPK(listdanhsach);
                }
                else
                {
                    MessageBox.Show("Xóa  thất bại");
                }
            }
            else if (flag == "them")
            {
                PhieuKhamDTO pk = new PhieuKhamDTO();
                pk.MaPK1     = TaoMaTuDong("PK");
                pk.MaBN1     = tB_mabn.Text;
                pk.NgayKham1 = dateTimePicker1.Value.Date;
                pk.MaLB1     = comboBox_LoaiBenh.Text.Substring(1, 4);
                pk.MaNV1     = comboBox_TenBS.Text.Substring(1, 5);
                pk.NgayKham1 = dateTimePicker1.Value;


                PhieuKhamBUS pk1bus = new PhieuKhamBUS();
                bool         kq     = pk1bus.them(pk);
                if (kq == true)
                {
                    MessageBox.Show("Thêm  thành công");
                }
                else
                {
                    MessageBox.Show("Thêm  thất bại");
                }
            }
            dataGridView1.Enabled     = true;
            bt_sua.Visible            = true;
            bt_luu.Visible            = false;
            bt_Huy.Visible            = false;
            comboBox_TenBS.Enabled    = false;
            comboBox_LoaiBenh.Enabled = false;
            load();
        }