コード例 #1
0
        private void mem_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(str0))
            {
            }
            else
            {
                string strQuery1 = "Select Sname as 用户姓名 From Students Where Sid='" + str0 + "' ";
                string strQuery2 = "Select Spwd as 密码 From Students Where Sid='" + str0 + "' ";

                Sql1          sqlHelper = new Sql1();
                SqlConnection con       = sqlHelper.GetConnection();
                SqlCommand    cmd1      = new SqlCommand(strQuery1, con);
                SqlCommand    cmd2      = new SqlCommand(strQuery2, con);

                con.Open();
                id1 = (string)cmd1.ExecuteScalar();
                id2 = (string)cmd2.ExecuteScalar();

                textBox2.Text = id1;
                textBox3.Text = id2;
            }
        }
コード例 #2
0
ファイル: Admin.cs プロジェクト: wenjunjiecn/NCEPU-CS-COURSES
        private void 书籍查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panel1.Visible = false;
            panel4.Visible = false;
            panel6.Visible = true;
            panel5.Visible = true;
            Sql1          sqlHelper = new Sql1();
            SqlConnection con       = sqlHelper.GetConnection();

            con.Open();
            string strQuery = "select Bid as 书籍编号, Bname as 书名, Bpress as 出版社, Bstate as 状态, Bwriter as 作者, Bdate as 出版时间 from Books";

            try
            {
                DataSet   ds = sqlHelper.GetDataSet(strQuery);
                DataTable dt = ds.Tables[0];

                dataGridView6.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "" || textBox2.Text.Length > 10)
            {
                MessageBox.Show("请输入正确的书籍编号!");
            }
            else
            {
                //借阅书籍
                string str1 = textBox2.Text.Trim(); // 编号
                string str2 = textBox4.Text.Trim(); // 时间

                //检查是否可借
                string strQuery = "Select Bstate From Books Where Bid='" + str1 + "' ";
                //检查该用户是否已借过该书
                string strQuery0 = "Select Sid From Borrow Where Bid='" + str1 + "' AND Sid='" + str0 + "'";
                //更新状态
                string strUpdata = "Update Books Set Bstate='借出' Where Bid='" + str1 + "'AND Bid='" + str1 + "'";
                //增加借阅记录
                string strInsert2 = "Insert Into Borrow(Bid,Sid,Borrowtime) Values('"
                                    + str1 + "','" + str0 + "','" + str2 + "')";
                //增加归还记录
                string strInsert3 = "Insert Into Reback(Bid,Sid,Returntime) Values('"
                                    + str1 + "','" + str0 + "','未还')";
                string strDelete = "Delete From Reback Where Sid='" + str0 + "' AND Bid='" + str1 + "'";
                try
                {
                    Sql1          sqlHelper = new Sql1();
                    SqlConnection con       = sqlHelper.GetConnection();
                    SqlCommand    cmd       = new SqlCommand(strQuery, con);
                    SqlCommand    cmd2      = new SqlCommand(strQuery0, con);
                    con.Open();
                    string id1 = (string)cmd.ExecuteScalar();
                    id1 = id1.Trim();
                    string id2 = (string)cmd2.ExecuteScalar();

                    if ((id1 == "可借") && (string.IsNullOrEmpty(id2)))
                    {
                        sqlHelper.OperateTb(strUpdata);
                        sqlHelper.OperateTb(strInsert2);
                        sqlHelper.OperateTb(strDelete);
                        sqlHelper.OperateTb(strInsert3);
                        MessageBox.Show("借阅成功");
                        借阅书籍ToolStripMenuItem_Click(null, null);//刷新页面
                        textBox2.Text = null;
                        textBox1.Text = null;
                    }
                    else if (id1 == "借出") // &&(string.IsNullOrEmpty(id2))
                    {
                        MessageBox.Show("书已借出,借书失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else // if (!string.IsNullOrEmpty(id2))
                    {
                        MessageBox.Show("已借阅过该书(不允许重复借阅)", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("该书籍编号不存在!");
                }
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: luocr7/NCEPU-CS-COURSES
        private void button1_Click(object sender, EventArgs e)  // 登录
        {
            string userid = textBox1.Text.Trim();
            string userpw = textBox2.Text.Trim();

            if (radioButton2.Checked == true)
            {
                try
                {
                    Sql1           sqlHelper = new Sql1();
                    SqlConnection  con       = sqlHelper.GetConnection();
                    SqlCommand     com       = new SqlCommand("select Aid,Apwd from Administrators where Aid='" + userid + "' and Apwd='" + userpw + "'", con);
                    SqlDataAdapter da        = new SqlDataAdapter(com);
                    DataSet        ds        = new DataSet();
                    int            n         = da.Fill(ds, "register");


                    if (n != 0)
                    {
                        Admin f = new Admin();
                        f.ShowDialog();
                        textBox1.Text = null;
                        textBox2.Text = null;
                    }
                    else
                    {
                        MessageBox.Show("请输入正确的账号和密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        textBox2.Text = null;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                try
                {
                    Sql1           sqlHelper = new Sql1();
                    SqlConnection  con       = sqlHelper.GetConnection();
                    SqlCommand     com       = new SqlCommand("select Sid,Spwd from Students where Sid='" + userid + "' and Spwd='" + userpw + "'", con);
                    SqlDataAdapter da        = new SqlDataAdapter(com);
                    DataSet        ds        = new DataSet();
                    int            n         = da.Fill(ds, "register");


                    if (n != 0)
                    {
                        Puser f = new Puser();
                        f.str0 = userid;
                        f.ShowDialog();
                        textBox1.Text = null;
                        textBox2.Text = null;
                    }
                    else
                    {
                        MessageBox.Show("请输入正确的账号和密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        textBox2.Text = null;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #5
0
ファイル: Admin.cs プロジェクト: wenjunjiecn/NCEPU-CS-COURSES
        private void button2_Click(object sender, EventArgs e)
        {
            //修改书籍
            DateTime dt = new DateTime();

            dt = DateTime.Now;
            if (textBox1.Text.Trim() == "")
            {
                MessageBox.Show("请输入书籍编号!");
            }
            else if (textBox2.Text.Trim() == "")
            {
                MessageBox.Show("请输入书名!");
            }
            else if (textBox3.Text.Trim() == "")
            {
                MessageBox.Show("请输入出版社!");
            }
            else if (comboBox1.Text.Trim() == "")
            {
                MessageBox.Show("请输入状态!");
            }
            else if (textBox5.Text.Trim() == "")
            {
                MessageBox.Show("请输入作者!");
            }
            else if (DateTime.Compare(dateTimePicker1.Value.Date, dt) > 0)
            {
                MessageBox.Show("日期超前,请选择正确日期!");
            }
            else
            {
                string Bid     = textBox1.Text.Trim();
                string Bname   = textBox2.Text.Trim();
                string Bpress  = textBox3.Text.Trim();
                string Bstate  = comboBox1.Text.Trim();
                string Bwriter = textBox5.Text.Trim();
                string Bdate   = dateTimePicker1.Value.Date.ToShortDateString();

                string strUpdata = "Update Books Set Bid='" + Bid + "',Bname='" + Bname + "',Bpress='" + Bpress + "',Bstate='" + Bstate + "',Bwriter='" + Bwriter + "',Bdate='" + Bdate + "' Where Bid='" + Bid + "'";

                try
                {
                    Sql1          sqlHelper = new Sql1();
                    SqlConnection con       = sqlHelper.GetConnection();
                    con.Open();
                    SqlCommand    com = new SqlCommand("select Bid from Books where Bid='" + Bid + "'", con);
                    SqlDataReader sdr = com.ExecuteReader();
                    if (sdr.HasRows)
                    {
                        sqlHelper.OperateTb(strUpdata);
                        MessageBox.Show("修改成功!");
                        书籍管理ToolStripMenuItem_Click(null, null);
                    }
                    else
                    {
                        MessageBox.Show("修改失败!不存在该书籍");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #6
0
ファイル: Admin.cs プロジェクト: wenjunjiecn/NCEPU-CS-COURSES
        private void button1_Click(object sender, EventArgs e)
        {
            //添加书籍
            DateTime dt = new DateTime();

            dt = DateTime.Now;
            if (textBox1.Text.Trim() == "")
            {
                MessageBox.Show("请输入书籍编号!");
            }
            else if (textBox2.Text.Trim() == "")
            {
                MessageBox.Show("请输入书名!");
            }
            else if (textBox3.Text.Trim() == "")
            {
                MessageBox.Show("请输入出版社!");
            }
            else if (comboBox1.Text.Trim() == "")
            {
                MessageBox.Show("请输入状态!");
            }
            else if (textBox5.Text.Trim() == "")
            {
                MessageBox.Show("请输入作者!");
            }
            else if (DateTime.Compare(dateTimePicker1.Value.Date, dt) > 0)
            {
                MessageBox.Show("日期超前,请选择正确日期!");
            }
            else
            {
                string Bid       = textBox1.Text.Trim();
                string Bname     = textBox2.Text.Trim();
                string Bpress    = textBox3.Text.Trim();
                string Bstate    = comboBox1.Text.Trim();
                string Bwriter   = textBox5.Text.Trim();
                string Bdate     = dateTimePicker1.Value.Date.ToShortDateString();
                string strInsert = "Insert Into Books(Bid,Bname,Bpress,Bstate,Bwriter,Bdate) Values('"
                                   + Bid + "','" + Bname + "','" + Bpress + "','" + Bstate + "','" + Bwriter + "','" + Bdate + "')";

                //string strQuery1 = "Select Bstate as 状态 From Books Where Bstate='" + comboBox1.Text + "' ";
                Sql1          sqlHelper = new Sql1();
                SqlConnection con       = sqlHelper.GetConnection();
                // SqlCommand cmd1 = new SqlCommand(strQuery1, con);
                con.Open();
                // string id1 = (string)cmd1.ExecuteScalar();

                try
                {
                    //con.Open();
                    SqlCommand    com = new SqlCommand("select Bid from Books where Bid='" + Bid + "'", con);
                    SqlDataReader sdr = com.ExecuteReader();
                    if (sdr.HasRows)
                    {
                        MessageBox.Show("该书籍已存在!");
                    }
                    else
                    {
                        int intResult = sqlHelper.OperateTb(strInsert);
                        MessageBox.Show("成功添加" + intResult + "记录!");
                        书籍管理ToolStripMenuItem_Click(null, null);
                    }
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }