// update gridview
        private void updateGridview()
        {
            dataGridView1.Rows.Clear();

            try
            {
                db.OpenConnection();
                dt = db.ExecuteReader("select * from phieukham");
                db.CloseConnection();

                foreach (System.Data.DataRow r in dt.Rows)
                {
                    string[] row = new string[6];
                    string   tenbn;

                    db.OpenConnection();
                    System.Data.DataTable temp = db.ExecuteReader("select ten from benhnhan where idBN=" + r["idBN"].ToString());
                    db.CloseConnection();

                    tenbn = temp.Rows[0][0].ToString();

                    row[0] = r["idPhieuKham"].ToString();
                    row[1] = r["idBN"].ToString();
                    row[2] = tenbn;
                    row[3] = r["ngay_lap"].ToString();
                    row[4] = r["ten_BS"].ToString();
                    row[5] = r["chan_doan"].ToString();

                    dataGridView1.Rows.Add(row);
                }
            } catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void btn_ok_Click(object sender, EventArgs e)
        {
            try
            {
                string          path    = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "config/connection_info.cfg");
                string[]        coninfo = System.IO.File.ReadAllLines(path);
                ConnDb.ConnData db      = new ConnDb.ConnData(coninfo[0], coninfo[1], coninfo[2], coninfo[3]);

                string insert = "insert into thuoc(ten_thuoc, dvt, so_luong, gia_mua, gia_ban, han_sd) values('" + txt_tenthuoc.Text + "', '" + txt_dvt.Text + "', '" +
                                txt_soluong.Text + "', '" + txt_giamua.Text + "', '" + txt_giaban.Text + "', '" + txt_hsd.Text + "')";

                db.OpenConnection();
                db.ExecuteNonQuery(insert);
                db.CloseConnection();

                txt_tenthuoc.Clear();
                txt_soluong.Clear();
                txt_hsd.Clear();
                txt_giamua.Clear();
                txt_giaban.Clear();
                txt_dvt.Clear();

                Owner.Activate();
                Activate();
            } catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //
        // Update datagridview danh sách các loại thuốc
        //
        public void update_gridview_dsthuoc(string query)
        {
            dtgv_dsthuoc.Rows.Clear();
            btn_edit.Enabled = false;

            try
            {
                db.OpenConnection();
                dsthuoc = db.ExecuteReader(query);

                foreach (DataRow row in dsthuoc.Rows)
                {
                    dtgv_dsthuoc.Rows.Add(row.ItemArray);
                }
                db.CloseConnection();

                if (dtgv_dsthuoc.Rows.Count > 0)
                {
                    txt_tenthuoc.Text = dtgv_dsthuoc.Rows[dtgv_dsthuoc.SelectedRows[0].Index].Cells["tenthuoc"].Value.ToString();
                    txt_dvt.Text      = dtgv_dsthuoc.Rows[dtgv_dsthuoc.SelectedRows[0].Index].Cells["dvt"].Value.ToString();
                    txt_giamua.Text   = dtgv_dsthuoc.Rows[dtgv_dsthuoc.SelectedRows[0].Index].Cells["giamua"].Value.ToString();
                    txt_giaban.Text   = dtgv_dsthuoc.Rows[dtgv_dsthuoc.SelectedRows[0].Index].Cells["giaban"].Value.ToString();
                    txt_hsd.Text      = dtgv_dsthuoc.Rows[dtgv_dsthuoc.SelectedRows[0].Index].Cells["hsd"].Value.ToString();
                    txt_soluong.Text  = dtgv_dsthuoc.Rows[dtgv_dsthuoc.SelectedRows[0].Index].Cells["soluong"].Value.ToString();
                    btn_edit.Enabled  = true;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (dtgv_dsthuoc.SelectedRows.Count > 0)
            {
                btn_xoa.Enabled = true;
            }
            else
            {
                btn_xoa.Enabled = false;
            }
        }
        private void showinfo(string idbn)
        {
            try
            {
                db.OpenConnection();
                string sql = "select * from benhnhan where idBN=" + idbn;
                dt_temp = db.ExecuteReader(sql);
                db.CloseConnection();

                txt_hotenbn.Text    = dt_temp.Rows[0]["ten"].ToString();
                txt_idbn.Text       = dt_temp.Rows[0]["idBN"].ToString();
                txt_para.Text       = dt_temp.Rows[0]["PARA"].ToString();
                txt_sdtbn.Text      = dt_temp.Rows[0]["phone_num"].ToString();
                txt_tiencanbn.Text  = dt_temp.Rows[0]["tiencan_bt"].ToString();
                txt_tiencangd.Text  = dt_temp.Rows[0]["tiencan_gd"].ToString();
                txt_tuoibn.Text     = dt_temp.Rows[0]["tuoi"].ToString();
                txt_diachibn.Text   = dt_temp.Rows[0]["address"].ToString();
                txt_nghenghiep.Text = dt_temp.Rows[0]["nghe_nghiep"].ToString();
            }
            catch (System.Exception)
            {
                return;
            }
        }
Esempio n. 5
0
        //
        // Update gridview danh sách bệnh nhân
        //
        public bool updateGridView_dscho()
        {
            dtgv_dsbn.Rows.Clear();

            try
            {
                db.OpenConnection();
                string sql = "select * from danhsachcho where sieuam like '.%'";
                dt_dscho = db.ExecuteReader(sql);
                foreach (System.Data.DataRow row in dt_dscho.Rows)
                {
                    string stt = row["stt"].ToString();
                    string id  = row["idBN"].ToString();
                    sql     = "select * from benhnhan where idBN=" + id;
                    dt_temp = db.ExecuteReader(sql);
                    string[] bn = new string[8];
                    bn[0] = stt;
                    for (int i = 0; i < 7; i++)
                    {
                        bn[i + 1] = dt_temp.Rows[0][i].ToString();
                    }
                    dtgv_dsbn.Rows.Add(bn);
                }
                db.CloseConnection();

                try
                {
                    txt_hotenbn.Text    = dtgv_dsbn.Rows[dtgv_dsbn.SelectedRows[0].Index].Cells["hoten"].Value.ToString();
                    txt_diachibn.Text   = dtgv_dsbn.Rows[dtgv_dsbn.SelectedRows[0].Index].Cells["diachi"].Value.ToString();
                    txt_idbn.Text       = dtgv_dsbn.Rows[dtgv_dsbn.SelectedRows[0].Index].Cells["id"].Value.ToString();
                    txt_nghenghiep.Text = dtgv_dsbn.Rows[dtgv_dsbn.SelectedRows[0].Index].Cells["nghenghiep"].Value.ToString();
                    txt_para.Text       = dtgv_dsbn.Rows[dtgv_dsbn.SelectedRows[0].Index].Cells["para"].Value.ToString();
                    txt_sdtbn.Text      = dtgv_dsbn.Rows[dtgv_dsbn.SelectedRows[0].Index].Cells["sdt"].Value.ToString();
                    txt_tuoibn.Text     = dtgv_dsbn.Rows[dtgv_dsbn.SelectedRows[0].Index].Cells["tuoi"].Value.ToString();

                    db.OpenConnection();
                    sql     = "select * from benhnhan where idBN=" + txt_idbn.Text;
                    dt_temp = db.ExecuteReader(sql);
                    db.CloseConnection();

                    txt_tiencanbn.Text        = dt_temp.Rows[0]["tiencan_bt"].ToString();
                    txt_tiencangd.Text        = dt_temp.Rows[0]["tiencan_gd"].ToString();
                    btn_editphieukham.Visible = true;

                    try
                    {
                        chb_sa2d.Checked  = false;
                        chb_sahth.Checked = false;
                        chb_sam.Checked   = false;
                        chb_sanad.Checked = false;

                        db.OpenConnection();
                        System.Data.DataTable t = db.ExecuteReader("select sieuam from danhsachcho where stt=" + dtgv_dsbn.Rows[dtgv_dsbn.SelectedRows[0].Index].Cells["stt"].Value.ToString());
                        db.CloseConnection();

                        string d = t.Rows[0][0].ToString();
                        string v = d.Trim('.');

                        string[] r = v.Split('-');

                        foreach (string s in r)
                        {
                            if (s == "Thai 2D")
                            {
                                chb_sa2d.Checked = true;
                            }
                            if (s == "Ngã âm đạo")
                            {
                                chb_sanad.Checked = true;
                            }
                            if (s == "Hình thái học")
                            {
                                chb_sahth.Checked = true;
                            }
                            if (s == "Màu")
                            {
                                chb_sam.Checked = true;
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                catch
                {
                    return(false);
                }

                return(true);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }