Beispiel #1
0
        private void btn_accept_Click(object sender, System.EventArgs e)
        {
            readonly_textboxes(true);
            btn_editphieukham.Visible = true;
            btn_accept.Visible        = false;
            btn_cancel.Visible        = false;

            if (txt_hotenbn.Text != temp_hoten || txt_diachibn.Text != temp_address || txt_sdtbn.Text != temp_phone ||
                txt_tuoibn.Text != temp_tuoi || txt_para.Text != temp_PARA || txt_nghenghiep.Text != temp_nghenghiep ||
                txt_tiencangd.Text != temp_tiencangd || txt_tiencanbn.Text != temp_tiencanbt)
            {
                string sql = "update benhnhan set ten=\"" + txt_hotenbn.Text + "\", address=\"" + txt_diachibn.Text + "\", phone_num=\""
                             + txt_sdtbn.Text + "\", tuoi=\"" + txt_tuoibn.Text + "\", PARA=\"" + txt_para.Text + "\", nghe_nghiep=\"" + txt_nghenghiep.Text
                             + "\", tiencan_gd=\"" + txt_tiencangd.Text + "\", tiencan_bt=\"" + txt_tiencanbn.Text + "\" where idBN=" + txt_idbn.Text;
                try
                {
                    db.OpenConnection();
                    db.ExecuteNonQuery(sql);
                    db.CloseConnection();
                    updateGridView_dscho();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            groupbox_dsbn.Enabled = groupbox_lskb.Enabled = groupbox_chandoan.Enabled = groupbox_control.Enabled = true;
        }
        private void btn_print_Click(object sender, System.EventArgs e)
        {
            string sqldatetime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string query       = "insert into toathuoc (ngay_lap, so_ngay, loi_dan, tong_tien, idPhieuKham) values ('" + sqldatetime + "', '" + txt_songay.Text + "', '" + txt_loidan.Text + "', '" + txt_tongtien.Text + "', '" + idpk + "')";

            try
            {
                db.OpenConnection();
                db.ExecuteNonQuery(query);
                db.CloseConnection();
            } catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                db.CloseConnection();
            }

            string idtoathuoc;

            try
            {
                db.OpenConnection();
                DataTable x = db.ExecuteReader("select idToaThuoc from toathuoc where ngay_lap='" + sqldatetime + "'");
                db.CloseConnection();
                idtoathuoc = x.Rows[0][0].ToString();

                db.OpenConnection();
                foreach (DataGridViewRow r in dtgv_donthuoc.Rows)
                {
                    string solan;
                    string moilan;
                    if (r.Cells["solan"].Value.ToString() == "")
                    {
                        solan = "0";
                    }
                    else
                    {
                        solan = r.Cells["solan"].Value.ToString();
                    }

                    if (r.Cells["moilan"].Value.ToString() == "")
                    {
                        moilan = "0";
                    }
                    else
                    {
                        moilan = r.Cells["moilan"].Value.ToString();
                    }

                    db.ExecuteNonQuery("insert into chitietthuoc(idThuoc, tenthuoc, so_vien, gia_ban, sl_trong_ngay, moi_lan, idToaThuoc) values(" + r.Cells["idthuoc"].Value.ToString() + ", '" + r.Cells["tenthuoc"].Value.ToString() + "', " + r.Cells["sl"].Value.ToString() + ", " + r.Cells["dongia"].Value.ToString() + ", " + solan + ", " + moilan + ", " + idtoathuoc + ")");
                }
                db.CloseConnection();
                Close();
            } catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }