Esempio n. 1
0
        private void Alter_reader_btn(object sender, EventArgs e)
        {
            string rrid    = alter_reader_rid.Text.Trim();
            string account = alter_reader_account.Text.Trim();
            string rsex    = alter_reader_rsex.Text.Trim();
            int    rbcnum  = int.Parse(alter_reader_rbcnum.Text);
            string rname   = alter_reader_rname.Text.Trim();
            string rwdep   = alter_reader_rwdep.Text.Trim();
            string rtel    = alter_reader_rtel.Text.Trim();
            string psw     = alter_reader_psw.Text.Trim();
            int    rbhnum  = rbhnum_p;
            string sql_alter_readertable = "update readertable" +
                                           " set rname = '" + rname + "', rsex = " + "'" + rsex + "', rbcnum = " + rbcnum + ", rbhnum = " + rbhnum + ", rwdep = '" + rwdep + "', rtel = '" + rtel + "' where rrid = '" + rrid + "'";
            string sql_alter_logintable = "update logintable set account = '" + account + "', psw = '" + psw + "' where rid = '" + rrid + "'";

            try
            {
                OprSql.ExecuteSql(sql_alter_readertable);
                OprSql.ExecuteSql(sql_alter_logintable);
            }
            catch
            {
                MessageBox.Show("违反约束或与数据库连接失败,修改失败");
                return;
            }
            MessageBox.Show("修改成功");
            ReaderManagement.form.reflash();
            this.Close();
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            string rrid;

            try
            {
                int delete_readerlist_index = reader_datalist.CurrentRow.Index;
                rrid = reader_datalist.Rows[delete_readerlist_index].Cells[0].Value.ToString();
            }
            catch (Exception index_e)
            {
                MessageBox.Show("未选定行");
                return;
            }
            string sql_delete_logintable  = "delete logintable where rid = '" + rrid + "'";
            string sql_delete_readertable = "delete readertable where rrid = '" + rrid + "'";

            //查看待删除读者是否有借阅记录,有就无法删除
            string sql_test  = "select * from borinfotable where rrrid = '" + rrid + "' and returndate is NULL";
            int    test_rows = OprSql.Queue(sql_test, "test_delete").Tables["test_delete"].Rows.Count;

            if (test_rows > 0)
            {
                MessageBox.Show("该读者有未归还书籍,不能删除");
                return;
            }

            try
            {
                string sql_delete_borinfotable = "delete from borinfotable where rrrid = '" + rrid + "'";
                OprSql.ExecuteSql(sql_delete_borinfotable);

                OprSql.ExecuteSql(sql_delete_logintable);
                OprSql.ExecuteSql(sql_delete_readertable);
            }
            catch
            {
                MessageBox.Show("无法与数据库连接,删除失败");
                return;
            }
            MessageBox.Show("删除成功!");
            button4_Click_1(this, e);
        }
Esempio n. 3
0
        private void rb_bt_Click(object sender, EventArgs e)
        {
            if (rbdatalist.CurrentRow == null)
            {
                MessageBox.Show("请正确选择你想还的书籍!");
                return;
            }
            int    index    = rbdatalist.CurrentRow.Index;
            string borid    = rbdatalist.Rows[index].Cells[0].Value.ToString().Trim();
            string datetime = DateTime.Parse(DateTime.Now.ToShortDateString()).ToString("yyyy-MM-dd");
            string sql      = "update borinfotable set returndate = '" + datetime + "' where id =" + borid;

            if (OprSql.ExecuteSql(sql) > 0)
            {
                MessageBox.Show("还书成功!");
                rbdatalist.DataSource = null;// 清空图书
                reflash();
            }
            else
            {
                MessageBox.Show("还书失败!");
            }
        }
Esempio n. 4
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(add_reader_rrid.Text))
            {
                MessageBox.Show("借书证号不能为空!");
                return;
            }

            if (string.IsNullOrEmpty(add_reader_account.Text) || string.IsNullOrEmpty(add_reader_psw.Text))
            {
                MessageBox.Show("账号密码不能为空!");
                return;
            }

            string rrid  = add_reader_rrid.Text.Trim();
            string rname = add_reader_rname.Text.Trim();


            //性别默认为m
            string rsex = "m";

            if (add_reader_rsex.Text.Trim() != "f" && add_reader_rsex.Text.Trim() != "m")
            {
                MessageBox.Show("无效性别,已设为默认值m");
            }
            else if (add_reader_rsex.Text.Trim() != "f")
            {
                rsex = "f";
            }


            int rbcnum = 16;

            if (add_reader_rbcnum.Text.Trim() != "")
            {
                rbcnum = int.Parse(add_reader_rbcnum.Text);
            }
            int rbhnum = 0;


            string rwdep = add_reader_rdep.Text.Trim();
            string rtel  = add_reader_psw.Text.Trim();
            string sql   = "insert into readertable(rrid, rname, rsex, rbcnum, rbhnum, rwdep, rtel)" +
                           " values ('" + rrid + "', '" + rname + "', '" + rsex + "', "
                           + rbcnum + ", " + rbhnum + ", '" + rwdep + "', '" + rtel + "')";

            //logintable
            string account   = add_reader_account.Text.Trim();
            string psw       = add_reader_psw.Text.Trim();
            int    authority = 2;
            string rid       = rrid;

            string sql_login = "******" +
                               "values('" + account + "', '" + psw + "', " + authority + ", '" + rid + "')";

            try
            {
                OprSql.ExecuteSql(sql);
                OprSql.ExecuteSql(sql_login);
            }
            catch
            {
                MessageBox.Show("添加了重复的借书证号或账户名,新增失败");
                return;
            }
            this.Close();
        }
Esempio n. 5
0
        private void button1_Click(object sender, EventArgs e)
        {   // 借阅
            //先判断借书是否到上限
            //判断是否有罚款 否提示交罚款 有借阅成功

            string    readersql = "select * from readertable where rrid = '" + Reader.form.getRid() + "'";
            DataTable dreader   = OprSql.Queue(readersql, "readertable").Tables["readertable"];

            if (int.Parse(dreader.Rows[0]["rbcnum"].ToString()) -
                int.Parse(dreader.Rows[0]["rbhnum"].ToString()) == 0)
            {
                // 到借阅上限,无法再借
                MessageBox.Show("无法再借");
                return;
            }

            // 是否有罚款
            string sql = "select * from borinfotable where fine != 0 and rrrid='" +
                         Reader.form.getRid() + "'";
            DataTable dt = OprSql.Queue(sql, "bortable").Tables["bortable"];

            if (dt.Rows.Count != 0)
            {
                MessageBox.Show("有罚款不能借阅");
                if (MessageBox.Show("是否提交罚款?", "提示", MessageBoxButtons.YesNo)
                    == DialogResult.Yes)
                {
                    // 提交罚款后,将所有的罚款进行更新为0
                    string updateFine = "update  borinfotable set fine=0 where fine != 0 and rrrid='" + Reader.form.getRid() + "'";
                    if (OprSql.ExecuteSql(updateFine) > 0)
                    {
                        MessageBox.Show("交款成功!");
                    }
                    else
                    {
                        MessageBox.Show("交款失败,请再次尝试!");
                    }
                }
                else
                {
                    // 拒绝提交罚款
                    return;
                }
            }
            else
            {
                // 借书部分
                if (datalist.CurrentRow == null)
                {
                    MessageBox.Show("请先查询!");
                    return;
                }
                int    index  = datalist.CurrentRow.Index;
                string bookid = datalist.Rows[index].Cells[0].Value.ToString().Trim();

                string nowString      = DateTime.Parse(DateTime.Now.ToShortDateString()).ToString("yyyy-MM-dd");
                string terminalString = DateTime.Parse(DateTime.Now.AddDays(60).ToShortDateString()).ToString("yyyy-MM-dd");
                // 更改表,使得同一个人可以借多本书
                string borsql = "insert into borinfotable(rrrid,brid,bdate,bterminaldate,returndate,fine)  values('" + Reader.form.getRid() + "','" + bookid + "','" + nowString + "','" +
                                terminalString + "'," + "null" + "," + 0 + ")";

                // 判断是否还有书本可借
                if (int.Parse(datalist.Rows[index].Cells[4].Value.ToString().Trim()) == 0)
                {
                    MessageBox.Show("此本书已经被借完,请等候!");
                    return;
                }
                try
                {
                    // 已经借阅,不可重复借阅
                    string hasborrow = "select * from borinfotable where rrrid='" + Reader.form.getRid() + "' and brid='" +
                                       bookid + "' and returndate is null";
                    if (OprSql.Queue(hasborrow, "hasbortable").Tables["hasbortable"].Rows.Count != 0)
                    {
                        MessageBox.Show("您已经借过此书,为了保证资源合理利用,请借其他书");
                        return;
                    }

                    if (OprSql.ExecuteSql(borsql) > 0)
                    {
                        MessageBox.Show("借书成功!");
                        datalist.DataSource = OprSql.Queue(searchsql, "searchtable").Tables["searchtable"];
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("借书失败!");
                }
            }
        }